[Python-3000-checkins] r56478 - in python/branches/p3yk: Include/bytesobject.h Include/frameobject.h Include/object.h Misc/NEWS Modules/_bsddb.c Modules/_elementtree.c Modules/_fileio.c Modules/_lsprof.c Modules/_sre.c Modules/_tkinter.c Modules/arraymodule.c Modules/datetimemodule.c Objects/boolobject.c Objects/bytesobject.c Objects/classobject.c Objects/dictobject.c Objects/exceptions.c Objects/iterobject.c Objects/longobject.c Objects/rangeobject.c Objects/setobject.c Objects/stringobject.c Objects/typeobject.c Objects/unicodeobject.c Python/ceval.c Python/marshal.c
martin.v.loewis
python-3000-checkins at python.org
Sat Jul 21 09:47:25 CEST 2007
Author: martin.v.loewis
Date: Sat Jul 21 09:47:23 2007
New Revision: 56478
Modified:
python/branches/p3yk/Include/bytesobject.h
python/branches/p3yk/Include/frameobject.h
python/branches/p3yk/Include/object.h
python/branches/p3yk/Misc/NEWS
python/branches/p3yk/Modules/_bsddb.c
python/branches/p3yk/Modules/_elementtree.c
python/branches/p3yk/Modules/_fileio.c
python/branches/p3yk/Modules/_lsprof.c
python/branches/p3yk/Modules/_sre.c
python/branches/p3yk/Modules/_tkinter.c
python/branches/p3yk/Modules/arraymodule.c
python/branches/p3yk/Modules/datetimemodule.c
python/branches/p3yk/Objects/boolobject.c
python/branches/p3yk/Objects/bytesobject.c
python/branches/p3yk/Objects/classobject.c
python/branches/p3yk/Objects/dictobject.c
python/branches/p3yk/Objects/exceptions.c
python/branches/p3yk/Objects/iterobject.c
python/branches/p3yk/Objects/longobject.c
python/branches/p3yk/Objects/rangeobject.c
python/branches/p3yk/Objects/setobject.c
python/branches/p3yk/Objects/stringobject.c
python/branches/p3yk/Objects/typeobject.c
python/branches/p3yk/Objects/unicodeobject.c
python/branches/p3yk/Python/ceval.c
python/branches/p3yk/Python/marshal.c
Log:
PEP 3123: Use proper C inheritance for PyObject.
Modified: python/branches/p3yk/Include/bytesobject.h
==============================================================================
--- python/branches/p3yk/Include/bytesobject.h (original)
+++ python/branches/p3yk/Include/bytesobject.h Sat Jul 21 09:47:23 2007
@@ -30,7 +30,7 @@
/* Type check macros */
#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
-#define PyBytes_CheckExact(self) ((self)->ob_type == &PyBytes_Type)
+#define PyBytes_CheckExact(self) (Py_Type(self) == &PyBytes_Type)
/* Direct API functions */
PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
@@ -42,7 +42,7 @@
/* Macros, trading safety for speed */
#define PyBytes_AS_STRING(self) (((PyBytesObject *)(self))->ob_bytes)
-#define PyBytes_GET_SIZE(self) (((PyBytesObject *)(self))->ob_size)
+#define PyBytes_GET_SIZE(self) Py_Size(self)
#ifdef __cplusplus
}
Modified: python/branches/p3yk/Include/frameobject.h
==============================================================================
--- python/branches/p3yk/Include/frameobject.h (original)
+++ python/branches/p3yk/Include/frameobject.h Sat Jul 21 09:47:23 2007
@@ -51,7 +51,7 @@
PyAPI_DATA(PyTypeObject) PyFrame_Type;
-#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
+#define PyFrame_Check(op) (Py_Type(op) == &PyFrame_Type)
PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
PyObject *, PyObject *);
Modified: python/branches/p3yk/Include/object.h
==============================================================================
--- python/branches/p3yk/Include/object.h (original)
+++ python/branches/p3yk/Include/object.h Sat Jul 21 09:47:23 2007
@@ -75,17 +75,14 @@
#endif
/* PyObject_HEAD defines the initial segment of every PyObject. */
-#define PyObject_HEAD \
- _PyObject_HEAD_EXTRA \
- Py_ssize_t ob_refcnt; \
- struct _typeobject *ob_type;
+#define PyObject_HEAD PyObject ob_base;
#define PyObject_HEAD_INIT(type) \
- _PyObject_EXTRA_INIT \
- 1, type,
+ { _PyObject_EXTRA_INIT \
+ 1, type },
#define PyVarObject_HEAD_INIT(type, size) \
- PyObject_HEAD_INIT(type) size,
+ { PyObject_HEAD_INIT(type) size },
/* PyObject_VAR_HEAD defines the initial segment of all variable-size
* container objects. These end with a declaration of an array with 1
@@ -93,9 +90,7 @@
* has room for ob_size elements. Note that ob_size is an element count,
* not necessarily a byte count.
*/
-#define PyObject_VAR_HEAD \
- PyObject_HEAD \
- Py_ssize_t ob_size; /* Number of items in variable part */
+#define PyObject_VAR_HEAD PyVarObject ob_base;
#define Py_INVALID_SIZE (Py_ssize_t)-1
/* Nothing is actually declared to be a PyObject, but every pointer to
@@ -104,11 +99,14 @@
* in addition, be cast to PyVarObject*.
*/
typedef struct _object {
- PyObject_HEAD
+ _PyObject_HEAD_EXTRA
+ Py_ssize_t ob_refcnt;
+ struct _typeobject *ob_type;
} PyObject;
typedef struct {
- PyObject_VAR_HEAD
+ PyObject ob_base;
+ Py_ssize_t ob_size; /* Number of items in variable part */
} PyVarObject;
#define Py_Refcnt(ob) (((PyObject*)(ob))->ob_refcnt)
Modified: python/branches/p3yk/Misc/NEWS
==============================================================================
--- python/branches/p3yk/Misc/NEWS (original)
+++ python/branches/p3yk/Misc/NEWS Sat Jul 21 09:47:23 2007
@@ -26,6 +26,8 @@
Core and Builtins
-----------------
+- PEP 3123: Use proper C inheritance for PyObject.
+
- Removed the __oct__ and __hex__ special methods and added a bin()
builtin function.
Modified: python/branches/p3yk/Modules/_bsddb.c
==============================================================================
--- python/branches/p3yk/Modules/_bsddb.c (original)
+++ python/branches/p3yk/Modules/_bsddb.c Sat Jul 21 09:47:23 2007
@@ -5369,8 +5369,7 @@
#endif
static PyTypeObject DB_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"DB", /*tp_name*/
sizeof(DBObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -5402,8 +5401,7 @@
static PyTypeObject DBCursor_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"DBCursor", /*tp_name*/
sizeof(DBCursorObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -5435,8 +5433,7 @@
static PyTypeObject DBEnv_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"DBEnv", /*tp_name*/
sizeof(DBEnvObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -5467,8 +5464,7 @@
};
static PyTypeObject DBTxn_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"DBTxn", /*tp_name*/
sizeof(DBTxnObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -5500,8 +5496,7 @@
static PyTypeObject DBLock_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"DBLock", /*tp_name*/
sizeof(DBLockObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -5533,8 +5528,7 @@
#if (DBVER >= 43)
static PyTypeObject DBSequence_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"DBSequence", /*tp_name*/
sizeof(DBSequenceObject), /*tp_basicsize*/
0, /*tp_itemsize*/
Modified: python/branches/p3yk/Modules/_elementtree.c
==============================================================================
--- python/branches/p3yk/Modules/_elementtree.c (original)
+++ python/branches/p3yk/Modules/_elementtree.c Sat Jul 21 09:47:23 2007
@@ -1400,8 +1400,8 @@
};
static PyTypeObject Element_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "Element", sizeof(ElementObject), 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "Element", sizeof(ElementObject), 0,
/* methods */
(destructor)element_dealloc, /* tp_dealloc */
0, /* tp_print */
@@ -1813,8 +1813,8 @@
}
static PyTypeObject TreeBuilder_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "TreeBuilder", sizeof(TreeBuilderObject), 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "TreeBuilder", sizeof(TreeBuilderObject), 0,
/* methods */
(destructor)treebuilder_dealloc, /* tp_dealloc */
0, /* tp_print */
@@ -2588,8 +2588,8 @@
}
static PyTypeObject XMLParser_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "XMLParser", sizeof(XMLParserObject), 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "XMLParser", sizeof(XMLParserObject), 0,
/* methods */
(destructor)xmlparser_dealloc, /* tp_dealloc */
0, /* tp_print */
Modified: python/branches/p3yk/Modules/_fileio.c
==============================================================================
--- python/branches/p3yk/Modules/_fileio.c (original)
+++ python/branches/p3yk/Modules/_fileio.c Sat Jul 21 09:47:23 2007
@@ -273,7 +273,7 @@
Py_DECREF(closeresult);
}
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static PyObject *
@@ -704,8 +704,7 @@
};
PyTypeObject PyFileIO_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"FileIO",
sizeof(PyFileIOObject),
0,
Modified: python/branches/p3yk/Modules/_lsprof.c
==============================================================================
--- python/branches/p3yk/Modules/_lsprof.c (original)
+++ python/branches/p3yk/Modules/_lsprof.c Sat Jul 21 09:47:23 2007
@@ -800,8 +800,7 @@
");
static PyTypeObject PyProfiler_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_lsprof.Profiler", /* tp_name */
sizeof(ProfilerObject), /* tp_basicsize */
0, /* tp_itemsize */
Modified: python/branches/p3yk/Modules/_sre.c
==============================================================================
--- python/branches/p3yk/Modules/_sre.c (original)
+++ python/branches/p3yk/Modules/_sre.c Sat Jul 21 09:47:23 2007
@@ -2633,8 +2633,8 @@
}
static PyTypeObject Pattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "_" SRE_MODULE ".SRE_Pattern",
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "_" SRE_MODULE ".SRE_Pattern",
sizeof(PatternObject), sizeof(SRE_CODE),
(destructor)pattern_dealloc, /*tp_dealloc*/
0, /*tp_print*/
@@ -3168,8 +3168,8 @@
detach the associated string, if any */
static PyTypeObject Match_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "_" SRE_MODULE ".SRE_Match",
+ PyVarObject_HEAD_INIT(NULL,0)
+ "_" SRE_MODULE ".SRE_Match",
sizeof(MatchObject), sizeof(Py_ssize_t),
(destructor)match_dealloc, /*tp_dealloc*/
0, /*tp_print*/
@@ -3343,8 +3343,8 @@
}
static PyTypeObject Scanner_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "_" SRE_MODULE ".SRE_Scanner",
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "_" SRE_MODULE ".SRE_Scanner",
sizeof(ScannerObject), 0,
(destructor)scanner_dealloc, /*tp_dealloc*/
0, /*tp_print*/
Modified: python/branches/p3yk/Modules/_tkinter.c
==============================================================================
--- python/branches/p3yk/Modules/_tkinter.c (original)
+++ python/branches/p3yk/Modules/_tkinter.c Sat Jul 21 09:47:23 2007
@@ -859,8 +859,7 @@
};
static PyTypeObject PyTclObject_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_tkinter.Tcl_Obj", /*tp_name*/
sizeof(PyTclObject), /*tp_basicsize*/
0, /*tp_itemsize*/
Modified: python/branches/p3yk/Modules/arraymodule.c
==============================================================================
--- python/branches/p3yk/Modules/arraymodule.c (original)
+++ python/branches/p3yk/Modules/arraymodule.c Sat Jul 21 09:47:23 2007
@@ -1259,20 +1259,20 @@
{
FILE *fp;
- if (self->ob_size == 0)
+ if (Py_Size(self) == 0)
goto done;
fp = PyFile_AsFile(f);
if (fp != NULL) {
if (fwrite(self->ob_item, self->ob_descr->itemsize,
- self->ob_size, fp) != (size_t)self->ob_size) {
+ Py_Size(self), fp) != (size_t)Py_Size(self)) {
PyErr_SetFromErrno(PyExc_IOError);
clearerr(fp);
return NULL;
}
}
else {
- Py_ssize_t nbytes = self->ob_size * self->ob_descr->itemsize;
+ Py_ssize_t nbytes = Py_Size(self) * self->ob_descr->itemsize;
/* Write 64K blocks at a time */
/* XXX Make the block size settable */
int BLOCKSIZE = 64*1024;
@@ -2151,7 +2151,7 @@
if (PyType_Ready(&Arraytype) < 0)
return;
- PyArrayIter_Type.ob_type = &PyType_Type;
+ Py_Type(&PyArrayIter_Type) = &PyType_Type;
m = Py_InitModule3("array", a_methods, module_doc);
if (m == NULL)
return;
Modified: python/branches/p3yk/Modules/datetimemodule.c
==============================================================================
--- python/branches/p3yk/Modules/datetimemodule.c (original)
+++ python/branches/p3yk/Modules/datetimemodule.c Sat Jul 21 09:47:23 2007
@@ -2909,8 +2909,7 @@
PyDoc_STR("Abstract base class for time zone info objects.");
static PyTypeObject PyDateTime_TZInfoType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.tzinfo", /* tp_name */
sizeof(PyDateTime_TZInfo), /* tp_basicsize */
0, /* tp_itemsize */
@@ -3419,8 +3418,7 @@
};
static PyTypeObject PyDateTime_TimeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.time", /* tp_name */
sizeof(PyDateTime_Time), /* tp_basicsize */
0, /* tp_itemsize */
@@ -4508,8 +4506,7 @@
};
static PyTypeObject PyDateTime_DateTimeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.datetime", /* tp_name */
sizeof(PyDateTime_DateTime), /* tp_basicsize */
0, /* tp_itemsize */
Modified: python/branches/p3yk/Objects/boolobject.c
==============================================================================
--- python/branches/p3yk/Objects/boolobject.c (original)
+++ python/branches/p3yk/Objects/boolobject.c Sat Jul 21 09:47:23 2007
@@ -187,11 +187,11 @@
/* Named Zero for link-level compatibility */
struct _longobject _Py_FalseStruct = {
- PyObject_HEAD_INIT(&PyBool_Type)
- 0, { 0 }
+ PyVarObject_HEAD_INIT(&PyBool_Type, 0)
+ { 0 }
};
struct _longobject _Py_TrueStruct = {
- PyObject_HEAD_INIT(&PyBool_Type)
- 1, { 1 }
+ PyVarObject_HEAD_INIT(&PyBool_Type, 1)
+ { 1 }
};
Modified: python/branches/p3yk/Objects/bytesobject.c
==============================================================================
--- python/branches/p3yk/Objects/bytesobject.c (original)
+++ python/branches/p3yk/Objects/bytesobject.c Sat Jul 21 09:47:23 2007
@@ -25,7 +25,7 @@
if (nullbytes == NULL)
return 0;
nullbytes->ob_bytes = NULL;
- nullbytes->ob_size = nullbytes->ob_alloc = 0;
+ Py_Size(nullbytes) = nullbytes->ob_alloc = 0;
return 1;
}
@@ -51,7 +51,7 @@
Py_ssize_t
_getbuffer(PyObject *obj, void **ptr)
{
- PyBufferProcs *buffer = obj->ob_type->tp_as_buffer;
+ PyBufferProcs *buffer = Py_Type(obj)->tp_as_buffer;
if (buffer == NULL ||
PyUnicode_Check(obj) ||
@@ -97,7 +97,7 @@
if (bytes != NULL)
memcpy(new->ob_bytes, bytes, size);
}
- new->ob_size = new->ob_alloc = size;
+ Py_Size(new) = new->ob_alloc = size;
return (PyObject *)new;
}
@@ -136,7 +136,7 @@
}
else if (size <= alloc) {
/* Within allocated size; quick exit */
- ((PyBytesObject *)self)->ob_size = size;
+ Py_Size(self) = size;
return 0;
}
else if (size <= alloc * 1.125) {
@@ -155,7 +155,7 @@
}
((PyBytesObject *)self)->ob_bytes = sval;
- ((PyBytesObject *)self)->ob_size = size;
+ Py_Size(self) = size;
((PyBytesObject *)self)->ob_alloc = alloc;
return 0;
@@ -172,7 +172,7 @@
bsize = _getbuffer(b, &bptr);
if (asize < 0 || bsize < 0) {
PyErr_Format(PyExc_TypeError, "can't concat %.100s to %.100s",
- a->ob_type->tp_name, b->ob_type->tp_name);
+ Py_Type(a)->tp_name, Py_Type(b)->tp_name);
return NULL;
}
@@ -193,7 +193,7 @@
static Py_ssize_t
bytes_length(PyBytesObject *self)
{
- return self->ob_size;
+ return Py_Size(self);
}
static PyObject *
@@ -213,16 +213,16 @@
osize = _getbuffer(other, &optr);
if (osize < 0) {
PyErr_Format(PyExc_TypeError,
- "can't concat bytes to %.100s", other->ob_type->tp_name);
+ "can't concat bytes to %.100s", Py_Type(other)->tp_name);
return NULL;
}
- mysize = self->ob_size;
+ mysize = Py_Size(self);
size = mysize + osize;
if (size < 0)
return PyErr_NoMemory();
if (size <= self->ob_alloc)
- self->ob_size = size;
+ Py_Size(self) = size;
else if (PyBytes_Resize((PyObject *)self, size) < 0)
return NULL;
memcpy(self->ob_bytes + mysize, optr, osize);
@@ -239,7 +239,7 @@
if (count < 0)
count = 0;
- mysize = self->ob_size;
+ mysize = Py_Size(self);
size = mysize * count;
if (count != 0 && size / count != mysize)
return PyErr_NoMemory();
@@ -264,12 +264,12 @@
if (count < 0)
count = 0;
- mysize = self->ob_size;
+ mysize = Py_Size(self);
size = mysize * count;
if (count != 0 && size / count != mysize)
return PyErr_NoMemory();
if (size <= self->ob_alloc)
- self->ob_size = size;
+ Py_Size(self) = size;
else if (PyBytes_Resize((PyObject *)self, size) < 0)
return NULL;
@@ -290,15 +290,15 @@
{
Py_ssize_t i;
- if (other->ob_size == 1) {
+ if (Py_Size(other) == 1) {
return memchr(self->ob_bytes, other->ob_bytes[0],
- self->ob_size) != NULL;
+ Py_Size(self)) != NULL;
}
- if (other->ob_size == 0)
+ if (Py_Size(other) == 0)
return 1; /* Edge case */
- for (i = 0; i + other->ob_size <= self->ob_size; i++) {
+ for (i = 0; i + Py_Size(other) <= Py_Size(self); i++) {
/* XXX Yeah, yeah, lots of optimizations possible... */
- if (memcmp(self->ob_bytes + i, other->ob_bytes, other->ob_size) == 0)
+ if (memcmp(self->ob_bytes + i, other->ob_bytes, Py_Size(other)) == 0)
return 1;
}
return 0;
@@ -320,15 +320,15 @@
return -1;
}
- return memchr(self->ob_bytes, ival, self->ob_size) != NULL;
+ return memchr(self->ob_bytes, ival, Py_Size(self)) != NULL;
}
static PyObject *
bytes_getitem(PyBytesObject *self, Py_ssize_t i)
{
if (i < 0)
- i += self->ob_size;
- if (i < 0 || i >= self->ob_size) {
+ i += Py_Size(self);
+ if (i < 0 || i >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "bytes index out of range");
return NULL;
}
@@ -347,7 +347,7 @@
if (i < 0)
i += PyBytes_GET_SIZE(self);
- if (i < 0 || i >= self->ob_size) {
+ if (i < 0 || i >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "bytes index out of range");
return NULL;
}
@@ -417,7 +417,7 @@
if (needed < 0) {
PyErr_Format(PyExc_TypeError,
"can't set bytes slice from %.100s",
- values->ob_type->tp_name);
+ Py_Type(values)->tp_name);
return -1;
}
}
@@ -426,8 +426,8 @@
lo = 0;
if (hi < lo)
hi = lo;
- if (hi > self->ob_size)
- hi = self->ob_size;
+ if (hi > Py_Size(self))
+ hi = Py_Size(self);
avail = hi - lo;
if (avail < 0)
@@ -442,10 +442,10 @@
0 lo new_hi new_size
*/
memmove(self->ob_bytes + lo + needed, self->ob_bytes + hi,
- self->ob_size - hi);
+ Py_Size(self) - hi);
}
if (PyBytes_Resize((PyObject *)self,
- self->ob_size + needed - avail) < 0)
+ Py_Size(self) + needed - avail) < 0)
return -1;
if (avail < needed) {
/*
@@ -455,7 +455,7 @@
0 lo new_hi new_size
*/
memmove(self->ob_bytes + lo + needed, self->ob_bytes + hi,
- self->ob_size - lo - needed);
+ Py_Size(self) - lo - needed);
}
}
@@ -471,9 +471,9 @@
Py_ssize_t ival;
if (i < 0)
- i += self->ob_size;
+ i += Py_Size(self);
- if (i < 0 || i >= self->ob_size) {
+ if (i < 0 || i >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "bytes index out of range");
return -1;
}
@@ -509,7 +509,7 @@
if (i < 0)
i += PyBytes_GET_SIZE(self);
- if (i < 0 || i >= self->ob_size) {
+ if (i < 0 || i >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "bytes index out of range");
return -1;
}
@@ -563,7 +563,7 @@
else {
assert(PyBytes_Check(values));
bytes = ((PyBytesObject *)values)->ob_bytes;
- needed = ((PyBytesObject *)values)->ob_size;
+ needed = Py_Size(values);
}
/* Make sure b[5:2] = ... inserts before 5, not before 2. */
if ((step < 0 && start < stop) ||
@@ -579,10 +579,10 @@
0 lo new_hi new_size
*/
memmove(self->ob_bytes + start + needed, self->ob_bytes + stop,
- self->ob_size - stop);
+ Py_Size(self) - stop);
}
if (PyBytes_Resize((PyObject *)self,
- self->ob_size + needed - slicelen) < 0)
+ Py_Size(self) + needed - slicelen) < 0)
return -1;
if (slicelen < needed) {
/*
@@ -592,7 +592,7 @@
0 lo new_hi new_size
*/
memmove(self->ob_bytes + start + needed, self->ob_bytes + stop,
- self->ob_size - start - needed);
+ Py_Size(self) - start - needed);
}
}
@@ -663,7 +663,7 @@
PyObject *it;
PyObject *(*iternext)(PyObject *);
- if (self->ob_size != 0) {
+ if (Py_Size(self) != 0) {
/* Empty previous contents (yes, do this first of all!) */
if (PyBytes_Resize((PyObject *)self, 0) < 0)
return -1;
@@ -697,14 +697,14 @@
if (!PyString_Check(encoded)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
- encoded->ob_type->tp_name);
+ Py_Type(encoded)->tp_name);
Py_DECREF(encoded);
return -1;
}
bytes = PyString_AS_STRING(encoded);
size = PyString_GET_SIZE(encoded);
if (size <= self->ob_alloc)
- self->ob_size = size;
+ Py_Size(self) = size;
else if (PyBytes_Resize((PyObject *)self, size) < 0) {
Py_DECREF(encoded);
return -1;
@@ -755,7 +755,7 @@
it = PyObject_GetIter(arg);
if (it == NULL)
return -1;
- iternext = *it->ob_type->tp_iternext;
+ iternext = *Py_Type(it)->tp_iternext;
/* Run the iterator to exhaustion */
for (;;) {
@@ -787,11 +787,11 @@
}
/* Append the byte */
- if (self->ob_size < self->ob_alloc)
- self->ob_size++;
- else if (PyBytes_Resize((PyObject *)self, self->ob_size+1) < 0)
+ if (Py_Size(self) < self->ob_alloc)
+ Py_Size(self)++;
+ else if (PyBytes_Resize((PyObject *)self, Py_Size(self)+1) < 0)
goto error;
- self->ob_bytes[self->ob_size-1] = value;
+ self->ob_bytes[Py_Size(self)-1] = value;
}
/* Clean up and return success */
@@ -809,9 +809,9 @@
static PyObject *
bytes_repr(PyBytesObject *self)
{
- size_t newsize = 3 + 4 * self->ob_size;
+ size_t newsize = 3 + 4 * Py_Size(self);
PyObject *v;
- if (newsize > PY_SSIZE_T_MAX || newsize / 4 != self->ob_size) {
+ if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_Size(self)) {
PyErr_SetString(PyExc_OverflowError,
"bytes object is too large to make repr");
return NULL;
@@ -829,7 +829,7 @@
p = PyString_AS_STRING(v);
*p++ = 'b';
*p++ = quote;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
/* There's at least enough room for a hex escape
and a closing quote. */
assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
@@ -866,7 +866,7 @@
static PyObject *
bytes_str(PyBytesObject *self)
{
- return PyString_FromStringAndSize(self->ob_bytes, self->ob_size);
+ return PyString_FromStringAndSize(self->ob_bytes, Py_Size(self));
}
static PyObject *
@@ -933,7 +933,7 @@
if (self->ob_bytes != 0) {
PyMem_Free(self->ob_bytes);
}
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static Py_ssize_t
@@ -945,14 +945,14 @@
return -1;
}
*ptr = (void *)self->ob_bytes;
- return self->ob_size;
+ return Py_Size(self);
}
static Py_ssize_t
bytes_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
{
if (lenp)
- *lenp = self->ob_size;
+ *lenp = Py_Size(self);
return 1;
}
@@ -2032,7 +2032,7 @@
count++; }
/* Always force the list to the expected size. */
-#define FIX_PREALLOC_SIZE(list) ((PyListObject *)list)->ob_size = count
+#define FIX_PREALLOC_SIZE(list) Py_Size(list) = count
Py_LOCAL_INLINE(PyObject *)
@@ -2296,7 +2296,7 @@
static PyObject *
bytes_extend(PyBytesObject *self, PyObject *arg)
{
- if (bytes_setslice(self, self->ob_size, self->ob_size, arg) == -1)
+ if (bytes_setslice(self, Py_Size(self), Py_Size(self), arg) == -1)
return NULL;
Py_RETURN_NONE;
}
@@ -2310,7 +2310,7 @@
bytes_reverse(PyBytesObject *self, PyObject *unused)
{
char swap, *head, *tail;
- Py_ssize_t i, j, n = self->ob_size;
+ Py_ssize_t i, j, n = Py_Size(self);
j = n / 2;
head = self->ob_bytes;
@@ -2332,7 +2332,7 @@
bytes_insert(PyBytesObject *self, PyObject *args)
{
int value;
- Py_ssize_t where, n = self->ob_size;
+ Py_ssize_t where, n = Py_Size(self);
if (!PyArg_ParseTuple(args, "ni:insert", &where, &value))
return NULL;
@@ -2371,7 +2371,7 @@
bytes_append(PyBytesObject *self, PyObject *arg)
{
int value;
- Py_ssize_t n = self->ob_size;
+ Py_ssize_t n = Py_Size(self);
if (! _getbytevalue(arg, &value))
return NULL;
@@ -2397,7 +2397,7 @@
bytes_pop(PyBytesObject *self, PyObject *args)
{
int value;
- Py_ssize_t where = -1, n = self->ob_size;
+ Py_ssize_t where = -1, n = Py_Size(self);
if (!PyArg_ParseTuple(args, "|n:pop", &where))
return NULL;
@@ -2408,8 +2408,8 @@
return NULL;
}
if (where < 0)
- where += self->ob_size;
- if (where < 0 || where >= self->ob_size) {
+ where += Py_Size(self);
+ if (where < 0 || where >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "pop index out of range");
return NULL;
}
@@ -2430,7 +2430,7 @@
bytes_remove(PyBytesObject *self, PyObject *arg)
{
int value;
- Py_ssize_t where, n = self->ob_size;
+ Py_ssize_t where, n = Py_Size(self);
if (! _getbytevalue(arg, &value))
return NULL;
@@ -2487,9 +2487,9 @@
return NULL;
}
myptr = self->ob_bytes;
- mysize = self->ob_size;
+ mysize = Py_Size(self);
argptr = ((PyBytesObject *)arg)->ob_bytes;
- argsize = ((PyBytesObject *)arg)->ob_size;
+ argsize = Py_Size(arg);
left = lstrip_helper(myptr, mysize, argptr, argsize);
right = rstrip_helper(myptr, mysize, argptr, argsize);
return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
@@ -2509,9 +2509,9 @@
return NULL;
}
myptr = self->ob_bytes;
- mysize = self->ob_size;
+ mysize = Py_Size(self);
argptr = ((PyBytesObject *)arg)->ob_bytes;
- argsize = ((PyBytesObject *)arg)->ob_size;
+ argsize = Py_Size(arg);
left = lstrip_helper(myptr, mysize, argptr, argsize);
right = mysize;
return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
@@ -2531,9 +2531,9 @@
return NULL;
}
myptr = self->ob_bytes;
- mysize = self->ob_size;
+ mysize = Py_Size(self);
argptr = ((PyBytesObject *)arg)->ob_bytes;
- argsize = ((PyBytesObject *)arg)->ob_size;
+ argsize = Py_Size(arg);
left = 0;
right = rstrip_helper(myptr, mysize, argptr, argsize);
return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
@@ -2604,7 +2604,7 @@
"can only join an iterable of bytes "
"(item %ld has type '%.100s')",
/* XXX %ld isn't right on Win64 */
- (long)i, obj->ob_type->tp_name);
+ (long)i, Py_Type(obj)->tp_name);
goto error;
}
totalsize += PyBytes_GET_SIZE(obj);
@@ -2707,9 +2707,9 @@
bytes_reduce(PyBytesObject *self)
{
return Py_BuildValue("(O(s#))",
- self->ob_type,
+ Py_Type(self),
self->ob_bytes == NULL ? "" : self->ob_bytes,
- self->ob_size);
+ Py_Size(self));
}
static PySequenceMethods bytes_as_sequence = {
@@ -2780,8 +2780,7 @@
If an argument is given it must be an iterable yielding ints in range(256).");
PyTypeObject PyBytes_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"bytes",
sizeof(PyBytesObject),
0,
Modified: python/branches/p3yk/Objects/classobject.c
==============================================================================
--- python/branches/p3yk/Objects/classobject.c (original)
+++ python/branches/p3yk/Objects/classobject.c Sat Jul 21 09:47:23 2007
@@ -438,8 +438,7 @@
}
PyTypeObject PyMethod_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"method",
sizeof(PyMethodObject),
0,
Modified: python/branches/p3yk/Objects/dictobject.c
==============================================================================
--- python/branches/p3yk/Objects/dictobject.c (original)
+++ python/branches/p3yk/Objects/dictobject.c Sat Jul 21 09:47:23 2007
@@ -2570,8 +2570,7 @@
};
PyTypeObject PyDictKeys_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dict_keys", /* tp_name */
sizeof(dictviewobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2655,8 +2654,7 @@
};
PyTypeObject PyDictItems_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dict_items", /* tp_name */
sizeof(dictviewobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2721,8 +2719,7 @@
};
PyTypeObject PyDictValues_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dict_values", /* tp_name */
sizeof(dictviewobject), /* tp_basicsize */
0, /* tp_itemsize */
Modified: python/branches/p3yk/Objects/exceptions.c
==============================================================================
--- python/branches/p3yk/Objects/exceptions.c (original)
+++ python/branches/p3yk/Objects/exceptions.c Sat Jul 21 09:47:23 2007
@@ -227,8 +227,7 @@
static PyTypeObject _PyExc_BaseException = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"BaseException", /*tp_name*/
sizeof(PyBaseExceptionObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -278,8 +277,7 @@
*/
#define SimpleExtendsException(EXCBASE, EXCNAME, EXCDOC) \
static PyTypeObject _PyExc_ ## EXCNAME = { \
- PyObject_HEAD_INIT(NULL) \
- 0, \
+ PyVarObject_HEAD_INIT(NULL, 0) \
# EXCNAME, \
sizeof(PyBaseExceptionObject), \
0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \
@@ -294,8 +292,7 @@
#define MiddlingExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDOC) \
static PyTypeObject _PyExc_ ## EXCNAME = { \
- PyObject_HEAD_INIT(NULL) \
- 0, \
+ PyVarObject_HEAD_INIT(NULL, 0) \
# EXCNAME, \
sizeof(Py ## EXCSTORE ## Object), \
0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -310,8 +307,7 @@
#define ComplexExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDEALLOC, EXCMETHODS, EXCMEMBERS, EXCSTR, EXCDOC) \
static PyTypeObject _PyExc_ ## EXCNAME = { \
- PyObject_HEAD_INIT(NULL) \
- 0, \
+ PyVarObject_HEAD_INIT(NULL, 0) \
# EXCNAME, \
sizeof(Py ## EXCSTORE ## Object), 0, \
(destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -1515,8 +1511,7 @@
}
static PyTypeObject _PyExc_UnicodeEncodeError = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"UnicodeEncodeError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1580,8 +1575,7 @@
}
static PyTypeObject _PyExc_UnicodeDecodeError = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"UnicodeDecodeError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1667,8 +1661,7 @@
}
static PyTypeObject _PyExc_UnicodeTranslateError = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"UnicodeTranslateError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Modified: python/branches/p3yk/Objects/iterobject.c
==============================================================================
--- python/branches/p3yk/Objects/iterobject.c (original)
+++ python/branches/p3yk/Objects/iterobject.c Sat Jul 21 09:47:23 2007
@@ -253,7 +253,7 @@
assert(PyTuple_Check(args));
- if (PyZipIter_Type.ob_type == NULL) {
+ if (Py_Type(&PyZipIter_Type) == NULL) {
if (PyType_Ready(&PyZipIter_Type) < 0)
return NULL;
}
@@ -368,8 +368,7 @@
}
static PyTypeObject PyZipIter_Type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(0, 0)
"zipiterator", /* tp_name */
sizeof(zipiterobject), /* tp_basicsize */
0, /* tp_itemsize */
Modified: python/branches/p3yk/Objects/longobject.c
==============================================================================
--- python/branches/p3yk/Objects/longobject.c (original)
+++ python/branches/p3yk/Objects/longobject.c Sat Jul 21 09:47:23 2007
@@ -46,11 +46,11 @@
#define CHECK_SMALL_INT(ival)
#endif
-#define MEDIUM_VALUE(x) ((x)->ob_size < 0 ? -(x)->ob_digit[0] : ((x)->ob_size == 0 ? 0 : (x)->ob_digit[0]))
+#define MEDIUM_VALUE(x) (Py_Size(x) < 0 ? -(x)->ob_digit[0] : (Py_Size(x) == 0 ? 0 : (x)->ob_digit[0]))
/* If a freshly-allocated long is already shared, it must
be a small integer, so negating it must go to PyLong_FromLong */
#define NEGATE(x) \
- do if ((x)->ob_refcnt == 1) (x)->ob_size = -(x)->ob_size; \
+ do if (Py_Refcnt(x) == 1) Py_Size(x) = -Py_Size(x); \
else { PyObject* tmp=PyInt_FromLong(-MEDIUM_VALUE(x)); \
Py_DECREF(x); (x) = (PyLongObject*)tmp; } \
while(0)
@@ -134,18 +134,18 @@
Py_ssize_t i;
assert(src != NULL);
- i = src->ob_size;
+ i = Py_Size(src);
if (i < 0)
i = -(i);
if (i < 2) {
int ival = src->ob_digit[0];
- if (src->ob_size < 0)
+ if (Py_Size(src) < 0)
ival = -ival;
CHECK_SMALL_INT(ival);
}
result = _PyLong_New(i);
if (result != NULL) {
- result->ob_size = src->ob_size;
+ Py_Size(result) = Py_Size(src);
while (--i >= 0)
result->ob_digit[i] = src->ob_digit[i];
}
@@ -173,7 +173,7 @@
if (!(ival>>SHIFT)) {
v = _PyLong_New(1);
if (v) {
- v->ob_size = sign;
+ Py_Size(v) = sign;
v->ob_digit[0] = ival;
}
return (PyObject*)v;
@@ -183,7 +183,7 @@
if (!(ival >> 2*SHIFT)) {
v = _PyLong_New(2);
if (v) {
- v->ob_size = 2*sign;
+ Py_Size(v) = 2*sign;
v->ob_digit[0] = (digit)ival & MASK;
v->ob_digit[1] = ival >> SHIFT;
}
@@ -199,7 +199,7 @@
v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->ob_digit;
- v->ob_size = ndigits*sign;
+ Py_Size(v) = ndigits*sign;
t = (unsigned long)ival;
while (t) {
*p++ = (digit)(t & MASK);
@@ -328,7 +328,7 @@
res = -1;
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_Size(v);
switch (i) {
case -1:
@@ -386,7 +386,7 @@
return 0;
}
/* conservative estimate */
- size = ((PyLongObject*)vv)->ob_size;
+ size = Py_Size(vv);
return -2 <= size && size <= 2;
}
@@ -405,7 +405,7 @@
return -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_Size(v);
switch (i) {
case -1: return -v->ob_digit[0];
case 0: return 0;
@@ -493,7 +493,7 @@
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_Size(v);
x = 0;
if (i < 0) {
PyErr_SetString(PyExc_OverflowError,
@@ -532,7 +532,7 @@
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_Size(v);
switch (i) {
case 0: return 0;
case 1: return v->ob_digit[0];
@@ -1152,7 +1152,7 @@
}
v = (PyLongObject*)vv;
- switch(v->ob_size) {
+ switch(Py_Size(v)) {
case -1: return -v->ob_digit[0];
case 0: return 0;
case 1: return v->ob_digit[0];
@@ -1185,7 +1185,7 @@
}
v = (PyLongObject*)vv;
- switch(v->ob_size) {
+ switch(Py_Size(v)) {
case 0: return 0;
case 1: return v->ob_digit[0];
}
@@ -1217,11 +1217,11 @@
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- switch(v->ob_size) {
+ switch(Py_Size(v)) {
case 0: return 0;
case 1: return v->ob_digit[0];
}
- i = v->ob_size;
+ i = Py_Size(v);
sign = 1;
x = 0;
if (i < 0) {
@@ -1463,10 +1463,10 @@
return NULL;
p = PyString_AS_STRING(str) + sz;
*p = '\0';
- if (a->ob_size < 0)
+ if (Py_Size(a) < 0)
sign = '-';
- if (a->ob_size == 0) {
+ if (Py_Size(a) == 0) {
*--p = '0';
}
else if ((base & (base - 1)) == 0) {
@@ -1926,7 +1926,7 @@
/* reset the base to 0, else the exception message
doesn't make too much sense */
base = 0;
- if (z->ob_size != 0)
+ if (Py_Size(z) != 0)
goto onError;
/* there might still be other problems, therefore base
remains zero here for the same reason */
@@ -2034,9 +2034,9 @@
The quotient z has the sign of a*b;
the remainder r has the sign of a,
so a = b*z + r. */
- if ((a->ob_size < 0) != (b->ob_size < 0))
+ if ((Py_Size(a) < 0) != (Py_Size(b) < 0))
NEGATE(z);
- if (a->ob_size < 0 && (*prem)->ob_size != 0)
+ if (Py_Size(a) < 0 && Py_Size(*prem) != 0)
NEGATE(*prem);
*pdiv = z;
return 0;
@@ -2204,7 +2204,7 @@
/* This is designed so that Python ints and longs with the
same value hash to the same value, otherwise comparisons
of mapping keys will turn out weird */
- i = v->ob_size;
+ i = Py_Size(v);
switch(i) {
case -1: return v->ob_digit[0]==1 ? -2 : -v->ob_digit[0];
case 0: return 0;
@@ -2326,24 +2326,24 @@
CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
- if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) {
+ if (ABS(Py_Size(a)) <= 1 && ABS(Py_Size(b)) <= 1) {
PyObject *result = PyInt_FromLong(MEDIUM_VALUE(a) +
MEDIUM_VALUE(b));
Py_DECREF(a);
Py_DECREF(b);
return result;
}
- if (a->ob_size < 0) {
- if (b->ob_size < 0) {
+ if (Py_Size(a) < 0) {
+ if (Py_Size(b) < 0) {
z = x_add(a, b);
- if (z != NULL && z->ob_size != 0)
- z->ob_size = -(z->ob_size);
+ if (z != NULL && Py_Size(z) != 0)
+ Py_Size(z) = -(Py_Size(z));
}
else
z = x_sub(b, a);
}
else {
- if (b->ob_size < 0)
+ if (Py_Size(b) < 0)
z = x_sub(a, b);
else
z = x_add(a, b);
@@ -2360,23 +2360,23 @@
CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
- if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) {
+ if (ABS(Py_Size(a)) <= 1 && ABS(Py_Size(b)) <= 1) {
PyObject* r;
r = PyLong_FromLong(MEDIUM_VALUE(a)-MEDIUM_VALUE(b));
Py_DECREF(a);
Py_DECREF(b);
return r;
}
- if (a->ob_size < 0) {
- if (b->ob_size < 0)
+ if (Py_Size(a) < 0) {
+ if (Py_Size(b) < 0)
z = x_sub(a, b);
else
z = x_add(a, b);
- if (z != NULL && z->ob_size != 0)
- z->ob_size = -(z->ob_size);
+ if (z != NULL && Py_Size(z) != 0)
+ Py_Size(z) = -(Py_Size(z));
}
else {
- if (b->ob_size < 0)
+ if (Py_Size(b) < 0)
z = x_add(a, b);
else
z = x_sub(a, b);
@@ -2796,7 +2796,7 @@
return Py_NotImplemented;
}
- if (ABS(v->ob_size) <= 1 && ABS(w->ob_size) <= 1) {
+ if (ABS(Py_Size(v)) <= 1 && ABS(Py_Size(w)) <= 1) {
PyObject *r;
r = PyLong_FromLong(MEDIUM_VALUE(v)*MEDIUM_VALUE(w));
Py_DECREF(a);
@@ -2806,7 +2806,7 @@
z = k_mul(a, b);
/* Negate if exactly one of the inputs is negative. */
- if (((a->ob_size ^ b->ob_size) < 0) && z)
+ if (((Py_Size(a) ^ Py_Size(b)) < 0) && z)
NEGATE(z);
Py_DECREF(a);
Py_DECREF(b);
@@ -3167,7 +3167,7 @@
/* Implement ~x as -(x+1) */
PyLongObject *x;
PyLongObject *w;
- if (ABS(v->ob_size) <=1)
+ if (ABS(Py_Size(v)) <=1)
return PyLong_FromLong(-(MEDIUM_VALUE(v)+1));
w = (PyLongObject *)PyLong_FromLong(1L);
if (w == NULL)
@@ -3195,18 +3195,18 @@
long_neg(PyLongObject *v)
{
PyLongObject *z;
- if (ABS(v->ob_size) <= 1)
+ if (ABS(Py_Size(v)) <= 1)
return PyLong_FromLong(-MEDIUM_VALUE(v));
z = (PyLongObject *)_PyLong_Copy(v);
if (z != NULL)
- z->ob_size = -(v->ob_size);
+ Py_Size(z) = -(Py_Size(v));
return (PyObject *)z;
}
static PyObject *
long_abs(PyLongObject *v)
{
- if (v->ob_size < 0)
+ if (Py_Size(v) < 0)
return long_neg(v);
else
return long_pos(v);
@@ -3312,14 +3312,14 @@
wordshift = (int)shiftby / SHIFT;
remshift = (int)shiftby - wordshift * SHIFT;
- oldsize = ABS(a->ob_size);
+ oldsize = ABS(Py_Size(a));
newsize = oldsize + wordshift;
if (remshift)
++newsize;
z = _PyLong_New(newsize);
if (z == NULL)
goto lshift_error;
- if (a->ob_size < 0)
+ if (Py_Size(a) < 0)
NEGATE(z);
for (i = 0; i < wordshift; i++)
z->ob_digit[i] = 0;
@@ -3655,8 +3655,7 @@
};
PyTypeObject PyLong_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"int", /* tp_name */
/* See _PyLong_New for why this isn't
sizeof(PyLongObject) - sizeof(digit) */
@@ -3708,12 +3707,12 @@
PyLongObject *v = small_ints;
for (ival = -NSMALLNEGINTS; ival < 0; ival++, v++) {
PyObject_INIT(v, &PyLong_Type);
- v->ob_size = -1;
+ Py_Size(v) = -1;
v->ob_digit[0] = -ival;
}
for (; ival < NSMALLPOSINTS; ival++, v++) {
PyObject_INIT(v, &PyLong_Type);
- v->ob_size = ival ? 1 : 0;
+ Py_Size(v) = ival ? 1 : 0;
v->ob_digit[0] = ival;
}
#endif
Modified: python/branches/p3yk/Objects/rangeobject.c
==============================================================================
--- python/branches/p3yk/Objects/rangeobject.c (original)
+++ python/branches/p3yk/Objects/rangeobject.c Sat Jul 21 09:47:23 2007
@@ -303,8 +303,7 @@
};
PyTypeObject PyRange_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* Number of items for varobject */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"range", /* Name of this type */
sizeof(rangeobject), /* Basic object size */
0, /* Item size for varobject */
@@ -399,8 +398,7 @@
};
PyTypeObject Pyrangeiter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"rangeiterator", /* tp_name */
sizeof(rangeiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -551,8 +549,7 @@
}
static PyTypeObject Pylongrangeiter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"rangeiterator", /* tp_name */
sizeof(longrangeiterobject), /* tp_basicsize */
0, /* tp_itemsize */
Modified: python/branches/p3yk/Objects/setobject.c
==============================================================================
--- python/branches/p3yk/Objects/setobject.c (original)
+++ python/branches/p3yk/Objects/setobject.c Sat Jul 21 09:47:23 2007
@@ -578,21 +578,21 @@
if (status != 0) {
if (status < 0)
return status;
- fprintf(fp, "%s(...)", so->ob_type->tp_name);
+ fprintf(fp, "%s(...)", Py_Type(so)->tp_name);
return 0;
}
if (!so->used) {
Py_ReprLeave((PyObject*)so);
- fprintf(fp, "%s()", so->ob_type->tp_name);
+ fprintf(fp, "%s()", Py_Type(so)->tp_name);
return 0;
}
- if (so->ob_type == &PySet_Type) {
+ if (Py_Type(so) == &PySet_Type) {
literalform = 1;
fprintf(fp, "{");
} else
- fprintf(fp, "%s([", so->ob_type->tp_name);
+ fprintf(fp, "%s([", Py_Type(so)->tp_name);
while (set_next(so, &pos, &entry)) {
fputs(emit, fp);
emit = separator;
@@ -618,13 +618,13 @@
if (status != 0) {
if (status < 0)
return NULL;
- return PyString_FromFormat("%s(...)", so->ob_type->tp_name);
+ return PyString_FromFormat("%s(...)", Py_Type(so)->tp_name);
}
/* shortcut for the empty set */
if (!so->used) {
Py_ReprLeave((PyObject*)so);
- return PyString_FromFormat("%s()", so->ob_type->tp_name);
+ return PyString_FromFormat("%s()", Py_Type(so)->tp_name);
}
keys = PySequence_List((PyObject *)so);
@@ -635,13 +635,13 @@
if (listrepr == NULL)
goto done;
- if (so->ob_type == &PySet_Type) {
+ if (Py_Type(so) == &PySet_Type) {
char *s = PyString_AS_STRING(listrepr);
s += 1;
s[strlen(s)-1] = 0;
result = PyString_FromFormat("{%s}", s);
} else {
- result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name,
+ result = PyString_FromFormat("%s(%s)", Py_Type(so)->tp_name,
PyString_AS_STRING(listrepr));
}
Py_DECREF(listrepr);
Modified: python/branches/p3yk/Objects/stringobject.c
==============================================================================
--- python/branches/p3yk/Objects/stringobject.c (original)
+++ python/branches/p3yk/Objects/stringobject.c Sat Jul 21 09:47:23 2007
@@ -5110,8 +5110,7 @@
};
PyTypeObject PyStringIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"striterator", /* tp_name */
sizeof(striterobject), /* tp_basicsize */
0, /* tp_itemsize */
Modified: python/branches/p3yk/Objects/typeobject.c
==============================================================================
--- python/branches/p3yk/Objects/typeobject.c (original)
+++ python/branches/p3yk/Objects/typeobject.c Sat Jul 21 09:47:23 2007
@@ -422,9 +422,9 @@
return obj;
/* If the returned object is not an instance of type,
it won't be initialized. */
- if (!PyType_IsSubtype(obj->ob_type, type))
+ if (!PyType_IsSubtype(Py_Type(obj), type))
return obj;
- type = obj->ob_type;
+ type = Py_Type(obj);
if (type->tp_init != NULL &&
type->tp_init(obj, args, kwds) < 0) {
Py_DECREF(obj);
@@ -1432,7 +1432,7 @@
{
PyErr_Format(PyExc_TypeError,
"this __dict__ descriptor does not support "
- "'%.200s' objects", obj->ob_type->tp_name);
+ "'%.200s' objects", Py_Type(obj)->tp_name);
}
static PyObject *
@@ -1442,7 +1442,7 @@
PyObject *dict;
PyTypeObject *base;
- base = get_builtin_base_with_dict(obj->ob_type);
+ base = get_builtin_base_with_dict(Py_Type(obj));
if (base != NULL) {
descrgetfunc func;
PyObject *descr = get_dict_descriptor(base);
@@ -1450,12 +1450,12 @@
raise_dict_descr_error(obj);
return NULL;
}
- func = descr->ob_type->tp_descr_get;
+ func = Py_Type(descr)->tp_descr_get;
if (func == NULL) {
raise_dict_descr_error(obj);
return NULL;
}
- return func(descr, obj, (PyObject *)(obj->ob_type));
+ return func(descr, obj, (PyObject *)(Py_Type(obj)));
}
dictptr = _PyObject_GetDictPtr(obj);
@@ -1478,7 +1478,7 @@
PyObject *dict;
PyTypeObject *base;
- base = get_builtin_base_with_dict(obj->ob_type);
+ base = get_builtin_base_with_dict(Py_Type(obj));
if (base != NULL) {
descrsetfunc func;
PyObject *descr = get_dict_descriptor(base);
@@ -1486,7 +1486,7 @@
raise_dict_descr_error(obj);
return -1;
}
- func = descr->ob_type->tp_descr_set;
+ func = Py_Type(descr)->tp_descr_set;
if (func == NULL) {
raise_dict_descr_error(obj);
return -1;
@@ -1707,7 +1707,7 @@
winner = metatype;
for (i = 0; i < nbases; i++) {
tmp = PyTuple_GET_ITEM(bases, i);
- tmptype = tmp->ob_type;
+ tmptype = Py_Type(tmp);
if (PyType_IsSubtype(winner, tmptype))
continue;
if (PyType_IsSubtype(tmptype, winner)) {
@@ -3669,7 +3669,7 @@
if (!check_num_args(args, 1))
return NULL;
other = PyTuple_GET_ITEM(args, 0);
- if (!PyType_IsSubtype(other->ob_type, self->ob_type)) {
+ if (!PyType_IsSubtype(Py_Type(other), Py_Type(self))) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
@@ -4524,7 +4524,7 @@
PyErr_Format(PyExc_TypeError,
"__bool__ should return "
"bool, returned %s",
- temp->ob_type->tp_name);
+ Py_Type(temp)->tp_name);
result = -1;
}
Py_DECREF(temp);
@@ -4682,7 +4682,7 @@
if (func == NULL) {
PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
- self->ob_type->tp_name);
+ Py_Type(self)->tp_name);
return -1;
}
@@ -5922,7 +5922,7 @@
if (!PyType_Check(type)) {
PyErr_Format(PyExc_SystemError,
"super(): __class__ is not a type (%s)",
- type->ob_type->tp_name);
+ Py_Type(type)->tp_name);
return -1;
}
break;
Modified: python/branches/p3yk/Objects/unicodeobject.c
==============================================================================
--- python/branches/p3yk/Objects/unicodeobject.c (original)
+++ python/branches/p3yk/Objects/unicodeobject.c Sat Jul 21 09:47:23 2007
@@ -8151,8 +8151,7 @@
};
PyTypeObject PyUnicodeIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"unicodeiterator", /* tp_name */
sizeof(unicodeiterobject), /* tp_basicsize */
0, /* tp_itemsize */
Modified: python/branches/p3yk/Python/ceval.c
==============================================================================
--- python/branches/p3yk/Python/ceval.c (original)
+++ python/branches/p3yk/Python/ceval.c Sat Jul 21 09:47:23 2007
@@ -3149,7 +3149,7 @@
*--sp = PyList_GET_ITEM(l, ll - j);
}
/* Resize the list. */
- ((PyListObject *)l)->ob_size = ll - argcntafter;
+ Py_Size(l) = ll - argcntafter;
Py_DECREF(it);
return 1;
Modified: python/branches/p3yk/Python/marshal.c
==============================================================================
--- python/branches/p3yk/Python/marshal.c (original)
+++ python/branches/p3yk/Python/marshal.c Sat Jul 21 09:47:23 2007
@@ -150,7 +150,7 @@
PyLongObject *ob = (PyLongObject *)v;
PyErr_Clear();
w_byte(TYPE_LONG, p);
- n = ob->ob_size;
+ n = Py_Size(ob);
w_long((long)n, p);
if (n < 0)
n = -n;
@@ -573,7 +573,7 @@
retval = NULL;
break;
}
- ob->ob_size = n;
+ Py_Size(ob) = n;
for (i = 0; i < size; i++) {
int digit = r_short(p);
if (digit < 0) {
More information about the Python-3000-checkins
mailing list