@@ -149,6 +149,27 @@ PyMethod_Class(PyObject *im)
149149 return ((PyMethodObject * )im )-> im_class ;
150150}
151151
152+ PyDoc_STRVAR (class_doc ,
153+ "classobj(name, bases, dict)\n\
154+ \n\
155+ Create a class object. The name must be a string; the second argument\n\
156+ a tuple of classes, and the third a dictionary." );
157+
158+ static PyObject *
159+ new_class (PyObject * unused , PyObject * args )
160+ {
161+ PyObject * name ;
162+ PyObject * classes ;
163+ PyObject * dict ;
164+
165+ if (!PyArg_ParseTuple (args , "SO!O!:class" ,
166+ & name ,
167+ & PyTuple_Type , & classes ,
168+ & PyDict_Type , & dict ))
169+ return NULL ;
170+ return PyClass_New (classes , dict , name );
171+ }
172+
152173static PyObject *
153174class_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
154175{
@@ -435,7 +456,7 @@ class_traverse(PyClassObject *o, visitproc visit, void *arg)
435456PyTypeObject PyClass_Type = {
436457 PyObject_HEAD_INIT (& PyType_Type )
437458 0 ,
438- "class " ,
459+ "classobj " ,
439460 sizeof (PyClassObject ),
440461 0 ,
441462 (destructor )class_dealloc , /* tp_dealloc */
@@ -454,7 +475,7 @@ PyTypeObject PyClass_Type = {
454475 (setattrofunc )class_setattr , /* tp_setattro */
455476 0 , /* tp_as_buffer */
456477 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,/* tp_flags */
457- 0 , /* tp_doc */
478+ class_doc , /* tp_doc */
458479 (traverseproc )class_traverse , /* tp_traverse */
459480 0 , /* tp_clear */
460481 0 , /* tp_richcompare */
@@ -575,6 +596,34 @@ PyInstance_New(PyObject *klass, PyObject *arg, PyObject *kw)
575596
576597/* Instance methods */
577598
599+ PyDoc_STRVAR (instance_doc ,
600+ "instance(class[, dict])\n\
601+ \n\
602+ Create an instance without calling its __init__() method.\n\
603+ The class must be a classic class.\n\
604+ If present, dict must be a dictionary or None." );
605+
606+ static PyObject *
607+ instance_new (PyTypeObject * type , PyObject * args , PyObject * kw )
608+ {
609+ PyObject * klass ;
610+ PyObject * dict = Py_None ;
611+
612+ if (!PyArg_ParseTuple (args , "O!|O:instance" ,
613+ & PyClass_Type , & klass , & dict ))
614+ return NULL ;
615+
616+ if (dict == Py_None )
617+ dict = NULL ;
618+ else if (!PyDict_Check (dict )) {
619+ PyErr_SetString (PyExc_TypeError ,
620+ "instance() second arg must be dictionary or None" );
621+ return NULL ;
622+ }
623+ return PyInstance_NewRaw (klass , dict );
624+ }
625+
626+
578627static void
579628instance_dealloc (register PyInstanceObject * inst )
580629{
@@ -2014,13 +2063,24 @@ PyTypeObject PyInstance_Type = {
20142063 (setattrofunc )instance_setattr , /* tp_setattro */
20152064 0 , /* tp_as_buffer */
20162065 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES ,/*tp_flags*/
2017- 0 , /* tp_doc */
2066+ instance_doc , /* tp_doc */
20182067 (traverseproc )instance_traverse , /* tp_traverse */
20192068 0 , /* tp_clear */
20202069 instance_richcompare , /* tp_richcompare */
20212070 offsetof(PyInstanceObject , in_weakreflist ), /* tp_weaklistoffset */
20222071 (getiterfunc )instance_getiter , /* tp_iter */
20232072 (iternextfunc )instance_iternext , /* tp_iternext */
2073+ 0 , /* tp_methods */
2074+ 0 , /* tp_members */
2075+ 0 , /* tp_getset */
2076+ 0 , /* tp_base */
2077+ 0 , /* tp_dict */
2078+ 0 , /* tp_descr_get */
2079+ 0 , /* tp_descr_set */
2080+ 0 , /* tp_dictoffset */
2081+ 0 , /* tp_init */
2082+ 0 , /* tp_alloc */
2083+ instance_new , /* tp_new */
20242084};
20252085
20262086
@@ -2125,6 +2185,31 @@ instancemethod_getattro(PyObject *obj, PyObject *name)
21252185 return NULL ;
21262186}
21272187
2188+ PyDoc_STRVAR (instancemethod_doc ,
2189+ "instancemethod(function, instance, class)\n\
2190+ \n\
2191+ Create an instance method object." );
2192+
2193+ static PyObject *
2194+ instancemethod_new (PyTypeObject * type , PyObject * args , PyObject * kw )
2195+ {
2196+ PyObject * func ;
2197+ PyObject * self ;
2198+ PyObject * classObj ;
2199+
2200+ if (!PyArg_ParseTuple (args , "OOO:instancemethod" ,
2201+ & func , & self , & classObj ))
2202+ return NULL ;
2203+ if (!PyCallable_Check (func )) {
2204+ PyErr_SetString (PyExc_TypeError ,
2205+ "first argument must be callable" );
2206+ return NULL ;
2207+ }
2208+ if (self == Py_None )
2209+ self = NULL ;
2210+ return PyMethod_New (func , self , classObj );
2211+ }
2212+
21282213static void
21292214instancemethod_dealloc (register PyMethodObject * im )
21302215{
@@ -2362,7 +2447,7 @@ instancemethod_descr_get(PyObject *meth, PyObject *obj, PyObject *class)
23622447PyTypeObject PyMethod_Type = {
23632448 PyObject_HEAD_INIT (& PyType_Type )
23642449 0 ,
2365- "instance method " ,
2450+ "instancemethod " ,
23662451 sizeof (PyMethodObject ),
23672452 0 ,
23682453 (destructor )instancemethod_dealloc , /* tp_dealloc */
@@ -2381,7 +2466,7 @@ PyTypeObject PyMethod_Type = {
23812466 PyObject_GenericSetAttr , /* tp_setattro */
23822467 0 , /* tp_as_buffer */
23832468 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,/* tp_flags */
2384- 0 , /* tp_doc */
2469+ instancemethod_doc , /* tp_doc */
23852470 (traverseproc )instancemethod_traverse , /* tp_traverse */
23862471 0 , /* tp_clear */
23872472 0 , /* tp_richcompare */
@@ -2396,6 +2481,9 @@ PyTypeObject PyMethod_Type = {
23962481 instancemethod_descr_get , /* tp_descr_get */
23972482 0 , /* tp_descr_set */
23982483 0 , /* tp_dictoffset */
2484+ 0 , /* tp_init */
2485+ 0 , /* tp_alloc */
2486+ instancemethod_new , /* tp_new */
23992487};
24002488
24012489/* Clear out the free list */
0 commit comments