Skip to content

Commit 276888a

Browse files
authored
Merge pull request #122 from JRaspass/master
Minor XS simplifications
2 parents 629bb67 + ef97f35 commit 276888a

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

DBI.xs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ typedef struct dbi_ima_st {
200200
(SvOK(state) /* SQLSTATE is implemented by driver */ \
201201
? (strEQ(SvPV_nolen(state),"00000") ? &PL_sv_no : sv_mortalcopy(state))\
202202
: (SvTRUE(DBIc_ERR(imp_xxh)) \
203-
? sv_2mortal(newSVpv("S1000",5)) /* General error */ \
203+
? sv_2mortal(newSVpvs("S1000")) /* General error */ \
204204
: &PL_sv_no) /* Success ("00000") */ \
205205
)
206206

@@ -425,7 +425,7 @@ _join_hash_sorted(HV *hash, char *kv_sep, STRLEN kv_sep_len, char *pair_sep, STR
425425

426426
keys = _sort_hash_keys(hash, num_sort, &total_len);
427427
if (!keys)
428-
return newSVpv("", 0);
428+
return newSVpvs("");
429429

430430
if (!kv_sep_len)
431431
kv_sep_len = strlen(kv_sep);
@@ -446,7 +446,7 @@ _join_hash_sorted(HV *hash, char *kv_sep, STRLEN kv_sep_len, char *pair_sep, STR
446446

447447
if (!hash_svp) { /* should never happen */
448448
warn("No hash entry with key '%s'", keys[i]);
449-
sv_catpvn(return_sv, "???", 3);
449+
sv_catpvs(return_sv, "???");
450450
continue;
451451
}
452452

@@ -457,11 +457,11 @@ _join_hash_sorted(HV *hash, char *kv_sep, STRLEN kv_sep_len, char *pair_sep, STR
457457
if (SvOK(*hash_svp)) {
458458
STRLEN hv_val_len;
459459
char *hv_val = SvPV(*hash_svp, hv_val_len);
460-
sv_catpvn(return_sv, "'", 1);
460+
sv_catpvs(return_sv, "'");
461461
sv_catpvn(return_sv, hv_val, hv_val_len);
462-
sv_catpvn(return_sv, "'", 1);
462+
sv_catpvs(return_sv, "'");
463463
}
464-
else sv_catpvn(return_sv, "undef", 5);
464+
else sv_catpvs(return_sv, "undef");
465465
}
466466

467467
if (i < hv_len-1)
@@ -612,14 +612,14 @@ neatsvpv(SV *sv, STRLEN maxlen) /* return a tidy ascii value, for debugging only
612612
if (SvMAGICAL(sv)) {
613613
if (DBIS_TRACE_LEVEL >= 5) { /* add magic details to help debugging */
614614
MAGIC* mg;
615-
infosv = sv_2mortal(newSVpv(" (magic-",0));
616-
if (SvSMAGICAL(sv)) sv_catpvn(infosv,"s",1);
617-
if (SvGMAGICAL(sv)) sv_catpvn(infosv,"g",1);
618-
if (SvRMAGICAL(sv)) sv_catpvn(infosv,"r",1);
619-
sv_catpvn(infosv,":",1);
615+
infosv = sv_2mortal(newSVpvs(" (magic-"));
616+
if (SvSMAGICAL(sv)) sv_catpvs(infosv, "s");
617+
if (SvGMAGICAL(sv)) sv_catpvs(infosv, "g");
618+
if (SvRMAGICAL(sv)) sv_catpvs(infosv, "r");
619+
sv_catpvs(infosv, ":");
620620
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
621621
sv_catpvn(infosv, &mg->mg_type, 1);
622-
sv_catpvn(infosv, ")", 1);
622+
sv_catpvs(infosv, ")");
623623
}
624624
if (SvGMAGICAL(sv) && !PL_dirty)
625625
mg_get(sv); /* trigger magic to FETCH the value */
@@ -689,7 +689,7 @@ neatsvpv(SV *sv, STRLEN maxlen) /* return a tidy ascii value, for debugging only
689689
SvGROW(nsv, (1+maxlen+1+1));
690690
sv_setpvn(nsv, quote, 1);
691691
sv_catpvn(nsv, v, maxlen-3); /* account for three dots */
692-
sv_catpvn(nsv, "...", 3);
692+
sv_catpvs(nsv, "...");
693693
} else {
694694
SvGROW(nsv, (1+len+1+1));
695695
sv_setpvn(nsv, quote, 1);
@@ -720,7 +720,7 @@ copy_statement_to_parent(pTHX_ SV *h, imp_xxh_t *imp_xxh)
720720
if (parent && SvROK(parent)) {
721721
SV *tmp_sv = *hv_fetchs((HV*)SvRV(h), "Statement", 1);
722722
if (SvOK(tmp_sv))
723-
(void)hv_store((HV*)SvRV(parent), "Statement", 9, SvREFCNT_inc(tmp_sv), 0);
723+
(void)hv_stores((HV*)SvRV(parent), "Statement", SvREFCNT_inc(tmp_sv));
724724
}
725725
}
726726

@@ -771,7 +771,7 @@ set_err_sv(SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV *state, SV *method
771771
neatsvpv(method,0)
772772
);
773773
PUSHMARK(SP);
774-
XPUSHs(sv_2mortal(newRV_inc((SV*)DBIc_MY_H(imp_xxh))));
774+
mXPUSHs(newRV_inc((SV*)DBIc_MY_H(imp_xxh)));
775775
XPUSHs(err);
776776
XPUSHs(errstr);
777777
XPUSHs(state);
@@ -813,7 +813,7 @@ set_err_sv(SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV *state, SV *method
813813
if (SvTRUE(h_state) && SvTRUE(state) && strNE(SvPV_nolen(h_state), SvPV_nolen(state)))
814814
sv_catpvf(h_errstr, " [state was %s now %s]", SvPV_nolen(h_state), SvPV_nolen(state));
815815
if (strNE(SvPV_nolen(h_errstr), SvPV_nolen(errstr))) {
816-
sv_catpvn(h_errstr, "\n", 1);
816+
sv_catpvs(h_errstr, "\n");
817817
sv_catsv(h_errstr, errstr);
818818
}
819819
}
@@ -1484,7 +1484,7 @@ dbih_setup_handle(pTHX_ SV *orv, char *imp_class, SV *parent, SV *imp_datasv)
14841484
&& SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV
14851485
) {
14861486
/* XXX mirrors behaviour of dbih_set_attr_k() of Callbacks */
1487-
(void)hv_store((HV*)SvRV(h), "Callbacks", 9, newRV_inc(SvRV(*tmp_svp)), 0);
1487+
(void)hv_stores((HV*)SvRV(h), "Callbacks", newRV_inc(SvRV(*tmp_svp)));
14881488
DBIc_set(imp, DBIcf_Callbacks, 1);
14891489
}
14901490

@@ -1522,16 +1522,16 @@ dbih_setup_handle(pTHX_ SV *orv, char *imp_class, SV *parent, SV *imp_datasv)
15221522
switch (DBIc_TYPE(imp)) {
15231523
case DBIt_DB:
15241524
/* cache _inner_ handle, but also see quick_FETCH */
1525-
(void)hv_store((HV*)SvRV(h), "Driver", 6, newRV_inc(SvRV(parent)), 0);
1525+
(void)hv_stores((HV*)SvRV(h), "Driver", newRV_inc(SvRV(parent)));
15261526
(void)hv_fetchs((HV*)SvRV(h), "Statement", 1); /* store writable undef */
15271527
break;
15281528
case DBIt_ST:
15291529
DBIc_NUM_FIELDS((imp_sth_t*)imp) = -1;
15301530
/* cache _inner_ handle, but also see quick_FETCH */
1531-
(void)hv_store((HV*)SvRV(h), "Database", 8, newRV_inc(SvRV(parent)), 0);
1531+
(void)hv_stores((HV*)SvRV(h), "Database", newRV_inc(SvRV(parent)));
15321532
/* copy (alias) Statement from the sth up into the dbh */
15331533
tmp_svp = hv_fetchs((HV*)SvRV(h), "Statement", 1);
1534-
(void)hv_store((HV*)SvRV(parent), "Statement", 9, SvREFCNT_inc(*tmp_svp), 0);
1534+
(void)hv_stores((HV*)SvRV(parent), "Statement", SvREFCNT_inc(*tmp_svp));
15351535
break;
15361536
}
15371537
}
@@ -1586,7 +1586,7 @@ static int
15861586
dbih_dumpcom(pTHX_ imp_xxh_t *imp_xxh, const char *msg, int level)
15871587
{
15881588
dMY_CXT;
1589-
SV *flags = sv_2mortal(newSVpv("",0));
1589+
SV *flags = sv_2mortal(newSVpvs(""));
15901590
SV *inner;
15911591
static const char pad[] = " ";
15921592
if (!msg)
@@ -1834,7 +1834,7 @@ dbih_get_fbav(imp_sth_t *imp_sth)
18341834
"0", 0, "Number of row fields inconsistent with NUM_OF_FIELDS (driver bug)", "", "_get_fbav");
18351835
/*
18361836
DBIc_NUM_FIELDS(imp_sth) = i;
1837-
hv_delete((HV*)SvRV(sth), "NUM_OF_FIELDS", 13, G_DISCARD);
1837+
hv_deletes((HV*)SvRV(sth), "NUM_OF_FIELDS", G_DISCARD);
18381838
*/
18391839
}
18401840
/* don't let SvUTF8 flag persist from one row to the next */
@@ -2151,14 +2151,14 @@ dbih_set_attr_k(SV *h, SV *keysv, int dbikey, SV *valuesv)
21512151
dSP;
21522152
I32 returns;
21532153
TAINT_NOT; /* the require is presumed innocent till proven guilty */
2154-
perl_require_pv("DBI/Profile.pm");
2154+
require_pv("DBI/Profile.pm");
21552155
if (SvTRUE(ERRSV)) {
21562156
warn("Can't load %s: %s", profile_class, SvPV_nolen(ERRSV));
21572157
valuesv = &PL_sv_undef;
21582158
}
21592159
else {
21602160
PUSHMARK(SP);
2161-
XPUSHs(sv_2mortal(newSVpv(profile_class,0)));
2161+
mXPUSHs(newSVpv(profile_class, 0));
21622162
XPUSHs(valuesv);
21632163
PUTBACK;
21642164
returns = call_method("_auto_new", G_SCALAR);
@@ -2173,7 +2173,7 @@ dbih_set_attr_k(SV *h, SV *keysv, int dbikey, SV *valuesv)
21732173
if (on && !sv_isobject(valuesv)) {
21742174
/* not blessed already - so default to DBI::Profile */
21752175
HV *stash;
2176-
perl_require_pv(profile_class);
2176+
require_pv(profile_class);
21772177
stash = gv_stashpv(profile_class, GV_ADDWARN);
21782178
sv_bless(valuesv, stash);
21792179
}
@@ -2752,14 +2752,14 @@ log_where(SV *buf, int append, char *prefix, char *suffix, int show_line, int sh
27522752
dTHX;
27532753
dTHR;
27542754
if (!buf)
2755-
buf = sv_2mortal(newSVpv("",0));
2755+
buf = sv_2mortal(newSVpvs(""));
27562756
else if (!append)
27572757
sv_setpv(buf,"");
27582758
if (CopLINE(PL_curcop)) {
27592759
COP *cop;
27602760
dbi_caller_string(buf, PL_curcop, prefix, show_line, show_path);
27612761
if (show_caller && (cop = dbi_caller_cop())) {
2762-
SV *via = sv_2mortal(newSVpv("",0));
2762+
SV *via = sv_2mortal(newSVpvs(""));
27632763
dbi_caller_string(via, cop, prefix, show_line, show_path);
27642764
sv_catpvf(buf, " via %s", SvPV_nolen(via));
27652765
}
@@ -2938,7 +2938,7 @@ dbi_profile(SV *h, imp_xxh_t *imp_xxh, SV *statement_sv, SV *method, NV t1, NV t
29382938
EXTEND(SP, 4);
29392939
PUSHMARK(SP);
29402940
PUSHs(h); /* push inner handle, then others params */
2941-
PUSHs( sv_2mortal(newSVpv(method_pv,0)));
2941+
mPUSHs(newSVpv(method_pv, 0));
29422942
PUTBACK;
29432943
SAVE_DEFSV; /* local($_) = $statement */
29442944
DEFSV_set(statement_sv);
@@ -2983,7 +2983,7 @@ dbi_profile(SV *h, imp_xxh_t *imp_xxh, SV *statement_sv, SV *method, NV t1, NV t
29832983
else if (isGV(method)) {
29842984
/* just using SvPV_nolen(method) sometimes causes an error: */
29852985
/* "Can't coerce GLOB to string" so we use gv_efullname() */
2986-
SV *tmpsv = sv_2mortal(newSVpv("",0));
2986+
SV *tmpsv = sv_2mortal(newSVpvs(""));
29872987
gv_efullname4(tmpsv, (GV*)method, "", TRUE);
29882988
p = SvPV_nolen(tmpsv);
29892989
if (*p == '*') ++p; /* skip past leading '*' glob sigil */
@@ -3415,7 +3415,7 @@ XS(XS_DBI_dispatch)
34153415
keep_error = TRUE;
34163416
if (ima_flags & IMA_CLEAR_STMT) {
34173417
/* don't use SvOK_off: dbh's Statement may be ref to sth's */
3418-
(void)hv_store((HV*)SvRV(h), "Statement", 9, &PL_sv_undef, 0);
3418+
(void)hv_stores((HV*)SvRV(h), "Statement", &PL_sv_undef);
34193419
}
34203420
if (ima_flags & IMA_CLEAR_CACHED_KIDS)
34213421
clear_cached_kids(aTHX_ h, imp_xxh, meth_name, trace_flags);
@@ -3719,7 +3719,7 @@ XS(XS_DBI_dispatch)
37193719
imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh), "func", FALSE);
37203720
if (imp_msv) {
37213721
/* driver does have func method so undo the earlier 'func' stack changes */
3722-
PUSHs(sv_2mortal(newSVpv(meth_name,0)));
3722+
mPUSHs(newSVpv(meth_name, 0));
37233723
PUTBACK;
37243724
++items;
37253725
meth_name = "func";
@@ -3925,7 +3925,7 @@ XS(XS_DBI_dispatch)
39253925
/* and may mess up the error handling below for the commit/rollback */
39263926
PUSHMARK(SP);
39273927
XPUSHs(h);
3928-
XPUSHs(sv_2mortal(newSVpv("AutoCommit",0)));
3928+
mXPUSHs(newSVpvs("AutoCommit"));
39293929
XPUSHs(&PL_sv_yes);
39303930
PUTBACK;
39313931
call_method("STORE", G_VOID);
@@ -4082,7 +4082,7 @@ XS(XS_DBI_dispatch)
40824082
);
40834083
PUSHMARK(SP);
40844084
XPUSHs(msg);
4085-
XPUSHs(sv_2mortal(newRV_inc((SV*)DBIc_MY_H(imp_xxh))));
4085+
mXPUSHs(newRV_inc((SV*)DBIc_MY_H(imp_xxh)));
40864086
XPUSHs( result );
40874087
PUTBACK;
40884088
items = call_sv(*hook_svp, G_SCALAR);
@@ -4605,7 +4605,7 @@ _new_handle(class, parent, attr_ref, imp_datasv, imp_class)
46054605
PERL_UNUSED_VAR(cv);
46064606
}
46074607

4608-
(void)hv_store((HV*)SvRV(attr_ref), "ImplementorClass", 16, SvREFCNT_inc(imp_class), 0);
4608+
(void)hv_stores((HV*)SvRV(attr_ref), "ImplementorClass", SvREFCNT_inc(imp_class));
46094609

46104610
/* make attr into inner handle by blessing it into class */
46114611
sv_bless(attr_ref, class_stash);
@@ -4711,7 +4711,7 @@ _install_method(dbi_class, meth_name, file, attribs=Nullsv)
47114711
{
47124712
dMY_CXT;
47134713
/* install another method name/interface for the DBI dispatcher */
4714-
SV *trace_msg = (DBIS_TRACE_LEVEL >= 10) ? sv_2mortal(newSVpv("",0)) : Nullsv;
4714+
SV *trace_msg = (DBIS_TRACE_LEVEL >= 10) ? sv_2mortal(newSVpvs("")) : Nullsv;
47154715
CV *cv;
47164716
SV **svp;
47174717
dbi_ima_t *ima;
@@ -5576,8 +5576,7 @@ set_err(h, err, errstr=&PL_sv_no, state=&PL_sv_undef, method=&PL_sv_undef, resul
55765576
}
55775577
else
55785578
(void)SvOK_off(*sem_svp);
5579-
EXTEND(SP, 1);
5580-
PUSHs( result ? result : &PL_sv_undef );
5579+
XPUSHs( result ? result : &PL_sv_undef );
55815580
}
55825581
/* We don't check RaiseError and call die here because that must be */
55835582
/* done by returning through dispatch and letting the DBI handle it */

0 commit comments

Comments
 (0)