Je comprends enfin... I accidentally came across a StackOverflow answer that suggested the String object is immutable. That makes perfect sense, as I know the C function is actually /*trying*/ to write to the buffer. That gave me the idea to use a ByteArray instead. Now, everything works! horrido wrote
There is shockingly very little documentation on how to use uFFI. In particular, I have the following situation...
A shared C lib has the following function:
void get_machine(char *machine) { uname(&uname_s); strcpy(machine, uname_s.machine); }
It copies the content of a string value into the buffer passed to it (char *machine).
I want to call this function from Pharo, thus:
buffer := String new: 64. self ffiCall: #( void get_machine(String buffer) ).
The buffer never receives the string value (it just contains the 64 initiialized spaces).
Clearly, I'm misunderstanding the proper mechanism for doing this.
[There are other functions in the shared C lib that work fine, such as:
uint get_uptime() { sysinfo(&info); return info.uptime; }
Returning integers or floats is no problem. But passing arguments by reference seems to be verboten.]
-- View this message in context: http://forum.world.st/How-to-use-uFFI-with-String-tp4947890p4948144.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.