Re: Inline PI function
[p5sagit/p5-mst-13.2.git] / pod / perlcall.pod
index 996c914..9a4a886 100644 (file)
@@ -5,7 +5,7 @@ perlcall - Perl calling conventions from C
 =head1 DESCRIPTION
 
 The purpose of this document is to show you how to call Perl subroutines
-directly from C, i.e. how to write I<callbacks>.
+directly from C, i.e., how to write I<callbacks>.
 
 Apart from discussing the C interface provided by Perl for writing
 callbacks the document uses a series of examples to show how the
@@ -29,8 +29,8 @@ called instead.
 
 The classic example of where callbacks are used is when writing an
 event driven program like for an X windows application.  In this case
-your register functions to be called whenever specific events occur,
-e.g. a mouse button is pressed, the cursor moves into a window or a
+you register functions to be called whenever specific events occur,
+e.g., a mouse button is pressed, the cursor moves into a window or a
 menu item is selected.
 
 =back
@@ -61,7 +61,7 @@ subroutines.  They are
 The key function is I<perl_call_sv>.  All the other functions are
 fairly simple wrappers which make it easier to call Perl subroutines in
 special cases. At the end of the day they will all call I<perl_call_sv>
-to actually invoke the Perl subroutine.
+to invoke the Perl subroutine.
 
 All the I<perl_call_*> functions have a C<flags> parameter which is
 used to pass a bit mask of options to Perl.  This bit mask operates
@@ -84,9 +84,9 @@ use of I<perl_call_sv>.
 
 The function, I<perl_call_pv>, is similar to I<perl_call_sv> except it
 expects its first parameter to be a C char* which identifies the Perl
-subroutine you want to call, e.g. C<perl_call_pv("fred", 0)>.  If the
+subroutine you want to call, e.g., C<perl_call_pv("fred", 0)>.  If the
 subroutine you want to call is in another package, just include the
-package name in the string, e.g. C<"pkg::fred">.
+package name in the string, e.g., C<"pkg::fred">.
 
 =item B<perl_call_method>
 
@@ -131,26 +131,26 @@ OR'ed together.
 Calls the Perl subroutine in a scalar context.  This is the default
 context flag setting for all the I<perl_call_*> functions.
 
-This flag has 2 effects
+This flag has 2 effects:
 
 =over 5
 
 =item 1.
 
-it indicates to the subroutine being called that it is executing in a
+It indicates to the subroutine being called that it is executing in a
 scalar context (if it executes I<wantarray> the result will be false).
 
 
 =item 2.
 
-it ensures that only a scalar is actually returned from the subroutine.
+It ensures that only a scalar is actually returned from the subroutine.
 The subroutine can, of course,  ignore the I<wantarray> and return a
 list anyway. If so, then only the last element of the list will be
 returned.
 
 =back
 
-The value returned by the I<perl_call_*> function indicates how may
+The value returned by the I<perl_call_*> function indicates how many
 items have been returned by the Perl subroutine - in this case it will
 be either 0 or 1.
 
@@ -171,27 +171,27 @@ context> shows an example of this behaviour.
 
 Calls the Perl subroutine in a list context.
 
-As with G_SCALAR, this flag has 2 effects
+As with G_SCALAR, this flag has 2 effects:
 
 =over 5
 
 =item 1.
 
-it indicates to the subroutine being called that it is executing in an
+It indicates to the subroutine being called that it is executing in an
 array context (if it executes I<wantarray> the result will be true).
 
 
 =item 2.
 
-it ensures that all items returned from the subroutine will be
+It ensures that all items returned from the subroutine will be
 accessible when control returns from the I<perl_call_*> function.
 
 =back
 
-The value returned by the I<perl_call_*> function indicates how may
+The value returned by the I<perl_call_*> function indicates how many
 items have been returned by the Perl subroutine.
 
-If 0, the you have specified the G_DISCARD flag.
+If 0, then you have specified the G_DISCARD flag.
 
 If not 0, then it will be a count of the number of items returned by
 the subroutine. These items will be stored on the Perl stack.  The
