Amar Deep Singh <[EMAIL PROTECTED]> writes:
>Hi
>
>I am calling a C subroutine from Perl. The "*argv_ptr" if the global @ARGV
>is perl.
>I am passing the pointer to this to the C which does some manipulations and
>removes some of the arguments in @ARGV.
>But it seems the values returned are not the same which I want.
>
>Any idea how I can push the values of "args_av" back into "argv_ptr".
>I am pushing back the values in "args_av" but its not working. Any idea if I
>am missing something.
>In simple words I want the modified values of c_args to be put into @ARGV,
>which is nothing but the pointer "argv_ptr"

@ARGV is an AV not just an SV ** - you need to get the AV and call 
av_push() etc. to keep length in sync.



>
>Thanks
>Amar
>
>Here is the code in xs. which i call from Perl as return
>_Initialise($config, $0, \@ARGV);
>
>============================================================================
>=============
>int D_Initialise(config, appname, argv_ptr)
>    Configuration config
>    char *appname
>    SV *argv_ptr
>    CODE:
>    {
>        int argc, i, str_length;
>        char **c_args;
>        char *arg;
>        SV *tmpSV;
>        AV *args_av, *ret_args;
>
>        /* dereference the argv */
>        args_av = (AV*) SvRV(argv_ptr);
>
>        /* get the number of arguments */
>        argc = av_len(args_av) + 1;
>
>        /* allocate enough memory */
>        c_args = (char **) malloc((argc + 1) * sizeof(char *));
>
>        /* copy the appname into the c_args array */
>        c_args[0] = (char *) malloc((strlen(appname) + 1) * sizeof(char));
>
>        /* copy the contents of the argv ref */
>        for(i = 0; i < argc; i++) {
>            /* get the string */
>            tmpSV = av_shift(args_av);
>            arg = (char *) SvPV(tmpSV, str_length);
>            c_args[i + 1] = (char *) malloc((str_length + 1) *
>sizeof(char));
>            strcpy(c_args[i + 1], arg);
>        }
>
>        /* now call the proper Initialise */
>        RETVAL = Initialise(config, &c_args, &argc);
>
>        /* put the arguments back */
>        for(i = 0; i < argc; i++) {
>            av_unshift(args_av, 1);
>            av_store(args_av, i, (SV *) newSVpv(c_args[i], 0));
>        }
>    }
>    OUTPUT:
>    argv_ptr
>    RETVAL
>============================================================================
>=============
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/

Reply via email to