红宝石64位AIX编译正则表达式的限制 [英] Regex limit in ruby 64 bit aix compilation
问题描述
我编红宝石64位在AIX箱。 似乎没有要当我使用一些特定的规律EX pressions在我的code除外的任何问题。 下面是一个例子:
I have compiled ruby 64 bit on an AIX Box. There doesn't seem to be any issue except when I use some specific regular expressions in my code. Here is an example:
/([0-9]){1000}/.match("2")
结果:
RegexpError: too big quantifier in {,}: /([0-9]*){1000}/
当我尝试减少重复次数,似乎工作。
When I try reducing the number of repetitions, it seems to work.
我试图挖成红宝石code。但无法明白其中的道理。 这是一些依赖或限制,我们在AIX / 64位红宝石?
I tried digging into the ruby code. But could not understand the reason. Is this some dependency or restriction that we have in AIX/64 bit ruby?
在此先感谢:)
推荐答案
我几乎立刻就找到了答案。
I almost immediately found the answer.
第一件事是在Ruby源$ C $下被抛出的错误进行搜索。我发现,regex.h负责这一点。
The first thing I did was to search in the ruby source code for the error being thrown. I found that regex.h was responsible for this.
在regex.h中,code流量是这样的:
In regex.h, the code flow is something like this:
/* Maximum number of duplicates an interval can allow. */
#ifndef RE_DUP_MAX
#define RE_DUP_MAX ((1 << 15) - 1)
#endif
现在这里的问题是RE_DUP_MAX。在AIX中,相同的常已在/ usr中定义的某个地方/有。我搜索了一下,发现在
Now the problem here is RE_DUP_MAX. On AIX box, the same constant has been defined somewhere in /usr/include. I searched for it and found in
/usr/include/NLregexp.h
/usr/include/sys/limits.h
/usr/include/unistd.h
我不知道这三个正在使用(最有可能NLregexp.h)。在这些头,RE_DUP_MAX的值已被设置为255!因此,有一个帽放置在正则表达式的重复数!
I am not sure which of the three is being used(most probably NLregexp.h). In these headers, the value of RE_DUP_MAX has been set to 255! So there is a cap placed on the number of repetitions of a regex!
总之,原因是编译取系统定义的值比我们在regex.h定义!
In short, the reason is the compilation taking the system defined value than that we define in regex.h!
因此,问题是解决了重新分配RE_DUP_MAX的regex.h价值 即
Hence the issue was solved by reassigning the value of RE_DUP_MAX in regex.h i.e
# ifdef RE_DUP_MAX
# undef RE_DUP_MAX
# endif
# define RE_DUP_MAX ((1 << 15) - 1)
干杯!
这篇关于红宝石64位AIX编译正则表达式的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!