@@ -208,10 +208,10 @@ automatically for you.  Note that it is still possible to indicate a
 context to the Perl subroutine by using either G_SCALAR or G_ARRAY.
 
 If you do not set this flag then it is I<very> important that you make
-sure that any temporaries (i.e. parameters passed to the Perl
+sure that any temporaries (i.e., parameters passed to the Perl
 subroutine and values returned from the subroutine) are disposed of
 yourself.  The section I<Returning a Scalar> gives details of how to
-explicitly dispose of these temporaries and the section I<Using Perl to
+dispose of these temporaries explicitly and the section I<Using Perl to
 dispose of temporaries> discusses the specific circumstances where you
 can ignore the problem and let Perl deal with it for you.
 
@@ -254,7 +254,7 @@ belongs to C<joe>.
 =head2 G_EVAL  
 
 It is possible for the Perl subroutine you are calling to terminate
-abnormally, e.g. by calling I<die> explicitly or by not actually
+abnormally, e.g., by calling I<die> explicitly or by not actually
 existing.  By default, when either of these of events occurs, the
 process will terminate immediately.  If though, you want to trap this
 type of event, specify the G_EVAL flag.  It will put an I<eval { }>
@@ -265,7 +265,7 @@ check the C<$@> variable as you would in a normal Perl script.
 
 The value returned from the I<perl_call_*> function is dependent on
 what other flags have been specified and whether an error has
-occurred.  Here are all the different cases that can occur
+occurred.  Here are all the different cases that can occur:
 
 =over 5
 
@@ -408,7 +408,7 @@ Enough of the definition talk, let's have a few examples.
 
 Perl provides many macros to assist in accessing the Perl stack.
 Wherever possible, these macros should always be used when interfacing
-to Perl internals.  Hopefully this should make the code less vulnerable
+to Perl internals.  We hope this should make the code less vulnerable
 to any changes made to Perl in the future.
 
 Another point worth noting is that in the first series of examples I
@@ -458,7 +458,7 @@ specified.
 =item 3.
 
 We aren't interested in anything returned from I<PrintUID>, so
-G_DISCARD is specified. Even if I<PrintUID> was changed to actually
+G_DISCARD is specified. Even if I<PrintUID> was changed to
 return some value(s), having specified G_DISCARD will mean that they
 will be wiped by the time control returns from I<perl_call_pv>.
 
@@ -529,15 +529,15 @@ have used this macro.
 
 The exception to this rule is if you are calling a Perl subroutine
 directly from an XSUB function. In this case it is not necessary to
-explicitly use the C<dSP> macro - it will be declared for you
+use the C<dSP> macro explicitly - it will be declared for you
 automatically.
 
 =item 3.
 
 Any parameters to be pushed onto the stack should be bracketed by the
 C<PUSHMARK> and C<PUTBACK> macros.  The purpose of these two macros, in
-this context, is to automatically count the number of parameters you
-are pushing. Then whenever Perl is creating the C<@_> array for the
+this context, is to count the number of parameters you are
+pushing automatically.  Then whenever Perl is creating the C<@_> array for the
 subroutine, it knows how big to make it.
 
 The C<PUSHMARK> macro tells Perl to make a mental note of the current
@@ -555,7 +555,7 @@ local copy, I<not> the global copy.
 
 =item 4.
 
-The only flag specified this time is G_DISCARD. Since we are passing 2
+The only flag specified this time is G_DISCARD. Because we are passing 2
 parameters to the Perl subroutine this time, we have not specified
 G_NOARGS.
 
@@ -565,7 +565,7 @@ Next, we come to XPUSHs. This is where the parameters actually get
 pushed onto the stack. In this case we are pushing a string and an
 integer.
 
-See the section L<perlguts/"XSUB'S and the Argument Stack"> for details
+See the L<perlguts/"XSUB's and the Argument Stack"> for details
 on how the XPUSH macros work.
 
 =item 6.
@@ -580,7 +580,7 @@ function.
 Now for an example of dealing with the items returned from a Perl
 subroutine.
 
-Here is a Perl subroutine, I<Adder>,  which takes 2 integer parameters
+Here is a Perl subroutine, I<Adder>, that takes 2 integer parameters
 and simply returns their sum.
 
     sub Adder
@@ -589,7 +589,7 @@ and simply returns their sum.
         $a + $b ;
     }
 
