Skip to content

Commit

Permalink
Merge pull request #77 from pali/no-expressions-in-macros
Browse files Browse the repository at this point in the history
Do not use expressions in macros SvTRUE, SvPV, SvIV, attr and attr_true
  • Loading branch information
dankogai authored Nov 22, 2016
2 parents 3728813 + e271ab0 commit e5234b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
10 changes: 8 additions & 2 deletions Encode.xs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ CODE:
void
Method_perlio_ok(obj)
SV * obj
PREINIT:
SV *sv;
CODE:
{
/* encode_t *enc = INT2PTR(encode_t *, SvIV(SvRV(obj))); */
Expand All @@ -841,7 +843,8 @@ CODE:
eval_pv("require PerlIO::encoding", 0);
SPAGAIN;

if (SvTRUE(get_sv("@", 0))) {
sv = get_sv("@", 0);
if (SvTRUE(sv)) {
ST(0) = &PL_sv_no;
}else{
ST(0) = &PL_sv_yes;
Expand All @@ -852,14 +855,17 @@ CODE:
void
Method_mime_name(obj)
SV * obj
PREINIT:
SV *sv;
CODE:
{
encode_t *enc = INT2PTR(encode_t *, SvIV(SvRV(obj)));
SV *retval;
eval_pv("require Encode::MIME::Name", 0);
SPAGAIN;

if (SvTRUE(get_sv("@", 0))) {
sv = get_sv("@", 0);
if (SvTRUE(sv)) {
ST(0) = &PL_sv_undef;
}else{
ENTER;
Expand Down
28 changes: 18 additions & 10 deletions Unicode/Unicode.xs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ PROTOTYPES: DISABLE

#define attr(k, l) (hv_exists((HV *)SvRV(obj),k,l) ? \
*hv_fetch((HV *)SvRV(obj),k,l,0) : &PL_sv_undef)
#define attr_true(k, l) (hv_exists((HV *)SvRV(obj),k,l) ? \
SvTRUE(*hv_fetch((HV *)SvRV(obj),k,l,0)) : FALSE)

void
decode_xs(obj, str, check = 0)
Expand All @@ -135,8 +133,10 @@ SV * str
IV check
CODE:
{
U8 endian = *((U8 *)SvPV_nolen(attr("endian", 6)));
int size = SvIV(attr("size", 4));
SV *sve = attr("endian", 6);
U8 endian = *((U8 *)SvPV_nolen(sve));
SV *svs = attr("size", 4);
int size = SvIV(svs);
int ucs2 = -1; /* only needed in the event of surrogate pairs */
SV *result = newSVpvn("",0);
STRLEN usize = (size > 0 ? size : 1); /* protect against rogue size<=0 */
Expand Down Expand Up @@ -180,6 +180,7 @@ CODE:
SvUTF8_on(result);

if (!endian && s+size <= e) {
SV *sv;
UV bom;
endian = (size == 4) ? 'N' : 'n';
bom = enc_unpack(aTHX_ &s,e,size,endian);
Expand Down Expand Up @@ -208,7 +209,8 @@ CODE:
}
#if 1
/* Update endian for next sequence */
if (attr_true("renewed", 7)) {
sv = attr("renewed", 7);
if (SvTRUE(sv)) {
(void)hv_store((HV *)SvRV(obj),"endian",6,newSVpv((char *)&endian,1),0);
}
#endif
Expand All @@ -227,7 +229,8 @@ CODE:
U8 *d;
if (issurrogate(ord)) {
if (ucs2 == -1) {
ucs2 = attr_true("ucs2", 4);
SV *sv = attr("ucs2", 4);
ucs2 = SvTRUE(sv);
}
if (ucs2 || size == 4) {
if (check) {
Expand Down Expand Up @@ -348,8 +351,10 @@ SV * utf8
IV check
CODE:
{
U8 endian = *((U8 *)SvPV_nolen(attr("endian", 6)));
const int size = SvIV(attr("size", 4));
SV *sve = attr("endian", 6);
U8 endian = *((U8 *)SvPV_nolen(sve));
SV *svs = attr("size", 4);
const int size = SvIV(svs);
int ucs2 = -1; /* only needed if there is invalid_ucs2 input */
const STRLEN usize = (size > 0 ? size : 1);
SV *result = newSVpvn("", 0);
Expand Down Expand Up @@ -389,11 +394,13 @@ CODE:
SvGROW(result, ((ulen+1) * usize));

if (!endian) {
SV *sv;
endian = (size == 4) ? 'N' : 'n';
enc_pack(aTHX_ result,size,endian,BOM_BE);
#if 1
/* Update endian for next sequence */
if (attr_true("renewed", 7)) {
sv = attr("renewed", 7);
if (SvTRUE(sv)) {
(void)hv_store((HV *)SvRV(obj),"endian",6,newSVpv((char *)&endian,1),0);
}
#endif
Expand All @@ -409,7 +416,8 @@ CODE:
if (size != 4 && invalid_ucs2(ord)) {
if (!issurrogate(ord)) {
if (ucs2 == -1) {
ucs2 = attr_true("ucs2", 4);
SV *sv = attr("ucs2", 4);
ucs2 = SvTRUE(sv);
}
if (ucs2 || ord > 0x10FFFF) {
if (check) {
Expand Down

0 comments on commit e5234b1

Please sign in to comment.