In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/f720c878cb3248e9e723e67cb95dab8b304b2650?hp=5bad3c4f3a4515aaa622eecdf6f5a84fcaff7ed9>
- Log ----------------------------------------------------------------- commit f720c878cb3248e9e723e67cb95dab8b304b2650 Author: Karl Williamson <k...@cpan.org> Date: Sat Mar 25 14:01:58 2017 -0600 numeric.c: Add comment commit a15aa957e30616c059f73afcce11c7610ddc8d3a Author: Karl Williamson <k...@cpan.org> Date: Wed Mar 8 21:55:08 2017 -0700 Convert strncmp into strnEQ, strnNE The new versions are much easier to comprehend. There are several cases in vms.c where strEQ and strNE suffice, instead of having to have a count parameter. commit 083b2a61ee6281f67b6d6a21ad5d27e6219df60f Author: Karl Williamson <k...@cpan.org> Date: Thu Mar 9 13:13:07 2017 -0700 Convert strcmp into strEQ, strNE The latter two are easier to read ----------------------------------------------------------------------- Summary of changes: cygwin/cygwin.c | 8 +-- ext/DynaLoader/dl_aix.xs | 4 +- ext/DynaLoader/dl_win32.xs | 2 +- ext/Hash-Util-FieldHash/FieldHash.xs | 2 +- ext/Hash-Util-FieldHash/lib/Hash/Util/FieldHash.pm | 2 +- ext/POSIX/POSIX.xs | 2 +- ext/POSIX/lib/POSIX.pm | 2 +- ext/XS-APItest/APItest.pm | 2 +- ext/XS-APItest/APItest.xs | 6 +- numeric.c | 2 + symbian/symbian_stubs.c | 4 +- vms/vms.c | 72 ++++++++++------------ win32/win32.c | 6 +- win32/wince.c | 4 +- 14 files changed, 55 insertions(+), 63 deletions(-) diff --git a/cygwin/cygwin.c b/cygwin/cygwin.c index 24b278f2fd..7bcf02ab34 100644 --- a/cygwin/cygwin.c +++ b/cygwin/cygwin.c @@ -488,7 +488,7 @@ XS(XS_Cygwin_mount_flags) pathname = SvPV_nolen(ST(0)); - if (!strcmp(pathname, "/cygdrive")) { + if (strEQ(pathname, "/cygdrive")) { char user[PATH_MAX]; char system[PATH_MAX]; char user_flags[PATH_MAX]; @@ -511,7 +511,7 @@ XS(XS_Cygwin_mount_flags) int found = 0; setmntent (0, 0); while ((mnt = getmntent (0))) { - if (!strcmp(pathname, mnt->mnt_dir)) { + if (strEQ(pathname, mnt->mnt_dir)) { strcpy(flags, mnt->mnt_type); if (strlen(mnt->mnt_opts) > 0) { strcat(flags, ","); @@ -536,12 +536,12 @@ XS(XS_Cygwin_mount_flags) user_flags, system_flags); if (strlen(user) > 0) { - if (strcmp(user,pathname)) { + if (strNE(user,pathname)) { sprintf(flags, "%s,cygdrive,%s", user_flags, user); found++; } } else { - if (strcmp(user,pathname)) { + if (strNE(user,pathname)) { sprintf(flags, "%s,cygdrive,%s", system_flags, system); found++; } diff --git a/ext/DynaLoader/dl_aix.xs b/ext/DynaLoader/dl_aix.xs index 8e7d8ac0a5..54a8e3db13 100644 --- a/ext/DynaLoader/dl_aix.xs +++ b/ext/DynaLoader/dl_aix.xs @@ -226,7 +226,7 @@ void *dlopen(char *path, int mode) * Scan the list of modules if have the module already loaded. */ for (mp = dl_modList; mp; mp = mp->next) - if (strcmp(mp->name, path) == 0) { + if (strEQ(mp->name, path)) { mp->refCnt++; return mp; } @@ -364,7 +364,7 @@ void *dlsym(void *handle, const char *symbol) * the result to function pointers anyways. */ for (ep = mp->exports, i = mp->nExports; i; i--, ep++) - if (strcmp(ep->name, symbol) == 0) + if (strEQ(ep->name, symbol)) return ep->addr; dl_errvalid++; strcpy(dl_errbuf, "dlsym: undefined symbol "); diff --git a/ext/DynaLoader/dl_win32.xs b/ext/DynaLoader/dl_win32.xs index 9c5b809470..b076f2141c 100644 --- a/ext/DynaLoader/dl_win32.xs +++ b/ext/DynaLoader/dl_win32.xs @@ -102,7 +102,7 @@ dl_static_linked(char *filename) if (hptr = strstr(ptr, *p)) { /* found substring, need more detailed check if module name match */ if (hptr==ptr) { - return strcmp(ptr, *p)==0; + return strEQ(ptr, *p); } if (hptr[strlen(*p)] == 0) return hptr[-1]=='/'; diff --git a/ext/Hash-Util-FieldHash/FieldHash.xs b/ext/Hash-Util-FieldHash/FieldHash.xs index 2fcb612525..9cfd87a694 100644 --- a/ext/Hash-Util-FieldHash/FieldHash.xs +++ b/ext/Hash-Util-FieldHash/FieldHash.xs @@ -431,7 +431,7 @@ OUTPUT: void CLONE(char* classname) CODE: - if (0 == strcmp(classname, "Hash::Util::FieldHash")) { + if (strEQ(classname, "Hash::Util::FieldHash")) { HUF_global(aTHX_ HUF_CLONE); HUF_fix_objects(aTHX); } diff --git a/ext/Hash-Util-FieldHash/lib/Hash/Util/FieldHash.pm b/ext/Hash-Util-FieldHash/lib/Hash/Util/FieldHash.pm index 0d0b7921c3..7b39cca450 100644 --- a/ext/Hash-Util-FieldHash/lib/Hash/Util/FieldHash.pm +++ b/ext/Hash-Util-FieldHash/lib/Hash/Util/FieldHash.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Scalar::Util qw( reftype); -our $VERSION = '1.19'; +our $VERSION = '1.20'; require Exporter; our @ISA = qw(Exporter); diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index e52fa5b0e0..3bfeb6c80a 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -1791,7 +1791,7 @@ fix_win32_tzenv(void) perl_tz_env = ""; if (crt_tz_env == NULL) crt_tz_env = ""; - if (strcmp(perl_tz_env, crt_tz_env) != 0) { + if (strNE(perl_tz_env, crt_tz_env)) { newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char)); if (newenv != NULL) { sprintf(newenv, "TZ=%s", perl_tz_env); diff --git a/ext/POSIX/lib/POSIX.pm b/ext/POSIX/lib/POSIX.pm index 2fd13c2225..ff61981aee 100644 --- a/ext/POSIX/lib/POSIX.pm +++ b/ext/POSIX/lib/POSIX.pm @@ -4,7 +4,7 @@ use warnings; our ($AUTOLOAD, %SIGRT); -our $VERSION = '1.79'; +our $VERSION = '1.80'; require XSLoader; diff --git a/ext/XS-APItest/APItest.pm b/ext/XS-APItest/APItest.pm index d4edcac51a..cdc7e5c380 100644 --- a/ext/XS-APItest/APItest.pm +++ b/ext/XS-APItest/APItest.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Carp; -our $VERSION = '0.92'; +our $VERSION = '0.93'; require XSLoader; diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index e9a55b4030..9eafb0adf2 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -3340,13 +3340,13 @@ test_coplabel() cop = &PL_compiling; Perl_cop_store_label(aTHX_ cop, "foo", 3, 0); label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8); - if (strcmp(label,"foo")) croak("fail # cop_fetch_label label"); + if (strNE(label,"foo")) croak("fail # cop_fetch_label label"); if (len != 3) croak("fail # cop_fetch_label len"); if (utf8) croak("fail # cop_fetch_label utf8"); /* SMALL GERMAN UMLAUT A */ Perl_cop_store_label(aTHX_ cop, "fo\xc3\xa4", 4, SVf_UTF8); label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8); - if (strcmp(label,"fo\xc3\xa4")) croak("fail # cop_fetch_label label"); + if (strNE(label,"fo\xc3\xa4")) croak("fail # cop_fetch_label label"); if (len != 4) croak("fail # cop_fetch_label len"); if (!utf8) croak("fail # cop_fetch_label utf8"); @@ -3477,7 +3477,7 @@ test_op_list() #define iv_op(iv) newSVOP(OP_CONST, 0, newSViv(iv)) #define check_op(o, expect) \ do { \ - if (strcmp(test_op_list_describe(o), (expect))) \ + if (strNE(test_op_list_describe(o), (expect))) \ croak("fail %s %s", test_op_list_describe(o), (expect)); \ } while(0) a = op_append_elem(OP_LIST, NULL, NULL); diff --git a/numeric.c b/numeric.c index 9d5982a871..6821114f70 100644 --- a/numeric.c +++ b/numeric.c @@ -1209,6 +1209,8 @@ S_mulexp10(NV value, I32 exponent) NV Perl_my_atof(pTHX_ const char* s) { + /* 's' must be NUL terminated */ + NV x = 0.0; #ifdef USE_QUADMATH Perl_my_atof2(aTHX_ s, &x); diff --git a/symbian/symbian_stubs.c b/symbian/symbian_stubs.c index c997446cfd..314bd5772c 100644 --- a/symbian/symbian_stubs.c +++ b/symbian/symbian_stubs.c @@ -89,7 +89,7 @@ struct protoent* getprotobynumber(int number) { struct protoent* getprotobyname(const char* name) { int i; for (i = 0; i < sizeof(protocols)/sizeof(struct protoent); i++) - if (strcmp(name, protocols[i].p_name) == 0) + if (strEQ(name, protocols[i].p_name)) return (struct protoent*)(&(protocols[i])); return 0; } @@ -97,7 +97,7 @@ struct protoent* getprotobyname(const char* name) { struct servent* getservbyname(const char* name, const char* proto) { int i; for (i = 0; i < sizeof(services)/sizeof(struct servent); i++) - if (strcmp(name, services[i].s_name) == 0) + if (strEQ(name, services[i].s_name)) return (struct servent*)(&(services[i])); return 0; } diff --git a/vms/vms.c b/vms/vms.c index df0aed85b7..7750b935a0 100644 --- a/vms/vms.c +++ b/vms/vms.c @@ -293,7 +293,7 @@ is_unix_filespec(const char *path) /* If the user wants UNIX files, "." needs to be treated as in UNIX */ if (decc_filename_unix_report || decc_filename_unix_only) { - if (strcmp(path,".") == 0) + if (strEQ(path,".") ret_val = 1; } } @@ -844,10 +844,10 @@ S_remove_ppf_prefix(const char *lnm, char *eqv, unsigned short int eqvlen) { if (*((int *)lnm) == *((int *)"SYS$") && eqvlen >= 4 && eqv[0] == 0x1b && eqv[1] == 0x00 && - ( (lnm[4] == 'O' && !strcmp(lnm,"SYS$OUTPUT")) || - (lnm[4] == 'I' && !strcmp(lnm,"SYS$INPUT")) || - (lnm[4] == 'E' && !strcmp(lnm,"SYS$ERROR")) || - (lnm[4] == 'C' && !strcmp(lnm,"SYS$COMMAND")) ) ) { + ( (lnm[4] == 'O' && strEQ(lnm,"SYS$OUTPUT")) || + (lnm[4] == 'I' && strEQ(lnm,"SYS$INPUT")) || + (lnm[4] == 'E' && strEQ(lnm,"SYS$ERROR")) || + (lnm[4] == 'C' && strEQ(lnm,"SYS$COMMAND")) ) ) { memmove(eqv, eqv+4, eqvlen-4); eqvlen -= 4; @@ -919,7 +919,7 @@ Perl_vmstrnenv(const char *lnm, char *eqv, unsigned long int idx, for (i = 0; environ[i]; i++) { if ((eq = strchr(environ[i],'=')) && lnmdsc.dsc$w_length == (eq - environ[i]) && - !strncmp(environ[i],lnm,eq - environ[i])) { + strnEQ(environ[i],lnm,eq - environ[i])) { eq++; for (eqvlen = 0; eq[eqvlen]; eqvlen++) eqv[eqvlen] = eq[eqvlen]; if (!eqvlen) continue; @@ -1505,7 +1505,7 @@ Perl_vmssetenv(pTHX_ const char *lnm, const char *eqv, struct dsc$descriptor_s * for (i = 0; environ[i]; i++) { /* If it's an environ elt, reset */ if ((cp1 = strchr(environ[i],'=')) && lnmdsc.dsc$w_length == (cp1 - environ[i]) && - !strncmp(environ[i],lnm,cp1 - environ[i])) { + strnEQ(environ[i],lnm,cp1 - environ[i])) { unsetenv(lnm); return 0; } @@ -1637,7 +1637,7 @@ Perl_my_setenv(pTHX_ const char *lnm, const char *eqv) char uplnm[8]; int i; for (i = 0; lnm[i]; i++) uplnm[i] = toUPPER_A(lnm[i]); - if (!strcmp(uplnm,"DEFAULT")) { + if (strEQ(uplnm,"DEFAULT")) { if (eqv && *eqv) my_chdir(eqv); return; } @@ -3720,7 +3720,7 @@ store_pipelocs(pTHX) if (SvROK(dirsv)) continue; dir = SvPVx(dirsv,n_a); - if (strcmp(dir,".") == 0) continue; + if (strEQ(dir,".")) continue; if ((tounixpath_utf8(dir, unixdir, NULL)) == NULL) continue; @@ -6047,11 +6047,11 @@ int_fileify_dirspec(const char *dir, char *buf, int *utf8_fl) * ... do_fileify_dirspec("myroot",buf,1) ... * does something useful. */ - if (dirlen >= 2 && !strcmp(trndir+dirlen-2,".]")) { + if (dirlen >= 2 && strEQ(trndir+dirlen-2,".]")) { trndir[--dirlen] = '\0'; trndir[dirlen-1] = ']'; } - if (dirlen >= 2 && !strcmp(trndir+dirlen-2,".>")) { + if (dirlen >= 2 && strEQ(trndir+dirlen-2,".>")) { trndir[--dirlen] = '\0'; trndir[dirlen-1] = '>'; } @@ -6139,7 +6139,7 @@ int_fileify_dirspec(const char *dir, char *buf, int *utf8_fl) } while ((cp1 = strstr(cp1,"/.")) != NULL); lastdir = strrchr(trndir,'/'); } - else if (dirlen >= 7 && !strcmp(&trndir[dirlen-7],"/000000")) { + else if (dirlen >= 7 && strEQ(&trndir[dirlen-7],"/000000")) { char * ret_chr; /* Ditto for specs that end in an MFD -- let the VMS code * figure out whether it's a real device or a rooted logical. */ @@ -6332,7 +6332,7 @@ int_fileify_dirspec(const char *dir, char *buf, int *utf8_fl) if (rms_is_nam_fnb(dirnam, NAM$M_EXP_TYPE)) { /* Was type specified? */ /* Yep; check version while we're at it, if it's there. */ cmplen = rms_is_nam_fnb(dirnam, NAM$M_EXP_VER) ? 6 : 4; - if (strncmp(rms_nam_typel(dirnam), ".DIR;1", cmplen)) { + if (strnNE(rms_nam_typel(dirnam), ".DIR;1", cmplen)) { /* Something other than .DIR[;1]. Bzzt. */ sts = rms_free_search_context(&dirfab); PerlMem_free(esa); @@ -6697,7 +6697,7 @@ int_pathify_dirspec(const char *dir, char *buf) trnlen = strlen(trndir); /* Trap simple rooted lnms, and return lnm:[000000] */ - if (!strcmp(trndir+trnlen-2,".]")) { + if (strEQ(trndir+trnlen-2,".]")) { my_strlcpy(buf, dir, VMS_MAXRSS); strcat(buf, ":[000000]"); PerlMem_free(trndir); @@ -7652,15 +7652,13 @@ slash_dev_special_to_vms(const char *unixptr, char *vmspath, int vmspath_len) { char * nextslash; int len; - int cmp; unixptr += 4; nextslash = strchr(unixptr, '/'); len = strlen(unixptr); if (nextslash != NULL) len = nextslash - unixptr; - cmp = strncmp("null", unixptr, 5); - if (cmp == 0) { + if (strEQ(unixptr, "null")) { if (vmspath_len >= 6) { strcpy(vmspath, "_NLA0:"); return SS$_NORMAL; @@ -7816,7 +7814,6 @@ posix_to_vmsspec_hardway(char *vmspath, int vmspath_len, const char *unixpath, &vs_len); while (sts == 0) { - int cmp; /* A logical name must be a directory or the full specification. It is only a full specification if @@ -7864,8 +7861,7 @@ posix_to_vmsspec_hardway(char *vmspath, int vmspath_len, const char *unixpath, /* This should not be there, but nothing is perfect */ if (r_len > 9) { - cmp = strcmp(&r_spec[1], "000000."); - if (cmp == 0) { + if (strEQ(&r_spec[1], "000000.")) { r_spec += 7; r_spec[7] = '['; r_len -= 7; @@ -7886,8 +7882,7 @@ posix_to_vmsspec_hardway(char *vmspath, int vmspath_len, const char *unixpath, d_spec[0] = '['; d_spec[d_len - 1] = ']'; if (d_len > 9) { - cmp = strcmp(&d_spec[1], "000000."); - if (cmp == 0) { + if (strEQ(&d_spec[1], "000000.")) { d_spec += 7; d_spec[7] = '['; d_len -= 7; @@ -8025,10 +8020,8 @@ posix_to_vmsspec_hardway(char *vmspath, int vmspath_len, const char *unixpath, dir_start = 1; dir_dot = 1; if (vmslen > 7) { - int cmp; rptr = vmsptr - 7; - cmp = strcmp(rptr,"000000."); - if (cmp == 0) { + if (strEQ(rptr,"000000.")) { vmslen -= 7; vmsptr -= 7; vmsptr[1] = '\0'; @@ -8073,22 +8066,18 @@ posix_to_vmsspec_hardway(char *vmspath, int vmspath_len, const char *unixpath, } else { int trnend; - int cmp; /* now we have foo:bar or foo:[000000]bar to decide from */ islnm = vmstrnenv(vmspath, esa, 0, fildev, 0); if (!islnm && !decc_posix_compliant_pathnames) { - - cmp = strncmp("bin", vmspath, 4); - if (cmp == 0) { + if (strEQ(vmspath, "bin")) { /* bin => SYS$SYSTEM: */ islnm = vmstrnenv("SYS$SYSTEM:", esa, 0, fildev, 0); } else { /* tmp => SYS$SCRATCH: */ - cmp = strncmp("tmp", vmspath, 4); - if (cmp == 0) { + if (strEQ(vmspath, "tmp")) { islnm = vmstrnenv("SYS$SCRATCH:", esa, 0, fildev, 0); } } @@ -8570,13 +8559,13 @@ int_tovmsspec(const char *path, char *rslt, int dir_flag, int * utf8_flag) /* DECC special handling */ if (!islnm) { - if (strcmp(rslt,"bin") == 0) { + if (strEQ(rslt,"bin")) { strcpy(rslt,"sys$system"); cp1 = rslt + 10; *cp1 = 0; islnm = simple_trnlnm(rslt,trndev,VMS_MAXRSS-1); } - else if (strcmp(rslt,"tmp") == 0) { + else if (strEQ(rslt,"tmp")) { strcpy(rslt,"sys$scratch"); cp1 = rslt + 11; *cp1 = 0; @@ -8590,7 +8579,7 @@ int_tovmsspec(const char *path, char *rslt, int dir_flag, int * utf8_flag) while (*(cp2+1) == '/') cp2++; /* Skip multiple /s */ islnm = simple_trnlnm(rslt,trndev,VMS_MAXRSS-1); } - else if (strcmp(rslt,"dev") == 0) { + else if (strEQ(rslt,"dev")) { if (strncmp(cp2,"/null", 5) == 0) { if ((cp2[5] == 0) || (cp2[5] == '/')) { strcpy(rslt,"NLA0"); @@ -9184,7 +9173,7 @@ mp_getredirection(pTHX_ int *ac, char ***av) * subprocess, so we satisfy that desire. */ ap = argv[argc-1]; - if (0 == strcmp("&", ap)) + if (strEQ(ap, "&")) exit(background_process(aTHX_ --argc, argv)); if (*ap && '&' == ap[strlen(ap)-1]) { @@ -9197,7 +9186,7 @@ mp_getredirection(pTHX_ int *ac, char ***av) */ for (j = 0; j < argc; ++j) { - if (0 == strcmp("<", argv[j])) + if (strEQ(argv[j], "<")) { if (j+1 >= argc) { @@ -9212,7 +9201,7 @@ mp_getredirection(pTHX_ int *ac, char ***av) in = 1 + ap; continue; } - if (0 == strcmp(">", ap)) + if (strEQ(ap, ">")) { if (j+1 >= argc) { @@ -9263,7 +9252,7 @@ mp_getredirection(pTHX_ int *ac, char ***av) } continue; } - if (0 == strcmp("|", argv[j])) + if (strEQ(argv[j], "|")) { if (j+1 >= argc) { @@ -9349,7 +9338,7 @@ mp_getredirection(pTHX_ int *ac, char ***av) if (out != NULL) vmssetuserlnm("SYS$OUTPUT", out); if (err != NULL) { - if (strcmp(err,"&1") == 0) { + if (strEQ(err, "&1")) { dup2(fileno(stdout), fileno(stderr)); vmssetuserlnm("SYS$ERROR", "SYS$OUTPUT"); } else { @@ -10761,12 +10750,13 @@ setup_cmddsc(pTHX_ const char *incmd, int check_img, int *suggest_quote, shebang_len = 2; #ifdef ALTERNATE_SHEBANG else { - shebang_len = strlen(ALTERNATE_SHEBANG); - if (strncmp(b, ALTERNATE_SHEBANG, shebang_len) == 0) { + if (strEQ(b, ALTERNATE_SHEBANG)) { char * perlstr; perlstr = strstr("perl",b); if (perlstr == NULL) shebang_len = 0; + else + shebang_len = strlen(ALTERNATE_SHEBANG); } else shebang_len = 0; diff --git a/win32/win32.c b/win32/win32.c index 2e82c53462..f41ce6db8c 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -348,8 +348,8 @@ get_emd_part(SV **prev_pathp, STRLEN *const len, char *trailing_path, ...) if (!ptr || stricmp(ptr+1, strip) != 0) { /* ... but not if component matches m|5\.$patchlevel.*| */ if (!ptr || !(*strip == '5' && *(ptr+1) == '5' - && strncmp(strip, base, baselen) == 0 - && strncmp(ptr+1, base, baselen) == 0)) + && strnEQ(strip, base, baselen) + && strnEQ(ptr+1, base, baselen))) { *optr = '/'; ptr = optr; @@ -1832,7 +1832,7 @@ win32_getenv(const char *name) char *end = strchr(cur,'='); if (end && end != cur) { *end = '\0'; - if (!strcmp(cur,name)) { + if (strEQ(cur,name)) { curitem = sv_2mortal(newSVpv(end+1,0)); *end = '='; break; diff --git a/win32/wince.c b/win32/wince.c index 045853779a..0758595240 100644 --- a/win32/wince.c +++ b/win32/wince.c @@ -196,8 +196,8 @@ get_emd_part(SV **prev_pathp, STRLEN *const len, char *trailing_path, ...) if (!ptr || stricmp(ptr+1, strip) != 0) { /* ... but not if component matches m|5\.$patchlevel.*| */ if (!ptr || !(*strip == '5' && *(ptr+1) == '5' - && strncmp(strip, base, baselen) == 0 - && strncmp(ptr+1, base, baselen) == 0)) + && strnEQ(strip, base, baselen) + && strnEQ(ptr+1, base, baselen))) { *optr = '/'; ptr = optr; -- Perl5 Master Repository