-Since we are now concerned with the return value from I<Adder>, the C
+Because we are now concerned with the return value from I<Adder>, the C
 function required to call it is now a bit more complex.
 
     static void
@@ -685,7 +685,7 @@ Expecting a single value is not quite the same as knowing that there
 will be one. If someone modified I<Adder> to return a list and we
 didn't check for that possibility and take appropriate action the Perl
 stack would end up in an inconsistent state. That is something you
-I<really> don't want to ever happen.
+I<really> don't want to happen ever.
 
 =item 5.
 
@@ -998,7 +998,7 @@ refers to the C equivalent of C<$@>.
 Note that the stack is popped using C<POPs> in the block where
 C<SvTRUE(GvSV(errgv))> is true.  This is necessary because whenever a
 I<perl_call_*> function invoked with G_EVAL|G_SCALAR returns an error,
-the top of the stack holds the value I<undef>. Since we want the
+the top of the stack holds the value I<undef>. Because we want the
 program to continue after detecting this error, it is essential that
 the stack is tidied up by removing the I<undef>.
 
@@ -1026,7 +1026,7 @@ version of the call_Subtract example above inside a destructor:
 
 This example will fail to recognize that an error occurred inside the
 C<eval {}>.  Here's why: the call_Subtract code got executed while perl
-was cleaning up temporaries when exiting the eval block, and since
+was cleaning up temporaries when exiting the eval block, and because
 call_Subtract is implemented with I<perl_call_pv> using the G_EVAL
 flag, it promptly reset C<$@>.  This results in the failure of the
 outermost test for C<$@>, and thereby the failure of the error trap.
@@ -1064,7 +1064,7 @@ Here is a snippet of XSUB which defines I<CallSubPV>.
        perl_call_pv(name, G_DISCARD|G_NOARGS) ;
 
 That is fine as far as it goes. The thing is, the Perl subroutine 
-can be specified only as a string.  For Perl 4 this was adequate,
+can be specified as only a string.  For Perl 4 this was adequate,
 but Perl 5 allows references to subroutines and anonymous subroutines.
 This is where I<perl_call_sv> is useful.
 
@@ -1079,7 +1079,7 @@ I<perl_call_sv> instead of I<perl_call_pv>.
        PUSHMARK(sp) ;
        perl_call_sv(name, G_DISCARD|G_NOARGS) ;
 
-Since we are using an SV to call I<fred> the following can all be used
+Because we are using an SV to call I<fred> the following can all be used
 
     CallSubSV("fred") ;
     CallSubSV(\&fred) ;
@@ -1092,7 +1092,7 @@ how you can specify the Perl subroutine.
 
 You should note that if it is necessary to store the SV (C<name> in the
 example above) which corresponds to the Perl subroutine so that it can
-be used later in the program, it not enough to just store a copy of the
+be used later in the program, it not enough just to store a copy of the
 pointer to the SV. Say the code above had been like this
 
     static SV * rememberSub ;
@@ -1135,7 +1135,7 @@ Similarly, with this code
     $ref = 47 ;
     CallSavedSub1() ;
 
-you can expect one of these messages (which you actually get is dependant on 
+you can expect one of these messages (which you actually get is dependent on 
 the version of Perl you are using) 
 
     Not a CODE reference at ...
@@ -1143,7 +1143,7 @@ the version of Perl you are using)
 
 The variable C<$ref> may have referred to the subroutine C<fred>
 whenever the call to C<SaveSub1> was made but by the time
