You should try passing in a \$buf instead of $buf (using both implementations).
The "char * buf" formal argument is misleading and is only ever used as an ordinary lexcial "char *" variable.
The PREINIT: line, SV * const bufsv = SvROK(ST(2)) ? SvRV(ST(2)) : ST(2); means that you can either pass in $buf to have it populated or pass in \$buf. It looks to me like the line you asked about is just wasteful in the case of passing in $buf. I think it actually breaks things if you pass in \$buf.
It smells like historical baggage. I'd rewrite the code like so:
pg_lo_read( dbh, fd, bufsv, len ) SV * dbh int fd SV * bufsv size_t len CODE: int ret; char * buf; if( SvROK(bufsv) ) { bufsv= SvRV(bufsv); } sv_setpvn(bufsv,"",0); /* Make sure we can grow it safely */ buf= SvGROW( bufsv, len + 1 ); ret= pg_db_lo_read( dbh, fd, buf, len ); if( 0 < ret ) { SvCUR_set( bufsv, ret ); *SvEND(bufsv)= '\0'; SvSETMAGIC( bufsv ); } ST(0)= 0 <= ret ? sv_2mortal(newSViv(ret)) : &PL_sv_undef;
- tye
In reply to Re: Perl XS - is this code required in DBD::Pg? (cruft)
by tye
in thread Perl XS - is this code required in DBD::Pg?
by mje
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |