Damn you LPVOID.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Damn you LPVOID.

Sean Malloy-2
Chris, you were right. LPVOID is a pain in the ass.

Here's my callback function.

callback := [ :length :fieldValues :fieldNames |
    "length is SmallInteger"
    "fieldValues and fieldNames are LPVOID"
].

now, I KNOW that they are both type of char**/sbyte**

its a pointer to an array of pointers to strings. My problem is everything
I've tried to convert that lpvoid into an object I can call at: on, is
fruitless.. I mean, I want my code to look like this:

columnNames := Dictionary new.
callback := [ :length :fieldValues :fieldNames |
    "length is SmallInteger"
    "values and fields are LPVOID"
    (columnNames size = 0) ifTrue: [
        1 to: length do: [ :ea |
            columnNames at: (String fromAddress: (fieldNames at: ea)) put:
ea.
        ].
    ].
].

ala C# code:
internal unsafe int SqliteCallback (ref object o, int argc, sbyte **argv,
sbyte **colnames)
{
    if (column_names.Count == 0) {
        for (int i = 0; i < argc; i++) {
            string col = new String (colnames[i]);
            column_names[col.ToLower ()] = i;
        }
    }
    ...
}

can anyone offer any insight into this? Curse the LPVOID.


Reply | Threaded
Open this post in threaded view
|

Re: Damn you LPVOID.

Sean Malloy-2
> columnNames := Dictionary new.
> callback := [ :length :fieldValues :fieldNames |
>     "length is SmallInteger"
>     "values and fields are LPVOID"
>     (columnNames size = 0) ifTrue: [
>         1 to: length do: [ :ea |
>             columnNames at: (String fromAddress: (fieldNames at: ea)) put:
> ea.
>         ].
>     ].
> ].

columnNames := Dictionary new.
callback := [ :columns :values :names |
| namesArray valuesArray |
valuesArray := PointerArray fromAddress: values bytes length: columns
elementClass: String.
namesArray := PointerArray fromAddress: names bytes length: columns
elementClass: String.
(columnNames size = 0) ifTrue: [
  1 to: columns do: [ :ea |
   columnNames at: (namesArray at: ea) put: ea.
  ].
 ].
].

Holy shit that works! but it seems like a lot of bloody code. Is there
something more compact than having to create new temporary arrays?