@@ -2293,14 +2293,38 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
2293
2293
}
2294
2294
break ;
2295
2295
2296
- case UTF8_GOT_SURROGATE :
2297
-
2298
- /* Code earlier in this function has set things up so we don't
2299
- * get here unless at least one of the two top-level 'if's in
2300
- * this case are true */
2296
+ /* PACK_WARN returns:
2297
+ * 0 when there is no reason to generate a message for this condition
2298
+ * because the appropriate warnings categories are off and not
2299
+ * overridden
2300
+ * < 0 if the only reason would be to return a message in an AV structure;
2301
+ * but this is only done if this condition is to be rejected
2302
+ * > 0 if the categories are effectively on; but this is only done for these
2303
+ * default-accepted conditions if at least one of the following is true:
2304
+ * 1) the caller has expicitly set the individual flag to demand
2305
+ * warnings for this condition; or
2306
+ * 2) the caller has passed flags that demand all conditions generate
2307
+ * warnings; or
2308
+ * 3) the condition is to be rejected and is to be passed back to the
2309
+ * caller in an AV structure
2310
+ * This macro relies on each GOT and ACCEPT flags being identical.
2311
+ */
2312
+ #define COMMON_DEFAULT_ACCEPTEDS (warn_flag , p1 , p2 , p3 ) \
2313
+ pack_warn = PACK_WARN(p1, p2, p3); \
2314
+ if ( pack_warn == 0 \
2315
+ || (pack_warn < 0 && ! (this_problem & rejects)) \
2316
+ || ( pack_warn > 0 \
2317
+ && (0 == (flags & ( warn_flag \
2318
+ |UTF8_DIE_IF_MALFORMED \
2319
+ |UTF8_FORCE_WARN_IF_MALFORMED))) \
2320
+ && (! msgs || ! (this_problem & rejects)))) \
2321
+ { \
2322
+ continue; \
2323
+ }
2301
2324
2302
- if (flags & UTF8_WARN_SURROGATE ) {
2303
- if (PACK_WARN (WARN_SURROGATE ,,)) {
2325
+ case UTF8_GOT_SURROGATE :
2326
+ COMMON_DEFAULT_ACCEPTEDS (UTF8_WARN_SURROGATE ,
2327
+ WARN_SURROGATE ,,);
2304
2328
2305
2329
/* These are the only errors that can occur with a
2306
2330
* surrogate when the 'input_uv' isn't valid */
@@ -2314,19 +2338,13 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
2314
2338
message = Perl_form (aTHX_ surrogate_cp_format ,
2315
2339
input_uv );
2316
2340
}
2317
- }
2318
- }
2319
2341
2320
2342
break ;
2321
2343
2322
2344
case UTF8_GOT_NONCHAR :
2323
2345
2324
- /* Code earlier in this function has set things up so we don't
2325
- * get here unless at least one of the two top-level 'if's in
2326
- * this case are true */
2346
+ COMMON_DEFAULT_ACCEPTEDS (UTF8_WARN_NONCHAR , WARN_NONCHAR ,,);
2327
2347
2328
- if (flags & UTF8_WARN_NONCHAR ) {
2329
- if (PACK_WARN (WARN_NONCHAR ,,)) {
2330
2348
/* The code above should have guaranteed that we don't
2331
2349
* get here with conditions other than these */
2332
2350
assert (! (orig_problems & ~( UTF8_GOT_LONG
@@ -2335,8 +2353,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
2335
2353
|UTF8_GOT_NONCHAR )));
2336
2354
2337
2355
message = Perl_form (aTHX_ nonchar_cp_format , input_uv );
2338
- }
2339
- }
2340
2356
2341
2357
break ;
2342
2358
0 commit comments