summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 11:16:48 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 11:16:48 (GMT)
commita093d0d6a92147bd0d024afdf03474c14b5b4594 (patch)
tree5291b14c1921fbb53a98d0f0d724e16f553aed01
parentc3a51ecb8518540625034ff07f9d518e0f84e7ac (diff)
downloadcpython-a093d0d6a92147bd0d024afdf03474c14b5b4594.zip
cpython-a093d0d6a92147bd0d024afdf03474c14b5b4594.tar.gz
cpython-a093d0d6a92147bd0d024afdf03474c14b5b4594.tar.bz2
Issue #8992: Simplify addcleanup() API
Don't need to handle unknown destructor anymore.
-rw-r--r--Python/getargs.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index aac1d17..487f1aa 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -146,10 +146,19 @@ cleanup_buffer(PyObject *self)
}
static int
-addcleanup(void *ptr, PyObject **freelist, PyCapsule_Destructor destr)
+addcleanup(void *ptr, PyObject **freelist, int is_buffer)
{
PyObject *cobj;
const char *name;
+ PyCapsule_Destructor destr;
+
+ if (is_buffer) {
+ destr = cleanup_buffer;
+ name = GETARGS_CAPSULE_NAME_CLEANUP_BUFFER;
+ } else {
+ destr = cleanup_ptr;
+ name = GETARGS_CAPSULE_NAME_CLEANUP_PTR;
+ }
if (!*freelist) {
*freelist = PyList_New(0);
@@ -159,13 +168,6 @@ addcleanup(void *ptr, PyObject **freelist, PyCapsule_Destructor destr)
}
}
- if (destr == cleanup_ptr) {
- name = GETARGS_CAPSULE_NAME_CLEANUP_PTR;
- } else if (destr == cleanup_buffer) {
- name = GETARGS_CAPSULE_NAME_CLEANUP_BUFFER;
- } else {
- return -1;
- }
cobj = PyCapsule_New(ptr, name, destr);
if (!cobj) {
destr(ptr);
@@ -855,7 +857,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if (getbuffer(arg, (Py_buffer*)p, &buf) < 0)
return converterr(buf, arg, msgbuf, bufsize);
format++;
- if (addcleanup(p, freelist, cleanup_buffer)) {
+ if (addcleanup(p, freelist, 1)) {
return converterr(
"(cleanup problem)",
arg, msgbuf, bufsize);
@@ -901,7 +903,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if (getbuffer(arg, p, &buf) < 0)
return converterr(buf, arg, msgbuf, bufsize);
}
- if (addcleanup(p, freelist, cleanup_buffer)) {
+ if (addcleanup(p, freelist, 1)) {
return converterr(
"(cleanup problem)",
arg, msgbuf, bufsize);
@@ -1109,7 +1111,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
"(memory error)",
arg, msgbuf, bufsize);
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(*buffer, freelist, 0)) {
Py_DECREF(s);
return converterr(
"(cleanup problem)",
@@ -1152,7 +1154,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
return converterr("(memory error)",
arg, msgbuf, bufsize);
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(*buffer, freelist, 0)) {
Py_DECREF(s);
return converterr("(cleanup problem)",
arg, msgbuf, bufsize);
@@ -1244,7 +1246,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
PyBuffer_Release((Py_buffer*)p);
return converterr("contiguous buffer", arg, msgbuf, bufsize);
}
- if (addcleanup(p, freelist, cleanup_buffer)) {
+ if (addcleanup(p, freelist, 1)) {
return converterr(
"(cleanup problem)",
arg, msgbuf, bufsize);