📄 perlos2.pod
字号:
Very useful for extensions which use PM, like C<Perl/Tk> or C<OpenGL>.=head2 F<perl___.exe>This is an C<omf>-style executable which is dynamically linked toF<perl.dll> and CRT DLL. I know no advantages of this executableover C<perl.exe>, but it cannot fork() at all. Well, one advantage isthat the build process is not so convoluted as with C<perl.exe>.It is a VIO application.=head2 Why strange names?Since Perl processes the C<#!>-line (cf. L<perlrun/DESCRIPTION>, L<perlrun/Switches>,L<perldiag/"Not a perl script">, L<perldiag/"No Perl script found in input">), it should know when aprogram I<is a Perl>. There is some naming convention which allowsPerl to distinguish correct lines from wrong ones. The above names arealmost the only names allowed by this convention which do not containdigits (which have absolutely different semantics).=head2 Why dynamic linking?Well, having several executables dynamically linked to the same hugelibrary has its advantages, but this would not substantiate theadditional work to make it compile. The reason is the complicated-to-developersbut very quick and convenient-to-users "hard" dynamic linking used by OS/2.There are two distinctive features of the dyna-linking model of OS/2:all the references to external functions are resolved at the compile time;there is no runtime fixup of the DLLs after they are loaded into memory.The first feature is an enormous advantage over other models: it avoidsconflicts when several DLLs used by an application export entries withthe same name. In such cases "other" models of dyna-linking just choosebetween these two entry points using some random criterion - with predictabledisasters as results. But it is the second feature which requires the buildof F<perl.dll>.The address tables of DLLs are patched only once, when they areloaded. The addresses of the entry points into DLLs are guaranteed to bethe same for all the programs which use the same DLL. This removes theruntime fixup - once DLL is loaded, its code is read-only.While this allows some (significant?) performance advantages, this makes lifemuch harder for developers, since the above scheme makes it impossiblefor a DLL to be "linked" to a symbol in the F<.EXE> file. Indeed, thiswould need a DLL to have different relocations tables for the(different) executables which use this DLL.However, a dynamically loaded Perl extension is forced to use some symbolsfrom the perlexecutable, e.g., to know how to find the arguments to the functions:the arguments live on the perlinternal evaluation stack. The solution is to put the main code ofthe interpreter into a DLL, and make the F<.EXE> file which just loadsthis DLL into memory and supplies command-arguments. The extension DLLcannot link to symbols in F<.EXE>, but it has no problem linkingto symbols in the F<.DLL>.This I<greatly> increases the load time for the application (as well ascomplexity of the compilation). Since interpreter is in a DLL,the C RTL is basically forced to reside in a DLL as well (otherwiseextensions would not be able to use CRT). There are some advantages ifyou use different flavors of perl, such as running F<perl.exe> andF<perl__.exe> simultaneously: they share the memory of F<perl.dll>.B<NOTE>. There is one additional effect which makes DLLs more wasteful:DLLs are loaded in the shared memory region, which is a scarse resourcegiven the 512M barrier of the "standard" OS/2 virtual memory. The code ofF<.EXE> files is also shared by all the processes which use the particularF<.EXE>, but they are "shared in the private address space of the process";this is possible because the address at which different sectionsof the F<.EXE> file are loaded is decided at compile-time, thus all theprocesses have these sections loaded at same addresses, and no fixupof internal links inside the F<.EXE> is needed.Since DLLs may be loaded at run time, to have the same mechanism for for DLLsone needs to have the address range of I<any of the loaded> DLLs in thesystem to be available I<in all the processes> which did not load a particularDLL yet. This is why the DLLs are mapped to the shared memory region.=head2 Why chimera build?Current EMX environment does not allow DLLs compiled using UnixishC<a.out> format to export symbols for data (or at least some types ofdata). This forces C<omf>-style compile of F<perl.dll>.Current EMX environment does not allow F<.EXE> files compiled inC<omf> format to fork(). fork() is needed for exactly three Perloperations:=over 4=item *explicit fork() in the script, =item *C<open FH, "|-">=item *C<open FH, "-|">, in other words, opening pipes to itself.=backWhile these operations are not questions of life and death, they areneeded for a lot ofuseful scripts. This forces C<a.out>-style compile ofF<perl.exe>.=head1 ENVIRONMENTHere we list environment variables with are either OS/2- and DOS- andWin*-specific, or are more important under OS/2 than under other OSes.=head2 C<PERLLIB_PREFIX>Specific for EMX port. Should have the form path1;path2or path1 path2If the beginning of some prebuilt path matches F<path1>, it issubstituted with F<path2>.Should be used if the perl library is moved from the defaultlocation in preference to C<PERL(5)LIB>, since this would not leave wrongentries in @INC. For example, if the compiled version of perl looks for @INCin F<f:/perllib/lib>, and you want to install the library inF<h:/opt/gnu>, do set PERLLIB_PREFIX=f:/perllib/lib;h:/opt/gnuThis will cause Perl with the prebuilt @INC of f:/perllib/lib/5.00553/os2 f:/perllib/lib/5.00553 f:/perllib/lib/site_perl/5.00553/os2 f:/perllib/lib/site_perl/5.00553 .to use the following @INC: h:/opt/gnu/5.00553/os2 h:/opt/gnu/5.00553 h:/opt/gnu/site_perl/5.00553/os2 h:/opt/gnu/site_perl/5.00553 .=head2 C<PERL_BADLANG>If 0, perl ignores setlocale() failing. May be useful with somestrange I<locale>s.=head2 C<PERL_BADFREE>If 0, perl would not warn of in case of unwarranted free(). With olderperls this might beuseful in conjunction with the module DB_File, which was buggy whendynamically linked and OMF-built.Should not be set with newer Perls, since this may hide some I<real> problems.=head2 C<PERL_SH_DIR>Specific for EMX port. Gives the directory part of the location forF<sh.exe>.=head2 C<USE_PERL_FLOCK>Specific for EMX port. Since L<flock(3)> is present in EMX, but is not functional, it is emulated by perl. To disable the emulations, set environment variable C<USE_PERL_FLOCK=0>.=head2 C<TMP> or C<TEMP>Specific for EMX port. Used as storage place for temporary files.=head1 EvolutionHere we list major changes which could make you by surprise.=head2 PrioritiesC<setpriority> and C<getpriority> are not compatible with earlierports by Andreas Kaiser. See C<"setpriority, getpriority">.=head2 DLL name manglingWith the release 5.003_01 the dynamically loadable librariesshould be rebuilt when a different version of Perl is compiled. In particular,DLLs (including F<perl.dll>) are now created with the nameswhich contain a checksum, thus allowing workaround for OS/2 scheme ofcaching DLLs.It may be possible to code a simple workaround which would =over=item *find the old DLLs looking through the old @INC;=item *mangle the names according to the scheme of new perl and copy the DLLs tothese names;=item *edit the internal C<LX> tables of DLL to reflect the change of the name(probably not needed for Perl extension DLLs, since the internally coded namesare not used for "specific" DLLs, they used only for "global" DLLs).=item *edit the internal C<IMPORT> tables and change the name of the "old"F<perl????.dll> to the "new" F<perl????.dll>.=back=head2 ThreadingAs of release 5.003_01 perl is linked to multithreaded C RTLDLL. If perl itself is not compiled multithread-enabled, so will not be perl'smalloc(). However, extensions may use multiple thread on their ownrisk. This was needed to compile C<Perl/Tk> for XFree86-OS/2 out-of-the-box, andlink with DLLs for other useful libraries, which typically are compiledwith C<-Zmt -Zcrtdll>.=head2 Calls to external programsDue to a popular demand the perl external program calling has beenchanged wrt Andreas Kaiser's port. I<If> perl needs to call anexternal program I<via shell>, the F<f:/bin/sh.exe> will be called, orwhatever is the override, see L<"PERL_SH_DIR">.Thus means that you need to get some copy of a F<sh.exe> as well (Iuse one from pdksh). The path F<F:/bin> above is set up automatically duringthe build to a correct value on the builder machine, but isoverridable at runtime,B<Reasons:> a consensus on C<perl5-porters> was that perl should useone non-overridable shell per platform. The obvious choices for OS/2are F<cmd.exe> and F<sh.exe>. Having perl build itself would be impossiblewith F<cmd.exe> as a shell, thus I picked up C<sh.exe>. This assures almost100% compatibility with the scripts coming from *nix. As an added benefit this works as well under DOS if you use DOS-enabled port of pdksh (see L<"Prerequisites">).B<Disadvantages:> currently F<sh.exe> of pdksh calls external programsvia fork()/exec(), and there is I<no> functioning exec() onOS/2. exec() is emulated by EMX by an asynchronous call while the callerwaits for child completion (to pretend that the C<pid> did not change). Thismeans that 1 I<extra> copy of F<sh.exe> is made active via fork()/exec(),which may lead to some resources taken from the system (even if we donot count extra work needed for fork()ing).Note that this a lesser issue now when we do not spawn F<sh.exe>unless needed (metachars found).One can always start F<cmd.exe> explicitly via system 'cmd', '/c', 'mycmd', 'arg1', 'arg2', ...If you need to use F<cmd.exe>, and do not want to hand-edit thousands of yourscripts, the long-term solution proposed on p5-p is to have a directive use OS2::Cmd;which will override system(), exec(), C<``>, andC<open(,'...|')>. With current perl you may override only system(),readpipe() - the explicit version of C<``>, and maybe exec(). The codewill substitute the one-argument call to system() byC<CORE::system('cmd.exe', '/c', shift)>.If you have some working code for C<OS2::Cmd>, please send it to me,I will include it into distribution. I have no need for such a module, socannot test it.For the details of the current situation with calling external programs,see L<Starting OS/2 (and DOS) programs under Perl>. Set us mention a coupleof features:=over 4=item *External scripts may be called by their basename. Perl will try the sameextensions as when processing B<-S> command-line switch.=item *External scripts starting with C<#!> or C<extproc > will be executed directly,without calling the shell, by calling the program specified on the rest ofthe first line.=back=head2 Memory allocationPerl uses its own malloc() under OS/2 - interpreters are usually malloc-boundfor speed, but perl is not, since its malloc is lightning-fast.Perl-memory-usage-tuned benchmarks show that Perl's malloc is 5 times quickerthan EMX one. I do not have convincing data about memory footprint, buta (pretty random) benchmark showed that Perl's one is 5% better.Combination of perl's malloc() and rigid DLL name resolution createsa special problem with library functions which expect their return value tobe free()d by system's free(). To facilitate extensions which need to call such functions, system memory-allocation functions are still available withthe prefix C<emx_> added. (Currently only DLL perl has this, it should propagate to F<perl_.exe> shortly.)=head2 ThreadsOne can build perl with thread support enabled by providing C<-D usethreads>option to F<Configure>. Currently OS/2 support of threads is very preliminary.Most notable problems: =over 4=item C<COND_WAIT> may have a race condition. Needs a reimplementation (in terms of chainingwaiting threads, with the linked list stored in per-thread structure?).=item F<os2.c>has a couple of static variables used in OS/2-specific functions. (Need to bemoved to per-thread structure, or serialized?)=backNote that these problems should not discourage experimenting, since theyhave a low probability of affecting small programs.=cutOS/2 extensions~~~~~~~~~~~~~~~I include 3 extensions by Andreas Kaiser, OS2::REXX, OS2::UPM, and OS2::FTP, into my ftp directory, mirrored on CPAN. I madesome minor changes needed to compile them by standard tools. I cannot test UPM and FTP, so I will appreciate your feedback. Other extensionsthere are OS2::ExtAttr, OS2::PrfDB for tied access to EAs and .INIfiles - and maybe some other extensions at the time you read it.Note that OS2 perl defines 2 pseudo-extension functionsOS2::Copy::copy and DynaLoader::mod2fname (many more now, seeL<Prebuilt methods>).The -R switch of older perl is deprecated. If you need to call a REXX codewhich needs access to variables, include the call into a REXX compartmentcreated by REXX_call {...block...};Two new functions are supported by REXX code, REXX_eval 'string'; REXX_eval_with 'string', REXX_function_name => \&perl_sub_reference;If you have some other extensions you want to share, send the code tome. At least two are available: tied access to EA's, and tied accessto system databases.=head1 AUTHORIlya Zakharevich, ilya@math.ohio-state.edu=head1 SEE ALSOperl(1).=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -