Skip to content

Commit 6405fee

Browse files
bpo-33012: Fix invalid function casts for long_long. (GH-6652)
long_long() was used with three function types: PyCFunction, getter and unaryfunction.
1 parent ca40501 commit 6405fee

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

Objects/longobject.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ PyLong_FromUnicodeObject(PyObject *u, int base)
25372537
/* forward */
25382538
static PyLongObject *x_divrem
25392539
(PyLongObject *, PyLongObject *, PyLongObject **);
2540-
static PyObject *long_long(PyObject *v, PyObject *Py_UNUSED(ignored));
2540+
static PyObject *long_long(PyObject *v);
25412541

25422542
/* Int division with remainder, top-level routine */
25432543

@@ -2557,7 +2557,7 @@ long_divrem(PyLongObject *a, PyLongObject *b,
25572557
(size_a == size_b &&
25582558
a->ob_digit[size_a-1] < b->ob_digit[size_b-1])) {
25592559
/* |a| < |b|. */
2560-
*prem = (PyLongObject *)long_long((PyObject *)a, NULL);
2560+
*prem = (PyLongObject *)long_long((PyObject *)a);
25612561
if (*prem == NULL) {
25622562
return -1;
25632563
}
@@ -4242,7 +4242,7 @@ long_abs(PyLongObject *v)
42424242
if (Py_SIZE(v) < 0)
42434243
return long_neg(v);
42444244
else
4245-
return long_long((PyObject *)v, NULL);
4245+
return long_long((PyObject *)v);
42464246
}
42474247

42484248
static int
@@ -4554,7 +4554,7 @@ long_or(PyObject *a, PyObject *b)
45544554
}
45554555

45564556
static PyObject *
4557-
long_long(PyObject *v, PyObject *Py_UNUSED(ignored))
4557+
long_long(PyObject *v)
45584558
{
45594559
if (PyLong_CheckExact(v))
45604560
Py_INCREF(v);
@@ -4880,12 +4880,14 @@ int___getnewargs___impl(PyObject *self)
48804880
}
48814881

48824882
static PyObject *
4883-
long_get0(PyLongObject *v, void *context) {
4883+
long_get0(PyObject *Py_UNUSED(self), void *Py_UNUSED(context))
4884+
{
48844885
return PyLong_FromLong(0L);
48854886
}
48864887

48874888
static PyObject *
4888-
long_get1(PyLongObject *v, void *context) {
4889+
long_get1(PyObject *Py_UNUSED(self), void *Py_UNUSED(ignored))
4890+
{
48894891
return PyLong_FromLong(1L);
48904892
}
48914893

@@ -5028,7 +5030,7 @@ long_round(PyObject *self, PyObject *args)
50285030
if (!PyArg_ParseTuple(args, "|O", &o_ndigits))
50295031
return NULL;
50305032
if (o_ndigits == NULL)
5031-
return long_long(self, NULL);
5033+
return long_long(self);
50325034

50335035
ndigits = PyNumber_Index(o_ndigits);
50345036
if (ndigits == NULL)
@@ -5037,7 +5039,7 @@ long_round(PyObject *self, PyObject *args)
50375039
/* if ndigits >= 0 then no rounding is necessary; return self unchanged */
50385040
if (Py_SIZE(ndigits) >= 0) {
50395041
Py_DECREF(ndigits);
5040-
return long_long(self, NULL);
5042+
return long_long(self);
50415043
}
50425044

50435045
/* result = self - divmod_near(self, 10 ** -ndigits)[1] */
@@ -5278,8 +5280,14 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
52785280
return long_obj;
52795281
}
52805282

5283+
static PyObject *
5284+
long_long_meth(PyObject *self, PyObject *Py_UNUSED(ignored))
5285+
{
5286+
return long_long(self);
5287+
}
5288+
52815289
static PyMethodDef long_methods[] = {
5282-
{"conjugate", long_long, METH_NOARGS,
5290+
{"conjugate", long_long_meth, METH_NOARGS,
52835291
"Returns self, the complex conjugate of any int."},
52845292
INT_BIT_LENGTH_METHODDEF
52855293
#if 0
@@ -5288,11 +5296,11 @@ static PyMethodDef long_methods[] = {
52885296
#endif
52895297
INT_TO_BYTES_METHODDEF
52905298
INT_FROM_BYTES_METHODDEF
5291-
{"__trunc__", long_long, METH_NOARGS,
5299+
{"__trunc__", long_long_meth, METH_NOARGS,
52925300
"Truncating an Integral returns itself."},
5293-
{"__floor__", long_long, METH_NOARGS,
5301+
{"__floor__", long_long_meth, METH_NOARGS,
52945302
"Flooring an Integral returns itself."},
5295-
{"__ceil__", long_long, METH_NOARGS,
5303+
{"__ceil__", long_long_meth, METH_NOARGS,
52965304
"Ceiling of an Integral returns itself."},
52975305
{"__round__", (PyCFunction)long_round, METH_VARARGS,
52985306
"Rounding an Integral returns itself.\n"
@@ -5305,19 +5313,19 @@ static PyMethodDef long_methods[] = {
53055313

53065314
static PyGetSetDef long_getset[] = {
53075315
{"real",
5308-
(getter)long_long, (setter)NULL,
5316+
(getter)long_long_meth, (setter)NULL,
53095317
"the real part of a complex number",
53105318
NULL},
53115319
{"imag",
5312-
(getter)long_get0, (setter)NULL,
5320+
long_get0, (setter)NULL,
53135321
"the imaginary part of a complex number",
53145322
NULL},
53155323
{"numerator",
5316-
(getter)long_long, (setter)NULL,
5324+
(getter)long_long_meth, (setter)NULL,
53175325
"the numerator of a rational number in lowest terms",
53185326
NULL},
53195327
{"denominator",
5320-
(getter)long_get1, (setter)NULL,
5328+
long_get1, (setter)NULL,
53215329
"the denominator of a rational number in lowest terms",
53225330
NULL},
53235331
{NULL} /* Sentinel */
@@ -5347,7 +5355,7 @@ static PyNumberMethods long_as_number = {
53475355
long_divmod, /*nb_divmod*/
53485356
long_pow, /*nb_power*/
53495357
(unaryfunc)long_neg, /*nb_negative*/
5350-
(unaryfunc)long_long, /*tp_positive*/
5358+
long_long, /*tp_positive*/
53515359
(unaryfunc)long_abs, /*tp_absolute*/
53525360
(inquiry)long_bool, /*tp_bool*/
53535361
(unaryfunc)long_invert, /*nb_invert*/

0 commit comments

Comments
 (0)