]> granicus.if.org Git - python/commitdiff
SF patch 568629 by Oren Tirosh: types made callable.
authorGuido van Rossum <guido@python.org>
Fri, 14 Jun 2002 20:41:17 +0000 (20:41 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 14 Jun 2002 20:41:17 +0000 (20:41 +0000)
These built-in functions are replaced by their (now callable) type:

    slice()
    buffer()

and these types can also be called (but have no built-in named
function named after them)

    classobj (type name used to be "class")
    code
    function
    instance
    instancemethod (type name used to be "instance method")

The module "new" has been replaced with a small backward compatibility
placeholder in Python.

A large portion of the patch simply removes the new module from
various platform-specific build recipes.  The following binary Mac
project files still have references to it:

    Mac/Build/PythonCore.mcp
    Mac/Build/PythonStandSmall.mcp
    Mac/Build/PythonStandalone.mcp

[I've tweaked the code layout and the doc strings here and there, and
added a comment to types.py about StringTypes vs. basestring.  --Guido]

17 files changed:
Lib/types.py
Mac/Distributions/dev.include
Mac/MPW/Makefile
Misc/BeOS-setup.py
Modules/Setup.dist
Objects/bufferobject.c
Objects/classobject.c
Objects/descrobject.c
Objects/funcobject.c
Objects/sliceobject.c
PC/os2vacpp/makefile
PC/os2vacpp/makefile.omk
PCbuild/pythoncore.dsp
Python/bltinmodule.c
Python/compile.c
Python/dynload_aix.c
RISCOS/Makefile

index da0e59748781afa4572e4f10a326a49bc9bcd6a2..fc0fbfb40181761ffefa5b8cff403e657d4cd0a1 100644 (file)
@@ -23,13 +23,17 @@ except NameError:
     pass
 
 StringType = str
+
+# StringTypes is already outdated.  Instead of writing "type(x) in
+# types.StringTypes", you should use "isinstance(x, basestring)".  But
+# we keep around for compatibility with Python 2.2.
 try:
     UnicodeType = unicode
     StringTypes = (StringType, UnicodeType)
 except NameError:
     StringTypes = (StringType,)
 
-BufferType = type(buffer(''))
+BufferType = buffer
 
 TupleType = tuple
 ListType = list
@@ -77,7 +81,7 @@ except TypeError:
         pass
     tb = None; del tb
 
-SliceType = type(slice(0))
+SliceType = slice
 EllipsisType = type(Ellipsis)
 
 DictProxyType = type(TypeType.__dict__)
index 70c75cb2d9484832a24069513eb54c11d9c41a92..4ac3b51c47fb7857d2da0ed973fc16e16b4469d6 100644 (file)
 (':Modules:md5module.c', None)
 (':Modules:mmapmodule.c', None)
 (':Modules:mpzmodule.c', None)
-(':Modules:newmodule.c', None)
 (':Modules:nismodule.c', None)
 (':Modules:operator.c', None)
 (':Modules:parsermodule.c', None)
index 3c06014cf6468845faab91cc3ed3fcd29894df3d..817198ca46825e35327de7cb4b4adf3f81ec5a2a 100644 (file)
@@ -77,7 +77,6 @@ ALL = 
        "{Objs}"moduleobject.c.o ¶
        "{Objs}"myreadline.c.o ¶
        "{Objs}"mystrtoul.c.o ¶
-       "{Objs}"newmodule.c.o ¶
        "{Objs}"nfullpath.c.o ¶
        "{Objs}"node.c.o ¶
        "{Objs}"object.c.o ¶
@@ -473,9 +472,6 @@ xxmodule.slb 
 "{Objs}"mathmodule.c.o Ä "{Top}"Modules:mathmodule.c
        {CC} "{Top}"Modules:mathmodule.c -o "{Objs}"mathmodule.c.o -s mathmodule.c {CFlags}
 
-"{Objs}"newmodule.c.o Ä "{Top}"Modules:newmodule.c
-       {CC} "{Top}"Modules:newmodule.c -o "{Objs}"newmodule.c.o -s newmodule.c {CFlags}
-
 "{Objs}"parsermodule.c.o Ä "{Top}"Modules:parsermodule.c
        {CC} "{Top}"Modules:parsermodule.c -o "{Objs}"parsermodule.c.o -s parsermodule.c {CFlags}
 
index 8f9b7766b297c19597eebb6eea191ef3318115b2..53b62b7191ce1c7f6a0ba80c4c6f0dfaae1b963f 100644 (file)
@@ -232,10 +232,6 @@ class PyBuildExt(build_ext):
         # (NIST's Secure Hash Algorithm.)
         exts.append( Extension('sha', ['shamodule.c']) )
 
-        # Tommy Burnette's 'new' module (creates new empty objects of certain
-        # kinds):
-        exts.append( Extension('new', ['newmodule.c']) )
-
         # Helper module for various ascii-encoders
         exts.append( Extension('binascii', ['binascii.c']) )
 
index 0c7e0152e8da5e9b81e4b8d93bc837510dc56be8..f3bc312e2249ee6fcdd9b66dfff541020aa8f21a 100644 (file)
@@ -110,7 +110,6 @@ PYTHONPATH=$(COREPYTHONPATH)
 
 posix posixmodule.c            # posix (UNIX) system calls
 _sre _sre.c                    # Fredrik Lundh's new regular expressions
-new newmodule.c                        # Tommy Burnette's 'new' module
 
 # The rest of the modules listed in this file are all commented out by
 # default.  Usually they can be detected and built as dynamically
index 51b9ef9b14315dd6f4bc6e5517cfc5b5532c03ac..031c000b8ea9cd6bfebf4a3a4baa19822d033f83 100644 (file)
@@ -155,6 +155,27 @@ PyBuffer_New(int size)
 
 /* Methods */
 
+static PyObject *
+buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
+{
+       PyObject *ob;
+       int offset = 0;
+       int size = Py_END_OF_BUFFER;
+
+       if ( !PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size) )
+           return NULL;
+       return PyBuffer_FromObject(ob, offset, size);
+}
+
+PyDoc_STRVAR(buffer_doc,
+"buffer(object [, offset[, size]])\n\
+\n\
+Create a new buffer object which references the given object.\n\
+The buffer will reference a slice of the target object from the\n\
+start of the object (or at the specified offset). The slice will\n\
+extend to the end of the target object (or with the specified size).");
+
+
 static void
 buffer_dealloc(PyBufferObject *self)
 {
@@ -539,5 +560,22 @@ PyTypeObject PyBuffer_Type = {
        0,                                      /* tp_setattro */
        &buffer_as_buffer,                      /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT,                     /* tp_flags */
-       0,                                      /* tp_doc */
+       buffer_doc,                             /* tp_doc */
+       0,                                      /* tp_traverse */
+       0,                                      /* tp_clear */
+       0,                                      /* tp_richcompare */
+       0,                                      /* tp_weaklistoffset */
+       0,                                      /* tp_iter */
+       0,                                      /* tp_iternext */
+       0,                                      /* tp_methods */        
+       0,                                      /* tp_members */
+       0,                                      /* tp_getset */
+       0,                                      /* tp_base */
+       0,                                      /* tp_dict */
+       0,                                      /* tp_descr_get */
+       0,                                      /* tp_descr_set */
+       0,                                      /* tp_dictoffset */
+       0,                                      /* tp_init */
+       0,                                      /* tp_alloc */
+       buffer_new,                             /* tp_new */
 };
index 1033ab67f8945a6a3b88749229893bedc543266b..979c967a06f72915cf37a1e47202ff558a3b5819 100644 (file)
@@ -149,6 +149,27 @@ PyMethod_Class(PyObject *im)
        return ((PyMethodObject *)im)->im_class;
 }
 
