[Python-checkins] cpython: cleanup after custom buffer converter

benjamin.peterson python-checkins at python.org
Sun Jan 26 16:42:04 CET 2014


http://hg.python.org/cpython/rev/259aeb0ecd2a
changeset:   88725:259aeb0ecd2a
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Jan 26 10:41:58 2014 -0500
summary:
  cleanup after custom buffer converter

files:
  Modules/binascii.c          |   5 +++
  Modules/clinic/binascii.c.h |  32 ++++++++++++++++++++----
  2 files changed, 31 insertions(+), 6 deletions(-)


diff --git a/Modules/binascii.c b/Modules/binascii.c
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -195,6 +195,11 @@
     type = 'Py_buffer'
     converter = 'ascii_buffer_converter'
     impl_by_reference = True
+    c_default = "{NULL, NULL}"
+
+    def cleanup(self):
+        name = self.name
+        return "".join(["if (", name, ".obj)\n   PyBuffer_Release(&", name, ");\n"])
 
 [python start generated code]*/
 /*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h
--- a/Modules/clinic/binascii.c.h
+++ b/Modules/clinic/binascii.c.h
@@ -16,7 +16,7 @@
 binascii_a2b_uu(PyModuleDef *module, PyObject *args)
 {
     PyObject *return_value = NULL;
-    Py_buffer data;
+    Py_buffer data = {NULL, NULL};
 
     if (!PyArg_ParseTuple(args,
         "O&:a2b_uu",
@@ -25,6 +25,10 @@
     return_value = binascii_a2b_uu_impl(module, &data);
 
 exit:
+    /* Cleanup for data */
+    if (data.obj)
+       PyBuffer_Release(&data);
+
     return return_value;
 }
 
@@ -72,7 +76,7 @@
 binascii_a2b_base64(PyModuleDef *module, PyObject *args)
 {
     PyObject *return_value = NULL;
-    Py_buffer data;
+    Py_buffer data = {NULL, NULL};
 
     if (!PyArg_ParseTuple(args,
         "O&:a2b_base64",
@@ -81,6 +85,10 @@
     return_value = binascii_a2b_base64_impl(module, &data);
 
 exit:
+    /* Cleanup for data */
+    if (data.obj)
+       PyBuffer_Release(&data);
+
     return return_value;
 }
 
@@ -128,7 +136,7 @@
 binascii_a2b_hqx(PyModuleDef *module, PyObject *args)
 {
     PyObject *return_value = NULL;
-    Py_buffer data;
+    Py_buffer data = {NULL, NULL};
 
     if (!PyArg_ParseTuple(args,
         "O&:a2b_hqx",
@@ -137,6 +145,10 @@
     return_value = binascii_a2b_hqx_impl(module, &data);
 
 exit:
+    /* Cleanup for data */
+    if (data.obj)
+       PyBuffer_Release(&data);
+
     return return_value;
 }
 
@@ -350,7 +362,7 @@
 binascii_a2b_hex(PyModuleDef *module, PyObject *args)
 {
     PyObject *return_value = NULL;
-    Py_buffer hexstr;
+    Py_buffer hexstr = {NULL, NULL};
 
     if (!PyArg_ParseTuple(args,
         "O&:a2b_hex",
@@ -359,6 +371,10 @@
     return_value = binascii_a2b_hex_impl(module, &hexstr);
 
 exit:
+    /* Cleanup for hexstr */
+    if (hexstr.obj)
+       PyBuffer_Release(&hexstr);
+
     return return_value;
 }
 
@@ -377,7 +393,7 @@
 {
     PyObject *return_value = NULL;
     static char *_keywords[] = {"data", "header", NULL};
-    Py_buffer data;
+    Py_buffer data = {NULL, NULL};
     int header = 0;
 
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
@@ -387,6 +403,10 @@
     return_value = binascii_a2b_qp_impl(module, &data, header);
 
 exit:
+    /* Cleanup for data */
+    if (data.obj)
+       PyBuffer_Release(&data);
+
     return return_value;
 }
 
@@ -427,4 +447,4 @@
 
     return return_value;
 }
-/*[clinic end generated code: checksum=abe48ca8020fa3ec25e13bd9fa7414f6b3ee2946]*/
+/*[clinic end generated code: checksum=8180e5be47a110ae8c89263a7c12a91d80754f60]*/

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list