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.

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