TL;DR: How to pass as argument an array of Strings (char **) with Unified-FFI?
Vincent
De : Blondeau Vincent
Envoy� : mercredi 25 mai 2016 13:58
� : Pharo Development List
Objet : [UFFI] Call a function where argument type is char ** (argv)
Hello,
I have written a R bridge in Pharo and I would like to migrate it from NativeBoost to UFFI.
Most of the changes are easy to do but I am stuck to a double pointer problem.
I have to call the function: int Rf_initEmbeddedR(int argc, char ** argv). I know how to give the int but the char ** is a problem. It is an array of Strings.
With NB, I managed to have this (working) code:
"This is 32bit... too bad..."
strings := OrderedCollection new.
par := NativeBoost allocate: 4 * params size.
params
keysAndValuesDo: [ :i :each |
| str |
str := each asNBExternalString.
strings add: str.
par nbUInt32AtOffset: (i - 1) * 4 put: str value ].
self prim_initEmbeddedRargc: params size argv: par ]
ensure: [
"Free the memory we allocated"
par ifNotNil: [ par free ].
strings ifNotNil: [ strings do: [ :each | each free ] ] ]
With a primitive call:
Self nbCall: #(int Rf_initEmbeddedR(int argc, char *argv))
Do I still need to create my own array of strings or FFI creates it for me? How?
Thanks in advance for your answers,
Vincent