in reply to Re^2: Perl XS - is this code required in DBD::Pg? (cruft)
in thread Perl XS - is this code required in DBD::Pg?
Heh, rereading the same basic code in your implementation made me realize that there is another minor bug. SvSETMAGIC() doesn't get called if the 'read' is successful but returns no data. That suggests the following simplification:
void odbc_lob_read(sth, colno, bufsv, length, attr = NULL) SV *sth int colno SV *bufsv UV length SV *attr; PROTOTYPE: $$$$;$ PREINIT: char *buf; UV ret_len; IV sql_type = 0; CODE: if (length == 0) { croak("Cannot retrieve 0 length lob"); } if (SvROK(bufsv)) { bufsv = SvRV(bufsv); } if (attr) { SV **svp; DBD_ATTRIBS_CHECK("odbc_lob_read", sth, attr); DBD_ATTRIB_GET_IV(attr, "Type", 4, svp, sql_type); } sv_setpvn(bufsv, "", 0); /* ensure we can grow +ok */ buf = SvGROW(bufsv, length + 1); ret_len = odbc_st_lob_read(sth, colno, bufsv, length, sql_type); if (ret_len < 0) { ST(0) = &PL_sv_undef; } else { SvCUR_set(bufsv, ret_len); /* set length in SV */ *SvEND(bufsv) = '\0'; /* NUL terminate */ SvSETMAGIC(bufsv); ST(0) = sv_2mortal(newSViv(ret_len)); } XSRETURN(1);
(Update: Added XSRETURN(1) after prompting in the chatterbox from ikegami.)
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl XS - is this code required in DBD::Pg? (empty)
by mje (Curate) on Jul 21, 2010 at 19:19 UTC | |
|
Re^4: Perl XS - is this code required in DBD::Pg? (empty)
by mje (Curate) on Jul 22, 2010 at 10:17 UTC | |
by tye (Sage) on Jul 22, 2010 at 21:06 UTC | |
by mje (Curate) on Jul 23, 2010 at 09:54 UTC |