This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nordaux
Recipients nordaux
Date 2012-08-07.20:38:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344371910.44.0.262957922939.issue15577@psf.upfronthosting.co.za>
In-reply-to
Content
I have found out certain peculiarity of interpreter in case it is embedded.
There is no way to reference to the real parameters argv, argc of main process from embedded python's C extensions.
When python is not embedded, it is task of function Py_Main, which sets the value of variables orig_argv, orig_argc.
These variables keep references to the original values of  argv, argc and give opportunity to manage them from the python C extensions if necessary.
I understand that the function Py_GetArgcArgv is rarely used, and this is true, but still believe that ability to manipulate these variables should be exist in any form of python from its C extension modules.
I tried different modules of C-extensions with such functional in embedded environment, but they all causes Segmentation Fault. The problem is not only in their implementation quality without any additional inspections, but also the function Py_GetArgcArgv doesn't additionally reported that its returned, and just ruturn null pointer in self argv parameter when used in embedded environment.
The following quote all the code that refers to this functionality in Python 2.7-3.3 at the moment:

/* For Py_GetArgcArgv(); set by main() */
static char **orig_argv;
static int  orig_argc;

..........................................................................................
/* Main program */

int
Py_Main(int argc, char **argv)
{
..........................................................................................
    orig_argc = argc;           /* For Py_GetArgcArgv() */
    orig_argv = argv;
..........................................................................................
}

void
Py_GetArgcArgv(int *argc, char ***argv)
{
    *argc = orig_argc;
    *argv = orig_argv;
}

Thats why I would like to suggest something similar to such function and use it in Py_Main and probably make it available from Python C API.
And also extend Py_GetArgcArgv with more detailed null pointer handling if variables orig_argv, orig_argc had not been initialized.

void
Py_InitArgcArgv(int *argc, char ***argv)
{
    if(! *argv) return -1;

    orig_argc = *argc;           /* For Py_GetArgcArgv() */
    orig_argv = *argv;

    return 0;   
}

Would like to see other suggestions.
Thanks.
History
Date User Action Args
2012-08-07 20:38:30nordauxsetrecipients: + nordaux
2012-08-07 20:38:30nordauxsetmessageid: <1344371910.44.0.262957922939.issue15577@psf.upfronthosting.co.za>
2012-08-07 20:38:29nordauxlinkissue15577 messages
2012-08-07 20:38:27nordauxcreate