Rev 4765: factor out the check of each internal item. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-st-concat
John Arbash Meinel
john at arbash-meinel.com
Wed Oct 21 05:21:24 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1-st-concat
------------------------------------------------------------
revno: 4765
revision-id: john at arbash-meinel.com-20091021042107-we0xfhc0bhr7m7l9
parent: john at arbash-meinel.com-20091021041454-gofau8rwtplnolaf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-st-concat
timestamp: Tue 2009-10-20 23:21:07 -0500
message:
factor out the check of each internal item.
-------------- next part --------------
=== modified file 'bzrlib/_static_tuple_c.c'
--- a/bzrlib/_static_tuple_c.c 2009-10-21 04:14:54 +0000
+++ b/bzrlib/_static_tuple_c.c 2009-10-21 04:21:07 +0000
@@ -220,6 +220,32 @@
}
+/* Check that all items we point to are 'valid' */
+static int
+StaticTuple_check_items(StaticTuple *self)
+{
+ int i;
+ PyObject *obj;
+
+ for (i = 0; i < self->size; ++i) {
+ obj = self->items[i];
+ if (obj == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "StaticTuple(...)"
+ " should not have a NULL entry.");
+ return 0;
+ }
+ if (!PyString_CheckExact(obj)) {
+ if (!StaticTuple_CheckExact(obj)) {
+ PyErr_Format(PyExc_TypeError, "StaticTuple(...)"
+ " requires that all items are strings or StaticTuples"
+ " not %s.", Py_TYPE(obj)->tp_name);
+ return 0;
+ }
+ }
+ }
+ return 1;
+}
+
static PyObject *
StaticTuple_new_constructor(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
@@ -248,18 +274,13 @@
}
for (i = 0; i < len; ++i) {
obj = PyTuple_GET_ITEM(args, i);
- if (!PyString_CheckExact(obj)) {
- if (!StaticTuple_CheckExact(obj)) {
- PyErr_Format(PyExc_TypeError, "StaticTuple(...)"
- " requires that all items are strings or StaticTuples"
- " not %s.", Py_TYPE(obj)->tp_name);
- type->tp_dealloc((PyObject *)self);
- return NULL;
- }
- }
Py_INCREF(obj);
self->items[i] = obj;
}
+ if (!StaticTuple_check_items(self)) {
+ type->tp_dealloc((PyObject *)self);
+ return NULL;
+ }
return (PyObject *)self;
}
More information about the bazaar-commits
mailing list