Re: Passing scalars to C functions
[email protected] (Reinhard Pagitsch)
| Newsgroups | perl.xs |
|---|---|
| Message-ID | <[email protected]> |
Josef Moellers wrote:
> Reinhard Pagitsch wrote:
>> Josef Moellers wrote:
>>
>>> Hi,
>>>
>>> I'm fairly new to the XS business. I have managed to get the skeleton
>>> up (h2xs) and have also managed to write short functions that have
>>> ints as arguments and return strings, but I'd like to pass a full
>>> Perl scalar (my $cdb = pack('C*', 0x12, 0, 0, 0, 128, 0);) and
>>> retrieve the length (6) and the bytes themselves in the C function
>>> and also return such a scalar.
>>>
>>> How do I do that?
>>>
>>> Thanks,
>>>
>>> Josef
>>>
>>>
>>
>>
>> Did you looked at the eval_* functions in perlapi.pod?
>>
>> eval_pv
>>
>> Tells Perl to eval the given string and return an SV* result.
>> NOTE: the perl_ form of this function is deprecated.
>> SV* eval_pv(const char* p, I32 croak_on_error)
>>
>> eval_sv
>>
>> Tells Perl to eval the string in the SV.
>> NOTE: the perl_ form of this function is deprecated.
>> I32 eval_sv(SV* sv, I32 flags)
>
> No,
>
> but some kind soul already pointed me at perlguts and there I found a
> reference to SvPV() which does exactly what I want:
>
> void
> scsi_cmd_in(fh, cmd, data_cnt)
> PerlIO *fh
> SV *cmd
> int data_cnt
> PREINIT:
> ...
> unsigned char *scsi_cmd;
> STRLEN cmd_len;
> PPCODE:
> ...
> scsi_cmd = SvPV(cmd, cmd_len);
>
> Josef
>
Hm, than I misunderstood you, I guess.
regards,
Reinhard