You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, thanks for all your work on creating the FFI:: set of modules. I was wondering if it's possible to create an uninitialized or even zero-initialized FFI::C::Stat object. Specifically, I'm trying to use smbc_stat (from libsmbclient.h) which looks exactly like the examples in your documentation, where I have a function that requires a pointer to a stat as an input. However, FFI::C::Stat seems to always perform a variant of stat, or require an existing stat.
C function definition:
/** * @param st pointer to a buffer that will be filled with * standard Unix struct stat information.*/intsmbc_stat(constchar*url, structstat*st);
The following Perl code successfully runs and performs the stat, but something seems odd about my explicit use of malloc and the hardcoded number of bytes. Although it works, I'm wondering if I am using this module incorrectly. I'm certainly no FFI expert.
...
$ffi->type('object(FFI::C::Stat)'=>'stat');
$ffi->attach( 'smbc_stat'=> ['string', 'stat'] =>'int' );
...
my$ptr = malloc(144); # Number of bytes found in C with: printf("Size of struct stat: %lu bytes\n", sizeof(struct stat));my$stat = FFI::C::Stat->clone($ptr);
free $ptr;
my$result = smbc_stat($url, $stat);
Thanks!
The text was updated successfully, but these errors were encountered:
Yes that code is correct and works for the platform that you are running on, but it won't be portable if you need the code to run on platforms where stat is a different size (and it can and does vary).
There should be a way to construct an uninitialized stat though this is a thing that is missing from the interface. I'm thinking that calling new with no arguments should do exactly that:
my$stat = FFI::C::Stat->new;
Since that is currently an error it will complain and die if you try to do that with an old version of FFI::C::Stat instead of silently erroring or corrupting memory.
Hi, thanks for all your work on creating the FFI:: set of modules. I was wondering if it's possible to create an uninitialized or even zero-initialized
FFI::C::Stat
object. Specifically, I'm trying to usesmbc_stat
(from libsmbclient.h) which looks exactly like the examples in your documentation, where I have a function that requires a pointer to a stat as an input. However,FFI::C::Stat
seems to always perform a variant of stat, or require an existing stat.C function definition:
The following Perl code successfully runs and performs the stat, but something seems odd about my explicit use of malloc and the hardcoded number of bytes. Although it works, I'm wondering if I am using this module incorrectly. I'm certainly no FFI expert.
Thanks!
The text was updated successfully, but these errors were encountered: