Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3596 lines
107 KiB

  1. =head1 NAME
  2. perlguts - Perl's Internal Functions
  3. =head1 DESCRIPTION
  4. This document attempts to describe some of the internal functions of the
  5. Perl executable. It is far from complete and probably contains many errors.
  6. Please refer any questions or comments to the author below.
  7. =head1 Variables
  8. =head2 Datatypes
  9. Perl has three typedefs that handle Perl's three main data types:
  10. SV Scalar Value
  11. AV Array Value
  12. HV Hash Value
  13. Each typedef has specific routines that manipulate the various data types.
  14. =head2 What is an "IV"?
  15. Perl uses a special typedef IV which is a simple integer type that is
  16. guaranteed to be large enough to hold a pointer (as well as an integer).
  17. Perl also uses two special typedefs, I32 and I16, which will always be at
  18. least 32-bits and 16-bits long, respectively.
  19. =head2 Working with SVs
  20. An SV can be created and loaded with one command. There are four types of
  21. values that can be loaded: an integer value (IV), a double (NV), a string,
  22. (PV), and another scalar (SV).
  23. The six routines are:
  24. SV* newSViv(IV);
  25. SV* newSVnv(double);
  26. SV* newSVpv(char*, int);
  27. SV* newSVpvn(char*, int);
  28. SV* newSVpvf(const char*, ...);
  29. SV* newSVsv(SV*);
  30. To change the value of an *already-existing* SV, there are seven routines:
  31. void sv_setiv(SV*, IV);
  32. void sv_setuv(SV*, UV);
  33. void sv_setnv(SV*, double);
  34. void sv_setpv(SV*, const char*);
  35. void sv_setpvn(SV*, const char*, int)
  36. void sv_setpvf(SV*, const char*, ...);
  37. void sv_setpvfn(SV*, const char*, STRLEN, va_list *, SV **, I32, bool);
  38. void sv_setsv(SV*, SV*);
  39. Notice that you can choose to specify the length of the string to be
  40. assigned by using C<sv_setpvn>, C<newSVpvn>, or C<newSVpv>, or you may
  41. allow Perl to calculate the length by using C<sv_setpv> or by specifying
  42. 0 as the second argument to C<newSVpv>. Be warned, though, that Perl will
  43. determine the string's length by using C<strlen>, which depends on the
  44. string terminating with a NUL character.
  45. The arguments of C<sv_setpvf> are processed like C<sprintf>, and the
  46. formatted output becomes the value.
  47. C<sv_setpvfn> is an analogue of C<vsprintf>, but it allows you to specify
  48. either a pointer to a variable argument list or the address and length of
  49. an array of SVs. The last argument points to a boolean; on return, if that
  50. boolean is true, then locale-specific information has been used to format
  51. the string, and the string's contents are therefore untrustworthy (see
  52. L<perlsec>). This pointer may be NULL if that information is not
  53. important. Note that this function requires you to specify the length of
  54. the format.
  55. The C<sv_set*()> functions are not generic enough to operate on values
  56. that have "magic". See L<Magic Virtual Tables> later in this document.
  57. All SVs that contain strings should be terminated with a NUL character.
  58. If it is not NUL-terminated there is a risk of
  59. core dumps and corruptions from code which passes the string to C
  60. functions or system calls which expect a NUL-terminated string.
  61. Perl's own functions typically add a trailing NUL for this reason.
  62. Nevertheless, you should be very careful when you pass a string stored
  63. in an SV to a C function or system call.
  64. To access the actual value that an SV points to, you can use the macros:
  65. SvIV(SV*)
  66. SvNV(SV*)
  67. SvPV(SV*, STRLEN len)
  68. which will automatically coerce the actual scalar type into an IV, double,
  69. or string.
  70. In the C<SvPV> macro, the length of the string returned is placed into the
  71. variable C<len> (this is a macro, so you do I<not> use C<&len>). If you do not
  72. care what the length of the data is, use the global variable C<PL_na> or a
  73. local variable of type C<STRLEN>. However using C<PL_na> can be quite
  74. inefficient because C<PL_na> must be accessed in thread-local storage in
  75. threaded Perl. In any case, remember that Perl allows arbitrary strings of
  76. data that may both contain NULs and might not be terminated by a NUL.
  77. Also remember that C doesn't allow you to safely say C<foo(SvPV(s, len),
  78. len);>. It might work with your compiler, but it won't work for everyone.
  79. Break this sort of statement up into separate assignments:
  80. STRLEN len;
  81. char * ptr;
  82. ptr = SvPV(len);
  83. foo(ptr, len);
  84. If you want to know if the scalar value is TRUE, you can use:
  85. SvTRUE(SV*)
  86. Although Perl will automatically grow strings for you, if you need to force
  87. Perl to allocate more memory for your SV, you can use the macro
  88. SvGROW(SV*, STRLEN newlen)
  89. which will determine if more memory needs to be allocated. If so, it will
  90. call the function C<sv_grow>. Note that C<SvGROW> can only increase, not
  91. decrease, the allocated memory of an SV and that it does not automatically
  92. add a byte for the a trailing NUL (perl's own string functions typically do
  93. C<SvGROW(sv, len + 1)>).
  94. If you have an SV and want to know what kind of data Perl thinks is stored
  95. in it, you can use the following macros to check the type of SV you have.
  96. SvIOK(SV*)
  97. SvNOK(SV*)
  98. SvPOK(SV*)
  99. You can get and set the current length of the string stored in an SV with
  100. the following macros:
  101. SvCUR(SV*)
  102. SvCUR_set(SV*, I32 val)
  103. You can also get a pointer to the end of the string stored in the SV
  104. with the macro:
  105. SvEND(SV*)
  106. But note that these last three macros are valid only if C<SvPOK()> is true.
  107. If you want to append something to the end of string stored in an C<SV*>,
  108. you can use the following functions:
  109. void sv_catpv(SV*, char*);
  110. void sv_catpvn(SV*, char*, STRLEN);
  111. void sv_catpvf(SV*, const char*, ...);
  112. void sv_catpvfn(SV*, const char*, STRLEN, va_list *, SV **, I32, bool);
  113. void sv_catsv(SV*, SV*);
  114. The first function calculates the length of the string to be appended by
  115. using C<strlen>. In the second, you specify the length of the string
  116. yourself. The third function processes its arguments like C<sprintf> and
  117. appends the formatted output. The fourth function works like C<vsprintf>.
  118. You can specify the address and length of an array of SVs instead of the
  119. va_list argument. The fifth function extends the string stored in the first
  120. SV with the string stored in the second SV. It also forces the second SV
  121. to be interpreted as a string.
  122. The C<sv_cat*()> functions are not generic enough to operate on values that
  123. have "magic". See L<Magic Virtual Tables> later in this document.
  124. If you know the name of a scalar variable, you can get a pointer to its SV
  125. by using the following:
  126. SV* perl_get_sv("package::varname", FALSE);
  127. This returns NULL if the variable does not exist.
  128. If you want to know if this variable (or any other SV) is actually C<defined>,
  129. you can call:
  130. SvOK(SV*)
  131. The scalar C<undef> value is stored in an SV instance called C<PL_sv_undef>. Its
  132. address can be used whenever an C<SV*> is needed.
  133. There are also the two values C<PL_sv_yes> and C<PL_sv_no>, which contain Boolean
  134. TRUE and FALSE values, respectively. Like C<PL_sv_undef>, their addresses can
  135. be used whenever an C<SV*> is needed.
  136. Do not be fooled into thinking that C<(SV *) 0> is the same as C<&PL_sv_undef>.
  137. Take this code:
  138. SV* sv = (SV*) 0;
  139. if (I-am-to-return-a-real-value) {
  140. sv = sv_2mortal(newSViv(42));
  141. }
  142. sv_setsv(ST(0), sv);
  143. This code tries to return a new SV (which contains the value 42) if it should
  144. return a real value, or undef otherwise. Instead it has returned a NULL
  145. pointer which, somewhere down the line, will cause a segmentation violation,
  146. bus error, or just weird results. Change the zero to C<&PL_sv_undef> in the first
  147. line and all will be well.
  148. To free an SV that you've created, call C<SvREFCNT_dec(SV*)>. Normally this
  149. call is not necessary (see L<Reference Counts and Mortality>).
  150. =head2 What's Really Stored in an SV?
  151. Recall that the usual method of determining the type of scalar you have is
  152. to use C<Sv*OK> macros. Because a scalar can be both a number and a string,
  153. usually these macros will always return TRUE and calling the C<Sv*V>
  154. macros will do the appropriate conversion of string to integer/double or
  155. integer/double to string.
  156. If you I<really> need to know if you have an integer, double, or string
  157. pointer in an SV, you can use the following three macros instead:
  158. SvIOKp(SV*)
  159. SvNOKp(SV*)
  160. SvPOKp(SV*)
  161. These will tell you if you truly have an integer, double, or string pointer
  162. stored in your SV. The "p" stands for private.
  163. In general, though, it's best to use the C<Sv*V> macros.
  164. =head2 Working with AVs
  165. There are two ways to create and load an AV. The first method creates an
  166. empty AV:
  167. AV* newAV();
  168. The second method both creates the AV and initially populates it with SVs:
  169. AV* av_make(I32 num, SV **ptr);
  170. The second argument points to an array containing C<num> C<SV*>'s. Once the
  171. AV has been created, the SVs can be destroyed, if so desired.
  172. Once the AV has been created, the following operations are possible on AVs:
  173. void av_push(AV*, SV*);
  174. SV* av_pop(AV*);
  175. SV* av_shift(AV*);
  176. void av_unshift(AV*, I32 num);
  177. These should be familiar operations, with the exception of C<av_unshift>.
  178. This routine adds C<num> elements at the front of the array with the C<undef>
  179. value. You must then use C<av_store> (described below) to assign values
  180. to these new elements.
  181. Here are some other functions:
  182. I32 av_len(AV*);
  183. SV** av_fetch(AV*, I32 key, I32 lval);
  184. SV** av_store(AV*, I32 key, SV* val);
  185. The C<av_len> function returns the highest index value in array (just
  186. like $#array in Perl). If the array is empty, -1 is returned. The
  187. C<av_fetch> function returns the value at index C<key>, but if C<lval>
  188. is non-zero, then C<av_fetch> will store an undef value at that index.
  189. The C<av_store> function stores the value C<val> at index C<key>, and does
  190. not increment the reference count of C<val>. Thus the caller is responsible
  191. for taking care of that, and if C<av_store> returns NULL, the caller will
  192. have to decrement the reference count to avoid a memory leak. Note that
  193. C<av_fetch> and C<av_store> both return C<SV**>'s, not C<SV*>'s as their
  194. return value.
  195. void av_clear(AV*);
  196. void av_undef(AV*);
  197. void av_extend(AV*, I32 key);
  198. The C<av_clear> function deletes all the elements in the AV* array, but
  199. does not actually delete the array itself. The C<av_undef> function will
  200. delete all the elements in the array plus the array itself. The
  201. C<av_extend> function extends the array so that it contains at least C<key+1>
  202. elements. If C<key+1> is less than the currently allocated length of the array,
  203. then nothing is done.
  204. If you know the name of an array variable, you can get a pointer to its AV
  205. by using the following:
  206. AV* perl_get_av("package::varname", FALSE);
  207. This returns NULL if the variable does not exist.
  208. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  209. information on how to use the array access functions on tied arrays.
  210. =head2 Working with HVs
  211. To create an HV, you use the following routine:
  212. HV* newHV();
  213. Once the HV has been created, the following operations are possible on HVs:
  214. SV** hv_store(HV*, char* key, U32 klen, SV* val, U32 hash);
  215. SV** hv_fetch(HV*, char* key, U32 klen, I32 lval);
  216. The C<klen> parameter is the length of the key being passed in (Note that
  217. you cannot pass 0 in as a value of C<klen> to tell Perl to measure the
  218. length of the key). The C<val> argument contains the SV pointer to the
  219. scalar being stored, and C<hash> is the precomputed hash value (zero if
  220. you want C<hv_store> to calculate it for you). The C<lval> parameter
  221. indicates whether this fetch is actually a part of a store operation, in
  222. which case a new undefined value will be added to the HV with the supplied
  223. key and C<hv_fetch> will return as if the value had already existed.
  224. Remember that C<hv_store> and C<hv_fetch> return C<SV**>'s and not just
  225. C<SV*>. To access the scalar value, you must first dereference the return
  226. value. However, you should check to make sure that the return value is
  227. not NULL before dereferencing it.
  228. These two functions check if a hash table entry exists, and deletes it.
  229. bool hv_exists(HV*, char* key, U32 klen);
  230. SV* hv_delete(HV*, char* key, U32 klen, I32 flags);
  231. If C<flags> does not include the C<G_DISCARD> flag then C<hv_delete> will
  232. create and return a mortal copy of the deleted value.
  233. And more miscellaneous functions:
  234. void hv_clear(HV*);
  235. void hv_undef(HV*);
  236. Like their AV counterparts, C<hv_clear> deletes all the entries in the hash
  237. table but does not actually delete the hash table. The C<hv_undef> deletes
  238. both the entries and the hash table itself.
  239. Perl keeps the actual data in linked list of structures with a typedef of HE.
  240. These contain the actual key and value pointers (plus extra administrative
  241. overhead). The key is a string pointer; the value is an C<SV*>. However,
  242. once you have an C<HE*>, to get the actual key and value, use the routines
  243. specified below.
  244. I32 hv_iterinit(HV*);
  245. /* Prepares starting point to traverse hash table */
  246. HE* hv_iternext(HV*);
  247. /* Get the next entry, and return a pointer to a
  248. structure that has both the key and value */
  249. char* hv_iterkey(HE* entry, I32* retlen);
  250. /* Get the key from an HE structure and also return
  251. the length of the key string */
  252. SV* hv_iterval(HV*, HE* entry);
  253. /* Return a SV pointer to the value of the HE
  254. structure */
  255. SV* hv_iternextsv(HV*, char** key, I32* retlen);
  256. /* This convenience routine combines hv_iternext,
  257. hv_iterkey, and hv_iterval. The key and retlen
  258. arguments are return values for the key and its
  259. length. The value is returned in the SV* argument */
  260. If you know the name of a hash variable, you can get a pointer to its HV
  261. by using the following:
  262. HV* perl_get_hv("package::varname", FALSE);
  263. This returns NULL if the variable does not exist.
  264. The hash algorithm is defined in the C<PERL_HASH(hash, key, klen)> macro:
  265. hash = 0;
  266. while (klen--)
  267. hash = (hash * 33) + *key++;
  268. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  269. information on how to use the hash access functions on tied hashes.
  270. =head2 Hash API Extensions
  271. Beginning with version 5.004, the following functions are also supported:
  272. HE* hv_fetch_ent (HV* tb, SV* key, I32 lval, U32 hash);
  273. HE* hv_store_ent (HV* tb, SV* key, SV* val, U32 hash);
  274. bool hv_exists_ent (HV* tb, SV* key, U32 hash);
  275. SV* hv_delete_ent (HV* tb, SV* key, I32 flags, U32 hash);
  276. SV* hv_iterkeysv (HE* entry);
  277. Note that these functions take C<SV*> keys, which simplifies writing
  278. of extension code that deals with hash structures. These functions
  279. also allow passing of C<SV*> keys to C<tie> functions without forcing
  280. you to stringify the keys (unlike the previous set of functions).
  281. They also return and accept whole hash entries (C<HE*>), making their
  282. use more efficient (since the hash number for a particular string
  283. doesn't have to be recomputed every time). See L<API LISTING> later in
  284. this document for detailed descriptions.
  285. The following macros must always be used to access the contents of hash
  286. entries. Note that the arguments to these macros must be simple
  287. variables, since they may get evaluated more than once. See
  288. L<API LISTING> later in this document for detailed descriptions of these
  289. macros.
  290. HePV(HE* he, STRLEN len)
  291. HeVAL(HE* he)
  292. HeHASH(HE* he)
  293. HeSVKEY(HE* he)
  294. HeSVKEY_force(HE* he)
  295. HeSVKEY_set(HE* he, SV* sv)
  296. These two lower level macros are defined, but must only be used when
  297. dealing with keys that are not C<SV*>s:
  298. HeKEY(HE* he)
  299. HeKLEN(HE* he)
  300. Note that both C<hv_store> and C<hv_store_ent> do not increment the
  301. reference count of the stored C<val>, which is the caller's responsibility.
  302. If these functions return a NULL value, the caller will usually have to
  303. decrement the reference count of C<val> to avoid a memory leak.
  304. =head2 References
  305. References are a special type of scalar that point to other data types
  306. (including references).
  307. To create a reference, use either of the following functions:
  308. SV* newRV_inc((SV*) thing);
  309. SV* newRV_noinc((SV*) thing);
  310. The C<thing> argument can be any of an C<SV*>, C<AV*>, or C<HV*>. The
  311. functions are identical except that C<newRV_inc> increments the reference
  312. count of the C<thing>, while C<newRV_noinc> does not. For historical
  313. reasons, C<newRV> is a synonym for C<newRV_inc>.
  314. Once you have a reference, you can use the following macro to dereference
  315. the reference:
  316. SvRV(SV*)
  317. then call the appropriate routines, casting the returned C<SV*> to either an
  318. C<AV*> or C<HV*>, if required.
  319. To determine if an SV is a reference, you can use the following macro:
  320. SvROK(SV*)
  321. To discover what type of value the reference refers to, use the following
  322. macro and then check the return value.
  323. SvTYPE(SvRV(SV*))
  324. The most useful types that will be returned are:
  325. SVt_IV Scalar
  326. SVt_NV Scalar
  327. SVt_PV Scalar
  328. SVt_RV Scalar
  329. SVt_PVAV Array
  330. SVt_PVHV Hash
  331. SVt_PVCV Code
  332. SVt_PVGV Glob (possible a file handle)
  333. SVt_PVMG Blessed or Magical Scalar
  334. See the sv.h header file for more details.
  335. =head2 Blessed References and Class Objects
  336. References are also used to support object-oriented programming. In the
  337. OO lexicon, an object is simply a reference that has been blessed into a
  338. package (or class). Once blessed, the programmer may now use the reference
  339. to access the various methods in the class.
  340. A reference can be blessed into a package with the following function:
  341. SV* sv_bless(SV* sv, HV* stash);
  342. The C<sv> argument must be a reference. The C<stash> argument specifies
  343. which class the reference will belong to. See
  344. L<Stashes and Globs> for information on converting class names into stashes.
  345. /* Still under construction */
  346. Upgrades rv to reference if not already one. Creates new SV for rv to
  347. point to. If C<classname> is non-null, the SV is blessed into the specified
  348. class. SV is returned.
  349. SV* newSVrv(SV* rv, char* classname);
  350. Copies integer or double into an SV whose reference is C<rv>. SV is blessed
  351. if C<classname> is non-null.
  352. SV* sv_setref_iv(SV* rv, char* classname, IV iv);
  353. SV* sv_setref_nv(SV* rv, char* classname, NV iv);
  354. Copies the pointer value (I<the address, not the string!>) into an SV whose
  355. reference is rv. SV is blessed if C<classname> is non-null.
  356. SV* sv_setref_pv(SV* rv, char* classname, PV iv);
  357. Copies string into an SV whose reference is C<rv>. Set length to 0 to let
  358. Perl calculate the string length. SV is blessed if C<classname> is non-null.
  359. SV* sv_setref_pvn(SV* rv, char* classname, PV iv, STRLEN length);
  360. Tests whether the SV is blessed into the specified class. It does not
  361. check inheritance relationships.
  362. int sv_isa(SV* sv, char* name);
  363. Tests whether the SV is a reference to a blessed object.
  364. int sv_isobject(SV* sv);
  365. Tests whether the SV is derived from the specified class. SV can be either
  366. a reference to a blessed object or a string containing a class name. This
  367. is the function implementing the C<UNIVERSAL::isa> functionality.
  368. bool sv_derived_from(SV* sv, char* name);
  369. To check if you've got an object derived from a specific class you have
  370. to write:
  371. if (sv_isobject(sv) && sv_derived_from(sv, class)) { ... }
  372. =head2 Creating New Variables
  373. To create a new Perl variable with an undef value which can be accessed from
  374. your Perl script, use the following routines, depending on the variable type.
  375. SV* perl_get_sv("package::varname", TRUE);
  376. AV* perl_get_av("package::varname", TRUE);
  377. HV* perl_get_hv("package::varname", TRUE);
  378. Notice the use of TRUE as the second parameter. The new variable can now
  379. be set, using the routines appropriate to the data type.
  380. There are additional macros whose values may be bitwise OR'ed with the
  381. C<TRUE> argument to enable certain extra features. Those bits are:
  382. GV_ADDMULTI Marks the variable as multiply defined, thus preventing the
  383. "Name <varname> used only once: possible typo" warning.
  384. GV_ADDWARN Issues the warning "Had to create <varname> unexpectedly" if
  385. the variable did not exist before the function was called.
  386. If you do not specify a package name, the variable is created in the current
  387. package.
  388. =head2 Reference Counts and Mortality
  389. Perl uses an reference count-driven garbage collection mechanism. SVs,
  390. AVs, or HVs (xV for short in the following) start their life with a
  391. reference count of 1. If the reference count of an xV ever drops to 0,
  392. then it will be destroyed and its memory made available for reuse.
  393. This normally doesn't happen at the Perl level unless a variable is
  394. undef'ed or the last variable holding a reference to it is changed or
  395. overwritten. At the internal level, however, reference counts can be
  396. manipulated with the following macros:
  397. int SvREFCNT(SV* sv);
  398. SV* SvREFCNT_inc(SV* sv);
  399. void SvREFCNT_dec(SV* sv);
  400. However, there is one other function which manipulates the reference
  401. count of its argument. The C<newRV_inc> function, you will recall,
  402. creates a reference to the specified argument. As a side effect,
  403. it increments the argument's reference count. If this is not what
  404. you want, use C<newRV_noinc> instead.
  405. For example, imagine you want to return a reference from an XSUB function.
  406. Inside the XSUB routine, you create an SV which initially has a reference
  407. count of one. Then you call C<newRV_inc>, passing it the just-created SV.
  408. This returns the reference as a new SV, but the reference count of the
  409. SV you passed to C<newRV_inc> has been incremented to two. Now you
  410. return the reference from the XSUB routine and forget about the SV.
  411. But Perl hasn't! Whenever the returned reference is destroyed, the
  412. reference count of the original SV is decreased to one and nothing happens.
  413. The SV will hang around without any way to access it until Perl itself
  414. terminates. This is a memory leak.
  415. The correct procedure, then, is to use C<newRV_noinc> instead of
  416. C<newRV_inc>. Then, if and when the last reference is destroyed,
  417. the reference count of the SV will go to zero and it will be destroyed,
  418. stopping any memory leak.
  419. There are some convenience functions available that can help with the
  420. destruction of xVs. These functions introduce the concept of "mortality".
  421. An xV that is mortal has had its reference count marked to be decremented,
  422. but not actually decremented, until "a short time later". Generally the
  423. term "short time later" means a single Perl statement, such as a call to
  424. an XSUB function. The actual determinant for when mortal xVs have their
  425. reference count decremented depends on two macros, SAVETMPS and FREETMPS.
  426. See L<perlcall> and L<perlxs> for more details on these macros.
  427. "Mortalization" then is at its simplest a deferred C<SvREFCNT_dec>.
  428. However, if you mortalize a variable twice, the reference count will
  429. later be decremented twice.
  430. You should be careful about creating mortal variables. Strange things
  431. can happen if you make the same value mortal within multiple contexts,
  432. or if you make a variable mortal multiple times.
  433. To create a mortal variable, use the functions:
  434. SV* sv_newmortal()
  435. SV* sv_2mortal(SV*)
  436. SV* sv_mortalcopy(SV*)
  437. The first call creates a mortal SV, the second converts an existing
  438. SV to a mortal SV (and thus defers a call to C<SvREFCNT_dec>), and the
  439. third creates a mortal copy of an existing SV.
  440. The mortal routines are not just for SVs -- AVs and HVs can be
  441. made mortal by passing their address (type-casted to C<SV*>) to the
  442. C<sv_2mortal> or C<sv_mortalcopy> routines.
  443. =head2 Stashes and Globs
  444. A "stash" is a hash that contains all of the different objects that
  445. are contained within a package. Each key of the stash is a symbol
  446. name (shared by all the different types of objects that have the same
  447. name), and each value in the hash table is a GV (Glob Value). This GV
  448. in turn contains references to the various objects of that name,
  449. including (but not limited to) the following:
  450. Scalar Value
  451. Array Value
  452. Hash Value
  453. I/O Handle
  454. Format
  455. Subroutine
  456. There is a single stash called "PL_defstash" that holds the items that exist
  457. in the "main" package. To get at the items in other packages, append the
  458. string "::" to the package name. The items in the "Foo" package are in
  459. the stash "Foo::" in PL_defstash. The items in the "Bar::Baz" package are
  460. in the stash "Baz::" in "Bar::"'s stash.
  461. To get the stash pointer for a particular package, use the function:
  462. HV* gv_stashpv(char* name, I32 create)
  463. HV* gv_stashsv(SV*, I32 create)
  464. The first function takes a literal string, the second uses the string stored
  465. in the SV. Remember that a stash is just a hash table, so you get back an
  466. C<HV*>. The C<create> flag will create a new package if it is set.
  467. The name that C<gv_stash*v> wants is the name of the package whose symbol table
  468. you want. The default package is called C<main>. If you have multiply nested
  469. packages, pass their names to C<gv_stash*v>, separated by C<::> as in the Perl
  470. language itself.
  471. Alternately, if you have an SV that is a blessed reference, you can find
  472. out the stash pointer by using:
  473. HV* SvSTASH(SvRV(SV*));
  474. then use the following to get the package name itself:
  475. char* HvNAME(HV* stash);
  476. If you need to bless or re-bless an object you can use the following
  477. function:
  478. SV* sv_bless(SV*, HV* stash)
  479. where the first argument, an C<SV*>, must be a reference, and the second
  480. argument is a stash. The returned C<SV*> can now be used in the same way
  481. as any other SV.
  482. For more information on references and blessings, consult L<perlref>.
  483. =head2 Double-Typed SVs
  484. Scalar variables normally contain only one type of value, an integer,
  485. double, pointer, or reference. Perl will automatically convert the
  486. actual scalar data from the stored type into the requested type.
  487. Some scalar variables contain more than one type of scalar data. For
  488. example, the variable C<$!> contains either the numeric value of C<errno>
  489. or its string equivalent from either C<strerror> or C<sys_errlist[]>.
  490. To force multiple data values into an SV, you must do two things: use the
  491. C<sv_set*v> routines to add the additional scalar type, then set a flag
  492. so that Perl will believe it contains more than one type of data. The
  493. four macros to set the flags are:
  494. SvIOK_on
  495. SvNOK_on
  496. SvPOK_on
  497. SvROK_on
  498. The particular macro you must use depends on which C<sv_set*v> routine
  499. you called first. This is because every C<sv_set*v> routine turns on
  500. only the bit for the particular type of data being set, and turns off
  501. all the rest.
  502. For example, to create a new Perl variable called "dberror" that contains
  503. both the numeric and descriptive string error values, you could use the
  504. following code:
  505. extern int dberror;
  506. extern char *dberror_list;
  507. SV* sv = perl_get_sv("dberror", TRUE);
  508. sv_setiv(sv, (IV) dberror);
  509. sv_setpv(sv, dberror_list[dberror]);
  510. SvIOK_on(sv);
  511. If the order of C<sv_setiv> and C<sv_setpv> had been reversed, then the
  512. macro C<SvPOK_on> would need to be called instead of C<SvIOK_on>.
  513. =head2 Magic Variables
  514. [This section still under construction. Ignore everything here. Post no
  515. bills. Everything not permitted is forbidden.]
  516. Any SV may be magical, that is, it has special features that a normal
  517. SV does not have. These features are stored in the SV structure in a
  518. linked list of C<struct magic>'s, typedef'ed to C<MAGIC>.
  519. struct magic {
  520. MAGIC* mg_moremagic;
  521. MGVTBL* mg_virtual;
  522. U16 mg_private;
  523. char mg_type;
  524. U8 mg_flags;
  525. SV* mg_obj;
  526. char* mg_ptr;
  527. I32 mg_len;
  528. };
  529. Note this is current as of patchlevel 0, and could change at any time.
  530. =head2 Assigning Magic
  531. Perl adds magic to an SV using the sv_magic function:
  532. void sv_magic(SV* sv, SV* obj, int how, char* name, I32 namlen);
  533. The C<sv> argument is a pointer to the SV that is to acquire a new magical
  534. feature.
  535. If C<sv> is not already magical, Perl uses the C<SvUPGRADE> macro to
  536. set the C<SVt_PVMG> flag for the C<sv>. Perl then continues by adding
  537. it to the beginning of the linked list of magical features. Any prior
  538. entry of the same type of magic is deleted. Note that this can be
  539. overridden, and multiple instances of the same type of magic can be
  540. associated with an SV.
  541. The C<name> and C<namlen> arguments are used to associate a string with
  542. the magic, typically the name of a variable. C<namlen> is stored in the
  543. C<mg_len> field and if C<name> is non-null and C<namlen> >= 0 a malloc'd
  544. copy of the name is stored in C<mg_ptr> field.
  545. The sv_magic function uses C<how> to determine which, if any, predefined
  546. "Magic Virtual Table" should be assigned to the C<mg_virtual> field.
  547. See the "Magic Virtual Table" section below. The C<how> argument is also
  548. stored in the C<mg_type> field.
  549. The C<obj> argument is stored in the C<mg_obj> field of the C<MAGIC>
  550. structure. If it is not the same as the C<sv> argument, the reference
  551. count of the C<obj> object is incremented. If it is the same, or if
  552. the C<how> argument is "#", or if it is a NULL pointer, then C<obj> is
  553. merely stored, without the reference count being incremented.
  554. There is also a function to add magic to an C<HV>:
  555. void hv_magic(HV *hv, GV *gv, int how);
  556. This simply calls C<sv_magic> and coerces the C<gv> argument into an C<SV>.
  557. To remove the magic from an SV, call the function sv_unmagic:
  558. void sv_unmagic(SV *sv, int type);
  559. The C<type> argument should be equal to the C<how> value when the C<SV>
  560. was initially made magical.
  561. =head2 Magic Virtual Tables
  562. The C<mg_virtual> field in the C<MAGIC> structure is a pointer to a
  563. C<MGVTBL>, which is a structure of function pointers and stands for
  564. "Magic Virtual Table" to handle the various operations that might be
  565. applied to that variable.
  566. The C<MGVTBL> has five pointers to the following routine types:
  567. int (*svt_get)(SV* sv, MAGIC* mg);
  568. int (*svt_set)(SV* sv, MAGIC* mg);
  569. U32 (*svt_len)(SV* sv, MAGIC* mg);
  570. int (*svt_clear)(SV* sv, MAGIC* mg);
  571. int (*svt_free)(SV* sv, MAGIC* mg);
  572. This MGVTBL structure is set at compile-time in C<perl.h> and there are
  573. currently 19 types (or 21 with overloading turned on). These different
  574. structures contain pointers to various routines that perform additional
  575. actions depending on which function is being called.
  576. Function pointer Action taken
  577. ---------------- ------------
  578. svt_get Do something after the value of the SV is retrieved.
  579. svt_set Do something after the SV is assigned a value.
  580. svt_len Report on the SV's length.
  581. svt_clear Clear something the SV represents.
  582. svt_free Free any extra storage associated with the SV.
  583. For instance, the MGVTBL structure called C<vtbl_sv> (which corresponds
  584. to an C<mg_type> of '\0') contains:
  585. { magic_get, magic_set, magic_len, 0, 0 }
  586. Thus, when an SV is determined to be magical and of type '\0', if a get
  587. operation is being performed, the routine C<magic_get> is called. All
  588. the various routines for the various magical types begin with C<magic_>.
  589. The current kinds of Magic Virtual Tables are:
  590. mg_type MGVTBL Type of magic
  591. ------- ------ ----------------------------
  592. \0 vtbl_sv Special scalar variable
  593. A vtbl_amagic %OVERLOAD hash
  594. a vtbl_amagicelem %OVERLOAD hash element
  595. c (none) Holds overload table (AMT) on stash
  596. B vtbl_bm Boyer-Moore (fast string search)
  597. E vtbl_env %ENV hash
  598. e vtbl_envelem %ENV hash element
  599. f vtbl_fm Formline ('compiled' format)
  600. g vtbl_mglob m//g target / study()ed string
  601. I vtbl_isa @ISA array
  602. i vtbl_isaelem @ISA array element
  603. k vtbl_nkeys scalar(keys()) lvalue
  604. L (none) Debugger %_<filename
  605. l vtbl_dbline Debugger %_<filename element
  606. o vtbl_collxfrm Locale transformation
  607. P vtbl_pack Tied array or hash
  608. p vtbl_packelem Tied array or hash element
  609. q vtbl_packelem Tied scalar or handle
  610. S vtbl_sig %SIG hash
  611. s vtbl_sigelem %SIG hash element
  612. t vtbl_taint Taintedness
  613. U vtbl_uvar Available for use by extensions
  614. v vtbl_vec vec() lvalue
  615. x vtbl_substr substr() lvalue
  616. y vtbl_defelem Shadow "foreach" iterator variable /
  617. smart parameter vivification
  618. * vtbl_glob GV (typeglob)
  619. # vtbl_arylen Array length ($#ary)
  620. . vtbl_pos pos() lvalue
  621. ~ (none) Available for use by extensions
  622. When an uppercase and lowercase letter both exist in the table, then the
  623. uppercase letter is used to represent some kind of composite type (a list
  624. or a hash), and the lowercase letter is used to represent an element of
  625. that composite type.
  626. The '~' and 'U' magic types are defined specifically for use by
  627. extensions and will not be used by perl itself. Extensions can use
  628. '~' magic to 'attach' private information to variables (typically
  629. objects). This is especially useful because there is no way for
  630. normal perl code to corrupt this private information (unlike using
  631. extra elements of a hash object).
  632. Similarly, 'U' magic can be used much like tie() to call a C function
  633. any time a scalar's value is used or changed. The C<MAGIC>'s
  634. C<mg_ptr> field points to a C<ufuncs> structure:
  635. struct ufuncs {
  636. I32 (*uf_val)(IV, SV*);
  637. I32 (*uf_set)(IV, SV*);
  638. IV uf_index;
  639. };
  640. When the SV is read from or written to, the C<uf_val> or C<uf_set>
  641. function will be called with C<uf_index> as the first arg and a
  642. pointer to the SV as the second. A simple example of how to add 'U'
  643. magic is shown below. Note that the ufuncs structure is copied by
  644. sv_magic, so you can safely allocate it on the stack.
  645. void
  646. Umagic(sv)
  647. SV *sv;
  648. PREINIT:
  649. struct ufuncs uf;
  650. CODE:
  651. uf.uf_val = &my_get_fn;
  652. uf.uf_set = &my_set_fn;
  653. uf.uf_index = 0;
  654. sv_magic(sv, 0, 'U', (char*)&uf, sizeof(uf));
  655. Note that because multiple extensions may be using '~' or 'U' magic,
  656. it is important for extensions to take extra care to avoid conflict.
  657. Typically only using the magic on objects blessed into the same class
  658. as the extension is sufficient. For '~' magic, it may also be
  659. appropriate to add an I32 'signature' at the top of the private data
  660. area and check that.
  661. Also note that the C<sv_set*()> and C<sv_cat*()> functions described
  662. earlier do B<not> invoke 'set' magic on their targets. This must
  663. be done by the user either by calling the C<SvSETMAGIC()> macro after
  664. calling these functions, or by using one of the C<sv_set*_mg()> or
  665. C<sv_cat*_mg()> functions. Similarly, generic C code must call the
  666. C<SvGETMAGIC()> macro to invoke any 'get' magic if they use an SV
  667. obtained from external sources in functions that don't handle magic.
  668. L<API LISTING> later in this document identifies such functions.
  669. For example, calls to the C<sv_cat*()> functions typically need to be
  670. followed by C<SvSETMAGIC()>, but they don't need a prior C<SvGETMAGIC()>
  671. since their implementation handles 'get' magic.
  672. =head2 Finding Magic
  673. MAGIC* mg_find(SV*, int type); /* Finds the magic pointer of that type */
  674. This routine returns a pointer to the C<MAGIC> structure stored in the SV.
  675. If the SV does not have that magical feature, C<NULL> is returned. Also,
  676. if the SV is not of type SVt_PVMG, Perl may core dump.
  677. int mg_copy(SV* sv, SV* nsv, char* key, STRLEN klen);
  678. This routine checks to see what types of magic C<sv> has. If the mg_type
  679. field is an uppercase letter, then the mg_obj is copied to C<nsv>, but
  680. the mg_type field is changed to be the lowercase letter.
  681. =head2 Understanding the Magic of Tied Hashes and Arrays
  682. Tied hashes and arrays are magical beasts of the 'P' magic type.
  683. WARNING: As of the 5.004 release, proper usage of the array and hash
  684. access functions requires understanding a few caveats. Some
  685. of these caveats are actually considered bugs in the API, to be fixed
  686. in later releases, and are bracketed with [MAYCHANGE] below. If
  687. you find yourself actually applying such information in this section, be
  688. aware that the behavior may change in the future, umm, without warning.
  689. The perl tie function associates a variable with an object that implements
  690. the various GET, SET etc methods. To perform the equivalent of the perl
  691. tie function from an XSUB, you must mimic this behaviour. The code below
  692. carries out the necessary steps - firstly it creates a new hash, and then
  693. creates a second hash which it blesses into the class which will implement
  694. the tie methods. Lastly it ties the two hashes together, and returns a
  695. reference to the new tied hash. Note that the code below does NOT call the
  696. TIEHASH method in the MyTie class -
  697. see L<Calling Perl Routines from within C Programs> for details on how
  698. to do this.
  699. SV*
  700. mytie()
  701. PREINIT:
  702. HV *hash;
  703. HV *stash;
  704. SV *tie;
  705. CODE:
  706. hash = newHV();
  707. tie = newRV_noinc((SV*)newHV());
  708. stash = gv_stashpv("MyTie", TRUE);
  709. sv_bless(tie, stash);
  710. hv_magic(hash, tie, 'P');
  711. RETVAL = newRV_noinc(hash);
  712. OUTPUT:
  713. RETVAL
  714. The C<av_store> function, when given a tied array argument, merely
  715. copies the magic of the array onto the value to be "stored", using
  716. C<mg_copy>. It may also return NULL, indicating that the value did not
  717. actually need to be stored in the array. [MAYCHANGE] After a call to
  718. C<av_store> on a tied array, the caller will usually need to call
  719. C<mg_set(val)> to actually invoke the perl level "STORE" method on the
  720. TIEARRAY object. If C<av_store> did return NULL, a call to
  721. C<SvREFCNT_dec(val)> will also be usually necessary to avoid a memory
  722. leak. [/MAYCHANGE]
  723. The previous paragraph is applicable verbatim to tied hash access using the
  724. C<hv_store> and C<hv_store_ent> functions as well.
  725. C<av_fetch> and the corresponding hash functions C<hv_fetch> and
  726. C<hv_fetch_ent> actually return an undefined mortal value whose magic
  727. has been initialized using C<mg_copy>. Note the value so returned does not
  728. need to be deallocated, as it is already mortal. [MAYCHANGE] But you will
  729. need to call C<mg_get()> on the returned value in order to actually invoke
  730. the perl level "FETCH" method on the underlying TIE object. Similarly,
  731. you may also call C<mg_set()> on the return value after possibly assigning
  732. a suitable value to it using C<sv_setsv>, which will invoke the "STORE"
  733. method on the TIE object. [/MAYCHANGE]
  734. [MAYCHANGE]
  735. In other words, the array or hash fetch/store functions don't really
  736. fetch and store actual values in the case of tied arrays and hashes. They
  737. merely call C<mg_copy> to attach magic to the values that were meant to be
  738. "stored" or "fetched". Later calls to C<mg_get> and C<mg_set> actually
  739. do the job of invoking the TIE methods on the underlying objects. Thus
  740. the magic mechanism currently implements a kind of lazy access to arrays
  741. and hashes.
  742. Currently (as of perl version 5.004), use of the hash and array access
  743. functions requires the user to be aware of whether they are operating on
  744. "normal" hashes and arrays, or on their tied variants. The API may be
  745. changed to provide more transparent access to both tied and normal data
  746. types in future versions.
  747. [/MAYCHANGE]
  748. You would do well to understand that the TIEARRAY and TIEHASH interfaces
  749. are mere sugar to invoke some perl method calls while using the uniform hash
  750. and array syntax. The use of this sugar imposes some overhead (typically
  751. about two to four extra opcodes per FETCH/STORE operation, in addition to
  752. the creation of all the mortal variables required to invoke the methods).
  753. This overhead will be comparatively small if the TIE methods are themselves
  754. substantial, but if they are only a few statements long, the overhead
  755. will not be insignificant.
  756. =head2 Localizing changes
  757. Perl has a very handy construction
  758. {
  759. local $var = 2;
  760. ...
  761. }
  762. This construction is I<approximately> equivalent to
  763. {
  764. my $oldvar = $var;
  765. $var = 2;
  766. ...
  767. $var = $oldvar;
  768. }
  769. The biggest difference is that the first construction would
  770. reinstate the initial value of $var, irrespective of how control exits
  771. the block: C<goto>, C<return>, C<die>/C<eval> etc. It is a little bit
  772. more efficient as well.
  773. There is a way to achieve a similar task from C via Perl API: create a
  774. I<pseudo-block>, and arrange for some changes to be automatically
  775. undone at the end of it, either explicit, or via a non-local exit (via
  776. die()). A I<block>-like construct is created by a pair of
  777. C<ENTER>/C<LEAVE> macros (see L<perlcall/"Returning a Scalar">).
  778. Such a construct may be created specially for some important localized
  779. task, or an existing one (like boundaries of enclosing Perl
  780. subroutine/block, or an existing pair for freeing TMPs) may be
  781. used. (In the second case the overhead of additional localization must
  782. be almost negligible.) Note that any XSUB is automatically enclosed in
  783. an C<ENTER>/C<LEAVE> pair.
  784. Inside such a I<pseudo-block> the following service is available:
  785. =over
  786. =item C<SAVEINT(int i)>
  787. =item C<SAVEIV(IV i)>
  788. =item C<SAVEI32(I32 i)>
  789. =item C<SAVELONG(long i)>
  790. These macros arrange things to restore the value of integer variable
  791. C<i> at the end of enclosing I<pseudo-block>.
  792. =item C<SAVESPTR(s)>
  793. =item C<SAVEPPTR(p)>
  794. These macros arrange things to restore the value of pointers C<s> and
  795. C<p>. C<s> must be a pointer of a type which survives conversion to
  796. C<SV*> and back, C<p> should be able to survive conversion to C<char*>
  797. and back.
  798. =item C<SAVEFREESV(SV *sv)>
  799. The refcount of C<sv> would be decremented at the end of
  800. I<pseudo-block>. This is similar to C<sv_2mortal>, which should (?) be
  801. used instead.
  802. =item C<SAVEFREEOP(OP *op)>
  803. The C<OP *> is op_free()ed at the end of I<pseudo-block>.
  804. =item C<SAVEFREEPV(p)>
  805. The chunk of memory which is pointed to by C<p> is Safefree()ed at the
  806. end of I<pseudo-block>.
  807. =item C<SAVECLEARSV(SV *sv)>
  808. Clears a slot in the current scratchpad which corresponds to C<sv> at
  809. the end of I<pseudo-block>.
  810. =item C<SAVEDELETE(HV *hv, char *key, I32 length)>
  811. The key C<key> of C<hv> is deleted at the end of I<pseudo-block>. The
  812. string pointed to by C<key> is Safefree()ed. If one has a I<key> in
  813. short-lived storage, the corresponding string may be reallocated like
  814. this:
  815. SAVEDELETE(PL_defstash, savepv(tmpbuf), strlen(tmpbuf));
  816. =item C<SAVEDESTRUCTOR(f,p)>
  817. At the end of I<pseudo-block> the function C<f> is called with the
  818. only argument (of type C<void*>) C<p>.
  819. =item C<SAVESTACK_POS()>
  820. The current offset on the Perl internal stack (cf. C<SP>) is restored
  821. at the end of I<pseudo-block>.
  822. =back
  823. The following API list contains functions, thus one needs to
  824. provide pointers to the modifiable data explicitly (either C pointers,
  825. or Perlish C<GV *>s). Where the above macros take C<int>, a similar
  826. function takes C<int *>.
  827. =over
  828. =item C<SV* save_scalar(GV *gv)>
  829. Equivalent to Perl code C<local $gv>.
  830. =item C<AV* save_ary(GV *gv)>
  831. =item C<HV* save_hash(GV *gv)>
  832. Similar to C<save_scalar>, but localize C<@gv> and C<%gv>.
  833. =item C<void save_item(SV *item)>
  834. Duplicates the current value of C<SV>, on the exit from the current
  835. C<ENTER>/C<LEAVE> I<pseudo-block> will restore the value of C<SV>
  836. using the stored value.
  837. =item C<void save_list(SV **sarg, I32 maxsarg)>
  838. A variant of C<save_item> which takes multiple arguments via an array
  839. C<sarg> of C<SV*> of length C<maxsarg>.
  840. =item C<SV* save_svref(SV **sptr)>
  841. Similar to C<save_scalar>, but will reinstate a C<SV *>.
  842. =item C<void save_aptr(AV **aptr)>
  843. =item C<void save_hptr(HV **hptr)>
  844. Similar to C<save_svref>, but localize C<AV *> and C<HV *>.
  845. =back
  846. The C<Alias> module implements localization of the basic types within the
  847. I<caller's scope>. People who are interested in how to localize things in
  848. the containing scope should take a look there too.
  849. =head1 Subroutines
  850. =head2 XSUBs and the Argument Stack
  851. The XSUB mechanism is a simple way for Perl programs to access C subroutines.
  852. An XSUB routine will have a stack that contains the arguments from the Perl
  853. program, and a way to map from the Perl data structures to a C equivalent.
  854. The stack arguments are accessible through the C<ST(n)> macro, which returns
  855. the C<n>'th stack argument. Argument 0 is the first argument passed in the
  856. Perl subroutine call. These arguments are C<SV*>, and can be used anywhere
  857. an C<SV*> is used.
  858. Most of the time, output from the C routine can be handled through use of
  859. the RETVAL and OUTPUT directives. However, there are some cases where the
  860. argument stack is not already long enough to handle all the return values.
  861. An example is the POSIX tzname() call, which takes no arguments, but returns
  862. two, the local time zone's standard and summer time abbreviations.
  863. To handle this situation, the PPCODE directive is used and the stack is
  864. extended using the macro:
  865. EXTEND(SP, num);
  866. where C<SP> is the macro that represents the local copy of the stack pointer,
  867. and C<num> is the number of elements the stack should be extended by.
  868. Now that there is room on the stack, values can be pushed on it using the
  869. macros to push IVs, doubles, strings, and SV pointers respectively:
  870. PUSHi(IV)
  871. PUSHn(double)
  872. PUSHp(char*, I32)
  873. PUSHs(SV*)
  874. And now the Perl program calling C<tzname>, the two values will be assigned
  875. as in:
  876. ($standard_abbrev, $summer_abbrev) = POSIX::tzname;
  877. An alternate (and possibly simpler) method to pushing values on the stack is
  878. to use the macros:
  879. XPUSHi(IV)
  880. XPUSHn(double)
  881. XPUSHp(char*, I32)
  882. XPUSHs(SV*)
  883. These macros automatically adjust the stack for you, if needed. Thus, you
  884. do not need to call C<EXTEND> to extend the stack.
  885. For more information, consult L<perlxs> and L<perlxstut>.
  886. =head2 Calling Perl Routines from within C Programs
  887. There are four routines that can be used to call a Perl subroutine from
  888. within a C program. These four are:
  889. I32 perl_call_sv(SV*, I32);
  890. I32 perl_call_pv(char*, I32);
  891. I32 perl_call_method(char*, I32);
  892. I32 perl_call_argv(char*, I32, register char**);
  893. The routine most often used is C<perl_call_sv>. The C<SV*> argument
  894. contains either the name of the Perl subroutine to be called, or a
  895. reference to the subroutine. The second argument consists of flags
  896. that control the context in which the subroutine is called, whether
  897. or not the subroutine is being passed arguments, how errors should be
  898. trapped, and how to treat return values.
  899. All four routines return the number of arguments that the subroutine returned
  900. on the Perl stack.
  901. When using any of these routines (except C<perl_call_argv>), the programmer
  902. must manipulate the Perl stack. These include the following macros and
  903. functions:
  904. dSP
  905. SP
  906. PUSHMARK()
  907. PUTBACK
  908. SPAGAIN
  909. ENTER
  910. SAVETMPS
  911. FREETMPS
  912. LEAVE
  913. XPUSH*()
  914. POP*()
  915. For a detailed description of calling conventions from C to Perl,
  916. consult L<perlcall>.
  917. =head2 Memory Allocation
  918. All memory meant to be used with the Perl API functions should be manipulated
  919. using the macros described in this section. The macros provide the necessary
  920. transparency between differences in the actual malloc implementation that is
  921. used within perl.
  922. It is suggested that you enable the version of malloc that is distributed
  923. with Perl. It keeps pools of various sizes of unallocated memory in
  924. order to satisfy allocation requests more quickly. However, on some
  925. platforms, it may cause spurious malloc or free errors.
  926. New(x, pointer, number, type);
  927. Newc(x, pointer, number, type, cast);
  928. Newz(x, pointer, number, type);
  929. These three macros are used to initially allocate memory.
  930. The first argument C<x> was a "magic cookie" that was used to keep track
  931. of who called the macro, to help when debugging memory problems. However,
  932. the current code makes no use of this feature (most Perl developers now
  933. use run-time memory checkers), so this argument can be any number.
  934. The second argument C<pointer> should be the name of a variable that will
  935. point to the newly allocated memory.
  936. The third and fourth arguments C<number> and C<type> specify how many of
  937. the specified type of data structure should be allocated. The argument
  938. C<type> is passed to C<sizeof>. The final argument to C<Newc>, C<cast>,
  939. should be used if the C<pointer> argument is different from the C<type>
  940. argument.
  941. Unlike the C<New> and C<Newc> macros, the C<Newz> macro calls C<memzero>
  942. to zero out all the newly allocated memory.
  943. Renew(pointer, number, type);
  944. Renewc(pointer, number, type, cast);
  945. Safefree(pointer)
  946. These three macros are used to change a memory buffer size or to free a
  947. piece of memory no longer needed. The arguments to C<Renew> and C<Renewc>
  948. match those of C<New> and C<Newc> with the exception of not needing the
  949. "magic cookie" argument.
  950. Move(source, dest, number, type);
  951. Copy(source, dest, number, type);
  952. Zero(dest, number, type);
  953. These three macros are used to move, copy, or zero out previously allocated
  954. memory. The C<source> and C<dest> arguments point to the source and
  955. destination starting points. Perl will move, copy, or zero out C<number>
  956. instances of the size of the C<type> data structure (using the C<sizeof>
  957. function).
  958. =head2 PerlIO
  959. The most recent development releases of Perl has been experimenting with
  960. removing Perl's dependency on the "normal" standard I/O suite and allowing
  961. other stdio implementations to be used. This involves creating a new
  962. abstraction layer that then calls whichever implementation of stdio Perl
  963. was compiled with. All XSUBs should now use the functions in the PerlIO
  964. abstraction layer and not make any assumptions about what kind of stdio
  965. is being used.
  966. For a complete description of the PerlIO abstraction, consult L<perlapio>.
  967. =head2 Putting a C value on Perl stack
  968. A lot of opcodes (this is an elementary operation in the internal perl
  969. stack machine) put an SV* on the stack. However, as an optimization
  970. the corresponding SV is (usually) not recreated each time. The opcodes
  971. reuse specially assigned SVs (I<target>s) which are (as a corollary)
  972. not constantly freed/created.
  973. Each of the targets is created only once (but see
  974. L<Scratchpads and recursion> below), and when an opcode needs to put
  975. an integer, a double, or a string on stack, it just sets the
  976. corresponding parts of its I<target> and puts the I<target> on stack.
  977. The macro to put this target on stack is C<PUSHTARG>, and it is
  978. directly used in some opcodes, as well as indirectly in zillions of
  979. others, which use it via C<(X)PUSH[pni]>.
  980. =head2 Scratchpads
  981. The question remains on when the SVs which are I<target>s for opcodes
  982. are created. The answer is that they are created when the current unit --
  983. a subroutine or a file (for opcodes for statements outside of
  984. subroutines) -- is compiled. During this time a special anonymous Perl
  985. array is created, which is called a scratchpad for the current
  986. unit.
  987. A scratchpad keeps SVs which are lexicals for the current unit and are
  988. targets for opcodes. One can deduce that an SV lives on a scratchpad
  989. by looking on its flags: lexicals have C<SVs_PADMY> set, and
  990. I<target>s have C<SVs_PADTMP> set.
  991. The correspondence between OPs and I<target>s is not 1-to-1. Different
  992. OPs in the compile tree of the unit can use the same target, if this
  993. would not conflict with the expected life of the temporary.
  994. =head2 Scratchpads and recursion
  995. In fact it is not 100% true that a compiled unit contains a pointer to
  996. the scratchpad AV. In fact it contains a pointer to an AV of
  997. (initially) one element, and this element is the scratchpad AV. Why do
  998. we need an extra level of indirection?
  999. The answer is B<recursion>, and maybe (sometime soon) B<threads>. Both
  1000. these can create several execution pointers going into the same
  1001. subroutine. For the subroutine-child not write over the temporaries
  1002. for the subroutine-parent (lifespan of which covers the call to the
  1003. child), the parent and the child should have different
  1004. scratchpads. (I<And> the lexicals should be separate anyway!)
  1005. So each subroutine is born with an array of scratchpads (of length 1).
  1006. On each entry to the subroutine it is checked that the current
  1007. depth of the recursion is not more than the length of this array, and
  1008. if it is, new scratchpad is created and pushed into the array.
  1009. The I<target>s on this scratchpad are C<undef>s, but they are already
  1010. marked with correct flags.
  1011. =head1 Compiled code
  1012. =head2 Code tree
  1013. Here we describe the internal form your code is converted to by
  1014. Perl. Start with a simple example:
  1015. $a = $b + $c;
  1016. This is converted to a tree similar to this one:
  1017. assign-to
  1018. / \
  1019. + $a
  1020. / \
  1021. $b $c
  1022. (but slightly more complicated). This tree reflects the way Perl
  1023. parsed your code, but has nothing to do with the execution order.
  1024. There is an additional "thread" going through the nodes of the tree
  1025. which shows the order of execution of the nodes. In our simplified
  1026. example above it looks like:
  1027. $b ---> $c ---> + ---> $a ---> assign-to
  1028. But with the actual compile tree for C<$a = $b + $c> it is different:
  1029. some nodes I<optimized away>. As a corollary, though the actual tree
  1030. contains more nodes than our simplified example, the execution order
  1031. is the same as in our example.
  1032. =head2 Examining the tree
  1033. If you have your perl compiled for debugging (usually done with C<-D
  1034. optimize=-g> on C<Configure> command line), you may examine the
  1035. compiled tree by specifying C<-Dx> on the Perl command line. The
  1036. output takes several lines per node, and for C<$b+$c> it looks like
  1037. this:
  1038. 5 TYPE = add ===> 6
  1039. TARG = 1
  1040. FLAGS = (SCALAR,KIDS)
  1041. {
  1042. TYPE = null ===> (4)
  1043. (was rv2sv)
  1044. FLAGS = (SCALAR,KIDS)
  1045. {
  1046. 3 TYPE = gvsv ===> 4
  1047. FLAGS = (SCALAR)
  1048. GV = main::b
  1049. }
  1050. }
  1051. {
  1052. TYPE = null ===> (5)
  1053. (was rv2sv)
  1054. FLAGS = (SCALAR,KIDS)
  1055. {
  1056. 4 TYPE = gvsv ===> 5
  1057. FLAGS = (SCALAR)
  1058. GV = main::c
  1059. }
  1060. }
  1061. This tree has 5 nodes (one per C<TYPE> specifier), only 3 of them are
  1062. not optimized away (one per number in the left column). The immediate
  1063. children of the given node correspond to C<{}> pairs on the same level
  1064. of indentation, thus this listing corresponds to the tree:
  1065. add
  1066. / \
  1067. null null
  1068. | |
  1069. gvsv gvsv
  1070. The execution order is indicated by C<===E<gt>> marks, thus it is C<3
  1071. 4 5 6> (node C<6> is not included into above listing), i.e.,
  1072. C<gvsv gvsv add whatever>.
  1073. =head2 Compile pass 1: check routines
  1074. The tree is created by the I<pseudo-compiler> while yacc code feeds it
  1075. the constructions it recognizes. Since yacc works bottom-up, so does
  1076. the first pass of perl compilation.
  1077. What makes this pass interesting for perl developers is that some
  1078. optimization may be performed on this pass. This is optimization by
  1079. so-called I<check routines>. The correspondence between node names
  1080. and corresponding check routines is described in F<opcode.pl> (do not
  1081. forget to run C<make regen_headers> if you modify this file).
  1082. A check routine is called when the node is fully constructed except
  1083. for the execution-order thread. Since at this time there are no
  1084. back-links to the currently constructed node, one can do most any
  1085. operation to the top-level node, including freeing it and/or creating
  1086. new nodes above/below it.
  1087. The check routine returns the node which should be inserted into the
  1088. tree (if the top-level node was not modified, check routine returns
  1089. its argument).
  1090. By convention, check routines have names C<ck_*>. They are usually
  1091. called from C<new*OP> subroutines (or C<convert>) (which in turn are
  1092. called from F<perly.y>).
  1093. =head2 Compile pass 1a: constant folding
  1094. Immediately after the check routine is called the returned node is
  1095. checked for being compile-time executable. If it is (the value is
  1096. judged to be constant) it is immediately executed, and a I<constant>
  1097. node with the "return value" of the corresponding subtree is
  1098. substituted instead. The subtree is deleted.
  1099. If constant folding was not performed, the execution-order thread is
  1100. created.
  1101. =head2 Compile pass 2: context propagation
  1102. When a context for a part of compile tree is known, it is propagated
  1103. down through the tree. At this time the context can have 5 values
  1104. (instead of 2 for runtime context): void, boolean, scalar, list, and
  1105. lvalue. In contrast with the pass 1 this pass is processed from top
  1106. to bottom: a node's context determines the context for its children.
  1107. Additional context-dependent optimizations are performed at this time.
  1108. Since at this moment the compile tree contains back-references (via
  1109. "thread" pointers), nodes cannot be free()d now. To allow
  1110. optimized-away nodes at this stage, such nodes are null()ified instead
  1111. of free()ing (i.e. their type is changed to OP_NULL).
  1112. =head2 Compile pass 3: peephole optimization
  1113. After the compile tree for a subroutine (or for an C<eval> or a file)
  1114. is created, an additional pass over the code is performed. This pass
  1115. is neither top-down or bottom-up, but in the execution order (with
  1116. additional complications for conditionals). These optimizations are
  1117. done in the subroutine peep(). Optimizations performed at this stage
  1118. are subject to the same restrictions as in the pass 2.
  1119. =head1 API LISTING
  1120. This is a listing of functions, macros, flags, and variables that may be
  1121. useful to extension writers or that may be found while reading other
  1122. extensions.
  1123. Note that all Perl API global variables must be referenced with the C<PL_>
  1124. prefix. Some macros are provided for compatibility with the older,
  1125. unadorned names, but this support will be removed in a future release.
  1126. It is strongly recommended that all Perl API functions that don't begin
  1127. with C<perl> be referenced with an explicit C<Perl_> prefix.
  1128. The sort order of the listing is case insensitive, with any
  1129. occurrences of '_' ignored for the purpose of sorting.
  1130. =over 8
  1131. =item av_clear
  1132. Clears an array, making it empty. Does not free the memory used by the
  1133. array itself.
  1134. void av_clear (AV* ar)
  1135. =item av_extend
  1136. Pre-extend an array. The C<key> is the index to which the array should be
  1137. extended.
  1138. void av_extend (AV* ar, I32 key)
  1139. =item av_fetch
  1140. Returns the SV at the specified index in the array. The C<key> is the
  1141. index. If C<lval> is set then the fetch will be part of a store. Check
  1142. that the return value is non-null before dereferencing it to a C<SV*>.
  1143. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  1144. information on how to use this function on tied arrays.
  1145. SV** av_fetch (AV* ar, I32 key, I32 lval)
  1146. =item AvFILL
  1147. Same as C<av_len()>. Deprecated, use C<av_len()> instead.
  1148. =item av_len
  1149. Returns the highest index in the array. Returns -1 if the array is empty.
  1150. I32 av_len (AV* ar)
  1151. =item av_make
  1152. Creates a new AV and populates it with a list of SVs. The SVs are copied
  1153. into the array, so they may be freed after the call to av_make. The new AV
  1154. will have a reference count of 1.
  1155. AV* av_make (I32 size, SV** svp)
  1156. =item av_pop
  1157. Pops an SV off the end of the array. Returns C<&PL_sv_undef> if the array is
  1158. empty.
  1159. SV* av_pop (AV* ar)
  1160. =item av_push
  1161. Pushes an SV onto the end of the array. The array will grow automatically
  1162. to accommodate the addition.
  1163. void av_push (AV* ar, SV* val)
  1164. =item av_shift
  1165. Shifts an SV off the beginning of the array.
  1166. SV* av_shift (AV* ar)
  1167. =item av_store
  1168. Stores an SV in an array. The array index is specified as C<key>. The
  1169. return value will be NULL if the operation failed or if the value did not
  1170. need to be actually stored within the array (as in the case of tied arrays).
  1171. Otherwise it can be dereferenced to get the original C<SV*>. Note that the
  1172. caller is responsible for suitably incrementing the reference count of C<val>
  1173. before the call, and decrementing it if the function returned NULL.
  1174. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  1175. information on how to use this function on tied arrays.
  1176. SV** av_store (AV* ar, I32 key, SV* val)
  1177. =item av_undef
  1178. Undefines the array. Frees the memory used by the array itself.
  1179. void av_undef (AV* ar)
  1180. =item av_unshift
  1181. Unshift the given number of C<undef> values onto the beginning of the
  1182. array. The array will grow automatically to accommodate the addition.
  1183. You must then use C<av_store> to assign values to these new elements.
  1184. void av_unshift (AV* ar, I32 num)
  1185. =item CLASS
  1186. Variable which is setup by C<xsubpp> to indicate the class name for a C++ XS
  1187. constructor. This is always a C<char*>. See C<THIS> and
  1188. L<perlxs/"Using XS With C++">.
  1189. =item Copy
  1190. The XSUB-writer's interface to the C C<memcpy> function. The C<s> is the
  1191. source, C<d> is the destination, C<n> is the number of items, and C<t> is
  1192. the type. May fail on overlapping copies. See also C<Move>.
  1193. void Copy( s, d, n, t )
  1194. =item croak
  1195. This is the XSUB-writer's interface to Perl's C<die> function. Use this
  1196. function the same way you use the C C<printf> function. See C<warn>.
  1197. =item CvSTASH
  1198. Returns the stash of the CV.
  1199. HV* CvSTASH( SV* sv )
  1200. =item PL_DBsingle
  1201. When Perl is run in debugging mode, with the B<-d> switch, this SV is a
  1202. boolean which indicates whether subs are being single-stepped.
  1203. Single-stepping is automatically turned on after every step. This is the C
  1204. variable which corresponds to Perl's $DB::single variable. See C<PL_DBsub>.
  1205. =item PL_DBsub
  1206. When Perl is run in debugging mode, with the B<-d> switch, this GV contains
  1207. the SV which holds the name of the sub being debugged. This is the C
  1208. variable which corresponds to Perl's $DB::sub variable. See C<PL_DBsingle>.
  1209. The sub name can be found by
  1210. SvPV( GvSV( PL_DBsub ), len )
  1211. =item PL_DBtrace
  1212. Trace variable used when Perl is run in debugging mode, with the B<-d>
  1213. switch. This is the C variable which corresponds to Perl's $DB::trace
  1214. variable. See C<PL_DBsingle>.
  1215. =item dMARK
  1216. Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
  1217. C<dORIGMARK>.
  1218. =item dORIGMARK
  1219. Saves the original stack mark for the XSUB. See C<ORIGMARK>.
  1220. =item PL_dowarn
  1221. The C variable which corresponds to Perl's $^W warning variable.
  1222. =item dSP
  1223. Declares a local copy of perl's stack pointer for the XSUB, available via
  1224. the C<SP> macro. See C<SP>.
  1225. =item dXSARGS
  1226. Sets up stack and mark pointers for an XSUB, calling dSP and dMARK. This is
  1227. usually handled automatically by C<xsubpp>. Declares the C<items> variable
  1228. to indicate the number of items on the stack.
  1229. =item dXSI32
  1230. Sets up the C<ix> variable for an XSUB which has aliases. This is usually
  1231. handled automatically by C<xsubpp>.
  1232. =item do_binmode
  1233. Switches filehandle to binmode. C<iotype> is what C<IoTYPE(io)> would
  1234. contain.
  1235. do_binmode(fp, iotype, TRUE);
  1236. =item ENTER
  1237. Opening bracket on a callback. See C<LEAVE> and L<perlcall>.
  1238. ENTER;
  1239. =item EXTEND
  1240. Used to extend the argument stack for an XSUB's return values.
  1241. EXTEND( sp, int x )
  1242. =item fbm_compile
  1243. Analyses the string in order to make fast searches on it using fbm_instr() --
  1244. the Boyer-Moore algorithm.
  1245. void fbm_compile(SV* sv, U32 flags)
  1246. =item fbm_instr
  1247. Returns the location of the SV in the string delimited by C<str> and
  1248. C<strend>. It returns C<Nullch> if the string can't be found. The
  1249. C<sv> does not have to be fbm_compiled, but the search will not be as
  1250. fast then.
  1251. char* fbm_instr(char *str, char *strend, SV *sv, U32 flags)
  1252. =item FREETMPS
  1253. Closing bracket for temporaries on a callback. See C<SAVETMPS> and
  1254. L<perlcall>.
  1255. FREETMPS;
  1256. =item G_ARRAY
  1257. Used to indicate array context. See C<GIMME_V>, C<GIMME> and L<perlcall>.
  1258. =item G_DISCARD
  1259. Indicates that arguments returned from a callback should be discarded. See
  1260. L<perlcall>.
  1261. =item G_EVAL
  1262. Used to force a Perl C<eval> wrapper around a callback. See L<perlcall>.
  1263. =item GIMME
  1264. A backward-compatible version of C<GIMME_V> which can only return
  1265. C<G_SCALAR> or C<G_ARRAY>; in a void context, it returns C<G_SCALAR>.
  1266. =item GIMME_V
  1267. The XSUB-writer's equivalent to Perl's C<wantarray>. Returns
  1268. C<G_VOID>, C<G_SCALAR> or C<G_ARRAY> for void, scalar or array
  1269. context, respectively.
  1270. =item G_NOARGS
  1271. Indicates that no arguments are being sent to a callback. See L<perlcall>.
  1272. =item G_SCALAR
  1273. Used to indicate scalar context. See C<GIMME_V>, C<GIMME>, and L<perlcall>.
  1274. =item gv_fetchmeth
  1275. Returns the glob with the given C<name> and a defined subroutine or
  1276. C<NULL>. The glob lives in the given C<stash>, or in the stashes
  1277. accessible via @ISA and @UNIVERSAL.
  1278. The argument C<level> should be either 0 or -1. If C<level==0>, as a
  1279. side-effect creates a glob with the given C<name> in the given
  1280. C<stash> which in the case of success contains an alias for the
  1281. subroutine, and sets up caching info for this glob. Similarly for all
  1282. the searched stashes.
  1283. This function grants C<"SUPER"> token as a postfix of the stash name.
  1284. The GV returned from C<gv_fetchmeth> may be a method cache entry,
  1285. which is not visible to Perl code. So when calling C<perl_call_sv>,
  1286. you should not use the GV directly; instead, you should use the
  1287. method's CV, which can be obtained from the GV with the C<GvCV> macro.
  1288. GV* gv_fetchmeth (HV* stash, char* name, STRLEN len, I32 level)
  1289. =item gv_fetchmethod
  1290. =item gv_fetchmethod_autoload
  1291. Returns the glob which contains the subroutine to call to invoke the
  1292. method on the C<stash>. In fact in the presence of autoloading this may
  1293. be the glob for "AUTOLOAD". In this case the corresponding variable
  1294. $AUTOLOAD is already setup.
  1295. The third parameter of C<gv_fetchmethod_autoload> determines whether AUTOLOAD
  1296. lookup is performed if the given method is not present: non-zero means
  1297. yes, look for AUTOLOAD; zero means no, don't look for AUTOLOAD. Calling
  1298. C<gv_fetchmethod> is equivalent to calling C<gv_fetchmethod_autoload> with a
  1299. non-zero C<autoload> parameter.
  1300. These functions grant C<"SUPER"> token as a prefix of the method name.
  1301. Note that if you want to keep the returned glob for a long time, you
  1302. need to check for it being "AUTOLOAD", since at the later time the call
  1303. may load a different subroutine due to $AUTOLOAD changing its value.
  1304. Use the glob created via a side effect to do this.
  1305. These functions have the same side-effects and as C<gv_fetchmeth> with
  1306. C<level==0>. C<name> should be writable if contains C<':'> or C<'\''>.
  1307. The warning against passing the GV returned by C<gv_fetchmeth> to
  1308. C<perl_call_sv> apply equally to these functions.
  1309. GV* gv_fetchmethod (HV* stash, char* name)
  1310. GV* gv_fetchmethod_autoload (HV* stash, char* name, I32 autoload)
  1311. =item G_VOID
  1312. Used to indicate void context. See C<GIMME_V> and L<perlcall>.
  1313. =item gv_stashpv
  1314. Returns a pointer to the stash for a specified package. If C<create> is set
  1315. then the package will be created if it does not already exist. If C<create>
  1316. is not set and the package does not exist then NULL is returned.
  1317. HV* gv_stashpv (char* name, I32 create)
  1318. =item gv_stashsv
  1319. Returns a pointer to the stash for a specified package. See C<gv_stashpv>.
  1320. HV* gv_stashsv (SV* sv, I32 create)
  1321. =item GvSV
  1322. Return the SV from the GV.
  1323. =item HEf_SVKEY
  1324. This flag, used in the length slot of hash entries and magic
  1325. structures, specifies the structure contains a C<SV*> pointer where a
  1326. C<char*> pointer is to be expected. (For information only--not to be used).
  1327. =item HeHASH
  1328. Returns the computed hash stored in the hash entry.
  1329. U32 HeHASH(HE* he)
  1330. =item HeKEY
  1331. Returns the actual pointer stored in the key slot of the hash entry.
  1332. The pointer may be either C<char*> or C<SV*>, depending on the value of
  1333. C<HeKLEN()>. Can be assigned to. The C<HePV()> or C<HeSVKEY()> macros
  1334. are usually preferable for finding the value of a key.
  1335. char* HeKEY(HE* he)
  1336. =item HeKLEN
  1337. If this is negative, and amounts to C<HEf_SVKEY>, it indicates the entry
  1338. holds an C<SV*> key. Otherwise, holds the actual length of the key.
  1339. Can be assigned to. The C<HePV()> macro is usually preferable for finding
  1340. key lengths.
  1341. int HeKLEN(HE* he)
  1342. =item HePV
  1343. Returns the key slot of the hash entry as a C<char*> value, doing any
  1344. necessary dereferencing of possibly C<SV*> keys. The length of
  1345. the string is placed in C<len> (this is a macro, so do I<not> use
  1346. C<&len>). If you do not care about what the length of the key is,
  1347. you may use the global variable C<PL_na>, though this is rather less
  1348. efficient than using a local variable. Remember though, that hash
  1349. keys in perl are free to contain embedded nulls, so using C<strlen()>
  1350. or similar is not a good way to find the length of hash keys.
  1351. This is very similar to the C<SvPV()> macro described elsewhere in
  1352. this document.
  1353. char* HePV(HE* he, STRLEN len)
  1354. =item HeSVKEY
  1355. Returns the key as an C<SV*>, or C<Nullsv> if the hash entry
  1356. does not contain an C<SV*> key.
  1357. HeSVKEY(HE* he)
  1358. =item HeSVKEY_force
  1359. Returns the key as an C<SV*>. Will create and return a temporary
  1360. mortal C<SV*> if the hash entry contains only a C<char*> key.
  1361. HeSVKEY_force(HE* he)
  1362. =item HeSVKEY_set
  1363. Sets the key to a given C<SV*>, taking care to set the appropriate flags
  1364. to indicate the presence of an C<SV*> key, and returns the same C<SV*>.
  1365. HeSVKEY_set(HE* he, SV* sv)
  1366. =item HeVAL
  1367. Returns the value slot (type C<SV*>) stored in the hash entry.
  1368. HeVAL(HE* he)
  1369. =item hv_clear
  1370. Clears a hash, making it empty.
  1371. void hv_clear (HV* tb)
  1372. =item hv_delete
  1373. Deletes a key/value pair in the hash. The value SV is removed from the hash
  1374. and returned to the caller. The C<klen> is the length of the key. The
  1375. C<flags> value will normally be zero; if set to G_DISCARD then NULL will be
  1376. returned.
  1377. SV* hv_delete (HV* tb, char* key, U32 klen, I32 flags)
  1378. =item hv_delete_ent
  1379. Deletes a key/value pair in the hash. The value SV is removed from the hash
  1380. and returned to the caller. The C<flags> value will normally be zero; if set
  1381. to G_DISCARD then NULL will be returned. C<hash> can be a valid precomputed
  1382. hash value, or 0 to ask for it to be computed.
  1383. SV* hv_delete_ent (HV* tb, SV* key, I32 flags, U32 hash)
  1384. =item hv_exists
  1385. Returns a boolean indicating whether the specified hash key exists. The
  1386. C<klen> is the length of the key.
  1387. bool hv_exists (HV* tb, char* key, U32 klen)
  1388. =item hv_exists_ent
  1389. Returns a boolean indicating whether the specified hash key exists. C<hash>
  1390. can be a valid precomputed hash value, or 0 to ask for it to be computed.
  1391. bool hv_exists_ent (HV* tb, SV* key, U32 hash)
  1392. =item hv_fetch
  1393. Returns the SV which corresponds to the specified key in the hash. The
  1394. C<klen> is the length of the key. If C<lval> is set then the fetch will be
  1395. part of a store. Check that the return value is non-null before
  1396. dereferencing it to a C<SV*>.
  1397. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  1398. information on how to use this function on tied hashes.
  1399. SV** hv_fetch (HV* tb, char* key, U32 klen, I32 lval)
  1400. =item hv_fetch_ent
  1401. Returns the hash entry which corresponds to the specified key in the hash.
  1402. C<hash> must be a valid precomputed hash number for the given C<key>, or
  1403. 0 if you want the function to compute it. IF C<lval> is set then the
  1404. fetch will be part of a store. Make sure the return value is non-null
  1405. before accessing it. The return value when C<tb> is a tied hash
  1406. is a pointer to a static location, so be sure to make a copy of the
  1407. structure if you need to store it somewhere.
  1408. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  1409. information on how to use this function on tied hashes.
  1410. HE* hv_fetch_ent (HV* tb, SV* key, I32 lval, U32 hash)
  1411. =item hv_iterinit
  1412. Prepares a starting point to traverse a hash table.
  1413. I32 hv_iterinit (HV* tb)
  1414. Returns the number of keys in the hash (i.e. the same as C<HvKEYS(tb)>).
  1415. The return value is currently only meaningful for hashes without tie
  1416. magic.
  1417. NOTE: Before version 5.004_65, C<hv_iterinit> used to return the number
  1418. of hash buckets that happen to be in use. If you still need that
  1419. esoteric value, you can get it through the macro C<HvFILL(tb)>.
  1420. =item hv_iterkey
  1421. Returns the key from the current position of the hash iterator. See
  1422. C<hv_iterinit>.
  1423. char* hv_iterkey (HE* entry, I32* retlen)
  1424. =item hv_iterkeysv
  1425. Returns the key as an C<SV*> from the current position of the hash
  1426. iterator. The return value will always be a mortal copy of the
  1427. key. Also see C<hv_iterinit>.
  1428. SV* hv_iterkeysv (HE* entry)
  1429. =item hv_iternext
  1430. Returns entries from a hash iterator. See C<hv_iterinit>.
  1431. HE* hv_iternext (HV* tb)
  1432. =item hv_iternextsv
  1433. Performs an C<hv_iternext>, C<hv_iterkey>, and C<hv_iterval> in one
  1434. operation.
  1435. SV* hv_iternextsv (HV* hv, char** key, I32* retlen)
  1436. =item hv_iterval
  1437. Returns the value from the current position of the hash iterator. See
  1438. C<hv_iterkey>.
  1439. SV* hv_iterval (HV* tb, HE* entry)
  1440. =item hv_magic
  1441. Adds magic to a hash. See C<sv_magic>.
  1442. void hv_magic (HV* hv, GV* gv, int how)
  1443. =item HvNAME
  1444. Returns the package name of a stash. See C<SvSTASH>, C<CvSTASH>.
  1445. char* HvNAME (HV* stash)
  1446. =item hv_store
  1447. Stores an SV in a hash. The hash key is specified as C<key> and C<klen> is
  1448. the length of the key. The C<hash> parameter is the precomputed hash
  1449. value; if it is zero then Perl will compute it. The return value will be
  1450. NULL if the operation failed or if the value did not need to be actually
  1451. stored within the hash (as in the case of tied hashes). Otherwise it can
  1452. be dereferenced to get the original C<SV*>. Note that the caller is
  1453. responsible for suitably incrementing the reference count of C<val>
  1454. before the call, and decrementing it if the function returned NULL.
  1455. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  1456. information on how to use this function on tied hashes.
  1457. SV** hv_store (HV* tb, char* key, U32 klen, SV* val, U32 hash)
  1458. =item hv_store_ent
  1459. Stores C<val> in a hash. The hash key is specified as C<key>. The C<hash>
  1460. parameter is the precomputed hash value; if it is zero then Perl will
  1461. compute it. The return value is the new hash entry so created. It will be
  1462. NULL if the operation failed or if the value did not need to be actually
  1463. stored within the hash (as in the case of tied hashes). Otherwise the
  1464. contents of the return value can be accessed using the C<He???> macros
  1465. described here. Note that the caller is responsible for suitably
  1466. incrementing the reference count of C<val> before the call, and decrementing
  1467. it if the function returned NULL.
  1468. See L<Understanding the Magic of Tied Hashes and Arrays> for more
  1469. information on how to use this function on tied hashes.
  1470. HE* hv_store_ent (HV* tb, SV* key, SV* val, U32 hash)
  1471. =item hv_undef
  1472. Undefines the hash.
  1473. void hv_undef (HV* tb)
  1474. =item isALNUM
  1475. Returns a boolean indicating whether the C C<char> is an ascii alphanumeric
  1476. character or digit.
  1477. int isALNUM (char c)
  1478. =item isALPHA
  1479. Returns a boolean indicating whether the C C<char> is an ascii alphabetic
  1480. character.
  1481. int isALPHA (char c)
  1482. =item isDIGIT
  1483. Returns a boolean indicating whether the C C<char> is an ascii digit.
  1484. int isDIGIT (char c)
  1485. =item isLOWER
  1486. Returns a boolean indicating whether the C C<char> is a lowercase character.
  1487. int isLOWER (char c)
  1488. =item isSPACE
  1489. Returns a boolean indicating whether the C C<char> is whitespace.
  1490. int isSPACE (char c)
  1491. =item isUPPER
  1492. Returns a boolean indicating whether the C C<char> is an uppercase character.
  1493. int isUPPER (char c)
  1494. =item items
  1495. Variable which is setup by C<xsubpp> to indicate the number of items on the
  1496. stack. See L<perlxs/"Variable-length Parameter Lists">.
  1497. =item ix
  1498. Variable which is setup by C<xsubpp> to indicate which of an XSUB's aliases
  1499. was used to invoke it. See L<perlxs/"The ALIAS: Keyword">.
  1500. =item LEAVE
  1501. Closing bracket on a callback. See C<ENTER> and L<perlcall>.
  1502. LEAVE;
  1503. =item looks_like_number
  1504. Test if an the content of an SV looks like a number (or is a number).
  1505. int looks_like_number(SV*)
  1506. =item MARK
  1507. Stack marker variable for the XSUB. See C<dMARK>.
  1508. =item mg_clear
  1509. Clear something magical that the SV represents. See C<sv_magic>.
  1510. int mg_clear (SV* sv)
  1511. =item mg_copy
  1512. Copies the magic from one SV to another. See C<sv_magic>.
  1513. int mg_copy (SV *, SV *, char *, STRLEN)
  1514. =item mg_find
  1515. Finds the magic pointer for type matching the SV. See C<sv_magic>.
  1516. MAGIC* mg_find (SV* sv, int type)
  1517. =item mg_free
  1518. Free any magic storage used by the SV. See C<sv_magic>.
  1519. int mg_free (SV* sv)
  1520. =item mg_get
  1521. Do magic after a value is retrieved from the SV. See C<sv_magic>.
  1522. int mg_get (SV* sv)
  1523. =item mg_len
  1524. Report on the SV's length. See C<sv_magic>.
  1525. U32 mg_len (SV* sv)
  1526. =item mg_magical
  1527. Turns on the magical status of an SV. See C<sv_magic>.
  1528. void mg_magical (SV* sv)
  1529. =item mg_set
  1530. Do magic after a value is assigned to the SV. See C<sv_magic>.
  1531. int mg_set (SV* sv)
  1532. =item modglobal
  1533. C<modglobal> is a general purpose, interpreter global HV for use by
  1534. extensions that need to keep information on a per-interpreter basis.
  1535. In a pinch, it can also be used as a symbol table for extensions
  1536. to share data among each other. It is a good idea to use keys
  1537. prefixed by the package name of the extension that owns the data.
  1538. =item Move
  1539. The XSUB-writer's interface to the C C<memmove> function. The C<s> is the
  1540. source, C<d> is the destination, C<n> is the number of items, and C<t> is
  1541. the type. Can do overlapping moves. See also C<Copy>.
  1542. void Move( s, d, n, t )
  1543. =item PL_na
  1544. A convenience variable which is typically used with C<SvPV> when one doesn't
  1545. care about the length of the string. It is usually more efficient to
  1546. declare a local variable and use that instead.
  1547. =item New
  1548. The XSUB-writer's interface to the C C<malloc> function.
  1549. void* New( x, void *ptr, int size, type )
  1550. =item newAV
  1551. Creates a new AV. The reference count is set to 1.
  1552. AV* newAV (void)
  1553. =item Newc
  1554. The XSUB-writer's interface to the C C<malloc> function, with cast.
  1555. void* Newc( x, void *ptr, int size, type, cast )
  1556. =item newCONSTSUB
  1557. Creates a constant sub equivalent to Perl C<sub FOO () { 123 }>
  1558. which is eligible for inlining at compile-time.
  1559. void newCONSTSUB(HV* stash, char* name, SV* sv)
  1560. =item newHV
  1561. Creates a new HV. The reference count is set to 1.
  1562. HV* newHV (void)
  1563. =item newRV_inc
  1564. Creates an RV wrapper for an SV. The reference count for the original SV is
  1565. incremented.
  1566. SV* newRV_inc (SV* ref)
  1567. For historical reasons, "newRV" is a synonym for "newRV_inc".
  1568. =item newRV_noinc
  1569. Creates an RV wrapper for an SV. The reference count for the original
  1570. SV is B<not> incremented.
  1571. SV* newRV_noinc (SV* ref)
  1572. =item NEWSV
  1573. Creates a new SV. A non-zero C<len> parameter indicates the number of
  1574. bytes of preallocated string space the SV should have. An extra byte
  1575. for a tailing NUL is also reserved. (SvPOK is not set for the SV even
  1576. if string space is allocated.) The reference count for the new SV is
  1577. set to 1. C<id> is an integer id between 0 and 1299 (used to identify
  1578. leaks).
  1579. SV* NEWSV (int id, STRLEN len)
  1580. =item newSViv
  1581. Creates a new SV and copies an integer into it. The reference count for the
  1582. SV is set to 1.
  1583. SV* newSViv (IV i)
  1584. =item newSVnv
  1585. Creates a new SV and copies a double into it. The reference count for the
  1586. SV is set to 1.
  1587. SV* newSVnv (NV i)
  1588. =item newSVpv
  1589. Creates a new SV and copies a string into it. The reference count for the
  1590. SV is set to 1. If C<len> is zero then Perl will compute the length.
  1591. SV* newSVpv (char* s, STRLEN len)
  1592. =item newSVpvf
  1593. Creates a new SV an initialize it with the string formatted like
  1594. C<sprintf>.
  1595. SV* newSVpvf(const char* pat, ...);
  1596. =item newSVpvn
  1597. Creates a new SV and copies a string into it. The reference count for the
  1598. SV is set to 1. If C<len> is zero then Perl will create a zero length
  1599. string.
  1600. SV* newSVpvn (char* s, STRLEN len)
  1601. =item newSVrv
  1602. Creates a new SV for the RV, C<rv>, to point to. If C<rv> is not an RV then
  1603. it will be upgraded to one. If C<classname> is non-null then the new SV will
  1604. be blessed in the specified package. The new SV is returned and its
  1605. reference count is 1.
  1606. SV* newSVrv (SV* rv, char* classname)
  1607. =item newSVsv
  1608. Creates a new SV which is an exact duplicate of the original SV.
  1609. SV* newSVsv (SV* old)
  1610. =item newXS
  1611. Used by C<xsubpp> to hook up XSUBs as Perl subs.
  1612. =item newXSproto
  1613. Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to
  1614. the subs.
  1615. =item Newz
  1616. The XSUB-writer's interface to the C C<malloc> function. The allocated
  1617. memory is zeroed with C<memzero>.
  1618. void* Newz( x, void *ptr, int size, type )
  1619. =item Nullav
  1620. Null AV pointer.
  1621. =item Nullch
  1622. Null character pointer.
  1623. =item Nullcv
  1624. Null CV pointer.
  1625. =item Nullhv
  1626. Null HV pointer.
  1627. =item Nullsv
  1628. Null SV pointer.
  1629. =item ORIGMARK
  1630. The original stack mark for the XSUB. See C<dORIGMARK>.
  1631. =item perl_alloc
  1632. Allocates a new Perl interpreter. See L<perlembed>.
  1633. =item perl_call_argv
  1634. Performs a callback to the specified Perl sub. See L<perlcall>.
  1635. I32 perl_call_argv (char* subname, I32 flags, char** argv)
  1636. =item perl_call_method
  1637. Performs a callback to the specified Perl method. The blessed object must
  1638. be on the stack. See L<perlcall>.
  1639. I32 perl_call_method (char* methname, I32 flags)
  1640. =item perl_call_pv
  1641. Performs a callback to the specified Perl sub. See L<perlcall>.
  1642. I32 perl_call_pv (char* subname, I32 flags)
  1643. =item perl_call_sv
  1644. Performs a callback to the Perl sub whose name is in the SV. See
  1645. L<perlcall>.
  1646. I32 perl_call_sv (SV* sv, I32 flags)
  1647. =item perl_construct
  1648. Initializes a new Perl interpreter. See L<perlembed>.
  1649. =item perl_destruct
  1650. Shuts down a Perl interpreter. See L<perlembed>.
  1651. =item perl_eval_sv
  1652. Tells Perl to C<eval> the string in the SV.
  1653. I32 perl_eval_sv (SV* sv, I32 flags)
  1654. =item perl_eval_pv
  1655. Tells Perl to C<eval> the given string and return an SV* result.
  1656. SV* perl_eval_pv (char* p, I32 croak_on_error)
  1657. =item perl_free
  1658. Releases a Perl interpreter. See L<perlembed>.
  1659. =item perl_get_av
  1660. Returns the AV of the specified Perl array. If C<create> is set and the
  1661. Perl variable does not exist then it will be created. If C<create> is not
  1662. set and the variable does not exist then NULL is returned.
  1663. AV* perl_get_av (char* name, I32 create)
  1664. =item perl_get_cv
  1665. Returns the CV of the specified Perl sub. If C<create> is set and the Perl
  1666. variable does not exist then it will be created. If C<create> is not
  1667. set and the variable does not exist then NULL is returned.
  1668. CV* perl_get_cv (char* name, I32 create)
  1669. =item perl_get_hv
  1670. Returns the HV of the specified Perl hash. If C<create> is set and the Perl
  1671. variable does not exist then it will be created. If C<create> is not
  1672. set and the variable does not exist then NULL is returned.
  1673. HV* perl_get_hv (char* name, I32 create)
  1674. =item perl_get_sv
  1675. Returns the SV of the specified Perl scalar. If C<create> is set and the
  1676. Perl variable does not exist then it will be created. If C<create> is not
  1677. set and the variable does not exist then NULL is returned.
  1678. SV* perl_get_sv (char* name, I32 create)
  1679. =item perl_parse
  1680. Tells a Perl interpreter to parse a Perl script. See L<perlembed>.
  1681. =item perl_require_pv
  1682. Tells Perl to C<require> a module.
  1683. void perl_require_pv (char* pv)
  1684. =item perl_run
  1685. Tells a Perl interpreter to run. See L<perlembed>.
  1686. =item POPi
  1687. Pops an integer off the stack.
  1688. int POPi()
  1689. =item POPl
  1690. Pops a long off the stack.
  1691. long POPl()
  1692. =item POPp
  1693. Pops a string off the stack.
  1694. char* POPp()
  1695. =item POPn
  1696. Pops a double off the stack.
  1697. double POPn()
  1698. =item POPs
  1699. Pops an SV off the stack.
  1700. SV* POPs()
  1701. =item PUSHMARK
  1702. Opening bracket for arguments on a callback. See C<PUTBACK> and L<perlcall>.
  1703. PUSHMARK(p)
  1704. =item PUSHi
  1705. Push an integer onto the stack. The stack must have room for this element.
  1706. Handles 'set' magic. See C<XPUSHi>.
  1707. void PUSHi(int d)
  1708. =item PUSHn
  1709. Push a double onto the stack. The stack must have room for this element.
  1710. Handles 'set' magic. See C<XPUSHn>.
  1711. void PUSHn(double d)
  1712. =item PUSHp
  1713. Push a string onto the stack. The stack must have room for this element.
  1714. The C<len> indicates the length of the string. Handles 'set' magic. See
  1715. C<XPUSHp>.
  1716. void PUSHp(char *c, int len )
  1717. =item PUSHs
  1718. Push an SV onto the stack. The stack must have room for this element. Does
  1719. not handle 'set' magic. See C<XPUSHs>.
  1720. void PUSHs(sv)
  1721. =item PUSHu
  1722. Push an unsigned integer onto the stack. The stack must have room for
  1723. this element. See C<XPUSHu>.
  1724. void PUSHu(unsigned int d)
  1725. =item PUTBACK
  1726. Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
  1727. See C<PUSHMARK> and L<perlcall> for other uses.
  1728. PUTBACK;
  1729. =item Renew
  1730. The XSUB-writer's interface to the C C<realloc> function.
  1731. void* Renew( void *ptr, int size, type )
  1732. =item Renewc
  1733. The XSUB-writer's interface to the C C<realloc> function, with cast.
  1734. void* Renewc( void *ptr, int size, type, cast )
  1735. =item RETVAL
  1736. Variable which is setup by C<xsubpp> to hold the return value for an XSUB.
  1737. This is always the proper type for the XSUB.
  1738. See L<perlxs/"The RETVAL Variable">.
  1739. =item safefree
  1740. The XSUB-writer's interface to the C C<free> function.
  1741. =item safemalloc
  1742. The XSUB-writer's interface to the C C<malloc> function.
  1743. =item saferealloc
  1744. The XSUB-writer's interface to the C C<realloc> function.
  1745. =item savepv
  1746. Copy a string to a safe spot. This does not use an SV.
  1747. char* savepv (char* sv)
  1748. =item savepvn
  1749. Copy a string to a safe spot. The C<len> indicates number of bytes to
  1750. copy. This does not use an SV.
  1751. char* savepvn (char* sv, I32 len)
  1752. =item SAVETMPS
  1753. Opening bracket for temporaries on a callback. See C<FREETMPS> and
  1754. L<perlcall>.
  1755. SAVETMPS;
  1756. =item SP
  1757. Stack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
  1758. C<SPAGAIN>.
  1759. =item SPAGAIN
  1760. Refetch the stack pointer. Used after a callback. See L<perlcall>.
  1761. SPAGAIN;
  1762. =item ST
  1763. Used to access elements on the XSUB's stack.
  1764. SV* ST(int x)
  1765. =item strEQ
  1766. Test two strings to see if they are equal. Returns true or false.
  1767. int strEQ( char *s1, char *s2 )
  1768. =item strGE
  1769. Test two strings to see if the first, C<s1>, is greater than or equal to the
  1770. second, C<s2>. Returns true or false.
  1771. int strGE( char *s1, char *s2 )
  1772. =item strGT
  1773. Test two strings to see if the first, C<s1>, is greater than the second,
  1774. C<s2>. Returns true or false.
  1775. int strGT( char *s1, char *s2 )
  1776. =item strLE
  1777. Test two strings to see if the first, C<s1>, is less than or equal to the
  1778. second, C<s2>. Returns true or false.
  1779. int strLE( char *s1, char *s2 )
  1780. =item strLT
  1781. Test two strings to see if the first, C<s1>, is less than the second,
  1782. C<s2>. Returns true or false.
  1783. int strLT( char *s1, char *s2 )
  1784. =item strNE
  1785. Test two strings to see if they are different. Returns true or false.
  1786. int strNE( char *s1, char *s2 )
  1787. =item strnEQ
  1788. Test two strings to see if they are equal. The C<len> parameter indicates
  1789. the number of bytes to compare. Returns true or false.
  1790. int strnEQ( char *s1, char *s2 )
  1791. =item strnNE
  1792. Test two strings to see if they are different. The C<len> parameter
  1793. indicates the number of bytes to compare. Returns true or false.
  1794. int strnNE( char *s1, char *s2, int len )
  1795. =item sv_2mortal
  1796. Marks an SV as mortal. The SV will be destroyed when the current context
  1797. ends.
  1798. SV* sv_2mortal (SV* sv)
  1799. =item sv_bless
  1800. Blesses an SV into a specified package. The SV must be an RV. The package
  1801. must be designated by its stash (see C<gv_stashpv()>). The reference count
  1802. of the SV is unaffected.
  1803. SV* sv_bless (SV* sv, HV* stash)
  1804. =item sv_catpv
  1805. Concatenates the string onto the end of the string which is in the SV.
  1806. Handles 'get' magic, but not 'set' magic. See C<sv_catpv_mg>.
  1807. void sv_catpv (SV* sv, char* ptr)
  1808. =item sv_catpv_mg
  1809. Like C<sv_catpv>, but also handles 'set' magic.
  1810. void sv_catpv_mg (SV* sv, const char* ptr)
  1811. =item sv_catpvn
  1812. Concatenates the string onto the end of the string which is in the SV. The
  1813. C<len> indicates number of bytes to copy. Handles 'get' magic, but not
  1814. 'set' magic. See C<sv_catpvn_mg>.
  1815. void sv_catpvn (SV* sv, char* ptr, STRLEN len)
  1816. =item sv_catpvn_mg
  1817. Like C<sv_catpvn>, but also handles 'set' magic.
  1818. void sv_catpvn_mg (SV* sv, char* ptr, STRLEN len)
  1819. =item sv_catpvf
  1820. Processes its arguments like C<sprintf> and appends the formatted output
  1821. to an SV. Handles 'get' magic, but not 'set' magic. C<SvSETMAGIC()> must
  1822. typically be called after calling this function to handle 'set' magic.
  1823. void sv_catpvf (SV* sv, const char* pat, ...)
  1824. =item sv_catpvf_mg
  1825. Like C<sv_catpvf>, but also handles 'set' magic.
  1826. void sv_catpvf_mg (SV* sv, const char* pat, ...)
  1827. =item sv_catsv
  1828. Concatenates the string from SV C<ssv> onto the end of the string in SV
  1829. C<dsv>. Handles 'get' magic, but not 'set' magic. See C<sv_catsv_mg>.
  1830. void sv_catsv (SV* dsv, SV* ssv)
  1831. =item sv_catsv_mg
  1832. Like C<sv_catsv>, but also handles 'set' magic.
  1833. void sv_catsv_mg (SV* dsv, SV* ssv)
  1834. =item sv_chop
  1835. Efficient removal of characters from the beginning of the string
  1836. buffer. SvPOK(sv) must be true and the C<ptr> must be a pointer to
  1837. somewhere inside the string buffer. The C<ptr> becomes the first
  1838. character of the adjusted string.
  1839. void sv_chop(SV* sv, char *ptr)
  1840. =item sv_cmp
  1841. Compares the strings in two SVs. Returns -1, 0, or 1 indicating whether the
  1842. string in C<sv1> is less than, equal to, or greater than the string in
  1843. C<sv2>.
  1844. I32 sv_cmp (SV* sv1, SV* sv2)
  1845. =item SvCUR
  1846. Returns the length of the string which is in the SV. See C<SvLEN>.
  1847. int SvCUR (SV* sv)
  1848. =item SvCUR_set
  1849. Set the length of the string which is in the SV. See C<SvCUR>.
  1850. void SvCUR_set (SV* sv, int val)
  1851. =item sv_dec
  1852. Auto-decrement of the value in the SV.
  1853. void sv_dec (SV* sv)
  1854. =item sv_derived_from
  1855. Returns a boolean indicating whether the SV is derived from the specified
  1856. class. This is the function that implements C<UNIVERSAL::isa>. It works
  1857. for class names as well as for objects.
  1858. bool sv_derived_from _((SV* sv, char* name));
  1859. =item SvEND
  1860. Returns a pointer to the last character in the string which is in the SV.
  1861. See C<SvCUR>. Access the character as
  1862. char* SvEND(sv)
  1863. =item sv_eq
  1864. Returns a boolean indicating whether the strings in the two SVs are
  1865. identical.
  1866. I32 sv_eq (SV* sv1, SV* sv2)
  1867. =item SvGETMAGIC
  1868. Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates
  1869. its argument more than once.
  1870. void SvGETMAGIC(SV *sv)
  1871. =item SvGROW
  1872. Expands the character buffer in the SV so that it has room for the
  1873. indicated number of bytes (remember to reserve space for an extra
  1874. trailing NUL character). Calls C<sv_grow> to perform the expansion if
  1875. necessary. Returns a pointer to the character buffer.
  1876. char* SvGROW(SV* sv, STRLEN len)
  1877. =item sv_grow
  1878. Expands the character buffer in the SV. This will use C<sv_unref> and will
  1879. upgrade the SV to C<SVt_PV>. Returns a pointer to the character buffer.
  1880. Use C<SvGROW>.
  1881. =item sv_inc
  1882. Auto-increment of the value in the SV.
  1883. void sv_inc (SV* sv)
  1884. =item sv_insert
  1885. Inserts a string at the specified offset/length within the SV.
  1886. Similar to the Perl substr() function.
  1887. void sv_insert(SV *sv, STRLEN offset, STRLEN len,
  1888. char *str, STRLEN strlen)
  1889. =item SvIOK
  1890. Returns a boolean indicating whether the SV contains an integer.
  1891. int SvIOK (SV* SV)
  1892. =item SvIOK_off
  1893. Unsets the IV status of an SV.
  1894. void SvIOK_off (SV* sv)
  1895. =item SvIOK_on
  1896. Tells an SV that it is an integer.
  1897. void SvIOK_on (SV* sv)
  1898. =item SvIOK_only
  1899. Tells an SV that it is an integer and disables all other OK bits.
  1900. void SvIOK_only (SV* sv)
  1901. =item SvIOKp
  1902. Returns a boolean indicating whether the SV contains an integer. Checks the
  1903. B<private> setting. Use C<SvIOK>.
  1904. int SvIOKp (SV* SV)
  1905. =item sv_isa
  1906. Returns a boolean indicating whether the SV is blessed into the specified
  1907. class. This does not check for subtypes; use C<sv_derived_from> to verify
  1908. an inheritance relationship.
  1909. int sv_isa (SV* sv, char* name)
  1910. =item sv_isobject
  1911. Returns a boolean indicating whether the SV is an RV pointing to a blessed
  1912. object. If the SV is not an RV, or if the object is not blessed, then this
  1913. will return false.
  1914. int sv_isobject (SV* sv)
  1915. =item SvIV
  1916. Coerces the given SV to an integer and returns it.
  1917. int SvIV (SV* sv)
  1918. =item SvIVX
  1919. Returns the integer which is stored in the SV, assuming SvIOK is true.
  1920. int SvIVX (SV* sv)
  1921. =item SvLEN
  1922. Returns the size of the string buffer in the SV. See C<SvCUR>.
  1923. int SvLEN (SV* sv)
  1924. =item sv_len
  1925. Returns the length of the string in the SV. Use C<SvCUR>.
  1926. STRLEN sv_len (SV* sv)
  1927. =item sv_magic
  1928. Adds magic to an SV.
  1929. void sv_magic (SV* sv, SV* obj, int how, char* name, I32 namlen)
  1930. =item sv_mortalcopy
  1931. Creates a new SV which is a copy of the original SV. The new SV is marked
  1932. as mortal.
  1933. SV* sv_mortalcopy (SV* oldsv)
  1934. =item sv_newmortal
  1935. Creates a new SV which is mortal. The reference count of the SV is set to 1.
  1936. SV* sv_newmortal (void)
  1937. =item SvNIOK
  1938. Returns a boolean indicating whether the SV contains a number, integer or
  1939. double.
  1940. int SvNIOK (SV* SV)
  1941. =item SvNIOK_off
  1942. Unsets the NV/IV status of an SV.
  1943. void SvNIOK_off (SV* sv)
  1944. =item SvNIOKp
  1945. Returns a boolean indicating whether the SV contains a number, integer or
  1946. double. Checks the B<private> setting. Use C<SvNIOK>.
  1947. int SvNIOKp (SV* SV)
  1948. =item PL_sv_no
  1949. This is the C<false> SV. See C<PL_sv_yes>. Always refer to this as C<&PL_sv_no>.
  1950. =item SvNOK
  1951. Returns a boolean indicating whether the SV contains a double.
  1952. int SvNOK (SV* SV)
  1953. =item SvNOK_off
  1954. Unsets the NV status of an SV.
  1955. void SvNOK_off (SV* sv)
  1956. =item SvNOK_on
  1957. Tells an SV that it is a double.
  1958. void SvNOK_on (SV* sv)
  1959. =item SvNOK_only
  1960. Tells an SV that it is a double and disables all other OK bits.
  1961. void SvNOK_only (SV* sv)
  1962. =item SvNOKp
  1963. Returns a boolean indicating whether the SV contains a double. Checks the
  1964. B<private> setting. Use C<SvNOK>.
  1965. int SvNOKp (SV* SV)
  1966. =item SvNV
  1967. Coerce the given SV to a double and return it.
  1968. double SvNV (SV* sv)
  1969. =item SvNVX
  1970. Returns the double which is stored in the SV, assuming SvNOK is true.
  1971. double SvNVX (SV* sv)
  1972. =item SvOK
  1973. Returns a boolean indicating whether the value is an SV.
  1974. int SvOK (SV* sv)
  1975. =item SvOOK
  1976. Returns a boolean indicating whether the SvIVX is a valid offset value
  1977. for the SvPVX. This hack is used internally to speed up removal of
  1978. characters from the beginning of a SvPV. When SvOOK is true, then the
  1979. start of the allocated string buffer is really (SvPVX - SvIVX).
  1980. int SvOOK(SV* sv)
  1981. =item SvPOK
  1982. Returns a boolean indicating whether the SV contains a character string.
  1983. int SvPOK (SV* SV)
  1984. =item SvPOK_off
  1985. Unsets the PV status of an SV.
  1986. void SvPOK_off (SV* sv)
  1987. =item SvPOK_on
  1988. Tells an SV that it is a string.
  1989. void SvPOK_on (SV* sv)
  1990. =item SvPOK_only
  1991. Tells an SV that it is a string and disables all other OK bits.
  1992. void SvPOK_only (SV* sv)
  1993. =item SvPOKp
  1994. Returns a boolean indicating whether the SV contains a character string.
  1995. Checks the B<private> setting. Use C<SvPOK>.
  1996. int SvPOKp (SV* SV)
  1997. =item SvPV
  1998. Returns a pointer to the string in the SV, or a stringified form of the SV
  1999. if the SV does not contain a string. Handles 'get' magic.
  2000. char* SvPV (SV* sv, STRLEN len)
  2001. =item SvPV_force
  2002. Like <SvPV> but will force the SV into becoming a string (SvPOK). You
  2003. want force if you are going to update the SvPVX directly.
  2004. char* SvPV_force(SV* sv, STRLEN len)
  2005. =item SvPVX
  2006. Returns a pointer to the string in the SV. The SV must contain a string.
  2007. char* SvPVX (SV* sv)
  2008. =item SvREFCNT
  2009. Returns the value of the object's reference count.
  2010. int SvREFCNT (SV* sv)
  2011. =item SvREFCNT_dec
  2012. Decrements the reference count of the given SV.
  2013. void SvREFCNT_dec (SV* sv)
  2014. =item SvREFCNT_inc
  2015. Increments the reference count of the given SV.
  2016. void SvREFCNT_inc (SV* sv)
  2017. =item SvROK
  2018. Tests if the SV is an RV.
  2019. int SvROK (SV* sv)
  2020. =item SvROK_off
  2021. Unsets the RV status of an SV.
  2022. void SvROK_off (SV* sv)
  2023. =item SvROK_on
  2024. Tells an SV that it is an RV.
  2025. void SvROK_on (SV* sv)
  2026. =item SvRV
  2027. Dereferences an RV to return the SV.
  2028. SV* SvRV (SV* sv)
  2029. =item SvSETMAGIC
  2030. Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates
  2031. its argument more than once.
  2032. void SvSETMAGIC( SV *sv )
  2033. =item sv_setiv
  2034. Copies an integer into the given SV. Does not handle 'set' magic.
  2035. See C<sv_setiv_mg>.
  2036. void sv_setiv (SV* sv, IV num)
  2037. =item sv_setiv_mg
  2038. Like C<sv_setiv>, but also handles 'set' magic.
  2039. void sv_setiv_mg (SV* sv, IV num)
  2040. =item sv_setnv
  2041. Copies a double into the given SV. Does not handle 'set' magic.
  2042. See C<sv_setnv_mg>.
  2043. void sv_setnv (SV* sv, double num)
  2044. =item sv_setnv_mg
  2045. Like C<sv_setnv>, but also handles 'set' magic.
  2046. void sv_setnv_mg (SV* sv, double num)
  2047. =item sv_setpv
  2048. Copies a string into an SV. The string must be null-terminated.
  2049. Does not handle 'set' magic. See C<sv_setpv_mg>.
  2050. void sv_setpv (SV* sv, const char* ptr)
  2051. =item sv_setpv_mg
  2052. Like C<sv_setpv>, but also handles 'set' magic.
  2053. void sv_setpv_mg (SV* sv, const char* ptr)
  2054. =item sv_setpviv
  2055. Copies an integer into the given SV, also updating its string value.
  2056. Does not handle 'set' magic. See C<sv_setpviv_mg>.
  2057. void sv_setpviv (SV* sv, IV num)
  2058. =item sv_setpviv_mg
  2059. Like C<sv_setpviv>, but also handles 'set' magic.
  2060. void sv_setpviv_mg (SV* sv, IV num)
  2061. =item sv_setpvn
  2062. Copies a string into an SV. The C<len> parameter indicates the number of
  2063. bytes to be copied. Does not handle 'set' magic. See C<sv_setpvn_mg>.
  2064. void sv_setpvn (SV* sv, const char* ptr, STRLEN len)
  2065. =item sv_setpvn_mg
  2066. Like C<sv_setpvn>, but also handles 'set' magic.
  2067. void sv_setpvn_mg (SV* sv, const char* ptr, STRLEN len)
  2068. =item sv_setpvf
  2069. Processes its arguments like C<sprintf> and sets an SV to the formatted
  2070. output. Does not handle 'set' magic. See C<sv_setpvf_mg>.
  2071. void sv_setpvf (SV* sv, const char* pat, ...)
  2072. =item sv_setpvf_mg
  2073. Like C<sv_setpvf>, but also handles 'set' magic.
  2074. void sv_setpvf_mg (SV* sv, const char* pat, ...)
  2075. =item sv_setref_iv
  2076. Copies an integer into a new SV, optionally blessing the SV. The C<rv>
  2077. argument will be upgraded to an RV. That RV will be modified to point to
  2078. the new SV. The C<classname> argument indicates the package for the
  2079. blessing. Set C<classname> to C<Nullch> to avoid the blessing. The new SV
  2080. will be returned and will have a reference count of 1.
  2081. SV* sv_setref_iv (SV *rv, char *classname, IV iv)
  2082. =item sv_setref_nv
  2083. Copies a double into a new SV, optionally blessing the SV. The C<rv>
  2084. argument will be upgraded to an RV. That RV will be modified to point to
  2085. the new SV. The C<classname> argument indicates the package for the
  2086. blessing. Set C<classname> to C<Nullch> to avoid the blessing. The new SV
  2087. will be returned and will have a reference count of 1.
  2088. SV* sv_setref_nv (SV *rv, char *classname, double nv)
  2089. =item sv_setref_pv
  2090. Copies a pointer into a new SV, optionally blessing the SV. The C<rv>
  2091. argument will be upgraded to an RV. That RV will be modified to point to
  2092. the new SV. If the C<pv> argument is NULL then C<PL_sv_undef> will be placed
  2093. into the SV. The C<classname> argument indicates the package for the
  2094. blessing. Set C<classname> to C<Nullch> to avoid the blessing. The new SV
  2095. will be returned and will have a reference count of 1.
  2096. SV* sv_setref_pv (SV *rv, char *classname, void* pv)
  2097. Do not use with integral Perl types such as HV, AV, SV, CV, because those
  2098. objects will become corrupted by the pointer copy process.
  2099. Note that C<sv_setref_pvn> copies the string while this copies the pointer.
  2100. =item sv_setref_pvn
  2101. Copies a string into a new SV, optionally blessing the SV. The length of the
  2102. string must be specified with C<n>. The C<rv> argument will be upgraded to
  2103. an RV. That RV will be modified to point to the new SV. The C<classname>
  2104. argument indicates the package for the blessing. Set C<classname> to
  2105. C<Nullch> to avoid the blessing. The new SV will be returned and will have
  2106. a reference count of 1.
  2107. SV* sv_setref_pvn (SV *rv, char *classname, char* pv, I32 n)
  2108. Note that C<sv_setref_pv> copies the pointer while this copies the string.
  2109. =item SvSetSV
  2110. Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
  2111. more than once.
  2112. void SvSetSV (SV* dsv, SV* ssv)
  2113. =item SvSetSV_nosteal
  2114. Calls a non-destructive version of C<sv_setsv> if dsv is not the same as ssv.
  2115. May evaluate arguments more than once.
  2116. void SvSetSV_nosteal (SV* dsv, SV* ssv)
  2117. =item sv_setsv
  2118. Copies the contents of the source SV C<ssv> into the destination SV C<dsv>.
  2119. The source SV may be destroyed if it is mortal. Does not handle 'set' magic.
  2120. See the macro forms C<SvSetSV>, C<SvSetSV_nosteal> and C<sv_setsv_mg>.
  2121. void sv_setsv (SV* dsv, SV* ssv)
  2122. =item sv_setsv_mg
  2123. Like C<sv_setsv>, but also handles 'set' magic.
  2124. void sv_setsv_mg (SV* dsv, SV* ssv)
  2125. =item sv_setuv
  2126. Copies an unsigned integer into the given SV. Does not handle 'set' magic.
  2127. See C<sv_setuv_mg>.
  2128. void sv_setuv (SV* sv, UV num)
  2129. =item sv_setuv_mg
  2130. Like C<sv_setuv>, but also handles 'set' magic.
  2131. void sv_setuv_mg (SV* sv, UV num)
  2132. =item SvSTASH
  2133. Returns the stash of the SV.
  2134. HV* SvSTASH (SV* sv)
  2135. =item SvTAINT
  2136. Taints an SV if tainting is enabled
  2137. void SvTAINT (SV* sv)
  2138. =item SvTAINTED
  2139. Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if not.
  2140. int SvTAINTED (SV* sv)
  2141. =item SvTAINTED_off
  2142. Untaints an SV. Be I<very> careful with this routine, as it short-circuits
  2143. some of Perl's fundamental security features. XS module authors should
  2144. not use this function unless they fully understand all the implications
  2145. of unconditionally untainting the value. Untainting should be done in
  2146. the standard perl fashion, via a carefully crafted regexp, rather than
  2147. directly untainting variables.
  2148. void SvTAINTED_off (SV* sv)
  2149. =item SvTAINTED_on
  2150. Marks an SV as tainted.
  2151. void SvTAINTED_on (SV* sv)
  2152. =item SVt_IV
  2153. Integer type flag for scalars. See C<svtype>.
  2154. =item SVt_PV
  2155. Pointer type flag for scalars. See C<svtype>.
  2156. =item SVt_PVAV
  2157. Type flag for arrays. See C<svtype>.
  2158. =item SVt_PVCV
  2159. Type flag for code refs. See C<svtype>.
  2160. =item SVt_PVHV
  2161. Type flag for hashes. See C<svtype>.
  2162. =item SVt_PVMG
  2163. Type flag for blessed scalars. See C<svtype>.
  2164. =item SVt_NV
  2165. Double type flag for scalars. See C<svtype>.
  2166. =item SvTRUE
  2167. Returns a boolean indicating whether Perl would evaluate the SV as true or
  2168. false, defined or undefined. Does not handle 'get' magic.
  2169. int SvTRUE (SV* sv)
  2170. =item SvTYPE
  2171. Returns the type of the SV. See C<svtype>.
  2172. svtype SvTYPE (SV* sv)
  2173. =item svtype
  2174. An enum of flags for Perl types. These are found in the file B<sv.h> in the
  2175. C<svtype> enum. Test these flags with the C<SvTYPE> macro.
  2176. =item PL_sv_undef
  2177. This is the C<undef> SV. Always refer to this as C<&PL_sv_undef>.
  2178. =item sv_unref
  2179. Unsets the RV status of the SV, and decrements the reference count of
  2180. whatever was being referenced by the RV. This can almost be thought of
  2181. as a reversal of C<newSVrv>. See C<SvROK_off>.
  2182. void sv_unref (SV* sv)
  2183. =item SvUPGRADE
  2184. Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to perform
  2185. the upgrade if necessary. See C<svtype>.
  2186. bool SvUPGRADE (SV* sv, svtype mt)
  2187. =item sv_upgrade
  2188. Upgrade an SV to a more complex form. Use C<SvUPGRADE>. See C<svtype>.
  2189. =item sv_usepvn
  2190. Tells an SV to use C<ptr> to find its string value. Normally the string is
  2191. stored inside the SV but sv_usepvn allows the SV to use an outside string.
  2192. The C<ptr> should point to memory that was allocated by C<malloc>. The
  2193. string length, C<len>, must be supplied. This function will realloc the
  2194. memory pointed to by C<ptr>, so that pointer should not be freed or used by
  2195. the programmer after giving it to sv_usepvn. Does not handle 'set' magic.
  2196. See C<sv_usepvn_mg>.
  2197. void sv_usepvn (SV* sv, char* ptr, STRLEN len)
  2198. =item sv_usepvn_mg
  2199. Like C<sv_usepvn>, but also handles 'set' magic.
  2200. void sv_usepvn_mg (SV* sv, char* ptr, STRLEN len)
  2201. =item sv_vcatpvfn(sv, pat, patlen, args, svargs, svmax, used_locale)
  2202. Processes its arguments like C<vsprintf> and appends the formatted output
  2203. to an SV. Uses an array of SVs if the C style variable argument list is
  2204. missing (NULL). Indicates if locale information has been used for formatting.
  2205. void sv_catpvfn _((SV* sv, const char* pat, STRLEN patlen,
  2206. va_list *args, SV **svargs, I32 svmax,
  2207. bool *used_locale));
  2208. =item sv_vsetpvfn(sv, pat, patlen, args, svargs, svmax, used_locale)
  2209. Works like C<vcatpvfn> but copies the text into the SV instead of
  2210. appending it.
  2211. void sv_setpvfn _((SV* sv, const char* pat, STRLEN patlen,
  2212. va_list *args, SV **svargs, I32 svmax,
  2213. bool *used_locale));
  2214. =item SvUV
  2215. Coerces the given SV to an unsigned integer and returns it.
  2216. UV SvUV(SV* sv)
  2217. =item SvUVX
  2218. Returns the unsigned integer which is stored in the SV, assuming SvIOK is true.
  2219. UV SvUVX(SV* sv)
  2220. =item PL_sv_yes
  2221. This is the C<true> SV. See C<PL_sv_no>. Always refer to this as C<&PL_sv_yes>.
  2222. =item THIS
  2223. Variable which is setup by C<xsubpp> to designate the object in a C++ XSUB.
  2224. This is always the proper type for the C++ object. See C<CLASS> and
  2225. L<perlxs/"Using XS With C++">.
  2226. =item toLOWER
  2227. Converts the specified character to lowercase.
  2228. int toLOWER (char c)
  2229. =item toUPPER
  2230. Converts the specified character to uppercase.
  2231. int toUPPER (char c)
  2232. =item warn
  2233. This is the XSUB-writer's interface to Perl's C<warn> function. Use this
  2234. function the same way you use the C C<printf> function. See C<croak()>.
  2235. =item XPUSHi
  2236. Push an integer onto the stack, extending the stack if necessary. Handles
  2237. 'set' magic. See C<PUSHi>.
  2238. XPUSHi(int d)
  2239. =item XPUSHn
  2240. Push a double onto the stack, extending the stack if necessary. Handles 'set'
  2241. magic. See C<PUSHn>.
  2242. XPUSHn(double d)
  2243. =item XPUSHp
  2244. Push a string onto the stack, extending the stack if necessary. The C<len>
  2245. indicates the length of the string. Handles 'set' magic. See C<PUSHp>.
  2246. XPUSHp(char *c, int len)
  2247. =item XPUSHs
  2248. Push an SV onto the stack, extending the stack if necessary. Does not
  2249. handle 'set' magic. See C<PUSHs>.
  2250. XPUSHs(sv)
  2251. =item XPUSHu
  2252. Push an unsigned integer onto the stack, extending the stack if
  2253. necessary. See C<PUSHu>.
  2254. =item XS
  2255. Macro to declare an XSUB and its C parameter list. This is handled by
  2256. C<xsubpp>.
  2257. =item XSRETURN
  2258. Return from XSUB, indicating number of items on the stack. This is usually
  2259. handled by C<xsubpp>.
  2260. XSRETURN(int x)
  2261. =item XSRETURN_EMPTY
  2262. Return an empty list from an XSUB immediately.
  2263. XSRETURN_EMPTY;
  2264. =item XSRETURN_IV
  2265. Return an integer from an XSUB immediately. Uses C<XST_mIV>.
  2266. XSRETURN_IV(IV v)
  2267. =item XSRETURN_NO
  2268. Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
  2269. XSRETURN_NO;
  2270. =item XSRETURN_NV
  2271. Return an double from an XSUB immediately. Uses C<XST_mNV>.
  2272. XSRETURN_NV(NV v)
  2273. =item XSRETURN_PV
  2274. Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
  2275. XSRETURN_PV(char *v)
  2276. =item XSRETURN_UNDEF
  2277. Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
  2278. XSRETURN_UNDEF;
  2279. =item XSRETURN_YES
  2280. Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
  2281. XSRETURN_YES;
  2282. =item XST_mIV
  2283. Place an integer into the specified position C<i> on the stack. The value is
  2284. stored in a new mortal SV.
  2285. XST_mIV( int i, IV v )
  2286. =item XST_mNV
  2287. Place a double into the specified position C<i> on the stack. The value is
  2288. stored in a new mortal SV.
  2289. XST_mNV( int i, NV v )
  2290. =item XST_mNO
  2291. Place C<&PL_sv_no> into the specified position C<i> on the stack.
  2292. XST_mNO( int i )
  2293. =item XST_mPV
  2294. Place a copy of a string into the specified position C<i> on the stack. The
  2295. value is stored in a new mortal SV.
  2296. XST_mPV( int i, char *v )
  2297. =item XST_mUNDEF
  2298. Place C<&PL_sv_undef> into the specified position C<i> on the stack.
  2299. XST_mUNDEF( int i )
  2300. =item XST_mYES
  2301. Place C<&PL_sv_yes> into the specified position C<i> on the stack.
  2302. XST_mYES( int i )
  2303. =item XS_VERSION
  2304. The version identifier for an XS module. This is usually handled
  2305. automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>.
  2306. =item XS_VERSION_BOOTCHECK
  2307. Macro to verify that a PM module's $VERSION variable matches the XS module's
  2308. C<XS_VERSION> variable. This is usually handled automatically by
  2309. C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.
  2310. =item Zero
  2311. The XSUB-writer's interface to the C C<memzero> function. The C<d> is the
  2312. destination, C<n> is the number of items, and C<t> is the type.
  2313. void Zero( d, n, t )
  2314. =back
  2315. =head1 AUTHORS
  2316. Until May 1997, this document was maintained by Jeff Okamoto
  2317. <[email protected]>. It is now maintained as part of Perl itself.
  2318. With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
  2319. Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
  2320. Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer,
  2321. Stephen McCamant, and Gurusamy Sarathy.
  2322. API Listing originally by Dean Roehrich <[email protected]>.