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

Delta Between Two Patch Sets: Objects/funcobject.c

Issue 29259: Add tp_fastcall to PyTypeObject: support FASTCALL calling convention for all callable objects
Left Patch Set: Created 3 years ago
Right Patch Set: Created 2 years, 11 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 1
2 /* Function object implementation */ 2 /* Function object implementation */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 #include "code.h" 5 #include "code.h"
6 #include "structmember.h" 6 #include "structmember.h"
7 7
8 PyObject * 8 PyObject *
9 PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname ) 9 PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname )
10 { 10 {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 315 }
316 Py_INCREF(value); 316 Py_INCREF(value);
317 Py_XSETREF(op->func_qualname, value); 317 Py_XSETREF(op->func_qualname, value);
318 return 0; 318 return 0;
319 } 319 }
320 320
321 static PyObject * 321 static PyObject *
322 func_get_defaults(PyFunctionObject *op) 322 func_get_defaults(PyFunctionObject *op)
323 { 323 {
324 if (op->func_defaults == NULL) { 324 if (op->func_defaults == NULL) {
325 Py_INCREF(Py_None); 325 Py_RETURN_NONE;
326 return Py_None;
327 } 326 }
328 Py_INCREF(op->func_defaults); 327 Py_INCREF(op->func_defaults);
329 return op->func_defaults; 328 return op->func_defaults;
330 } 329 }
331 330
332 static int 331 static int
333 func_set_defaults(PyFunctionObject *op, PyObject *value) 332 func_set_defaults(PyFunctionObject *op, PyObject *value)
334 { 333 {
335 /* Legal to del f.func_defaults. 334 /* Legal to del f.func_defaults.
336 * Can only set func_defaults to NULL or a tuple. */ 335 * Can only set func_defaults to NULL or a tuple. */
337 if (value == Py_None) 336 if (value == Py_None)
338 value = NULL; 337 value = NULL;
339 if (value != NULL && !PyTuple_Check(value)) { 338 if (value != NULL && !PyTuple_Check(value)) {
340 PyErr_SetString(PyExc_TypeError, 339 PyErr_SetString(PyExc_TypeError,
341 "__defaults__ must be set to a tuple object"); 340 "__defaults__ must be set to a tuple object");
342 return -1; 341 return -1;
343 } 342 }
344 Py_XINCREF(value); 343 Py_XINCREF(value);
345 Py_XSETREF(op->func_defaults, value); 344 Py_XSETREF(op->func_defaults, value);
346 return 0; 345 return 0;
347 } 346 }
348 347
349 static PyObject * 348 static PyObject *
350 func_get_kwdefaults(PyFunctionObject *op) 349 func_get_kwdefaults(PyFunctionObject *op)
351 { 350 {
352 if (op->func_kwdefaults == NULL) { 351 if (op->func_kwdefaults == NULL) {
353 Py_INCREF(Py_None); 352 Py_RETURN_NONE;
354 return Py_None;
355 } 353 }
356 Py_INCREF(op->func_kwdefaults); 354 Py_INCREF(op->func_kwdefaults);
357 return op->func_kwdefaults; 355 return op->func_kwdefaults;
358 } 356 }
359 357
360 static int 358 static int
361 func_set_kwdefaults(PyFunctionObject *op, PyObject *value) 359 func_set_kwdefaults(PyFunctionObject *op, PyObject *value)
362 { 360 {
363 if (value == Py_None) 361 if (value == Py_None)
364 value = NULL; 362 value = NULL;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 Py_VISIT(f->func_kwdefaults); 553 Py_VISIT(f->func_kwdefaults);
556 Py_VISIT(f->func_doc); 554 Py_VISIT(f->func_doc);
557 Py_VISIT(f->func_name); 555 Py_VISIT(f->func_name);
558 Py_VISIT(f->func_dict); 556 Py_VISIT(f->func_dict);
559 Py_VISIT(f->func_closure); 557 Py_VISIT(f->func_closure);
560 Py_VISIT(f->func_annotations); 558 Py_VISIT(f->func_annotations);
561 Py_VISIT(f->func_qualname); 559 Py_VISIT(f->func_qualname);
562 return 0; 560 return 0;
563 } 561 }
564 562
565 #if 0
566 static PyObject * 563 static PyObject *
567 function_call(PyObject *func, PyObject *args, PyObject *kwargs) 564 function_call(PyObject *func, PyObject *args, PyObject *kwargs)
568 { 565 {
569 PyObject **stack; 566 PyObject **stack;
570 Py_ssize_t nargs; 567 Py_ssize_t nargs;
571 568
572 stack = &PyTuple_GET_ITEM(args, 0); 569 stack = &PyTuple_GET_ITEM(args, 0);
573 nargs = PyTuple_GET_SIZE(args); 570 nargs = PyTuple_GET_SIZE(args);
574 return _PyFunction_FastCallDict(func, stack, nargs, kwargs); 571 return _PyFunction_FastCallDict(func, stack, nargs, kwargs);
575 } 572 }
576 #endif
577 573
578 /* Bind a function to an object */ 574 /* Bind a function to an object */
579 static PyObject * 575 static PyObject *
580 func_descr_get(PyObject *func, PyObject *obj, PyObject *type) 576 func_descr_get(PyObject *func, PyObject *obj, PyObject *type)
581 { 577 {
582 if (obj == Py_None || obj == NULL) { 578 if (obj == Py_None || obj == NULL) {
583 Py_INCREF(func); 579 Py_INCREF(func);
584 return func; 580 return func;
585 } 581 }
586 return PyMethod_New(func, obj); 582 return PyMethod_New(func, obj);
587 } 583 }
588 584
589 PyTypeObject PyFunction_Type = { 585 PyTypeObject PyFunction_Type = {
590 PyVarObject_HEAD_INIT(&PyType_Type, 0) 586 PyVarObject_HEAD_INIT(&PyType_Type, 0)
591 "function", 587 "function",
592 sizeof(PyFunctionObject), 588 sizeof(PyFunctionObject),
593 0, 589 0,
594 (destructor)func_dealloc, /* tp_dealloc */ 590 (destructor)func_dealloc, /* tp_dealloc */
595 0, /* tp_print */ 591 0, /* tp_print */
596 0, /* tp_getattr */ 592 0, /* tp_getattr */
597 0, /* tp_setattr */ 593 0, /* tp_setattr */
598 0, /* tp_reserved */ 594 0, /* tp_reserved */
599 (reprfunc)func_repr, /* tp_repr */ 595 (reprfunc)func_repr, /* tp_repr */
600 0, /* tp_as_number */ 596 0, /* tp_as_number */
601 0, /* tp_as_sequence */ 597 0, /* tp_as_sequence */
602 0, /* tp_as_mapping */ 598 0, /* tp_as_mapping */
603 0, /* tp_hash */ 599 0, /* tp_hash */
604 #if 0
605 function_call, /* tp_call */ 600 function_call, /* tp_call */
606 #else
607 /* FIXME: revert this change, 0 is used to test fastcall_wrapper() */
608 0, /* tp_call */
609 #endif
610 0, /* tp_str */ 601 0, /* tp_str */
611 0, /* tp_getattro */ 602 0, /* tp_getattro */
612 0, /* tp_setattro */ 603 0, /* tp_setattro */
613 0, /* tp_as_buffer */ 604 0, /* tp_as_buffer */
614 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC 605 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
615 | Py_TPFLAGS_HAVE_FASTCALL, /* tp_flags */
616 func_doc, /* tp_doc */ 606 func_doc, /* tp_doc */
617 (traverseproc)func_traverse, /* tp_traverse */ 607 (traverseproc)func_traverse, /* tp_traverse */
618 0, /* tp_clear */ 608 0, /* tp_clear */
619 0, /* tp_richcompare */ 609 0, /* tp_richcompare */
620 offsetof(PyFunctionObject, func_weakreflist), /* tp_weaklistoffset */ 610 offsetof(PyFunctionObject, func_weakreflist), /* tp_weaklistoffset */
621 0, /* tp_iter */ 611 0, /* tp_iter */
622 0, /* tp_iternext */ 612 0, /* tp_iternext */
623 0, /* tp_methods */ 613 0, /* tp_methods */
624 func_memberlist, /* tp_members */ 614 func_memberlist, /* tp_members */
625 func_getsetlist, /* tp_getset */ 615 func_getsetlist, /* tp_getset */
626 0, /* tp_base */ 616 0, /* tp_base */
627 0, /* tp_dict */ 617 0, /* tp_dict */
628 func_descr_get, /* tp_descr_get */ 618 func_descr_get, /* tp_descr_get */
629 0, /* tp_descr_set */ 619 0, /* tp_descr_set */
630 offsetof(PyFunctionObject, func_dict), /* tp_dictoffset */ 620 offsetof(PyFunctionObject, func_dict), /* tp_dictoffset */
631 0, /* tp_init */ 621 0, /* tp_init */
632 0, /* tp_alloc */ 622 0, /* tp_alloc */
633 func_new, /* tp_new */ 623 func_new, /* tp_new */
634 0, /* tp_free */ 624
635 0, /* tp_is_gc */ 625 .tp_fastcall = _PyFunction_FastCallKeywords,
636 0, /* tp_bases */
637 0, /* tp_mro */
638 0, /* tp_cache */
639 0, /* tp_subclasses */
640 0, /* tp_weaklist */
641 0, /* tp_del */
642 0, /* tp_version_tag */
643 0, /* tp_finalize */
644 _PyFunction_FastCallKeywords, /* tp_fastcall */
645 }; 626 };
646 627
647 628
648 /* Class method object */ 629 /* Class method object */
649 630
650 /* A class method receives the class as implicit first argument, 631 /* A class method receives the class as implicit first argument,
651 just like an instance method receives the instance. 632 just like an instance method receives the instance.
652 To declare a class method, use this idiom: 633 To declare a class method, use this idiom:
653 634
654 class C: 635 class C:
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 PyStaticMethod_New(PyObject *callable) 981 PyStaticMethod_New(PyObject *callable)
1001 { 982 {
1002 staticmethod *sm = (staticmethod *) 983 staticmethod *sm = (staticmethod *)
1003 PyType_GenericAlloc(&PyStaticMethod_Type, 0); 984 PyType_GenericAlloc(&PyStaticMethod_Type, 0);
1004 if (sm != NULL) { 985 if (sm != NULL) {
1005 Py_INCREF(callable); 986 Py_INCREF(callable);
1006 sm->sm_callable = callable; 987 sm->sm_callable = callable;
1007 } 988 }
1008 return (PyObject *)sm; 989 return (PyObject *)sm;
1009 } 990 }
LEFTRIGHT

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