| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "ExtUtils::Constant::Base 3perl" |
| 58 |
.TH ExtUtils::Constant::Base 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
ExtUtils::Constant::Base \- base class for ExtUtils::Constant objects |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 2 |
| 68 |
\& require ExtUtils::Constant::Base; |
| 69 |
\& @ISA = \*(AqExtUtils::Constant::Base\*(Aq; |
| 70 |
.Ve |
| 71 |
.SH DESCRIPTION |
| 72 |
.IX Header "DESCRIPTION" |
| 73 |
ExtUtils::Constant::Base provides a base implementation of methods to |
| 74 |
generate C code to give fast constant value lookup by named string. Currently |
| 75 |
it's mostly used ExtUtils::Constant::XS, which generates the lookup code |
| 76 |
for the \fBconstant()\fR subroutine found in many XS modules. |
| 77 |
.SH USAGE |
| 78 |
.IX Header "USAGE" |
| 79 |
ExtUtils::Constant::Base exports no subroutines. The following methods are |
| 80 |
available |
| 81 |
.IP header 4 |
| 82 |
.IX Item "header" |
| 83 |
A method returning a scalar containing definitions needed, typically for a |
| 84 |
C header file. |
| 85 |
.IP "memEQ_clause args_hashref" 4 |
| 86 |
.IX Item "memEQ_clause args_hashref" |
| 87 |
A method to return a suitable C \f(CW\*(C`if\*(C'\fR statement to check whether \fIname\fR |
| 88 |
is equal to the C variable \f(CW\*(C`name\*(C'\fR. If \fIchecked_at\fR is defined, then it |
| 89 |
is used to avoid \f(CW\*(C`memEQ\*(C'\fR for short names, or to generate a comment to |
| 90 |
highlight the position of the character in the \f(CW\*(C`switch\*(C'\fR statement. |
| 91 |
.Sp |
| 92 |
If i<checked_at> is a reference to a scalar, then instead it gives |
| 93 |
the characters pre-checked at the beginning, (and the number of chars by |
| 94 |
which the C variable name has been advanced. These need to be chopped from |
| 95 |
the front of \fIname\fR). |
| 96 |
.IP "dump_names arg_hashref, ITEM..." 4 |
| 97 |
.IX Item "dump_names arg_hashref, ITEM..." |
| 98 |
An internal function to generate the embedded perl code that will regenerate |
| 99 |
the constant subroutines. \fIdefault_type\fR, \fItypes\fR and \fIITEM\fRs are the |
| 100 |
same as for C_constant. \fIindent\fR is treated as number of spaces to indent |
| 101 |
by. If \f(CW\*(C`declare_types\*(C'\fR is true a \f(CW$types\fR is always declared in the perl |
| 102 |
code generated, if defined and false never declared, and if undefined \f(CW$types\fR |
| 103 |
is only declared if the values in \fItypes\fR as passed in cannot be inferred from |
| 104 |
\&\fIdefault_types\fR and the \fIITEM\fRs. |
| 105 |
.IP "assign arg_hashref, VALUE..." 4 |
| 106 |
.IX Item "assign arg_hashref, VALUE..." |
| 107 |
A method to return a suitable assignment clause. If \fItype\fR is aggregate |
| 108 |
(eg \fIPVN\fR expects both pointer and length) then there should be multiple |
| 109 |
\&\fIVALUE\fRs for the components. \fIpre\fR and \fIpost\fR if defined give snippets |
| 110 |
of C code to proceed and follow the assignment. \fIpre\fR will be at the start |
| 111 |
of a block, so variables may be defined in it. |
| 112 |
.IP "return_clause arg_hashref, ITEM" 4 |
| 113 |
.IX Item "return_clause arg_hashref, ITEM" |
| 114 |
A method to return a suitable \f(CW\*(C`#ifdef\*(C'\fR clause. \fIITEM\fR is a hashref |
| 115 |
(as passed to \f(CW\*(C`C_constant\*(C'\fR and \f(CW\*(C`match_clause\*(C'\fR. \fIindent\fR is the number |
| 116 |
of spaces to indent, defaulting to 6. |
| 117 |
.IP "switch_clause arg_hashref, NAMELEN, ITEMHASH, ITEM..." 4 |
| 118 |
.IX Item "switch_clause arg_hashref, NAMELEN, ITEMHASH, ITEM..." |
| 119 |
An internal method to generate a suitable \f(CW\*(C`switch\*(C'\fR clause, called by |
| 120 |
\&\f(CW\*(C`C_constant\*(C'\fR \fIITEM\fRs are in the hash ref format as given in the description |
| 121 |
of \f(CW\*(C`C_constant\*(C'\fR, and must all have the names of the same length, given by |
| 122 |
\&\fINAMELEN\fR. \fIITEMHASH\fR is a reference to a hash, keyed by name, values being |
| 123 |
the hashrefs in the \fIITEM\fR list. (No parameters are modified, and there can |
| 124 |
be keys in the \fIITEMHASH\fR that are not in the list of \fIITEM\fRs without |
| 125 |
causing problems \- the hash is passed in to save generating it afresh for |
| 126 |
each call). |
| 127 |
.IP "params WHAT" 4 |
| 128 |
.IX Item "params WHAT" |
| 129 |
An "internal" method, subject to change, currently called to allow an |
| 130 |
overriding class to cache information that will then be passed into all |
| 131 |
the \f(CW\*(C`*param*\*(C'\fR calls. (Yes, having to read the source to make sense of this is |
| 132 |
considered a known bug). \fIWHAT\fR is be a hashref of types the constant |
| 133 |
function will return. In ExtUtils::Constant::XS this method is used to |
| 134 |
returns a hashref keyed IV NV PV SV to show which combination of pointers will |
| 135 |
be needed in the C argument list generated by |
| 136 |
C_constant_other_params_definition and C_constant_other_params |
| 137 |
.IP "dogfood arg_hashref, ITEM..." 4 |
| 138 |
.IX Item "dogfood arg_hashref, ITEM..." |
| 139 |
An internal function to generate the embedded perl code that will regenerate |
| 140 |
the constant subroutines. Parameters are the same as for C_constant. |
| 141 |
.Sp |
| 142 |
Currently the base class does nothing and returns an empty string. |
| 143 |
.IP "normalise_items args, default_type, seen_types, seen_items, ITEM..." 4 |
| 144 |
.IX Item "normalise_items args, default_type, seen_types, seen_items, ITEM..." |
| 145 |
Convert the items to a normalised form. For 8 bit and Unicode values converts |
| 146 |
the item to an array of 1 or 2 items, both 8 bit and UTF\-8 encoded. |
| 147 |
.IP "C_constant arg_hashref, ITEM..." 4 |
| 148 |
.IX Item "C_constant arg_hashref, ITEM..." |
| 149 |
A function that returns a \fBlist\fR of C subroutine definitions that return |
| 150 |
the value and type of constants when passed the name by the XS wrapper. |
| 151 |
\&\fIITEM...\fR gives a list of constant names. Each can either be a string, |
| 152 |
which is taken as a C macro name, or a reference to a hash with the following |
| 153 |
keys |
| 154 |
.RS 4 |
| 155 |
.IP name 8 |
| 156 |
.IX Item "name" |
| 157 |
The name of the constant, as seen by the perl code. |
| 158 |
.IP type 8 |
| 159 |
.IX Item "type" |
| 160 |
The type of the constant (\fIIV\fR, \fINV\fR etc) |
| 161 |
.IP value 8 |
| 162 |
.IX Item "value" |
| 163 |
A C expression for the value of the constant, or a list of C expressions if |
| 164 |
the type is aggregate. This defaults to the \fIname\fR if not given. |
| 165 |
.IP macro 8 |
| 166 |
.IX Item "macro" |
| 167 |
The C pre-processor macro to use in the \f(CW\*(C`#ifdef\*(C'\fR. This defaults to the |
| 168 |
\&\fIname\fR, and is mainly used if \fIvalue\fR is an \f(CW\*(C`enum\*(C'\fR. If a reference an |
| 169 |
array is passed then the first element is used in place of the \f(CW\*(C`#ifdef\*(C'\fR |
| 170 |
line, and the second element in place of the \f(CW\*(C`#endif\*(C'\fR. This allows |
| 171 |
pre-processor constructions such as |
| 172 |
.Sp |
| 173 |
.Vb 5 |
| 174 |
\& #if defined (foo) |
| 175 |
\& #if !defined (bar) |
| 176 |
\& ... |
| 177 |
\& #endif |
| 178 |
\& #endif |
| 179 |
.Ve |
| 180 |
.Sp |
| 181 |
to be used to determine if a constant is to be defined. |
| 182 |
.Sp |
| 183 |
A "macro" 1 signals that the constant is always defined, so the \f(CW\*(C`#if\*(C'\fR/\f(CW\*(C`#endif\*(C'\fR |
| 184 |
test is omitted. |
| 185 |
.IP default 8 |
| 186 |
.IX Item "default" |
| 187 |
Default value to use (instead of \f(CW\*(C`croak\*(C'\fRing with "your vendor has not |
| 188 |
defined...") to return if the macro isn't defined. Specify a reference to |
| 189 |
an array with type followed by value(s). |
| 190 |
.IP pre 8 |
| 191 |
.IX Item "pre" |
| 192 |
C code to use before the assignment of the value of the constant. This allows |
| 193 |
you to use temporary variables to extract a value from part of a \f(CW\*(C`struct\*(C'\fR |
| 194 |
and return this as \fIvalue\fR. This C code is places at the start of a block, |
| 195 |
so you can declare variables in it. |
| 196 |
.IP post 8 |
| 197 |
.IX Item "post" |
| 198 |
C code to place between the assignment of value (to a temporary) and the |
| 199 |
return from the function. This allows you to clear up anything in \fIpre\fR. |
| 200 |
Rarely needed. |
| 201 |
.IP def_pre 8 |
| 202 |
.IX Item "def_pre" |
| 203 |
.PD 0 |
| 204 |
.IP def_post 8 |
| 205 |
.IX Item "def_post" |
| 206 |
.PD |
| 207 |
Equivalents of \fIpre\fR and \fIpost\fR for the default value. |
| 208 |
.IP utf8 8 |
| 209 |
.IX Item "utf8" |
| 210 |
Generated internally. Is zero or undefined if name is 7 bit ASCII, |
| 211 |
"no" if the name is 8 bit (and so should only match if \fBSvUTF8()\fR is false), |
| 212 |
"yes" if the name is utf8 encoded. |
| 213 |
.Sp |
| 214 |
The internals automatically clone any name with characters 128\-255 but none |
| 215 |
256+ (ie one that could be either in bytes or utf8) into a second entry |
| 216 |
which is utf8 encoded. |
| 217 |
.IP weight 8 |
| 218 |
.IX Item "weight" |
| 219 |
Optional sorting weight for names, to determine the order of |
| 220 |
linear testing when multiple names fall in the same case of a switch clause. |
| 221 |
Higher comes earlier, undefined defaults to zero. |
| 222 |
.RE |
| 223 |
.RS 4 |
| 224 |
.Sp |
| 225 |
In the argument hashref, \fIpackage\fR is the name of the package, and is only |
| 226 |
used in comments inside the generated C code. \fIsubname\fR defaults to |
| 227 |
\&\f(CW\*(C`constant\*(C'\fR if undefined. |
| 228 |
.Sp |
| 229 |
\&\fIdefault_type\fR is the type returned by \f(CW\*(C`ITEM\*(C'\fRs that don't specify their |
| 230 |
type. It defaults to the value of \f(CWdefault_type()\fR. \fItypes\fR should be given |
| 231 |
either as a comma separated list of types that the C subroutine \fIsubname\fR |
| 232 |
will generate or as a reference to a hash. \fIdefault_type\fR will be added to |
| 233 |
the list if not present, as will any types given in the list of \fIITEM\fRs. The |
| 234 |
resultant list should be the same list of types that \f(CW\*(C`XS_constant\*(C'\fR is |
| 235 |
given. [Otherwise \f(CW\*(C`XS_constant\*(C'\fR and \f(CW\*(C`C_constant\*(C'\fR may differ in the number of |
| 236 |
parameters to the constant function. \fIindent\fR is currently unused and |
| 237 |
ignored. In future it may be used to pass in information used to change the C |
| 238 |
indentation style used.] The best way to maintain consistency is to pass in a |
| 239 |
hash reference and let this function update it. |
| 240 |
.Sp |
| 241 |
\&\fIbreakout\fR governs when child functions of \fIsubname\fR are generated. If there |
| 242 |
are \fIbreakout\fR or more \fIITEM\fRs with the same length of name, then the code |
| 243 |
to switch between them is placed into a function named \fIsubname\fR_\fIlen\fR, for |
| 244 |
example \f(CW\*(C`constant_5\*(C'\fR for names 5 characters long. The default \fIbreakout\fR is |
| 245 |
3. A single \f(CW\*(C`ITEM\*(C'\fR is always inlined. |
| 246 |
.RE |
| 247 |
.SH BUGS |
| 248 |
.IX Header "BUGS" |
| 249 |
Not everything is documented yet. |
| 250 |
.PP |
| 251 |
Probably others. |
| 252 |
.SH AUTHOR |
| 253 |
.IX Header "AUTHOR" |
| 254 |
Nicholas Clark <[email protected]> based on the code in \f(CW\*(C`h2xs\*(C'\fR by Larry Wall and |
| 255 |
others |