Skip to content

Commit ae7ba09

Browse files
committed
ParseXS: refactor: inline and rm standard_XS_defs
(This commit is part of a series which will extend the AST parse tree from just representing individual XSUBs to representing the whole XS file.) The ExtUtils::ParseXS::Utilities::standard_XS_defs() function just returns a big string containing all the standard boilerplate code that gets added to the C file. Delete this function, and instead include the text directly within C_part_postamble::as_code().
1 parent bcc6c05 commit ae7ba09

File tree

4 files changed

+154
-211
lines changed

4 files changed

+154
-211
lines changed

MANIFEST

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4201,7 +4201,6 @@ dist/ExtUtils-ParseXS/t/104-map_type.t ExtUtils::ParseXS tests
42014201
dist/ExtUtils-ParseXS/t/105-valid_proto_string.t ExtUtils::ParseXS tests
42024202
dist/ExtUtils-ParseXS/t/106-process_typemaps.t ExtUtils::ParseXS tests
42034203
dist/ExtUtils-ParseXS/t/108-map_type.t ExtUtils::ParseXS tests
4204-
dist/ExtUtils-ParseXS/t/109-standard_XS_defs.t ExtUtils::ParseXS tests
42054204
dist/ExtUtils-ParseXS/t/112-set_cond.t ExtUtils::ParseXS tests
42064205
dist/ExtUtils-ParseXS/t/113-check_cond_preproc_statements.t ExtUtils::ParseXS tests
42074206
dist/ExtUtils-ParseXS/t/114-blurt_death_Warn.t ExtUtils::ParseXS tests

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,160 @@ sub as_code {
825825
# Emit boilerplate postamble following any code passed through from
826826
# the 'C' part of the XS file
827827

828-
ExtUtils::ParseXS::Utilities::standard_XS_defs();
828+
print ExtUtils::ParseXS::Q(<<'EOF');
829+
|#ifndef PERL_UNUSED_VAR
830+
|# define PERL_UNUSED_VAR(var) if (0) var = var
831+
|#endif
832+
|
833+
|#ifndef dVAR
834+
|# define dVAR dNOOP
835+
|#endif
836+
|
837+
|
838+
|/* This stuff is not part of the API! You have been warned. */
839+
|#ifndef PERL_VERSION_DECIMAL
840+
|# define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
841+
|#endif
842+
|#ifndef PERL_DECIMAL_VERSION
843+
|# define PERL_DECIMAL_VERSION \
844+
| PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
845+
|#endif
846+
|#ifndef PERL_VERSION_GE
847+
|# define PERL_VERSION_GE(r,v,s) \
848+
| (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
849+
|#endif
850+
|#ifndef PERL_VERSION_LE
851+
|# define PERL_VERSION_LE(r,v,s) \
852+
| (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
853+
|#endif
854+
|
855+
|/* XS_INTERNAL is the explicit static-linkage variant of the default
856+
| * XS macro.
857+
| *
858+
| * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
859+
| * "STATIC", ie. it exports XSUB symbols. You probably don't want that
860+
| * for anything but the BOOT XSUB.
861+
| *
862+
| * See XSUB.h in core!
863+
| */
864+
|
865+
|
866+
|/* TODO: This might be compatible further back than 5.10.0. */
867+
|#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
868+
|# undef XS_EXTERNAL
869+
|# undef XS_INTERNAL
870+
|# if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
871+
|# define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
872+
|# define XS_INTERNAL(name) STATIC XSPROTO(name)
873+
|# endif
874+
|# if defined(__SYMBIAN32__)
875+
|# define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
876+
|# define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
877+
|# endif
878+
|# ifndef XS_EXTERNAL
879+
|# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
880+
|# define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
881+
|# define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
882+
|# else
883+
|# ifdef __cplusplus
884+
|# define XS_EXTERNAL(name) extern "C" XSPROTO(name)
885+
|# define XS_INTERNAL(name) static XSPROTO(name)
886+
|# else
887+
|# define XS_EXTERNAL(name) XSPROTO(name)
888+
|# define XS_INTERNAL(name) STATIC XSPROTO(name)
889+
|# endif
890+
|# endif
891+
|# endif
892+
|#endif
893+
|
894+
|/* perl >= 5.10.0 && perl <= 5.15.1 */
895+
|
896+
|
897+
|/* The XS_EXTERNAL macro is used for functions that must not be static
898+
| * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
899+
| * macro defined, the best we can do is assume XS is the same.
900+
| * Dito for XS_INTERNAL.
901+
| */
902+
|#ifndef XS_EXTERNAL
903+
|# define XS_EXTERNAL(name) XS(name)
904+
|#endif
905+
|#ifndef XS_INTERNAL
906+
|# define XS_INTERNAL(name) XS(name)
907+
|#endif
908+
|
909+
|/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
910+
| * internal macro that we're free to redefine for varying linkage due
911+
| * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
912+
| * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
913+
| */
914+
|
915+
|#undef XS_EUPXS
916+
|#if defined(PERL_EUPXS_ALWAYS_EXPORT)
917+
|# define XS_EUPXS(name) XS_EXTERNAL(name)
918+
|#else
919+
| /* default to internal */
920+
|# define XS_EUPXS(name) XS_INTERNAL(name)
921+
|#endif
922+
|
923+
|#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
924+
|#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
925+
|
926+
|/* prototype to pass -Wmissing-prototypes */
927+
|STATIC void
928+
|S_croak_xs_usage(const CV *const cv, const char *const params);
929+
|
930+
|STATIC void
931+
|S_croak_xs_usage(const CV *const cv, const char *const params)
932+
|{
933+
| const GV *const gv = CvGV(cv);
934+
|
935+
| PERL_ARGS_ASSERT_CROAK_XS_USAGE;
936+
|
937+
| if (gv) {
938+
| const char *const gvname = GvNAME(gv);
939+
| const HV *const stash = GvSTASH(gv);
940+
| const char *const hvname = stash ? HvNAME(stash) : NULL;
941+
|
942+
| if (hvname)
943+
| Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
944+
| else
945+
| Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
946+
| } else {
947+
| /* Pants. I don't think that it should be possible to get here. */
948+
| Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
949+
| }
950+
|}
951+
|#undef PERL_ARGS_ASSERT_CROAK_XS_USAGE
952+
|
953+
|#define croak_xs_usage S_croak_xs_usage
954+
|
955+
|#endif
956+
|
957+
|/* NOTE: the prototype of newXSproto() is different in versions of perls,
958+
| * so we define a portable version of newXSproto()
959+
| */
960+
|#ifdef newXS_flags
961+
|#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
962+
|#else
963+
|#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
964+
|#endif /* !defined(newXS_flags) */
965+
|
966+
|#if PERL_VERSION_LE(5, 21, 5)
967+
|# define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
968+
|#else
969+
|# define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
970+
|#endif
971+
|
972+
|/* simple backcompat versions of the TARGx() macros with no optimisation */
973+
|#ifndef TARGi
974+
|# define TARGi(iv, do_taint) sv_setiv_mg(TARG, iv)
975+
|# define TARGu(uv, do_taint) sv_setuv_mg(TARG, uv)
976+
|# define TARGn(nv, do_taint) sv_setnv_mg(TARG, nv)
977+
|#endif
978+
|
979+
EOF
980+
981+
# Fix up line number reckoning
829982

830983
print 'ExtUtils::ParseXS::CountLines'->end_marker, "\n"
831984
if $pxs->{config_WantLineNumbers};

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm

Lines changed: 0 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ our (@ISA, @EXPORT_OK);
1616
valid_proto_string
1717
process_typemaps
1818
map_type
19-
standard_XS_defs
2019
set_cond
2120
Warn
2221
WarnHint
@@ -41,7 +40,6 @@ ExtUtils::ParseXS::Utilities - Subroutines used with ExtUtils::ParseXS
4140
valid_proto_string
4241
process_typemaps
4342
map_type
44-
standard_XS_defs
4543
set_cond
4644
Warn
4745
blurt
@@ -301,186 +299,6 @@ sub map_type {
301299
}
302300

303301

304-
=head2 C<standard_XS_defs()>
305-
306-
=over 4
307-
308-
=item * Purpose
309-
310-
Writes to the C<.c> output file certain preprocessor directives and function
311-
headers needed in all such files.
312-
313-
=item * Arguments
314-
315-
None.
316-
317-
=item * Return Value
318-
319-
Returns true.
320-
321-
=back
322-
323-
=cut
324-
325-
sub standard_XS_defs {
326-
print <<"EOF";
327-
#ifndef PERL_UNUSED_VAR
328-
# define PERL_UNUSED_VAR(var) if (0) var = var
329-
#endif
330-
331-
#ifndef dVAR
332-
# define dVAR dNOOP
333-
#endif
334-
335-
336-
/* This stuff is not part of the API! You have been warned. */
337-
#ifndef PERL_VERSION_DECIMAL
338-
# define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
339-
#endif
340-
#ifndef PERL_DECIMAL_VERSION
341-
# define PERL_DECIMAL_VERSION \\
342-
PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
343-
#endif
344-
#ifndef PERL_VERSION_GE
345-
# define PERL_VERSION_GE(r,v,s) \\
346-
(PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
347-
#endif
348-
#ifndef PERL_VERSION_LE
349-
# define PERL_VERSION_LE(r,v,s) \\
350-
(PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
351-
#endif
352-
353-
/* XS_INTERNAL is the explicit static-linkage variant of the default
354-
* XS macro.
355-
*
356-
* XS_EXTERNAL is the same as XS_INTERNAL except it does not include
357-
* "STATIC", ie. it exports XSUB symbols. You probably don't want that
358-
* for anything but the BOOT XSUB.
359-
*
360-
* See XSUB.h in core!
361-
*/
362-
363-
364-
/* TODO: This might be compatible further back than 5.10.0. */
365-
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
366-
# undef XS_EXTERNAL
367-
# undef XS_INTERNAL
368-
# if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
369-
# define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
370-
# define XS_INTERNAL(name) STATIC XSPROTO(name)
371-
# endif
372-
# if defined(__SYMBIAN32__)
373-
# define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
374-
# define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
375-
# endif
376-
# ifndef XS_EXTERNAL
377-
# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
378-
# define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
379-
# define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
380-
# else
381-
# ifdef __cplusplus
382-
# define XS_EXTERNAL(name) extern "C" XSPROTO(name)
383-
# define XS_INTERNAL(name) static XSPROTO(name)
384-
# else
385-
# define XS_EXTERNAL(name) XSPROTO(name)
386-
# define XS_INTERNAL(name) STATIC XSPROTO(name)
387-
# endif
388-
# endif
389-
# endif
390-
#endif
391-
392-
/* perl >= 5.10.0 && perl <= 5.15.1 */
393-
394-
395-
/* The XS_EXTERNAL macro is used for functions that must not be static
396-
* like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
397-
* macro defined, the best we can do is assume XS is the same.
398-
* Dito for XS_INTERNAL.
399-
*/
400-
#ifndef XS_EXTERNAL
401-
# define XS_EXTERNAL(name) XS(name)
402-
#endif
403-
#ifndef XS_INTERNAL
404-
# define XS_INTERNAL(name) XS(name)
405-
#endif
406-
407-
/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
408-
* internal macro that we're free to redefine for varying linkage due
409-
* to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
410-
* XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
411-
*/
412-
413-
#undef XS_EUPXS
414-
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
415-
# define XS_EUPXS(name) XS_EXTERNAL(name)
416-
#else
417-
/* default to internal */
418-
# define XS_EUPXS(name) XS_INTERNAL(name)
419-
#endif
420-
421-
EOF
422-
423-
print <<"EOF";
424-
#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
425-
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
426-
427-
/* prototype to pass -Wmissing-prototypes */
428-
STATIC void
429-
S_croak_xs_usage(const CV *const cv, const char *const params);
430-
431-
STATIC void
432-
S_croak_xs_usage(const CV *const cv, const char *const params)
433-
{
434-
const GV *const gv = CvGV(cv);
435-
436-
PERL_ARGS_ASSERT_CROAK_XS_USAGE;
437-
438-
if (gv) {
439-
const char *const gvname = GvNAME(gv);
440-
const HV *const stash = GvSTASH(gv);
441-
const char *const hvname = stash ? HvNAME(stash) : NULL;
442-
443-
if (hvname)
444-
Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
445-
else
446-
Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
447-
} else {
448-
/* Pants. I don't think that it should be possible to get here. */
449-
Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
450-
}
451-
}
452-
#undef PERL_ARGS_ASSERT_CROAK_XS_USAGE
453-
454-
#define croak_xs_usage S_croak_xs_usage
455-
456-
#endif
457-
458-
/* NOTE: the prototype of newXSproto() is different in versions of perls,
459-
* so we define a portable version of newXSproto()
460-
*/
461-
#ifdef newXS_flags
462-
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
463-
#else
464-
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
465-
#endif /* !defined(newXS_flags) */
466-
467-
#if PERL_VERSION_LE(5, 21, 5)
468-
# define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
469-
#else
470-
# define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
471-
#endif
472-
473-
/* simple backcompat versions of the TARGx() macros with no optimisation */
474-
#ifndef TARGi
475-
# define TARGi(iv, do_taint) sv_setiv_mg(TARG, iv)
476-
# define TARGu(uv, do_taint) sv_setuv_mg(TARG, uv)
477-
# define TARGn(nv, do_taint) sv_setnv_mg(TARG, nv)
478-
#endif
479-
480-
EOF
481-
return 1;
482-
}
483-
484302
=head2 C<set_cond()>
485303
486304
=over 4

0 commit comments

Comments
 (0)