+PyDoc_STRVAR(class_doc,
+"classobj(name, bases, dict)\n\
+\n\
+Create a class object.  The name must be a string; the second argument\n\
+a tuple of classes, and the third a dictionary.");
+
+static PyObject *
+new_class(PyObject* unused, PyObject* args)
+{
+       PyObject *name;
+       PyObject *classes;
+       PyObject *dict;
+  
+       if (!PyArg_ParseTuple(args, "SO!O!:class",
+                             &name,
+                             &PyTuple_Type, &classes,
+                             &PyDict_Type, &dict))
+               return NULL;
+       return PyClass_New(classes, dict, name);
+}
+
 static PyObject *
 class_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
@@ -435,7 +456,7 @@ class_traverse(PyClassObject *o, visitproc visit, void *arg)
 PyTypeObject PyClass_Type = {
        PyObject_HEAD_INIT(&PyType_Type)
        0,
-       "class",
+       "classobj",
        sizeof(PyClassObject),
        0,
        (destructor)class_dealloc,              /* tp_dealloc */
@@ -454,7 +475,7 @@ PyTypeObject PyClass_Type = {
        (setattrofunc)class_setattr,            /* tp_setattro */
        0,                                      /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
-       0,                                      /* tp_doc */
+       class_doc,                              /* tp_doc */
        (traverseproc)class_traverse,           /* tp_traverse */
        0,                                      /* tp_clear */
        0,                                      /* tp_richcompare */
@@ -575,6 +596,34 @@ PyInstance_New(PyObject *klass, PyObject *arg, PyObject *kw)
 
 /* Instance methods */
 
+PyDoc_STRVAR(instance_doc,
+"instance(class[, dict])\n\
+\n\
+Create an instance without calling its __init__() method.\n\
+The class must be a classic class.\n\
+If present, dict must be a dictionary or None.");
+
+static PyObject *
+instance_new(PyTypeObject* type, PyObject* args, PyObject *kw)
+{
+       PyObject *klass;
+       PyObject *dict = Py_None;
+
+       if (!PyArg_ParseTuple(args, "O!|O:instance",
+                             &PyClass_Type, &klass, &dict))
+               return NULL;
+
+       if (dict == Py_None)
+               dict = NULL;
+       else if (!PyDict_Check(dict)) {
+               PyErr_SetString(PyExc_TypeError,
+                     "instance() second arg must be dictionary or None");
+               return NULL;
+       }
+       return PyInstance_NewRaw(klass, dict);
+}
+
+
 static void
 instance_dealloc(register PyInstanceObject *inst)
 {
@@ -2014,13 +2063,24 @@ PyTypeObject PyInstance_Type = {
        (setattrofunc)instance_setattr,         /* tp_setattro */
        0,                                      /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES,/*tp_flags*/
-       0,                                      /* tp_doc */
+       instance_doc,                           /* tp_doc */
        (traverseproc)instance_traverse,        /* tp_traverse */
        0,                                      /* tp_clear */
        instance_richcompare,                   /* tp_richcompare */
        offsetof(PyInstanceObject, in_weakreflist), /* tp_weaklistoffset */
        (getiterfunc)instance_getiter,          /* tp_iter */
        (iternextfunc)instance_iternext,        /* tp_iternext */
+       0,                                      /* tp_methods */
+       0,                                      /* tp_members */
+       0,                                      /* tp_getset */
+       0,                                      /* tp_base */
+       0,                                      /* tp_dict */
+       0,                                      /* tp_descr_get */
+       0,                                      /* tp_descr_set */
+       0,                                      /* tp_dictoffset */
+       0,                                      /* tp_init */
+       0,                                      /* tp_alloc */
+       instance_new,                           /* tp_new */
 };
 
 
@@ -2125,6 +2185,31 @@ instancemethod_getattro(PyObject *obj, PyObject *name)
        return NULL;
 }
 
+PyDoc_STRVAR(instancemethod_doc,
+"instancemethod(function, instance, class)\n\
+\n\
+Create an instance method object.");
+
+static PyObject *
+instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw)
+{
+       PyObject *func;
+       PyObject *self;
+       PyObject *classObj;
+
+       if (!PyArg_ParseTuple(args, "OOO:instancemethod",
+                             &func, &self, &classObj))
+               return NULL;
+       if (!PyCallable_Check(func)) {
+               PyErr_SetString(PyExc_TypeError,
+                               "first argument must be callable");
+               return NULL;
+       }
+       if (self == Py_None)
+               self = NULL;
+       return PyMethod_New(func, self, classObj);
+}
+
 static void
 instancemethod_dealloc(register PyMethodObject *im)
 {
@@ -2362,7 +2447,7 @@ instancemethod_descr_get(PyObject *meth, PyObject *obj, PyObject *class)
 PyTypeObject PyMethod_Type = {
        PyObject_HEAD_INIT(&PyType_Type)
        0,
-       "instance method",
+       "instancemethod",
        sizeof(PyMethodObject),
        0,
        (destructor)instancemethod_dealloc,     /* tp_dealloc */
@@ -2381,7 +2466,7 @@ PyTypeObject PyMethod_Type = {
        PyObject_GenericSetAttr,                /* tp_setattro */
        0,                                      /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
-       0,                                      /* tp_doc */
+       instancemethod_doc,                     /* tp_doc */
        (traverseproc)instancemethod_traverse,  /* tp_traverse */
        0,                                      /* tp_clear */
        0,                                      /* tp_richcompare */
@@ -2396,6 +2481,9 @@ PyTypeObject PyMethod_Type = {
        instancemethod_descr_get,               /* tp_descr_get */
        0,                                      /* tp_descr_set */
        0,                                      /* tp_dictoffset */
+       0,                                      /* tp_init */
+       0,                                      /* tp_alloc */
+       instancemethod_new,                     /* tp_new */
 };
 
 /* Clear out the free list */
index 1130f86e009dd33c7af1d3632b2000be097cab26..2d926b44180fc9c84e54c793cbc4a3be545bcd24 100644 (file)
@@ -725,7 +725,7 @@ proxy_traverse(PyObject *self, visitproc visit, void *arg)
 static PyTypeObject proxytype = {
        PyObject_HEAD_INIT(&PyType_Type)
        0,                                      /* ob_size */
-       "dict-proxy",                           /* tp_name */
+       "dictproxy",                            /* tp_name */
        sizeof(proxyobject),                    /* tp_basicsize */
        0,                                      /* tp_itemsize */
        /* methods */
index f96d0dd9bff87085ea248ab38b275c005c9eab85..4eac035eb55db6a08c542f6b6c81e3dd6785d293 100644 (file)
@@ -266,6 +266,52 @@ static PyGetSetDef func_getsetlist[] = {
        {NULL} /* Sentinel */
 };
 
+PyDoc_STRVAR(func_doc,
+"function(code, globals[, name[, argdefs]])\n\
+\n\
+Create a function object from a code object and a dictionary.\n\
+The optional name string overrides the name from the code object.\n\
+The optional argdefs tuple specifies the default argument values.");
+
+static PyObject *
+func_new(PyTypeObject* type, PyObject* args, PyObject* kw)
+{
+       PyObject *code;
+       PyObject *globals;
+       PyObject *name = Py_None;
+       PyObject *defaults = Py_None;
+       PyFunctionObject *newfunc;
+
+       if (!PyArg_ParseTuple(args, "O!O!|OO!:function",
+                             &PyCode_Type, &code,
+                             &PyDict_Type, &globals,
+                             &name,
+                             &PyTuple_Type, &defaults))
+               return NULL;
+       if (name != Py_None && !PyString_Check(name)) {
+               PyErr_SetString(PyExc_TypeError,
+                               "arg 3 (name) must be None or string");
+               return NULL;
+       }
+
+       newfunc = (PyFunctionObject *)PyFunction_New(code, globals);
+       if (newfunc == NULL)
+               return NULL;
+
+       if (name != Py_None) {
+               Py_XINCREF(name);
+               Py_XDECREF(newfunc->func_name);
+               newfunc->func_name = name;
+       }
+       if (defaults != Py_None) {
+               Py_XINCREF(defaults);
+               Py_XDECREF(newfunc->func_defaults);
+               newfunc->func_defaults  = defaults;
+       }
+
+       return (PyObject *)newfunc;
+}
+
 static void
 func_dealloc(PyFunctionObject *op)
 {
@@ -415,7 +461,7 @@ PyTypeObject PyFunction_Type = {
        PyObject_GenericSetAttr,                /* tp_setattro */
        0,                                      /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
-       0,                                      /* tp_doc */
+       func_doc,                               /* tp_doc */
        (traverseproc)func_traverse,            /* tp_traverse */
        0,                                      /* tp_clear */
        0,                                      /* tp_richcompare */
@@ -430,6 +476,9 @@ PyTypeObject PyFunction_Type = {
        func_descr_get,                         /* tp_descr_get */
        0,                                      /* tp_descr_set */
        offsetof(PyFunctionObject, func_dict),  /* tp_dictoffset */
+       0,                                      /* tp_init */
+       0,                                      /* tp_alloc */
+       func_new,                               /* tp_new */
 };
 
 
index 9a268b715ce29a6a4c1f87aa4fcf80259344fbae..a43644d18fa3350acde6d14ea51dbbc50cd57143 100644 (file)
@@ -164,6 +164,30 @@ PySlice_GetIndicesEx(PySliceObject *r, int length,
        return 0;
 }
 
+static PyObject *
+slice_new(PyTypeObject *type, PyObject *args, PyObject *kw)
+{
+       PyObject *start, *stop, *step;
+
+       start = stop = step = NULL;
+
+       if (!PyArg_ParseTuple(args, "O|OO:slice", &start, &stop, &step))
+               return NULL;
+
+       /* This swapping of stop and start is to maintain similarity with
+          range(). */
+       if (stop == NULL) {
+               stop = start;
+               start = NULL;
+       }
+       return PySlice_New(start, stop, step);
+}
+
+PyDoc_STRVAR(slice_doc,
+"slice([start,] stop[, step])\n\
+\n\
+Create a slice object.  This is used for extended slicing (e.g. a[0:10:2]).");
+
 static void
 slice_dealloc(PySliceObject *r)
 {
@@ -240,7 +264,7 @@ PyTypeObject PySlice_Type = {
        0,                                      /* tp_setattro */
        0,                                      /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT,                     /* tp_flags */
-       0,                                      /* tp_doc */
+       slice_doc,                              /* tp_doc */
        0,                                      /* tp_traverse */
        0,                                      /* tp_clear */
        0,                                      /* tp_richcompare */
@@ -252,4 +276,10 @@ PyTypeObject PySlice_Type = {
        0,                                      /* tp_getset */
        0,                                      /* tp_base */
        0,                                      /* tp_dict */
+       0,                                      /* tp_descr_get */
+       0,                                      /* tp_descr_set */
+       0,                                      /* tp_dictoffset */
+       0,                                      /* tp_init */
+       0,                                      /* tp_alloc */
+       slice_new,                              /* tp_new */
 };
index 029b9011b5c4cf7d03f22aeef03b08edab1f3754..680a8e6b3b3f5b5a696cb59adc0be2699948bd63 100644 (file)
@@ -182,7 +182,6 @@ MODULES             =                              \
                   $(PATHOBJ)\MathModule.obj    \
                   $(PATHOBJ)\MD5c.obj          \
                   $(PATHOBJ)\MD5Module.obj     \
-                  $(PATHOBJ)\NewModule.obj     \
                   $(PATHOBJ)\Operator.obj      \
                   $(PATHOBJ)\PCREModule.obj    \
                   $(PATHOBJ)\PyPCRE.obj        \
@@ -806,20 +805,6 @@ mpzmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \
         $(PY_INCLUDE)\sliceobject.h $(PY_INCLUDE)\stringobject.h \
         $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h
 
-newmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \
-        $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\compile.h $(PY_INCLUDE)\complexobject.h \
-        pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \
-        $(PY_INCLUDE)\floatobject.h $(PY_INCLUDE)\funcobject.h $(PY_INCLUDE)\import.h \
-        $(PY_INCLUDE)\intobject.h $(PY_INCLUDE)\intrcheck.h $(PY_INCLUDE)\listobject.h \
-        $(PY_INCLUDE)\longobject.h $(PY_INCLUDE)\methodobject.h \
-        $(PY_INCLUDE)\modsupport.h $(PY_INCLUDE)\moduleobject.h $(PY_INCLUDE)\mymalloc.h \
-        $(PY_INCLUDE)\myproto.h $(PY_INCLUDE)\object.h $(PY_INCLUDE)\objimpl.h \
-        $(PY_INCLUDE)\pydebug.h $(PY_INCLUDE)\pyerrors.h $(PY_INCLUDE)\pyfpe.h \
-        $(PY_INCLUDE)\pystate.h $(PY_INCLUDE)\python.h $(PY_INCLUDE)\pythonrun.h \
-        $(PY_INCLUDE)\rangeobject.h $(PY_INCLUDE)\sliceobject.h \
-        $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \
-        $(PY_INCLUDE)\tupleobject.h
-
 nismodule.obj: $(PY_INCLUDE)\abstract.h $(OS2TCPIP)\Include\sys\time.h $(PY_INCLUDE)\ceval.h \
         $(PY_INCLUDE)\classobject.h $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h \
         pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \
index 6b90e89459b5bfc6be14bfd23c73cc6623ca4832..0d11b6a29f3c40660e63fa5bdac3104adc7d57c6 100644 (file)
@@ -152,7 +152,6 @@ MODULES             =                   \
                   MathModule.obj    \
                   MD5c.obj          \
                   MD5Module.obj     \
-                  NewModule.obj     \
                   Operator.obj      \
                   PosixModule.obj   \
                   RegexModule.obj   \
@@ -619,14 +618,6 @@ mpzmodule.obj: abstract.h ceval.h classobject.h cobject.h \
         pyerrors.h pyfpe.h pystate.h python.h pythonrun.h rangeobject.h \
         sliceobject.h stringobject.h sysmodule.h traceback.h tupleobject.h
 
-newmodule.obj: abstract.h ceval.h classobject.h cobject.h compile.h \
-        complexobject.h pyconfig.h dictobject.h fileobject.h floatobject.h \
-        funcobject.h import.h intobject.h intrcheck.h listobject.h \
-        longobject.h methodobject.h modsupport.h moduleobject.h mymalloc.h \
-        myproto.h object.h objimpl.h pydebug.h pyerrors.h pyfpe.h \
-        pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \
-        stringobject.h sysmodule.h traceback.h tupleobject.h
-
 nismodule.obj: abstract.h c:\mptn\include\sys\time.h ceval.h classobject.h \
         cobject.h complexobject.h pyconfig.h dictobject.h fileobject.h \
         floatobject.h funcobject.h import.h intobject.h intrcheck.h \
index 1c32bf1d5f4c7c6a45c8bef4a324d9ed046cc4ab..77b826891f09ed4d440a549c5379349abb5925d8 100644 (file)
@@ -1253,21 +1253,6 @@ SOURCE=..\Python\mystrtoul.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\Modules\newmodule.c\r
-\r
-!IF  "$(CFG)" == "pythoncore - Win32 Release"\r
-\r
-!ELSEIF  "$(CFG)" == "pythoncore - Win32 Debug"\r
-\r
-!ELSEIF  "$(CFG)" == "pythoncore - Win32 Alpha Debug"\r
-\r
-!ELSEIF  "$(CFG)" == "pythoncore - Win32 Alpha Release"\r
-\r
-!ENDIF \r
-\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=..\Parser\node.c\r
 \r
 !IF  "$(CFG)" == "pythoncore - Win32 Release"\r
index 8f28ea693c01f0b252b4bd592807b9a9b43b18f6..712639107df7785d7fe9f8776d78f7cde3b3b7b8 100644 (file)
@@ -106,27 +106,6 @@ and keyword arguments taken from the optional dictionary kwargs.\n\
 Note that classes are callable, as are instances with a __call__() method.");
 
 
-static PyObject *
-builtin_buffer(PyObject *self, PyObject *args)
-{
-       PyObject *ob;
-       int offset = 0;
-       int size = Py_END_OF_BUFFER;
-
-       if ( !PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size) )
-           return NULL;
-       return PyBuffer_FromObject(ob, offset, size);
-}
-
-PyDoc_STRVAR(buffer_doc,
-"buffer(object [, offset[, size]]) -> object\n\
-\n\
-Create a new buffer object which references the given object.\n\
-The buffer will reference a slice of the target object from the\n\
-start of the object (or at the specified offset). The slice will\n\
-extend to the end of the target object (or with the specified size).");
-
-
 static PyObject *
 builtin_callable(PyObject *self, PyObject *v)
 {
@@ -1078,31 +1057,6 @@ PyDoc_STRVAR(len_doc,
 Return the number of items of a sequence or mapping.");
 
 
-static PyObject *
-builtin_slice(PyObject *self, PyObject *args)
-{
-       PyObject *start, *stop, *step;
-
-       start = stop = step = NULL;
-
-       if (!PyArg_ParseTuple(args, "O|OO:slice", &start, &stop, &step))
-               return NULL;
-
-       /* This swapping of stop and start is to maintain similarity with
-          range(). */
-       if (stop == NULL) {
-               stop = start;
-               start = NULL;
-       }
-       return PySlice_New(start, stop, step);
-}
-
-PyDoc_STRVAR(slice_doc,
-"slice([start,] stop[, step]) -> slice object\n\
-\n\
-Create a slice object.  This is used for slicing by the Numeric extensions.");
-
-
 static PyObject *
 builtin_locals(PyObject *self)
 {
@@ -1775,7 +1729,6 @@ static PyMethodDef builtin_methods[] = {
        {"__import__",  builtin___import__, METH_VARARGS, import_doc},
        {"abs",         builtin_abs,        METH_O, abs_doc},
        {"apply",       builtin_apply,      METH_VARARGS, apply_doc},
-       {"buffer",      builtin_buffer,     METH_VARARGS, buffer_doc},
        {"callable",    builtin_callable,   METH_O, callable_doc},
        {"chr",         builtin_chr,        METH_VARARGS, chr_doc},
        {"cmp",         builtin_cmp,        METH_VARARGS, cmp_doc},
@@ -1813,7 +1766,6 @@ static PyMethodDef builtin_methods[] = {
        {"repr",        builtin_repr,       METH_O, repr_doc},
        {"round",       builtin_round,      METH_VARARGS, round_doc},
        {"setattr",     builtin_setattr,    METH_VARARGS, setattr_doc},
-       {"slice",       builtin_slice,      METH_VARARGS, slice_doc},
 #ifdef Py_USING_UNICODE
        {"unichr",      builtin_unichr,     METH_VARARGS, unichr_doc},
 #endif
@@ -1849,6 +1801,7 @@ _PyBuiltin_Init(void)
        SETBUILTIN("True",              Py_True);
        SETBUILTIN("basestring",        &PyBaseString_Type);
        SETBUILTIN("bool",              &PyBool_Type);
+       SETBUILTIN("buffer",            &PyBuffer_Type);
        SETBUILTIN("classmethod",       &PyClassMethod_Type);
 #ifndef WITHOUT_COMPLEX
        SETBUILTIN("complex",           &PyComplex_Type);
@@ -1861,6 +1814,7 @@ _PyBuiltin_Init(void)
        SETBUILTIN("list",              &PyList_Type);
        SETBUILTIN("long",              &PyLong_Type);
        SETBUILTIN("object",            &PyBaseObject_Type);
+       SETBUILTIN("slice",             &PySlice_Type);
        SETBUILTIN("staticmethod",      &PyStaticMethod_Type);
        SETBUILTIN("str",               &PyString_Type);
        SETBUILTIN("super",             &PySuper_Type);
index 4bbe44f7c981725a59eea060f1a775bdd9ecc881..b0e125de8eb4b4fa25497243cb168598284f7dd6 100644 (file)
@@ -91,6 +91,69 @@ static PyMemberDef code_memberlist[] = {
        {NULL}  /* Sentinel */
 };
 
+PyDoc_STRVAR(code_doc,
+"code(argcount, nlocals, stacksize, flags, codestring, constants, names,\n\
+      varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]])\n\
+\n\
+Create a code object.  Not for the faint of heart.");
+
+static PyObject *
+code_new(PyTypeObject *type, PyObject *args, PyObject *kw)
+{
+       int argcount;
+       int nlocals;
+       int stacksize;
+       int flags;
+       PyObject *code;
+       PyObject *consts;
+       PyObject *names;
+       PyObject *varnames;
+       PyObject *freevars = NULL;
+       PyObject *cellvars = NULL;
+       PyObject *filename;
+       PyObject *name;
+       int firstlineno;
+       PyObject *lnotab;
+
+       if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS|O!O!:code",
+                             &argcount, &nlocals, &stacksize, &flags,
+                             &code,
+                             &PyTuple_Type, &consts,
+                             &PyTuple_Type, &names,
+                             &PyTuple_Type, &varnames,
+                             &filename, &name,
+                             &firstlineno, &lnotab,
+                             &PyTuple_Type, &freevars,
+                             &PyTuple_Type, &cellvars))
+               return NULL;
+
+       if (freevars == NULL || cellvars == NULL) {
+               PyObject *empty = PyTuple_New(0);
+               if (empty == NULL)
+                   return NULL;
+               if (freevars == NULL) {
+                   freevars = empty;
+                   Py_INCREF(freevars);
+               }
+               if (cellvars == NULL) {
+                   cellvars = empty;
+                   Py_INCREF(cellvars);
+               }
+               Py_DECREF(empty);
+       }
+
+       if (!PyObject_CheckReadBuffer(code)) {
+               PyErr_SetString(PyExc_TypeError,
+                 "bytecode object must be a single-segment read-only buffer");
+               return NULL;
+       }
+
+       return (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags,
+                                     code, consts, names, varnames,
+                                     freevars, cellvars, filename, name,
+                                     firstlineno, lnotab); 
+}
+
 static void
 code_dealloc(PyCodeObject *co)
 {
@@ -200,7 +263,7 @@ PyTypeObject PyCode_Type = {
        0,                              /* tp_setattro */
        0,                              /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT,             /* tp_flags */
-       0,                              /* tp_doc */
+       code_doc,                       /* tp_doc */
        0,                              /* tp_traverse */
        0,                              /* tp_clear */
        0,                              /* tp_richcompare */
@@ -217,7 +280,7 @@ PyTypeObject PyCode_Type = {
        0,                              /* tp_dictoffset */
        0,                              /* tp_init */
        0,                              /* tp_alloc */
-       0,                              /* tp_new */
+       code_new,                       /* tp_new */
 };
 
 #define NAME_CHARS \
index 4e39c31d43f3082d8974041f7e796b9395c1cfee..bb26c07248ba7f30553f0fb9840b83144a449e30 100644 (file)
@@ -104,19 +104,6 @@ aix_getoldmodules(void **modlistptr)
        return 0;
 }
 
-static int
-aix_bindnewmodule(void *newmoduleptr, void *modlistptr)
-{
-       register ModulePtr modptr;
-
-       /*
-       -- Bind the new module with the list of loaded modules.
-       */
-       for (modptr = (ModulePtr)modlistptr; modptr; modptr = modptr->next)
-               if (loadbind(0, modptr->entry, newmoduleptr) != 0)
-                       return -1;
-       return 0;
-}
 
 static void
 aix_loaderror(const char *pathname)
@@ -192,10 +179,6 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                aix_loaderror(pathname);
                return NULL;
        }
-       if (aix_bindnewmodule((void *)p, staticmodlistptr) == -1) {
-               aix_loaderror(pathname);
-               return NULL;
-       }
 
        return p;
 }
index 649404bcf0e14445dbf5eec85db812c2f3917a01..bcfca81402a3cac6d31d33e704f3e902d01aa45f 100644 (file)
@@ -264,9 +264,6 @@ $(LIB_PYTHON):      $(OBJECTS)
        $(LINK) -aof -o @.^.Modules.o.md5link @.^.Modules.o.md5c @.^.Modules.o.md5module
        $(MAKEDLK) -d @.^.Lib.md5/pyd -s s.linktab -o @.^.Modules.o.md5link -e initmd5
 
-@.^.Lib.new/pyd: @.^.Modules.o.newmodule s.linktab
-       $(MAKEDLK) -d @.^.Lib.new/pyd -s s.linktab -o @.^.Modules.o.newmodule -e initnew
-
 @.^.Lib.operator/pyd: @.^.Modules.o.operator s.linktab
        $(MAKEDLK) -d @.^.Lib.operator/pyd -s s.linktab -o @.^.Modules.o.operator -e initoperator