primitives and corrections/arrays?
Ragnar Hojland Espinosa
ragnar at linalco.com
Thu Oct 16 14:53:15 UTC 2003
I'm trying to pass a collection/array of strings through a primitive,
but its not working.. I'm having trouble at accessing the data in the
collection. Example code pointers welcome.. I'm stuck :(
I guess I'll find the same problem when trying to populate an array
from C back to squeak..
BTW, I'm putting together some rather noobish notes on plugin writings
on http://minnow.cc.gatech.edu/squeak/3408 FWIW..
primitiveLDAPSearch: someAttrs
| i buffer buflen attrs mystr |
self var: #buffer declareC: 'char buffer[8192]'.
self var: #buflen declareC: 'int buflen'.
self var: #attrs declareC: 'char** attrs'.
self var: #i declareC: 'int i'.
self primitive: 'primitiveLDAPSearch' parameters: #(ByteArray).
buflen _ someAttrs size.
self cCode: 'attrs = (char**) malloc (buflen)'.
i _ 0.
1 to: (someAttrs size) do: [ :idx |
mystr _ someAttrs at: idx.
buflen _ interpreterProxy byteSizeOf: mystr cPtrAsOop.
self cCode: 'strncpy (buffer, mystr, buflen)'.
buffer at: buflen put: 0.
self cCode: 'attrs[i++] = strdup(buffer)'.
].
self cCode: 'LDAP_Search (attrs)'.
^ true asOop: Boolean
I also tried the following, as the do: wasnt vorking very well..
self primitive: 'primitiveLDAPSearch' parameters: #(Oop Array).
buflen _ someAttrs size.
self cCode: 'attrs = (char**) malloc (buflen)'.
i _ 0.
someAttrs do: [:each |
buflen _ interpreterProxy byteSizeOf: each cPtrAsOop.
self cCode: 'strncpy (buffer, each, buflen)'.
buffer at: buflen put: 0.
self cCode: 'attrs[i++] = strdup(each)'.
].
self cCode: 'LDAP_Search (attrs)'.
--
Ragnar Hojland - Project Manager
Linalco "Specialists in Linux and Free Software"
http://www.linalco.com Tel: +34-91-5970074 Fax: +34-91-5970083
More information about the Squeak-dev
mailing list
|