From bfb92de7b779debf4420f39b16dd2e9532e99a40 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Sat, 11 Jun 2011 00:01:12 -0400 Subject: [PATCH] provided options are now checked against the available options --- rendernode.py | 2 ++ src/iterate.c | 7 +++---- src/rendermodes.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/rendernode.py b/rendernode.py index f2b9bfb..0d1836d 100644 --- a/rendernode.py +++ b/rendernode.py @@ -148,7 +148,9 @@ class RenderNode(object): pool = FakePool() pool_initializer(self) else: + pool_initializer(self) pool = multiprocessing.Pool(processes=procs,initializer=pool_initializer,initargs=(self,)) + #warm up the pool so it reports all the worker id's if logging.getLogger().level >= 10: pool.map(bool,xrange(multiprocessing.cpu_count()),1) diff --git a/src/iterate.c b/src/iterate.c index 92b176b..5d82aaa 100644 --- a/src/iterate.c +++ b/src/iterate.c @@ -26,11 +26,10 @@ static PyObject *transparent_blocks = NULL; PyObject *init_chunk_render(PyObject *self, PyObject *args) { - /* this function only needs to be called once, anything more is an - * error... */ + /* this function only needs to be called once, anything more should be + * ignored */ if (blockmap) { - PyErr_SetString(PyExc_RuntimeError, "init_chunk_render should only be called once per process."); - return NULL; + Py_RETURN_NONE; } textures = PyImport_ImportModule("textures"); diff --git a/src/rendermodes.c b/src/rendermodes.c index 9cac54c..cc19561 100644 --- a/src/rendermodes.c +++ b/src/rendermodes.c @@ -301,14 +301,56 @@ PyObject *get_render_mode_options(PyObject *self, PyObject *args) return options; } +/* helper to decide if a rendermode supports a given option */ +static inline int +render_mode_supports_option(RenderModeInterface *iface, const char *name) { + unsigned int i; + + if (iface->options != NULL) { + for (i = 0; iface->options[i].name != NULL; i++) { + if (strcmp(iface->options[i].name, name) == 0) { + return 1; + } + } + } + + if (iface->parent != NULL) + return render_mode_supports_option(iface->parent, name); + + return 0; +} + /* python rendermode options bindings */ PyObject *set_render_mode_options(PyObject *self, PyObject *args) { const char *rendermode; - PyObject *opts; + PyObject *opts, *key, *value; + Py_ssize_t pos = 0; + RenderModeInterface *iface = NULL; + unsigned int i; if (!PyArg_ParseTuple(args, "sO!", &rendermode, &PyDict_Type, &opts)) return NULL; - /* check options here */ + for (i = 0; render_modes[i] != NULL; i++) { + if (strcmp(render_modes[i]->name, rendermode) == 0) { + iface = render_modes[i]; + break; + } + } + + if (iface == NULL) { + return PyErr_Format(PyExc_ValueError, "'%s' is not a valid rendermode name", rendermode); + } + + /* check options to make sure they're available */ + while (PyDict_Next(opts, &pos, &key, &value)) { + const char *name = PyString_AsString(key); + if (name == NULL) + return NULL; + + if (!render_mode_supports_option(iface, name)) { + return PyErr_Format(PyExc_ValueError, "'%s' is not a valid option for rendermode '%s'", name, rendermode); + } + } if (render_mode_options == NULL) render_mode_options = PyDict_New();