[Python-checkins] r84328 - in python/branches/pep-0384: Include/Python.h Include/cellobject.h Include/classobject.h Include/code.h Include/fileobject.h Include/frameobject.h Include/funcobject.h Include/genobject.h Include/import.h Include/marshal.h Include/object.h Include/parsetok.h Include/pyarena.h Include/pydebug.h Include/pyerrors.h Include/pythonrun.h Include/symtable.h Include/token.h Include/typeslots.h Makefile.pre.in Objects/typeobject.c Objects/typeslots.inc Objects/typeslots.py

martin.v.loewis python-checkins at python.org
Thu Aug 26 18:58:15 CEST 2010


Author: martin.v.loewis
Date: Thu Aug 26 18:58:15 2010
New Revision: 84328

Log:
Wrap code with Py_LIMITED_API, define PyType_FromSpec.


Added:
   python/branches/pep-0384/Include/typeslots.h
   python/branches/pep-0384/Objects/typeslots.inc
   python/branches/pep-0384/Objects/typeslots.py
Modified:
   python/branches/pep-0384/Include/Python.h
   python/branches/pep-0384/Include/cellobject.h
   python/branches/pep-0384/Include/classobject.h
   python/branches/pep-0384/Include/code.h
   python/branches/pep-0384/Include/fileobject.h
   python/branches/pep-0384/Include/frameobject.h
   python/branches/pep-0384/Include/funcobject.h
   python/branches/pep-0384/Include/genobject.h
   python/branches/pep-0384/Include/import.h
   python/branches/pep-0384/Include/marshal.h
   python/branches/pep-0384/Include/object.h
   python/branches/pep-0384/Include/parsetok.h
   python/branches/pep-0384/Include/pyarena.h
   python/branches/pep-0384/Include/pydebug.h
   python/branches/pep-0384/Include/pyerrors.h
   python/branches/pep-0384/Include/pythonrun.h
   python/branches/pep-0384/Include/symtable.h
   python/branches/pep-0384/Include/token.h
   python/branches/pep-0384/Makefile.pre.in
   python/branches/pep-0384/Objects/typeobject.c

Modified: python/branches/pep-0384/Include/Python.h
==============================================================================
--- python/branches/pep-0384/Include/Python.h	(original)
+++ python/branches/pep-0384/Include/Python.h	Thu Aug 26 18:58:15 2010
@@ -98,6 +98,7 @@
 #include "warnings.h"
 #include "weakrefobject.h"
 
+
 #include "codecs.h"
 #include "pyerrors.h"
 

Modified: python/branches/pep-0384/Include/cellobject.h
==============================================================================
--- python/branches/pep-0384/Include/cellobject.h	(original)
+++ python/branches/pep-0384/Include/cellobject.h	Thu Aug 26 18:58:15 2010
@@ -1,5 +1,5 @@
 /* Cell object interface */
-
+#ifndef Py_LIMITED_API
 #ifndef Py_CELLOBJECT_H
 #define Py_CELLOBJECT_H
 #ifdef __cplusplus
@@ -26,3 +26,4 @@
 }
 #endif
 #endif /* !Py_TUPLEOBJECT_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/classobject.h
==============================================================================
--- python/branches/pep-0384/Include/classobject.h	(original)
+++ python/branches/pep-0384/Include/classobject.h	Thu Aug 26 18:58:15 2010
@@ -2,6 +2,7 @@
 
 /* Revealing some structures (not for general use) */
 
+#ifndef Py_LIMITED_API
 #ifndef Py_CLASSOBJECT_H
 #define Py_CLASSOBJECT_H
 #ifdef __cplusplus
@@ -54,3 +55,4 @@
 }
 #endif
 #endif /* !Py_CLASSOBJECT_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/code.h
==============================================================================
--- python/branches/pep-0384/Include/code.h	(original)
+++ python/branches/pep-0384/Include/code.h	Thu Aug 26 18:58:15 2010
@@ -1,5 +1,6 @@
 /* Definitions for bytecode */
 
+#ifndef Py_LIMITED_API
 #ifndef Py_CODE_H
 #define Py_CODE_H
 #ifdef __cplusplus
@@ -103,3 +104,4 @@
 }
 #endif
 #endif /* !Py_CODE_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/fileobject.h
==============================================================================
--- python/branches/pep-0384/Include/fileobject.h	(original)
+++ python/branches/pep-0384/Include/fileobject.h	Thu Aug 26 18:58:15 2010
@@ -14,7 +14,9 @@
 PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
 PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
 PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
+#endif
 
 /* The default encoding used by the platform file system APIs
    If non-NULL, this is different than the default encoding for strings

Modified: python/branches/pep-0384/Include/frameobject.h
==============================================================================
--- python/branches/pep-0384/Include/frameobject.h	(original)
+++ python/branches/pep-0384/Include/frameobject.h	Thu Aug 26 18:58:15 2010
@@ -1,6 +1,7 @@
 
 /* Frame object interface */
 
+#ifndef Py_LIMITED_API
 #ifndef Py_FRAMEOBJECT_H
 #define Py_FRAMEOBJECT_H
 #ifdef __cplusplus
@@ -85,3 +86,4 @@
 }
 #endif
 #endif /* !Py_FRAMEOBJECT_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/funcobject.h
==============================================================================
--- python/branches/pep-0384/Include/funcobject.h	(original)
+++ python/branches/pep-0384/Include/funcobject.h	Thu Aug 26 18:58:15 2010
@@ -1,6 +1,6 @@
 
 /* Function object interface */
-
+#ifndef Py_LIMITED_API
 #ifndef Py_FUNCOBJECT_H
 #define Py_FUNCOBJECT_H
 #ifdef __cplusplus
@@ -84,3 +84,4 @@
 }
 #endif
 #endif /* !Py_FUNCOBJECT_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/genobject.h
==============================================================================
--- python/branches/pep-0384/Include/genobject.h	(original)
+++ python/branches/pep-0384/Include/genobject.h	Thu Aug 26 18:58:15 2010
@@ -1,6 +1,7 @@
 
 /* Generator object interface */
 
+#ifndef Py_LIMITED_API
 #ifndef Py_GENOBJECT_H
 #define Py_GENOBJECT_H
 #ifdef __cplusplus
@@ -38,3 +39,4 @@
 }
 #endif
 #endif /* !Py_GENOBJECT_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/import.h
==============================================================================
--- python/branches/pep-0384/Include/import.h	(original)
+++ python/branches/pep-0384/Include/import.h	Thu Aug 26 18:58:15 2010
@@ -38,8 +38,10 @@
 #define _PyImport_ReleaseLock() 1
 #endif
 
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(struct filedescr *) _PyImport_FindModule(
 	const char *, PyObject *, char *, size_t, FILE **, PyObject **);
+#endif
 PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr *);
 PyAPI_FUNC(void) _PyImport_ReInitLock(void);
 

Modified: python/branches/pep-0384/Include/marshal.h
==============================================================================
--- python/branches/pep-0384/Include/marshal.h	(original)
+++ python/branches/pep-0384/Include/marshal.h	Thu Aug 26 18:58:15 2010
@@ -13,10 +13,12 @@
 PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int);
 PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
 
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *);
 PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *);
 PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *);
 PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *);
+#endif
 PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
 
 #ifdef __cplusplus

Modified: python/branches/pep-0384/Include/object.h
==============================================================================
--- python/branches/pep-0384/Include/object.h	(original)
+++ python/branches/pep-0384/Include/object.h	Thu Aug 26 18:58:15 2010
@@ -61,6 +61,10 @@
 #define Py_REF_DEBUG
 #endif
 
+#if defined(Py_LIMITED_API) && defined(Py_REF_DEBUG)
+#error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
+#endif
+
 #ifdef Py_TRACE_REFS
 /* Define pointers to support a doubly-linked list of all live heap objects. */
 #define _PyObject_HEAD_EXTRA            \
@@ -269,7 +273,13 @@
 
 typedef void (*freefunc)(void *);
 typedef void (*destructor)(PyObject *);
+#ifndef Py_LIMITED_API
+/* We can't provide a full compile-time check that limited-API
+   users won't implement tp_print. However, not defining printfunc
+   and making tp_print of a different function pointer type
+   should at least cause a warning in most cases. */
 typedef int (*printfunc)(PyObject *, FILE *, int);
+#endif
 typedef PyObject *(*getattrfunc)(PyObject *, char *);
 typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
 typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
@@ -285,6 +295,9 @@
 typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
 typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
 
+#ifdef Py_LIMITED_API
+typedef struct _typeobject PyTypeObject; /* opaque */
+#else
 typedef struct _typeobject {
     PyObject_VAR_HEAD
     const char *tp_name; /* For printing, in format "<module>.<name>" */
@@ -372,6 +385,23 @@
     struct _typeobject *tp_next;
 #endif
 } PyTypeObject;
+#endif
+
+typedef struct{
+    int slot;    /* slot id, see below */
+    void *pfunc; /* function pointer */
+} PyType_Slot;
+
+typedef struct{
+    const char* name;
+    const char* doc;
+    int basicsize;
+    int itemsize;
+    int flags;
+    PyType_Slot *slots; /* terminated by slot==0. */
+} PyType_Spec;
+
+PyObject* PyType_FromSpec(PyType_Spec*);
 
 
 /* The *real* layout of a type object when allocated on the heap */
@@ -419,7 +449,9 @@
 PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
 
 /* Generic operations on objects */
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
+#endif
 PyAPI_FUNC(void) _Py_BreakPoint(void);
 PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
 PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);

Modified: python/branches/pep-0384/Include/parsetok.h
==============================================================================
--- python/branches/pep-0384/Include/parsetok.h	(original)
+++ python/branches/pep-0384/Include/parsetok.h	Thu Aug 26 18:58:15 2010
@@ -1,6 +1,6 @@
 
 /* Parser-tokenizer link interface */
-
+#ifndef Py_LIMITED_API
 #ifndef Py_PARSETOK_H
 #define Py_PARSETOK_H
 #ifdef __cplusplus
@@ -64,3 +64,4 @@
 }
 #endif
 #endif /* !Py_PARSETOK_H */
+#endif /* !Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/pyarena.h
==============================================================================
--- python/branches/pep-0384/Include/pyarena.h	(original)
+++ python/branches/pep-0384/Include/pyarena.h	Thu Aug 26 18:58:15 2010
@@ -1,6 +1,7 @@
 /* An arena-like memory interface for the compiler.
  */
 
+#ifndef Py_LIMITED_API
 #ifndef Py_PYARENA_H
 #define Py_PYARENA_H
 
@@ -60,3 +61,4 @@
 #endif
 
 #endif /* !Py_PYARENA_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/pydebug.h
==============================================================================
--- python/branches/pep-0384/Include/pydebug.h	(original)
+++ python/branches/pep-0384/Include/pydebug.h	Thu Aug 26 18:58:15 2010
@@ -1,4 +1,4 @@
-
+#ifndef Py_LIMITED_API
 #ifndef Py_PYDEBUG_H
 #define Py_PYDEBUG_H
 #ifdef __cplusplus
@@ -31,3 +31,4 @@
 }
 #endif
 #endif /* !Py_PYDEBUG_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/pyerrors.h
==============================================================================
--- python/branches/pep-0384/Include/pyerrors.h	(original)
+++ python/branches/pep-0384/Include/pyerrors.h	Thu Aug 26 18:58:15 2010
@@ -65,6 +65,7 @@
 PyAPI_FUNC(void) PyErr_Clear(void);
 PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
 PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
+PyAPI_FUNC(void) Py_FatalError(const char *message);
 
 #ifdef Py_DEBUG
 #define _PyErr_OCCURRED() PyErr_Occurred()

Modified: python/branches/pep-0384/Include/pythonrun.h
==============================================================================
--- python/branches/pep-0384/Include/pythonrun.h	(original)
+++ python/branches/pep-0384/Include/pythonrun.h	Thu Aug 26 18:58:15 2010
@@ -33,25 +33,32 @@
 PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
 PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
 
+PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
 PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
-PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
 PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
 PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
 PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
+#endif
 
 PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,
                                                  int, PyCompilerFlags *flags,
                                                  PyArena *);
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *,
                                                const char*, int,
                                                char *, char *,
                                                PyCompilerFlags *, int *,
                                                PyArena *);
+#endif
+
+#ifndef PyParser_SimpleParseString
 #define PyParser_SimpleParseString(S, B) \
     PyParser_SimpleParseStringFlags(S, B, 0)
 #define PyParser_SimpleParseFile(FP, S, B) \
     PyParser_SimpleParseFileFlags(FP, S, B, 0)
+#endif
 PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
                                                           int);
 PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
@@ -60,9 +67,11 @@
 PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
                                          PyObject *, PyCompilerFlags *);
 
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,
                                          PyObject *, PyObject *, int,
                                          PyCompilerFlags *);
+#endif
 
 #define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
 PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
@@ -84,11 +93,14 @@
 /* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
 PyAPI_FUNC(void) _Py_RestoreSignals(void);
 
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
+#endif
 
 /* Bootstrap */
 PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
 
+#ifndef Py_LIMITED_API
 /* Use macros for a bunch of old variants */
 #define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
 #define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
@@ -107,6 +119,7 @@
     PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
 #define PyRun_FileFlags(fp, p, s, g, l, flags) \
     PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
+#endif
 
 /* In getpath.c */
 PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
@@ -150,7 +163,9 @@
 PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
 
 /* Stuff with no proper home (yet) */
+#ifndef Py_LIMITED_API
 PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
+#endif
 PyAPI_DATA(int) (*PyOS_InputHook)(void);
 PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
 PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;

Modified: python/branches/pep-0384/Include/symtable.h
==============================================================================
--- python/branches/pep-0384/Include/symtable.h	(original)
+++ python/branches/pep-0384/Include/symtable.h	Thu Aug 26 18:58:15 2010
@@ -1,3 +1,4 @@
+#ifndef Py_LIMITED_API
 #ifndef Py_SYMTABLE_H
 #define Py_SYMTABLE_H
 
@@ -100,3 +101,4 @@
 }
 #endif
 #endif /* !Py_SYMTABLE_H */
+#endif /* Py_LIMITED_API */

Modified: python/branches/pep-0384/Include/token.h
==============================================================================
--- python/branches/pep-0384/Include/token.h	(original)
+++ python/branches/pep-0384/Include/token.h	Thu Aug 26 18:58:15 2010
@@ -1,6 +1,6 @@
 
 /* Token types */
-
+#ifndef Py_LIMITED_API
 #ifndef Py_TOKEN_H
 #define Py_TOKEN_H
 #ifdef __cplusplus
@@ -83,3 +83,4 @@
 }
 #endif
 #endif /* !Py_TOKEN_H */
+#endif /* Py_LIMITED_API */

Added: python/branches/pep-0384/Include/typeslots.h
==============================================================================
--- (empty file)
+++ python/branches/pep-0384/Include/typeslots.h	Thu Aug 26 18:58:15 2010
@@ -0,0 +1,71 @@
+#define Py_bf_getbuffer 1
+#define Py_bf_releasebuffer 2
+#define Py_mp_ass_subscript 3
+#define Py_mp_length 4
+#define Py_mp_subscript 5
+#define Py_nb_absolute 6
+#define Py_nb_add 7
+#define Py_nb_and 8
+#define Py_nb_bool 9
+#define Py_nb_divmod 10
+#define Py_nb_float 11
+#define Py_nb_floor_divide 12
+#define Py_nb_index 13
+#define Py_nb_inplace_add 14
+#define Py_nb_inplace_and 15
+#define Py_nb_inplace_floor_divide 16
+#define Py_nb_inplace_lshift 17
+#define Py_nb_inplace_multiply 18
+#define Py_nb_inplace_or 19
+#define Py_nb_inplace_power 20
+#define Py_nb_inplace_remainder 21
+#define Py_nb_inplace_rshift 22
+#define Py_nb_inplace_subtract 23
+#define Py_nb_inplace_true_divide 24
+#define Py_nb_inplace_xor 25
+#define Py_nb_int 26
+#define Py_nb_invert 27
+#define Py_nb_lshift 28
+#define Py_nb_multiply 29
+#define Py_nb_negative 30
+#define Py_nb_or 31
+#define Py_nb_positive 32
+#define Py_nb_power 33
+#define Py_nb_remainder 34
+#define Py_nb_rshift 35
+#define Py_nb_subtract 36
+#define Py_nb_true_divide 37
+#define Py_nb_xor 38
+#define Py_sq_ass_item 39
+#define Py_sq_concat 40
+#define Py_sq_contains 41
+#define Py_sq_inplace_concat 42
+#define Py_sq_inplace_repeat 43
+#define Py_sq_item 44
+#define Py_sq_length 45
+#define Py_sq_repeat 46
+#define Py_tp_alloc 47
+#define Py_tp_base 48
+#define Py_tp_bases 49
+#define Py_tp_call 50
+#define Py_tp_clear 51
+#define Py_tp_dealloc 52
+#define Py_tp_del 53
+#define Py_tp_descr_get 54
+#define Py_tp_descr_set 55
+#define Py_tp_doc 56
+#define Py_tp_getattr 57
+#define Py_tp_getattro 58
+#define Py_tp_hash 59
+#define Py_tp_init 60
+#define Py_tp_is_gc 61
+#define Py_tp_iter 62
+#define Py_tp_iternext 63
+#define Py_tp_methods 64
+#define Py_tp_new 65
+#define Py_tp_repr 66
+#define Py_tp_richcompare 67
+#define Py_tp_setattr 68
+#define Py_tp_setattro 69
+#define Py_tp_str 70
+#define Py_tp_traverse 71

Modified: python/branches/pep-0384/Makefile.pre.in
==============================================================================
--- python/branches/pep-0384/Makefile.pre.in	(original)
+++ python/branches/pep-0384/Makefile.pre.in	Thu Aug 26 18:58:15 2010
@@ -626,6 +626,9 @@
 				$(BYTESTR_DEPS) \
 				$(srcdir)/Objects/stringlib/formatter.h
 
+Objects/typeobject.o: $(srcdir)/Objects/typeslots.inc
+$(srcdir)/Objects/typeslots.inc: $(srcdir)/Include/typeslots.h $(srcdir)/Objects/typeslots.py
+	$(PYTHON) $(srcdir)/Objects/typeslots.py < $(srcdir)/Include/typeslots.h > $(srcdir)/Objects/typeslots.inc
 
 ############################################################################
 # Header files

Modified: python/branches/pep-0384/Objects/typeobject.c
==============================================================================
--- python/branches/pep-0384/Objects/typeobject.c	(original)
+++ python/branches/pep-0384/Objects/typeobject.c	Thu Aug 26 18:58:15 2010
@@ -2301,6 +2301,44 @@
     return (PyObject *)type;
 }
 
+static short slotoffsets[] = {
+    -1, /* invalid slot */
+#include "typeslots.inc"
+};
+
+PyObject* PyType_FromSpec(PyType_Spec *spec)
+{
+    PyHeapTypeObject *res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0);
+    char *res_start = (char*)res;
+    PyType_Slot *slot;
+
+    res->ht_name = PyUnicode_FromString(spec->name);
+    if (!res->ht_name)
+	goto fail;
+    res->ht_type.tp_name = _PyUnicode_AsString(res->ht_name);
+    if (!res->ht_type.tp_name)
+	goto fail;
+
+    res->ht_type.tp_basicsize = spec->basicsize;
+    res->ht_type.tp_itemsize = spec->itemsize;
+    res->ht_type.tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;
+    
+    for (slot = spec->slots; slot->slot; slot++) {
+	if (slot->slot >= sizeof(slotoffsets)/sizeof(slotoffsets[0])) {
+	    PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
+	    goto fail;
+	}
+	*(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc;
+    }
+
+    return (PyObject*)res;
+    
+ fail:
+    Py_DECREF(res);
+    return NULL;
+}
+
+
 /* Internal API to look for a name through the MRO.
    This returns a borrowed reference, and doesn't set an exception! */
 PyObject *

Added: python/branches/pep-0384/Objects/typeslots.inc
==============================================================================
--- (empty file)
+++ python/branches/pep-0384/Objects/typeslots.inc	Thu Aug 26 18:58:15 2010
@@ -0,0 +1,71 @@
+offsetof(PyHeapTypeObject, as_buffer.bf_getbuffer),
+offsetof(PyHeapTypeObject, as_buffer.bf_releasebuffer),
+offsetof(PyHeapTypeObject, as_mapping.mp_ass_subscript),
+offsetof(PyHeapTypeObject, as_mapping.mp_length),
+offsetof(PyHeapTypeObject, as_mapping.mp_subscript),
+offsetof(PyHeapTypeObject, as_number.nb_absolute),
+offsetof(PyHeapTypeObject, as_number.nb_add),
+offsetof(PyHeapTypeObject, as_number.nb_and),
+offsetof(PyHeapTypeObject, as_number.nb_bool),
+offsetof(PyHeapTypeObject, as_number.nb_divmod),
+offsetof(PyHeapTypeObject, as_number.nb_float),
+offsetof(PyHeapTypeObject, as_number.nb_floor_divide),
+offsetof(PyHeapTypeObject, as_number.nb_index),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_add),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_and),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_floor_divide),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_lshift),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_multiply),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_or),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_power),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_remainder),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_rshift),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_subtract),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_true_divide),
+offsetof(PyHeapTypeObject, as_number.nb_inplace_xor),
+offsetof(PyHeapTypeObject, as_number.nb_int),
+offsetof(PyHeapTypeObject, as_number.nb_invert),
+offsetof(PyHeapTypeObject, as_number.nb_lshift),
+offsetof(PyHeapTypeObject, as_number.nb_multiply),
+offsetof(PyHeapTypeObject, as_number.nb_negative),
+offsetof(PyHeapTypeObject, as_number.nb_or),
+offsetof(PyHeapTypeObject, as_number.nb_positive),
+offsetof(PyHeapTypeObject, as_number.nb_power),
+offsetof(PyHeapTypeObject, as_number.nb_remainder),
+offsetof(PyHeapTypeObject, as_number.nb_rshift),
+offsetof(PyHeapTypeObject, as_number.nb_subtract),
+offsetof(PyHeapTypeObject, as_number.nb_true_divide),
+offsetof(PyHeapTypeObject, as_number.nb_xor),
+offsetof(PyHeapTypeObject, as_sequence.sq_ass_item),
+offsetof(PyHeapTypeObject, as_sequence.sq_concat),
+offsetof(PyHeapTypeObject, as_sequence.sq_contains),
+offsetof(PyHeapTypeObject, as_sequence.sq_inplace_concat),
+offsetof(PyHeapTypeObject, as_sequence.sq_inplace_repeat),
+offsetof(PyHeapTypeObject, as_sequence.sq_item),
+offsetof(PyHeapTypeObject, as_sequence.sq_length),
+offsetof(PyHeapTypeObject, as_sequence.sq_repeat),
+offsetof(PyHeapTypeObject, ht_type.tp_alloc),
+offsetof(PyHeapTypeObject, ht_type.tp_base),
+offsetof(PyHeapTypeObject, ht_type.tp_bases),
+offsetof(PyHeapTypeObject, ht_type.tp_call),
+offsetof(PyHeapTypeObject, ht_type.tp_clear),
+offsetof(PyHeapTypeObject, ht_type.tp_dealloc),
+offsetof(PyHeapTypeObject, ht_type.tp_del),
+offsetof(PyHeapTypeObject, ht_type.tp_descr_get),
+offsetof(PyHeapTypeObject, ht_type.tp_descr_set),
+offsetof(PyHeapTypeObject, ht_type.tp_doc),
+offsetof(PyHeapTypeObject, ht_type.tp_getattr),
+offsetof(PyHeapTypeObject, ht_type.tp_getattro),
+offsetof(PyHeapTypeObject, ht_type.tp_hash),
+offsetof(PyHeapTypeObject, ht_type.tp_init),
+offsetof(PyHeapTypeObject, ht_type.tp_is_gc),
+offsetof(PyHeapTypeObject, ht_type.tp_iter),
+offsetof(PyHeapTypeObject, ht_type.tp_iternext),
+offsetof(PyHeapTypeObject, ht_type.tp_methods),
+offsetof(PyHeapTypeObject, ht_type.tp_new),
+offsetof(PyHeapTypeObject, ht_type.tp_repr),
+offsetof(PyHeapTypeObject, ht_type.tp_richcompare),
+offsetof(PyHeapTypeObject, ht_type.tp_setattr),
+offsetof(PyHeapTypeObject, ht_type.tp_setattro),
+offsetof(PyHeapTypeObject, ht_type.tp_str),
+offsetof(PyHeapTypeObject, ht_type.tp_traverse),

Added: python/branches/pep-0384/Objects/typeslots.py
==============================================================================
--- (empty file)
+++ python/branches/pep-0384/Objects/typeslots.py	Thu Aug 26 18:58:15 2010
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+# Usage: typeslots.py < Include/typeslots.h > typeslots.inc
+
+import sys, re
+
+res = {}
+for line in sys.stdin:
+    m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
+    member = m.group(1)
+    if member.startswith("tp_"):
+        member = "ht_type."+member
+    elif member.startswith("nb_"):
+        member = "as_number."+member
+    elif member.startswith("mp_"):
+        member = "as_mapping."+member
+    elif member.startswith("sq_"):
+        member = "as_sequence."+member
+    elif member.startswith("bf_"):
+        member = "as_buffer."+member
+    res[int(m.group(2))] = member
+
+M = max(res.keys())+1
+for i in range(1,M):
+    print "offsetof(PyHeapTypeObject, %s)," % res[i]


More information about the Python-checkins mailing list