primitives and corrections/arrays?
Ragnar Hojland Espinosa
ragnar at linalco.com
Mon Oct 20 11:50:52 UTC 2003
On Thu, Oct 16, 2003 at 09:09:49AM -0700, Ned Konz wrote:
> On Thursday 16 October 2003 7:53 am, Ragnar Hojland Espinosa wrote:
> > 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 assume you've read my "Writing Plugins" document, and Andy Greenberg's
> plugins tutorial. If not, look at:
> http://minnow.cc.gatech.edu/squeak/370
Right.
> And that you're using the SmartSyntaxInterpreterPlugin.
Right again.
> > 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).
>
> Is someAttrs *really* a ByteArray? That is, did you pack the attrs into it? Or
> is it an Array of String or something?
No. I tried also Array, but didnt work. Its an Array of Strings.
|a|
a _ Array new: 4.
a at: 2 put: 'hello'.
a at: 1 put: 'world'.
a at: 3 put: 'pluginia'.
a at: 4 put: '3423'.
LDAPPlugin primLDAPSearch: a.
as parameters: (#Array):
buflen _ someAttrs size.
self cCode: 'fprintf (stderr, "len %d\n", buflen)'.
says len is 0.. so I must be doing something really wrong.
> It is simpler to pack the strings into a ByteArray and then strdup them, but
> your code isn't doing that (apparently). Instead, it's reading bytes out of a
> byte array and then trying to duplicate them.
Yeah, thats what I'm doing. Unless there is no way, I'd prefer to
"mirror" the structures in C instead of packing and unpacking.
> > buflen _ someAttrs size.
>
> buflen := interpreterProxy sizeOfSTArrayFromCPrimitive: someAttrs.
>
> > self cCode: 'attrs = (char**) malloc (buflen)'.
>
> No. I would think you'd need to:
> attrs = (char**) malloc(buflen * sizeof(char*));
> or
> attrs = (char**) calloc(buflen, sizeof(char*));
I get too distracted by squeak.. :)
> > i _ 0.
> >
> > 1 to: (someAttrs size) do: [ :idx |
> > mystr _ someAttrs at: idx.
> > buflen _ interpreterProxy byteSizeOf: mystr cPtrAsOop.
>
> Yeah, but it's not a string; it's a character if you have a ByteArray.
I was expecting it to be a string..
--
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
|