Thelonius has asked for the wisdom of the Perl Monks concerning the following question:
So, what I coded after several tries is:
This works, but is it the right thing to do? I put in the check for SvREADONLY thinking the user might put in "undef" as a placeholder.void hperrmsg(displaycode,...) int displaycode PROTOTYPE: $;@ PREINIT: int depth=0; int errornum=0; SV *buffer=NULL; char *pbuf; short buflength=0; int status=0; int parm_ct; CODE: /* ... other items omitted for clarity */ if (items > 4) { buffer = ST(4); } if (buffer == NULL || SvREADONLY(buffer)) { pbuf = NULL; } else { int tmplen=buflength+1; if (!SvPOK(buffer)) { SvPV_force(buffer, tmplen); } else { SvGROW(buffer+1, tmplen); } pbuf = SvPVX(buffer); } HPERRMSG(parm_ct, displaycode, depth, 0, errornum, pbuf, &buflength, &status); if (buflength) { pbuf[buflength] = '\0'; SvPOK_on(buffer); SvCUR_set(buffer, buflength); }
Any feedback?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XS help
by MZSanford (Curate) on Oct 17, 2001 at 12:40 UTC |