Dear list,
I have a couple of questions, I started to play with FFI, so these are newbie ones, my intention is to port the ZOOM library. I was there happily writing ExternalStructure's until I found one that kills the VM. Then I've realized I have some basic doubts about FFI: 1) I have this C struct odr Struct Reference =============== int direction int error unsigned char * buf int top int size int pos const unsigned char * bp NMEM mem struct Odr_private * op which I wrote (with a lot of brilliant inspiration) like: ZOOMODR class>> fields " self defineFields " ^ #( (direction 'long') (error 'long') (buf 'char *') (top 'long') (size 'long') (pos 'long') (bp 'char *') (mem 'ZOOMNMem') (odrPrivate 'void *') " ========= HERE ========= " ) I don't know if this exists, the HERE means : I want to avoid to write an external structure for this... Odr_private Struct Reference ===================== struct odr_constack * stack_first struct odr_constack * stack_top const char ** tmp_names_buf int tmp_names_sz struct Odr_ber_tag odr_ber_tag yaz_iconv_t iconv_handle int error_id char element [80] void(* stream_write )(ODR o, void *handle, int type, const char *buf, int len) void(* stream_close )(void *handle) int can_grow int t_class int t_tag int enable_bias int choice_bias int lenlen FILE * print int indent After a look at the fields, I supose I do not care about the contents of that struct. It is ok the ... (odrPrivate 'void *') ... magic line to "stop" these C structs? If not, is there a way to say "I don't care what follows from here" (i.e. pass automagically nil to that pointer) ? 2) Z_NamePlusRecord Struct Reference ================================= Z_DatabaseName * databaseName int which union { Z_External * databaseRecord Z_DiagRec * surrogateDiagnostic Z_FragmentSyntax * startingFragment Z_FragmentSyntax * intermediateFragment Z_FragmentSyntax * finalFragment } u Is there something special to do about an union in the #fields method? Thanks in advance. Hernán |
Hernán Morales Durand wrote:
> I have a couple of questions, I started to play with FFI, so these > are newbie ones, my intention is to port the ZOOM library. I was there > happily writing ExternalStructure's until I found one that kills the > VM. Then I've realized I have some basic doubts about FFI: > ZOOMODR class>> fields > " self defineFields " > ^ #( > (direction 'long') > (error 'long') > (buf 'char *') > (top 'long') > (size 'long') > (pos 'long') > (bp 'char *') > (mem 'ZOOMNMem') > (odrPrivate 'void *') " ========= HERE ========= " > ) > > I don't know if this exists, the HERE means Yes, this will work fine. > 2) > Z_NamePlusRecord Struct Reference > ================================= > Z_DatabaseName * databaseName > int which > union { > Z_External * databaseRecord > Z_DiagRec * surrogateDiagnostic > Z_FragmentSyntax * startingFragment > Z_FragmentSyntax * intermediateFragment > Z_FragmentSyntax * finalFragment > } u > > Is there something special to do about an union in the #fields method? Just declare it as any pointer you'd like and provide methods for the particular conversions you need. Cheers, - Andreas |
On 30-Mar-09, at 10:49 AM, Andreas Raab wrote: > Hernán Morales Durand wrote: >> I have a couple of questions, I started to play with FFI, so these >> are newbie ones, my intention is to port the ZOOM library. I was >> there >> happily writing ExternalStructure's until I found one that kills the >> VM. Then I've realized I have some basic doubts about FFI: You might want to download a copy of Sophie from http://opensophie.org/ and start, hit cmd-period at some point to get a debugger up, then a browser To support os-x navigation services we had to code up quite a bit of ugly structure accessors. No Unions tho -- = = = ======================================================================== John M. McIntosh <[hidden email]> Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
Andreas, John, thank you very much!
Hernán 2009/3/30 John M McIntosh <[hidden email]>: > > On 30-Mar-09, at 10:49 AM, Andreas Raab wrote: > >> Hernán Morales Durand wrote: >>> >>> I have a couple of questions, I started to play with FFI, so these >>> are newbie ones, my intention is to port the ZOOM library. I was there >>> happily writing ExternalStructure's until I found one that kills the >>> VM. Then I've realized I have some basic doubts about FFI: > > You might want to download a copy of Sophie from http://opensophie.org/ > and start, hit cmd-period at some point to get a debugger up, then a browser > > To support os-x navigation services we had to code up quite a bit of ugly > structure accessors. > No Unions tho > > -- > =========================================================================== > John M. McIntosh <[hidden email]> > Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com > =========================================================================== > > > > > |
Free forum by Nabble | Edit this page |