returning a string from a primitive

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

returning a string from a primitive

Diman Todorov-3
Hello,
I am currently struggling to return a string from a virtual machine  
primitive. The only example derived from SmarySyntaxInterpreterPlugin  
I was able to find in the Squeak sources is in the  
InternetConfigPlugin (in primitiveGetStringKeyedBy:). This Plugin  
instantiates a new string object and explicitly iterates over the  
string to copy it to squeak. Isn't there a more elegant way to return  
a string from a c function?

cheers
Diman


Reply | Threaded
Open this post in threaded view
|

Re: returning a string from a primitive

Bert Freudenberg
On Mar 5, 2007, at 17:14 , Diman Todorov wrote:

> Hello,
> I am currently struggling to return a string from a virtual machine  
> primitive. The only example derived from  
> SmarySyntaxInterpreterPlugin I was able to find in the Squeak  
> sources is in the InternetConfigPlugin (in  
> primitiveGetStringKeyedBy:). This Plugin instantiates a new string  
> object and explicitly iterates over the string to copy it to  
> squeak. Isn't there a more elegant way to return a string from a c  
> function?

You have to copy the data into a proper oop in Squeak's object  
memory. What "more elegant way" to do that are you proposing? You can  
write a helper function of course. But eventually it will have to copy.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: returning a string from a primitive

johnmci
Well of course memcpy work *better* versus writing a loop and doing  
it yourself.
memcpy might even be optimized for your hardware too.
Of course make sure you don't copy a few too many bytes, or bytes to  
the wrong place.

There is also the ExernalAddress class, but I've not played with  
that, I guess you could make one of those

On Mar 5, 2007, at 8:23 AM, Bert Freudenberg wrote:

> On Mar 5, 2007, at 17:14 , Diman Todorov wrote:
>
>> Hello,
>> I am currently struggling to return a string from a virtual  
>> machine primitive. The only example derived from  
>> SmarySyntaxInterpreterPlugin I was able to find in the Squeak  
>> sources is in the InternetConfigPlugin (in  
>> primitiveGetStringKeyedBy:). This Plugin instantiates a new string  
>> object and explicitly iterates over the string to copy it to  
>> squeak. Isn't there a more elegant way to return a string from a c  
>> function?
>
> You have to copy the data into a proper oop in Squeak's object  
> memory. What "more elegant way" to do that are you proposing? You  
> can write a helper function of course. But eventually it will have  
> to copy.
>
> - Bert -
>
>
>

--
========================================================================
===
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===



Reply | Threaded
Open this post in threaded view
|

Re: returning a string from a primitive

Bert Freudenberg
ExternalAddress is FFI only.

- Bert -

On Mar 5, 2007, at 22:15 , John M McIntosh wrote:

> Well of course memcpy work *better* versus writing a loop and doing  
> it yourself.
> memcpy might even be optimized for your hardware too.
> Of course make sure you don't copy a few too many bytes, or bytes  
> to the wrong place.
>
> There is also the ExernalAddress class, but I've not played with  
> that, I guess you could make one of those
>
> On Mar 5, 2007, at 8:23 AM, Bert Freudenberg wrote:
>
>> On Mar 5, 2007, at 17:14 , Diman Todorov wrote:
>>
>>> Hello,
>>> I am currently struggling to return a string from a virtual  
>>> machine primitive. The only example derived from  
>>> SmarySyntaxInterpreterPlugin I was able to find in the Squeak  
>>> sources is in the InternetConfigPlugin (in  
>>> primitiveGetStringKeyedBy:). This Plugin instantiates a new  
>>> string object and explicitly iterates over the string to copy it  
>>> to squeak. Isn't there a more elegant way to return a string from  
>>> a c function?
>>
>> You have to copy the data into a proper oop in Squeak's object  
>> memory. What "more elegant way" to do that are you proposing? You  
>> can write a helper function of course. But eventually it will have  
>> to copy.
>>
>> - Bert -