help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] C Callouts issue


From: Stephen Woolerton
Subject: [Help-smalltalk] C Callouts issue
Date: Tue, 09 Jul 2013 13:26:12 +1200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7

Hi everyone,

I've been writing a tutorial on C Callouts from GNU Smalltalk, and am
trying to get a couple of C callout scenarios to work. I'm having
difficulty when there is an argument in the callout, which is a
pointer.

Given a C header of :-
----
struct       Note {
   int         id;
   char*       memo;     //variable length
   long        modified; //timestamp
};
extern struct Note* newBlankNote(unsigned int *resultCode);
extern unsigned int initializeNote(struct Note *note);
----


I created a Smalltalk class with mappings as follows:
----
CStruct subclass: CNote [
        <declaration: #( (#id  #int)
                         (#memomemo #string)
                         (#modified #long))>

  CNote class >> newBlankNote: retVal [
     <cCall: 'newBlankNote' returning: #{CNote} args: #(#{CObject})>
  ]
  initializeNote: aNote [
     <cCall: 'initializeNote' returning: #uint args: (#self)>
  ]
]
----

And inside the smalltalk script, I have this...
| note retVal |
retVal := 0.
note := CNote newBlankNote: retVal.


The error I'm receiving is...
./ccall2.st:31: Attempt to pass an instance of SmallInteger as a void *
Object: CFunctionDescriptor new: 1 "<0x7f935dbc4a10>" error: primitive
operation failed
SystemExceptions.PrimitiveFailed(Exception)>>signal (ExcHandling.st:254)
SystemExceptions.PrimitiveFailed class(Exception class)>>signal
(ExcHandling.st:151)
CFunctionDescriptor(Object)>>primitiveFailed (Object.st:1349)
CFunctionDescriptor(CCallable)>>callNoRetryFrom:into: (CCallable.st:179)
CFunctionDescriptor(CCallable)>>callInto: (CCallable.st:166)
CNote class>>newBlankNote: (ccall2.st:1)
UndefinedObject>>executeStatements (ccall2.st:30)
---------------

If I modify the scripts so that retVal is a standard "unsigned int" and
not a pointer, this callout works.

Also: if I try to run this code...
| note retVal |
note := CNote new.
retVal := note initializeNote.

I'm getting a similar error, namely...
./ccall2.st:36: Attempt to pass an instance of ValueHolder as a void *
Object: CFunctionDescriptor new: 1 "<0x7f935dbc6aa0>" error: primitive
operation failed
SystemExceptions.PrimitiveFailed(Exception)>>signal (ExcHandling.st:254)
SystemExceptions.PrimitiveFailed class(Exception class)>>signal
(ExcHandling.st:151)
CFunctionDescriptor(Object)>>primitiveFailed (Object.st:1349)
CFunctionDescriptor(CCallable)>>callNoRetryFrom:into: (CCallable.st:179)
CFunctionDescriptor(CCallable)>>callInto: (CCallable.st:166)
CNote>>initializeNote (ccall2.st:1)
UndefinedObject>>executeStatements (ccall2.st:35)

-----------------
The full code (C library, C test program, and smalltalk script) is
viewable at this URL: http://artinamessage.wordpress.com/2013/07/07/gnu-smalltalk-with-c-callouts-2/

I'm using GNU Smalltalk 3.2.5 on a copy of Gentoo Linux, and if someone could be so kind as to assist me finding the problem, this will be much appreciated.

Regards
Stephen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]