I'm trying to call a Perl sub from a C function using stacks to pass
arguments to and return variables from the Perl sub.  Here's a simplified
version of my code.  Can anyone tell me why it bombs and dumps core (on my
machine, at least)?



use Inline 'C';

interface();

sub Perl_sub { return "str_$_[0]" }

__DATA__
__C__

void C_function(double num, char* str);

void interface()
{
    double num;

    char str[30];

    /* this runs fine */
    num = 3.0;
    C_function(num, str);
    fprintf(stderr, "(%f, %s)\n\n", num, str);

    /* this dumps core */
    num = 4.0;
    C_function(num, str);
    fprintf(stderr, "(%f, %s)\n\n", num, str);
}

void C_function(double num, char* str)
{
    Inline_Stack_Vars;

    char ret[30];

    Inline_Stack_Reset;
    Inline_Stack_Push(newSVnv(num));
    Inline_Stack_Push(newSVpvn(str, strlen(str)));
    Inline_Stack_Done;

    call_pv("Perl_sub", G_SCALAR);

    strcpy(ret, SvPV(Inline_Stack_Item(0), PL_na));
    strcpy(str, ret);

    Inline_Stack_Void;
}




Thanks,

Brett Denner

-- 
 Brett W. Denner                    Lockheed Martin Aeronautics Co.
 email: [EMAIL PROTECTED]     PO Box 748, MZ 9332
 phone: 817-935-1144                Fort Worth, TX 76101
 fax:   817-935-1212

Reply via email to