Issue38037
Created on 2019-09-05 11:14 by malin, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| reproduce.py | malin, 2019-09-05 11:14 | |||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 15701 | closed | malin, 2019-09-05 14:13 | |
| PR 15753 | merged | malin, 2019-09-09 10:47 | |
| PR 15779 | merged | miss-islington, 2019-09-09 13:48 | |
| Messages (7) | |||
|---|---|---|---|
| msg351196 - (view) | Author: Ma Lin (malin) * | Date: 2019-09-05 11:14 | |
Adding these two lines to /Objects/longobject.c will disable the "preallocated small integer pool":
#define NSMALLPOSINTS 0
#define NSMALLNEGINTS 0
Then run this reproduce code (attached):
from enum import IntEnum
import _signal
class Handlers(IntEnum):
A = _signal.SIG_DFL
B = _signal.SIG_IGN
When the interpreter exits, will get this error:
d:\dev\cpython\PCbuild\win32>python_d.exe d:\a.py
d:\dev\cpython\include\object.h:541: _Py_NegativeRefcount: Assertion failed: object has negative ref count
<object: freed>
Fatal Python error: _PyObject_AssertFailed
Current thread 0x0000200c (most recent call first):
3.8 and 3.9 branches are affected.
I'm sorry, this issue is beyond my ability.
|
|||
| msg351200 - (view) | Author: Ma Lin (malin) * | Date: 2019-09-05 14:20 | |
I did a Git bisect, this is the first bad commit: https://github.com/python/cpython/commit/9541bd321a94f13dc41163a5d7a1a847816fac84 nosy involved mates. |
|||
| msg351249 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2019-09-06 13:44 | |
This issue is a Python 3.8 regression.
Joannah: Would you mind to have a look?
x = DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL);
if (PyModule_AddObject(m, "SIG_DFL", x))
goto finally;
This change is not easy to read.
DefaultHandler must be a strong reference: finisignal() calls Py_CLEAR(DefaultHandler);
Previously, the code uses PyDict_SetItemString(d, "SIG_DFL", x): PyDict_SetItemString increases the reference counter, whereas PyModule_AddObject leaves the reference counter unchanged (yeah, it's a strange/bad C API).
I guess than an INCREF() is needed somewhere.
Compare it to:
int
PyModule_AddIntConstant(PyObject *m, const char *name, long value)
{
PyObject *o = PyLong_FromLong(value);
if (!o)
return -1;
if (PyModule_AddObject(m, name, o) == 0)
return 0;
Py_DECREF(o);
return -1;
}
|
|||
| msg351250 - (view) | Author: Joannah Nanjekye (nanjekyejoannah) * ![]() |
Date: 2019-09-06 13:48 | |
I will look after my next meeting which is in 10 minutes. In the meantime have you perused this PR : https://github.com/python/cpython/pull/15701 If it can solve this? |
|||
| msg351466 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2019-09-09 13:46 | |
New changeset 77643c486fd22d8030e0d82c13012684b4ab6df1 by Victor Stinner (animalize) in branch 'master': bpo-38037: Fix reference counters in signal module (GH-15753) https://github.com/python/cpython/commit/77643c486fd22d8030e0d82c13012684b4ab6df1 |
|||
| msg351483 - (view) | Author: miss-islington (miss-islington) | Date: 2019-09-09 14:42 | |
New changeset b150d0bf1bb4c3203bb3293625e32aed01b25887 by Miss Islington (bot) in branch '3.8': bpo-38037: Fix reference counters in signal module (GH-15753) https://github.com/python/cpython/commit/b150d0bf1bb4c3203bb3293625e32aed01b25887 |
|||
| msg351485 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2019-09-09 14:44 | |
Thanks for the fix animalize. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:19 | admin | set | github: 82218 |
| 2019-09-09 14:44:15 | vstinner | set | status: open -> closed resolution: fixed messages: + msg351485 stage: patch review -> resolved |
| 2019-09-09 14:42:38 | miss-islington | set | nosy:
+ miss-islington messages: + msg351483 |
| 2019-09-09 13:48:18 | miss-islington | set | pull_requests: + pull_request15432 |
| 2019-09-09 13:46:29 | vstinner | set | messages: + msg351466 |
| 2019-09-09 10:47:44 | malin | set | pull_requests: + pull_request15407 |
| 2019-09-07 03:59:37 | malin | set | title: Assertion failed: object has negative ref count -> reference counter issue in signal module |
| 2019-09-06 13:48:33 | nanjekyejoannah | set | messages: + msg351250 |
| 2019-09-06 13:44:39 | vstinner | set | priority: normal -> release blocker nosy: + vstinner, lukasz.langa messages: + msg351249 |
| 2019-09-05 14:20:00 | malin | set | nosy:
+ berker.peksag, nanjekyejoannah messages: + msg351200 |
| 2019-09-05 14:13:03 | malin | set | keywords:
+ patch stage: patch review pull_requests: + pull_request15355 |
| 2019-09-05 11:14:08 | malin | create | |
