Skip to content

Commit

Permalink
emul
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed Jan 27, 2023
1 parent 953ffea commit 5e3ce3b
Show file tree
Hide file tree
Showing 14 changed files with 810 additions and 66 deletions.
18 changes: 15 additions & 3 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -4391,11 +4391,12 @@ S |bool |less_dicey_bool_setlocale_r \
!defined(USE_POSIX_2008_LOCALE) */
# if !( defined(USE_POSIX_2008_LOCALE) && defined(USE_QUERYLOCALE) )
: regen/embed.pl can't currently cope with 'elif'
# if !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || defined(WIN32)
# if !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \
defined(USE_THREAD_SAFE_LOCALE_EMULATION) || defined(WIN32)
S |const char *|calculate_LC_ALL \
|NN const char **individ_locales
# endif /* !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \
defined(WIN32) */
# endif /* !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \
defined(USE_THREAD_SAFE_LOCALE_EMULATION) || defined(WIN32) */
# endif /* !( defined(USE_POSIX_2008_LOCALE) && defined(USE_QUERYLOCALE) ) */
# if ( defined(USE_POSIX_2008_LOCALE) && !defined(USE_QUERYLOCALE) ) || \
defined(WIN32)
Expand Down Expand Up @@ -6101,6 +6102,17 @@ pTd |bool |quadmath_format_valid \
pTd |bool |quadmath_format_needed \
|NN const char *format
#endif /* defined(USE_QUADMATH) */
#if defined(USE_THREAD_SAFE_LOCALE_EMULATION)
Cp |void |category_lock_i|unsigned cat_index \
|NN const char *file \
|const line_t line
Cp |void |category_unlock_i \
|unsigned cat_index \
|NN const char *file \
|const line_t line
CIp |int |posix_LC_foo_ |const int c \
|const U8 classnum
#endif /* defined(USE_THREAD_SAFE_LOCALE_EMULATION) */
#if defined(VMS) || defined(WIN32)
Cp |int |do_aspawn |NULLOK SV *really \
|NN SV **mark \
Expand Down
16 changes: 11 additions & 5 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -1279,12 +1279,13 @@
# if defined(LC_ALL)
# define native_query_LC_ALL() S_native_query_LC_ALL(aTHX)
# endif /* defined(LC_ALL) */
# if ( !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \
defined(WIN32) ) && !( defined(USE_POSIX_2008_LOCALE) && \
defined(USE_QUERYLOCALE) )
# if ( !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \
defined(USE_THREAD_SAFE_LOCALE_EMULATION) || defined(WIN32) ) && \
!( defined(USE_POSIX_2008_LOCALE) && defined(USE_QUERYLOCALE) )
# define calculate_LC_ALL(a) S_calculate_LC_ALL(aTHX_ a)
# endif /* ( !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \
defined(WIN32) ) && !( defined(USE_POSIX_2008_LOCALE) && \
# endif /* ( !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \
defined(USE_THREAD_SAFE_LOCALE_EMULATION) || defined(WIN32) \
) && !( defined(USE_POSIX_2008_LOCALE) && \
defined(USE_QUERYLOCALE) ) */
# if defined(USE_LOCALE_COLLATE)
# define new_collate(a,b) S_new_collate(aTHX_ a,b)
Expand Down Expand Up @@ -2139,6 +2140,11 @@
# define PerlIO_unread(a,b,c) Perl_PerlIO_unread(aTHX_ a,b,c)
# define PerlIO_write(a,b,c) Perl_PerlIO_write(aTHX_ a,b,c)
# endif /* defined(USE_PERLIO) */
# if defined(USE_THREAD_SAFE_LOCALE_EMULATION)
# define category_lock_i(a,b,c) Perl_category_lock_i(aTHX_ a,b,c)
# define category_unlock_i(a,b,c) Perl_category_unlock_i(aTHX_ a,b,c)
# define posix_LC_foo_(a,b) Perl_posix_LC_foo_(aTHX_ a,b)
# endif /* defined(USE_THREAD_SAFE_LOCALE_EMULATION) */
# if defined(VMS) || defined(WIN32)
# define do_aspawn(a,b,c) Perl_do_aspawn(aTHX_ a,b,c)
# define do_spawn(a) Perl_do_spawn(aTHX_ a)
Expand Down
3 changes: 3 additions & 0 deletions embedvar.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions handy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1557,9 +1557,17 @@ or casts

# define HIGHEST_REGCOMP_DOT_H_SYNC_ CC_VERTSPACE_

/* The members of the third group below do not need to be coordinated with data
* structures in regcomp.[ch] and regexec.c. */
# define CC_IDFIRST_ 16
/* These three follow immediately after the final function that has a version
* defined by C, like isascii(), so they overlap with anything else. They are
* used in the 'PL_libc_char_fcns' data structure, along with the ones above
* XXX
* them */
# define CC_IDFIRST_ 16
# define CC_TOLOWER_ (CC_IDFIRST_ + 1)
# define CC_TOUPPER_ (CC_TOLOWER_ + 1)

