[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Pointer of pointer with Ruby/DL

Guillaume Marcais

12/8/2004 3:13:00 PM

I have the following C prototype:

int auth(char *user, char *passwd, char **msgp);

I pass user and passwd, and I get in response 0 or 1 for success or
failure and a message in *msgp.

How can i call this function from Ruby using Ruby/DL? So far I did the
following:

<code>
module Auth
extend DL::Importable
dlload "./auth.so"
extern "int auth(char *, char *, char **)"
end

msgp = [0].pack('L').to_ptr
r = Tenant2Auth.public_tenant2_auth_pap_auth("coucou", "titi", msgp)
</code>

I get the correct result in 'r'. But how do I get access to the string
in *msgp?

I guess I don't yet have a good grasp on pointer dereferencing with
Ruby/DL.

Anyone?

Guillaume.



2 Answers

Kent Sibilev

12/8/2004 5:25:00 PM

0

Try this:
msgp = DL.malloc(DL.sizeof('P'))
r = Tenant2Auth.public_tenant2_auth_pap_auth("coucou", "titi", msgp.ref)
puts msgp.to_s

Cheers,
Kent.
On Dec 8, 2004, at 10:13 AM, Guillaume Marcais wrote:

> I have the following C prototype:
>
> int auth(char *user, char *passwd, char **msgp);
>
> I pass user and passwd, and I get in response 0 or 1 for success or
> failure and a message in *msgp.
>
> How can i call this function from Ruby using Ruby/DL? So far I did the
> following:
>
> <code>
> module Auth
> extend DL::Importable
> dlload "./auth.so"
> extern "int auth(char *, char *, char **)"
> end
>
> msgp = [0].pack('L').to_ptr
> r = Tenant2Auth.public_tenant2_auth_pap_auth("coucou", "titi", msgp)
> </code>
>
> I get the correct result in 'r'. But how do I get access to the string
> in *msgp?
>
> I guess I don't yet have a good grasp on pointer dereferencing with
> Ruby/DL.
>
> Anyone?
>
> Guillaume.
>
>



Guillaume Marcais

12/9/2004 3:18:00 AM

0

Le 8 déc. 04, à 12:25, Kent Sibilev a écrit :

> Try this:
> msgp = DL.malloc(DL.sizeof('P'))
> r = Tenant2Auth.public_tenant2_auth_pap_auth("coucou", "titi",
> msgp.ref)
> puts msgp.to_s

Works great, thanks.

Guillaume.

> Cheers,
> Kent.
> On Dec 8, 2004, at 10:13 AM, Guillaume Marcais wrote:
>
>> I have the following C prototype:
>>
>> int auth(char *user, char *passwd, char **msgp);
>>
>> I pass user and passwd, and I get in response 0 or 1 for success or
>> failure and a message in *msgp.
>>
>> How can i call this function from Ruby using Ruby/DL? So far I did the
>> following:
>>
>> <code>
>> module Auth
>> extend DL::Importable
>> dlload "./auth.so"
>> extern "int auth(char *, char *, char **)"
>> end
>>
>> msgp = [0].pack('L').to_ptr
>> r = Tenant2Auth.public_tenant2_auth_pap_auth("coucou", "titi", msgp)
>> </code>
>>
>> I get the correct result in 'r'. But how do I get access to the string
>> in *msgp?
>>
>> I guess I don't yet have a good grasp on pointer dereferencing with
>> Ruby/DL.
>>
>> Anyone?
>>
>> Guillaume.
>>
>>
>
>