Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
UNDEF,SV_YES,SV_NO,PLACEHOLDER macros #252
Browse files Browse the repository at this point in the history
UNDEF and PLACEHOLDER only in *.c core files,
SV_YES, SV_NO also in *.h files, which are used in external XS

Closes #252
  • Loading branch information
rurban committed Feb 14, 2017
1 parent 121a6a1 commit ad17bda
Show file tree
Hide file tree
Showing 38 changed files with 492 additions and 470 deletions.
10 changes: 5 additions & 5 deletions XSUB.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ is a lexical C<$_> in scope.
/* These 3 macros are replacements for dXSARGS macro only in bootstrap.
They factor out common code in every BOOT XSUB. Computation of vars mark
and items will optimize away in most BOOT functions. Var ax can never be
optimized away since BOOT must return &PL_sv_yes by default from xsubpp.
optimized away since BOOT must return SV_YES by default from xsubpp.
Note these macros are not drop in replacements for dXSARGS since they set
PL_xsubfilename. */
#define dXSBOOTARGSXSAPIVERCHK \
Expand Down Expand Up @@ -218,11 +218,11 @@ Place a copy of a string into the specified position C<pos> on the stack.
The value is stored in a new mortal SV.
=for apidoc Am|void|XST_mNO|int pos
Place C<&PL_sv_no> into the specified position C<pos> on the
Place C<SV_NO> into the specified position C<pos> on the
stack.
=for apidoc Am|void|XST_mYES|int pos
Place C<&PL_sv_yes> into the specified position C<pos> on the
Place C<SV_YES> into the specified position C<pos> on the
stack.
=for apidoc Am|void|XST_mUNDEF|int pos
Expand All @@ -246,10 +246,10 @@ Return a double from an XSUB immediately. Uses C<XST_mNV>.
Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
=for apidoc Ams||XSRETURN_NO
Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
Return C<SV_NO> from an XSUB immediately. Uses C<XST_mNO>.
=for apidoc Ams||XSRETURN_YES
Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
Return C<SV_YES> from an XSUB immediately. Uses C<XST_mYES>.
=for apidoc Ams||XSRETURN_UNDEF
Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
Expand Down
22 changes: 11 additions & 11 deletions av.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Perl_av_reify(pTHX_ AV *av)
AvARRAY(av)[--key] = NULL;
while (key) {
SV * const sv = AvARRAY(av)[--key];
if (sv != &PL_sv_undef)
if (sv != UNDEF)
SvREFCNT_inc_simple_void(sv);
}
key = AvARRAY(av) - AvALLOC(av);
Expand Down Expand Up @@ -493,7 +493,7 @@ Perl_av_make(pTHX_ SSize_t size, SV **strp)
if (LIKELY(PL_tmps_ix == orig_ix))
PL_tmps_ix--;
else
PL_tmps_stack[orig_ix] = &PL_sv_undef;
PL_tmps_stack[orig_ix] = UNDEF;
}
return av;
}
Expand Down Expand Up @@ -548,7 +548,7 @@ Perl_av_init_shaped(pTHX_ AV* av, const SSize_t size, const HV *type)
else if (memEQs(name, l, "Str"))
def = newSVpvs("");
else if (memEQs(name, l, "Scalar"))
def = NULL; /* not &PL_sv_undef, it's r-o */
def = NULL; /* not UNDEF, it's r-o */
else if (memEQs(name, l, "int")
|| memEQs(name, l, "uint")
|| memEQs(name, l, "str"))
Expand Down Expand Up @@ -667,7 +667,7 @@ Perl_av_clear(pTHX_ AV *av)
if (LIKELY(PL_tmps_ix == orig_ix))
PL_tmps_ix--;
else
PL_tmps_stack[orig_ix] = &PL_sv_undef;
PL_tmps_stack[orig_ix] = UNDEF;
SvREFCNT_dec_NN(av);
}
}
Expand Down Expand Up @@ -729,7 +729,7 @@ Perl_av_undef(pTHX_ AV *av)
else {
/* known gcc bug, since 4.7 */
GCC47_DIAG_IGNORE(-Wmaybe-uninitialized)
PL_tmps_stack[orig_ix] = &PL_sv_undef;
PL_tmps_stack[orig_ix] = UNDEF;
GCC47_DIAG_RESTORE
}
SvREFCNT_dec_NN(av);
Expand Down Expand Up @@ -793,7 +793,7 @@ Perl_av_push(pTHX_ AV *av, SV *val)
Removes one SV from the end of the array, reducing its size by one and
returning the SV (transferring control of one reference count) to the
caller. Returns C<&PL_sv_undef> if the array is empty.
caller. Returns C<UNDEF> if the array is empty.
Perl equivalent: C<pop(@myarray);>
Expand All @@ -820,12 +820,12 @@ Perl_av_pop(pTHX_ AV *av)
return retval;
}
if (AvFILL(av) < 0)
return &PL_sv_undef;
return UNDEF;
retval = AvARRAY(av)[AvFILLp(av)];
AvARRAY(av)[AvFILLp(av)--] = NULL;
if (UNLIKELY(SvSMAGICAL(av)))
mg_set(MUTABLE_SV(av));
return retval ? retval : &PL_sv_undef;
return retval ? retval : UNDEF;
}

/*
Expand Down Expand Up @@ -920,7 +920,7 @@ Perl_av_unshift(pTHX_ AV *av, SSize_t num)
Removes one SV from the start of the array, reducing its size by one and
returning the SV (transferring control of one reference count) to the
caller. Returns C<&PL_sv_undef> if the array is empty.
caller. Returns C<UNDEF> if the array is empty.
Perl equivalent: C<shift(@myarray);>
Expand All @@ -947,7 +947,7 @@ Perl_av_shift(pTHX_ AV *av)
return retval;
}
if (AvFILL(av) < 0)
return &PL_sv_undef;
return UNDEF;
retval = *AvARRAY(av);
if (AvREAL(av))
*AvARRAY(av) = NULL;
Expand All @@ -956,7 +956,7 @@ Perl_av_shift(pTHX_ AV *av)
AvFILLp(av)--;
if (UNLIKELY(SvSMAGICAL(av)))
mg_set(MUTABLE_SV(av));
return retval ? retval : &PL_sv_undef;
return retval ? retval : UNDEF;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion cop.h
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ L<perlcall>.
#define G_METHOD 128 /* Calling method. */
#define G_FAKINGEVAL 256 /* Faking an eval context for call_sv or
fold_constants. */
#define G_UNDEF_FILL 512 /* Fill the stack with &PL_sv_undef
#define G_UNDEF_FILL 512 /* Fill the stack with UNDEF
A special case for UNSHIFT in
Perl_magic_methcall(). */
#define G_WRITING_TO_STDERR 1024 /* Perl_write_to_stderr() is calling
Expand Down
2 changes: 1 addition & 1 deletion deb.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
if (i > stack_min)
PerlIO_printf(Perl_debug_log, "... ");

