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

Py_InitModule* is still referenced in docs #47967

Closed
erickt mannequin opened this issue Aug 28, 2008 · 6 comments
Closed

Py_InitModule* is still referenced in docs #47967

erickt mannequin opened this issue Aug 28, 2008 · 6 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@erickt
Copy link
Mannequin

erickt mannequin commented Aug 28, 2008

BPO 3717
Nosy @loewis, @birkenfeld, @amauryfa, @benjaminp
Files
  • embed.diff
  • 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 = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-10-17.15:55:15.301>
    created_at = <Date 2008-08-28.20:48:50.286>
    labels = ['docs']
    title = 'Py_InitModule* is still referenced in docs'
    updated_at = <Date 2008-10-17.15:55:15.300>
    user = 'https://bugs.python.org/erickt'

    bugs.python.org fields:

    activity = <Date 2008-10-17.15:55:15.300>
    actor = 'loewis'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-10-17.15:55:15.301>
    closer = 'loewis'
    components = ['Documentation']
    creation = <Date 2008-08-28.20:48:50.286>
    creator = 'erickt'
    dependencies = []
    files = ['11816']
    hgrepos = []
    issue_num = 3717
    keywords = ['patch', 'needs review']
    message_count = 6.0
    messages = ['72111', '72113', '72128', '74912', '74913', '74921']
    nosy_count = 6.0
    nosy_names = ['loewis', 'georg.brandl', 'amaury.forgeotdarc', 'idadesub', 'benjamin.peterson', 'erickt']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3717'
    versions = ['Python 3.0']

    @erickt
    Copy link
    Mannequin Author

    erickt mannequin commented Aug 28, 2008

    The docs still reference Py_InitModule*, which was removed in r64107.
    Also, Demo/embed/demo.c still use Py_InitModule, and thus doesn't
    compile.

    @erickt erickt mannequin assigned birkenfeld Aug 28, 2008
    @erickt erickt mannequin added the docs Documentation in the Doc dir label Aug 28, 2008
    @idadesub
    Copy link
    Mannequin

    idadesub mannequin commented Aug 28, 2008

    On Thu, Aug 28, 2008 at 1:48 PM, Erick Tryzelaar <report@bugs.python.org> wrote:

    New submission from Erick Tryzelaar <idadesub@users.sourceforge.net>:

    The docs still reference Py_InitModule*, which was removed in r64107.
    Also, Demo/embed/demo.c still use Py_InitModule, and thus doesn't
    compile.

    Here's a patch to get demo.c working, though it's acting a little
    strange. Printing out sys.argv results in japanese characters for some
    reason.

    Index: Demo/embed/demo.c
    ===================================================================
    --- Demo/embed/demo.c (revision 66055)
    +++ Demo/embed/demo.c (working copy)
    @@ -2,9 +2,9 @@

     #include "Python.h"

    -void initxyzzy(void); /* Forward */
    +PyObject* PyInit_xyzzy(void); /* Forward */

    -main(int argc, char **argv)
    +main(int argc, wchar_t **argv)
     {
     	/* Pass argv[0] to the Python interpreter */
     	Py_SetProgramName(argv[0]);
    @@ -13,7 +13,7 @@
     	Py_Initialize();
    /* Add a static module \*/
    
    • initxyzzy();
      + PyInit_xyzzy();

      /* Define sys.argv. It is up to the application if you
      want this; you can also let it undefined (since the Python
      @@ -26,10 +26,10 @@

     	/* Execute some Python statements (in module __main__) */
     	PyRun_SimpleString("import sys\n");
    -	PyRun_SimpleString("print sys.builtin_module_names\n");
    -	PyRun_SimpleString("print sys.modules.keys()\n");
    -	PyRun_SimpleString("print sys.executable\n");
    -	PyRun_SimpleString("print sys.argv\n");
    +	PyRun_SimpleString("print(sys.builtin_module_names)\n");
    +	PyRun_SimpleString("print(sys.modules.keys())\n");
    +	PyRun_SimpleString("print(sys.executable)\n");
    +	PyRun_SimpleString("print(sys.argv)\n");
    /* Note that you can call any public function of the Python
       interpreter here, e.g. call_object(). \*/
    

    @@ -57,9 +57,22 @@
    {NULL, NULL} /* sentinel */
    };

    -void
    -initxyzzy(void)
    +static struct PyModuleDef xyzzymodule = {
    +	{}, /* m_base */
    +	"xyzzy",  /* m_name */
    +	0,  /* m_doc */
    +	0,  /* m_size */
    +	xyzzy_methods,  /* m_methods */
    +	0,  /* m_reload */
    +	0,  /* m_traverse */
    +	0,  /* m_clear */
    +	0,  /* m_free */
    +};
    +
    +PyObject*
    +PyInit_xyzzy(void)
     {
    -	PyImport_AddModule("xyzzy");
    -	Py_InitModule("xyzzy", xyzzy_methods);
    +	PyObject* res = PyModule_Create(&xyzzymodule);
    +	if (!res) return NULL;
    +	return res;
     }

    With loop.c, there are issues with char*/wchar_t* and I'm not sure
    what the right approach is. Finally, importexc.c is segfaulting with:

    #0  0x0005b2f3 in PyDict_SetItem (op=0x0, key=0x44bed0,
    value=0x17d460) at Objects/dictobject.c:712
    #1  0x0005ee02 in PyDict_SetItemString (v=0x0, key=0x16e860
    "last_type", item=0x17d460) at Objects/dictobject.c:2090
    #2  0x0012c23a in PySys_SetObject (name=0x16e860 "last_type",
    v=0x17d460) at Python/sysmodule.c:67
    #3  0x00122c99 in PyErr_PrintEx (set_sys_last_vars=1) at Python/pythonrun.c:1254
    #4  0x001228bc in PyErr_Print () at Python/pythonrun.c:1150
    #5  0x001223a1 in PyRun_SimpleStringFlags (command=0x157b80 "import
    sys", flags=0x0) at Python/pythonrun.c:1075
    #6  0x0000243b in main () at importexc.c:13

    @amauryfa
    Copy link
    Member

    In your patch, it is not correct to declare main as
    main(int argc, wchar_t **argv)
    It is simply not the correct signature: the OS only supports "char** argv".

    You have to perform the conversion yourself. Look for example at
    Modules/python.c.

    The problem with importexc.c is more serious; I've filled bpo-3723 for
    this.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 17, 2008

    Here is a patch that makes Demo/embed compile and run successfully.

    @benjaminp
    Copy link
    Contributor

    Looks good to me.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 17, 2008

    Committed as r66961.

    @loewis loewis mannequin closed this as completed Oct 17, 2008
    @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
    docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants