[Cuis-dev] FFI changed?
    Stephen Travis Pope 
    stephen at heaveneverywhere.com
       
    Fri Apr 21 17:12:30 PDT 2023
    
    
  
Holà Juan et al.,
So, I put the attached dylib in the Resources folder of the Squeak-jit VM (like always), then I fired up a fresh 5772 image and loaded the FFI and FFI-Test packages, and filed in the attached ST code (PortMIDILibrary class).
(I checked and the dylib exports a code token named “pm_count_devices” (try nm -ng libportmidi.dylib | grep pm_ ))
These tests worked:
	FFITestLibrary ffiTestInt: $A asCharacter with: 65 with: 65.0 with: true.
	FFITestLibrary new ffiPrintString:'Hello World!!' asUtf8BytesOrByteString.
	FFIPluginTests new testBiggerStruct
	FFIPluginTests new testConstructedPrintString
and this returned a nice string
	FFITestLibrary moduleName
and this returned the expected lib name
	PortMIDILibrary moduleName
But trying to call a simple prim like
	PortMIDILibrary pm_count_devices
failed, not being able to locate the C fcn.  All that the method does is,
	pm_count_devices
		"Answer the number of MIDI ports"
		"PortMIDILibrary pm_count_devices”
		< cdecl: long 'pm_count_devices' (void) module: 'libportmidi.dylib' >
		^self externalCallFailed
So I tried the lower-level way, as in,
Works
	[ExternalAddress loadSymbol: 'ffiTestFloats' asUtf8BytesOrByteString 
		module: FFITestLibrary moduleName asUtf8BytesOrByteString]
Doesn’t work
	[ExternalAddress loadSymbol: 'pm_count_devices' asUtf8BytesOrByteString 
		module: PortMIDILibrary moduleName asUtf8BytesOrByteString]
All variations of this return a function with address 0
	[ExternalLibraryFunction
		name: 'pm_count_devices' asUtf8BytesOrByteString
			module: ‘libportmidi.dylib' asUtf8BytesOrByteString
		callType: 0 
		returnType: ExternalType long
		argumentTypes: ((1 to: 1) collect: [ :i | ExternalType void])]
And this fails, of course
	[ | meth |
	meth := ExternalLibraryFunction
		name: 'pm_count_devices' asUtf8BytesOrByteString
			module: 'libportmidi' asUtf8BytesOrByteString
		callType: 0 
		returnType: ExternalType long
		argumentTypes: ((1 to: 1) collect: [ :i | ExternalType void]).
	result := meth invoke.
	result]
Is there something obvious that I’m doing wrong?
I’m running on an ARM-based MacStudio.
The prims work fine with Squeak and the Squeak6.1alpha VM.
…any reply MOST appreciated…
stp
——
Attachments
Minimal ST class w prim interface

PortMIDI dylib

--------
Stephen Travis Pope    Ojai, California, USA
    
     http://HeavenEverywhere.com
     http://FASTLabInc.com
     https://vimeo.com/user19434036/videos
     http://heaveneverywhere.com/Reflections
> On Apr 20, 2023, at 4:35 AM, Juan Vuletich via Cuis-dev <cuis-dev at lists.cuis.st> wrote:
> 
> Hi Stephen,
> 
> On 4/19/2023 9:17 PM, Stephen Travis Pope via Cuis-dev wrote:
>> 
>> 
>> Hi all,
>> 
>> I’m porting Siren back from Squeak to Cuis, hoping to be able to use the vector graphics extensively.
> 
> That is great news! I believe that VG can simplify the UI and improve the looks and experience for any kind of apps, like it does for DrGeo.
> 
>> One issue that has come up is that the FFI interface to the PortMIDI library that worked a few months ago stopped working.
>> 
>> Has something changed in the VM FFI interface?
> 
> In November 2022, I integrated UnicodeString. Since them, anywhere you may expect an instance of String, you may instead get an instance of UnicodeString. This hasn't brought much trouble, as they are polymorphic. But a few tweaks here and there were needed. Last commit to FFI.pck.st <http://ffi.pck.st/> is from Jan 6 and it was specifically for this.
> 
> On my Intel Mac, using an updated Cuis, and loading `Feature require: 'Tests-FFI'`, all the FFI test pass. Do they pass on your Apple Silicon Mac?
> 
>> Can we still load dylibs (rather than only bundles) on Macs?
> 
> I believe we can. Not too long ago, before Apple dropped support for OpenCL, I used it extensively, and I believe it was a dylib. Nowadays, I'm not using FFI much.
> 
> Can you help me reproduce what you are doing on my Mac? I'd like to see it running on a Cuis from the date it did work from you, and also reproduce your updated setup to see the failure.
> 
> Do you get a debugger? Error messages? Something on the Transcript or StdIO (in Terminal)?
> 
> If I can reproduce your setup and the problems you see, I'm sure we'll fix them.
> 
>> …any reply appreciated…
>> 
>> stp
>> 
>> --------
>> 
>> Stephen Travis Pope    Ojai, California, USA
>>      http://HeavenEverywhere.com <http://heaveneverywhere.com/>
>>      http://FASTLabInc.com <http://fastlabinc.com/>
>>      https://vimeo.com/user19434036/videos
>>      http://heaveneverywhere.com/Reflections
>> 
> 
> Thanks,
> -- 
> Juan Vuletich
> cuis.st <http://cuis.st/>
> github.com/jvuletich <http://github.com/jvuletich>
> researchgate.net/profile/Juan-Vuletich <http://researchgate.net/profile/Juan-Vuletich>
> independent.academia.edu/JuanVuletich <http://independent.academia.edu/JuanVuletich>
> patents.justia.com/inventor/juan-manuel-vuletich <http://patents.justia.com/inventor/juan-manuel-vuletich>
> linkedin.com/in/juan-vuletich-75611b3 <http://linkedin.com/in/juan-vuletich-75611b3>
> twitter.com/JuanVuletich <http://twitter.com/JuanVuletich>-- 
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st <mailto:Cuis-dev at lists.cuis.st>
> https://lists.cuis.st/mailman/listinfo/cuis-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230421/e8d5615f/attachment-0004.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MusicIO-MIDI.st
Type: application/octet-stream
Size: 7508 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230421/e8d5615f/attachment-0002.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230421/e8d5615f/attachment-0005.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libportmidi.dylib
Type: application/octet-stream
Size: 97120 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230421/e8d5615f/attachment-0003.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230421/e8d5615f/attachment-0006.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.tiff
Type: image/tiff
Size: 2442 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230421/e8d5615f/attachment-0001.tiff>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230421/e8d5615f/attachment-0007.htm>
    
    
More information about the Cuis-dev
mailing list