You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

399 lines
12 KiB

  1. commit d36adde059ed1c4f7af210b4f9fc3a7bd2d7d343
  2. Author: Karl Williamson <khw@cpan.org>
  3. Date: Wed May 23 15:32:47 2018 -0600
  4. Fix to compile under -DNO_LOCALE
  5. Several problems with this compile option were not caught before 5.28
  6. was frozen.
  7. diff --git a/embed.fnc b/embed.fnc
  8. index 0f06e38..36f9f97 100644
  9. --- a/embed.fnc
  10. +++ b/embed.fnc
  11. @@ -2765,9 +2765,11 @@ s |bool |isa_lookup |NN HV *stash|NN const char * const name \
  12. #endif
  13. #if defined(PERL_IN_LOCALE_C)
  14. +# ifdef USE_LOCALE
  15. sn |const char*|category_name |const int category
  16. s |const char*|switch_category_locale_to_template|const int switch_category|const int template_category|NULLOK const char * template_locale
  17. s |void |restore_switched_locale|const int category|NULLOK const char * const original_locale
  18. +# endif
  19. # ifdef HAS_NL_LANGINFO
  20. sn |const char*|my_nl_langinfo|const nl_item item|bool toggle
  21. # else
  22. diff --git a/embed.h b/embed.h
  23. index cf3ad9e..fb66c26 100644
  24. --- a/embed.h
  25. +++ b/embed.h
  26. @@ -1724,16 +1724,16 @@
  27. #define unshare_hek_or_pvn(a,b,c,d) S_unshare_hek_or_pvn(aTHX_ a,b,c,d)
  28. # endif
  29. # if defined(PERL_IN_LOCALE_C)
  30. -#define category_name S_category_name
  31. -#define restore_switched_locale(a,b) S_restore_switched_locale(aTHX_ a,b)
  32. #define save_to_buffer S_save_to_buffer
  33. -#define switch_category_locale_to_template(a,b,c) S_switch_category_locale_to_template(aTHX_ a,b,c)
  34. # if defined(USE_LOCALE)
  35. +#define category_name S_category_name
  36. #define new_collate(a) S_new_collate(aTHX_ a)
  37. #define new_ctype(a) S_new_ctype(aTHX_ a)
  38. #define new_numeric(a) S_new_numeric(aTHX_ a)
  39. +#define restore_switched_locale(a,b) S_restore_switched_locale(aTHX_ a,b)
  40. #define set_numeric_radix(a) S_set_numeric_radix(aTHX_ a)
  41. #define stdize_locale(a) S_stdize_locale(aTHX_ a)
  42. +#define switch_category_locale_to_template(a,b,c) S_switch_category_locale_to_template(aTHX_ a,b,c)
  43. # if defined(USE_POSIX_2008_LOCALE)
  44. #define emulate_setlocale S_emulate_setlocale
  45. # endif
  46. diff --git a/locale.c b/locale.c
  47. index 7653340..f8f77fb 100644
  48. --- a/locale.c
  49. +++ b/locale.c
  50. @@ -1264,6 +1264,7 @@ S_locking_setlocale(pTHX_
  51. }
  52. #endif
  53. +#ifdef USE_LOCALE
  54. STATIC void
  55. S_set_numeric_radix(pTHX_ const bool use_locale)
  56. @@ -1299,6 +1300,10 @@ S_set_numeric_radix(pTHX_ const bool use_locale)
  57. }
  58. # endif
  59. +#else
  60. +
  61. + PERL_UNUSED_ARG(use_locale);
  62. +
  63. #endif /* USE_LOCALE_NUMERIC and can find the radix char */
  64. }
  65. @@ -1481,7 +1486,6 @@ S_new_ctype(pTHX_ const char *newctype)
  66. #ifndef USE_LOCALE_CTYPE
  67. - PERL_ARGS_ASSERT_NEW_CTYPE;
  68. PERL_UNUSED_ARG(newctype);
  69. PERL_UNUSED_CONTEXT;
  70. @@ -1994,6 +1998,8 @@ S_new_collate(pTHX_ const char *newcoll)
  71. }
  72. +#endif
  73. +
  74. #ifdef WIN32
  75. STATIC char *
  76. @@ -2139,11 +2145,20 @@ Perl_setlocale(const int category, const char * locale)
  77. {
  78. /* This wraps POSIX::setlocale() */
  79. +#ifdef NO_LOCALE
  80. +
  81. + PERL_UNUSED_ARG(category);
  82. + PERL_UNUSED_ARG(locale);
  83. +
  84. + return "C";
  85. +
  86. +#else
  87. +
  88. const char * retval;
  89. const char * newlocale;
  90. dSAVEDERRNO;
  91. - DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
  92. dTHX;
  93. + DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
  94. #ifdef USE_LOCALE_NUMERIC
  95. @@ -2262,6 +2277,8 @@ Perl_setlocale(const int category, const char * locale)
  96. return retval;
  97. +#endif
  98. +
  99. }
  100. PERL_STATIC_INLINE const char *
  101. @@ -2414,13 +2431,16 @@ S_my_nl_langinfo(const int item, bool toggle)
  102. dTHX;
  103. const char * retval;
  104. +#ifdef USE_LOCALE_NUMERIC
  105. +
  106. /* We only need to toggle into the underlying LC_NUMERIC locale for these
  107. * two items, and only if not already there */
  108. if (toggle && (( item != RADIXCHAR && item != THOUSEP)
  109. || PL_numeric_underlying))
  110. - {
  111. +
  112. +#endif /* No toggling needed if not using LC_NUMERIC */
  113. +
  114. toggle = FALSE;
  115. - }
  116. #if defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */
  117. # if ! defined(HAS_THREAD_SAFE_NL_LANGINFO_L) \
  118. @@ -2468,6 +2488,8 @@ S_my_nl_langinfo(const int item, bool toggle)
  119. do_free = TRUE;
  120. }
  121. +# ifdef USE_LOCALE_NUMERIC
  122. +
  123. if (toggle) {
  124. if (PL_underlying_numeric_obj) {
  125. cur = PL_underlying_numeric_obj;
  126. @@ -2478,6 +2500,8 @@ S_my_nl_langinfo(const int item, bool toggle)
  127. }
  128. }
  129. +# endif
  130. +
  131. /* We have to save it to a buffer, because the freelocale() just below
  132. * can invalidate the internal one */
  133. retval = save_to_buffer(nl_langinfo_l(item, cur),
  134. @@ -5169,9 +5193,7 @@ Perl_my_strerror(pTHX_ const int errnum)
  135. LOCALE_UNLOCK;
  136. # endif /* End of doesn't have strerror_l */
  137. -#endif /* End of does have locale messages */
  138. -
  139. -#ifdef DEBUGGING
  140. +# ifdef DEBUGGING
  141. if (DEBUG_Lv_TEST) {
  142. PerlIO_printf(Perl_debug_log, "Strerror returned; saving a copy: '");
  143. @@ -5179,7 +5201,8 @@ Perl_my_strerror(pTHX_ const int errnum)
  144. PerlIO_printf(Perl_debug_log, "'\n");
  145. }
  146. -#endif
  147. +# endif
  148. +#endif /* End of does have locale messages */
  149. SAVEFREEPV(errstr);
  150. return errstr;
  151. @@ -5301,10 +5324,17 @@ L<C<Perl_switch_to_global_locale>|perlapi/switch_to_global_locale>.
  152. bool
  153. Perl_sync_locale()
  154. {
  155. +
  156. +#ifndef USE_LOCALE
  157. +
  158. + return TRUE;
  159. +
  160. +#else
  161. +
  162. const char * newlocale;
  163. dTHX;
  164. -#ifdef USE_POSIX_2008_LOCALE
  165. +# ifdef USE_POSIX_2008_LOCALE
  166. bool was_in_global_locale = FALSE;
  167. locale_t cur_obj = uselocale((locale_t) 0);
  168. @@ -5316,11 +5346,11 @@ Perl_sync_locale()
  169. * will affect the */
  170. if (cur_obj == LC_GLOBAL_LOCALE) {
  171. -# ifdef HAS_QUERY_LOCALE
  172. +# ifdef HAS_QUERY_LOCALE
  173. do_setlocale_c(LC_ALL, setlocale(LC_ALL, NULL));
  174. -# else
  175. +# else
  176. unsigned int i;
  177. @@ -5330,17 +5360,17 @@ Perl_sync_locale()
  178. do_setlocale_r(categories[i], setlocale(categories[i], NULL));
  179. }
  180. -# endif
  181. +# endif
  182. was_in_global_locale = TRUE;
  183. }
  184. -#else
  185. +# else
  186. bool was_in_global_locale = TRUE;
  187. -#endif
  188. -#ifdef USE_LOCALE_CTYPE
  189. +# endif
  190. +# ifdef USE_LOCALE_CTYPE
  191. newlocale = savepv(do_setlocale_c(LC_CTYPE, NULL));
  192. DEBUG_Lv(PerlIO_printf(Perl_debug_log,
  193. @@ -5349,8 +5379,8 @@ Perl_sync_locale()
  194. new_ctype(newlocale);
  195. Safefree(newlocale);
  196. -#endif /* USE_LOCALE_CTYPE */
  197. -#ifdef USE_LOCALE_COLLATE
  198. +# endif /* USE_LOCALE_CTYPE */
  199. +# ifdef USE_LOCALE_COLLATE
  200. newlocale = savepv(do_setlocale_c(LC_COLLATE, NULL));
  201. DEBUG_Lv(PerlIO_printf(Perl_debug_log,
  202. @@ -5359,8 +5389,8 @@ Perl_sync_locale()
  203. new_collate(newlocale);
  204. Safefree(newlocale);
  205. -#endif
  206. -#ifdef USE_LOCALE_NUMERIC
  207. +# endif
  208. +# ifdef USE_LOCALE_NUMERIC
  209. newlocale = savepv(do_setlocale_c(LC_NUMERIC, NULL));
  210. DEBUG_Lv(PerlIO_printf(Perl_debug_log,
  211. @@ -5369,9 +5399,12 @@ Perl_sync_locale()
  212. new_numeric(newlocale);
  213. Safefree(newlocale);
  214. -#endif /* USE_LOCALE_NUMERIC */
  215. +# endif /* USE_LOCALE_NUMERIC */
  216. return was_in_global_locale;
  217. +
  218. +#endif
  219. +
  220. }
  221. #if defined(DEBUGGING) && defined(USE_LOCALE)
  222. diff --git a/makedef.pl b/makedef.pl
  223. index dbd756d..661b71d 100644
  224. --- a/makedef.pl
  225. +++ b/makedef.pl
  226. @@ -574,6 +574,9 @@ unless ($define{USE_LOCALE_COLLATE}) {
  227. PL_collxfrm_mult
  228. Perl_sv_collxfrm
  229. Perl_sv_collxfrm_flags
  230. + PL_strxfrm_NUL_replacement
  231. + PL_strxfrm_is_behaved
  232. + PL_strxfrm_max_cp
  233. );
  234. }
  235. @@ -583,6 +586,9 @@ unless ($define{USE_LOCALE_NUMERIC}) {
  236. PL_numeric_name
  237. PL_numeric_radix_sv
  238. PL_numeric_standard
  239. + PL_numeric_underlying
  240. + PL_numeric_underlying_is_standard
  241. + PL_underlying_numeric_obj
  242. );
  243. }
  244. diff --git a/perl.h b/perl.h
  245. index 3e1f6cd..d457776 100644
  246. --- a/perl.h
  247. +++ b/perl.h
  248. @@ -5657,6 +5657,9 @@ typedef struct am_table_short AMTS;
  249. # define IN_LC_COMPILETIME(category) 0
  250. # define IN_LC_RUNTIME(category) 0
  251. # define IN_LC(category) 0
  252. +# define _CHECK_AND_WARN_PROBLEMATIC_LOCALE
  253. +# define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send)
  254. +# define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(c)
  255. #endif
  256. diff --git a/proto.h b/proto.h
  257. index 3e027ab..558c33a 100644
  258. --- a/proto.h
  259. +++ b/proto.h
  260. @@ -4669,8 +4669,6 @@ PERL_CALLCONV SV* Perl_hfree_next_entry(pTHX_ HV *hv, STRLEN *indexp);
  261. assert(hv); assert(indexp)
  262. #endif
  263. #if defined(PERL_IN_LOCALE_C)
  264. -STATIC const char* S_category_name(const int category);
  265. -STATIC void S_restore_switched_locale(pTHX_ const int category, const char * const original_locale);
  266. #ifndef PERL_NO_INLINE_FUNCTIONS
  267. PERL_STATIC_INLINE const char * S_save_to_buffer(const char * string, char **buf, Size_t *buf_size, const Size_t offset)
  268. __attribute__warn_unused_result__;
  269. @@ -4678,17 +4676,19 @@ PERL_STATIC_INLINE const char * S_save_to_buffer(const char * string, char **buf
  270. assert(buf_size)
  271. #endif
  272. -STATIC const char* S_switch_category_locale_to_template(pTHX_ const int switch_category, const int template_category, const char * template_locale);
  273. # if defined(USE_LOCALE)
  274. +STATIC const char* S_category_name(const int category);
  275. STATIC void S_new_collate(pTHX_ const char* newcoll);
  276. STATIC void S_new_ctype(pTHX_ const char* newctype);
  277. #define PERL_ARGS_ASSERT_NEW_CTYPE \
  278. assert(newctype)
  279. STATIC void S_new_numeric(pTHX_ const char* newnum);
  280. +STATIC void S_restore_switched_locale(pTHX_ const int category, const char * const original_locale);
  281. STATIC void S_set_numeric_radix(pTHX_ const bool use_locale);
  282. STATIC char* S_stdize_locale(pTHX_ char* locs);
  283. #define PERL_ARGS_ASSERT_STDIZE_LOCALE \
  284. assert(locs)
  285. +STATIC const char* S_switch_category_locale_to_template(pTHX_ const int switch_category, const int template_category, const char * template_locale);
  286. # if defined(USE_POSIX_2008_LOCALE)
  287. STATIC const char* S_emulate_setlocale(const int category, const char* locale, unsigned int index, const bool is_index_valid);
  288. # endif
  289. diff --git a/sv.c b/sv.c
  290. index 07865bb..81223ca 100644
  291. --- a/sv.c
  292. +++ b/sv.c
  293. @@ -13330,10 +13330,15 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
  294. SvTAINT(sv);
  295. +#ifdef USE_LOCALE_NUMERIC
  296. +
  297. if (lc_numeric_set) {
  298. RESTORE_LC_NUMERIC(); /* Done outside loop, so don't have to
  299. save/restore each iteration. */
  300. }
  301. +
  302. +#endif
  303. +
  304. }
  305. /* =========================================================================
  306. diff --git a/t/lib/warnings/regexec b/t/lib/warnings/regexec
  307. index 900dd6e..b9e53c9 100644
  308. --- a/t/lib/warnings/regexec
  309. +++ b/t/lib/warnings/regexec
  310. @@ -215,6 +215,10 @@ Use of \b{} or \B{} for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at -
  311. Use of \b{} or \B{} for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 17.
  312. ########
  313. # NAME (?[ ]) in non-UTF-8 locale
  314. +require '../loc_tools.pl';
  315. +unless (locales_enabled()) {
  316. + print("SKIPPED\n# locales not available\n"),exit;
  317. +}
  318. eval { require POSIX; POSIX->import("locale_h") };
  319. if ($@) {
  320. print("SKIPPED\n# no POSIX\n"),exit;
  321. @@ -229,14 +233,14 @@ setlocale(&POSIX::LC_CTYPE, "C");
  322. ":" =~ /(?[ \: ])/;
  323. no warnings 'locale';
  324. EXPECT
  325. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 9.
  326. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 9.
  327. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 10.
  328. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 10.
  329. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 11.
  330. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 11.
  331. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 12.
  332. -Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 12.
  333. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 13.
  334. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 13.
  335. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 14.
  336. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 14.
  337. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 15.
  338. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 15.
  339. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 16.
  340. +Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 16.
  341. ########
  342. # NAME (?[ ]) in UTF-8 locale
  343. require '../loc_tools.pl';