[squeak-dev] FFI issue in Squeak 4.2 ?

Levente Uzonyi leves at elte.hu
Mon Feb 21 01:40:27 UTC 2011

On Sun, 20 Feb 2011, mkobetic at gmail.com wrote:

> I'm struggling to load Xtreams-Xtras into the new release of Squeak. I sprinkled all the classes with allowUnderscoreSelectors (true) and allowUnderscoreAssignments (false), made sure I don't have any underscores on class side, made sure none of the classes have underscores in their names, but it still seems that unless i explicitly turn off allowUnderscoreAssignments in global preferences it won't compile the instance side methods with underscore selectors.

There's no need to turn off #allowUnderscoreAsAssignment if the code is 
not ambiguous (it's not). The need for the global 
#allowUnderscoreSelectors is because of MC. It tries to load EVPMD >> 
#'block_size' before EVPMD class >> #allowUnderscoreSelectors which won't 

IMHO it's better to just use the global preference, since the per class 
methods are not good enough.

> Then even when I get past it with the help of the global preference, I still get the following syntax error which doesn't make any sense to me:
> HMAC_CTX_cleanup: ctx
> 	<cdecl:	void 'HMAC_CTX_cleanup' (HMACCTX*Matching number of arguments expected ->) module: 'libcrypto'>
> 	^self externalCallFailed
> HMACCTX is a subclass of ExternalStructure. This all seems to be fine on Pharo side and I would swear I could load it into an earlier Squeak version, but I don't remember the details anymore. I even made sure I'm using the exact same versions of FFI packages as I do in Pharo (the configuration from MetacelloRepository that I normally load in Pharo doesn't seem to be quite up to date), but that didn't help either. Any suggestions ? How should one go about writing portable FFI code (I mean portable between Pharo and Squeak)? Any chance that FFI support would be in the base image one day so that one didn't have to worry about where to get it and which one ?

FFI is fine. The cause of the problem is String >> #numArgs. $_ is not 
accepted by it as a valid selector character, so it returns -1 instead of 
1 for #'HMAC_CTX_cleanup:'. It will be fixed in the Trunk soon, along 
with the other underscore related problems.

I doubt FFI will be preloaded in images, because it has some security 
risk. However there's a simple solution: Metacello. A Metacello 
configuration can ensure that FFI is loaded before the FFI specific parts 
are loaded, take care about platform specific stuff, like changing the 
preferences, etc.

I managed to load XTreams to Squeak Trunk (possibly works with 4.2 too) 
using the following script:

"Make sure that underscores are allowed in selectors."
 	compile: 'tokenish
 	"Answer whether the receiver is a valid token-character--letter, digit, or

 	^self == $_ or: [self == $: or: [self isLetter or: [self isDigit]]]'
 	classified: 'testing'.
String initialize.
Scanner prefAllowUnderscoreSelectors: true.
"Load FFI"
Installer squeak
 	project: 'FFI';
 	install: 'FFI-Pools';
 	install: 'FFI-Kernel';
 	install: 'FFI-Tests';
 	install: 'FFI-Win32';
 	install: 'FFI-MacOS';
 	install: 'FFI-Unix'.
"Load XTreams"
Installer ss
 	project: 'Xtreams';
  	install: 'Xtreams-Support';
  	install: 'Xtreams-Core-';
  	install: 'Xtreams-Terminals-';
  	install: 'Xtreams-Transforms-';
  	install: 'Xtreams-Substreams-';
  	install: 'Xtreams-Parsing-';
  	" --- tests follow --- "
  	install: 'Xtreams-CoreTests';
  	install: 'Xtreams-TerminalsTests';
  	install: 'Xtreams-TransformsTests';
  	install: 'Xtreams-SubstreamsTests';
  	install: 'Xtreams-ParsingTests';
  	" --- following require FFI --- "
  	install: 'Xtreams-Xtras-';
  	install: 'Xtreams-XtrasTests'.

I also uploaded a new version of Xtreams-Xtras to the repository which 
fixes XTHMACTest and XTHashTest for Squeak.

With these changes, all tests are green on Windows.


> Thanks,
> Martin

More information about the Squeak-dev mailing list