Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b62deac

Browse files
committed
cleanup after custom buffer converter
1 parent 08673c5 commit b62deac

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

Modules/binascii.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ class ascii_buffer_converter(CConverter):
195195
type = 'Py_buffer'
196196
converter = 'ascii_buffer_converter'
197197
impl_by_reference = True
198+
c_default = "{NULL, NULL}"
199+
200+
def cleanup(self):
201+
name = self.name
202+
return "".join(["if (", name, ".obj)\n PyBuffer_Release(&", name, ");\n"])
198203
199204
[python start generated code]*/
200205
/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/

Modules/clinic/binascii.c.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static PyObject *
1616
binascii_a2b_uu(PyModuleDef *module, PyObject *args)
1717
{
1818
PyObject *return_value = NULL;
19-
Py_buffer data;
19+
Py_buffer data = {NULL, NULL};
2020

2121
if (!PyArg_ParseTuple(args,
2222
"O&:a2b_uu",
@@ -25,6 +25,10 @@ binascii_a2b_uu(PyModuleDef *module, PyObject *args)
2525
return_value = binascii_a2b_uu_impl(module, &data);
2626

2727
exit:
28+
/* Cleanup for data */
29+
if (data.obj)
30+
PyBuffer_Release(&data);
31+
2832
return return_value;
2933
}
3034

@@ -72,7 +76,7 @@ static PyObject *
7276
binascii_a2b_base64(PyModuleDef *module, PyObject *args)
7377
{
7478
PyObject *return_value = NULL;
75-
Py_buffer data;
79+
Py_buffer data = {NULL, NULL};
7680

7781
if (!PyArg_ParseTuple(args,
7882
"O&:a2b_base64",
@@ -81,6 +85,10 @@ binascii_a2b_base64(PyModuleDef *module, PyObject *args)
8185
return_value = binascii_a2b_base64_impl(module, &data);
8286

8387
exit:
88+
/* Cleanup for data */
89+
if (data.obj)
90+
PyBuffer_Release(&data);
91+
8492
return return_value;
8593
}
8694

@@ -128,7 +136,7 @@ static PyObject *
128136
binascii_a2b_hqx(PyModuleDef *module, PyObject *args)
129137
{
130138
PyObject *return_value = NULL;
131-
Py_buffer data;
139+
Py_buffer data = {NULL, NULL};
132140

133141
if (!PyArg_ParseTuple(args,
134142
"O&:a2b_hqx",
@@ -137,6 +145,10 @@ binascii_a2b_hqx(PyModuleDef *module, PyObject *args)
137145
return_value = binascii_a2b_hqx_impl(module, &data);
138146

139147
exit:
148+
/* Cleanup for data */
149+
if (data.obj)
150+
PyBuffer_Release(&data);
151+
140152
return return_value;
141153
}
142154

@@ -350,7 +362,7 @@ static PyObject *
350362
binascii_a2b_hex(PyModuleDef *module, PyObject *args)
351363
{
352364
PyObject *return_value = NULL;
353-
Py_buffer hexstr;
365+
Py_buffer hexstr = {NULL, NULL};
354366

355367
if (!PyArg_ParseTuple(args,
356368
"O&:a2b_hex",
@@ -359,6 +371,10 @@ binascii_a2b_hex(PyModuleDef *module, PyObject *args)
359371
return_value = binascii_a2b_hex_impl(module, &hexstr);
360372

361373
exit:
374+
/* Cleanup for hexstr */
375+
if (hexstr.obj)
376+
PyBuffer_Release(&hexstr);
377+
362378
return return_value;
363379
}
364380

@@ -377,7 +393,7 @@ binascii_a2b_qp(PyModuleDef *module, PyObject *args, PyObject *kwargs)
377393
{
378394
PyObject *return_value = NULL;
379395
static char *_keywords[] = {"data", "header", NULL};
380-
Py_buffer data;
396+
Py_buffer data = {NULL, NULL};
381397
int header = 0;
382398

383399
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
@@ -387,6 +403,10 @@ binascii_a2b_qp(PyModuleDef *module, PyObject *args, PyObject *kwargs)
387403
return_value = binascii_a2b_qp_impl(module, &data, header);
388404

389405
exit:
406+
/* Cleanup for data */
407+
if (data.obj)
408+
PyBuffer_Release(&data);
409+
390410
return return_value;
391411
}
392412

@@ -427,4 +447,4 @@ binascii_b2a_qp(PyModuleDef *module, PyObject *args, PyObject *kwargs)
427447

428448
return return_value;
429449
}
430-
/*[clinic end generated code: checksum=abe48ca8020fa3ec25e13bd9fa7414f6b3ee2946]*/
450+
/*[clinic end generated code: checksum=8180e5be47a110ae8c89263a7c12a91d80754f60]*/

0 commit comments

Comments
 (0)