in reply to Re: Pointer to null terminated string
in thread Pointer to null terminated string

Well, actually I got a number, which is a pointer no null terminated string.

I know that Perl doesn't have pointers, but the function, returns this value, is wrote with XS glue.

And yet one thing, now I'm not sure that the function returns me pointer to null terminated string, probably it's pointer to SCALAR. Although I'm sure I got just pointer.
  • Comment on Re: Re: Pointer to null terminated string

Replies are listed 'Best First'.
Re: Re: Re: Pointer to null terminated string
by jmcnamara (Monsignor) on Feb 18, 2003 at 09:33 UTC

    If the function returns a 4 byte pointer then you should be able to do this:
    $str = unpack "p", some_func();

    If the function returns a pointer to a, known length, packed structure you can do this (where 32 is used as an example):

    $struct = unpack "P32", some_func();

    You will then probably need to unpack the structure to get at the members.

    Referring to the particular XS API or source should tell you what is being returned.

    --
    John.

Re: Re: Re: Pointer to null terminated string
by xmath (Hermit) on Feb 18, 2003 at 09:35 UTC
    Here you go:

    $string = unpack "p", pack "i", $pointer;

    if $pointer is a pointer to a cstring, represented as integer, then $string should contain the data.

    And if it's not, enjoy the core dump ;-)