External Interface

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

External Interface

Michael Gross-4

The following was generated by the Interface builder …..

 

CALL3:parm1 with:parm2 with:parm3 with:parm4with:parm5with:parm6:withparm7

 

              <C: void CALL3(char parm1[80], double * parm2, char * parm3, double parm4[100], char parm5[100][41], char parm6[100], double parm7[100])>

              ^self externalAccessFailedWith: _errorCode

 

I am having trouble setting up this call in Smalltalk.

I know what I need to send in Parm1 but, I am not sure about the others.

For example Parm5, do I need to send an array or can I send a string.

 

 

Thanks!!!!

 

 

Mike Gross


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: External Interface

Travis Griggs-4

On May 18, 2011, at 10:07 AM, Michael Gross wrote:

The following was generated by the Interface builder …..
 
CALL3:parm1 with:parm2 with:parm3 with:parm4with:parm5with:parm6:withparm7
 
              <C: void CALL3(char parm1[80], double * parm2, char * parm3, double parm4[100], char parm5[100][41], char parm6[100], double parm7[100])>
              ^self externalAccessFailedWith: _errorCode
 
I am having trouble setting up this call in Smalltalk.
I know what I need to send in Parm1 but, I am not sure about the others.
For example Parm5, do I need to send an array or can I send a string.
 

parm5 is an array with 100 character arrays of size 41 in them. This isn't something that can be simply marshaled by sending in a string. What you need to pass is a pointer to a char pointer.

Presumably you have an array of Smalltalk strings to pass as parm5, one way to do it would be:

