Skip to content

[Enhancement] Support Python 3.9.x #3

@amal-khailtash

Description

@amal-khailtash

There are two issues to support latest version of Python. Python header include is hard-coded:

     PyScModule.cpp:9:30: fatal error: python3.6/Python.h: No such file or directory
9:   #include <python3.6/Python.h>

Changing it to the following makes this independent of Python version:

9:     #include <Python.h>

In PyScModule constructor, I get the following warnings:

    PyScModule.cpp: In constructor ‘scc::PyScModule::PyScModule(PyObject*, const sc_core::sc_module_name&)’:
    PyScModule.cpp:22:11: warning: ‘int PyEval_ThreadsInitialized()’ is deprecated (declared at /opt/tools/wh/dtd/RHE64-7/python/3.9.2/include/python3.9/ceval.h:129) [-Wdeprecated-declarations]
         if (! PyEval_ThreadsInitialized())
               ^
    PyScModule.cpp:22:37: warning: ‘int PyEval_ThreadsInitialized()’ is deprecated (declared at /opt/tools/wh/dtd/RHE64-7/python/3.9.2/include/python3.9/ceval.h:129) [-Wdeprecated-declarations]
         if (! PyEval_ThreadsInitialized())
                                         ^
    PyScModule.cpp:23:9: warning: ‘void PyEval_InitThreads()’ is deprecated (declared at /opt/tools/wh/dtd/RHE64-7/python/3.9.2/include/python3.9/ceval.h:130) [-Wdeprecated-declarations]
             PyEval_InitThreads();
             ^
    PyScModule.cpp:23:28: warning: ‘void PyEval_InitThreads()’ is deprecated (declared at /opt/tools/wh/dtd/RHE64-7/python/3.9.2/include/python3.9/ceval.h:130) [-Wdeprecated-declarations]
             PyEval_InitThreads();

PyEval_InitThreads is deprecated since 3.9 and "Changed in version 3.9: The function now does nothing."
https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads

Changing the constructor to the following would get rid of the problem.

scc::PyScModule::PyScModule(PyObject*  self, const sc_core::sc_module_name& nm)
: sc_core::sc_module(nm)
, self(self)
{
#if PY_MAJOR_VERSION < 3 || PY_MINOR_VERSION < 7
    if (! PyEval_ThreadsInitialized())
        PyEval_InitThreads();
#endif
    Py_INCREF(self);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions