|
14 | 14 | : file, and which expands to call the real (full) name, with any appropriate |
15 | 15 | : thread context parameters, thus hiding that detail from the typical code. |
16 | 16 | : |
17 | | -: Many macros (as opposed to functions) listed here are the complete full name, |
18 | | -: though we may want to start converting those to have full names. |
19 | | -: |
20 | 17 | : embed.pl uses the entries here to construct: |
21 | 18 | : 1) proto.h to declare to the compiler the function interfaces; and |
22 | 19 | : 2) embed.h to create short name macros, and to control the visibility of |
23 | 20 | : other macros |
| 21 | +: 3) long_names.c holds long-named function definitions that implement |
| 22 | +: short-named macros listed here, when a function is necessary. |
24 | 23 | : |
25 | 24 | : Static functions internal to a file need not appear here, but there is |
26 | 25 | : benefit to declaring them here: |
|
37 | 36 | : Lines in this file are of the form: |
38 | 37 | : flags|return_type|name|arg1|arg2|...|argN ( assert(...) )* |
39 | 38 | : |
| 39 | +: A line may be continued onto the next by ending it with a backslash. |
| 40 | +: Leading and trailing whitespace will be ignored in each component. |
| 41 | +: |
| 42 | +: 'name' is the name of the function, macro, typedef, etc. It returns values |
| 43 | +: of type 'return_type'. Use 'void' if there is no return value. |
| 44 | +: |
40 | 45 | : 'flags' is a string of single letters. Most of the flags are meaningful only |
41 | 46 | : to embed.pl; some only to autodoc.pl, and others only to makedef.pl. The |
42 | 47 | : comments here mostly don't include how Devel::PPPort or diag.t use them: |
43 | | -: All the possible flags and their meanings are given below. |
| 48 | +: All the possible flags and their meanings are given in comments below. |
44 | 49 | : |
45 | 50 | : A function taking no parameters will have no 'arg' elements. Currently |
46 | 51 | : arguments that are function pointers are unlikely to be parsed properly here |
47 | 52 | : (patches welcome!); you can work around this by creating a typedef for the |
48 | | -: function pointer, in an appropriate header file and using that here. |
49 | | -: |
50 | | -: A line may be continued onto the next by ending it with a backslash. |
51 | | -: Leading and trailing whitespace will be ignored in each component. |
| 53 | +: function pointer in an appropriate header file and use that here. |
52 | 54 | : |
53 | 55 | : The optional list of asserts is used to customize the generated |
54 | 56 | : PERL_ARGS_ASSERT macro. See AUTOMATIC PARAMETER SANITY CHECKING below |
55 | 57 | : |
56 | | -: Most entries here have a macro created with the entry name. This presents |
57 | | -: name space collision potentials which haven't been well thought out, but are |
58 | | -: now documented here. In practice this has rarely been an issue. At least, |
59 | | -: with a macro, the XS author can #undef it, unlike a function. |
60 | | -: |
61 | | -: The default without flags is to declare a function for internal perl-core use |
62 | | -: only. The short name is visible only when the PERL_CORE symbol is defined. |
63 | | -: On some platforms all non-static functions are currently externally visible. |
64 | | -: Because of this, and also for programs that embed perl, most non-static |
65 | | -: functions should have the 'p' flag to avoid namespace clashes. |
66 | | -: |
67 | | -: There are several advantages to using a macro instead of the full Perl_foo or |
68 | | -: S_foo form: it hides the need to know if the called function requires a |
69 | | -: thread context parameter or not, and the code using it is more readable |
70 | | -: because of fewer parameters being visible. And if there is some bug in it |
71 | | -: that gets fixed in a later release, ppport.h can be changed to automatically |
72 | | -: backport the fixed version to modules. The only disadvantage khw can think |
73 | | -: of is the namespace pollution one. |
74 | | -: |
75 | | -: The default for any macro created after v5.43.6 is to hide it from all but |
76 | | -: the Perl core. Use the visibility-affecting flags described below to change |
77 | | -: that. |
| 58 | +: In practice, every element here will have at least one flag. But without any |
| 59 | +: flags, the default would be to create an entry in proto.h declaring 'name' as |
| 60 | +: a function returning 'return_type' with arguments aTHX, 'arg1', ..., 'argN'. |
| 61 | +: The function would be visible to only other files in the perl core, unless |
| 62 | +: the system doesn't allow visibility restrictions. |
| 63 | +: |
| 64 | +: But, in practice, every function listed here will have a flag to indicate |
| 65 | +: that the function's name isn't precisely 'name', but is a perturbation of |
| 66 | +: that so that the actual name declared in proto.h is either 'S_name' (for |
| 67 | +: static (file-scoped) functions) or 'Perl_name' (for functions visible outside |
| 68 | +: a single file). (A very few cases have a different backwards-compatibility |
| 69 | +: name instead.) A macro is then added to embed.h which maps 'name' to the |
| 70 | +: actual name. If the Perl interpreter is embedded in a larger application, or |
| 71 | +: on platforms where all non-static functions are externally visible, there |
| 72 | +: could be two functions with the same name; making ours 'Perl_foo' instead of |
| 73 | +: 'foo' prevents that. This is done by using the 'p' flag. Hence, just about |
| 74 | +: every function element here that is non-static should have that flag |
| 75 | +: specified. |
| 76 | +: |
| 77 | +: Most calls wanting to invoke 'name' will use that precise spelling, which |
| 78 | +: embed.h maps to the actual function. This allows the macro to do some |
| 79 | +: hanky-panky behind the scenes to hide various details from the caller. |
| 80 | +: Notably, this includes whether or not to call the function with a |
| 81 | +: thread-context parameter. This parameter is only needed for threaded or |
| 82 | +: embedded uses of perl, and it would be wasteful to have to call functions |
| 83 | +: with an extra meaningless parameter, so it is omitted unless needed. The |
| 84 | +: macro in embed.h knows whether there is one or not, expanding appropriately |
| 85 | +: without exposing it to the code calling it. Hence the same source code works |
| 86 | +: in both cases. The macro can hide other things as well. Devel::PPPort, for |
| 87 | +: example, can redefine the macro to backport fixes to bugs. |
| 88 | +: |
| 89 | +: For elements in place here in 5.42 and earlier, the visibility of the macros |
| 90 | +: in embed.h (and other header files) is everywhere. This presents the |
| 91 | +: possibility of name space collisions in XS code, generally resolved by the XS |
| 92 | +: writer changing their name to not conflict. For elements created later than |
| 93 | +: that, the default visibility is core-only. |
78 | 94 | : |
79 | 95 | : WARNING: The default hiding of symbols from XS code applies only to functions |
80 | 96 | : and macros. Other types of values that are created in a header file, such as |
|
121 | 137 | : |
122 | 138 | : Some of these have been constructed so that the wrapper macro names |
123 | 139 | : begin with an underscore to lessen the chances of a name collision. |
124 | | -: However, this is contrary to the C standard, and those should be |
125 | | -: changed. |
| 140 | +: However, this is contrary to the C standard, many of those have been |
| 141 | +: changed, and the remainder should be. |
126 | 142 | : |
127 | 143 | : The 'E' flag is used instead for elements that are supposed to be used only |
128 | 144 | : in the core, plus extensions compiled with the PERL_EXT symbol |
|
0 commit comments