if (stack_base[0] != &PL_sv_undef || stack_max < 0)
if (stack_base[0] != UNDEF || stack_max < 0)
PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
do {
++i;
Expand Down
2 changes: 1 addition & 1 deletion doio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ nothing in the core.
* library figure out what to do. This usually means
* "current time". */

if ( accessed == &PL_sv_undef && modified == &PL_sv_undef )
if ( accessed == UNDEF && modified == UNDEF )
utbufp = NULL;
else {
Zero(&utbuf, sizeof utbuf, char);
Expand Down
18 changes: 9 additions & 9 deletions dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,15 @@ Perl_sv_peek(pTHX_ SV *sv)
sv_catpv(t, "WILD");
goto finish;
}
else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
if (sv == &PL_sv_undef) {
else if (sv == UNDEF || sv == SV_NO || sv == SV_YES || sv == PLACEHOLDER) {
if (sv == UNDEF) {
sv_catpv(t, "SV_UNDEF");
if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)) &&
SvREADONLY(sv))
goto finish;
}
else if (sv == &PL_sv_no) {
else if (sv == SV_NO) {
sv_catpv(t, "SV_NO");
if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)) &&
Expand All @@ -397,7 +397,7 @@ Perl_sv_peek(pTHX_ SV *sv)
SvNVX(sv) == 0.0)
goto finish;
}
else if (sv == &PL_sv_yes) {
else if (sv == SV_YES) {
sv_catpv(t, "SV_YES");
if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
SVs_GMG|SVs_SMG|SVs_RMG)) &&
Expand Down Expand Up @@ -2599,19 +2599,19 @@ S_deb_hek(pTHX_ HEK* hek, SV* val)
if (HEK_FLAGS(hek) > 1)
PerlIO_printf(Perl_debug_log, "0x%x ", HEK_FLAGS(hek));
}
if (val == &PL_sv_placeholder) {
if (val == PLACEHOLDER) {
PerlIO_printf(Perl_debug_log, "PLACEHOLDER]");
}
else if (val == &PL_sv_undef) {
else if (val == UNDEF) {
PerlIO_printf(Perl_debug_log, "UNDEF]");
}
else if (val == &PL_sv_yes) {
else if (val == SV_YES) {
PerlIO_printf(Perl_debug_log, "YES]");
}
else if (val == &PL_sv_no) {
else if (val == SV_NO) {
PerlIO_printf(Perl_debug_log, "NO]");
}
else if (val < &PL_sv_undef) { /* than the first alloced variable, a refcnt */
else if (val < UNDEF) { /* than the first alloced variable, a refcnt */
PerlIO_printf(Perl_debug_log, "%" UVuf "]", PTR2UV(val));
}
else {
Expand Down
3 changes: 3 additions & 0 deletions ext/mro/mro.xs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ S_mro_get_linear_isa_c3(pTHX_ HV* stash, U32 level)
SSize_t items = AvFILLp(isa) + 1;
SV** isa_ptr = AvARRAY(isa);
while (items--) {
/* Deleted ISA items end up as empty PVMG, never NULL.
And their stash will be "main", not empty.
But you still can create empty entries with $#ISA++; RT 119433. */
SV* const isa_item = *isa_ptr ? *isa_ptr : &PL_sv_undef;
HV* const isa_item_stash = gv_stashsv(isa_item, 0);
isa_ptr++;
Expand Down
5 changes: 5 additions & 0 deletions ext/re/re_top.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
# define DEBUGGING
#endif

#define UNDEF (0 + &PL_sv_undef)
#define SV_YES (0 + &PL_sv_yes)
#define SV_NO (0 + &PL_sv_no)
#define PLACEHOLDER (0 + &PL_sv_placeholder)

/* We *really* need to overwrite these symbols: */
#define Perl_regexec_flags my_regexec
#define Perl_regdump my_regdump
Expand Down
34 changes: 17 additions & 17 deletions gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le
Foo->unimport from being an error even if there's no
import/unimport subroutine */
if (strEQc(name,"import") || strEQc(name,"unimport"))
gv = MUTABLE_GV(&PL_sv_yes);
gv = MUTABLE_GV(SV_YES);
else if (autoload)
gv = gv_autoload_pvn(
ostash, name, nend - name, GV_AUTOLOAD_ISMETHOD|flags
Expand Down Expand Up @@ -1631,15 +1631,15 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,
}
gvp = (GV**)hv_fetch(*stash, key, is_utf8 ? -((I32)*len) : (I32)*len, add);
*gv = gvp ? *gvp : NULL;
if (*gv && *gv != (const GV *)&PL_sv_undef) {
if (*gv && *gv != (const GV *)UNDEF) {
if (SvTYPE(*gv) != SVt_PVGV)
gv_init_pvn(*gv, *stash, key, *len, (add & GV_ADDMULTI)|is_utf8);
else
GvMULTI_on(*gv);
}
if (key != *name /*&& (!*gv || !GvSTATIC(*gv)) */)
Safefree(key);
if (!*gv || *gv == (const GV *)&PL_sv_undef)
if (!*gv || *gv == (const GV *)UNDEF)
return FALSE;

if (!(*stash = GvHV(*gv))) {
Expand Down Expand Up @@ -1759,7 +1759,7 @@ S_find_default_stash(pTHX_ HV **stash, const char *name, STRLEN len,
(*name == 'a' || *name == 'b')) )
{
GV**gvp = (GV**)hv_fetch(*stash,name,is_utf8 ? -(I32)len : (I32)len,0);
if (!gvp || *gvp == (const GV *)&PL_sv_undef ||
if (!gvp || *gvp == (const GV *)UNDEF ||
SvTYPE(*gvp) != SVt_PVGV)
{
*stash = NULL;
Expand Down Expand Up @@ -1969,7 +1969,7 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
for (i = 1; i < SIG_SIZE; i++) {
SV * const * const init = hv_fetch(hv, PL_sig_name[i], strlen(PL_sig_name[i]), 1);
if (init)
sv_setsv(*init, &PL_sv_undef);
sv_setsv(*init, UNDEF);
}
}
break;
Expand Down Expand Up @@ -2349,7 +2349,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
else return NULL;
}
gvp = (GV**)hv_fetch(stash, name, is_utf8 ? -(I32)len : (I32)len,add);
if (!gvp || *gvp == (const GV *)&PL_sv_undef) {
if (!gvp || *gvp == (const GV *)UNDEF) {
if (addmg) gv = (GV *)newSV(0);
else return NULL;
}
Expand Down Expand Up @@ -2938,7 +2938,7 @@ Perl_try_amagic_un(pTHX_ int method, int flags) {

SvGETMAGIC(arg);

if (SvAMAGIC(arg) && (tmpsv = amagic_call(arg, &PL_sv_undef, method,
if (SvAMAGIC(arg) && (tmpsv = amagic_call(arg, UNDEF, method,
AMGf_noright | AMGf_unary
| (flags & AMGf_numarg))))
{
Expand Down Expand Up @@ -3014,7 +3014,7 @@ Perl_try_amagic_bin(pTHX_ int method, int flags) {
able name. */
if (!SvOK(right)) {
if (ckWARN(WARN_UNINITIALIZED)) report_uninit(right);
sv_setsv_flags(left, &PL_sv_no, 0);
sv_setsv_flags(left, SV_NO, 0);
}
else sv_setsv_flags(left, right, 0);
SvGETMAGIC(right);
Expand Down Expand Up @@ -3043,7 +3043,7 @@ Perl_amagic_deref_call(pTHX_ SV *ref, int method) {
if (HvAUX(stash)->xhv_aux_flags & HvAUXf_NO_DEREF)
return ref;

while ((tmpsv = amagic_call(ref, &PL_sv_undef, method,
while ((tmpsv = amagic_call(ref, UNDEF, method,
AMGf_noright | AMGf_unary))) {
if (!SvROK(tmpsv))
Perl_croak(aTHX_ "Overloaded dereference did not return a reference");
Expand Down Expand Up @@ -3134,14 +3134,14 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
force_cpy = 1;
if ((cv = cvp[off=add_ass_amg])
|| ((cv = cvp[off = add_amg]) && (force_cpy = 0, postpr = 1))) {
right = &PL_sv_yes; lr = -1; assign = 1;
right = SV_YES; lr = -1; assign = 1;
}
break;
case dec_amg:
force_cpy = 1;
if ((cv = cvp[off = subtr_ass_amg])
|| ((cv = cvp[off = subtr_amg]) && (force_cpy = 0, postpr=1))) {
right = &PL_sv_yes; lr = -1; assign = 1;
right = SV_YES; lr = -1; assign = 1;
}
break;
case bool__amg:
Expand Down Expand Up @@ -3316,15 +3316,15 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
"has no overloaded magic",
SvAMAGIC(left)?
SVfARG(sv_2mortal(newSVhek(HvNAME_HEK(SvSTASH(SvRV(left)))))):
SVfARG(&PL_sv_no),
SVfARG(SV_NO),
SvAMAGIC(right)?
",\n\tright argument in overloaded package ":
(flags & AMGf_unary
? ""
: ",\n\tright argument has no overloaded magic"),
SvAMAGIC(right)?
SVfARG(sv_2mortal(newSVhek(HvNAME_HEK(SvSTASH(SvRV(right)))))):
SVfARG(&PL_sv_no)));
SVfARG(SV_NO)));
if (use_default_op) {
DEBUG_o( Perl_deb(aTHX_ "%" SVf, SVfARG(msg)) );
} else {
Expand Down Expand Up @@ -3490,15 +3490,15 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
EXTEND(SP, notfound + 5);
PUSHs(lr>0? right: left);
PUSHs(lr>0? left: right);
PUSHs( lr > 0 ? &PL_sv_yes : ( assign ? &PL_sv_undef : &PL_sv_no ));
PUSHs( lr > 0 ? SV_YES : ( assign ? UNDEF : SV_NO ));
if (notfound) {
PUSHs(newSVpvn_flags(AMG_id2name(method + assignshift),
AMG_id2namelen(method + assignshift), SVs_TEMP));
}
else if (flags & AMGf_numarg)
PUSHs(&PL_sv_undef);
PUSHs(UNDEF);
if (flags & AMGf_numarg)
PUSHs(&PL_sv_yes);
PUSHs(SV_YES);
PUSHs(MUTABLE_SV(cv));
PUTBACK;
oldmark = TOPMARK;
Expand All @@ -3514,7 +3514,7 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
/* returning NULL has another meaning, and we check the context
* at the call site too, so this can be differentiated from the
* scalar case */
res = &PL_sv_undef;
res = UNDEF;
SP = PL_stack_base + oldmark;
break;
case G_ARRAY: {
Expand Down
Loading

0 comments on commit ad17bda

Please sign in to comment.