Skip to content

Commit fca8f27

Browse files
committed
embed.fnc: Refactor comments about NN, NULLOK etc
This consolidates the several portions of this file that dealt with these; making it easier to understand.
1 parent 80f5af7 commit fca8f27

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

embed.fnc

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,49 @@
134134
:
135135
: Don't spend any time trying to get your changes to this file to look nice,
136136
: or, for example, for the conditionals to be in order of importance. Any
137-
: changes you make here will be resorted and reformatted according to the
138-
: current rules in regen/embed.pl and regen/embed_lib.pl. Each entry's flags
139-
: will be sorted asciibetically. (This can cause hassles if the rules
137+
: changes you make here will be resorted and reformatted (by
138+
: regen/tidy_embed.pl) according to its current rules. Each entry's flags
139+
: will be sorted asciibetically. (This all can cause hassles if the rules
140140
: change between when you make changes here and when you rebase.)
141141
:
142+
: AUTOMATIC PARAMETER SANITY CHECKING
143+
:
144+
: For each function entry in this file, regen/embed.pl, generates a macro
145+
: that performs parameter sanity validation. If the function is named
146+
: 'foo()', the generated macro will be named 'PERL_ARGS_ASSERT_FOO'. You
147+
: should place a call to that macro in foo() before any other code. It will
148+
: automatically expand to whatever checking is currently generated for foo
149+
: (often none). These are in the form of assert() calls, so they are only
150+
: activated for DEBUGGING builds.
151+
:
152+
: You must specify what checking is needed for all pointer arguments. If the
153+
: pointer is allowed to point to NULL, prefix that argument with 'NULLOK'
154+
: (following the template of the many entries in this file that have that).
155+
: If it can't be NULL, use 'NN' (again many entries herein do that).
156+
: The reason for this requirement is to tell the maintainers that you have
157+
: considered the question about the argument, and this is the answer.
158+
:
159+
: For a numeric argument, you may specify that it can't be 0 by using 'NZ'
160+
:
161+
: regen/embed.pl may automatically add further checking for any argument as
162+
: it deems desirable. You can override this by specifying 'NOCHECK'
163+
:
164+
: Currently this further checking is just for pointer parameters that
165+
: point to AVs, CVs or HVs. The check is that the SV being pointed to is
166+
: of the intended type, by inspecting its SvTYPE(). For some functions
167+
: this check may be inappropriate, as in rare cases the arguments passed
168+
: may not be of the correct type. As already mentioned, NOCHECK
169+
: suppresses this check.
170+
:
171+
: Currently, it is optional to include an empty ARGS_ASSERT macro in your
172+
: functions. But a porting test enforces that a non-empty one is included.
173+
: The call should be at the top of your function so that the sanity checks
174+
: have passed before anything tries to use an argument. When writing a new
175+
: function, add the macro even if not required, and you'll never have to go
176+
: back and add one later when more checks do get added
177+
:
178+
: AUTOMATIC DOCUMENTATION GENERATION
179+
:
142180
: Just below is a description of the relevant parts of the automatic
143181
: documentation generation system which heavily involves this file. Below that
144182
: is a description of all the flags used in this file.
@@ -284,6 +322,8 @@
284322
:
285323
: porting/diag.t checks some things for consistency based on this file.
286324
:
325+
: FLAGS REFERENCE
326+
:
287327
: The remainder of these introductory comments detail all the possible flags:
288328
:
289329
: 'A' Both long and short names are accessible fully everywhere (usually
@@ -397,21 +437,12 @@
397437
: flag even on a format function is if the format would generate error:
398438
: format string argument is not a string type
399439
:
400-
: 'G' Suppress empty PERL_ARGS_ASSERT_foo macro. Normally such a macro is
401-
: generated for all entries for functions 'foo' in this file. If there
402-
: is a pointer argument to 'foo', it needs to be declared in this file
403-
: as either NN or NULLOK, and the function definition must call its
404-
: corresponding PERL_ARGS_ASSERT_foo macro (a porting test ensures this)
405-
: which asserts at runtime (under DEBUGGING builds) that NN arguments
406-
: are not NULL. If there aren't NN arguments, use of this macro is
407-
: optional. Rarely, a function will define its own PERL_ARGS_ASSERT_foo
408-
: macro, and in those cases, adding this flag to its entry in this file
409-
: will suppress the normal one. It is not possible to suppress the
410-
: generated macro if it isn't optional, that is, if there is at least
411-
: one NN argument.
412-
:
413-
: proto.h: PERL_ARGS_ASSERT macro is not defined unless the function
414-
: has NN arguments
440+
: 'G' Suppress empty PERL_ARGS_ASSERT_foo macro. Normally such a macro is
441+
: generated for all entries for functions 'foo' in this file. The macro
442+
: is empty unless regen/embed.pl deems that there should be assert()
443+
: calls to verify the sanity of some or all of foo's arguments.
444+
:
445+
: proto.h: An empty PERL_ARGS_ASSERT macro is not defined
415446
:
416447
: 'h' Hide any documentation that would normally go into perlapi or
417448
: perlintern. This is typically used when the documentation is actually
@@ -636,24 +667,6 @@
636667
: indicate that it does not have enough information to generate a
637668
: proper test case.
638669
:
639-
: In this file, pointer parameters that must not be passed NULLs should be
640-
: prefixed with NN.
641-
:
642-
: And, pointer parameters that may be NULL should be prefixed with NULLOK.
643-
: This has no effect on output yet. It's a notation for the maintainers to
644-
: know "I have defined whether NULL is OK or not" rather than having neither
645-
: NULL or NULLOK, which is ambiguous.
646-
:
647-
: Pointer parameters that point to AVs, CVs or HVs will generate additional
648-
: checks in the arguments assertion macro, that check on entry to the
649-
: function that the SV being pointed to is of the intended type, by
650-
: inspecting its SvTYPE(). For some functions this check may be inappropriate
651-
: as in rare cases the arguments passed may not be of the correct type. To
652-
: skip checking on an argument type, prefix its type with NOCHECK.
653-
:
654-
: Numeric arguments may also be prefixed with NZ, which will cause the
655-
: appropriate asserts to be generated to validate that this is the case.
656-
:
657670
: Please keep the next line *BLANK*
658671

659672
pr |void |abort_execution|NULLOK SV *msg_sv \

0 commit comments

Comments
 (0)