in reply to Perl XS - is this code required in DBD::Pg?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl XS - is this code required in DBD::Pg? (cruft)
by ikegami (Patriarch) on Jul 21, 2010 at 18:39 UTC | |
by tye (Sage) on Jul 21, 2010 at 19:01 UTC | |
by mje (Curate) on Jul 21, 2010 at 19:06 UTC | |
|
Re^2: Perl XS - is this code required in DBD::Pg? (cruft)
by mje (Curate) on Jul 21, 2010 at 19:03 UTC | |
by tye (Sage) on Jul 21, 2010 at 19:14 UTC | |
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 | |
by mje (Curate) on Jul 21, 2010 at 19:19 UTC |