-C<CallSavedSub1> gets called it now holds the number C<47>. Since we
+C<CallSavedSub1> gets called it now holds the number C<47>. Because we
 saved only a pointer to the original SV in C<SaveSub1>, any changes to
 C<$ref> will be tracked by the pointer C<rememberSub>. This means that
 whenever C<CallSavedSub1> gets called, it will attempt to execute the
@@ -1185,7 +1185,7 @@ SV.  The code below shows C<SaveSub2> modified to do that
        PUSHMARK(sp) ;
        perl_call_sv(keepSub, G_DISCARD|G_NOARGS) ;
 
-In order to avoid creating a new SV every time C<SaveSub2> is called,
+To avoid creating a new SV every time C<SaveSub2> is called,
 the function first checks to see if it has been called before.  If not,
 then space for a new SV is allocated and the reference to the Perl
 subroutine, C<name> is copied to the variable C<keepSub> in one
@@ -1247,9 +1247,9 @@ Consider the following Perl code
         }
     }
 
-It just implements a very simple class to manage an array.  Apart from
+It implements just a very simple class to manage an array.  Apart from
 the constructor, C<new>, it declares methods, one static and one
-virtual. The static method, C<PrintID>, simply prints out the class
+virtual. The static method, C<PrintID>, prints out simply the class
 name and a version number. The virtual method, C<Display>, prints out a
 single element of the array.  Here is an all Perl example of using it.
 
@@ -1346,7 +1346,7 @@ The output from that will be
 =head2 Using Perl to dispose of temporaries
 
 In the examples given to date, any temporaries created in the callback
-(i.e. parameters passed on the stack to the I<perl_call_*> function or
+(i.e., parameters passed on the stack to the I<perl_call_*> function or
 values returned via the stack) have been freed by one of these methods
 
 =over 5
@@ -1441,7 +1441,7 @@ the extreme left.
 
 So what is the big problem? Well, if you are expecting Perl to tidy up
 those temporaries for you, you might be in for a long wait.  For Perl
-to actually dispose of your temporaries, control must drop back to the
+to dispose of your temporaries, control must drop back to the
 enclosing scope at some stage.  In the event driven scenario that may
 never happen.  This means that as time goes on, your program will
 create more and more temporaries, none of which will ever be freed. As
@@ -1450,7 +1450,7 @@ eventually consume all the available memory in your system - kapow!
 
 So here is the bottom line - if you are sure that control will revert
 back to the enclosing Perl scope fairly quickly after the end of your
-callback, then it isn't absolutely necessary to explicitly dispose of
+callback, then it isn't absolutely necessary to dispose explicitly of
 any temporaries you may have created. Mind you, if you are at all
 uncertain about what to do, it doesn't do any harm to tidy up anyway.
 
@@ -1524,7 +1524,7 @@ registers, C<pcb1>, might look like this
 The mapping between the C callback and the Perl equivalent is stored in
 the global variable C<callback>.
 
-This will be adequate if you ever need to have only 1 callback
+This will be adequate if you ever need to have only one callback
 registered at any time. An example could be an error handler like the
 code sketched out above. Remember though, repeated calls to
 C<register_fatal> will replace the previously registered callback
@@ -1761,7 +1761,7 @@ series of C functions to act as the interface to Perl, thus
 
         asynch_close(fh) ;
 
-In this case the functions C<fn1>, C<fn2> and C<fn3> are used to
+In this case the functions C<fn1>, C<fn2>, and C<fn3> are used to
 remember the Perl subroutine to be called. Each of the functions holds
 a separate hard-wired index which is used in the function C<Pcb> to
 access the C<Map> array and actually call the Perl subroutine.
@@ -1889,7 +1889,7 @@ L<perlxs>, L<perlguts>, L<perlembed>
 
 =head1 AUTHOR
 
-Paul Marquess <pmarquess@bfsec.bt.co.uk>
+Paul Marquess <F<pmarquess@bfsec.bt.co.uk>>
 
 Special thanks to the following people who assisted in the creation of
 the document.