home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1996 July / AMIGA_1996_7.BIN / ausgabe_7_96 / pd-programmierung / perl5_002bin.lha / man / catp / perlxs.0 < prev    next >
Text File  |  1996-03-02  |  92KB  |  1,585 lines

  1.  
  2.  
  3.  
  4. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  5.  
  6.  
  7. NNNNAAAAMMMMEEEE
  8.        perlxs - XS language reference manual
  9.  
  10. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  11.        IIIInnnnttttrrrroooodddduuuuccccttttiiiioooonnnn
  12.  
  13.        XS is a language used to create an extension interface
  14.        between Perl and some C library which one wishes to use
  15.        with Perl.  The XS interface is combined with the library
  16.        to create a new library which can be linked to Perl.  An
  17.        XXXXSSSSUUUUBBBB is a function in the XS language and is the core
  18.        component of the Perl application interface.
  19.  
  20.        The XS compiler is called xxxxssssuuuubbbbpppppppp.  This compiler will
  21.        embed the constructs necessary to let an XSUB, which is
  22.        really a C function in disguise, manipulate Perl values
  23.        and creates the glue necessary to let Perl access the
  24.        XSUB.  The compiler uses ttttyyyyppppeeeemmmmaaaappppssss to determine how to map
  25.        C function parameters and variables to Perl values.  The
  26.        default typemap handles many common C types.  A supplement
  27.        typemap must be created to handle special structures and
  28.        types for the library being linked.
  29.  
  30.        See the _p_e_r_l_x_s_t_u_t manpage for a tutorial on the whole
  31.        extension creation process.
  32.  
  33.        OOOOnnnn TTTThhhheeee RRRRooooaaaadddd
  34.  
  35.        Many of the examples which follow will concentrate on
  36.        creating an interface between Perl and the ONC+ RPC bind
  37.        library functions.  The _r_p_c_b___g_e_t_t_i_m_e_(_) function is used to
  38.        demonstrate many features of the XS language.  This
  39.        function has two parameters; the first is an input
  40.        parameter and the second is an output parameter.  The
  41.        function also returns a status value.
  42.  
  43.                bbbboooooooollll____tttt rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****hhhhoooosssstttt,,,, ttttiiiimmmmeeee____tttt ****ttttiiiimmmmeeeepppp))));;;;
  44.  
  45.        From C this function will be called with the following
  46.        statements.
  47.  
  48.             ####iiiinnnncccclllluuuuddddeeee <<<<rrrrppppcccc////rrrrppppcccc....hhhh>>>>
  49.             bbbboooooooollll____tttt ssssttttaaaattttuuuussss;;;;
  50.             ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp;;;;
  51.             ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( """"llllooooccccaaaallllhhhhoooosssstttt"""",,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  52.  
  53.        If an XSUB is created to offer a direct translation
  54.        between this function and Perl, then this XSUB will be
  55.        used from Perl with the following code.  The $$$$ssssttttaaaattttuuuussss and
  56.        $$$$ttttiiiimmmmeeeepppp variables will contain the output of the function.
  57.  
  58.             uuuusssseeee RRRRPPPPCCCC;;;;
  59.             $$$$ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( """"llllooooccccaaaallllhhhhoooosssstttt"""",,,, $$$$ttttiiiimmmmeeeepppp ))));;;;
  60.  
  61.  
  62.  
  63.  
  64. 15/Feb/96                perl 5.002 with                        1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  71.  
  72.  
  73.        The following XS file shows an XS subroutine, or XSUB,
  74.        which demonstrates one possible interface to the
  75.        _r_p_c_b___g_e_t_t_i_m_e_(_) function.  This XSUB represents a direct
  76.        translation between C and Perl and so preserves the
  77.        interface even from Perl.  This XSUB will be invoked from
  78.        Perl with the usage shown above.  Note that the first
  79.        three #include statements, for EEEEXXXXTTTTEEEERRRRNNNN....hhhh, ppppeeeerrrrllll....hhhh, and
  80.        XXXXSSSSUUUUBBBB....hhhh, will always be present at the beginning of an XS
  81.        file.  This approach and others will be expanded later in
  82.        this document.
  83.  
  84.             ####iiiinnnncccclllluuuuddddeeee """"EEEEXXXXTTTTEEEERRRRNNNN....hhhh""""
  85.             ####iiiinnnncccclllluuuuddddeeee """"ppppeeeerrrrllll....hhhh""""
  86.             ####iiiinnnncccclllluuuuddddeeee """"XXXXSSSSUUUUBBBB....hhhh""""
  87.             ####iiiinnnncccclllluuuuddddeeee <<<<rrrrppppcccc////rrrrppppcccc....hhhh>>>>
  88.  
  89.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== RRRRPPPPCCCC
  90.  
  91.             bbbboooooooollll____tttt
  92.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  93.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  94.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp
  95.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  96.                  ttttiiiimmmmeeeepppp
  97.  
  98.        Any extension to Perl, including those containing XSUBs,
  99.        should have a Perl module to serve as the bootstrap which
  100.        pulls the extension into Perl.  This module will export
  101.        the extension's functions and variables to the Perl
  102.        program and will cause the extension's XSUBs to be linked
  103.        into Perl.  The following module will be used for most of
  104.        the examples in this document and should be used from Perl
  105.        with the uuuusssseeee command as shown earlier.  Perl modules are
  106.        explained in more detail later in this document.
  107.  
  108.             ppppaaaacccckkkkaaaaggggeeee RRRRPPPPCCCC;;;;
  109.  
  110.             rrrreeeeqqqquuuuiiiirrrreeee EEEExxxxppppoooorrrrtttteeeerrrr;;;;
  111.             rrrreeeeqqqquuuuiiiirrrreeee DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr;;;;
  112.             @@@@IIIISSSSAAAA ==== qqqqwwww((((EEEExxxxppppoooorrrrtttteeeerrrr DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr))));;;;
  113.             @@@@EEEEXXXXPPPPOOOORRRRTTTT ==== qqqqwwww(((( rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee ))));;;;
  114.  
  115.             bbbboooooooottttssssttttrrrraaaapppp RRRRPPPPCCCC;;;;
  116.             1111;;;;
  117.  
  118.        Throughout this document a variety of interfaces to the
  119.        _r_p_c_b___g_e_t_t_i_m_e_(_) XSUB will be explored.  The XSUBs will take
  120.        their parameters in different orders or will take
  121.        different numbers of parameters.  In each case the XSUB is
  122.        an abstraction between Perl and the real C _r_p_c_b___g_e_t_t_i_m_e_(_)
  123.        function, and the XSUB must always ensure that the real
  124.        _r_p_c_b___g_e_t_t_i_m_e_(_) function is called with the correct
  125.        parameters.  This abstraction will allow the programmer to
  126.        create a more Perl-like interface to the C function.
  127.  
  128.  
  129.  
  130. 15/Feb/96                perl 5.002 with                        2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  137.  
  138.  
  139.        TTTThhhheeee AAAAnnnnaaaattttoooommmmyyyy ooooffff aaaannnn XXXXSSSSUUUUBBBB
  140.  
  141.        The following XSUB allows a Perl program to access a C
  142.        library function called _s_i_n_(_).  The XSUB will imitate the
  143.        C function which takes a single argument and returns a
  144.        single value.
  145.  
  146.             ddddoooouuuubbbblllleeee
  147.             ssssiiiinnnn((((xxxx))))
  148.               ddddoooouuuubbbblllleeee xxxx
  149.  
  150.        When using C pointers the indirection operator **** should be
  151.        considered part of the type and the address operator &&&&
  152.        should be considered part of the variable, as is
  153.        demonstrated in the _r_p_c_b___g_e_t_t_i_m_e_(_) function above.  See
  154.        the section on typemaps for more about handling qualifiers
  155.        and unary operators in C types.
  156.  
  157.        The function name and the return type must be placed on
  158.        separate lines.
  159.  
  160.          IIIINNNNCCCCOOOORRRRRRRREEEECCCCTTTT                        CCCCOOOORRRRRRRREEEECCCCTTTT
  161.  
  162.          ddddoooouuuubbbblllleeee ssssiiiinnnn((((xxxx))))                    ddddoooouuuubbbblllleeee
  163.            ddddoooouuuubbbblllleeee xxxx                       ssssiiiinnnn((((xxxx))))
  164.                                             ddddoooouuuubbbblllleeee xxxx
  165.  
  166.        The function body may be indented or left-adjusted.  The
  167.        following example shows a function with its body left-
  168.        adjusted.  Most examples in this document will indent the
  169.        body.
  170.  
  171.          CCCCOOOORRRRRRRREEEECCCCTTTT
  172.  
  173.          ddddoooouuuubbbblllleeee
  174.          ssssiiiinnnn((((xxxx))))
  175.          ddddoooouuuubbbblllleeee xxxx
  176.  
  177.  
  178.        TTTThhhheeee AAAArrrrgggguuuummmmeeeennnntttt SSSSttttaaaacccckkkk
  179.  
  180.        The argument stack is used to store the values which are
  181.        sent as parameters to the XSUB and to store the XSUB's
  182.        return value.  In reality all Perl functions keep their
  183.        values on this stack at the same time, each limited to its
  184.        own range of positions on the stack.  In this document the
  185.        first position on that stack which belongs to the active
  186.        function will be referred to as position 0 for that
  187.        function.
  188.  
  189.        XSUBs refer to their stack arguments with the macro SSSSTTTT((((xxxx)))),
  190.        where _x refers to a position in this XSUB's part of the
  191.        stack.  Position 0 for that function would be known to the
  192.        XSUB as _S_T(0).  The XSUB's incoming parameters and
  193.  
  194.  
  195.  
  196. 15/Feb/96                perl 5.002 with                        3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  203.  
  204.  
  205.        outgoing return values always begin at _S_T(0).  For many
  206.        simple cases the xxxxssssuuuubbbbpppppppp compiler will generate the code
  207.        necessary to handle the argument stack by embedding code
  208.        fragments found in the typemaps.  In more complex cases
  209.        the programmer must supply the code.
  210.  
  211.        TTTThhhheeee RRRREEEETTTTVVVVAAAALLLL VVVVaaaarrrriiiiaaaabbbblllleeee
  212.  
  213.        The RETVAL variable is a magic variable which always
  214.        matches the return type of the C library function.  The
  215.        xxxxssssuuuubbbbpppppppp compiler will supply this variable in each XSUB and
  216.        by default will use it to hold the return value of the C
  217.        library function being called.  In simple cases the value
  218.        of RETVAL will be placed in _S_T(0) of the argument stack
  219.        where it can be received by Perl as the return value of
  220.        the XSUB.
  221.  
  222.        If the XSUB has a return type of vvvvooooiiiidddd then the compiler
  223.        will not supply a RETVAL variable for that function.  When
  224.        using the PPCODE: directive the RETVAL variable may not be
  225.        needed.
  226.  
  227.        TTTThhhheeee MMMMOOOODDDDUUUULLLLEEEE KKKKeeeeyyyywwwwoooorrrrdddd
  228.  
  229.        The MODULE keyword is used to start the XS code and to
  230.        specify the package of the functions which are being
  231.        defined.  All text preceding the first MODULE keyword is
  232.        considered C code and is passed through to the output
  233.        untouched.  Every XS module will have a bootstrap function
  234.        which is used to hook the XSUBs into Perl.  The package
  235.        name of this bootstrap function will match the value of
  236.        the last MODULE statement in the XS source files.  The
  237.        value of MODULE should always remain constant within the
  238.        same XS file, though this is not required.
  239.  
  240.        The following example will start the XS code and will
  241.        place all functions in a package named RPC.
  242.  
  243.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC
  244.  
  245.  
  246.        TTTThhhheeee PPPPAAAACCCCKKKKAAAAGGGGEEEE KKKKeeeeyyyywwwwoooorrrrdddd
  247.  
  248.        When functions within an XS source file must be separated
  249.        into packages the PACKAGE keyword should be used.  This
  250.        keyword is used with the MODULE keyword and must follow
  251.        immediately after it when used.
  252.  
  253.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== RRRRPPPPCCCC
  254.  
  255.             [[[[ XXXXSSSS ccccooooddddeeee iiiinnnn ppppaaaacccckkkkaaaaggggeeee RRRRPPPPCCCC ]]]]
  256.  
  257.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== RRRRPPPPCCCCBBBB
  258.  
  259.  
  260.  
  261.  
  262. 15/Feb/96                perl 5.002 with                        4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  269.  
  270.  
  271.             [[[[ XXXXSSSS ccccooooddddeeee iiiinnnn ppppaaaacccckkkkaaaaggggeeee RRRRPPPPCCCCBBBB ]]]]
  272.  
  273.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== RRRRPPPPCCCC
  274.  
  275.             [[[[ XXXXSSSS ccccooooddddeeee iiiinnnn ppppaaaacccckkkkaaaaggggeeee RRRRPPPPCCCC ]]]]
  276.  
  277.        Although this keyword is optional and in some cases
  278.        provides redundant information it should always be used.
  279.        This keyword will ensure that the XSUBs appear in the
  280.        desired package.
  281.  
  282.        TTTThhhheeee PPPPRRRREEEEFFFFIIIIXXXX KKKKeeeeyyyywwwwoooorrrrdddd
  283.  
  284.        The PREFIX keyword designates prefixes which should be
  285.        removed from the Perl function names.  If the C function
  286.        is rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((()))) and the PREFIX value is rrrrppppccccbbbb____ then Perl
  287.        will see this function as ggggeeeettttttttiiiimmmmeeee(((()))).
  288.  
  289.        This keyword should follow the PACKAGE keyword when used.
  290.        If PACKAGE is not used then PREFIX should follow the
  291.        MODULE keyword.
  292.  
  293.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPRRRREEEEFFFFIIIIXXXX ==== rrrrppppcccc____
  294.  
  295.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== RRRRPPPPCCCCBBBB  PPPPRRRREEEEFFFFIIIIXXXX ==== rrrrppppccccbbbb____
  296.  
  297.  
  298.        TTTThhhheeee OOOOUUUUTTTTPPPPUUUUTTTT:::: KKKKeeeeyyyywwwwoooorrrrdddd
  299.  
  300.        The OUTPUT: keyword indicates that certain function
  301.        parameters should be updated (new values made visible to
  302.        Perl) when the XSUB terminates or that certain values
  303.        should be returned to the calling Perl function.  For
  304.        simple functions, such as the _s_i_n_(_) function above, the
  305.        RETVAL variable is automatically designated as an output
  306.        value.  In more complex functions the xxxxssssuuuubbbbpppppppp compiler will
  307.        need help to determine which variables are output
  308.        variables.
  309.  
  310.        This keyword will normally be used to complement the CODE:
  311.        keyword.  The RETVAL variable is not recognized as an
  312.        output variable when the CODE: keyword is present.  The
  313.        OUTPUT:  keyword is used in this situation to tell the
  314.        compiler that RETVAL really is an output variable.
  315.  
  316.        The OUTPUT: keyword can also be used to indicate that
  317.        function parameters are output variables.  This may be
  318.        necessary when a parameter has been modified within the
  319.        function and the programmer would like the update to be
  320.        seen by Perl.
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. 15/Feb/96                perl 5.002 with                        5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  335.  
  336.  
  337.             bbbboooooooollll____tttt
  338.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  339.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  340.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp
  341.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  342.                  ttttiiiimmmmeeeepppp
  343.  
  344.        The OUTPUT: keyword will also allow an output parameter to
  345.        be mapped to a matching piece of code rather than to a
  346.        typemap.
  347.  
  348.             bbbboooooooollll____tttt
  349.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  350.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  351.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp
  352.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  353.                  ttttiiiimmmmeeeepppp ssssvvvv____sssseeeettttnnnnvvvv((((SSSSTTTT((((1111)))),,,, ((((ddddoooouuuubbbblllleeee))))ttttiiiimmmmeeeepppp))));;;;
  354.  
  355.  
  356.        TTTThhhheeee CCCCOOOODDDDEEEE:::: KKKKeeeeyyyywwwwoooorrrrdddd
  357.  
  358.        This keyword is used in more complicated XSUBs which
  359.        require special handling for the C function.  The RETVAL
  360.        variable is available but will not be returned unless it
  361.        is specified under the OUTPUT: keyword.
  362.  
  363.        The following XSUB is for a C function which requires
  364.        special handling of its parameters.  The Perl usage is
  365.        given first.
  366.  
  367.             $$$$ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( """"llllooooccccaaaallllhhhhoooosssstttt"""",,,, $$$$ttttiiiimmmmeeeepppp ))));;;;
  368.  
  369.        The XSUB follows.
  370.  
  371.             bbbboooooooollll____tttt
  372.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  373.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  374.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp
  375.                  CCCCOOOODDDDEEEE::::
  376.                       RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  377.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  378.                  ttttiiiimmmmeeeepppp
  379.                  RRRREEEETTTTVVVVAAAALLLL
  380.  
  381.  
  382.        TTTThhhheeee IIIINNNNIIIITTTT:::: KKKKeeeeyyyywwwwoooorrrrdddd
  383.  
  384.        The INIT: keyword allows initialization to be inserted
  385.        into the XSUB before the compiler generates the call to
  386.        the C function.  Unlike the CODE: keyword above, this
  387.        keyword does not affect the way the compiler handles
  388.        RETVAL.
  389.  
  390.  
  391.  
  392.  
  393.  
  394. 15/Feb/96                perl 5.002 with                        6
  395.  
  396.  
  397.  
  398.  
  399.  
  400. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  401.  
  402.  
  403.            bbbboooooooollll____tttt
  404.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  405.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  406.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp
  407.                  IIIINNNNIIIITTTT::::
  408.                  pppprrrriiiinnnnttttffff((((""""#### HHHHoooosssstttt iiiissss %%%%ssss\\\\nnnn"""",,,, hhhhoooosssstttt ))));;;;
  409.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  410.                  ttttiiiimmmmeeeepppp
  411.  
  412.  
  413.        TTTThhhheeee NNNNOOOO____IIIINNNNIIIITTTT KKKKeeeeyyyywwwwoooorrrrdddd
  414.  
  415.        The NO_INIT keyword is used to indicate that a function
  416.        parameter is being used as only an output value.  The
  417.        xxxxssssuuuubbbbpppppppp compiler will normally generate code to read the
  418.        values of all function parameters from the argument stack
  419.        and assign them to C variables upon entry to the function.
  420.        NO_INIT will tell the compiler that some parameters will
  421.        be used for output rather than for input and that they
  422.        will be handled before the function terminates.
  423.  
  424.        The following example shows a variation of the
  425.        _r_p_c_b___g_e_t_t_i_m_e_(_) function.  This function uses the timep
  426.        variable as only an output variable and does not care
  427.        about its initial contents.
  428.  
  429.             bbbboooooooollll____tttt
  430.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  431.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  432.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp ==== NNNNOOOO____IIIINNNNIIIITTTT
  433.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  434.                  ttttiiiimmmmeeeepppp
  435.  
  436.  
  437.        IIIInnnniiiittttiiiiaaaalllliiiizzzziiiinnnngggg FFFFuuuunnnnccccttttiiiioooonnnn PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss
  438.  
  439.        Function parameters are normally initialized with their
  440.        values from the argument stack.  The typemaps contain the
  441.        code segments which are used to transfer the Perl values
  442.        to the C parameters.  The programmer, however, is allowed
  443.        to override the typemaps and supply alternate
  444.        initialization code.
  445.  
  446.        The following code demonstrates how to supply
  447.        initialization code for function parameters.  The
  448.        initialization code is eval'd by the compiler before it is
  449.        added to the output so anything which should be
  450.        interpreted literally, such as double quotes, must be
  451.        protected with backslashes.
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460. 15/Feb/96                perl 5.002 with                        7
  461.  
  462.  
  463.  
  464.  
  465.  
  466. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  467.  
  468.  
  469.             bbbboooooooollll____tttt
  470.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  471.                  cccchhhhaaaarrrr ****hhhhoooosssstttt ==== ((((cccchhhhaaaarrrr ****))))SSSSvvvvPPPPVVVV((((SSSSTTTT((((0000)))),,,,nnnnaaaa))));;;;
  472.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp ==== 0000;;;;
  473.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  474.                  ttttiiiimmmmeeeepppp
  475.  
  476.        This should not be used to supply default values for
  477.        parameters.  One would normally use this when a function
  478.        parameter must be processed by another library function
  479.        before it can be used.  Default parameters are covered in
  480.        the next section.
  481.  
  482.        DDDDeeeeffffaaaauuuulllltttt PPPPaaaarrrraaaammmmeeeetttteeeerrrr VVVVaaaalllluuuueeeessss
  483.  
  484.        Default values can be specified for function parameters by
  485.        placing an assignment statement in the parameter list.
  486.        The default value may be a number or a string.  Defaults
  487.        should always be used on the right-most parameters only.
  488.  
  489.        To allow the XSUB for _r_p_c_b___g_e_t_t_i_m_e_(_) to have a default
  490.        host value the parameters to the XSUB could be rearranged.
  491.        The XSUB will then call the real _r_p_c_b___g_e_t_t_i_m_e_(_) function
  492.        with the parameters in the correct order.  Perl will call
  493.        this XSUB with either of the following statements.
  494.  
  495.             $$$$ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( $$$$ttttiiiimmmmeeeepppp,,,, $$$$hhhhoooosssstttt ))));;;;
  496.  
  497.             $$$$ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( $$$$ttttiiiimmmmeeeepppp ))));;;;
  498.  
  499.        The XSUB will look like the code  which  follows.   A
  500.        CODE: block  is used to call the real _r_p_c_b___g_e_t_t_i_m_e_(_)
  501.        function with the parameters in the correct order for that
  502.        function.
  503.  
  504.             bbbboooooooollll____tttt
  505.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((ttttiiiimmmmeeeepppp,,,,hhhhoooosssstttt====""""llllooooccccaaaallllhhhhoooosssstttt""""))))
  506.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  507.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp ==== NNNNOOOO____IIIINNNNIIIITTTT
  508.                  CCCCOOOODDDDEEEE::::
  509.                       RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  510.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  511.                  ttttiiiimmmmeeeepppp
  512.                  RRRREEEETTTTVVVVAAAALLLL
  513.  
  514.  
  515.        TTTThhhheeee PPPPRRRREEEEIIIINNNNIIIITTTT:::: KKKKeeeeyyyywwwwoooorrrrdddd
  516.  
  517.        The PREINIT: keyword allows extra variables to be declared
  518.        before the typemaps are expanded.  If a variable is
  519.        declared in a CODE: block then that variable will follow
  520.        any typemap code.  This may result in a C syntax error.
  521.        To force the variable to be declared before the typemap
  522.        code, place it into a PREINIT: block.  The PREINIT:
  523.  
  524.  
  525.  
  526. 15/Feb/96                perl 5.002 with                        8
  527.  
  528.  
  529.  
  530.  
  531.  
  532. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  533.  
  534.  
  535.        keyword may be used one or more times within an XSUB.
  536.  
  537.        The following examples are equivalent, but if the code is
  538.        using complex typemaps then the first example is safer.
  539.  
  540.             bbbboooooooollll____tttt
  541.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((ttttiiiimmmmeeeepppp))))
  542.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp ==== NNNNOOOO____IIIINNNNIIIITTTT
  543.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  544.                  cccchhhhaaaarrrr ****hhhhoooosssstttt ==== """"llllooooccccaaaallllhhhhoooosssstttt"""";;;;
  545.                  CCCCOOOODDDDEEEE::::
  546.                  RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  547.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  548.                  ttttiiiimmmmeeeepppp
  549.                  RRRREEEETTTTVVVVAAAALLLL
  550.  
  551.        A correct, but error-prone example.
  552.  
  553.             bbbboooooooollll____tttt
  554.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((ttttiiiimmmmeeeepppp))))
  555.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp ==== NNNNOOOO____IIIINNNNIIIITTTT
  556.                  CCCCOOOODDDDEEEE::::
  557.                  cccchhhhaaaarrrr ****hhhhoooosssstttt ==== """"llllooooccccaaaallllhhhhoooosssstttt"""";;;;
  558.                  RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  559.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  560.                  ttttiiiimmmmeeeepppp
  561.                  RRRREEEETTTTVVVVAAAALLLL
  562.  
  563.  
  564.        TTTThhhheeee IIIINNNNPPPPUUUUTTTT:::: KKKKeeeeyyyywwwwoooorrrrdddd
  565.  
  566.        The XSUB's parameters are usually evaluated immediately
  567.        after entering the XSUB.  The INPUT: keyword can be used
  568.        to force those parameters to be evaluated a little later.
  569.        The INPUT: keyword can be used multiple times within an
  570.        XSUB and can be used to list one or more input variables.
  571.        This keyword is used with the PREINIT: keyword.
  572.  
  573.        The following example shows how the input parameter ttttiiiimmmmeeeepppp
  574.        can be evaluated late, after a PREINIT.
  575.  
  576.            bbbboooooooollll____tttt
  577.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  578.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  579.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  580.                  ttttiiiimmmmeeee____tttt tttttttt;;;;
  581.                  IIIINNNNPPPPUUUUTTTT::::
  582.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp
  583.                  CCCCOOOODDDDEEEE::::
  584.                       RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&tttttttt ))));;;;
  585.                       ttttiiiimmmmeeeepppp ==== tttttttt;;;;
  586.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  587.                  ttttiiiimmmmeeeepppp
  588.                  RRRREEEETTTTVVVVAAAALLLL
  589.  
  590.  
  591.  
  592. 15/Feb/96                perl 5.002 with                        9
  593.  
  594.  
  595.  
  596.  
  597.  
  598. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  599.  
  600.  
  601.        The next example shows each input parameter evaluated
  602.        late.
  603.  
  604.            bbbboooooooollll____tttt
  605.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  606.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  607.                  ttttiiiimmmmeeee____tttt tttttttt;;;;
  608.                  IIIINNNNPPPPUUUUTTTT::::
  609.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  610.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  611.                  cccchhhhaaaarrrr ****hhhh;;;;
  612.                  IIIINNNNPPPPUUUUTTTT::::
  613.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp
  614.                  CCCCOOOODDDDEEEE::::
  615.                       hhhh ==== hhhhoooosssstttt;;;;
  616.                       RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhh,,,, &&&&tttttttt ))));;;;
  617.                       ttttiiiimmmmeeeepppp ==== tttttttt;;;;
  618.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  619.                  ttttiiiimmmmeeeepppp
  620.                  RRRREEEETTTTVVVVAAAALLLL
  621.  
  622.  
  623.        VVVVaaaarrrriiiiaaaabbbblllleeee----lllleeeennnnggggtttthhhh PPPPaaaarrrraaaammmmeeeetttteeeerrrr LLLLiiiissssttttssss
  624.  
  625.        XSUBs can have variable-length parameter lists by
  626.        specifying an ellipsis ((((............)))) in the parameter list.  This
  627.        use of the ellipsis is similar to that found in ANSI C.
  628.        The programmer is able to determine the number of
  629.        arguments passed to the XSUB by examining the iiiitttteeeemmmmssss
  630.        variable which the xxxxssssuuuubbbbpppppppp compiler supplies for all XSUBs.
  631.        By using this mechanism one can create an XSUB which
  632.        accepts a list of parameters of unknown length.
  633.  
  634.        The _h_o_s_t parameter for the _r_p_c_b___g_e_t_t_i_m_e_(_) XSUB can be
  635.        optional so the ellipsis can be used to indicate that the
  636.        XSUB will take a variable number of parameters.  Perl
  637.        should be able to call this XSUB with either of the
  638.        following statements.
  639.  
  640.             $$$$ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( $$$$ttttiiiimmmmeeeepppp,,,, $$$$hhhhoooosssstttt ))));;;;
  641.  
  642.             $$$$ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( $$$$ttttiiiimmmmeeeepppp ))));;;;
  643.  
  644.        The XS code, with ellipsis, follows.
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658. 15/Feb/96                perl 5.002 with                       10
  659.  
  660.  
  661.  
  662.  
  663.  
  664. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  665.  
  666.  
  667.             bbbboooooooollll____tttt
  668.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((ttttiiiimmmmeeeepppp,,,, ............))))
  669.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp ==== NNNNOOOO____IIIINNNNIIIITTTT
  670.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  671.                  cccchhhhaaaarrrr ****hhhhoooosssstttt ==== """"llllooooccccaaaallllhhhhoooosssstttt"""";;;;
  672.                  CCCCOOOODDDDEEEE::::
  673.                          iiiiffff(((( iiiitttteeeemmmmssss >>>> 1111 ))))
  674.                               hhhhoooosssstttt ==== ((((cccchhhhaaaarrrr ****))))SSSSvvvvPPPPVVVV((((SSSSTTTT((((1111)))),,,, nnnnaaaa))));;;;
  675.                          RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  676.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  677.                  ttttiiiimmmmeeeepppp
  678.                  RRRREEEETTTTVVVVAAAALLLL
  679.  
  680.  
  681.        TTTThhhheeee PPPPPPPPCCCCOOOODDDDEEEE:::: KKKKeeeeyyyywwwwoooorrrrdddd
  682.  
  683.        The PPCODE: keyword is an alternate form of the CODE:
  684.        keyword and is used to tell the xxxxssssuuuubbbbpppppppp compiler that the
  685.        programmer is supplying the code to control the argument
  686.        stack for the XSUBs return values.  Occasionally one will
  687.        want an XSUB to return a list of values rather than a
  688.        single value.  In these cases one must use PPCODE: and
  689.        then explicitly push the list of values on the stack.  The
  690.        PPCODE: and CODE:  keywords are not used together within
  691.        the same XSUB.
  692.  
  693.        The following XSUB will call the C _r_p_c_b___g_e_t_t_i_m_e_(_) function
  694.        and will return its two output values, timep and status,
  695.        to Perl as a single list.
  696.  
  697.             vvvvooooiiiidddd
  698.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt))))
  699.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  700.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  701.                  ttttiiiimmmmeeee____tttt  ttttiiiimmmmeeeepppp;;;;
  702.                  bbbboooooooollll____tttt  ssssttttaaaattttuuuussss;;;;
  703.                  PPPPPPPPCCCCOOOODDDDEEEE::::
  704.                  ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  705.                  EEEEXXXXTTTTEEEENNNNDDDD((((sssspppp,,,, 2222))));;;;
  706.                  PPPPUUUUSSSSHHHHssss((((ssssvvvv____2222mmmmoooorrrrttttaaaallll((((nnnneeeewwwwSSSSVVVViiiivvvv((((ssssttttaaaattttuuuussss))))))))))));;;;
  707.                  PPPPUUUUSSSSHHHHssss((((ssssvvvv____2222mmmmoooorrrrttttaaaallll((((nnnneeeewwwwSSSSVVVViiiivvvv((((ttttiiiimmmmeeeepppp))))))))))));;;;
  708.  
  709.        Notice that the programmer must supply the C code
  710.        necessary to have the real _r_p_c_b___g_e_t_t_i_m_e_(_) function called
  711.        and to have the return values properly placed on the
  712.        argument stack.
  713.  
  714.        The vvvvooooiiiidddd return type for this function tells the xxxxssssuuuubbbbpppppppp
  715.        compiler that the RETVAL variable is not needed or used
  716.        and that it should not be created.  In most scenarios the
  717.        void return type should be used with the PPCODE:
  718.        directive.
  719.  
  720.        The _E_X_T_E_N_D_(_) macro is used to make room on the argument
  721.  
  722.  
  723.  
  724. 15/Feb/96                perl 5.002 with                       11
  725.  
  726.  
  727.  
  728.  
  729.  
  730. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  731.  
  732.  
  733.        stack for 2 return values.  The PPCODE: directive causes
  734.        the xxxxssssuuuubbbbpppppppp compiler to create a stack pointer called sssspppp,
  735.        and it is this pointer which is being used in the _E_X_T_E_N_D_(_)
  736.        macro.  The values are then pushed onto the stack with the
  737.        _P_U_S_H_s_(_) macro.
  738.  
  739.        Now the _r_p_c_b___g_e_t_t_i_m_e_(_) function can be used from Perl with
  740.        the following statement.
  741.  
  742.             (((($$$$ssssttttaaaattttuuuussss,,,, $$$$ttttiiiimmmmeeeepppp)))) ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((""""llllooooccccaaaallllhhhhoooosssstttt""""))));;;;
  743.  
  744.  
  745.        RRRReeeettttuuuurrrrnnnniiiinnnngggg UUUUnnnnddddeeeeffff AAAAnnnndddd EEEEmmmmppppttttyyyy LLLLiiiissssttttssss
  746.  
  747.        Occasionally the programmer will want to simply return
  748.        uuuunnnnddddeeeeffff or an empty list if a function fails rather than a
  749.        separate status value.  The _r_p_c_b___g_e_t_t_i_m_e_(_) function offers
  750.        just this situation.  If the function succeeds we would
  751.        like to have it return the time and if it fails we would
  752.        like to have undef returned.  In the following Perl code
  753.        the value of $$$$ttttiiiimmmmeeeepppp will either be undef or it will be a
  754.        valid time.
  755.  
  756.             $$$$ttttiiiimmmmeeeepppp ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( """"llllooooccccaaaallllhhhhoooosssstttt"""" ))));;;;
  757.  
  758.        The following XSUB uses the vvvvooooiiiidddd return type to disable
  759.        the generation of the RETVAL variable and uses a CODE:
  760.        block to indicate to the compiler that the programmer has
  761.        supplied all the necessary code.  The _s_v___n_e_w_m_o_r_t_a_l_(_) call
  762.        will initialize the return value to undef, making that the
  763.        default return value.
  764.  
  765.             vvvvooooiiiidddd
  766.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt))))
  767.                  cccchhhhaaaarrrr ****  hhhhoooosssstttt
  768.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  769.                  ttttiiiimmmmeeee____tttt  ttttiiiimmmmeeeepppp;;;;
  770.                  bbbboooooooollll____tttt xxxx;;;;
  771.                  CCCCOOOODDDDEEEE::::
  772.                  SSSSTTTT((((0000)))) ==== ssssvvvv____nnnneeeewwwwmmmmoooorrrrttttaaaallll(((())));;;;
  773.                  iiiiffff(((( rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp )))) ))))
  774.                       ssssvvvv____sssseeeettttnnnnvvvv(((( SSSSTTTT((((0000)))),,,, ((((ddddoooouuuubbbblllleeee))))ttttiiiimmmmeeeepppp))));;;;
  775.  
  776.        The next example demonstrates how one would place an
  777.        explicit undef in the return value, should the need arise.
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790. 15/Feb/96                perl 5.002 with                       12
  791.  
  792.  
  793.  
  794.  
  795.  
  796. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  797.  
  798.  
  799.             vvvvooooiiiidddd
  800.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt))))
  801.                  cccchhhhaaaarrrr ****  hhhhoooosssstttt
  802.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  803.                  ttttiiiimmmmeeee____tttt  ttttiiiimmmmeeeepppp;;;;
  804.                  bbbboooooooollll____tttt xxxx;;;;
  805.                  CCCCOOOODDDDEEEE::::
  806.                  SSSSTTTT((((0000)))) ==== ssssvvvv____nnnneeeewwwwmmmmoooorrrrttttaaaallll(((())));;;;
  807.                  iiiiffff(((( rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp )))) )))){{{{
  808.                       ssssvvvv____sssseeeettttnnnnvvvv(((( SSSSTTTT((((0000)))),,,, ((((ddddoooouuuubbbblllleeee))))ttttiiiimmmmeeeepppp))));;;;
  809.                  }}}}
  810.                  eeeellllsssseeee{{{{
  811.                       SSSSTTTT((((0000)))) ==== &&&&ssssvvvv____uuuunnnnddddeeeeffff;;;;
  812.                  }}}}
  813.  
  814.        To return an empty list one must use a PPCODE: block and
  815.        then not push return values on the stack.
  816.  
  817.             vvvvooooiiiidddd
  818.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt))))
  819.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  820.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  821.                  ttttiiiimmmmeeee____tttt  ttttiiiimmmmeeeepppp;;;;
  822.                  PPPPPPPPCCCCOOOODDDDEEEE::::
  823.                  iiiiffff(((( rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp )))) ))))
  824.                       PPPPUUUUSSSSHHHHssss((((ssssvvvv____2222mmmmoooorrrrttttaaaallll((((nnnneeeewwwwSSSSVVVViiiivvvv((((ttttiiiimmmmeeeepppp))))))))))));;;;
  825.                  eeeellllsssseeee{{{{
  826.                  ////**** NNNNooootttthhhhiiiinnnngggg ppppuuuusssshhhheeeedddd oooonnnn ssssttttaaaacccckkkk,,,, ssssoooo aaaannnn eeeemmmmppppttttyyyy ****////
  827.                  ////**** lllliiiisssstttt iiiissss iiiimmmmpppplllliiiicccciiiittttllllyyyy rrrreeeettttuuuurrrrnnnneeeedddd.... ****////
  828.                  }}}}
  829.  
  830.  
  831.        TTTThhhheeee RRRREEEEQQQQUUUUIIIIRRRREEEE:::: KKKKeeeeyyyywwwwoooorrrrdddd
  832.  
  833.        The REQUIRE: keyword is used to indicate the minimum
  834.        version of the xxxxssssuuuubbbbpppppppp compiler needed to compile the XS
  835.        module.  An XS module which contains the following
  836.        statement will only compile with xxxxssssuuuubbbbpppppppp version 1.922 or
  837.        greater:
  838.  
  839.                RRRREEEEQQQQUUUUIIIIRRRREEEE:::: 1111....999922222222
  840.  
  841.  
  842.        TTTThhhheeee CCCCLLLLEEEEAAAANNNNUUUUPPPP:::: KKKKeeeeyyyywwwwoooorrrrdddd
  843.  
  844.        This keyword can be used when an XSUB requires special
  845.        cleanup procedures before it terminates.  When the
  846.        CLEANUP:  keyword is used it must follow any CODE:,
  847.        PPCODE:, or OUTPUT: blocks which are present in the XSUB.
  848.        The code specified for the cleanup block will be added as
  849.        the last statements in the XSUB.
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856. 15/Feb/96                perl 5.002 with                       13
  857.  
  858.  
  859.  
  860.  
  861.  
  862. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  863.  
  864.  
  865.        TTTThhhheeee BBBBOOOOOOOOTTTT:::: KKKKeeeeyyyywwwwoooorrrrdddd
  866.  
  867.        The BOOT: keyword is used to add code to the extension's
  868.        bootstrap function.  The bootstrap function is generated
  869.        by the xxxxssssuuuubbbbpppppppp compiler and normally holds the statements
  870.        necessary to register any XSUBs with Perl.  With the BOOT:
  871.        keyword the programmer can tell the compiler to add extra
  872.        statements to the bootstrap function.
  873.  
  874.        This keyword may be used any time after the first MODULE
  875.        keyword and should appear on a line by itself.  The first
  876.        blank line after the keyword will terminate the code
  877.        block.
  878.  
  879.             BBBBOOOOOOOOTTTT::::
  880.             #### TTTThhhheeee ffffoooolllllllloooowwwwiiiinnnngggg mmmmeeeessssssssaaaaggggeeee wwwwiiiillllllll bbbbeeee pppprrrriiiinnnntttteeeedddd wwwwhhhheeeennnn tttthhhheeee
  881.             #### bbbboooooooottttssssttttrrrraaaapppp ffffuuuunnnnccccttttiiiioooonnnn eeeexxxxeeeeccccuuuutttteeeessss....
  882.             pppprrrriiiinnnnttttffff((((""""HHHHeeeelllllllloooo ffffrrrroooommmm tttthhhheeee bbbboooooooottttssssttttrrrraaaapppp!!!!\\\\nnnn""""))));;;;
  883.  
  884.  
  885.        TTTThhhheeee VVVVEEEERRRRSSSSIIIIOOOONNNNCCCCHHHHEEEECCCCKKKK:::: KKKKeeeeyyyywwwwoooorrrrdddd
  886.  
  887.        The VERSIONCHECK: keyword corresponds to xxxxssssuuuubbbbpppppppp's
  888.        ----vvvveeeerrrrssssiiiioooonnnncccchhhheeeecccckkkk and ----nnnnoooovvvveeeerrrrssssiiiioooonnnncccchhhheeeecccckkkk options.  This keyword
  889.        overrides the commandline options.  Version checking is
  890.        enabled by default.  When version checking is enabled the
  891.        XS module will attempt to verify that its version matches
  892.        the version of the PM module.
  893.  
  894.        To enable version checking:
  895.  
  896.            VVVVEEEERRRRSSSSIIIIOOOONNNNCCCCHHHHEEEECCCCKKKK:::: EEEENNNNAAAABBBBLLLLEEEE
  897.  
  898.        To disable version checking:
  899.  
  900.            VVVVEEEERRRRSSSSIIIIOOOONNNNCCCCHHHHEEEECCCCKKKK:::: DDDDIIIISSSSAAAABBBBLLLLEEEE
  901.  
  902.  
  903.        TTTThhhheeee PPPPRRRROOOOTTTTOOOOTTTTYYYYPPPPEEEESSSS:::: KKKKeeeeyyyywwwwoooorrrrdddd
  904.  
  905.        The PROTOTYPES: keyword corresponds to xxxxssssuuuubbbbpppppppp's
  906.        ----pppprrrroooottttoooottttyyyyppppeeeessss and ----nnnnoooopppprrrroooottttoooottttyyyyppppeeeessss options.  This keyword
  907.        overrides the commandline options.  Prototypes are enabled
  908.        by default.  When prototypes are enabled XSUBs will be
  909.        given Perl prototypes.  This keyword may be used multiple
  910.        times in an XS module to enable and disable prototypes for
  911.        different parts of the module.
  912.  
  913.        To enable prototypes:
  914.  
  915.            PPPPRRRROOOOTTTTOOOOTTTTYYYYPPPPEEEESSSS:::: EEEENNNNAAAABBBBLLLLEEEE
  916.  
  917.        To disable prototypes:
  918.  
  919.  
  920.  
  921.  
  922. 15/Feb/96                perl 5.002 with                       14
  923.  
  924.  
  925.  
  926.  
  927.  
  928. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  929.  
  930.  
  931.            PPPPRRRROOOOTTTTOOOOTTTTYYYYPPPPEEEESSSS:::: DDDDIIIISSSSAAAABBBBLLLLEEEE
  932.  
  933.  
  934.        TTTThhhheeee PPPPRRRROOOOTTTTOOOOTTTTYYYYPPPPEEEE:::: KKKKeeeeyyyywwwwoooorrrrdddd
  935.  
  936.        This keyword is similar to the PROTOTYPES: keyword above
  937.        but can be used to force xxxxssssuuuubbbbpppppppp to use a specific
  938.        prototype for the XSUB.  This keyword overrides all other
  939.        prototype options and keywords but affects only the
  940.        current XSUB.  Consult the PPPPrrrroooottttoooottttyyyyppppeeeessss entry in the _p_e_r_l_s_u_b
  941.        manpage for information about Perl prototypes.
  942.  
  943.            bbbboooooooollll____tttt
  944.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((ttttiiiimmmmeeeepppp,,,, ............))))
  945.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp ==== NNNNOOOO____IIIINNNNIIIITTTT
  946.                  PPPPRRRROOOOTTTTOOOOTTTTYYYYPPPPEEEE:::: $$$$;;;;$$$$
  947.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  948.                  cccchhhhaaaarrrr ****hhhhoooosssstttt ==== """"llllooooccccaaaallllhhhhoooosssstttt"""";;;;
  949.                  CCCCOOOODDDDEEEE::::
  950.                          iiiiffff(((( iiiitttteeeemmmmssss >>>> 1111 ))))
  951.                               hhhhoooosssstttt ==== ((((cccchhhhaaaarrrr ****))))SSSSvvvvPPPPVVVV((((SSSSTTTT((((1111)))),,,, nnnnaaaa))));;;;
  952.                          RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp ))));;;;
  953.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  954.                  ttttiiiimmmmeeeepppp
  955.                  RRRREEEETTTTVVVVAAAALLLL
  956.  
  957.  
  958.        TTTThhhheeee AAAALLLLIIIIAAAASSSS:::: KKKKeeeeyyyywwwwoooorrrrdddd
  959.  
  960.        The ALIAS: keyword allows an XSUB to have two more more
  961.        unique Perl names and to know which of those names was
  962.        used when it was invoked.  The Perl names may be fully-
  963.        qualified with package names.  Each alias is given an
  964.        index.  The compiler will setup a variable called iiiixxxx which
  965.        contain the index of the alias which was used.  When the
  966.        XSUB is called with its declared name iiiixxxx will be 0.
  967.  
  968.        The following example will create aliases FFFFOOOOOOOO::::::::ggggeeeettttttttiiiimmmmeeee(((())))
  969.        and BBBBAAAARRRR::::::::ggggeeeettttiiiitttt(((()))) for this function.
  970.  
  971.            bbbboooooooollll____tttt
  972.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  973.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  974.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp
  975.                  AAAALLLLIIIIAAAASSSS::::
  976.                    FFFFOOOOOOOO::::::::ggggeeeettttttttiiiimmmmeeee ==== 1111
  977.                    BBBBAAAARRRR::::::::ggggeeeettttiiiitttt ==== 2222
  978.                  IIIINNNNIIIITTTT::::
  979.                  pppprrrriiiinnnnttttffff((((""""#### iiiixxxx ==== %%%%dddd\\\\nnnn"""",,,, iiiixxxx ))));;;;
  980.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  981.                  ttttiiiimmmmeeeepppp
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988. 15/Feb/96                perl 5.002 with                       15
  989.  
  990.  
  991.  
  992.  
  993.  
  994. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  995.  
  996.  
  997.        TTTThhhheeee IIIINNNNCCCCLLLLUUUUDDDDEEEE:::: KKKKeeeeyyyywwwwoooorrrrdddd
  998.  
  999.        This keyword can be used to pull other files into the XS
  1000.        module.  The other files may have XS code.  INCLUDE: can
  1001.        also be used to run a command to generate the XS code to
  1002.        be pulled into the module.
  1003.  
  1004.        The file _R_p_c_b_1_._x_s_h contains our rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((()))) function:
  1005.  
  1006.            bbbboooooooollll____tttt
  1007.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  1008.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  1009.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp
  1010.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  1011.                  ttttiiiimmmmeeeepppp
  1012.  
  1013.        The XS module can use INCLUDE: to pull that file into it.
  1014.  
  1015.            IIIINNNNCCCCLLLLUUUUDDDDEEEE:::: RRRRppppccccbbbb1111....xxxxsssshhhh
  1016.  
  1017.        If the parameters to the INCLUDE: keyword are followed by
  1018.        a pipe (||||) then the compiler will interpret the parameters
  1019.        as a command.
  1020.  
  1021.            IIIINNNNCCCCLLLLUUUUDDDDEEEE:::: ccccaaaatttt RRRRppppccccbbbb1111....xxxxsssshhhh ||||
  1022.  
  1023.  
  1024.        TTTThhhheeee CCCCAAAASSSSEEEE:::: KKKKeeeeyyyywwwwoooorrrrdddd
  1025.  
  1026.        The CASE: keyword allows an XSUB to have multiple distinct
  1027.        parts with each part acting as a virtual XSUB.  CASE: is
  1028.        greedy and if it is used then all other XS keywords must
  1029.        be contained within a CASE:.  This means nothing may
  1030.        precede the first CASE: in the XSUB and anything following
  1031.        the last CASE: is included in that case.
  1032.  
  1033.        A CASE: might switch via a parameter of the XSUB, via the
  1034.        iiiixxxx ALIAS: variable (see the section on _T_h_e _A_L_I_A_S_:
  1035.        _K_e_y_w_o_r_d), or maybe via the iiiitttteeeemmmmssss variable (see the section
  1036.        on _V_a_r_i_a_b_l_e_-_l_e_n_g_t_h _P_a_r_a_m_e_t_e_r _L_i_s_t_s).  The last CASE:
  1037.        becomes the ddddeeeeffffaaaauuuulllltttt case if it is not associated with a
  1038.        conditional.  The following example shows CASE switched
  1039.        via iiiixxxx with a function rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((()))) having an alias
  1040.        xxxx____ggggeeeettttttttiiiimmmmeeee(((()))).  When the function is called as
  1041.        rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((()))) it's parameters are the usual ((((cccchhhhaaaarrrr ****hhhhoooosssstttt,,,,
  1042.        ttttiiiimmmmeeee____tttt ****ttttiiiimmmmeeeepppp)))), but when the function is called as
  1043.        xxxx____ggggeeeettttttttiiiimmmmeeee(((()))) is parameters are reversed, ((((ttttiiiimmmmeeee____tttt ****ttttiiiimmmmeeeepppp,,,,
  1044.        cccchhhhaaaarrrr ****hhhhoooosssstttt)))).
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054. 15/Feb/96                perl 5.002 with                       16
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1061.  
  1062.  
  1063.            lllloooonnnngggg
  1064.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((aaaa,,,,bbbb))))
  1065.              CCCCAAAASSSSEEEE:::: iiiixxxx ======== 1111
  1066.                  AAAALLLLIIIIAAAASSSS::::
  1067.                  xxxx____ggggeeeettttttttiiiimmmmeeee ==== 1111
  1068.                  IIIINNNNPPPPUUUUTTTT::::
  1069.                  #### ''''aaaa'''' iiiissss ttttiiiimmmmeeeepppp,,,, ''''bbbb'''' iiiissss hhhhoooosssstttt
  1070.                  cccchhhhaaaarrrr ****bbbb
  1071.                  ttttiiiimmmmeeee____tttt aaaa ==== NNNNOOOO____IIIINNNNIIIITTTT
  1072.                  CCCCOOOODDDDEEEE::::
  1073.                       RRRREEEETTTTVVVVAAAALLLL ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( bbbb,,,, &&&&aaaa ))));;;;
  1074.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  1075.                  aaaa
  1076.                  RRRREEEETTTTVVVVAAAALLLL
  1077.              CCCCAAAASSSSEEEE::::
  1078.                  #### ''''aaaa'''' iiiissss hhhhoooosssstttt,,,, ''''bbbb'''' iiiissss ttttiiiimmmmeeeepppp
  1079.                  cccchhhhaaaarrrr ****aaaa
  1080.                  ttttiiiimmmmeeee____tttt &&&&bbbb ==== NNNNOOOO____IIIINNNNIIIITTTT
  1081.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  1082.                  bbbb
  1083.                  RRRREEEETTTTVVVVAAAALLLL
  1084.  
  1085.        That function can be called with either of the following
  1086.        statements.  Note the different argument lists.
  1087.  
  1088.                $$$$ssssttttaaaattttuuuussss ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( $$$$hhhhoooosssstttt,,,, $$$$ttttiiiimmmmeeeepppp ))));;;;
  1089.  
  1090.                $$$$ssssttttaaaattttuuuussss ==== xxxx____ggggeeeettttttttiiiimmmmeeee(((( $$$$ttttiiiimmmmeeeepppp,,,, $$$$hhhhoooosssstttt ))));;;;
  1091.  
  1092.  
  1093.        TTTThhhheeee &&&& UUUUnnnnaaaarrrryyyy OOOOppppeeeerrrraaaattttoooorrrr
  1094.  
  1095.        The & unary operator is used to tell the compiler that it
  1096.        should dereference the object when it calls the C
  1097.        function.  This is used when a CODE: block is not used and
  1098.        the object is a not a pointer type (the object is an iiiinnnntttt
  1099.        or lllloooonnnngggg but not a iiiinnnntttt**** or lllloooonnnngggg****).
  1100.  
  1101.        The following XSUB will generate incorrect C code.  The
  1102.        xsubpp compiler will turn this into code which calls
  1103.        rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((()))) with parameters ((((cccchhhhaaaarrrr ****hhhhoooosssstttt,,,, ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp)))),
  1104.        but the real rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((()))) wants the ttttiiiimmmmeeeepppp parameter to
  1105.        be of type ttttiiiimmmmeeee____tttt**** rather than ttttiiiimmmmeeee____tttt.
  1106.  
  1107.            bbbboooooooollll____tttt
  1108.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  1109.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  1110.                  ttttiiiimmmmeeee____tttt ttttiiiimmmmeeeepppp
  1111.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  1112.                  ttttiiiimmmmeeeepppp
  1113.  
  1114.        That problem is corrected by using the &&&& operator.  The
  1115.        xsubpp compiler will now turn this into code which calls
  1116.        rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((()))) correctly with parameters ((((cccchhhhaaaarrrr ****hhhhoooosssstttt,,,,
  1117.  
  1118.  
  1119.  
  1120. 15/Feb/96                perl 5.002 with                       17
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1127.  
  1128.  
  1129.        ttttiiiimmmmeeee____tttt ****ttttiiiimmmmeeeepppp)))).  It does this by carrying the &&&& through,
  1130.        so the function call looks like rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,
  1131.        &&&&ttttiiiimmmmeeeepppp)))).
  1132.  
  1133.            bbbboooooooollll____tttt
  1134.            rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt,,,,ttttiiiimmmmeeeepppp))))
  1135.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  1136.                  ttttiiiimmmmeeee____tttt &&&&ttttiiiimmmmeeeepppp
  1137.                  OOOOUUUUTTTTPPPPUUUUTTTT::::
  1138.                  ttttiiiimmmmeeeepppp
  1139.  
  1140.  
  1141.        IIIInnnnsssseeeerrrrttttiiiinnnngggg CCCCoooommmmmmmmeeeennnnttttssss aaaannnndddd CCCC PPPPrrrreeeepppprrrroooocccceeeessssssssoooorrrr DDDDiiiirrrreeeeccccttttiiiivvvveeeessss
  1142.  
  1143.        Comments and C preprocessor directives are allowed within
  1144.        CODE:, PPCODE:, BOOT:, and CLEANUP: blocks.  The compiler
  1145.        will pass the preprocessor directives through untouched
  1146.        and will remove the commented lines.  Comments can be
  1147.        added to XSUBs by placing a #### at the beginning of the
  1148.        line.  Care should be taken to avoid making the comment
  1149.        look like a C preprocessor directive, lest it be
  1150.        interpreted as such.
  1151.  
  1152.        UUUUssssiiiinnnngggg XXXXSSSS WWWWiiiitttthhhh CCCC++++++++
  1153.  
  1154.        If a function is defined as a C++ method then it will
  1155.        assume its first argument is an object pointer.  The
  1156.        object pointer will be stored in a variable called THIS.
  1157.        The object should have been created by C++ with the _n_e_w_(_)
  1158.        function and should be blessed by Perl with the
  1159.        _s_v___s_e_t_r_e_f___p_v_(_) macro.  The blessing of the object by Perl
  1160.        can be handled by a typemap.  An example typemap is shown
  1161.        at the end of this section.
  1162.  
  1163.        If the method is defined as static it will call the C++
  1164.        function using the _c_l_a_s_s_:_:_m_e_t_h_o_d_(_) syntax.  If the method
  1165.        is not static the function will be called using the
  1166.        THIS->_m_e_t_h_o_d_(_) syntax.
  1167.  
  1168.        The next examples will use the following C++ class.
  1169.  
  1170.             ccccllllaaaassssssss ccccoooolllloooorrrr {{{{
  1171.                  ppppuuuubbbblllliiiicccc::::
  1172.                  ccccoooolllloooorrrr(((())));;;;
  1173.                  ~~~~ccccoooolllloooorrrr(((())));;;;
  1174.                  iiiinnnntttt bbbblllluuuueeee(((())));;;;
  1175.                  vvvvooooiiiidddd sssseeeetttt____bbbblllluuuueeee(((( iiiinnnntttt ))));;;;
  1176.  
  1177.                  pppprrrriiiivvvvaaaatttteeee::::
  1178.                  iiiinnnntttt cccc____bbbblllluuuueeee;;;;
  1179.             }}}};;;;
  1180.  
  1181.        The XSUBs for the _b_l_u_e_(_) and _s_e_t___b_l_u_e_(_) methods are
  1182.        defined with the class name but the parameter for the
  1183.  
  1184.  
  1185.  
  1186. 15/Feb/96                perl 5.002 with                       18
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1193.  
  1194.  
  1195.        object (THIS, or "self") is implicit and is not listed.
  1196.  
  1197.             iiiinnnntttt
  1198.             ccccoooolllloooorrrr::::::::bbbblllluuuueeee(((())))
  1199.  
  1200.             vvvvooooiiiidddd
  1201.             ccccoooolllloooorrrr::::::::sssseeeetttt____bbbblllluuuueeee(((( vvvvaaaallll ))))
  1202.                  iiiinnnntttt vvvvaaaallll
  1203.  
  1204.        Both functions will expect an object as the first
  1205.        parameter.  The xsubpp compiler will call that object TTTTHHHHIIIISSSS
  1206.        and will use it to call the specified method.  So in the
  1207.        C++ code the _b_l_u_e_(_) and _s_e_t___b_l_u_e_(_) methods will be called
  1208.        in the following manner.
  1209.  
  1210.             RRRREEEETTTTVVVVAAAALLLL ==== TTTTHHHHIIIISSSS---->>>>bbbblllluuuueeee(((())));;;;
  1211.  
  1212.             TTTTHHHHIIIISSSS---->>>>sssseeeetttt____bbbblllluuuueeee(((( vvvvaaaallll ))));;;;
  1213.  
  1214.        If the function's name is DDDDEEEESSSSTTTTRRRROOOOYYYY then the C++ ddddeeeelllleeeetttteeee
  1215.        function will be called and TTTTHHHHIIIISSSS will be given as its
  1216.        parameter.
  1217.  
  1218.             vvvvooooiiiidddd
  1219.             ccccoooolllloooorrrr::::::::DDDDEEEESSSSTTTTRRRROOOOYYYY(((())))
  1220.  
  1221.        The C++ code will call ddddeeeelllleeeetttteeee.
  1222.  
  1223.             ddddeeeelllleeeetttteeee TTTTHHHHIIIISSSS;;;;
  1224.  
  1225.        If the function's name is nnnneeeewwww then the C++ nnnneeeewwww function
  1226.        will be called to create a dynamic C++ object.  The XSUB
  1227.        will expect the class name, which will be kept in a
  1228.        variable called CCCCLLLLAAAASSSSSSSS, to be given as the first argument.
  1229.  
  1230.             ccccoooolllloooorrrr ****
  1231.             ccccoooolllloooorrrr::::::::nnnneeeewwww(((())))
  1232.  
  1233.        The C++ code will call nnnneeeewwww.
  1234.  
  1235.                RRRREEEETTTTVVVVAAAALLLL ==== nnnneeeewwww ccccoooolllloooorrrr(((())));;;;
  1236.  
  1237.        The following is an example of a typemap that could be
  1238.        used for this C++ example.
  1239.  
  1240.            TTTTYYYYPPPPEEEEMMMMAAAAPPPP
  1241.            ccccoooolllloooorrrr ****             OOOO____OOOOBBBBJJJJEEEECCCCTTTT
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252. 15/Feb/96                perl 5.002 with                       19
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1259.  
  1260.  
  1261.            OOOOUUUUTTTTPPPPUUUUTTTT
  1262.            #### TTTThhhheeee PPPPeeeerrrrllll oooobbbbjjjjeeeecccctttt iiiissss bbbblllleeeesssssssseeeedddd iiiinnnnttttoooo ''''CCCCLLLLAAAASSSSSSSS'''',,,, wwwwhhhhiiiicccchhhh sssshhhhoooouuuulllldddd bbbbeeee aaaa
  1263.            #### cccchhhhaaaarrrr**** hhhhaaaavvvviiiinnnngggg tttthhhheeee nnnnaaaammmmeeee ooooffff tttthhhheeee ppppaaaacccckkkkaaaaggggeeee ffffoooorrrr tttthhhheeee bbbblllleeeessssssssiiiinnnngggg....
  1264.            OOOO____OOOOBBBBJJJJEEEECCCCTTTT
  1265.                ssssvvvv____sssseeeettttrrrreeeeffff____ppppvvvv(((( $$$$aaaarrrrgggg,,,, CCCCLLLLAAAASSSSSSSS,,,, ((((vvvvooooiiiidddd****))))$$$$vvvvaaaarrrr ))));;;;
  1266.  
  1267.            IIIINNNNPPPPUUUUTTTT
  1268.            OOOO____OOOOBBBBJJJJEEEECCCCTTTT
  1269.                iiiiffff(((( ssssvvvv____iiiissssoooobbbbjjjjeeeecccctttt(((($$$$aaaarrrrgggg)))) &&&&&&&& ((((SSSSvvvvTTTTYYYYPPPPEEEE((((SSSSvvvvRRRRVVVV(((($$$$aaaarrrrgggg)))))))) ======== SSSSVVVVtttt____PPPPVVVVMMMMGGGG)))) ))))
  1270.                        $$$$vvvvaaaarrrr ==== (((($$$$ttttyyyyppppeeee))))SSSSvvvvIIIIVVVV((((((((SSSSVVVV****))))SSSSvvvvRRRRVVVV(((( $$$$aaaarrrrgggg ))))))));;;;
  1271.                eeeellllsssseeee{{{{
  1272.                        wwwwaaaarrrrnnnn(((( \\\\""""$$$${{{{PPPPaaaacccckkkkaaaaggggeeee}}}}::::::::$$$$ffffuuuunnnncccc____nnnnaaaammmmeeee(((()))) -------- $$$$vvvvaaaarrrr iiiissss nnnnooootttt aaaa bbbblllleeeesssssssseeeedddd SSSSVVVV rrrreeeeffffeeeerrrreeeennnncccceeee\\\\"""" ))));;;;
  1273.                        XXXXSSSSRRRREEEETTTTUUUURRRRNNNN____UUUUNNNNDDDDEEEEFFFF;;;;
  1274.                }}}}
  1275.  
  1276.  
  1277.        IIIInnnntttteeeerrrrffffaaaacccceeee SSSSttttrrrraaaatttteeeeggggyyyy
  1278.  
  1279.        When designing an interface between Perl and a C library a
  1280.        straight translation from C to XS is often sufficient.
  1281.        The interface will often be very C-like and occasionally
  1282.        nonintuitive, especially when the C function modifies one
  1283.        of its parameters.  In cases where the programmer wishes
  1284.        to create a more Perl-like interface the following
  1285.        strategy may help to identify the more critical parts of
  1286.        the interface.
  1287.  
  1288.        Identify the C functions which modify their parameters.
  1289.        The XSUBs for these functions may be able to return lists
  1290.        to Perl, or may be candidates to return undef or an empty
  1291.        list in case of failure.
  1292.  
  1293.        Identify which values are used by only the C and XSUB
  1294.        functions themselves.  If Perl does not need to access the
  1295.        contents of the value then it may not be necessary to
  1296.        provide a translation for that value from C to Perl.
  1297.  
  1298.        Identify the pointers in the C function parameter lists
  1299.        and return values.  Some pointers can be handled in XS
  1300.        with the & unary operator on the variable name while
  1301.        others will require the use of the * operator on the type
  1302.        name.  In general it is easier to work with the &
  1303.        operator.
  1304.  
  1305.        Identify the structures used by the C functions.  In many
  1306.        cases it may be helpful to use the T_PTROBJ typemap for
  1307.        these structures so they can be manipulated by Perl as
  1308.        blessed objects.
  1309.  
  1310.        PPPPeeeerrrrllll OOOObbbbjjjjeeeeccccttttssss AAAAnnnndddd CCCC SSSSttttrrrruuuuccccttttuuuurrrreeeessss
  1311.  
  1312.        When dealing with C structures one should select either
  1313.        TTTT____PPPPTTTTRRRROOOOBBBBJJJJ or TTTT____PPPPTTTTRRRRRRRREEEEFFFF for the XS type.  Both types are
  1314.        designed to handle pointers to complex objects.  The
  1315.  
  1316.  
  1317.  
  1318. 15/Feb/96                perl 5.002 with                       20
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1325.  
  1326.  
  1327.        T_PTRREF type will allow the Perl object to be unblessed
  1328.        while the T_PTROBJ type requires that the object be
  1329.        blessed.  By using T_PTROBJ one can achieve a form of
  1330.        type-checking because the XSUB will attempt to verify that
  1331.        the Perl object is of the expected type.
  1332.  
  1333.        The following XS code shows the _g_e_t_n_e_t_c_o_n_f_i_g_e_n_t_(_) function
  1334.        which is used with ONC+ TIRPC.  The _g_e_t_n_e_t_c_o_n_f_i_g_e_n_t_(_)
  1335.        function will return a pointer to a C structure and has
  1336.        the C prototype shown below.  The example will demonstrate
  1337.        how the C pointer will become a Perl reference.  Perl will
  1338.        consider this reference to be a pointer to a blessed
  1339.        object and will attempt to call a destructor for the
  1340.        object.  A destructor will be provided in the XS source to
  1341.        free the memory used by _g_e_t_n_e_t_c_o_n_f_i_g_e_n_t_(_).  Destructors in
  1342.        XS can be created by specifying an XSUB function whose
  1343.        name ends with the word DDDDEEEESSSSTTTTRRRROOOOYYYY.  XS destructors can be
  1344.        used to free memory which may have been malloc'd by
  1345.        another XSUB.
  1346.  
  1347.             ssssttttrrrruuuucccctttt nnnneeeettttccccoooonnnnffffiiiigggg ****ggggeeeettttnnnneeeettttccccoooonnnnffffiiiiggggeeeennnntttt((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****nnnneeeettttiiiidddd))));;;;
  1348.  
  1349.        A ttttyyyyppppeeeeddddeeeeffff will be created for ssssttttrrrruuuucccctttt nnnneeeettttccccoooonnnnffffiiiigggg.  The Perl
  1350.        object will be blessed in a class matching the name of the
  1351.        C type, with the tag PPPPttttrrrr appended, and the name should not
  1352.        have embedded spaces if it will be a Perl package name.
  1353.        The destructor will be placed in a class corresponding to
  1354.        the class of the object and the PREFIX keyword will be
  1355.        used to trim the name to the word DESTROY as Perl will
  1356.        expect.
  1357.  
  1358.             ttttyyyyppppeeeeddddeeeeffff ssssttttrrrruuuucccctttt nnnneeeettttccccoooonnnnffffiiiigggg NNNNeeeettttccccoooonnnnffffiiiigggg;;;;
  1359.  
  1360.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== RRRRPPPPCCCC
  1361.  
  1362.             NNNNeeeettttccccoooonnnnffffiiiigggg ****
  1363.             ggggeeeettttnnnneeeettttccccoooonnnnffffiiiiggggeeeennnntttt((((nnnneeeettttiiiidddd))))
  1364.                  cccchhhhaaaarrrr ****nnnneeeettttiiiidddd
  1365.  
  1366.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== NNNNeeeettttccccoooonnnnffffiiiiggggPPPPttttrrrr  PPPPRRRREEEEFFFFIIIIXXXX ==== rrrrppppccccbbbb____
  1367.  
  1368.             vvvvooooiiiidddd
  1369.             rrrrppppccccbbbb____DDDDEEEESSSSTTTTRRRROOOOYYYY((((nnnneeeettttccccoooonnnnffff))))
  1370.                  NNNNeeeettttccccoooonnnnffffiiiigggg ****nnnneeeettttccccoooonnnnffff
  1371.                  CCCCOOOODDDDEEEE::::
  1372.                  pppprrrriiiinnnnttttffff((((""""NNNNoooowwww iiiinnnn NNNNeeeettttccccoooonnnnffffiiiiggggPPPPttttrrrr::::::::DDDDEEEESSSSTTTTRRRROOOOYYYY\\\\nnnn""""))));;;;
  1373.                  ffffrrrreeeeeeee(((( nnnneeeettttccccoooonnnnffff ))));;;;
  1374.  
  1375.        This example requires the following typemap entry.
  1376.        Consult the typemap section for more information about
  1377.        adding new typemaps for an extension.
  1378.  
  1379.             TTTTYYYYPPPPEEEEMMMMAAAAPPPP
  1380.             NNNNeeeettttccccoooonnnnffffiiiigggg ****  TTTT____PPPPTTTTRRRROOOOBBBBJJJJ
  1381.  
  1382.  
  1383.  
  1384. 15/Feb/96                perl 5.002 with                       21
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1391.  
  1392.  
  1393.        This example will be used with the following Perl
  1394.        statements.
  1395.  
  1396.             uuuusssseeee RRRRPPPPCCCC;;;;
  1397.             $$$$nnnneeeettttccccoooonnnnffff ==== ggggeeeettttnnnneeeettttccccoooonnnnffffiiiiggggeeeennnntttt((((""""uuuuddddpppp""""))));;;;
  1398.  
  1399.        When Perl destroys the object referenced by $$$$nnnneeeettttccccoooonnnnffff it
  1400.        will send the object to the supplied XSUB DESTROY
  1401.        function.  Perl cannot determine, and does not care, that
  1402.        this object is a C struct and not a Perl object.  In this
  1403.        sense, there is no difference between the object created
  1404.        by the _g_e_t_n_e_t_c_o_n_f_i_g_e_n_t_(_) XSUB and an object created by a
  1405.        normal Perl subroutine.
  1406.  
  1407.        TTTThhhheeee TTTTyyyyppppeeeemmmmaaaapppp
  1408.  
  1409.        The typemap is a collection of code fragments which are
  1410.        used by the xxxxssssuuuubbbbpppppppp compiler to map C function parameters
  1411.        and values to Perl values.  The typemap file may consist
  1412.        of three sections labeled TTTTYYYYPPPPEEEEMMMMAAAAPPPP, IIIINNNNPPPPUUUUTTTT, and OOOOUUUUTTTTPPPPUUUUTTTT.  The
  1413.        INPUT section tells the compiler how to translate Perl
  1414.        values into variables of certain C types.  The OUTPUT
  1415.        section tells the compiler how to translate the values
  1416.        from certain C types into values Perl can understand.  The
  1417.        TYPEMAP section tells the compiler which of the INPUT and
  1418.        OUTPUT code fragments should be used to map a given C type
  1419.        to a Perl value.  Each of the sections of the typemap must
  1420.        be preceded by one of the TYPEMAP, INPUT, or OUTPUT
  1421.        keywords.
  1422.  
  1423.        The default typemap in the eeeexxxxtttt directory of the Perl
  1424.        source contains many useful types which can be used by
  1425.        Perl extensions.  Some extensions define additional
  1426.        typemaps which they keep in their own directory.  These
  1427.        additional typemaps may reference INPUT and OUTPUT maps in
  1428.        the main typemap.  The xxxxssssuuuubbbbpppppppp compiler will allow the
  1429.        extension's own typemap to override any mappings which are
  1430.        in the default typemap.
  1431.  
  1432.        Most extensions which require a custom typemap will need
  1433.        only the TYPEMAP section of the typemap file.  The custom
  1434.        typemap used in the _g_e_t_n_e_t_c_o_n_f_i_g_e_n_t_(_) example shown
  1435.        earlier demonstrates what may be the typical use of
  1436.        extension typemaps.  That typemap is used to equate a C
  1437.        structure with the T_PTROBJ typemap.  The typemap used by
  1438.        _g_e_t_n_e_t_c_o_n_f_i_g_e_n_t_(_) is shown here.  Note that the C type is
  1439.        separated from the XS type with a tab and that the C unary
  1440.        operator **** is considered to be a part of the C type name.
  1441.  
  1442.             TTTTYYYYPPPPEEEEMMMMAAAAPPPP
  1443.             NNNNeeeettttccccoooonnnnffffiiiigggg ****<<<<ttttaaaabbbb>>>>TTTT____PPPPTTTTRRRROOOOBBBBJJJJ
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450. 15/Feb/96                perl 5.002 with                       22
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1457.  
  1458.  
  1459. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  1460.        File RRRRPPPPCCCC....xxxxssss: Interface to some ONC+ RPC bind library
  1461.        functions.
  1462.  
  1463.             ####iiiinnnncccclllluuuuddddeeee """"EEEEXXXXTTTTEEEERRRRNNNN....hhhh""""
  1464.             ####iiiinnnncccclllluuuuddddeeee """"ppppeeeerrrrllll....hhhh""""
  1465.             ####iiiinnnncccclllluuuuddddeeee """"XXXXSSSSUUUUBBBB....hhhh""""
  1466.  
  1467.             ####iiiinnnncccclllluuuuddddeeee <<<<rrrrppppcccc////rrrrppppcccc....hhhh>>>>
  1468.  
  1469.             ttttyyyyppppeeeeddddeeeeffff ssssttttrrrruuuucccctttt nnnneeeettttccccoooonnnnffffiiiigggg NNNNeeeettttccccoooonnnnffffiiiigggg;;;;
  1470.  
  1471.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== RRRRPPPPCCCC
  1472.  
  1473.             vvvvooooiiiidddd
  1474.             rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((hhhhoooosssstttt====""""llllooooccccaaaallllhhhhoooosssstttt""""))))
  1475.                  cccchhhhaaaarrrr ****hhhhoooosssstttt
  1476.                  PPPPRRRREEEEIIIINNNNIIIITTTT::::
  1477.                  ttttiiiimmmmeeee____tttt  ttttiiiimmmmeeeepppp;;;;
  1478.                  CCCCOOOODDDDEEEE::::
  1479.                  SSSSTTTT((((0000)))) ==== ssssvvvv____nnnneeeewwwwmmmmoooorrrrttttaaaallll(((())));;;;
  1480.                  iiiiffff(((( rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((( hhhhoooosssstttt,,,, &&&&ttttiiiimmmmeeeepppp )))) ))))
  1481.                       ssssvvvv____sssseeeettttnnnnvvvv(((( SSSSTTTT((((0000)))),,,, ((((ddddoooouuuubbbblllleeee))))ttttiiiimmmmeeeepppp ))));;;;
  1482.  
  1483.             NNNNeeeettttccccoooonnnnffffiiiigggg ****
  1484.             ggggeeeettttnnnneeeettttccccoooonnnnffffiiiiggggeeeennnntttt((((nnnneeeettttiiiidddd====""""uuuuddddpppp""""))))
  1485.                  cccchhhhaaaarrrr ****nnnneeeettttiiiidddd
  1486.  
  1487.             MMMMOOOODDDDUUUULLLLEEEE ==== RRRRPPPPCCCC  PPPPAAAACCCCKKKKAAAAGGGGEEEE ==== NNNNeeeettttccccoooonnnnffffiiiiggggPPPPttttrrrr  PPPPRRRREEEEFFFFIIIIXXXX ==== rrrrppppccccbbbb____
  1488.  
  1489.             vvvvooooiiiidddd
  1490.             rrrrppppccccbbbb____DDDDEEEESSSSTTTTRRRROOOOYYYY((((nnnneeeettttccccoooonnnnffff))))
  1491.                  NNNNeeeettttccccoooonnnnffffiiiigggg ****nnnneeeettttccccoooonnnnffff
  1492.                  CCCCOOOODDDDEEEE::::
  1493.                  pppprrrriiiinnnnttttffff((((""""NNNNeeeettttccccoooonnnnffffiiiiggggPPPPttttrrrr::::::::DDDDEEEESSSSTTTTRRRROOOOYYYY\\\\nnnn""""))));;;;
  1494.                  ffffrrrreeeeeeee(((( nnnneeeettttccccoooonnnnffff ))));;;;
  1495.  
  1496.        File ttttyyyyppppeeeemmmmaaaapppp: Custom typemap for RPC.xs.
  1497.  
  1498.             TTTTYYYYPPPPEEEEMMMMAAAAPPPP
  1499.             NNNNeeeettttccccoooonnnnffffiiiigggg ****  TTTT____PPPPTTTTRRRROOOOBBBBJJJJ
  1500.  
  1501.        File RRRRPPPPCCCC....ppppmmmm: Perl module for the RPC extension.
  1502.  
  1503.             ppppaaaacccckkkkaaaaggggeeee RRRRPPPPCCCC;;;;
  1504.  
  1505.             rrrreeeeqqqquuuuiiiirrrreeee EEEExxxxppppoooorrrrtttteeeerrrr;;;;
  1506.             rrrreeeeqqqquuuuiiiirrrreeee DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr;;;;
  1507.             @@@@IIIISSSSAAAA ==== qqqqwwww((((EEEExxxxppppoooorrrrtttteeeerrrr DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr))));;;;
  1508.             @@@@EEEEXXXXPPPPOOOORRRRTTTT ==== qqqqwwww((((rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee ggggeeeettttnnnneeeettttccccoooonnnnffffiiiiggggeeeennnntttt))));;;;
  1509.  
  1510.             bbbboooooooottttssssttttrrrraaaapppp RRRRPPPPCCCC;;;;
  1511.             1111;;;;
  1512.  
  1513.  
  1514.  
  1515.  
  1516. 15/Feb/96                perl 5.002 with                       23
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522. PERLXS(1)      User Contributed Perl Documentation      PERLXS(1)
  1523.  
  1524.  
  1525.        File rrrrppppcccctttteeeesssstttt....ppppllll: Perl test program for the RPC extension.
  1526.  
  1527.             uuuusssseeee RRRRPPPPCCCC;;;;
  1528.  
  1529.             $$$$nnnneeeettttccccoooonnnnffff ==== ggggeeeettttnnnneeeettttccccoooonnnnffffiiiiggggeeeennnntttt(((())));;;;
  1530.             $$$$aaaa ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee(((())));;;;
  1531.             pppprrrriiiinnnntttt """"ttttiiiimmmmeeee ==== $$$$aaaa\\\\nnnn"""";;;;
  1532.             pppprrrriiiinnnntttt """"nnnneeeettttccccoooonnnnffff ==== $$$$nnnneeeettttccccoooonnnnffff\\\\nnnn"""";;;;
  1533.  
  1534.             $$$$nnnneeeettttccccoooonnnnffff ==== ggggeeeettttnnnneeeettttccccoooonnnnffffiiiiggggeeeennnntttt((((""""ttttccccpppp""""))));;;;
  1535.             $$$$aaaa ==== rrrrppppccccbbbb____ggggeeeettttttttiiiimmmmeeee((((""""ppppooooppppllllaaaarrrr""""))));;;;
  1536.             pppprrrriiiinnnntttt """"ttttiiiimmmmeeee ==== $$$$aaaa\\\\nnnn"""";;;;
  1537.             pppprrrriiiinnnntttt """"nnnneeeettttccccoooonnnnffff ==== $$$$nnnneeeettttccccoooonnnnffff\\\\nnnn"""";;;;
  1538.  
  1539.  
  1540. XXXXSSSS VVVVEEEERRRRSSSSIIIIOOOONNNN
  1541.        This document covers features supported by xxxxssssuuuubbbbpppppppp 1.933.
  1542.  
  1543. AAAAUUUUTTTTHHHHOOOORRRR
  1544.        Dean Roehrich _<_r_o_e_h_r_i_c_h_@_c_r_a_y_._c_o_m_> Feb 13, 1996
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582. 15/Feb/96                perl 5.002 with                       24
  1583.  
  1584.  
  1585.