This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move cntrl_to_mnemonic() to util.c from regcomp.c
authorKarl Williamson <khw@cpan.org>
Thu, 16 Jan 2020 23:09:39 +0000 (16:09 -0700)
committerKarl Williamson <khw@cpan.org>
Thu, 23 Jan 2020 22:46:56 +0000 (15:46 -0700)
This is in preparation for it being used elsewhere, to reduce
duplication of code.

embed.fnc
embed.h
handy.h
proto.h
regcomp.c
util.c

index bb91d3a..e91f00e 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -785,6 +785,7 @@ p   |void   |dump_sub_perl  |NN const GV* gv|bool justperl
 Apd    |void   |fbm_compile    |NN SV* sv|U32 flags
 ApdR   |char*  |fbm_instr      |NN unsigned char* big|NN unsigned char* bigend \
                                |NN SV* littlestr|U32 flags
+pEXTR  |const char *|cntrl_to_mnemonic|const U8 c
 p      |CV *   |find_lexical_cv|PADOFFSET off
 : Defined in util.c, used only in perl.c
 p      |char*  |find_script    |NN const char *scriptname|bool dosearch \
@@ -2714,7 +2715,6 @@ ES        |I32    |make_trie      |NN RExC_state_t *pRExC_state \
                                |U32 word_count|U32 flags|U32 depth
 ES     |regnode *|construct_ahocorasick_from_trie|NN RExC_state_t *pRExC_state \
                                 |NN regnode *source|U32 depth
-ETSR   |const char *|cntrl_to_mnemonic|const U8 c
 ETSR   |int    |edit_distance  |NN const UV *src                   \
                                |NN const UV *tgt                   \
                                |const STRLEN x                     \
diff --git a/embed.h b/embed.h
index 82499a2..4326414 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define _inverse_folds(a,b,c)  Perl__inverse_folds(aTHX_ a,b,c)
 #define append_utf8_from_native_byte   Perl_append_utf8_from_native_byte
 #define av_reify(a)            Perl_av_reify(aTHX_ a)
+#define cntrl_to_mnemonic      Perl_cntrl_to_mnemonic
 #define current_re_engine()    Perl_current_re_engine(aTHX)
 #define cv_ckproto_len_flags(a,b,c,d,e)        Perl_cv_ckproto_len_flags(aTHX_ a,b,c,d,e)
 #define get_and_check_backslash_N_name(a,b,c,d)        Perl_get_and_check_backslash_N_name(aTHX_ a,b,c,d)
 #define add_data               S_add_data
 #define add_multi_match(a,b,c) S_add_multi_match(aTHX_ a,b,c)
 #define change_engine_size(a,b)        S_change_engine_size(aTHX_ a,b)
-#define cntrl_to_mnemonic      S_cntrl_to_mnemonic
 #define compute_EXACTish       S_compute_EXACTish
 #define construct_ahocorasick_from_trie(a,b,c) S_construct_ahocorasick_from_trie(aTHX_ a,b,c)
 #define edit_distance          S_edit_distance
diff --git a/handy.h b/handy.h
index a7a75f1..e5062e6 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -1497,8 +1497,11 @@ END_EXTERN_C
                                            _generic_isCC(c, _CC_NON_FINAL_FOLD)
 #   define _IS_IN_SOME_FOLD_ONLY_FOR_USE_BY_REGCOMP_DOT_C(c) \
                                            _generic_isCC(c, _CC_IS_IN_SOME_FOLD)
-#   define _IS_MNEMONIC_CNTRL_ONLY_FOR_USE_BY_REGCOMP_DOT_C(c) \
-                                            _generic_isCC(c, _CC_MNEMONIC_CNTRL)
+
+/* is c a control character for which we have a mnemonic? */
+#  if defined(PERL_CORE) || defined(PERL_EXT)
+#     define isMNEMONIC_CNTRL(c) _generic_isCC(c, _CC_MNEMONIC_CNTRL)
+#  endif
 #else   /* else we don't have perl.h H_PERL */
 
     /* If we don't have perl.h, we are compiling a utility program.  Below we
diff --git a/proto.h b/proto.h
index 0c5b766..8e915ba 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -656,6 +656,10 @@ PERL_CALLCONV void Perl_clear_defarray(pTHX_ AV* av, bool abandon);
 PERL_CALLCONV const COP*       Perl_closest_cop(pTHX_ const COP *cop, const OP *o, const OP *curop, bool opnext);
 #define PERL_ARGS_ASSERT_CLOSEST_COP   \
        assert(cop)
+PERL_CALLCONV const char *     Perl_cntrl_to_mnemonic(const U8 c)
+                       __attribute__warn_unused_result__;
+#define PERL_ARGS_ASSERT_CNTRL_TO_MNEMONIC
+
 PERL_CALLCONV const char *     Perl_cop_fetch_label(pTHX_ COP *const cop, STRLEN *len, U32 *flags);
 #define PERL_ARGS_ASSERT_COP_FETCH_LABEL       \
        assert(cop)
@@ -5561,10 +5565,6 @@ STATIC AV*       S_add_multi_match(pTHX_ AV* multi_char_matches, SV* multi_string, con
 STATIC void    S_change_engine_size(pTHX_ RExC_state_t *pRExC_state, const Ptrdiff_t size);
 #define PERL_ARGS_ASSERT_CHANGE_ENGINE_SIZE    \
        assert(pRExC_state)
-STATIC const char *    S_cntrl_to_mnemonic(const U8 c)
-                       __attribute__warn_unused_result__;
-#define PERL_ARGS_ASSERT_CNTRL_TO_MNEMONIC
-
 #ifndef PERL_NO_INLINE_FUNCTIONS
 PERL_STATIC_INLINE U8  S_compute_EXACTish(RExC_state_t *pRExC_state);
 #define PERL_ARGS_ASSERT_COMPUTE_EXACTISH      \
index ca876d5..dbf33d4 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -1399,29 +1399,6 @@ S_edit_distance(const UV* src,
 /* END of edit_distance() stuff
  * ========================================================= */
 
-/* is c a control character for which we have a mnemonic? */
-#define isMNEMONIC_CNTRL(c) _IS_MNEMONIC_CNTRL_ONLY_FOR_USE_BY_REGCOMP_DOT_C(c)
-
-STATIC const char *
-S_cntrl_to_mnemonic(const U8 c)
-{
-    /* Returns the mnemonic string that represents character 'c', if one
-     * exists; NULL otherwise.  The only ones that exist for the purposes of
-     * this routine are a few control characters */
-
-    switch (c) {
-        case '\a':       return "\\a";
-        case '\b':       return "\\b";
-        case ESC_NATIVE: return "\\e";
-        case '\f':       return "\\f";
-        case '\n':       return "\\n";
-        case '\r':       return "\\r";
-        case '\t':       return "\\t";
-    }
-
-    return NULL;
-}
-
 /* Mark that we cannot extend a found fixed substring at this point.
    Update the longest found anchored substring or the longest found
    floating substrings if needed. */
diff --git a/util.c b/util.c
index 8875265..f3acdfe 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1035,6 +1035,26 @@ Perl_fbm_instr(pTHX_ unsigned char *big, unsigned char *bigend, SV *littlestr, U
     }
 }
 
+const char *
+Perl_cntrl_to_mnemonic(const U8 c)
+{
+    /* Returns the mnemonic string that represents character 'c', if one
+     * exists; NULL otherwise.  The only ones that exist for the purposes of
+     * this routine are a few control characters */
+
+    switch (c) {
+        case '\a':       return "\\a";
+        case '\b':       return "\\b";
+        case ESC_NATIVE: return "\\e";
+        case '\f':       return "\\f";
+        case '\n':       return "\\n";
+        case '\r':       return "\\r";
+        case '\t':       return "\\t";
+    }
+
+    return NULL;
+}
+
 /* copy a string to a safe spot */
 
 /*