On Mon, May 7, 2012 at 6:30 PM, Sisyphus <sisyph...@optusnet.com.au> 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 perl...@perl.org 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
daosw...@gmail.com

Reply via email to