https://pantsbuild.org/ logo
#development
Title
# development
w

witty-crayon-22786

11/07/2019, 1:00 AM
can pass a Utf8Buffer
...maybe not called that. sec.
h

hundreds-breakfast-49010

11/07/2019, 1:01 AM
so not a normal python
str
w

witty-crayon-22786

11/07/2019, 1:01 AM
can also do that. multiple options.
actually: one is mostly for returning from an extern
h

hundreds-breakfast-49010

11/07/2019, 1:02 AM
so if I invoke a FFI funciton with an arg of
*const raw::c_char
, and pass a normal python string in that position, the FFI lib will make sure I don't do something wierd with memory?
w

witty-crayon-22786

11/07/2019, 1:02 AM
because if you return a
*const raw::c_char
, it will be garbage collected before it hits the rust code
yes, that is correct.
h

hundreds-breakfast-49010

11/07/2019, 1:02 AM
ok cool
w

witty-crayon-22786

11/07/2019, 1:03 AM
so yea.
*const raw::c_char
is fine as an argument, because the caller still has it on their stack
you need to copy it, because you don't own it.
but other than that, good.
but the alternative you've seen a few places is passing in a
Value
, and then using
externs
to get things.
h

hundreds-breakfast-49010

11/07/2019, 1:05 AM
ah yeah I guess a python string is also a
Value
w

witty-crayon-22786

11/07/2019, 1:05 AM
and that works as well, and generally uses the
externs::*Buffer
types'
well, it is if you make it one.
Value ~= "cffi handle" (search for "handle" in that page)