[Pharo-project] FFI definitions - structs
Hi, The FFI documentation states the following in terms of defining a C struct fields when defining subclasses of ExternalStructure: ##################################### For example, a color structur might implemented so: - first, create a new class named color in the System Browser (subclass of ExternalStructure) - add class method 'fields' to color maybe, like this: ------------------------------ fields ^#((red 'byte') (green 'byte') (blue 'byte')) ########################################## It only mentions simple data types, int, byte etc, as do the all the examples I've been able to find. How do you define pointers to other structs that are fields that are part of the C struct. E.g. C definition: struct Statement { Stmt *stmt; /* statement handle */ Resultset **rsts; /* pointer to resultset list */ .... Thanks
Try something like what appears below. If you search the Squeak archives, you'll probably find some useful posts by Andreas Raab. Don't expect too much documentation. Overall, Squeak/Pharo's FFI still falls far short of Dolphin's (sorry, but it's true), and structure mapping is a big area of relative weakness. Note that you *might* have to add an instance variable and accessors to allow the struct to hold a reference to the "real" target object - otherwise the GC might pull things out from under you. Somewhere in the Dolphin image, there are examples of the phenomenon. HTH. Bill ============================== fields " Gsl_wavelet defineFields struct { const gsl_wavelet_type *type; const double *h1; const double *g1; const double *h2; const double *g2; size_t nc; size_t offset; }" ^#( ( type 'Gsl_wavelet_type*' ) ( h1 'double*' ) ( g1 'double*' ) ( h2 'double*' ) ( g2 'double*' ) ( nc 'long' ) ( offset 'long' ) ) ________________________________ From: pharo-project-bounces@lists.gforge.inria.fr [pharo-project-bounces@lists.gforge.inria.fr] on behalf of recursive68@gmail.com [recursive68@gmail.com] Sent: Monday, April 09, 2012 8:04 AM To: pharo-project@lists.gforge.inria.fr Subject: [Pharo-project] FFI definitions - structs Hi, The FFI documentation states the following in terms of defining a C struct fields when defining subclasses of ExternalStructure: ##################################### For example, a color structur might implemented so: * first, create a new class named color in the System Browser (subclass of ExternalStructure) * add class method 'fields' to color maybe, like this: ________________________________ fields ^#((red 'byte') (green 'byte') (blue 'byte')) ########################################## It only mentions simple data types, int, byte etc, as do the all the examples I've been able to find. How do you define pointers to other structs that are fields that are part of the C struct. E.g. C definition: struct Statement { Stmt *stmt; /* statement handle */ Resultset **rsts; /* pointer to resultset list */ .... Thanks
participants (2)
-
recursive68@gmail.com -
Schwab,Wilhelm K