如何从 C 在 Perl 5.12 中创建 qr// ?
这在 5.8 和 5.10 中对我有用,但在 5.12 中,我的代码创建了这个奇怪的非 qr 对象:
# running "print Dumper($regex)"
$VAR1 = bless( do{\(my $o = '')}, 'Regexp' );
而打印 qr// 不是由我的代码创建的看起来像这样:
# running "print Dumper(qr/foo/i)"
$VAR1 = qr/(?i-xsm:foo)/;
我的代码基本上是:
REGEXP *rx = re_compile(pattern, flags);
SV *regex = sv_2mortal(newSVpv("",0));
sv_magic(regex, (SV*)rx, PERL_MAGIC_qr, 0, 0);
stash = gv_stashpv("Regexp", 0);
sv_bless(newRV((SV*)regex), stash);
任何人都知道如何正确创建5.12 中字符串的正则表达式?
This has been working for me in 5.8 and 5.10, but in 5.12 my code creates this weird non-qr object:
# running "print Dumper($regex)"
$VAR1 = bless( do{\(my $o = '')}, 'Regexp' );
Whereas printing a qr// not created by my code looks like this:
# running "print Dumper(qr/foo/i)"
$VAR1 = qr/(?i-xsm:foo)/;
My code is basically:
REGEXP *rx = re_compile(pattern, flags);
SV *regex = sv_2mortal(newSVpv("",0));
sv_magic(regex, (SV*)rx, PERL_MAGIC_qr, 0, 0);
stash = gv_stashpv("Regexp", 0);
sv_bless(newRV((SV*)regex), stash);
Anyone know how to correctly create a regex from a string in 5.12?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢你们让我走上正轨,伙计们,事实证明我想得太多了。他们只是剪掉了魔法线,并没有创建PV。
这就是您在 Perl 5.12 中需要做的全部事情:
Thanks for putting me on the right track, guys, it turns out I was seriously overthinking this. They just cut out the magic line and don't create the PV.
This is all you need to do in Perl 5.12:
看看 这个由霍布斯回答。为了方便阅读,我将其复制如下:
我不是特别喜欢熟悉 XS,但我怀疑您不能再使用标量值来创建正则表达式。
Take a look at the comments in this answer by hobbs. I've copied it below for ease of reading:
I'm not especially familiar with XS, but I suspect you can't use a scalar value any more to create your regex.
Perl 5.12 将正则表达式更改为一流对象,您可以在 如何检查标量中是否包含已编译的正则表达式?。
我不是 XS 人,所以我不知道您需要在代码中更改哪些内容才能使其正常工作。在 perl 源代码中搜索“REGEXP”会显示他们对核心模块进行的修复以使用新内容。
Perl 5.12 changed regexps to be first class objects, which you find as part of the tangential discussion in How do I check if a scalar has a compiled regex it in?.
I'm not an XS person, so I don't know what you need to change in your code to make it work out. Searching for 'REGEXP' in the perl sources shows the fixes they made to the core modules to use the new stuff.