Re: Stringwise comparisons (Inline::C)

[email protected] (David Oswald)
Newsgroups perl.inline
Message-ID <CAKTcQ97qk5vKCBmORXLMD=aFLBsSQEAWo481W+us7tWsCR_4pQ@mail.gmail.com>
On Mon, May 7, 2012 at 6:30 PM, Sisyphus <[email protected]> wrote:
>
> I think a callback to a perl subroutine is what you're after. See the
> perlcall documentation.
>

That demo will actually help when I get this function (in an XS
version of List::BinarySearch):

bsearch_custom { $_[0] cmp $_[1] } $needle, @haystack

But for this:

bsearch_str $needle, @haystack

I wouldn't be calling out to a subroutine implemented in Perl, but
rather, to a Perl internal built-in that does comparisons.

The [email protected] mailing list has been completely silent on my
request for suggestions.  Max Maischein (Corion) has been helpful,
with this suggestion over at PerlMonks:

        Corion says: I think you'll need to call the appropriate OP,
        which seems (wildly guessing) to be pp_scmp in pp.c.
        Or appropriate the code from there.

I've looked at pp.c (Perl internals) and I think he's right for the
case of 'cmp'.  Looks like I just need to figure out how to use the
undocumented function, and need to locate somewhere in that code the
'lt', 'gt', and 'eq' operators.

Once I figure it out it actually may make a good addition to the
Inline::C cookbook.  Any existing example code that shows how easy it
is to pass Perl strings as C-strings is glossing over the fact that as
soon as the user's data is utf8 encoded the code breaks.



--

David Oswald
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.