Kaydet (Commit) a6b7c714 authored tarafından Barry Warsaw's avatar Barry Warsaw

Renamed.

üst 5de1f8da
...@@ -31,155 +31,158 @@ PERFORMANCE OF THIS SOFTWARE. ...@@ -31,155 +31,158 @@ PERFORMANCE OF THIS SOFTWARE.
/* Module new -- create new objects of various types */ /* Module new -- create new objects of various types */
#include "allobjects.h" #include "Python.h"
#include "compile.h" #include "compile.h"
static char new_instance_doc[] = static char new_instance_doc[] =
"Create an instance object from (CLASS, DICT) without calling its __init__()."; "Create an instance object from (CLASS, DICT) without calling its __init__().";
static object * static PyObject *
new_instance(unused, args) new_instance(unused, args)
object* unused; PyObject* unused;
object* args; PyObject* args;
{ {
object* klass; PyObject* klass;
object *dict; PyObject *dict;
instanceobject *inst; PyInstanceObject *inst;
if (!newgetargs(args, "O!O!", if (!PyArg_ParseTuple(args, "O!O!",
&Classtype, &klass, &PyClass_Type, &klass,
&Dicttype, &dict)) &PyDict_Type, &dict))
return NULL; return NULL;
inst = NEWOBJ(instanceobject, &Instancetype); inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
if (inst == NULL) if (inst == NULL)
return NULL; return NULL;
INCREF(klass); Py_INCREF(klass);
INCREF(dict); Py_INCREF(dict);
inst->in_class = (classobject *)klass; inst->in_class = (PyClassObject *)klass;
inst->in_dict = dict; inst->in_dict = dict;
return (object *)inst; return (PyObject *)inst;
} }
static char new_im_doc[] = static char new_im_doc[] =
"Create a instance method object from (FUNCTION, INSTANCE, CLASS)."; "Create a instance method object from (FUNCTION, INSTANCE, CLASS).";
static object * static PyObject *
new_instancemethod(unused, args) new_instancemethod(unused, args)
object* unused; PyObject* unused;
object* args; PyObject* args;
{ {
object* func; PyObject* func;
object* self; PyObject* self;
object* classObj; PyObject* classObj;
if (!newgetargs(args, "O!O!O!", if (!PyArg_ParseTuple(args, "O!O!O!",
&Functype, &func, &PyFunction_Type, &func,
&Instancetype, &self, &PyInstance_Type, &self,
&Classtype, &classObj)) &PyClass_Type, &classObj))
return NULL; return NULL;
return newinstancemethodobject(func, self, classObj); return PyMethod_New(func, self, classObj);
} }
static char new_function_doc[] = static char new_function_doc[] =
"Create a function object from (CODE, GLOBALS, [NAME, ARGDEFS])."; "Create a function object from (CODE, GLOBALS, [NAME, ARGDEFS]).";
static object * static PyObject *
new_function(unused, args) new_function(unused, args)
object* unused; PyObject* unused;
object* args; PyObject* args;
{ {
object* code; PyObject* code;
object* globals; PyObject* globals;
object* name = None; PyObject* name = Py_None;
object* defaults = None; PyObject* defaults = Py_None;
funcobject* newfunc; PyFunctionObject* newfunc;
if (!newgetargs(args, "O!O!|SO!", if (!PyArg_ParseTuple(args, "O!O!|SO!",
&Codetype, &code, &PyCode_Type, &code,
&Mappingtype, &globals, &PyDict_Type, &globals,
&name, &name,
&Tupletype, &defaults)) &PyTuple_Type, &defaults))
return NULL; return NULL;
newfunc = (funcobject *)newfuncobject(code, globals); newfunc = (PyFunctionObject *)PyFunction_New(code, globals);
if (newfunc == NULL) if (newfunc == NULL)
return NULL; return NULL;
if (name != None) { if (name != Py_None) {
XINCREF(name); Py_XINCREF(name);
XDECREF(newfunc->func_name); Py_XDECREF(newfunc->func_name);
newfunc->func_name = name; newfunc->func_name = name;
} }
if (defaults != NULL) { if (defaults != NULL) {
XINCREF(defaults); Py_XINCREF(defaults);
XDECREF(newfunc->func_defaults); Py_XDECREF(newfunc->func_defaults);
newfunc->func_defaults = defaults; newfunc->func_defaults = defaults;
} }
return (object *)newfunc; return (PyObject *)newfunc;
} }
static char new_code_doc[] = static char new_code_doc[] =
"Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME)."; "Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME).";
static object * static PyObject *
new_code(unused, args) new_code(unused, args)
object* unused; PyObject* unused;
object* args; PyObject* args;
{ {
int argcount; int argcount;
int nlocals; int nlocals;
int flags; int flags;
object* code; PyObject* code;
object* consts; PyObject* consts;
object* names; PyObject* names;
object* varnames; PyObject* varnames;
object* filename; PyObject* filename;
object* name; PyObject* name;
if (!newgetargs(args, "iiiSO!O!O!SS", if (!PyArg_ParseTuple(args, "iiiSO!O!O!SS",
&argcount, &nlocals, &flags, /* These are new */ &argcount, &nlocals, &flags, /* These are new */
&code, &Tupletype, &consts, &Tupletype, &names, &code,
&Tupletype, &varnames, /* These are new */ &PyTuple_Type, &consts,
&filename, &name)) &PyTuple_Type, &names,
&PyTuple_Type, &varnames, /* These are new */
&filename, &name))
return NULL; return NULL;
return (object *)newcodeobject(argcount, nlocals, flags, return (PyObject *)PyCode_New(argcount, nlocals, flags,
code, consts, names, varnames, filename, name); code, consts, names, varnames,
filename, name);
} }
static char new_module_doc[] = static char new_module_doc[] =
"Create a module object from (NAME)."; "Create a module object from (NAME).";
static object * static PyObject *
new_module(unused, args) new_module(unused, args)
object* unused; PyObject* unused;
object* args; PyObject* args;
{ {
char *name; char *name;
if (!newgetargs(args, "s", &name)) if (!PyArg_ParseTuple(args, "s", &name))
return NULL; return NULL;
return newmoduleobject(name); return PyModule_New(name);
} }
static char new_class_doc[] = static char new_class_doc[] =
"Create a class object from (NAME, BASE_CLASSES, DICT)."; "Create a class object from (NAME, BASE_CLASSES, DICT).";
static object * static PyObject *
new_class(unused, args) new_class(unused, args)
object* unused; PyObject* unused;
object* args; PyObject* args;
{ {
object * name; PyObject * name;
object * classes; PyObject * classes;
object * dict; PyObject * dict;
if (!newgetargs(args, "SO!O!", &name, &Tupletype, &classes, if (!PyArg_ParseTuple(args, "SO!O!", &name, &PyTuple_Type, &classes,
&Mappingtype, &dict)) &PyDict_Type, &dict))
return NULL; return NULL;
return newclassobject(classes, dict, name); return PyClass_New(classes, dict, name);
} }
static struct methodlist new_methods[] = { static PyMethodDef new_methods[] = {
{"instance", new_instance, 1, new_instance_doc}, {"instance", new_instance, 1, new_instance_doc},
{"instancemethod", new_instancemethod, 1, new_im_doc}, {"instancemethod", new_instancemethod, 1, new_im_doc},
{"function", new_function, 1, new_function_doc}, {"function", new_function, 1, new_function_doc},
...@@ -197,6 +200,6 @@ You need to know a great deal about the interpreter to use this!"; ...@@ -197,6 +200,6 @@ You need to know a great deal about the interpreter to use this!";
void void
initnew() initnew()
{ {
initmodule4("new", new_methods, new_doc, (object *)NULL, Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
PYTHON_API_VERSION); PYTHON_API_VERSION);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment