Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real argc and argv in embedded interpreter #59782

Closed
nordaux mannequin opened this issue Aug 7, 2012 · 7 comments
Closed

Real argc and argv in embedded interpreter #59782

nordaux mannequin opened this issue Aug 7, 2012 · 7 comments
Labels
3.9 only security fixes extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@nordaux
Copy link
Mannequin

nordaux mannequin commented Aug 7, 2012

BPO 15577
Nosy @abalkin, @vstinner, @dvarrazzo, @encukou, @ericsnowcurrently
Superseder
  • bpo-23427: Add sys.orig_argv: original command line arguments passed to the Python executable
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-09-26.00:44:19.457>
    created_at = <Date 2012-08-07.20:38:29.739>
    labels = ['extension-modules', 'interpreter-core', 'type-feature', '3.9']
    title = 'Real argc and argv in embedded interpreter'
    updated_at = <Date 2020-06-08.17:25:56.658>
    user = 'https://bugs.python.org/nordaux'

    bugs.python.org fields:

    activity = <Date 2020-06-08.17:25:56.658>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-09-26.00:44:19.457>
    closer = 'vstinner'
    components = ['Extension Modules', 'Interpreter Core']
    creation = <Date 2012-08-07.20:38:29.739>
    creator = 'nordaux'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 15577
    keywords = []
    message_count = 7.0
    messages = ['167639', '222777', '353242', '370965', '370966', '371026', '371029']
    nosy_count = 6.0
    nosy_names = ['belopolsky', 'vstinner', 'piro', 'petr.viktorin', 'eric.snow', 'nordaux']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '23427'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue15577'
    versions = ['Python 3.9']

    @nordaux
    Copy link
    Mannequin Author

    nordaux mannequin commented Aug 7, 2012

    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.

    @nordaux nordaux mannequin added type-crash A hard crash of the interpreter, possibly with a core dump extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Aug 7, 2012
    @nordaux nordaux mannequin changed the title Real Argc Argv in embeded interpreter Real Argc Argv in embedded interpreter Aug 7, 2012
    @RamchandraApte RamchandraApte mannequin changed the title Real Argc Argv in embedded interpreter Real argc and argv in embedded interpreter Aug 8, 2012
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 11, 2014

    Without a patch this issue will go nowhere. I'm assuming that this limitation must have been overcome by other projects using embedded Python. Has anybody got any ideas as to how, I certainly haven't?

    @BreamoreBoy BreamoreBoy mannequin added type-feature A feature request or enhancement and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 11, 2014
    @vstinner
    Copy link
    Member

    I only saw one request (this issue) for this feature, in 2012. So it doesn't sound really important. I close the issue.

    @encukou
    Copy link
    Member

    encukou commented Jun 8, 2020

    FWIW, another project that needs Py_GetArgcArgv is "setproctitle": https://bugzilla.redhat.com/show_bug.cgi?id=1792059

    See also: cherrypy/cherrypy#1506

    @dvarrazzo
    Copy link
    Mannequin

    dvarrazzo mannequin commented Jun 8, 2020

    Py_GetArgcArgv gone broke setproctitle indeed.

    dvarrazzo/py-setproctitle#76

    Is there a way to get the same feature in 3.9 or should setproctitle become no-op from 3.9 on and Python loses this feature?

    Thank you.

    @dvarrazzo dvarrazzo mannequin added the 3.9 only security fixes label Jun 8, 2020
    @vstinner
    Copy link
    Member

    vstinner commented Jun 8, 2020

    I mark this issue as a duplicate of bpo-23427.

    @vstinner
    Copy link
    Member

    vstinner commented Jun 8, 2020

    See also bpo-40910: "Py_GetArgcArgv() is no longer exported by the C API".

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants