Christian Heimes added the comment:
> Why such a strong opinion? 'sys' is pretty close to the VM too...
sys is a very important and often used module, too. I don't like the
idea to remove one module (types) and clutter an important module with
its content.
The list of types has grown pretty long and most of the types can't be
instantiated in Python. I fear that the types are going to confuse too
many people. However the types are useful for type checking and ABCs.
['PyCObject', '__doc__', '__name__', 'builtin_function',
'builtin_method', 'bytearray_iterator', 'bytes_iterator',
'callable_iterator', 'cell', 'classmethod_descriptor', 'cmpwrapper',
'code', 'dict_itemiterator', 'dict_items', 'dict_keyiterator',
'dict_keys', 'dict_valueiterator', 'dict_values', 'dictproxy',
'enumerate', 'frame', 'function', 'generator', 'getset_descriptor',
'instance_method', 'iterator', 'list_iterator', 'list_reverseiterator',
'longrange_iterator', 'member_descriptor', 'method_descriptor',
'module', 'range_iterator', 'reversed', 'set_iterator', 'sortwrapper',
'str_iterator', 'traceback', 'tuple_iterator', 'wrapper_descriptor']
Added file: http://bugs.python.org/file8829/py3k_pyvm2.patch
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1522>
__________________________________
Index: Include/iterobject.h
===================================================================
--- Include/iterobject.h (Revision 59215)
+++ Include/iterobject.h (Arbeitskopie)
@@ -6,12 +6,14 @@
#endif
PyAPI_DATA(PyTypeObject) PySeqIter_Type;
+PyAPI_DATA(PyTypeObject) PyCallIter_Type;
+PyAPI_DATA(PyTypeObject) PyZipIter_Type;
+PyAPI_DATA(PyTypeObject) PyCmpWrapper_Type;
#define PySeqIter_Check(op) (Py_Type(op) == &PySeqIter_Type)
PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
-PyAPI_DATA(PyTypeObject) PyCallIter_Type;
#define PyCallIter_Check(op) (Py_Type(op) == &PyCallIter_Type)
Index: Include/stringobject.h
===================================================================
--- Include/stringobject.h (Revision 59215)
+++ Include/stringobject.h (Arbeitskopie)
@@ -40,6 +40,7 @@
} PyStringObject;
PyAPI_DATA(PyTypeObject) PyString_Type;
+PyAPI_DATA(PyTypeObject) PyStringIter_Type;
#define PyString_Check(op) \
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_STRING_SUBCLASS)
Index: Include/dictobject.h
===================================================================
--- Include/dictobject.h (Revision 59215)
+++ Include/dictobject.h (Arbeitskopie)
@@ -89,11 +89,24 @@
};
PyAPI_DATA(PyTypeObject) PyDict_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
+PyAPI_DATA(PyTypeObject) PyDictKeys_Type;
+PyAPI_DATA(PyTypeObject) PyDictItems_Type;
+PyAPI_DATA(PyTypeObject) PyDictValues_Type;
#define PyDict_Check(op) \
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_DICT_SUBCLASS)
#define PyDict_CheckExact(op) (Py_Type(op) == &PyDict_Type)
+#define PyDictKeys_Check(op) (Py_Type(op) == &PyDictKeys_Type)
+#define PyDictItems_Check(op) (Py_Type(op) == &PyDictItems_Type)
+#define PyDictValues_Check(op) (Py_Type(op) == &PyDictValues_Type)
+/* This excludes Values, since they are not sets. */
+# define PyDictViewSet_Check(op) \
+ (PyDictKeys_Check(op) || PyDictItems_Check(op))
+
PyAPI_FUNC(PyObject *) PyDict_New(void);
PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
Index: Include/unicodeobject.h
===================================================================
--- Include/unicodeobject.h (Revision 59215)
+++ Include/unicodeobject.h (Arbeitskopie)
@@ -417,6 +417,7 @@
} PyUnicodeObject;
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
+PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
#define SSTATE_NOT_INTERNED 0
#define SSTATE_INTERNED_MORTAL 1
Index: Include/rangeobject.h
===================================================================
--- Include/rangeobject.h (Revision 59215)
+++ Include/rangeobject.h (Arbeitskopie)
@@ -16,6 +16,8 @@
*/
PyAPI_DATA(PyTypeObject) PyRange_Type;
+PyAPI_DATA(PyTypeObject) PyRangeIter_Type;
+PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type;
#define PyRange_Check(op) (Py_Type(op) == &PyRange_Type)
Index: Include/listobject.h
===================================================================
--- Include/listobject.h (Revision 59215)
+++ Include/listobject.h (Arbeitskopie)
@@ -39,6 +39,9 @@
} PyListObject;
PyAPI_DATA(PyTypeObject) PyList_Type;
+PyAPI_DATA(PyTypeObject) PyListIter_Type;
+PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
+PyAPI_DATA(PyTypeObject) PySortWrapper_Type;
#define PyList_Check(op) \
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_LIST_SUBCLASS)
Index: Include/tupleobject.h
===================================================================
--- Include/tupleobject.h (Revision 59215)
+++ Include/tupleobject.h (Arbeitskopie)
@@ -32,6 +32,7 @@
} PyTupleObject;
PyAPI_DATA(PyTypeObject) PyTuple_Type;
+PyAPI_DATA(PyTypeObject) PyTupleIter_Type;
#define PyTuple_Check(op) \
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Index: Include/descrobject.h
===================================================================
--- Include/descrobject.h (Revision 59215)
+++ Include/descrobject.h (Arbeitskopie)
@@ -67,7 +67,12 @@
void *d_wrapped; /* This can be any function pointer */
} PyWrapperDescrObject;
+PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
+PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
+PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
+PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
+PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
Index: Include/bytesobject.h
===================================================================
--- Include/bytesobject.h (Revision 59215)
+++ Include/bytesobject.h (Arbeitskopie)
@@ -29,6 +29,7 @@
/* Type object */
PyAPI_DATA(PyTypeObject) PyBytes_Type;
+PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
/* Type check macros */
#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
Index: Include/setobject.h
===================================================================
--- Include/setobject.h (Revision 59215)
+++ Include/setobject.h (Arbeitskopie)
@@ -58,6 +58,7 @@
PyAPI_DATA(PyTypeObject) PySet_Type;
PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
+PyAPI_DATA(PyTypeObject) PySetIter_Type;
/* Invariants for frozensets:
* data is immutable.
Index: Objects/dictobject.c
===================================================================
--- Objects/dictobject.c (Revision 59215)
+++ Objects/dictobject.c (Arbeitskopie)
@@ -1794,13 +1794,8 @@
return 0;
}
-
-extern PyTypeObject PyDictIterKey_Type; /* Forward */
-extern PyTypeObject PyDictIterValue_Type; /* Forward */
-extern PyTypeObject PyDictIterItem_Type; /* Forward */
static PyObject *dictiter_new(PyDictObject *, PyTypeObject *);
-
PyDoc_STRVAR(contains__doc__,
"D.__contains__(k) -> True if D has a key k, else False");
@@ -2397,19 +2392,6 @@
- if public then they should probably be in builtins
*/
-/* Forward */
-PyTypeObject PyDictKeys_Type;
-PyTypeObject PyDictItems_Type;
-PyTypeObject PyDictValues_Type;
-
-#define PyDictKeys_Check(obj) ((obj)->ob_type == &PyDictKeys_Type)
-#define PyDictItems_Check(obj) ((obj)->ob_type == &PyDictItems_Type)
-#define PyDictValues_Check(obj) ((obj)->ob_type == &PyDictValues_Type)
-
-/* This excludes Values, since they are not sets. */
-# define PyDictViewSet_Check(obj) \
- (PyDictKeys_Check(obj) || PyDictItems_Check(obj))
-
/* Return 1 if self is a subset of other, iterating over self;
0 if not; -1 if an error occurred. */
static int
Index: Objects/tupleobject.c
===================================================================
--- Objects/tupleobject.c (Revision 59215)
+++ Objects/tupleobject.c (Arbeitskopie)
@@ -840,7 +840,7 @@
PyTypeObject PyTupleIter_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "tupleiterator", /* tp_name */
+ "tuple_iterator", /* tp_name */
sizeof(tupleiterobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
Index: Objects/rangeobject.c
===================================================================
--- Objects/rangeobject.c (Revision 59215)
+++ Objects/rangeobject.c (Arbeitskopie)
@@ -367,7 +367,7 @@
{NULL, NULL} /* sentinel */
};
-PyTypeObject Pyrangeiter_Type = {
+PyTypeObject PyRangeIter_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"range_iterator", /* tp_name */
sizeof(rangeiterobject), /* tp_basicsize */
@@ -441,7 +441,7 @@
static PyObject *
int_range_iter(long start, long stop, long step)
{
- rangeiterobject *it = PyObject_New(rangeiterobject, &Pyrangeiter_Type);
+ rangeiterobject *it = PyObject_New(rangeiterobject, &PyRangeIter_Type);
if (it == NULL)
return NULL;
it->start = start;
@@ -519,9 +519,9 @@
return result;
}
-static PyTypeObject Pylongrangeiter_Type = {
+PyTypeObject PyLongRangeIter_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "rangeiterator", /* tp_name */
+ "longrange_iterator", /* tp_name */
sizeof(longrangeiterobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
@@ -567,7 +567,7 @@
PyLong_AsLong(r->stop),
PyLong_AsLong(r->step));
- it = PyObject_New(longrangeiterobject, &Pylongrangeiter_Type);
+ it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type);
if (it == NULL)
return NULL;
@@ -627,7 +627,7 @@
return int_range_iter(new_start, new_stop, -step);
}
- it = PyObject_New(longrangeiterobject, &Pylongrangeiter_Type);
+ it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type);
if (it == NULL)
return NULL;
Index: Objects/descrobject.c
===================================================================
--- Objects/descrobject.c (Revision 59216)
+++ Objects/descrobject.c (Arbeitskopie)
@@ -383,7 +383,7 @@
return 0;
}
-static PyTypeObject PyMethodDescr_Type = {
+PyTypeObject PyMethodDescr_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"method_descriptor",
sizeof(PyMethodDescrObject),
@@ -421,7 +421,7 @@
};
/* This is for METH_CLASS in C, not for "f = classmethod(f)" in Python! */
-static PyTypeObject PyClassMethodDescr_Type = {
+PyTypeObject PyClassMethodDescr_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"classmethod_descriptor",
sizeof(PyMethodDescrObject),
@@ -458,7 +458,7 @@
0, /* tp_descr_set */
};
-static PyTypeObject PyMemberDescr_Type = {
+PyTypeObject PyMemberDescr_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"member_descriptor",
sizeof(PyMemberDescrObject),
@@ -495,7 +495,7 @@
(descrsetfunc)member_set, /* tp_descr_set */
};
-static PyTypeObject PyGetSetDescr_Type = {
+PyTypeObject PyGetSetDescr_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"getset_descriptor",
sizeof(PyGetSetDescrObject),
@@ -786,7 +786,7 @@
return PyObject_RichCompare(v->dict, w, op);
}
-static PyTypeObject proxytype = {
+PyTypeObject PyDictProxy_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dictproxy", /* tp_name */
sizeof(proxyobject), /* tp_basicsize */
@@ -829,7 +829,7 @@
{
proxyobject *pp;
- pp = PyObject_GC_New(proxyobject, &proxytype);
+ pp = PyObject_GC_New(proxyobject, &PyDictProxy_Type);
if (pp != NULL) {
Py_INCREF(dict);
pp->dict = dict;
Index: Objects/listobject.c
===================================================================
--- Objects/listobject.c (Revision 59215)
+++ Objects/listobject.c (Arbeitskopie)
@@ -1790,7 +1790,7 @@
static void
sortwrapper_dealloc(sortwrapperobject *);
-static PyTypeObject sortwrapper_type = {
+PyTypeObject PySortWrapper_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"sortwrapper", /* tp_name */
sizeof(sortwrapperobject), /* tp_basicsize */
@@ -1822,7 +1822,7 @@
static PyObject *
sortwrapper_richcompare(sortwrapperobject *a, sortwrapperobject *b, int op)
{
- if (!PyObject_TypeCheck(b, &sortwrapper_type)) {
+ if (!PyObject_TypeCheck(b, &PySortWrapper_Type)) {
PyErr_SetString(PyExc_TypeError,
"expected a sortwrapperobject");
return NULL;
@@ -1846,7 +1846,7 @@
{
sortwrapperobject *so;
- so = PyObject_New(sortwrapperobject, &sortwrapper_type);
+ so = PyObject_New(sortwrapperobject, &PySortWrapper_Type);
if (so == NULL)
return NULL;
so->key = key;
@@ -1860,7 +1860,7 @@
{
PyObject *value;
- if (!PyObject_TypeCheck(so, &sortwrapper_type)) {
+ if (!PyObject_TypeCheck(so, &PySortWrapper_Type)) {
PyErr_SetString(PyExc_TypeError,
"expected a sortwrapperobject");
return NULL;
@@ -1893,8 +1893,8 @@
if (!PyArg_UnpackTuple(args, "", 2, 2, &x, &y))
return NULL;
- if (!PyObject_TypeCheck(x, &sortwrapper_type) ||
- !PyObject_TypeCheck(y, &sortwrapper_type)) {
+ if (!PyObject_TypeCheck(x, &PySortWrapper_Type) ||
+ !PyObject_TypeCheck(y, &PySortWrapper_Type)) {
PyErr_SetString(PyExc_TypeError,
"expected a sortwrapperobject");
return NULL;
@@ -1906,7 +1906,7 @@
PyDoc_STRVAR(cmpwrapper_doc, "cmp() wrapper for sort with custom keys.");
-static PyTypeObject cmpwrapper_type = {
+PyTypeObject PyCmpWrapper_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"cmpwrapper", /* tp_name */
sizeof(cmpwrapperobject), /* tp_basicsize */
@@ -1936,7 +1936,7 @@
{
cmpwrapperobject *co;
- co = PyObject_New(cmpwrapperobject, &cmpwrapper_type);
+ co = PyObject_New(cmpwrapperobject, &PyCmpWrapper_Type);
if (co == NULL)
return NULL;
Py_INCREF(cmpfunc);
Index: Objects/setobject.c
===================================================================
--- Objects/setobject.c (Revision 59215)
+++ Objects/setobject.c (Arbeitskopie)
@@ -849,7 +849,7 @@
return NULL;
}
-static PyTypeObject PySetIter_Type = {
+PyTypeObject PySetIter_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"set_iterator", /* tp_name */
sizeof(setiterobject), /* tp_basicsize */
Index: Objects/iterobject.c
===================================================================
--- Objects/iterobject.c (Revision 59215)
+++ Objects/iterobject.c (Arbeitskopie)
@@ -199,7 +199,7 @@
PyTypeObject PyCallIter_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "callable-iterator", /* tp_name */
+ "callable_iterator", /* tp_name */
sizeof(calliterobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
@@ -240,7 +240,7 @@
PyTupleObject *result; /* Reusable tuple for optimization */
} zipiterobject;
-static PyTypeObject PyZipIter_Type; /* Forward */
+ /* Forward */
PyObject *
_PyZip_CreateIter(PyObject* args)
@@ -367,7 +367,7 @@
return result;
}
-static PyTypeObject PyZipIter_Type = {
+PyTypeObject PyZipIter_Type = {
PyVarObject_HEAD_INIT(0, 0)
"zip_iterator", /* tp_name */
sizeof(zipiterobject), /* tp_basicsize */
Index: Makefile.pre.in
===================================================================
--- Makefile.pre.in (Revision 59215)
+++ Makefile.pre.in (Arbeitskopie)
@@ -328,6 +328,7 @@
LIBRARY_OBJS= \
Modules/_typesmodule.o \
Modules/getbuildinfo.o \
+ Modules/pyvm.o \
$(PARSER_OBJS) \
$(OBJECT_OBJS) \
$(PYTHON_OBJS) \
@@ -365,6 +366,7 @@
-rm -f $@
$(AR) cr $@ Modules/getbuildinfo.o
$(AR) cr $@ Modules/_typesmodule.o
+ $(AR) cr $@ Modules/pyvm.o
$(AR) cr $@ $(PARSER_OBJS)
$(AR) cr $@ $(OBJECT_OBJS)
$(AR) cr $@ $(PYTHON_OBJS)
Index: Modules/pyvm.c
===================================================================
--- Modules/pyvm.c (Revision 0)
+++ Modules/pyvm.c (Revision 0)
@@ -0,0 +1,92 @@
+/* pyvm module
+ Low level interface to Python's virtual machine and internal types.
+
+ Copyright (c) 2007 by Christian Heimes <[EMAIL PROTECTED]>
+ Licensed to PSF under a Contributor Agreement.
+ All rights reserved.
+*/
+
+#include "Python.h"
+#include "frameobject.h"
+
+typedef struct _typeinfo {
+ PyTypeObject *type;
+ char *name;
+} typeinfo;
+
+PyDoc_STRVAR(pyvm_doc,
+"Python Virtual Machine module\n");
+
+static PyMethodDef pyvm_methods[] = {
+ {NULL, NULL} /* sentinel */
+};
+
+PyMODINIT_FUNC
+initpyvm(void)
+{
+ char *name;
+ PyObject *mod;
+ typeinfo *ti;
+ typeinfo types[] = {
+ /* descriptors */
+ {&PyClassMethodDescr_Type, NULL},
+ {&PyGetSetDescr_Type, NULL},
+ {&PyMemberDescr_Type, NULL},
+ {&PyMethodDescr_Type, NULL},
+ {&PyWrapperDescr_Type, NULL},
+ /* functions */
+ {&PyCFunction_Type, "builtin_method"},
+ {&PyCFunction_Type, "builtin_function"}, /* alias */
+ {&PyFunction_Type, NULL},
+ {&PyMethod_Type, "instance_method"},
+ /* dict */
+ {&PyDictIterKey_Type, NULL},
+ {&PyDictIterValue_Type, NULL},
+ {&PyDictIterItem_Type, NULL},
+ {&PyDictKeys_Type, NULL},
+ {&PyDictItems_Type, NULL},
+ {&PyDictValues_Type, NULL},
+ {&PyDictProxy_Type, NULL},
+ /* iter */
+ {&PyBytesIter_Type, NULL},
+ {&PyCallIter_Type, "callable_iterator"},
+ {&PyLongRangeIter_Type, NULL},
+ {&PyListIter_Type, NULL},
+ {&PyListRevIter_Type, NULL},
+ {&PyRangeIter_Type, NULL},
+ {&PySeqIter_Type, NULL},
+ {&PySetIter_Type, NULL},
+ {&PyStringIter_Type, NULL},
+ {&PyTupleIter_Type, NULL},
+ {&PyUnicodeIter_Type, NULL},
+ /* other */
+ {&PyCObject_Type, NULL},
+ {&PyCode_Type, NULL},
+ {&PyFrame_Type, NULL},
+ {&PyGen_Type, NULL},
+ {&PyModule_Type, NULL},
+ {&PyTraceBack_Type, NULL},
+ {&PyCell_Type, NULL},
+ {&PyEnum_Type, NULL},
+ {&PyReversed_Type, NULL},
+ {&PySortWrapper_Type, NULL},
+ {&PyCmpWrapper_Type, NULL},
+ /* sentinel */
+ {NULL, NULL}
+ };
+
+ mod = Py_InitModule3("pyvm", pyvm_methods, pyvm_doc);
+ if (mod == NULL)
+ return;
+
+ ti = types;
+ while(ti->type != NULL) {
+ name = ti->name;
+ if (name == NULL)
+ name = (char*)ti->type->tp_name;
+ assert(name);
+ Py_INCREF(ti->type);
+ PyModule_AddObject(mod, name, (PyObject *)ti->type);
+ ti++;
+ }
+}
Eigenschaftsänderungen: Modules/pyvm.c
___________________________________________________________________
Name: svn:keywords
+ Id
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com