@@ -10307,6 +10307,78 @@ Perl_newXS_deffile(pTHX_ const char *name, XSUBADDR_t subaddr)
10307
10307
);
10308
10308
}
10309
10309
10310
+ /*
10311
+ =for apidoc m|CV *|newXS_len_flags|const char *name|STRLEN len|XSUBADDR_t subaddr|const char *const filename|NULLOK const char *const proto|NULLOK SV **const_svp|U32 flags
10312
+
10313
+ Construct an XS subroutine, also performing some surrounding jobs.
10314
+
10315
+ The subroutine will have the entry point C<subaddr>. It will have
10316
+ the prototype specified by the nul-terminated string C<proto>, or
10317
+ no prototype if C<proto> is null. The prototype string is copied;
10318
+ the caller can mutate the supplied string afterwards. If C<filename>
10319
+ is non-null, it must be a nul-terminated filename, and the subroutine
10320
+ will have its C<CvFILE> set accordingly. By default C<CvFILE> is set to
10321
+ point directly to the supplied string, which must be static. If C<flags>
10322
+ has the C<XS_DYNAMIC_FILENAME> bit set, then a copy of the string will
10323
+ be taken instead.
10324
+
10325
+ Other aspects of the subroutine will be left in their default state.
10326
+ If anything else needs to be done to the subroutine for it to function
10327
+ correctly, it is the caller's responsibility to do that after this
10328
+ function has constructed it. However, beware of the subroutine
10329
+ potentially being destroyed before this function returns, as described
10330
+ below.
10331
+
10332
+ If C<name> is null then the subroutine will be anonymous, with its
10333
+ C<CvGV> referring to an C<__ANON__> glob. If C<name> is non-null then the
10334
+ subroutine will be named accordingly, referenced by the appropriate glob.
10335
+ C<name> is a string of length C<len> bytes giving a sigilless symbol name,
10336
+ in UTF-8 if C<flags> has the C<SVf_UTF8> bit set and in Latin-1 otherwise.
10337
+ The name may be either qualified or unqualified, with the stash defaulting
10338
+ in the same manner as for C<gv_fetchpvn_flags>. C<flags> may contain
10339
+ flag bits understood by C<gv_fetchpvn_flags> with the same meaning as
10340
+ they have there, such as C<GV_ADDWARN>. The symbol is always added to
10341
+ the stash if necessary, with C<GV_ADDMULTI> semantics.
10342
+
10343
+ If there is already a subroutine of the specified name, then the new sub
10344
+ will replace the existing one in the glob. A warning may be generated
10345
+ about the redefinition. If the old subroutine was C<CvCONST> then the
10346
+ decision about whether to warn is influenced by an expectation about
10347
+ whether the new subroutine will become a constant of similar value.
10348
+ That expectation is determined by C<const_svp>. (Note that the call to
10349
+ this function doesn't make the new subroutine C<CvCONST> in any case;
10350
+ that is left to the caller.) If C<const_svp> is null then it indicates
10351
+ that the new subroutine will not become a constant. If C<const_svp>
10352
+ is non-null then it indicates that the new subroutine will become a
10353
+ constant, and it points to an C<SV*> that provides the constant value
10354
+ that the subroutine will have.
10355
+
10356
+ If the subroutine has one of a few special names, such as C<BEGIN> or
10357
+ C<END>, then it will be claimed by the appropriate queue for automatic
10358
+ running of phase-related subroutines. In this case the relevant glob will
10359
+ be left not containing any subroutine, even if it did contain one before.
10360
+ In the case of C<BEGIN>, the subroutine will be executed and the reference
10361
+ to it disposed of before this function returns, and also before its
10362
+ prototype is set. If a C<BEGIN> subroutine would not be sufficiently
10363
+ constructed by this function to be ready for execution then the caller
10364
+ must prevent this happening by giving the subroutine a different name.
10365
+
10366
+ The function returns a pointer to the constructed subroutine. If the sub
10367
+ is anonymous then ownership of one counted reference to the subroutine
10368
+ is transferred to the caller. If the sub is named then the caller does
10369
+ not get ownership of a reference. In most such cases, where the sub
10370
+ has a non-phase name, the sub will be alive at the point it is returned
10371
+ by virtue of being contained in the glob that names it. A phase-named
10372
+ subroutine will usually be alive by virtue of the reference owned by the
10373
+ phase's automatic run queue. But a C<BEGIN> subroutine, having already
10374
+ been executed, will quite likely have been destroyed already by the
10375
+ time this function returns, making it erroneous for the caller to make
10376
+ any use of the returned pointer. It is the caller's responsibility to
10377
+ ensure that it knows which of these situations applies.
10378
+
10379
+ =cut
10380
+ */
10381
+
10310
10382
CV *
10311
10383
Perl_newXS_len_flags (pTHX_ const char * name , STRLEN len ,
10312
10384
XSUBADDR_t subaddr , const char * const filename ,
0 commit comments