summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-01-28 03:53:08 (GMT)
committerFred Drake <fdrake@acm.org>2001-01-28 03:53:08 (GMT)
commit5cc2c8c3c8d9809c45fee8d638dae431b56e773d (patch)
treef9dccb28b0879426f3b0a57584f62b47c0a40a33
parent05473edbe5a4d4f96769062a13550d403dd42f17 (diff)
downloadcpython-5cc2c8c3c8d9809c45fee8d638dae431b56e773d.zip
cpython-5cc2c8c3c8d9809c45fee8d638dae431b56e773d.tar.gz
cpython-5cc2c8c3c8d9809c45fee8d638dae431b56e773d.tar.bz2
Re-factored PyInstance_New() into PyInstance_New() and PyInstance_NewRaw().
-rw-r--r--Objects/classobject.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 40ff983..60214a4 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -428,27 +428,48 @@ PyClass_IsSubclass(PyObject *class, PyObject *base)
/* Instance objects */
PyObject *
-PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)
+PyInstance_NewRaw(PyObject *klass, PyObject *dict)
{
- register PyInstanceObject *inst;
- PyObject *init;
- static PyObject *initstr;
- if (!PyClass_Check(class)) {
+ PyInstanceObject *inst;
+
+ if (!PyClass_Check(klass)) {
PyErr_BadInternalCall();
return NULL;
}
+ if (dict == NULL) {
+ dict = PyDict_New();
+ if (dict == NULL)
+ return NULL;
+ }
+ else {
+ if (!PyDict_Check(dict)) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+ Py_INCREF(dict);
+ }
inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
- if (inst == NULL)
- return NULL;
- inst->in_dict = PyDict_New();
- if (inst->in_dict == NULL) {
- inst = (PyInstanceObject *) PyObject_AS_GC(inst);
- PyObject_DEL(inst);
+ if (inst == NULL) {
+ Py_DECREF(dict);
return NULL;
}
- Py_INCREF(class);
- inst->in_class = (PyClassObject *)class;
+ Py_INCREF(klass);
+ inst->in_class = (PyClassObject *)klass;
+ inst->in_dict = dict;
PyObject_GC_Init(inst);
+ return (PyObject *)inst;
+}
+
+PyObject *
+PyInstance_New(PyObject *klass, PyObject *arg, PyObject *kw)
+{
+ register PyInstanceObject *inst;
+ PyObject *init;
+ static PyObject *initstr;
+
+ inst = (PyInstanceObject *) PyInstance_NewRaw(klass, NULL);
+ if (inst == NULL)
+ return NULL;
if (initstr == NULL)
initstr = PyString_InternFromString("__init__");
init = instance_getattr2(inst, initstr);