[Python-checkins] CVS: python/dist/src/Modules newmodule.c,2.30,2.31
Fred L. Drake
fdrake@users.sourceforge.net
Sat, 27 Jan 2001 19:55:11 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv14741/Modules
Modified Files:
newmodule.c
Log Message:
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
about the internal initialization of instance objects. Make the
dict parameter optional, and allow None as equivalent to omission.
Index: newmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/newmodule.c,v
retrieving revision 2.30
retrieving revision 2.31
diff -C2 -r2.30 -r2.31
*** newmodule.c 2001/01/25 20:07:56 2.30
--- newmodule.c 2001/01/28 03:55:09 2.31
***************
*** 6,30 ****
static char new_instance_doc[] =
! "Create an instance object from (CLASS, DICT) without calling its __init__().";
static PyObject *
new_instance(PyObject* unused, PyObject* args)
{
! PyObject* klass;
! PyObject *dict;
! PyInstanceObject *inst;
! if (!PyArg_ParseTuple(args, "O!O!:instance",
! &PyClass_Type, &klass,
! &PyDict_Type, &dict))
return NULL;
! inst = PyObject_New(PyInstanceObject, &PyInstance_Type);
! if (inst == NULL)
return NULL;
! Py_INCREF(klass);
! Py_INCREF(dict);
! inst->in_class = (PyClassObject *)klass;
! inst->in_dict = dict;
! PyObject_GC_Init(inst);
! return (PyObject *)inst;
}
--- 6,32 ----
static char new_instance_doc[] =
! "Create an instance object from (CLASS [, DICT]) without calling its\n\
! __init__() method. DICT must be a dictionary or None.";
static PyObject *
new_instance(PyObject* unused, PyObject* args)
{
! PyObject *klass;
! PyObject *dict = NULL;
!
! if (!PyArg_ParseTuple(args, "O!|O:instance",
! &PyClass_Type, &klass, &dict))
return NULL;
!
! if (dict == Py_None)
! dict = NULL;
! else if (dict == NULL)
! /* do nothing */;
! else if (!PyDict_Check(dict)) {
! PyErr_SetString(PyExc_TypeError,
! "new.instance() second arg must be dictionary or None");
return NULL;
! }
! return PyInstance_NewRaw(klass, dict);
}