strings := #('Travis' 'Dan' 'Michael').
stringPointers := strings collect: [:each | each gcCopyToHeapEncoding: #UTF8]. 
arrayPointer := CIntegerType char pointerType gcMalloc: strings size.
stringPointers keysAndValuesDo: [:index :pointer | arrayPointer at: index - 1 put: pointer].

and then use arrayPointer as the argument for that associated with:.

HTH

The others, you can just pass strings to, since they're just char*'s basically.

--
Travis Griggs
Objologist
"I did not have time to write you a short program, so I wrote you a long one instead."


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: External Interface

Travis Griggs-4

On May 18, 2011, at 10:49 AM, Travis Griggs wrote:


On May 18, 2011, at 10:07 AM, Michael Gross wrote:

The following was generated by the Interface builder …..
 
CALL3:parm1 with:parm2 with:parm3 with:parm4with:parm5with:parm6:withparm7
 
              <C: void CALL3(char parm1[80], double * parm2, char * parm3, double parm4[100], char parm5[100][41], char parm6[100], double parm7[100])>
              ^self externalAccessFailedWith: _errorCode
 
I am having trouble setting up this call in Smalltalk.
I know what I need to send in Parm1 but, I am not sure about the others.
For example Parm5, do I need to send an array or can I send a string.
 

parm5 is an array with 100 character arrays of size 41 in them. This isn't something that can be simply marshaled by sending in a string. What you need to pass is a pointer to a char pointer.

Presumably you have an array of Smalltalk strings to pass as parm5, one way to do it would be:

strings := #('Travis' 'Dan' 'Michael').
stringPointers := strings collect: [:each | each gcCopyToHeapEncoding: #UTF8]. 
arrayPointer := CIntegerType char pointerType gcMalloc: strings size.
stringPointers keysAndValuesDo: [:index :pointer | arrayPointer at: index - 1 put: pointer].

and then use arrayPointer as the argument for that associated with:.

HTH

The others, you can just pass strings to, since they're just char*'s basically.


Argh, I'm on drugs. It's why I'm better off lurking here these days. The above is totally wrong, and mucho gracias to Michael for gently reminding me off channel.

parm5 is the same as parm5[4100]. It's basically one big long string, with sub ranges of size 41 (I may have this backward, it may be 41 subranges of size 100, I'll assume the first). 

I'd do something like this to get an object I could pass as parm5

strings := #('I' 'Love' 'C').
bytes := strings
collect: [:each | each asByteArray , (ByteArray new: 41 - each size)].
flattened := bytes fold: [:a :b | a , b]

You get to worry about strings that are bigger than 40 (I'm guessing the extra 1 is for the null terminator), as well as encoding issues. Pass flattened as your argument.

Question is how long it will be before someone pings me and tells me I've got this wrong too. :)

--
Travis Griggs
Objologist
"The project was so plagued by politics and ego that when the engineers requested technical oversight, our manager hired a psychologist instead." -- Ron Avitzur


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: External Interface

Michael Gross-4

Would the double array’s be the similar?

I copied some code I saw in the DLL C connect manual.

 

copyToHeap

| floatArrayPtr arraySize tempPtr |

arraySize := floatArrayInstVar size.

floatArrayPtr := CLimitedPrecisionRealType float malloc: arraySize.

tempPtr := floatArrayPtr copy.

1 to: arraySize do: [:i |

tempPtr contents: (floatArrayInstVar at: i).

tempPtr += 1].

^floatArrayPtr

 

 

I am using this for parm4 and Smalltalk keeps barfing with a CTypeError when calling the C object.

 

From: Travis Griggs [mailto:[hidden email]]
Sent: Wednesday, May 18, 2011 2:32 PM
To: Michael Gross; [hidden email] NC
Subject: Re: [vwnc] External Interface

 

 

On May 18, 2011, at 10:49 AM, Travis Griggs wrote:



 

On May 18, 2011, at 10:07 AM, Michael Gross wrote:



The following was generated by the Interface builder …..

 

CALL3:parm1 with:parm2 with:parm3 with:parm4with:parm5with:parm6:withparm7

 

              <C: void CALL3(char parm1[80], double * parm2, char * parm3, double parm4[100], char parm5[100][41], char parm6[100], double parm7[100])>

              ^self externalAccessFailedWith: _errorCode

 

I am having trouble setting up this call in Smalltalk.

I know what I need to send in Parm1 but, I am not sure about the others.

For example Parm5, do I need to send an array or can I send a string.

 

 

parm5 is an array with 100 character arrays of size 41 in them. This isn't something that can be simply marshaled by sending in a string. What you need to pass is a pointer to a char pointer.

 

Presumably you have an array of Smalltalk strings to pass as parm5, one way to do it would be:

 

strings := #('Travis' 'Dan' 'Michael').

stringPointers := strings collect: [:each | each gcCopyToHeapEncoding: #UTF8]. 

arrayPointer := CIntegerType char pointerType gcMalloc: strings size.

stringPointers keysAndValuesDo: [:index :pointer | arrayPointer at: index - 1 put: pointer].

 

and then use arrayPointer as the argument for that associated with:.

 

HTH

 

The others, you can just pass strings to, since they're just char*'s basically.

 

 

Argh, I'm on drugs. It's why I'm better off lurking here these days. The above is totally wrong, and mucho gracias to Michael for gently reminding me off channel.

 

parm5 is the same as parm5[4100]. It's basically one big long string, with sub ranges of size 41 (I may have this backward, it may be 41 subranges of size 100, I'll assume the first). 

 

I'd do something like this to get an object I could pass as parm5

 

strings := #('I' 'Love' 'C').

bytes := strings

                                    collect: [:each | each asByteArray , (ByteArray new: 41 - each size)].

flattened := bytes fold: [:a :b | a , b]

 

You get to worry about strings that are bigger than 40 (I'm guessing the extra 1 is for the null terminator), as well as encoding issues. Pass flattened as your argument.

 

Question is how long it will be before someone pings me and tells me I've got this wrong too. :)

 

--

Travis Griggs

Objologist

"The project was so plagued by politics and ego that when the engineers requested technical oversight, our manager hired a psychologist instead." -- Ron Avitzur

 


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc