Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(31926)

Delta Between Two Patch Sets: Objects/abstract.c

Issue 27095: Simplify MAKE_FUNCTION
Left Patch Set: Created 3 years, 3 months ago
Right Patch Set: Created 3 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* Abstract Object Interface (many thanks to Jim Fulton) */ 1 /* Abstract Object Interface (many thanks to Jim Fulton) */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include <ctype.h> 4 #include <ctype.h>
5 #include "structmember.h" /* we need the offsetof() macro from there */ 5 #include "structmember.h" /* we need the offsetof() macro from there */
6 #include "longintrepr.h" 6 #include "longintrepr.h"
7 7
8 8
9 9
10 /* Shorthands to return certain errors */ 10 /* Shorthands to return certain errors */
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 "or a number, not '%.200s'", o); 1344 "or a number, not '%.200s'", o);
1345 } 1345 }
1346 1346
1347 PyObject * 1347 PyObject *
1348 PyNumber_Float(PyObject *o) 1348 PyNumber_Float(PyObject *o)
1349 { 1349 {
1350 PyNumberMethods *m; 1350 PyNumberMethods *m;
1351 1351
1352 if (o == NULL) 1352 if (o == NULL)
1353 return null_error(); 1353 return null_error();
1354 if (PyFloat_CheckExact(o)) {
1355 Py_INCREF(o);
1356 return o;
1357 }
1354 m = o->ob_type->tp_as_number; 1358 m = o->ob_type->tp_as_number;
1355 if (m && m->nb_float) { /* This should include subclasses of float */ 1359 if (m && m->nb_float) { /* This should include subclasses of float */
1356 PyObject *res = m->nb_float(o); 1360 PyObject *res = m->nb_float(o);
1357 if (res && !PyFloat_Check(res)) { 1361 double val;
1362 if (!res || PyFloat_CheckExact(res)) {
1363 return res;
1364 }
1365 if (!PyFloat_Check(res)) {
1358 PyErr_Format(PyExc_TypeError, 1366 PyErr_Format(PyExc_TypeError,
1359 "__float__ returned non-float (type %.200s)", 1367 "%.50s.__float__ returned non-float (type %.50s)",
1360 res->ob_type->tp_name); 1368 o->ob_type->tp_name, res->ob_type->tp_name);
1361 Py_DECREF(res); 1369 Py_DECREF(res);
1362 return NULL; 1370 return NULL;
1363 } 1371 }
1364 return res; 1372 /* Issue #26983: warn if 'res' not of exact type float. */
1373 if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
1374 "%.50s.__float__ returned non-float (type %.50s). "
1375 "The ability to return an instance of a strict subclass of float "
1376 "is deprecated, and may be removed in a future version of Python .",
1377 o->ob_type->tp_name, res->ob_type->tp_name)) {
1378 Py_DECREF(res);
1379 return NULL;
1380 }
1381 val = PyFloat_AS_DOUBLE(res);
1382 Py_DECREF(res);
1383 return PyFloat_FromDouble(val);
1365 } 1384 }
1366 if (PyFloat_Check(o)) { /* A float subclass with nb_float == NULL */ 1385 if (PyFloat_Check(o)) { /* A float subclass with nb_float == NULL */
1367 PyFloatObject *po = (PyFloatObject *)o; 1386 return PyFloat_FromDouble(PyFloat_AS_DOUBLE(o));
1368 return PyFloat_FromDouble(po->ob_fval);
1369 } 1387 }
1370 return PyFloat_FromString(o); 1388 return PyFloat_FromString(o);
1371 } 1389 }
1372 1390
1373 1391
1374 PyObject * 1392 PyObject *
1375 PyNumber_ToBase(PyObject *n, int base) 1393 PyNumber_ToBase(PyObject *n, int base)
1376 { 1394 {
1377 PyObject *res = NULL; 1395 PyObject *res = NULL;
1378 PyObject *index = PyNumber_Index(n); 1396 PyObject *index = PyNumber_Index(n);
(...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2858 /* Free's a NULL terminated char** array of C strings. */ 2876 /* Free's a NULL terminated char** array of C strings. */
2859 void 2877 void
2860 _Py_FreeCharPArray(char *const array[]) 2878 _Py_FreeCharPArray(char *const array[])
2861 { 2879 {
2862 Py_ssize_t i; 2880 Py_ssize_t i;
2863 for (i = 0; array[i] != NULL; ++i) { 2881 for (i = 0; array[i] != NULL; ++i) {
2864 PyMem_Free(array[i]); 2882 PyMem_Free(array[i]);
2865 } 2883 }
2866 PyMem_Free((void*)array); 2884 PyMem_Free((void*)array);
2867 } 2885 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+