Skip to content

Conversation

@vstinner
Copy link
Contributor

The Python binding cannot be loaded in Python 3.8: import libcomps
fails with:

Traceback (most recent call last):
  File "src/python/src/python3/libcomps/__init__.py", line 1, in <module>
    from ._libpycomps import *
SystemError: bad call flags

Fedora bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1734777

The problem are the following method descriptors of
libcomps/src/python/src/pycomps.c:

{"categories_match", (PyCFunction)PyCOMPS_categories_match, METH_KEYWORDS,
 PyCOMPS_validate__doc__},
{"environments_match", (PyCFunction)PyCOMPS_envs_match, METH_KEYWORDS,
 PyCOMPS_validate__doc__},

In Python 3.7, import didn't check descriptor flags (METH_KEYWORDS):
these flags were only checked when the methods were called.

In Python 3.8, the flags are checked at soon as the module is
imported, which prevents the module to be imported.

This change fix the two method descriptors.

The Python binding cannot be loaded in Python 3.8: import libcomps
fails with:

    Traceback (most recent call last):
      File "src/python/src/python3/libcomps/__init__.py", line 1, in <module>
        from ._libpycomps import *
    SystemError: bad call flags

Fedora bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1734777

The problem are the following method descriptors of
libcomps/src/python/src/pycomps.c:

    {"categories_match", (PyCFunction)PyCOMPS_categories_match, METH_KEYWORDS,
     PyCOMPS_validate__doc__},
    {"environments_match", (PyCFunction)PyCOMPS_envs_match, METH_KEYWORDS,
     PyCOMPS_validate__doc__},

In Python 3.7, import didn't check descriptor flags (METH_KEYWORDS):
these flags were only checked when the methods were called.

In Python 3.8, the flags are checked at soon as the module is
imported, which prevents the module to be imported.

This change fix the two method descriptors.
@Conan-Kudo Conan-Kudo merged commit dce9d5d into rpm-software-management:master Jul 31, 2019
@Conan-Kudo
Copy link
Member

Thanks for the patch, merged!

@hroncok
Copy link
Contributor

hroncok commented Aug 1, 2019

This indeed never worked before (Python 3.7 example):

>>> import libcomps
>>> c = libcomps.Comps()
>>> c.categories_match()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Bad call flags in _PyMethodDef_RawFastCallKeywords. METH_OLDARGS is no longer supported!

I wonder if this went unnoticed for so long - is this API even used anywhere?

carlwgeorge added a commit to carlwgeorge/py-leveldb that referenced this pull request Sep 8, 2019
Importing leveldb in Python 3.8 raises `SystemError: bad call flags`.
This is due to a change in Python where the method descriptor flags are
checked at import time, rather than when the methods are called.  This
change fixes the incorrect method description.

Adapted from @vstinner's fix for the same problem in libcomps.

rpm-software-management/libcomps#50
pbrezina added a commit to pbrezina/sssd that referenced this pull request Sep 11, 2019
To fix this error that happened during mockbuild on rawhide.

FAIL: src/tests/pysss-test.py3
==============================
ERROR: test_import (__main__.PysssImport)
Import the module and assert it comes from tree
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/builddir/build/BUILD/sssd-1.16.5/src/tests/pysss-test.py", line 56, in test_import
   import pysss
 SystemError: bad call flags

In Python 3.7, import didn't check descriptor flags (METH_KEYWORDS):
these flags were only checked when the methods were called.

In Python 3.8, the flags are checked as soon as the module is imported,
which prevents the module to be imported.

Inspired by:
rpm-software-management/libcomps#50

Python doc:
https://docs.python.org/3/c-api/structures.html#METH_VARARGS
pbrezina added a commit to pbrezina/sssd that referenced this pull request Sep 17, 2019
To fix this error that happened during mockbuild on rawhide.

FAIL: src/tests/pysss-test.py3
==============================
ERROR: test_import (__main__.PysssImport)
Import the module and assert it comes from tree
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/builddir/build/BUILD/sssd-1.16.5/src/tests/pysss-test.py", line 56, in test_import
   import pysss
 SystemError: bad call flags

In Python 3.7, import didn't check descriptor flags (METH_KEYWORDS):
these flags were only checked when the methods were called.

In Python 3.8, the flags are checked as soon as the module is imported,
which prevents the module to be imported.

Inspired by:
rpm-software-management/libcomps#50

Python doc:
https://docs.python.org/3/c-api/structures.html#METH_VARARGS
pbrezina added a commit to pbrezina/sssd that referenced this pull request Sep 23, 2019
To fix this error that happened during mockbuild on rawhide.

FAIL: src/tests/pysss-test.py3
==============================
ERROR: test_import (__main__.PysssImport)
Import the module and assert it comes from tree
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/builddir/build/BUILD/sssd-1.16.5/src/tests/pysss-test.py", line 56, in test_import
   import pysss
 SystemError: bad call flags

In Python 3.7, import didn't check descriptor flags (METH_KEYWORDS):
these flags were only checked when the methods were called.

In Python 3.8, the flags are checked as soon as the module is imported,
which prevents the module to be imported.

Inspired by:
rpm-software-management/libcomps#50

Python doc:
https://docs.python.org/3/c-api/structures.html#METH_VARARGS
jhrozek pushed a commit to SSSD/sssd that referenced this pull request Sep 23, 2019
To fix this error that happened during mockbuild on rawhide.

FAIL: src/tests/pysss-test.py3
==============================
ERROR: test_import (__main__.PysssImport)
Import the module and assert it comes from tree
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/builddir/build/BUILD/sssd-1.16.5/src/tests/pysss-test.py", line 56, in test_import
   import pysss
 SystemError: bad call flags

In Python 3.7, import didn't check descriptor flags (METH_KEYWORDS):
these flags were only checked when the methods were called.

In Python 3.8, the flags are checked as soon as the module is imported,
which prevents the module to be imported.

Inspired by:
rpm-software-management/libcomps#50

Python doc:
https://docs.python.org/3/c-api/structures.html#METH_VARARGS

Reviewed-by: Tomáš Halman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants