0

pushed exception setting into the relevant function, removed redundant exceptions

The following functions set exceptions automatically:
PyImport_ImportModule, PyObject_GetAttrString, PyArg_ParseTuple. All
the exception setting functions in c_overviewer should act the same
way and set their own exceptions before returning.

Notably, PyDict_GetItemString does *not* set exceptions, so it is
handled specially in render_mode_find_interface.
This commit is contained in:
Aaron Griffith
2011-11-22 17:32:47 -05:00
parent 4739f4af93
commit bca7867b86
2 changed files with 20 additions and 20 deletions

View File

@@ -45,47 +45,47 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
textures = PyImport_ImportModule("overviewer_core.textures");
/* ensure none of these pointers are NULL */
if ((!textures)) {
return PyErr_Format(PyExc_ImportError, "Failed to import overviewer_core.textures");
return NULL;
}
chunk_mod = PyImport_ImportModule("overviewer_core.chunk");
/* ensure none of these pointers are NULL */
if ((!chunk_mod)) {
return PyErr_Format(PyExc_ImportError, "Failed to import overviewer_core.chunk");
return NULL;
}
blockmap = PyObject_GetAttrString(textures, "blockmap");
if (!blockmap)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.blockmap");
return NULL;
tmp = PyObject_GetAttrString(textures, "max_blockid");
if (!tmp)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.max_blockid");
return NULL;
max_blockid = PyInt_AsLong(tmp);
Py_DECREF(tmp);
tmp = PyObject_GetAttrString(textures, "max_data");
if (!tmp)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.max_blockid");
return NULL;
max_data = PyInt_AsLong(tmp);
Py_DECREF(tmp);
/* assemble the property table */
known_blocks = PyObject_GetAttrString(textures, "known_blocks");
if (!known_blocks)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.known_blocks");
return NULL;
transparent_blocks = PyObject_GetAttrString(textures, "transparent_blocks");
if (!transparent_blocks)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.transparent_blocks");
return NULL;
solid_blocks = PyObject_GetAttrString(textures, "solid_blocks");
if (!solid_blocks)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.solid_blocks");
return NULL;
fluid_blocks = PyObject_GetAttrString(textures, "fluid_blocks");
if (!fluid_blocks)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.fluid_blocks");
return NULL;
nospawn_blocks = PyObject_GetAttrString(textures, "nospawn_blocks");
if (!nospawn_blocks)
return PyErr_Format(PyExc_ImportError, "Failed to get textures.nospawn_blocks");
return NULL;
block_properties = calloc(max_blockid, sizeof(unsigned char));
for (i = 0; i < max_blockid; i++) {
@@ -104,7 +104,7 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
Py_DECREF(block);
}
Py_RETURN_NONE;
}
@@ -362,7 +362,7 @@ chunk_render(PyObject *self, PyObject *args) {
PyObject *t = NULL;
if (!PyArg_ParseTuple(args, "OOiiO", &state.self, &state.img, &xoff, &yoff, &state.blockdata_expanded))
return PyErr_Format(PyExc_ValueError, "Failed to ParseTuple");
return NULL;
/* fill in important modules */
state.textures = textures;

View File

@@ -106,13 +106,13 @@ render_mode_find_interface(const char *mode) {
/* check for custom modes */
custom = PyDict_GetItemString(custom_render_modes, mode);
if (custom == NULL)
return NULL;
return PyErr_Format(PyExc_RuntimeError, "Failed to find rendermode interface (custom not found)");
custom = PyDict_GetItemString(custom, "parent");
if (custom == NULL)
return NULL;
return PyErr_Format(PyExc_RuntimeError, "Failed to find rendermode interface (parent not found)");
custom_parent = PyString_AsString(custom);
if (custom_parent == NULL)
return NULL;
return NULL; // PyString_AsString sets an exception
return render_mode_find_interface(custom_parent);
}
@@ -124,11 +124,11 @@ RenderMode *render_mode_create(const char *mode, RenderState *state) {
iface = render_mode_find_interface(mode);
if (iface == NULL)
return PyErr_Format(PyExc_RuntimeError, "Failed to find rendermode interface");
return NULL;
options = render_mode_create_options(mode);
if (options == NULL)
return PyErr_Format(PyExc_RuntimeError, "Failed to create rendermode options");
return NULL;
ret = calloc(1, sizeof(RenderMode));
if (ret == NULL) {
@@ -150,13 +150,13 @@ RenderMode *render_mode_create(const char *mode, RenderState *state) {
Py_DECREF(options);
free(ret->mode);
free(ret);
return PyErr_Format(PyExc_RuntimeError, "Failed to start rendermode interface");
return NULL;
}
Py_DECREF(options);
return ret;
}
void render_mode_destroy(RenderMode *self) {
self->iface->finish(self->mode, self->state);
free(self->mode);