Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.5 Changeset: r92151:fee5f0e18b17 Date: 2017-08-14 20:52 +0200 http://bitbucket.org/pypy/pypy/changeset/fee5f0e18b17/
Log: hg merge default diff --git a/pypy/module/cpyext/src/modsupport.c b/pypy/module/cpyext/src/modsupport.c --- a/pypy/module/cpyext/src/modsupport.c +++ b/pypy/module/cpyext/src/modsupport.c @@ -523,12 +523,10 @@ return res; } -/* returns -1 in case of error, 0 if a new key was added, 1 if the key - was already there (and replaced) */ -static int -_PyModule_AddObject_NoConsumeRef(PyObject *m, const char *name, PyObject *o) +int +PyModule_AddObject(PyObject *m, const char *name, PyObject *o) { - PyObject *dict, *prev; + PyObject *dict; if (!PyModule_Check(m)) { PyErr_SetString(PyExc_TypeError, "PyModule_AddObject() needs module as first arg"); @@ -548,49 +546,34 @@ PyModule_GetName(m)); return -1; } - prev = PyDict_GetItemString(dict, name); if (PyDict_SetItemString(dict, name, o)) return -1; - return prev != NULL; -} - -int -PyModule_AddObject(PyObject *m, const char *name, PyObject *o) -{ - int result = _PyModule_AddObject_NoConsumeRef(m, name, o); - /* XXX WORKAROUND for a common misusage of PyModule_AddObject: - for the common case of adding a new key, we don't consume a - reference, but instead just leak it away. The issue is that - people generally don't realize that this function consumes a - reference, because on CPython the reference is still stored - on the dictionary. */ - if (result != 0) - Py_DECREF(o); - return result < 0 ? -1 : 0; + Py_DECREF(o); + return 0; } int PyModule_AddIntConstant(PyObject *m, const char *name, long value) { - int result; PyObject *o = PyLong_FromLong(value); if (!o) return -1; - result = _PyModule_AddObject_NoConsumeRef(m, name, o); + if (PyModule_AddObject(m, name, o) == 0) + return 0; Py_DECREF(o); - return result < 0 ? -1 : 0; + return -1; } int PyModule_AddStringConstant(PyObject *m, const char *name, const char *value) { - int result; PyObject *o = PyUnicode_FromString(value); if (!o) return -1; - result = _PyModule_AddObject_NoConsumeRef(m, name, o); + if (PyModule_AddObject(m, name, o) == 0) + return 0; Py_DECREF(o); - return result < 0 ? -1 : 0; + return -1; } PyModuleDef* diff --git a/pypy/module/cpyext/test/test_capsule.py b/pypy/module/cpyext/test/test_capsule.py --- a/pypy/module/cpyext/test/test_capsule.py +++ b/pypy/module/cpyext/test/test_capsule.py @@ -12,9 +12,6 @@ if (PyErr_Occurred()) return NULL; module = PyImport_ImportModule("foo"); PyModule_AddObject(module, "_ptr", capsule); - #ifdef PYPY_VERSION - Py_DECREF(capsule); /* XXX <--- anti-workaround */ - #endif Py_DECREF(module); if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit