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

Side by Side Diff: Objects/classobject.c

Issue 29259: Add tp_fastcall to PyTypeObject: support FASTCALL calling convention for all callable objects
Patch Set: Created 3 years 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:
View unified diff | Download patch
OLDNEW
1 /* Class object implementation (dead now except for methods) */ 1 /* Class object implementation (dead now except for methods) */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "structmember.h" 4 #include "structmember.h"
5 5
6 #define TP_DESCR_GET(t) ((t)->tp_descr_get) 6 #define TP_DESCR_GET(t) ((t)->tp_descr_get)
7 7
8 /* Free list for method objects to safe malloc/free overhead 8 /* Free list for method objects to safe malloc/free overhead
9 * The im_self element is used to chain the elements. 9 * The im_self element is used to chain the elements.
10 */ 10 */
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 static int 296 static int
297 method_traverse(PyMethodObject *im, visitproc visit, void *arg) 297 method_traverse(PyMethodObject *im, visitproc visit, void *arg)
298 { 298 {
299 Py_VISIT(im->im_func); 299 Py_VISIT(im->im_func);
300 Py_VISIT(im->im_self); 300 Py_VISIT(im->im_self);
301 return 0; 301 return 0;
302 } 302 }
303 303
304 static PyObject * 304 static PyObject *
305 method_call(PyObject *method, PyObject *args, PyObject *kwargs) 305 method_call(PyObject *method, PyObject **args, Py_ssize_t nargs,
306 PyObject *kwnames)
306 { 307 {
307 PyObject *self, *func; 308 PyObject *self, *func;
308 309
309 self = PyMethod_GET_SELF(method); 310 self = PyMethod_GET_SELF(method);
310 if (self == NULL) { 311 if (self == NULL) {
311 PyErr_BadInternalCall(); 312 PyErr_BadInternalCall();
312 return NULL; 313 return NULL;
313 } 314 }
314 315
315 func = PyMethod_GET_FUNCTION(method); 316 func = PyMethod_GET_FUNCTION(method);
316 317 return _PyObject_FastCall_Prepend(func, self, args, nargs, kwnames);
317 return _PyObject_Call_Prepend(func, self, args, kwargs);
318 } 318 }
319 319
320 static PyObject * 320 static PyObject *
321 method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) 321 method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls)
322 { 322 {
323 /* Don't rebind an already bound method of a class that's not a base 323 /* Don't rebind an already bound method of a class that's not a base
324 class of cls. */ 324 class of cls. */
325 if (PyMethod_GET_SELF(meth) != NULL) { 325 if (PyMethod_GET_SELF(meth) != NULL) {
326 /* Already bound */ 326 /* Already bound */
327 Py_INCREF(meth); 327 Py_INCREF(meth);
(...skipping 11 matching lines...) Expand all
339 (destructor)method_dealloc, /* tp_dealloc */ 339 (destructor)method_dealloc, /* tp_dealloc */
340 0, /* tp_print */ 340 0, /* tp_print */
341 0, /* tp_getattr */ 341 0, /* tp_getattr */
342 0, /* tp_setattr */ 342 0, /* tp_setattr */
343 0, /* tp_reserved */ 343 0, /* tp_reserved */
344 (reprfunc)method_repr, /* tp_repr */ 344 (reprfunc)method_repr, /* tp_repr */
345 0, /* tp_as_number */ 345 0, /* tp_as_number */
346 0, /* tp_as_sequence */ 346 0, /* tp_as_sequence */
347 0, /* tp_as_mapping */ 347 0, /* tp_as_mapping */
348 (hashfunc)method_hash, /* tp_hash */ 348 (hashfunc)method_hash, /* tp_hash */
349 method_call, /* tp_call */ 349 0, /* tp_call */
350 0, /* tp_str */ 350 0, /* tp_str */
351 method_getattro, /* tp_getattro */ 351 method_getattro, /* tp_getattro */
352 PyObject_GenericSetAttr, /* tp_setattro */ 352 PyObject_GenericSetAttr, /* tp_setattro */
353 0, /* tp_as_buffer */ 353 0, /* tp_as_buffer */
354 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ 354 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
355 method_doc, /* tp_doc */ 355 method_doc, /* tp_doc */
356 (traverseproc)method_traverse, /* tp_traverse */ 356 (traverseproc)method_traverse, /* tp_traverse */
357 0, /* tp_clear */ 357 0, /* tp_clear */
358 method_richcompare, /* tp_richcompare */ 358 method_richcompare, /* tp_richcompare */
359 offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */ 359 offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */
360 0, /* tp_iter */ 360 0, /* tp_iter */
361 0, /* tp_iternext */ 361 0, /* tp_iternext */
362 method_methods, /* tp_methods */ 362 method_methods, /* tp_methods */
363 method_memberlist, /* tp_members */ 363 method_memberlist, /* tp_members */
364 method_getset, /* tp_getset */ 364 method_getset, /* tp_getset */
365 0, /* tp_base */ 365 0, /* tp_base */
366 0, /* tp_dict */ 366 0, /* tp_dict */
367 method_descr_get, /* tp_descr_get */ 367 method_descr_get, /* tp_descr_get */
368 0, /* tp_descr_set */ 368 0, /* tp_descr_set */
369 0, /* tp_dictoffset */ 369 0, /* tp_dictoffset */
370 0, /* tp_init */ 370 0, /* tp_init */
371 0, /* tp_alloc */ 371 0, /* tp_alloc */
372 method_new, /* tp_new */ 372 method_new, /* tp_new */
373
374 .tp_fastcall = (fastternaryfunc)method_call,
373 }; 375 };
374 376
375 /* Clear out the free list */ 377 /* Clear out the free list */
376 378
377 int 379 int
378 PyMethod_ClearFreeList(void) 380 PyMethod_ClearFreeList(void)
379 { 381 {
380 int freelist_size = numfree; 382 int freelist_size = numfree;
381 383
382 while (free_list) { 384 while (free_list) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 instancemethod_getset, /* tp_getset */ 641 instancemethod_getset, /* tp_getset */
640 0, /* tp_base */ 642 0, /* tp_base */
641 0, /* tp_dict */ 643 0, /* tp_dict */
642 instancemethod_descr_get, /* tp_descr_get */ 644 instancemethod_descr_get, /* tp_descr_get */
643 0, /* tp_descr_set */ 645 0, /* tp_descr_set */
644 0, /* tp_dictoffset */ 646 0, /* tp_dictoffset */
645 0, /* tp_init */ 647 0, /* tp_init */
646 0, /* tp_alloc */ 648 0, /* tp_alloc */
647 instancemethod_new, /* tp_new */ 649 instancemethod_new, /* tp_new */
648 }; 650 };
OLDNEW

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