Commit | Line | Data |
adfe19db |
1 | =head1 NAME |
2 | |
3 | HACKERS - Devel::PPPort internals for hackers |
4 | |
5 | =head1 SYNOPSIS |
6 | |
7 | So you probably want to hack C<Devel::PPPort>? |
8 | |
9 | Well, here's some information to get you started with what's |
10 | lying around in this distribution. |
11 | |
12 | =head1 DESCRIPTION |
13 | |
f2ab5a41 |
14 | =head2 How to build 105 versions of Perl |
adfe19db |
15 | |
16 | C<Devel::PPPort> supports Perl versions between 5.003 and bleadperl. |
17 | To guarantee this support, I need some of these versions on my |
f2ab5a41 |
18 | machine. I currently have 105 different Perl version/configuration |
adfe19db |
19 | combinations installed on my laptop. |
20 | |
21 | As many of the old Perl distributions need patching to compile |
f2ab5a41 |
22 | cleanly on newer systems (and because building 105 Perls by hand |
adfe19db |
23 | just isn't fun), I wrote a tool to build all the different |
24 | versions and configurations. You can find it in F<devel/buildperl.pl>. |
25 | It can currently build the following Perl releases: |
26 | |
27 | 5.003 |
28 | 5.004 - 5.004_05 |
29 | 5.005 - 5.005_04 |
30 | 5.6.x |
31 | 5.7.x |
32 | 5.8.x |
33 | 5.9.x |
34 | |
35 | =head2 Fully automatic API checks |
36 | |
37 | Knowing which parts of the API are not backwards compatible and |
38 | probably need C<Devel::PPPort> support is another problem that's |
39 | not easy to deal with manually. If you run |
40 | |
41 | perl Makefile.PL --with-apicheck |
42 | |
43 | a C file is generated by F<parts/apicheck.pl> that is compiled |
44 | and linked with C<Devel::PPPort>. This C file has the purpose of |
45 | using each of the public API functions/macros once. |
46 | |
47 | The required information is derived from C<parts/embed.fnc> (just |
48 | a copy of bleadperl's C<embed.fnc>) and C<parts/apidoc.fnc> (which |
49 | is generated by F<devel/mkapidoc.sh> and simply collects the rest |
50 | of the apidoc entries spread over the Perl source code). |
51 | The generated C file C<apicheck.c> is currently about 500k in size |
52 | and takes quite a while to compile. |
53 | |
54 | Usually, C<apicheck.c> won't compile with older perls. And even if |
55 | it compiles, there's still a good chance of the dynamic linker |
56 | failing at C<make test> time. But that's on purpose! |
57 | |
58 | We can use these failures to find changes in the API automatically. |
59 | The two Perl scripts F<devel/mktodo> and F<devel/mktodo.pl> |
60 | repeatedly run C<Devel::PPPort> with the apicheck code through |
61 | all different versions of perl. Scanning the output of the compiler |
62 | and the dynamic linker for errors, the files in F<parts/todo/> are |
63 | generated. These files list all parts of the public API that don't |
64 | work with less than a certain version of Perl. |
65 | |
66 | This information is in turn used by F<parts/apicheck.pl> to mask |
67 | API calls in the generated C file for these versions, so the |
68 | process can be stopped by the time F<apicheck.c> compiles cleanly |
ba120f6f |
69 | and the dynamic linker is happy. (Actually, this process may generate |
70 | false positives, so by default each API call is checked once more |
71 | afterwards.) |
adfe19db |
72 | |
ba120f6f |
73 | Running C<devel/mktodo> takes about an hour, depending of course |
74 | on the machine you're running it on. If you run it with |
75 | the C<--nocheck> option, it won't recheck the API calls that failed |
76 | in the compilation stage and it'll take significantly less time. |
77 | Running with C<--nocheck> should usually be safe. |
adfe19db |
78 | |
79 | When running C<devel/mktodo> with the C<--base> option, it will |
80 | generate the I<baseline> todo files by disabling all functionality |
81 | provided by C<Devel::PPPort>. These are required for implementing |
82 | the C<--compat-version> option of the C<ppport.h> script. The |
83 | baseline todo files hold the information about which version of |
84 | Perl lacks a certain part of the API. |
85 | |
86 | However, only the documented public API can be checked this way. |
87 | And since C<Devel::PPPort> provides more macros, these would not be |
88 | affected by C<--compat-version>. It's the job of F<devel/scanprov> |
89 | to figure out the baseline information for all remaining provided |
90 | macros by scanning the include files in the F<CORE> directory of |
91 | various Perl versions. |
92 | |
ba120f6f |
93 | The whole process isn't platform independent. It has currently been |
94 | tested only under Linux, and it definitely requires at least C<gcc> and |
95 | the C<nm> utility. |
96 | |
97 | It's not very often that one has to regenerate the baseline and todo |
98 | files. If you have to, you can either run F<devel/regenerate> or just |
99 | execute the following steps by hand: |
adfe19db |
100 | |
101 | =over 4 |
102 | |
103 | =item * |
104 | |
105 | You need a whole bunch of different Perls. The more, the better. |
106 | You can use F<devel/buildperl.pl> to build them. I keep my perls |
107 | in F</tmp/perl>, so most of the tools take this as a default. |
108 | |
109 | =item * |
110 | |
56093a11 |
111 | You also need a freshly built bleadperl that is in the path under |
112 | exactly this name. (The name of the executable is currently hardcoded |
113 | in F<devel/mktodo> and F<devel/scanprov>.) |
114 | |
115 | =item * |
116 | |
adfe19db |
117 | Remove all existing todo files in the F<parts/base> and |
118 | F<parts/todo> directories. |
119 | |
120 | =item * |
121 | |
122 | Update the API information. Copy the latest F<embed.fnc> file from |
123 | bleadperl to the F<parts> directory and run F<devel/mkapidoc.sh> to |
124 | collect the remaining information in F<parts/apidoc.fnc>. |
125 | |
126 | =item * |
127 | |
128 | Build the new baseline by running |
129 | |
130 | perl devel/mktodo --base |
131 | |
132 | in the root directory of the distribution. When it's finished, |
133 | move all files from the F<parts/todo> directory to F<parts/base>. |
134 | |
135 | =item * |
136 | |
137 | Build the new todo files by running |
138 | |
139 | perl devel/mktodo |
140 | |
141 | in the root directory of the distribution. |
142 | |
143 | =item * |
144 | |
145 | Finally, add the remaining baseline information by running |
146 | |
4a582685 |
147 | perl Makefile.PL && make |
148 | perl devel/scanprov write |
adfe19db |
149 | |
150 | =back |
151 | |
152 | =head2 Implementation |
153 | |
154 | Residing in F<parts/inc/> is the "heart" of C<Devel::PPPort>. Each |
155 | of the files implements a part of the supported API, along with |
156 | hints, dependency information, XS code and tests. |
157 | The files are in a POD-like format that is parsed using the |
158 | functions in F<parts/ppptools.pl>. |
159 | |
160 | The scripts F<PPPort_pm.PL>, F<PPPort_xs.PL> and F<mktests.PL> all |
161 | use the information in F<parts/inc/> to generate the main module |
162 | F<PPPort.pm>, the XS code in F<PPPort.xs> and various test files |
163 | in F<t/>. |
164 | |
165 | All of these files could be generated on the fly while building |
166 | C<Devel::PPPort>, but not having the tests in C<t/> and not having |
167 | F<PPPort.xs> will confuse Configure and TEST/harness in the core. |
168 | Not having F<PPPort.pm> will be bad for viewing the docs on |
169 | C<search.cpan.org>. So unfortunately, it's unavoidable to put |
170 | some redundancy into the package. |
171 | |
172 | =head2 Adding stuff to Devel::PPPort |
173 | |
174 | First, check if the code you plan to add fits into one of the |
175 | existing files in F<parts/inc/>. If not, just start a new one and |
176 | remember to include it from within F<PPPort_pm.PL>. |
177 | |
178 | Each file holds all relevant data for implementing a certain part |
179 | of the API: |
180 | |
181 | =over 2 |
182 | |
183 | =item * |
184 | |
185 | A list of the provided API in the C<=provides> section. |
186 | |
187 | =item * |
188 | |
189 | The implementation to add to F<ppport.h> in the C<=implementation> |
190 | section. |
191 | |
192 | =item * |
193 | |
194 | The code required to add to PPPort.xs for testing the implementation. |
195 | This code goes into the C<=xshead>, C<=xsinit>, C<=xsmisc>, C<=xsboot> |
0d0f8426 |
196 | and C<=xsubs> section. Have a look at the template at the bottom |
197 | of F<PPPort_xs.PL> to see where the code ends up. |
adfe19db |
198 | |
199 | =item * |
200 | |
201 | The tests in the C<=tests> section. Remember not to use any fancy |
202 | modules or syntax elements, as the test code should be able to run |
203 | with Perl 5.003, which, for example, doesn't support C<my> in |
204 | C<for>-loops: |
205 | |
0d0f8426 |
206 | for my $x (1, 2, 3) { } # won't work with 5.003 |
adfe19db |
207 | |
0d0f8426 |
208 | You can use C<ok()> to report success or failure: |
209 | |
210 | ok($got == 42); |
211 | ok($got, $expected); |
212 | |
213 | Regular expressions are not supported as the second argument to C<ok>, |
214 | because older perls do not support the C<qr> operator. |
adfe19db |
215 | |
216 | =back |
217 | |
218 | It's usually the best approach to just copy an existing file and |
219 | use it as a template. |
220 | |
0d0f8426 |
221 | =head2 Implementation Hints |
222 | |
223 | In the C<=implementation> section, you can use |
224 | |
225 | __UNDEFINED__ macro some definition |
226 | |
227 | instead of |
228 | |
229 | #ifndef macro |
230 | # define macro some definition |
231 | #endif |
232 | |
233 | The macro can have optional arguments and the definition can even |
234 | span multiple lines, like in |
235 | |
236 | __UNDEFINED__ SvMAGIC_set(sv, val) \ |
237 | STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ |
238 | (((XPVMG*) SvANY(sv))->xmg_magic = (val)); } STMT_END |
239 | |
240 | This usually makes the code more compact and readable. And you |
241 | only have to add C<__UNDEFINED__> to the C<=provided> section. |
242 | |
243 | Version checking can be tricky if you want to do it correct. |
244 | You can use |
245 | |
246 | #if { VERSION < 5.9.3 } |
247 | |
248 | instead of |
249 | |
250 | #if ((PERL_VERSION < 9) || (PERL_VERSION == 9 && PERL_SUBVERSION < 3)) |
251 | |
252 | The version number can be either of the new form C<5.x.x> or of the older |
253 | form C<5.00x_yy>. Both are translated into the correct preprocessor |
254 | statements. It is also possible to combine this with other statements: |
255 | |
256 | #if { VERSION >= 5.004 } && !defined(sv_vcatpvf) |
257 | /* a */ |
258 | #elif { VERSION < 5.004_63 } && { VERSION != 5.004_05 } |
259 | /* b */ |
260 | #endif |
261 | |
262 | This not only works in the C<=implementation> section, but also in |
263 | the C<=xsubs>, C<=xsinit>, C<=xsmisc>, C<=xshead> and C<=xsboot> sections. |
264 | |
adfe19db |
265 | =head2 Testing |
266 | |
267 | To automatically test C<Devel::PPPort> with lots of different Perl |
268 | versions, you can use the F<soak> script. Just pass it a list of |
269 | all Perl binaries you want to test. |
270 | |
271 | =head2 Special Makefile targets |
272 | |
4a582685 |
273 | You can use |
adfe19db |
274 | |
275 | make regen |
276 | |
4a582685 |
277 | to regenerate all of the autogenerated files. To get rid of all |
278 | generated files (except for F<parts/todo/*> and F<parts/base/*>), |
279 | use |
adfe19db |
280 | |
281 | make purge_all |
282 | |
283 | That's it. |
284 | |
0d0f8426 |
285 | =head2 Submitting Patches |
286 | |
287 | If you've added some functionality to C<Devel::PPPort>, please |
288 | consider submitting a patch with your work to either the author |
289 | (E<lt>mhx@cpan.orgE<gt>) or to the CPAN Request Tracker at |
290 | L<http://rt.cpan.org>. |
291 | |
292 | When submitting patches, please only add the relevant changes |
293 | and don't include the differences of the generated files. You |
294 | can use the C<purge_all> target to delete all autogenerated |
295 | files. |
296 | |
56093a11 |
297 | =head2 Integrating into the Perl core |
298 | |
299 | When integrating this module into the Perl core, be sure to |
300 | remove the following files from the distribution. They are |
301 | either not needed or generated on the fly when building this |
302 | module in the core: |
303 | |
304 | MANIFEST |
305 | META.yml |
306 | PPPort.pm |
307 | |
adfe19db |
308 | =head1 COPYRIGHT |
309 | |
0d0f8426 |
310 | Version 3.x, Copyright (C) 2004-2006, Marcus Holland-Moritz. |
adfe19db |
311 | |
312 | Version 2.x, Copyright (C) 2001, Paul Marquess. |
313 | |
314 | Version 1.x, Copyright (C) 1999, Kenneth Albanowski. |
315 | |
316 | This program is free software; you can redistribute it and/or |
317 | modify it under the same terms as Perl itself. |
318 | |
319 | =head1 SEE ALSO |
320 | |
ba120f6f |
321 | See L<ppport.h> and L<devel/regenerate>. |
adfe19db |
322 | |
323 | =cut |
324 | |