[PATCH STABLE] parsers: do not cache RevlogError type (issue4451)
Yuya Nishihara
yuya at tcha.org
Fri Jun 12 21:35:50 CDT 2015
On Fri, 12 Jun 2015 14:45:25 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1434145439 25200
> # Fri Jun 12 14:43:59 2015 -0700
> # Branch stable
> # Node ID 6c0eef5e16a598e60623afcd8db0fdf7205bed1c
> # Parent 7298da81f5a9f64ebbdef2b2195585a65da0f99e
> parsers: do not cache RevlogError type (issue4451)
> + mod = PyImport_ImportModule("mercurial.error");
> + if (mod == NULL) {
> + goto cleanup;
> }
>
> - errobj = PyObject_CallFunction(errclass, NULL);
> - if (errobj == NULL)
> - return NULL;
> - PyErr_SetObject(errclass, errobj);
> - return errobj;
> + dict = PyModule_GetDict(mod);
> + if (dict == NULL) {
> + goto cleanup;
> + }
> + Py_INCREF(dict);
>
> -classfail:
> + errclass = PyDict_GetItemString(dict, "RevlogError");
> + if (errclass == NULL) {
> + PyErr_SetString(PyExc_SystemError,
> + "could not find RevlogError");
> + goto cleanup;
> + }
> +
> + /* value of exception is ignored by callers */
> + PyErr_SetString(errclass, "RevlogError");
> +
> +cleanup:
> + Py_XDECREF(dict);
> Py_XDECREF(mod);
I'm not sure if we need to incref/decref the module dict, but if we want to
make sure the errclass is alive in this function, we could instead do
errclass = PyObject_GetAttrString(mod, "RevlogError");
...
Py_XDECREF(errclass);
https://docs.python.org/2/faq/extending.html#how-do-i-access-a-module-written-in-python-from-c
That said, I don't think it won't be suitable for stable.
More information about the Mercurial-devel
mailing list