📄 perlhack.pod
字号:
=item It's easierSince you don't have to apply the patches yourself, you are sure allfiles in the source tree are in the right state.=item It's more recentAccording to Gurusamy Sarathy: "... The rsync mirror is automatic and syncs with the repository every five minutes. "Updating the patch area still requires manual intervention (with all the goofiness that implies, which you've noted) and is typically on a daily cycle. Making this process automatic is on my tuit list, but don't ask me when."=item It's more reliableWell, since the patches are updated by hand, I don't have to say anymore ... (see Sarathy's remark).=back=head2 Why rsync the patches=over 4=item It's easierIf you have more than one machine that you want to keep in track withbleadperl, it's easier to rsync the patches only once and then applythem to all the source trees on the different machines.In case you try to keep in pace on 5 different machines, for whichonly one of them has access to the WAN, rsync'ing all the sourcetrees should than be done 5 times over the NFS. Havingrsync'ed the patches only once, I can apply them to all the sourcetrees automatically. Need you say more ;-)=item It's a good referenceIf you do not only like to have the most recent development branch,but also like to B<fix> bugs, or extend features, you want to diveinto the sources. If you are a seasoned perl core diver, you don'tneed no manuals, tips, roadmaps, perlguts.pod or other aids to findyour way around. But if you are a starter, the patches may help youin finding where you should start and how to change the bits thatbug you.The file B<Changes> is updated on occasions the pumpking sees as hisown little sync points. On those occasions, he releases a tar-ball ofthe current source tree (i.e. perl@7582.tar.gz), which will be anexcellent point to start with when choosing to use the 'rsync thepatches' scheme. Starting with perl@7582, which means a set of sourcefiles on which the latest applied patch is number 7582, you apply allsucceeding patches available from then on (7583, 7584, ...).You can use the patches later as a kind of search archive.=over 4=item Finding a start pointIf you want to fix/change the behaviour of function/feature Foo, justscan the patches for patches that mention Foo either in the subject,the comments, or the body of the fix. A good chance the patch showsyou the files that are affected by that patch which are very likelyto be the starting point of your journey into the guts of perl.=item Finding how to fix a bugIf you've found I<where> the function/feature Foo misbehaves, but youdon't know how to fix it (but you do know the change you want tomake), you can, again, peruse the patches for similar changes andlook how others apply the fix.=item Finding the source of misbehaviourWhen you keep in sync with bleadperl, the pumpking would love toI<see> that the community efforts realy work. So after each of hissync points, you are to 'make test' to check if everything is stillin working order. If it is, you do 'make ok', which will send an OKreport to perlbug@perl.org. (If you do not have access to a mailerfrom the system you just finished successfully 'make test', you cando 'make okfile', which creates the file C<perl.ok>, which you canthan take to your favourite mailer and mail yourself).But of course, as always, things will not allways lead to a successpath, and one or more test do not pass the 'make test'. Beforesending in a bug report (using 'make nok' or 'make nokfile'), checkthe mailing list if someone else has reported the bug already and ifso, confirm it by replying to that message. If not, you might want totrace the source of that misbehaviour B<before> sending in the bug,which will help all the other porters in finding the solution.Here the saved patches come in very handy. You can check the list ofpatches to see which patch changed what file and what change causedthe misbehaviour. If you note that in the bug report, it saves theone trying to solve it, looking for that point.=backIf searching the patches is too bothersome, you might consider usingperl's bugtron to find more information about discussions andramblings on posted bugs.=backIf you want to get the best of both worlds, rsync both the sourcetree for convenience, reliability and ease and rsync the patchesfor reference.=head2 Submitting patchesAlways submit patches to I<perl5-porters@perl.org>. This lets otherporters review your patch, which catches a surprising number of errorsin patches. Either use the diff program (available in source codeform from I<ftp://ftp.gnu.org/pub/gnu/>), or use Johan Vromans'I<makepatch> (available from I<CPAN/authors/id/JV/>). Unified diffsare preferred, but context diffs are accepted. Do not send RCS-stylediffs or diffs without context lines. More information is given inthe I<Porting/patching.pod> file in the Perl source distribution.Please patch against the latest B<development> version (e.g., ifyou're fixing a bug in the 5.005 track, patch against the latest5.005_5x version). Only patches that survive the heat of thedevelopment branch get applied to maintenance versions.Your patch should update the documentation and test suite.To report a bug in Perl, use the program I<perlbug> which comes withPerl (if you can't get Perl to work, send mail to the addressI<perlbug@perl.org> or I<perlbug@perl.com>). Reporting bugs throughI<perlbug> feeds into the automated bug-tracking system, access towhich is provided through the web at I<http://bugs.perl.org/>. Itoften pays to check the archives of the perl5-porters mailing list tosee whether the bug you're reporting has been reported before, and ifso whether it was considered a bug. See above for the location ofthe searchable archives.The CPAN testers (I<http://testers.cpan.org/>) are a group ofvolunteers who test CPAN modules on a variety of platforms. Perl Labs(I<http://labs.perl.org/>) automatically tests Perl source releases onplatforms and gives feedback to the CPAN testers mailing list. Bothefforts welcome volunteers.It's a good idea to read and lurk for a while before chipping in.That way you'll get to see the dynamic of the conversations, learn thepersonalities of the players, and hopefully be better prepared to makea useful contribution when do you speak up.If after all this you still think you want to join the perl5-portersmailing list, send mail to I<perl5-porters-subscribe@perl.org>. Tounsubscribe, send mail to I<perl5-porters-unsubscribe@perl.org>.To hack on the Perl guts, you'll need to read the following things:=over 3=item L<perlguts>This is of paramount importance, since it's the documentation of whatgoes where in the Perl source. Read it over a couple of times and itmight start to make sense - don't worry if it doesn't yet, because thebest way to study it is to read it in conjunction with poking at Perlsource, and we'll do that later on.You might also want to look at Gisle Aas's illustrated perlguts -there's no guarantee that this will be absolutely up-to-date with thelatest documentation in the Perl core, but the fundamentals will beright. (http://gisle.aas.no/perl/illguts/)=item L<perlxstut> and L<perlxs>A working knowledge of XSUB programming is incredibly useful for corehacking; XSUBs use techniques drawn from the PP code, the portion of theguts that actually executes a Perl program. It's a lot gentler to learnthose techniques from simple examples and explanation than from the coreitself.=item L<perlapi>The documentation for the Perl API explains what some of the internalfunctions do, as well as the many macros used in the source.=item F<Porting/pumpkin.pod>This is a collection of words of wisdom for a Perl porter; some of it isonly useful to the pumpkin holder, but most of it applies to anyonewanting to go about Perl development.=item The perl5-porters FAQThis is posted to perl5-porters at the beginning on every month, andshould be available from http://perlhacker.org/p5p-faq; alternatively,you can get the FAQ emailed to you by sending mail toC<perl5-porters-faq@perl.org>. It contains hints on readingperl5-porters, information on how perl5-porters works and how Perldevelopment in general works.=back=head2 Finding Your Way AroundPerl maintenance can be split into a number of areas, and certain people(pumpkins) will have responsibility for each area. These areas sometimescorrespond to files or directories in the source kit. Among the areas are:=over 3=item Core modulesModules shipped as part of the Perl core live in the F<lib/> and F<ext/>subdirectories: F<lib/> is for the pure-Perl modules, and F<ext/>contains the core XS modules.=item DocumentationDocumentation maintenance includes looking after everything in theF<pod/> directory, (as well as contributing new documentation) andthe documentation to the modules in core.=item ConfigureThe configure process is the way we make Perl portable across themyriad of operating systems it supports. Responsibility for theconfigure, build and installation process, as well as the overallportability of the core code rests with the configure pumpkin - othershelp out with individual operating systems.The files involved are the operating system directories, (F<win32/>,F<os2/>, F<vms/> and so on) the shell scripts which generate F<config.h>and F<Makefile>, as well as the metaconfig files which generateF<Configure>. (metaconfig isn't included in the core distribution.)=item InterpreterAnd of course, there's the core of the Perl interpreter itself. Let'shave a look at that in a little more detail.=backBefore we leave looking at the layout, though, don't forget thatF<MANIFEST> contains not only the file names in the Perl distribution,but short descriptions of what's in them, too. For an overview of theimportant files, try this: perl -lne 'print if /^[^\/]+\.[ch]\s+/' MANIFEST=head2 Elements of the interpreterThe work of the interpreter has two main stages: compiling the codeinto the internal representation, or bytecode, and then executing it.L<perlguts/Compiled code> explains exactly how the compilation stagehappens.Here is a short breakdown of perl's operation:=over 3=item StartupThe action begins in F<perlmain.c>. (or F<miniperlmain.c> for miniperl)This is very high-level code, enough to fit on a single screen, and itresembles the code found in L<perlembed>; most of the real action takesplace in F<perl.c>First, F<perlmain.c> allocates some memory and constructs a Perlinterpreter: 1 PERL_SYS_INIT3(&argc,&argv,&env); 2 3 if (!PL_do_undump) { 4 my_perl = perl_alloc(); 5 if (!my_perl) 6 exit(1); 7 perl_construct(my_perl); 8 PL_perl_destruct_level = 0; 9 }Line 1 is a macro, and its definition is dependent on your operatingsystem. Line 3 references C<PL_do_undump>, a global variable - allglobal variables in Perl start with C<PL_>. This tells you whether thecurrent running program was created with the C<-u> flag to perl and thenF<undump>, which means it's going to be false in any sane context.Line 4 calls a function in F<perl.c> to allocate memory for a Perlinterpreter. It's quite a simple function, and the guts of it looks likethis: my_perl = (PerlInterpreter*)PerlMem_malloc(sizeof(PerlInterpreter));Here you see an example of Perl's system abstraction, which we'll seelater: C<PerlMem_malloc> is either your system's C<malloc>, or Perl'sown C<malloc> as defined in F<malloc.c> if you selected that option atconfigure time.Next, in line 7, we construct the interpreter; this sets up all thespecial variables that Perl needs, the stacks, and so on.Now we pass Perl the command line options, and tell it to go: exitstatus = perl_parse(my_perl, xs_init, argc, argv, (char **)NULL); if (!exitstatus) { exitstatus = perl_run(my_perl); }C<perl_parse> is actually a wrapper around C<S_parse_body>, as definedin F<perl.c>, which processes the command line options, sets up anystatically linked XS modules, opens the program and calls C<yyparse> toparse it.=item ParsingThe aim of this stage is to take the Perl source, and turn it into an optree. We'll see what one of those looks like later. Strictly speaking,there's three things going on here.C<yyparse>, the parser, lives in F<perly.c>, although you're better offreading the original YACC input in F<perly.y>. (Yes, Virginia, thereB<is> a YACC grammar for Perl!) The job of the parser is to take yourcode and `understand' it, splitting it into sentences, deciding whichoperands go with which operators and so on.The parser is nobly assisted by the lexer, which chunks up your inputinto tokens, and decides what type of thing each token is: a variablename, an operator, a bareword, a subroutine, a core function, and so on.The main point of entry to the lexer is C<yylex>, and that and itsassociated routines can be found in F<toke.c>. Perl isn't much likeother computer languages; it's highly context sensitive at times, it canbe tricky to work out what sort of token something is, or where a tokenends. As such, there's a lot of interplay between the tokeniser and theparser, which can get pretty frightening if you're not used to it.As the parser understands a Perl program, it builds up a tree ofoperations for the interpreter to perform during execution. The routineswhich construct and link together the various operations are to be foundin F<op.c>, and will be examined later.=item OptimizationNow the parsing stage is complete, and the finished tree representsthe operations that the Perl interpreter needs to perform to execute ourprogram. Next, Perl does a dry run over the tree looking for
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -