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.

classification
Title: SystemError: ../Objects/longobject.c:998: bad argument to internal function
Type: Stage: resolved
Components: Extension Modules Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: barry, benjamin.peterson, doko, python-dev, serhiy.storchaka, vstinner
Priority: release blocker Keywords: patch

Created on 2015-04-01 16:17 by doko, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
posix_dev_t_converter.patch serhiy.storchaka, 2015-04-01 20:08 review
Messages (8)
msg239826 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2015-04-01 16:17
an unreleased version of cinder fails a test when run with python 2.7 from the branch.  I don't have a test case yet, but looking at the error message and list of fixed issues after the 2.7.9 release, the fix for issue #23098 could be the culprit.

FAIL: cinder.tests.test_utils.GetBlkdevMajorMinorTestCase.test_get_blkdev_major_minor_file
cinder.tests.test_utils.GetBlkdevMajorMinorTestCase.test_get_blkdev_major_minor_file
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/build/buildd/cinder-2015.1~b3/cinder/tests/test_utils.py", line 721, in test_get_blkdev_major_minor_file
    dev = self._test_get_blkdev_major_minor_file('/dev/made_up_disk1')
  File "/usr/lib/python2.7/dist-packages/mock.py", line 1210, in patched
    return func(*args, **keywargs)
  File "/build/buildd/cinder-2015.1~b3/cinder/tests/test_utils.py", line 712, in _test_get_blkdev_major_minor_file
    dev = utils.get_blkdev_major_minor(test_file)
  File "/build/buildd/cinder-2015.1~b3/cinder/utils.py", line 656, in get_blkdev_major_minor
    return get_blkdev_major_minor(devpath, False)
  File "/build/buildd/cinder-2015.1~b3/cinder/utils.py", line 645, in get_blkdev_major_minor
    return '%d:%d' % (os.major(st.st_rdev), os.minor(st.st_rdev))
SystemError: ../Objects/longobject.c:998: bad argument to internal function
Traceback (most recent call last):
_StringException: Empty attachments:
  stderr
  stdout
msg239828 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-04-01 16:32
> return '%d:%d' % (os.major(st.st_rdev), os.minor(st.st_rdev))

Can you check if the error comes from os.major() or os.minor(), and please provide the value of st_rdev?

You can modify the unit test to catch SystemError and raise a new exception with more information.
msg239830 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2015-04-01 17:47
so the culprit is an "optimization":

"Committed to 2.7 with small change: stat() and makedev() should return int instead of long if possible."

the test case however expects a long. st_dev is now not always a long, but an int or long depending on the value.
msg239832 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2015-04-01 17:57
no, simpler:

>>> import os
>>> os.minor(os.makedev(8,65))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: ../Objects/longobject.c:998: bad argument to internal function
>>> os.major(os.makedev(8,65))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: ../Objects/longobject.c:998: bad argument to internal function
msg239833 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2015-04-01 17:59
casting to a long works ...

>>> os.major(long(os.makedev(8,65)))
8

so maybe revert that optimization for the released branches?
msg239841 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-04-01 19:44
Obviously, an unit test is missing ;)
msg239842 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-04-01 20:08
Oh, this is a catch when backport to 2.7. Here is a patch that makes dev_t converter to support int and int-like types. Added tests (surprisingly there were no tests for makedev/major/minor at all).

> so maybe revert that optimization for the released branches?

It is not an optimization, but required for backward compatibility. Third-party code can expect int and only int.
msg241615 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-04-20 06:33
New changeset cd7d51b5c951 by Serhiy Storchaka in branch '2.7':
Issue #23842: os.major(), os.minor() and os.makedev() now support ints again.
https://hg.python.org/cpython/rev/cd7d51b5c951

New changeset 998d967b8a57 by Serhiy Storchaka in branch '3.4':
Issue #23842: Added tests for os.major(), os.minor() and os.makedev().
https://hg.python.org/cpython/rev/998d967b8a57

New changeset d477da6f287f by Serhiy Storchaka in branch 'default':
Issue #23842: Added tests for os.major(), os.minor() and os.makedev().
https://hg.python.org/cpython/rev/d477da6f287f
History
Date User Action Args
2022-04-11 14:58:15adminsetgithub: 68030
2015-04-20 08:25:06serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-04-20 06:33:21python-devsetnosy: + python-dev
messages: + msg241615
2015-04-01 20:08:48serhiy.storchakasetassignee: serhiy.storchaka
stage: patch review
2015-04-01 20:08:04serhiy.storchakasetfiles: + posix_dev_t_converter.patch
keywords: + patch
messages: + msg239842
2015-04-01 19:44:48vstinnersetmessages: + msg239841
2015-04-01 18:30:56dokosetpriority: normal -> release blocker
nosy: + benjamin.peterson
2015-04-01 18:07:55barrysetnosy: + barry
2015-04-01 17:59:17dokosetmessages: + msg239833
2015-04-01 17:57:27dokosetmessages: + msg239832
2015-04-01 17:47:47dokosetmessages: + msg239830
2015-04-01 16:32:27vstinnersetmessages: + msg239828
2015-04-01 16:29:55vstinnersetnosy: + vstinner
2015-04-01 16:17:23dokocreate