develooper Front page | perl.perl5.porters | Postings from September 2010

[PATCH] Extract regcurly from regcomp.c and convert it to staticinline

Thread Next
From:
Andy Dougherty
Date:
September 10, 2010 13:18
Subject:
[PATCH] Extract regcurly from regcomp.c and convert it to staticinline
Message ID:
alpine.DEB.2.00.1009101543220.24563@fractal.phys.lafayette.edu
This patch extracts regcurly from regcomp.c and converts it to static 
inline in a new file to be included by regcomp.c and toke.c.

It required 'make regen', which I did as part of this patch.  (Only later 
did I read the part in perlrepository.pod telling me not to, but I confess 
I don't understand the logic of committing a known-broken state, but 
that's neither here nor there anyway, since I'm posting this for 
discussion, not for direct application).

Anyway, this patch tries to make use of the new Configure 
PERL_STATIC_INLINE probe.  I haven't tested performance with this patch at 
all.  

One other point worth considering:  I couldn't quite figure out the 
correct flags to get embed.pl to handle this function correctly.  I ended 
up calling it a 'macro' since I was too lazy to add static inline support 
to embed.pl today.

Tests, comments on the overall strategy and approach, and benchmarks 
welcome.

---
 MANIFEST    |    1 +
 embed.fnc   |    5 ++++-
 embed.h     |   12 ++++++------
 global.sym  |    1 -
 proto.h     |   15 ++++++++-------
 re_static.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 regcomp.c   |   27 ++-------------------------
 toke.c      |    1 +
 8 files changed, 71 insertions(+), 40 deletions(-)
 create mode 100644 re_static.c

diff --git a/MANIFEST b/MANIFEST
index 7900589..fb77a66 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4248,6 +4248,7 @@ regen.pl			Run all scripts that (re)generate files
 regexec.c			Regular expression evaluator
 regexp.h			Public declarations for the above
 regnodes.h			Description of nodes of RE engine
+re_static.c			Regex-related static functions
 run.c				The interpreter loop
 runtests.SH			A script that generates runtests
 scope.c				Scope entry and exit code
diff --git a/embed.fnc b/embed.fnc
index a4382a3..22f1e27 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -165,7 +165,6 @@ npR	|MEM_SIZE|malloc_good_size	|size_t nbytes
 
 AnpR	|void*	|get_context
 Anp	|void	|set_context	|NN void *t
-EXpRnPM	|I32	|regcurly	|NN const char *s
 
 END_EXTERN_C
 
@@ -1823,6 +1822,10 @@ Es	|U8	|regtail_study	|NN struct RExC_state_t *pRExC_state \
 #  endif
 #endif
 
+#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_TOKE_C)
+nmPR	|I32	|regcurly	|NN const char *s
+#endif
+
 #if defined(PERL_IN_REGEXEC_C)
 ERs	|I32	|regmatch	|NN regmatch_info *reginfo|NN regnode *prog
 ERs	|I32	|regrepeat	|NN const regexp *prog|NN const regnode *p|I32 max|int depth
diff --git a/embed.h b/embed.h
index b4e419c..508c44f 100644
--- a/embed.h
+++ b/embed.h
@@ -43,9 +43,6 @@
 #endif
 #define get_context		Perl_get_context
 #define set_context		Perl_set_context
-#if defined(PERL_CORE) || defined(PERL_EXT)
-#define regcurly		Perl_regcurly
-#endif
 #define amagic_call		Perl_amagic_call
 #define Gv_AMupdate		Perl_Gv_AMupdate
 #define gv_handler		Perl_gv_handler
@@ -1530,6 +1527,8 @@
 #endif
 #  endif
 #endif
+#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_TOKE_C)
+#endif
 #if defined(PERL_IN_REGEXEC_C)
 #if defined(PERL_CORE) || defined(PERL_EXT)
 #define regmatch		S_regmatch
@@ -2511,9 +2510,6 @@
 #define get_context		Perl_get_context
 #define set_context		Perl_set_context
 #if defined(PERL_CORE) || defined(PERL_EXT)
-#define regcurly		Perl_regcurly
-#endif
-#if defined(PERL_CORE) || defined(PERL_EXT)
 #endif
 #define amagic_call(a,b,c,d)	Perl_amagic_call(aTHX_ a,b,c,d)
 #define Gv_AMupdate(a,b)	Perl_Gv_AMupdate(aTHX_ a,b)
@@ -3990,6 +3986,10 @@
 #endif
 #  endif
 #endif
+#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_TOKE_C)
+#ifdef PERL_CORE
+#endif
+#endif
 #if defined(PERL_IN_REGEXEC_C)
 #if defined(PERL_CORE) || defined(PERL_EXT)
 #define regmatch(a,b)		S_regmatch(aTHX_ a,b)
diff --git a/global.sym b/global.sym
index 4734a33..db2390e 100644
--- a/global.sym
+++ b/global.sym
@@ -31,7 +31,6 @@ Perl_realloc
 Perl_mfree
 Perl_get_context
 Perl_set_context
-Perl_regcurly
 Perl_try_amagic_bin
 Perl_try_amagic_un
 Perl_amagic_call
diff --git a/proto.h b/proto.h
index a29bdc0..a446080 100644
--- a/proto.h
+++ b/proto.h
@@ -119,13 +119,6 @@ PERL_CALLCONV void	Perl_set_context(void *t)
 #define PERL_ARGS_ASSERT_SET_CONTEXT	\
 	assert(t)
 
-PERL_CALLCONV I32	Perl_regcurly(const char *s)
-			__attribute__warn_unused_result__
-			__attribute__pure__
-			__attribute__nonnull__(1);
-#define PERL_ARGS_ASSERT_REGCURLY	\
-	assert(s)
-
 
 END_EXTERN_C
 
@@ -5650,6 +5643,14 @@ STATIC U8	S_regtail_study(pTHX_ struct RExC_state_t *pRExC_state, regnode *p, co
 #  endif
 #endif
 
+#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_TOKE_C)
+/* PERL_CALLCONV I32	regcurly(const char *s)
+			__attribute__warn_unused_result__
+			__attribute__pure__
+			__attribute__nonnull__(1); */
+
+#endif
+
 #if defined(PERL_IN_REGEXEC_C)
 STATIC I32	S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
 			__attribute__warn_unused_result__
diff --git a/re_static.c b/re_static.c
new file mode 100644
index 0000000..f508928
--- /dev/null
+++ b/re_static.c
@@ -0,0 +1,49 @@
+/*    re_static.c
+ *
+ * This file contains static inline functions that are related to
+ * compiling regular expressions, but are used in more than one file.
+ * It is #included by regcomp.c and toke.c.
+*/
+
+/*
+ - regcurly - a little FSA that accepts {\d+,?\d*}
+    Pulled from regcomp.c.
+ */
+
+/* embed.pl doesn't yet know how to handle static inline functions, so 
+   manually decorate it here with gcc-style attributes.
+*/
+PERL_STATIC_INLINE I32
+regcurly(register const char *s)
+    __attribute__warn_unused_result__
+    __attribute__pure__
+    __attribute__nonnull__(1);
+
+PERL_STATIC_INLINE I32
+regcurly(register const char *s)
+{
+    assert(s);
+
+    if (*s++ != '{')
+	return FALSE;
+    if (!isDIGIT(*s))
+	return FALSE;
+    while (isDIGIT(*s))
+	s++;
+    if (*s == ',')
+	s++;
+    while (isDIGIT(*s))
+	s++;
+    if (*s != '}')
+	return FALSE;
+    return TRUE;
+}
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */
diff --git a/regcomp.c b/regcomp.c
index 43b881d..a1c8b49 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -85,6 +85,8 @@
 #  include "regcomp.h"
 #endif
 
+#include "re_static.c"
+
 #ifdef op
 #undef op
 #endif /* op */
@@ -8965,31 +8967,6 @@ S_regtail_study(pTHX_ RExC_state_t *pRExC_state, regnode *p, const regnode *val,
 #endif
 
 /*
- - regcurly - a little FSA that accepts {\d+,?\d*}
- */
-#ifndef PERL_IN_XSUB_RE
-I32
-Perl_regcurly(register const char *s)
-{
-    PERL_ARGS_ASSERT_REGCURLY;
-
-    if (*s++ != '{')
-	return FALSE;
-    if (!isDIGIT(*s))
-	return FALSE;
-    while (isDIGIT(*s))
-	s++;
-    if (*s == ',')
-	s++;
-    while (isDIGIT(*s))
-	s++;
-    if (*s != '}')
-	return FALSE;
-    return TRUE;
-}
-#endif
-
-/*
  - regdump - dump a regexp onto Perl_debug_log in vaguely comprehensible form
  */
 #ifdef DEBUGGING
diff --git a/toke.c b/toke.c
index a7ec612..6e01f25 100644
--- a/toke.c
+++ b/toke.c
@@ -39,6 +39,7 @@ Individual members of C<PL_parser> have their own documentation.
 #include "EXTERN.h"
 #define PERL_IN_TOKE_C
 #include "perl.h"
+#include "re_static.c"
 
 #define new_constant(a,b,c,d,e,f,g)	\
 	S_new_constant(aTHX_ a,b,STR_WITH_LEN(c),d,e,f, g)
-- 
1.5.6.5


-- 
    Andy Dougherty		doughera@lafayette.edu

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About