More C++-compliance. Note especially listobject.c - to get C++ to accept the
PyTypeObject structures, I had to make prototypes for the functions, and move the structure definition ahead of the functions. I'd dearly like a better way to do this - to change this would make for a massive set of changes to the codebase. There's still some warnings - this is purely to get rid of errors first.
This commit is contained in:
parent
bbfe4fad36
commit
377be11ee1
|
@ -169,7 +169,7 @@ PyBuffer_New(Py_ssize_t size)
|
||||||
}
|
}
|
||||||
/* XXX: check for overflow in multiply */
|
/* XXX: check for overflow in multiply */
|
||||||
/* Inline PyObject_New */
|
/* Inline PyObject_New */
|
||||||
o = PyObject_MALLOC(sizeof(*b) + size);
|
o = (PyObject *)PyObject_MALLOC(sizeof(*b) + size);
|
||||||
if ( o == NULL )
|
if ( o == NULL )
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
b = (PyBufferObject *) PyObject_INIT(o, &PyBuffer_Type);
|
b = (PyBufferObject *) PyObject_INIT(o, &PyBuffer_Type);
|
||||||
|
@ -305,7 +305,7 @@ buffer_str(PyBufferObject *self)
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
if (!get_buf(self, &ptr, &size))
|
if (!get_buf(self, &ptr, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
return PyString_FromStringAndSize(ptr, size);
|
return PyString_FromStringAndSize((const char *)ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sequence methods */
|
/* Sequence methods */
|
||||||
|
|
|
@ -208,7 +208,7 @@ class_getattr(register PyClassObject *op, PyObject *name)
|
||||||
{
|
{
|
||||||
register PyObject *v;
|
register PyObject *v;
|
||||||
register char *sname = PyString_AsString(name);
|
register char *sname = PyString_AsString(name);
|
||||||
PyClassObject *class;
|
PyClassObject *klass;
|
||||||
descrgetfunc f;
|
descrgetfunc f;
|
||||||
|
|
||||||
if (sname[0] == '_' && sname[1] == '_') {
|
if (sname[0] == '_' && sname[1] == '_') {
|
||||||
|
@ -234,7 +234,7 @@ class_getattr(register PyClassObject *op, PyObject *name)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v = class_lookup(op, name, &class);
|
v = class_lookup(op, name, &klass);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PyErr_Format(PyExc_AttributeError,
|
PyErr_Format(PyExc_AttributeError,
|
||||||
"class %.50s has no attribute '%.400s'",
|
"class %.50s has no attribute '%.400s'",
|
||||||
|
@ -481,23 +481,23 @@ PyTypeObject PyClass_Type = {
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
PyClass_IsSubclass(PyObject *class, PyObject *base)
|
PyClass_IsSubclass(PyObject *klass, PyObject *base)
|
||||||
{
|
{
|
||||||
Py_ssize_t i, n;
|
Py_ssize_t i, n;
|
||||||
PyClassObject *cp;
|
PyClassObject *cp;
|
||||||
if (class == base)
|
if (klass == base)
|
||||||
return 1;
|
return 1;
|
||||||
if (PyTuple_Check(base)) {
|
if (PyTuple_Check(base)) {
|
||||||
n = PyTuple_GET_SIZE(base);
|
n = PyTuple_GET_SIZE(base);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (PyClass_IsSubclass(class, PyTuple_GET_ITEM(base, i)))
|
if (PyClass_IsSubclass(klass, PyTuple_GET_ITEM(base, i)))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (class == NULL || !PyClass_Check(class))
|
if (klass == NULL || !PyClass_Check(klass))
|
||||||
return 0;
|
return 0;
|
||||||
cp = (PyClassObject *)class;
|
cp = (PyClassObject *)klass;
|
||||||
n = PyTuple_Size(cp->cl_bases);
|
n = PyTuple_Size(cp->cl_bases);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (PyClass_IsSubclass(PyTuple_GetItem(cp->cl_bases, i), base))
|
if (PyClass_IsSubclass(PyTuple_GetItem(cp->cl_bases, i), base))
|
||||||
|
@ -719,7 +719,7 @@ static PyObject *
|
||||||
instance_getattr2(register PyInstanceObject *inst, PyObject *name)
|
instance_getattr2(register PyInstanceObject *inst, PyObject *name)
|
||||||
{
|
{
|
||||||
register PyObject *v;
|
register PyObject *v;
|
||||||
PyClassObject *class;
|
PyClassObject *klass;
|
||||||
descrgetfunc f;
|
descrgetfunc f;
|
||||||
|
|
||||||
v = PyDict_GetItem(inst->in_dict, name);
|
v = PyDict_GetItem(inst->in_dict, name);
|
||||||
|
@ -727,7 +727,7 @@ instance_getattr2(register PyInstanceObject *inst, PyObject *name)
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
v = class_lookup(inst->in_class, name, &class);
|
v = class_lookup(inst->in_class, name, &klass);
|
||||||
if (v != NULL) {
|
if (v != NULL) {
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
f = TP_DESCR_GET(v->ob_type);
|
f = TP_DESCR_GET(v->ob_type);
|
||||||
|
@ -767,7 +767,7 @@ PyObject *
|
||||||
_PyInstance_Lookup(PyObject *pinst, PyObject *name)
|
_PyInstance_Lookup(PyObject *pinst, PyObject *name)
|
||||||
{
|
{
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
PyClassObject *class;
|
PyClassObject *klass;
|
||||||
PyInstanceObject *inst; /* pinst cast to the right type */
|
PyInstanceObject *inst; /* pinst cast to the right type */
|
||||||
|
|
||||||
assert(PyInstance_Check(pinst));
|
assert(PyInstance_Check(pinst));
|
||||||
|
@ -777,7 +777,7 @@ _PyInstance_Lookup(PyObject *pinst, PyObject *name)
|
||||||
|
|
||||||
v = PyDict_GetItem(inst->in_dict, name);
|
v = PyDict_GetItem(inst->in_dict, name);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
v = class_lookup(inst->in_class, name, &class);
|
v = class_lookup(inst->in_class, name, &klass);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2123,7 +2123,7 @@ PyTypeObject PyInstance_Type = {
|
||||||
static PyMethodObject *free_list;
|
static PyMethodObject *free_list;
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
|
PyMethod_New(PyObject *func, PyObject *self, PyObject *klass)
|
||||||
{
|
{
|
||||||
register PyMethodObject *im;
|
register PyMethodObject *im;
|
||||||
if (!PyCallable_Check(func)) {
|
if (!PyCallable_Check(func)) {
|
||||||
|
@ -2145,8 +2145,8 @@ PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
|
||||||
im->im_func = func;
|
im->im_func = func;
|
||||||
Py_XINCREF(self);
|
Py_XINCREF(self);
|
||||||
im->im_self = self;
|
im->im_self = self;
|
||||||
Py_XINCREF(class);
|
Py_XINCREF(klass);
|
||||||
im->im_class = class;
|
im->im_class = klass;
|
||||||
_PyObject_GC_TRACK(im);
|
_PyObject_GC_TRACK(im);
|
||||||
return (PyObject *)im;
|
return (PyObject *)im;
|
||||||
}
|
}
|
||||||
|
@ -2368,15 +2368,15 @@ instancemethod_traverse(PyMethodObject *im, visitproc visit, void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
getclassname(PyObject *class, char *buf, int bufsize)
|
getclassname(PyObject *klass, char *buf, int bufsize)
|
||||||
{
|
{
|
||||||
PyObject *name;
|
PyObject *name;
|
||||||
|
|
||||||
assert(bufsize > 1);
|
assert(bufsize > 1);
|
||||||
strcpy(buf, "?"); /* Default outcome */
|
strcpy(buf, "?"); /* Default outcome */
|
||||||
if (class == NULL)
|
if (klass == NULL)
|
||||||
return;
|
return;
|
||||||
name = PyObject_GetAttrString(class, "__name__");
|
name = PyObject_GetAttrString(klass, "__name__");
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
/* This function cannot return an exception */
|
/* This function cannot return an exception */
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -2392,7 +2392,7 @@ getclassname(PyObject *class, char *buf, int bufsize)
|
||||||
static void
|
static void
|
||||||
getinstclassname(PyObject *inst, char *buf, int bufsize)
|
getinstclassname(PyObject *inst, char *buf, int bufsize)
|
||||||
{
|
{
|
||||||
PyObject *class;
|
PyObject *klass;
|
||||||
|
|
||||||
if (inst == NULL) {
|
if (inst == NULL) {
|
||||||
assert(bufsize > 0 && (size_t)bufsize > strlen("nothing"));
|
assert(bufsize > 0 && (size_t)bufsize > strlen("nothing"));
|
||||||
|
@ -2400,22 +2400,22 @@ getinstclassname(PyObject *inst, char *buf, int bufsize)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
class = PyObject_GetAttrString(inst, "__class__");
|
klass = PyObject_GetAttrString(inst, "__class__");
|
||||||
if (class == NULL) {
|
if (klass == NULL) {
|
||||||
/* This function cannot return an exception */
|
/* This function cannot return an exception */
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
class = (PyObject *)(inst->ob_type);
|
klass = (PyObject *)(inst->ob_type);
|
||||||
Py_INCREF(class);
|
Py_INCREF(klass);
|
||||||
}
|
}
|
||||||
getclassname(class, buf, bufsize);
|
getclassname(klass, buf, bufsize);
|
||||||
Py_XDECREF(class);
|
Py_XDECREF(klass);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
instancemethod_call(PyObject *func, PyObject *arg, PyObject *kw)
|
instancemethod_call(PyObject *func, PyObject *arg, PyObject *kw)
|
||||||
{
|
{
|
||||||
PyObject *self = PyMethod_GET_SELF(func);
|
PyObject *self = PyMethod_GET_SELF(func);
|
||||||
PyObject *class = PyMethod_GET_CLASS(func);
|
PyObject *klass = PyMethod_GET_CLASS(func);
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
func = PyMethod_GET_FUNCTION(func);
|
func = PyMethod_GET_FUNCTION(func);
|
||||||
|
@ -2428,14 +2428,14 @@ instancemethod_call(PyObject *func, PyObject *arg, PyObject *kw)
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
ok = 0;
|
ok = 0;
|
||||||
else {
|
else {
|
||||||
ok = PyObject_IsInstance(self, class);
|
ok = PyObject_IsInstance(self, klass);
|
||||||
if (ok < 0)
|
if (ok < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
char clsbuf[256];
|
char clsbuf[256];
|
||||||
char instbuf[256];
|
char instbuf[256];
|
||||||
getclassname(class, clsbuf, sizeof(clsbuf));
|
getclassname(klass, clsbuf, sizeof(clsbuf));
|
||||||
getinstclassname(self, instbuf, sizeof(instbuf));
|
getinstclassname(self, instbuf, sizeof(instbuf));
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"unbound method %s%s must be called with "
|
"unbound method %s%s must be called with "
|
||||||
|
|
|
@ -9,8 +9,6 @@ typedef struct {
|
||||||
PyObject* en_result; /* result tuple */
|
PyObject* en_result; /* result tuple */
|
||||||
} enumobject;
|
} enumobject;
|
||||||
|
|
||||||
PyTypeObject PyEnum_Type;
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
enum_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
enum_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
|
|
|
@ -313,7 +313,8 @@ PyFile_SetBufSize(PyObject *f, int bufsize)
|
||||||
PyMem_Free(file->f_setbuf);
|
PyMem_Free(file->f_setbuf);
|
||||||
file->f_setbuf = NULL;
|
file->f_setbuf = NULL;
|
||||||
} else {
|
} else {
|
||||||
file->f_setbuf = PyMem_Realloc(file->f_setbuf, bufsize);
|
file->f_setbuf = (char *)PyMem_Realloc(file->f_setbuf,
|
||||||
|
bufsize);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SETVBUF
|
#ifdef HAVE_SETVBUF
|
||||||
setvbuf(file->f_fp, file->f_setbuf, type, bufsize);
|
setvbuf(file->f_fp, file->f_setbuf, type, bufsize);
|
||||||
|
@ -1391,7 +1392,7 @@ file_readlines(PyFileObject *f, PyObject *args)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
totalread += nread;
|
totalread += nread;
|
||||||
p = memchr(buffer+nfilled, '\n', nread);
|
p = (char *)memchr(buffer+nfilled, '\n', nread);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
/* Need a larger buffer to fit this line */
|
/* Need a larger buffer to fit this line */
|
||||||
nfilled += nread;
|
nfilled += nread;
|
||||||
|
@ -1431,7 +1432,7 @@ file_readlines(PyFileObject *f, PyObject *args)
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
goto error;
|
goto error;
|
||||||
q = p;
|
q = p;
|
||||||
p = memchr(q, '\n', end-q);
|
p = (char *)memchr(q, '\n', end-q);
|
||||||
} while (p != NULL);
|
} while (p != NULL);
|
||||||
/* Move the remaining incomplete line to the start */
|
/* Move the remaining incomplete line to the start */
|
||||||
nfilled = end-q;
|
nfilled = end-q;
|
||||||
|
@ -1809,7 +1810,7 @@ readahead(PyFileObject *f, int bufsize)
|
||||||
else
|
else
|
||||||
drop_readahead(f);
|
drop_readahead(f);
|
||||||
}
|
}
|
||||||
if ((f->f_buf = PyMem_Malloc(bufsize)) == NULL) {
|
if ((f->f_buf = (char *)PyMem_Malloc(bufsize)) == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1852,7 +1853,7 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return (PyStringObject *)
|
return (PyStringObject *)
|
||||||
PyString_FromStringAndSize(NULL, skip);
|
PyString_FromStringAndSize(NULL, skip);
|
||||||
bufptr = memchr(f->f_bufptr, '\n', len);
|
bufptr = (char *)memchr(f->f_bufptr, '\n', len);
|
||||||
if (bufptr != NULL) {
|
if (bufptr != NULL) {
|
||||||
bufptr++; /* Count the '\n' */
|
bufptr++; /* Count the '\n' */
|
||||||
len = bufptr - f->f_bufptr;
|
len = bufptr - f->f_bufptr;
|
||||||
|
|
|
@ -959,21 +959,21 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *tmp, *new;
|
PyObject *tmp, *newobj;
|
||||||
|
|
||||||
assert(PyType_IsSubtype(type, &PyFloat_Type));
|
assert(PyType_IsSubtype(type, &PyFloat_Type));
|
||||||
tmp = float_new(&PyFloat_Type, args, kwds);
|
tmp = float_new(&PyFloat_Type, args, kwds);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(PyFloat_CheckExact(tmp));
|
assert(PyFloat_CheckExact(tmp));
|
||||||
new = type->tp_alloc(type, 0);
|
newobj = type->tp_alloc(type, 0);
|
||||||
if (new == NULL) {
|
if (newobj == NULL) {
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
((PyFloatObject *)new)->ob_fval = ((PyFloatObject *)tmp)->ob_fval;
|
((PyFloatObject *)newobj)->ob_fval = ((PyFloatObject *)tmp)->ob_fval;
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return new;
|
return newobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -376,7 +376,7 @@ PyObject *
|
||||||
PyInt_FromUnicode(Py_UNICODE *s, Py_ssize_t length, int base)
|
PyInt_FromUnicode(Py_UNICODE *s, Py_ssize_t length, int base)
|
||||||
{
|
{
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
char *buffer = PyMem_MALLOC(length+1);
|
char *buffer = (char *)PyMem_MALLOC(length+1);
|
||||||
|
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -982,7 +982,7 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *tmp, *new;
|
PyObject *tmp, *newobj;
|
||||||
long ival;
|
long ival;
|
||||||
|
|
||||||
assert(PyType_IsSubtype(type, &PyInt_Type));
|
assert(PyType_IsSubtype(type, &PyInt_Type));
|
||||||
|
@ -999,14 +999,14 @@ int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
ival = ((PyIntObject *)tmp)->ob_ival;
|
ival = ((PyIntObject *)tmp)->ob_ival;
|
||||||
}
|
}
|
||||||
|
|
||||||
new = type->tp_alloc(type, 0);
|
newobj = type->tp_alloc(type, 0);
|
||||||
if (new == NULL) {
|
if (newobj == NULL) {
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
((PyIntObject *)new)->ob_ival = ival;
|
((PyIntObject *)newobj)->ob_ival = ival;
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return new;
|
return newobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -1805,28 +1805,11 @@ typedef struct {
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
} sortwrapperobject;
|
} sortwrapperobject;
|
||||||
|
|
||||||
static PyTypeObject sortwrapper_type;
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
sortwrapper_richcompare(sortwrapperobject *a, sortwrapperobject *b, int op)
|
|
||||||
{
|
|
||||||
if (!PyObject_TypeCheck(b, &sortwrapper_type)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"expected a sortwrapperobject");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return PyObject_RichCompare(a->key, b->key, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sortwrapper_dealloc(sortwrapperobject *so)
|
|
||||||
{
|
|
||||||
Py_XDECREF(so->key);
|
|
||||||
Py_XDECREF(so->value);
|
|
||||||
PyObject_Del(so);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyDoc_STRVAR(sortwrapper_doc, "Object wrapper with a custom sort key.");
|
PyDoc_STRVAR(sortwrapper_doc, "Object wrapper with a custom sort key.");
|
||||||
|
static PyObject *
|
||||||
|
sortwrapper_richcompare(sortwrapperobject *, sortwrapperobject *, int);
|
||||||
|
static void
|
||||||
|
sortwrapper_dealloc(sortwrapperobject *);
|
||||||
|
|
||||||
static PyTypeObject sortwrapper_type = {
|
static PyTypeObject sortwrapper_type = {
|
||||||
PyObject_HEAD_INIT(&PyType_Type)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
|
@ -1858,6 +1841,26 @@ static PyTypeObject sortwrapper_type = {
|
||||||
(richcmpfunc)sortwrapper_richcompare, /* tp_richcompare */
|
(richcmpfunc)sortwrapper_richcompare, /* tp_richcompare */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
sortwrapper_richcompare(sortwrapperobject *a, sortwrapperobject *b, int op)
|
||||||
|
{
|
||||||
|
if (!PyObject_TypeCheck(b, &sortwrapper_type)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"expected a sortwrapperobject");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return PyObject_RichCompare(a->key, b->key, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sortwrapper_dealloc(sortwrapperobject *so)
|
||||||
|
{
|
||||||
|
Py_XDECREF(so->key);
|
||||||
|
Py_XDECREF(so->value);
|
||||||
|
PyObject_Del(so);
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns a new reference to a sortwrapper.
|
/* Returns a new reference to a sortwrapper.
|
||||||
Consumes the references to the two underlying objects. */
|
Consumes the references to the two underlying objects. */
|
||||||
|
|
||||||
|
@ -2698,7 +2701,53 @@ typedef struct {
|
||||||
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
|
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
|
||||||
} listiterobject;
|
} listiterobject;
|
||||||
|
|
||||||
PyTypeObject PyListIter_Type;
|
static PyObject *list_iter(PyObject *);
|
||||||
|
static void listiter_dealloc(listiterobject *);
|
||||||
|
static int listiter_traverse(listiterobject *, visitproc, void *);
|
||||||
|
static PyObject *listiter_next(listiterobject *);
|
||||||
|
static PyObject *listiter_len(listiterobject *);
|
||||||
|
|
||||||
|
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
|
||||||
|
|
||||||
|
static PyMethodDef listiter_methods[] = {
|
||||||
|
{"__length_hint__", (PyCFunction)listiter_len, METH_NOARGS, length_hint_doc},
|
||||||
|
{NULL, NULL} /* sentinel */
|
||||||
|
};
|
||||||
|
|
||||||
|
PyTypeObject PyListIter_Type = {
|
||||||
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
|
0, /* ob_size */
|
||||||
|
"listiterator", /* tp_name */
|
||||||
|
sizeof(listiterobject), /* tp_basicsize */
|
||||||
|
0, /* tp_itemsize */
|
||||||
|
/* methods */
|
||||||
|
(destructor)listiter_dealloc, /* tp_dealloc */
|
||||||
|
0, /* tp_print */
|
||||||
|
0, /* tp_getattr */
|
||||||
|
0, /* tp_setattr */
|
||||||
|
0, /* tp_compare */
|
||||||
|
0, /* tp_repr */
|
||||||
|
0, /* tp_as_number */
|
||||||
|
0, /* tp_as_sequence */
|
||||||
|
0, /* tp_as_mapping */
|
||||||
|
0, /* tp_hash */
|
||||||
|
0, /* tp_call */
|
||||||
|
0, /* tp_str */
|
||||||
|
PyObject_GenericGetAttr, /* tp_getattro */
|
||||||
|
0, /* tp_setattro */
|
||||||
|
0, /* tp_as_buffer */
|
||||||
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||||
|
0, /* tp_doc */
|
||||||
|
(traverseproc)listiter_traverse, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
PyObject_SelfIter, /* tp_iter */
|
||||||
|
(iternextfunc)listiter_next, /* tp_iternext */
|
||||||
|
listiter_methods, /* tp_methods */
|
||||||
|
0, /* tp_members */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
list_iter(PyObject *seq)
|
list_iter(PyObject *seq)
|
||||||
|
@ -2770,29 +2819,40 @@ listiter_len(listiterobject *it)
|
||||||
}
|
}
|
||||||
return PyInt_FromLong(0);
|
return PyInt_FromLong(0);
|
||||||
}
|
}
|
||||||
|
/*********************** List Reverse Iterator **************************/
|
||||||
|
|
||||||
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
Py_ssize_t it_index;
|
||||||
|
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
|
||||||
|
} listreviterobject;
|
||||||
|
|
||||||
static PyMethodDef listiter_methods[] = {
|
static PyObject *list_reversed(PyListObject *, PyObject *);
|
||||||
{"__length_hint__", (PyCFunction)listiter_len, METH_NOARGS, length_hint_doc},
|
static void listreviter_dealloc(listreviterobject *);
|
||||||
{NULL, NULL} /* sentinel */
|
static int listreviter_traverse(listreviterobject *, visitproc, void *);
|
||||||
|
static PyObject *listreviter_next(listreviterobject *);
|
||||||
|
static Py_ssize_t listreviter_len(listreviterobject *);
|
||||||
|
|
||||||
|
static PySequenceMethods listreviter_as_sequence = {
|
||||||
|
(lenfunc)listreviter_len, /* sq_length */
|
||||||
|
0, /* sq_concat */
|
||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PyListIter_Type = {
|
PyTypeObject PyListRevIter_Type = {
|
||||||
PyObject_HEAD_INIT(&PyType_Type)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
0, /* ob_size */
|
0, /* ob_size */
|
||||||
"listiterator", /* tp_name */
|
"listreverseiterator", /* tp_name */
|
||||||
sizeof(listiterobject), /* tp_basicsize */
|
sizeof(listreviterobject), /* tp_basicsize */
|
||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
/* methods */
|
/* methods */
|
||||||
(destructor)listiter_dealloc, /* tp_dealloc */
|
(destructor)listreviter_dealloc, /* tp_dealloc */
|
||||||
0, /* tp_print */
|
0, /* tp_print */
|
||||||
0, /* tp_getattr */
|
0, /* tp_getattr */
|
||||||
0, /* tp_setattr */
|
0, /* tp_setattr */
|
||||||
0, /* tp_compare */
|
0, /* tp_compare */
|
||||||
0, /* tp_repr */
|
0, /* tp_repr */
|
||||||
0, /* tp_as_number */
|
0, /* tp_as_number */
|
||||||
0, /* tp_as_sequence */
|
&listreviter_as_sequence, /* tp_as_sequence */
|
||||||
0, /* tp_as_mapping */
|
0, /* tp_as_mapping */
|
||||||
0, /* tp_hash */
|
0, /* tp_hash */
|
||||||
0, /* tp_call */
|
0, /* tp_call */
|
||||||
|
@ -2802,26 +2862,15 @@ PyTypeObject PyListIter_Type = {
|
||||||
0, /* tp_as_buffer */
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||||
0, /* tp_doc */
|
0, /* tp_doc */
|
||||||
(traverseproc)listiter_traverse, /* tp_traverse */
|
(traverseproc)listreviter_traverse, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
0, /* tp_richcompare */
|
0, /* tp_richcompare */
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
PyObject_SelfIter, /* tp_iter */
|
PyObject_SelfIter, /* tp_iter */
|
||||||
(iternextfunc)listiter_next, /* tp_iternext */
|
(iternextfunc)listreviter_next, /* tp_iternext */
|
||||||
listiter_methods, /* tp_methods */
|
0,
|
||||||
0, /* tp_members */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*********************** List Reverse Iterator **************************/
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
Py_ssize_t it_index;
|
|
||||||
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
|
|
||||||
} listreviterobject;
|
|
||||||
|
|
||||||
PyTypeObject PyListRevIter_Type;
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
list_reversed(PyListObject *seq, PyObject *unused)
|
list_reversed(PyListObject *seq, PyObject *unused)
|
||||||
{
|
{
|
||||||
|
@ -2884,40 +2933,3 @@ listreviter_len(listreviterobject *it)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PySequenceMethods listreviter_as_sequence = {
|
|
||||||
(lenfunc)listreviter_len, /* sq_length */
|
|
||||||
0, /* sq_concat */
|
|
||||||
};
|
|
||||||
|
|
||||||
PyTypeObject PyListRevIter_Type = {
|
|
||||||
PyObject_HEAD_INIT(&PyType_Type)
|
|
||||||
0, /* ob_size */
|
|
||||||
"listreverseiterator", /* tp_name */
|
|
||||||
sizeof(listreviterobject), /* tp_basicsize */
|
|
||||||
0, /* tp_itemsize */
|
|
||||||
/* methods */
|
|
||||||
(destructor)listreviter_dealloc, /* tp_dealloc */
|
|
||||||
0, /* tp_print */
|
|
||||||
0, /* tp_getattr */
|
|
||||||
0, /* tp_setattr */
|
|
||||||
0, /* tp_compare */
|
|
||||||
0, /* tp_repr */
|
|
||||||
0, /* tp_as_number */
|
|
||||||
&listreviter_as_sequence, /* tp_as_sequence */
|
|
||||||
0, /* tp_as_mapping */
|
|
||||||
0, /* tp_hash */
|
|
||||||
0, /* tp_call */
|
|
||||||
0, /* tp_str */
|
|
||||||
PyObject_GenericGetAttr, /* tp_getattro */
|
|
||||||
0, /* tp_setattro */
|
|
||||||
0, /* tp_as_buffer */
|
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
|
||||||
0, /* tp_doc */
|
|
||||||
(traverseproc)listreviter_traverse, /* tp_traverse */
|
|
||||||
0, /* tp_clear */
|
|
||||||
0, /* tp_richcompare */
|
|
||||||
0, /* tp_weaklistoffset */
|
|
||||||
PyObject_SelfIter, /* tp_iter */
|
|
||||||
(iternextfunc)listreviter_next, /* tp_iternext */
|
|
||||||
0,
|
|
||||||
};
|
|
||||||
|
|
|
@ -1476,7 +1476,7 @@ PyObject *
|
||||||
PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
|
PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
|
||||||
{
|
{
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
char *buffer = PyMem_MALLOC(length+1);
|
char *buffer = (char *)PyMem_MALLOC(length+1);
|
||||||
|
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3088,7 +3088,7 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyLongObject *tmp, *new;
|
PyLongObject *tmp, *newobj;
|
||||||
Py_ssize_t i, n;
|
Py_ssize_t i, n;
|
||||||
|
|
||||||
assert(PyType_IsSubtype(type, &PyLong_Type));
|
assert(PyType_IsSubtype(type, &PyLong_Type));
|
||||||
|
@ -3099,17 +3099,17 @@ long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
n = tmp->ob_size;
|
n = tmp->ob_size;
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n = -n;
|
n = -n;
|
||||||
new = (PyLongObject *)type->tp_alloc(type, n);
|
newobj = (PyLongObject *)type->tp_alloc(type, n);
|
||||||
if (new == NULL) {
|
if (newobj == NULL) {
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
assert(PyLong_Check(new));
|
assert(PyLong_Check(newobj));
|
||||||
new->ob_size = tmp->ob_size;
|
newobj->ob_size = tmp->ob_size;
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
new->ob_digit[i] = tmp->ob_digit[i];
|
newobj->ob_digit[i] = tmp->ob_digit[i];
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return (PyObject *)new;
|
return (PyObject *)newobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Reference in New Issue