/* The members of the fourth group below do not need to be coordinated with
* data structures in regcomp.[ch] and regexec.c. */
# define CC_CHARNAME_CONT_ 17
# define CC_NONLATIN1_FOLD_ 18
# define CC_NONLATIN1_SIMPLE_FOLD_ 19
Expand Down Expand Up @@ -2027,7 +2035,7 @@ END_EXTERN_C
# define is_posix_XDIGIT(c) isxdigit((U8) (c))
#endif

/* Below is the next level up, which currently expands to nothing more
/* Below is the next level up, which on most platforms expands to nothing more
* than the previous layer. These are the macros to use if you really need
* something whose input domain is a byte, and the locale isn't UTF-8; that is,
* where you normally would have to use things like bare isalnum().
Expand All @@ -2039,7 +2047,13 @@ END_EXTERN_C
* (Note, proper general operation of the bare libc functions requires you to
* cast to U8. These do that for you automatically.) */

/* In this one circumstance, the macro is implemented with a lock; otherwise it
* expands to just the layer below */
#ifdef USE_THREAD_SAFE_LOCALE_EMULATION
# define WRAP_U8_LC_(c, classnum, posix) posix_LC_foo_((c), (classnum))
#else
# define WRAP_U8_LC_(c, classnum, posix) posix(c)
#endif

#define isU8_ALPHANUMERIC_LC(c) \
WRAP_U8_LC_((c), CC_ALPHANUMERIC_, is_posix_ALPHANUMERIC)
Expand Down
43 changes: 43 additions & 0 deletions inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,49 @@ Perl_PerlEnv_putenv(pTHX_ char * str)

#endif

/* ------------------------------- handy.h ------------------------------- */

#ifdef USE_THREAD_SAFE_LOCALE_EMULATION

PERL_STATIC_INLINE int
Perl_posix_LC_foo_(pTHX_ const int c, const U8 classnum) {
int result;

LC_CTYPE_LOCK;

/* All calls to this (so far) are with a 'classnum' known at compile time,
* so the compiler should constant fold this down to a single assignment */
switch (classnum) {
case CC_ALPHANUMERIC_:result = (bool) is_posix_ALPHANUMERIC(c); break;
case CC_ALPHA_: result = (bool) is_posix_ALPHA(c); break;
case CC_ASCII_: result = (bool) is_posix_ASCII(c); break;
case CC_BLANK_: result = (bool) is_posix_BLANK(c); break;
case CC_CASED_: result = (bool) is_posix_CASED(c); break;
case CC_CNTRL_: result = (bool) is_posix_CNTRL(c); break;
case CC_DIGIT_: result = (bool) is_posix_DIGIT(c); break;
case CC_GRAPH_: result = (bool) is_posix_GRAPH(c); break;
case CC_LOWER_: result = (bool) is_posix_LOWER(c); break;
case CC_PRINT_: result = (bool) is_posix_PRINT(c); break;
case CC_PUNCT_: result = (bool) is_posix_PUNCT(c); break;
case CC_SPACE_: result = (bool) is_posix_SPACE(c); break;
case CC_UPPER_: result = (bool) is_posix_UPPER(c); break;
case CC_WORDCHAR_: result = (bool) is_posix_WORDCHAR(c); break;
case CC_XDIGIT_: result = (bool) is_posix_XDIGIT(c); break;
case CC_IDFIRST_: result = (bool) is_posix_IDFIRST(c); break;
case CC_TOLOWER_: result = to_posix_LOWER(c); break;
case CC_TOUPPER_: result = to_posix_UPPER(c); break;

default:
LC_CTYPE_UNLOCK;
locale_panic_(Perl_form(aTHX_ "Unknown charclass %d", classnum));
}

LC_CTYPE_UNLOCK;
return result;
}

#endif

/* ------------------------------- mg.h ------------------------------- */

#if defined(PERL_CORE) || defined(PERL_EXT)
Expand Down
8 changes: 8 additions & 0 deletions intrpvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,14 @@ PERLVARA(I, curlocales, PERL_LOCALE_CATEGORIES_ALL_COUNT_, const char *)

PERLVARI(I, cur_LC_ALL, const char *, NULL)

#endif
#ifdef USE_THREAD_SAFE_LOCALE_EMULATION
PERLVARA(I, restore_locale, PERL_LOCALE_CATEGORIES_COUNT_, const char *)
PERLVARA(I, restore_locale_depth, PERL_LOCALE_CATEGORIES_COUNT_, Size_t)
#endif

#if defined(USE_LOCALE) && ! defined(USE_THREAD_SAFE_LOCALE)
PERLVARI(I, perl_controls_locale, bool, true)
#endif
#ifdef USE_LOCALE_COLLATE

Expand Down
Loading

0 comments on commit 5e3ce3b

Please sign in to comment.