[Cuis-dev] FFI changed?

Juan Vuletich juan at cuis.st
Sun Apr 23 14:55:23 PDT 2023


Hi Stephen,

I could not make your libportmidi.dylib work on my mac (MBP 2019 Intel), 
but I did some experiments that may prove useful. Please read.

1)
ExternalAddress loadSymbol: 'ffiTestFloats' module: 'SqueakFFIPrims'.
Works, OK, same as for you.

2) Copied your libportmidi.dylib to my main Cuis folder (where the VM is 
located)
ExternalAddress loadSymbol: 'pm_count_devices' module: 'libportmidi.dylib'.
Didn't work. I get a Debugger with error 'loadSymbol:module: failed', 
same as you.

3) Looked for some hopefully sane dylib in my system. Randomly picked 
HD/Library/Developer/CommandLineTools/usr/lib/libclang.dylib
Copied it to same folder. Googled a bit for some entry point. Then tried
ExternalAddress loadSymbol: 'clang_getCString' module: 'libclang.dylib'.
This works OK, answering a non zero ExternalAddress!

4) Googled a bit for libportmidi. Found http://zesty.ca/midi/ . 
Downloaded libportmidi.dylib from there. Renamed it as 
libportmidi_1.dylib. Copied this to same folder. Searched in the file 
for something that looked like an entry point.
ExternalAddress loadSymbol: 'Pm_CountDevices' module: 'libportmidi_1.dylib'.
Got an OSX error, warning me that the file is from an unidentified 
developer. Looks like it is not signed.

5) On MacOSFinder, on this libportmidi_1.dylib did shift+right click and 
open. Get the warning from OSX about unidentified developer, but with 
the option to [open] anyway. Click on Open. This does nothing, but marks 
the file as "approved", apparently. Now, I do
ExternalAddress loadSymbol: 'Pm_CountDevices' module: 'libportmidi_1.dylib'.
IT WORKS! I get a nonzero ExternalAddress!

So, what does all this mean? I guess that one of the following:
- Your libportmidi.dylib is for some reason incompatible with my system
- Your libportmidi.dylib is not signed, and I couldn't "approve" it for 
running
- Your libportmidi.dylib file is broken/corrupted

I hope this is of some use. I guess you could also ask in vm-dev, and 
someone who understands this stuff much better than me may answer. 
Please keep us posted.

Good luck!
Cheers,

On 4/21/2023 9:12 PM, Stephen Travis Pope via Cuis-dev wrote:
>
> 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 
>> toFFI.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://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
>


-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230423/a7af30e3/attachment-0001.htm>


More information about the Cuis-dev mailing list