hacker has asked for the wisdom of the Perl Monks concerning the following question:

This is currently an open bug in a piece of software called pilot-link that I maintain. The package (written in C) comes bundled with Perl bindings (as well as Python, Tcl, and Java bindings) which use XS to link to a shared library that provides the low-level functions. I can't seem to figure out why this particular snippet of perl fails when outputting this one character. Here is the code:
#!/usr/bin/perl use strict; use diagnostics; use warnings; use Carp 'verbose'; use PDA::Pilot; # part of pilot-link, not in CPAN # it's the last value which makes the program fail; # and it fails only for the value 11! my @rec = (0,0,0,0,0,0,0,0,11); my %info = ("type" =>"Data", "creator" =>"XXXX", "name" =>"test"); my $pdb = PDA::Pilot::File::create("test.pdb", \%info ) or die "something went wrong\n"; my $rec = join('', map(chr, @rec)); # It dies here, line 23 $pdb->addRecordRaw($rec,0,0,0);

The error that I'm getting (and ONLY when I use '11' as that last value) is:

Can't call method "Raw" without a package or object reference

If I change that '11' to any other value, it works without a hitch, no errors or warnings.

The function that is being called (found in Pilot.xs) is as follows:

int addRecordRaw(self, data, uid, attr, category) PDA::Pilot::File *self SV *data unsigned long uid int attr int category CODE: { STRLEN len; int result; void *buf; PackRaw; buf = SvPV(data, len); RETVAL = pi_file_append_record(self->pf, buf, len, attr, category, uid); } OUTPUT: RETVAL

The relevant subroutine, 'Raw', is in Pilot.pm, and is as follows:

sub Raw { # Just copy the "raw" item straight through my($self) = @_; return $self->{raw}; }

What am I missing here?

Replies are listed 'Best First'.
Re: Odd behavior with a "vertical tab" character
by Courage (Parson) on Nov 05, 2002 at 18:11 UTC
    Not that I am ready to catch your error (please show a place where your subroutine "Raw" is called), just a few thoughts:
    1. did you checked that your uid, attr, category are in correct order? I noticed that different subs have different order for them. This will not directly cause sympthoms you described, but I thought may be you did a typo here?
    2. please show a place where your "Raw" method is called (as I already mentioned)

    Best wishes,
    Courage, the Cowardly Dog

      I'm not calling "Raw" directly in my code, but here is the relevant structure from Pilot.xs itself:
      #define PackRaw\ {\ HV * h;\ if (SvRV(data) &&\ (SvTYPE(h=(HV*)SvRV(data))==SVt_PVHV)) {\ int count;\ PUSHMARK(sp);\ XPUSHs(data);\ PUTBACK;\ count = perl_call_method("Raw", G_SCALAR);\ SPAGAIN;\ if (count != 1) {\ SV ** s = hv_fetch(h, "raw", 3, 0);\ if (s)\ data = *s;\ } else {\ data = POPs;\ PUTBACK;\ }\ }\ }
        While I am not ready to point you to an exact place of an error (and do not expect me to, as we still have not enough information), but several notes I will do in my humble tries to step forward.
        1. "perl_call_method" call is 100% not portable between different installations of perl, you should use "call_method" and let "perl.h" to correctly prefix it. You're in danger of facing hard-to-fix errors if you're just following requests of your linker.
        2. Is your extra PUTBACK; at the very end of "PackRaw" macro is intentional?
        3. (most important point) As logic says, your code should not call "Raw" method at all, because your macro first checks for "SvRV" and will not suffice for sure. Is there any other place where your "Raw" method is called? Can you output a call trace?

        Courage, the Cowardly Dog