Skip to content

Commit 22d8ec6

Browse files
committed
utf8_to_uv_msgs: Create another common macro
This new macro allows two more case statements in the switch to have a common macro at their beginnings, instead of having to repeat code.
1 parent 51fbc1c commit 22d8ec6

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

utf8.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,14 +2293,38 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22932293
}
22942294
break;
22952295

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+
}
23012324

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,,);
23042328

23052329
/* These are the only errors that can occur with a
23062330
* surrogate when the 'input_uv' isn't valid */
@@ -2314,19 +2338,13 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23142338
message = Perl_form(aTHX_ surrogate_cp_format,
23152339
input_uv);
23162340
}
2317-
}
2318-
}
23192341

23202342
break;
23212343

23222344
case UTF8_GOT_NONCHAR:
23232345

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,,);
23272347

2328-
if (flags & UTF8_WARN_NONCHAR) {
2329-
if (PACK_WARN(WARN_NONCHAR,,)) {
23302348
/* The code above should have guaranteed that we don't
23312349
* get here with conditions other than these */
23322350
assert (! (orig_problems & ~( UTF8_GOT_LONG
@@ -2335,8 +2353,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23352353
|UTF8_GOT_NONCHAR)));
23362354

23372355
message = Perl_form(aTHX_ nonchar_cp_format, input_uv);
2338-
}
2339-
}
23402356

23412357
break;
23422358

0 commit comments

Comments
 (0)