Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use expressions in macros SvTRUE, SvPV, SvIV, attr and attr_true #77

Merged
merged 1 commit into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -155,6 +155,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 @@ -183,7 +184,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 @@ -202,7 +204,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 @@ -322,8 +325,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 All @@ -344,11 +349,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 @@ -364,7 +371,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