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

Skip to content

Commit 3cceb38

Browse files
committed
Issue #19976: Argument Clinic METH_NOARGS functions now always
take two parameters.
1 parent 583a939 commit 3cceb38

5 files changed

Lines changed: 150 additions & 31 deletions

File tree

Include/pymacro.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@
6969
/* Check if pointer "p" is aligned to "a"-bytes boundary. */
7070
#define _Py_IS_ALIGNED(p, a) (!((Py_uintptr_t)(p) & (Py_uintptr_t)((a) - 1)))
7171

72+
#ifdef __GNUC__
73+
#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
74+
#else
75+
#define Py_UNUSED(name) _unused_ ## name
76+
#endif
77+
7278
#endif /* Py_PYMACRO_H */

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ Documentation
342342

343343
- Issue #19795: Improved markup of True/False constants.
344344

345+
Tools/Demos
346+
-----------
347+
348+
- Issue #19976: Argument Clinic METH_NOARGS functions now always
349+
take two parameters.
345350

346351
What's New in Python 3.4.0 Beta 1?
347352
==================================

Modules/_pickle.c

Lines changed: 122 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,8 +3901,21 @@ PyDoc_STRVAR(_pickle_Pickler_clear_memo__doc__,
39013901
{"clear_memo", (PyCFunction)_pickle_Pickler_clear_memo, METH_NOARGS, _pickle_Pickler_clear_memo__doc__},
39023902

39033903
static PyObject *
3904-
_pickle_Pickler_clear_memo(PicklerObject *self)
3905-
/*[clinic checksum: 9c32be7e7a17ff82a81aae409d0d4f469033a5b2]*/
3904+
_pickle_Pickler_clear_memo_impl(PicklerObject *self);
3905+
3906+
static PyObject *
3907+
_pickle_Pickler_clear_memo(PyObject *self, PyObject *Py_UNUSED(ignored))
3908+
{
3909+
PyObject *return_value = NULL;
3910+
3911+
return_value = _pickle_Pickler_clear_memo_impl((PicklerObject *)self);
3912+
3913+
return return_value;
3914+
}
3915+
3916+
static PyObject *
3917+
_pickle_Pickler_clear_memo_impl(PicklerObject *self)
3918+
/*[clinic checksum: 0574593b102fffb8e781d7bb9b536ceffc525ac1]*/
39063919
{
39073920
if (self->memo)
39083921
PyMemoTable_Clear(self->memo);
@@ -4176,8 +4189,21 @@ PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__,
41764189
{"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__},
41774190

41784191
static PyObject *
4179-
_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self)
4180-
/*[clinic checksum: 507f13938721992e175a3e58b5ad02620045a1cc]*/
4192+
_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
4193+
4194+
static PyObject *
4195+
_pickle_PicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
4196+
{
4197+
PyObject *return_value = NULL;
4198+
4199+
return_value = _pickle_PicklerMemoProxy_clear_impl((PicklerMemoProxyObject *)self);
4200+
4201+
return return_value;
4202+
}
4203+
4204+
static PyObject *
4205+
_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self)
4206+
/*[clinic checksum: c6ca252530ccb3ea2f4b33507b51b183f23b24c7]*/
41814207
{
41824208
if (self->pickler->memo)
41834209
PyMemoTable_Clear(self->pickler->memo);
@@ -4200,8 +4226,21 @@ PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__,
42004226
{"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__},
42014227

42024228
static PyObject *
4203-
_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self)
4204-
/*[clinic checksum: 73a5117ab354290ebdbe07bd0bf7232d0936a69d]*/
4229+
_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
4230+
4231+
static PyObject *
4232+
_pickle_PicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
4233+
{
4234+
PyObject *return_value = NULL;
4235+
4236+
return_value = _pickle_PicklerMemoProxy_copy_impl((PicklerMemoProxyObject *)self);
4237+
4238+
return return_value;
4239+
}
4240+
4241+
static PyObject *
4242+
_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self)
4243+
/*[clinic checksum: 808c4d5a37359ed5fb2efe81dbe5ff480719f470]*/
42054244
{
42064245
Py_ssize_t i;
42074246
PyMemoTable *memo;
@@ -4254,11 +4293,24 @@ PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__,
42544293
{"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__},
42554294

42564295
static PyObject *
4257-
_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self)
4258-
/*[clinic checksum: 40f0bf7a9b161e77130674f0481bda0a0184dcce]*/
4296+
_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
4297+
4298+
static PyObject *
4299+
_pickle_PicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
4300+
{
4301+
PyObject *return_value = NULL;
4302+
4303+
return_value = _pickle_PicklerMemoProxy___reduce___impl((PicklerMemoProxyObject *)self);
4304+
4305+
return return_value;
4306+
}
4307+
4308+
static PyObject *
4309+
_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self)
4310+
/*[clinic checksum: 2293152bdf53951a012d430767b608f5fb4213b5]*/
42594311
{
42604312
PyObject *reduce_value, *dict_args;
4261-
PyObject *contents = _pickle_PicklerMemoProxy_copy(self);
4313+
PyObject *contents = _pickle_PicklerMemoProxy_copy_impl(self);
42624314
if (contents == NULL)
42634315
return NULL;
42644316

@@ -6288,8 +6340,21 @@ PyDoc_STRVAR(_pickle_Unpickler_load__doc__,
62886340
{"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__},
62896341

62906342
static PyObject *
6291-
_pickle_Unpickler_load(PyObject *self)
6292-
/*[clinic checksum: c2ae1263f0dd000f34ccf0fe59d7c544464babc4]*/
6343+
_pickle_Unpickler_load_impl(PyObject *self);
6344+
6345+
static PyObject *
6346+
_pickle_Unpickler_load(PyObject *self, PyObject *Py_UNUSED(ignored))
6347+
{
6348+
PyObject *return_value = NULL;
6349+
6350+
return_value = _pickle_Unpickler_load_impl(self);
6351+
6352+
return return_value;
6353+
}
6354+
6355+
static PyObject *
6356+
_pickle_Unpickler_load_impl(PyObject *self)
6357+
/*[clinic checksum: 55f35fcaf034817e75c355ec50b7878577355899]*/
62936358
{
62946359
UnpicklerObject *unpickler = (UnpicklerObject*)self;
62956360

@@ -6688,8 +6753,21 @@ PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__,
66886753
{"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__},
66896754

66906755
static PyObject *
6691-
_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self)
6692-
/*[clinic checksum: 46fecf4e33c0c873124f845edf6cc3a2e9864bd5]*/
6756+
_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
6757+
6758+
static PyObject *
6759+
_pickle_UnpicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
6760+
{
6761+
PyObject *return_value = NULL;
6762+
6763+
return_value = _pickle_UnpicklerMemoProxy_clear_impl((UnpicklerMemoProxyObject *)self);
6764+
6765+
return return_value;
6766+
}
6767+
6768+
static PyObject *
6769+
_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self)
6770+
/*[clinic checksum: e0f99c26d48444a3f58f598bec3190c66595fce7]*/
66936771
{
66946772
_Unpickler_MemoCleanup(self->unpickler);
66956773
self->unpickler->memo = _Unpickler_NewMemo(self->unpickler->memo_size);
@@ -6714,8 +6792,21 @@ PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__,
67146792
{"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__},
67156793

67166794
static PyObject *
6717-
_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self)
6718-
/*[clinic checksum: f8856c4e8a33540886dfbb245f286af3008fa0ad]*/
6795+
_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
6796+
6797+
static PyObject *
6798+
_pickle_UnpicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
6799+
{
6800+
PyObject *return_value = NULL;
6801+
6802+
return_value = _pickle_UnpicklerMemoProxy_copy_impl((UnpicklerMemoProxyObject *)self);
6803+
6804+
return return_value;
6805+
}
6806+
6807+
static PyObject *
6808+
_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self)
6809+
/*[clinic checksum: 8c0ab91c0b694ea71a1774650898a760d1ab4765]*/
67196810
{
67206811
Py_ssize_t i;
67216812
PyObject *new_memo = PyDict_New();
@@ -6761,12 +6852,25 @@ PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__,
67616852
{"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__},
67626853

67636854
static PyObject *
6764-
_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self)
6765-
/*[clinic checksum: ab5516a77659144e1191c7dd70a0c6c7455660bc]*/
6855+
_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
6856+
6857+
static PyObject *
6858+
_pickle_UnpicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
6859+
{
6860+
PyObject *return_value = NULL;
6861+
6862+
return_value = _pickle_UnpicklerMemoProxy___reduce___impl((UnpicklerMemoProxyObject *)self);
6863+
6864+
return return_value;
6865+
}
6866+
6867+
static PyObject *
6868+
_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self)
6869+
/*[clinic checksum: 4ee76a65511291f0de2e9e63db395d2e5d6d8df6]*/
67666870
{
67676871
PyObject *reduce_value;
67686872
PyObject *constructor_args;
6769-
PyObject *contents = _pickle_UnpicklerMemoProxy_copy(self);
6873+
PyObject *contents = _pickle_UnpicklerMemoProxy_copy_impl(self);
67706874
if (contents == NULL)
67716875
return NULL;
67726876

Modules/zlibmodule.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,21 @@ PyDoc_STRVAR(zlib_Compress_copy__doc__,
10451045
{"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
10461046

10471047
static PyObject *
1048-
zlib_Compress_copy(compobject *self)
1049-
/*[clinic checksum: 0b37c07f8f27deb7d4769951fbecf600a1006ef8]*/
1048+
zlib_Compress_copy_impl(compobject *self);
1049+
1050+
static PyObject *
1051+
zlib_Compress_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
1052+
{
1053+
PyObject *return_value = NULL;
1054+
1055+
return_value = zlib_Compress_copy_impl((compobject *)self);
1056+
1057+
return return_value;
1058+
}
1059+
1060+
static PyObject *
1061+
zlib_Compress_copy_impl(compobject *self)
1062+
/*[clinic checksum: 2f454ee15be3bc53cfb4e845c3f891f68be4c8e4]*/
10501063
{
10511064
compobject *retval = NULL;
10521065
int err;

Tools/clinic/clinic.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,13 @@ def template_base(*args):
400400
{{"{name}", (PyCFunction){c_basename}, {methoddef_flags}, {c_basename}__doc__}},
401401
""".replace('{methoddef_flags}', flags)
402402

403-
def meth_noargs_pyobject_template(self, methoddef_flags=""):
404-
return self.template_base("METH_NOARGS", methoddef_flags) + """
405-
static PyObject *
406-
{c_basename}({impl_parameters})
407-
"""
408-
409403
def meth_noargs_template(self, methoddef_flags=""):
410404
return self.template_base("METH_NOARGS", methoddef_flags) + """
411405
static {impl_return_type}
412406
{impl_prototype};
413407
414408
static PyObject *
415-
{c_basename}({self_type}{self_name})
409+
{c_basename}({self_type}{self_name}, PyObject *Py_UNUSED(ignored))
416410
{{
417411
PyObject *return_value = NULL;
418412
{declarations}
@@ -713,10 +707,7 @@ def render_function(self, f):
713707
f.return_converter.type == 'PyObject *')
714708

715709
if not parameters:
716-
if default_return_converter:
717-
template = self.meth_noargs_pyobject_template(f.methoddef_flags)
718-
else:
719-
template = self.meth_noargs_template(f.methoddef_flags)
710+
template = self.meth_noargs_template(f.methoddef_flags)
720711
elif (len(parameters) == 1 and
721712
parameters[0].kind == inspect.Parameter.POSITIONAL_ONLY and
722713
not converters[0].is_optional() and

0 commit comments

Comments
 (0)