FAQ
I've read the Jenness/Cozens book and the various perldocs on XS, but I
can find no hint of how to use the regex engine from XS.

What I want to do is accept an SV containing either qr/.../ or regular
string, and then check whether the specified regex matches the contents of
another SV.

If someone knows of a module that does this in XS, I'd be happy to be
pointed at it. Otherwise more explicit hints are welcome ;)

Poking through the internals, I see the Perl_pregexec function in
regexec.c, which seems like a likely start, but what the heck are the
arguments? What's screamer? And how do I turn an SV into a regexp
struct?

Help!


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Search Discussions

  • Nick Ing-Simmons at Jan 19, 2003 at 4:32 pm

    Dave Rolsky writes:
    I've read the Jenness/Cozens book and the various perldocs on XS, but I
    can find no hint of how to use the regex engine from XS.
    It is tricky and risky - trying to use perl's regex engine
    to subsitute for Tcl's is one of the recurring porting issues
    with perl/Tk.

    The main snag (as I recall) is that in perl you need an "OP" in order
    to call some of regex engine.
    What I want to do is accept an SV containing either qr/.../ or regular
    string, and then check whether the specified regex matches the contents of
    another SV.

    If someone knows of a module that does this in XS, I'd be happy to be
    pointed at it. Otherwise more explicit hints are welcome ;)

    Poking through the internals, I see the Perl_pregexec function in
    regexec.c, which seems like a likely start, but what the heck are the
    arguments? What's screamer? And how do I turn an SV into a regexp
    struct?

    Help!
    Unless you _really_ need this I strongly recommend writing the
    "leaf" functions for this in perl and perl_call_sv()-ing them from your
    XS code.

    Unless Hugo wants to give us a clean interface?



    -dave

    /*=======================
    House Absolute Consulting
    www.houseabsolute.com
    =======================*/
    --
    Nick Ing-Simmons
    http://www.ni-s.u-net.com/
  • Dave Rolsky at Jan 19, 2003 at 5:34 pm

    On Sun, 19 Jan 2003, Nick Ing-Simmons wrote:

    Dave Rolsky <autarch@urth.org> writes:
    I've read the Jenness/Cozens book and the various perldocs on XS, but I
    can find no hint of how to use the regex engine from XS.
    It is tricky and risky - trying to use perl's regex engine
    to subsitute for Tcl's is one of the recurring porting issues
    with perl/Tk.

    The main snag (as I recall) is that in perl you need an "OP" in order
    to call some of regex engine.
    Sigh ...

    I was afraid someone would say something like that.
    Unless you _really_ need this I strongly recommend writing the
    "leaf" functions for this in perl and perl_call_sv()-ing them from your
    XS code.
    Well, the main reason Ilya and I are working on this XS code (for
    Params::Validate) is to speed it up. Calling back and forth to Perl
    unnecessarily somewhat defeats the purpose.
    Unless Hugo wants to give us a clean interface?
    That'd be cool for the future.

    One thing I'd say in general about XS is that it just doesn't expose
    enough of Perl's functionality, at least not in what's documented. And I
    include the Jenness/Cozens book in that documentation (good book, but it
    doesn't cover everthing I _want_ to do with XS).

    For example, in the Params::Validate XS code we need to find out what
    package the caller is in. Now, obviously Perl can do this, because we
    have the caller() function. Ilya somehow found the CopSTASHPV macro, and
    then I found an equivalent way to do this for Perl 5.00503, but it's all a
    nasty hack since this isn't a documented interface.

    It seems to me that ideally you could call any Perl function from XS. I
    realize that's extremely difficult, but there must be some subset of
    Perl's functionality easily available from XS that isn't documented (like
    CopSTASHPV).


    -dave

    /*=======================
    House Absolute Consulting
    www.houseabsolute.com
    =======================*/
  • Nick Ing-Simmons at Jan 19, 2003 at 5:56 pm

    Dave Rolsky writes:
    On Sun, 19 Jan 2003, Nick Ing-Simmons wrote:

    Dave Rolsky <autarch@urth.org> writes:
    I've read the Jenness/Cozens book and the various perldocs on XS, but I
    can find no hint of how to use the regex engine from XS.
    It is tricky and risky - trying to use perl's regex engine
    to subsitute for Tcl's is one of the recurring porting issues
    with perl/Tk.

    The main snag (as I recall) is that in perl you need an "OP" in order
    to call some of regex engine.
    Sigh ...

    I was afraid someone would say something like that.
    It does not have to be an OP that is linked anywhere - tkGlue.c
    does do that, and it worked fine till UTF-8 stuff came along.
    Now something is not-quite-right :-(
    Unless you _really_ need this I strongly recommend writing the
    "leaf" functions for this in perl and perl_call_sv()-ing them from your
    XS code.
    Well, the main reason Ilya and I are working on this XS code (for
    Params::Validate) is to speed it up. Calling back and forth to Perl
    unnecessarily somewhat defeats the purpose.
    Unless Hugo wants to give us a clean interface?
    That'd be cool for the future.

    One thing I'd say in general about XS is that it just doesn't expose
    enough of Perl's functionality, at least not in what's documented.
    Depends what you consider documented :-)
    XS pods document what "we" are reasonably happy maintaining as an
    interface.

    If you want to you can get at _anything_ via an XS hook.
    And I
    include the Jenness/Cozens book in that documentation (good book, but it
    doesn't cover everthing I _want_ to do with XS).

    For example, in the Params::Validate XS code we need to find out what
    package the caller is in. Now, obviously Perl can do this, because we
    have the caller() function. Ilya somehow found the CopSTASHPV macro, and
    then I found an equivalent way to do this for Perl 5.00503, but it's all a
    nasty hack since this isn't a documented interface.
    I agree caller() is one of several things that are easy in perl, but
    code that implements them is "inline" in some pp_xxxx() and not
    easy to re-use from C/XS.
    It seems to me that ideally you could call any Perl function from XS. I
    realize that's extremely difficult, but there must be some subset of
    Perl's functionality easily available from XS that isn't documented (like
    CopSTASHPV).
    You can get at anything - but calling pp_caller() for example effectively
    calls back into perl with associated stack twiddling.


    -dave

    /*=======================
    House Absolute Consulting
    www.houseabsolute.com
    =======================*/
    --
    Nick Ing-Simmons
    http://www.ni-s.u-net.com/
  • Hv at Feb 11, 2003 at 12:53 am
    Nick Ing-Simmons wrote:
    :Dave Rolsky <autarch@urth.org> writes:
    :>I've read the Jenness/Cozens book and the various perldocs on XS, but I
    :>can find no hint of how to use the regex engine from XS.
    [...]
    :Unless you _really_ need this I strongly recommend writing the
    :"leaf" functions for this in perl and perl_call_sv()-ing them from your
    :XS code.
    :
    :Unless Hugo wants to give us a clean interface?

    I'd love to, but it isn't likely to happen soon.

    Hugo

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedJan 19, '03 at 1:53a
activeFeb 11, '03 at 12:53a
posts5
users3
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase