Skip to content

Commit dd52e3c

Browse files
committed
Add global hash to handle \p{user-defined}
A global hash has to be specially handled. The keys can't be shared, and all the SVs stored into it must be in its thread. This commit adds the hash, and initialization, and macros for context change, but doesn't use them. The code to deal with this is entirely confined to regcomp.c.
1 parent 8310e7f commit dd52e3c

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

embedvar.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@
468468
#define PL_Gtimesbase (my_vars->Gtimesbase)
469469
#define PL_use_safe_putenv (my_vars->Guse_safe_putenv)
470470
#define PL_Guse_safe_putenv (my_vars->Guse_safe_putenv)
471+
#define PL_user_def_props (my_vars->Guser_def_props)
472+
#define PL_Guser_def_props (my_vars->Guser_def_props)
473+
#define PL_user_def_props_aTHX (my_vars->Guser_def_props_aTHX)
474+
#define PL_Guser_def_props_aTHX (my_vars->Guser_def_props_aTHX)
471475
#define PL_user_prop_mutex (my_vars->Guser_prop_mutex)
472476
#define PL_Guser_prop_mutex (my_vars->Guser_prop_mutex)
473477
#define PL_utf8_charname_begin (my_vars->Gutf8_charname_begin)

makedef.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ sub readvar {
353353
unless ($define{'USE_ITHREADS'}) {
354354
++$skip{PL_thr_key};
355355
++$skip{PL_user_prop_mutex};
356+
++$skip{PL_user_def_props_aTHX};
356357
}
357358

358359
# USE_5005THREADS symbols. Kept as reference for easier removal

perlapi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ END_EXTERN_C
215215
#define PL_timesbase (*Perl_Gtimesbase_ptr(NULL))
216216
#undef PL_use_safe_putenv
217217
#define PL_use_safe_putenv (*Perl_Guse_safe_putenv_ptr(NULL))
218+
#undef PL_user_def_props
219+
#define PL_user_def_props (*Perl_Guser_def_props_ptr(NULL))
220+
#undef PL_user_def_props_aTHX
221+
#define PL_user_def_props_aTHX (*Perl_Guser_def_props_aTHX_ptr(NULL))
218222
#undef PL_user_prop_mutex
219223
#define PL_user_prop_mutex (*Perl_Guser_prop_mutex_ptr(NULL))
220224
#undef PL_utf8_charname_begin

perlvars.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,15 @@ PERLVAR(G, utf8_mark, SV *)
307307
PERLVAR(G, InBitmap, SV *)
308308
PERLVAR(G, CCC_non0_non230, SV *)
309309

310+
/* Definitions of user-defined \p{} properties, as the subs that define them
311+
* are only called once */
312+
PERLVARI(G, user_def_props, HV *, NULL)
313+
310314
#if defined(USE_ITHREADS)
311-
PERLVAR(G, user_prop_mutex, perl_mutex)
315+
PERLVAR(G, user_def_props_aTHX, PerlInterpreter *) /* aTHX that user_def_props
316+
was defined in */
317+
PERLVAR(G, user_prop_mutex, perl_mutex) /* Mutex for manipulating
318+
PL_user_defined_properties */
312319
#endif
313320

314321
/* Everything that folds to a given character, for case insensitivity regex

regcomp.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21928,6 +21928,15 @@ S_dumpuntil(pTHX_ const regexp *r, const regnode *start, const regnode *node,
2192821928
void
2192921929
Perl_init_uniprops(pTHX)
2193021930
{
21931+
PL_user_def_props = newHV();
21932+
21933+
#ifdef USE_ITHREADS
21934+
21935+
HvSHAREKEYS_off(PL_user_def_props);
21936+
PL_user_def_props_aTHX = aTHX;
21937+
21938+
#endif
21939+
2193121940
/* Set up the inversion list global variables */
2193221941

2193321942
PL_XPosix_ptrs[_CC_ASCII] = _new_invlist_C_array(uni_prop_ptrs[UNI_ASCII]);
@@ -22007,6 +22016,22 @@ Perl_init_uniprops(pTHX)
2200722016
#endif
2200822017
}
2200922018

22019+
#ifdef USE_ITHREADS
22020+
# define DECLARATION_FOR_GLOBAL_CONTEXT \
22021+
PerlInterpreter * save_aTHX = aTHX;
22022+
# define SWITCH_TO_GLOBAL_CONTEXT \
22023+
PERL_SET_CONTEXT((aTHX = PL_user_def_props_aTHX))
22024+
# define RESTORE_CONTEXT PERL_SET_CONTEXT((aTHX = save_aTHX));
22025+
# define CUR_CONTEXT aTHX
22026+
# define ORIGINAL_CONTEXT save_aTHX
22027+
#else
22028+
# define DECLARATION_FOR_GLOBAL_CONTEXT
22029+
# define SWITCH_TO_GLOBAL_CONTEXT NOOP
22030+
# define RESTORE_CONTEXT NOOP
22031+
# define CUR_CONTEXT NULL
22032+
# define ORIGINAL_CONTEXT NULL
22033+
#endif
22034+
2201022035
SV *
2201122036
Perl_parse_uniprop_string(pTHX_ const char * const name, const Size_t name_len,
2201222037
const bool to_fold, bool * invert)

0 commit comments

Comments
 (0)