/* * Ask the model */ static int ask_model(tdi_render_t *self, tdi_node_t *node, int *done) { PyObject *tmp, *result; int user_control; if (node->kind == DONE_NODE) { *done = 1; return 0; } #define AS_BOOL(op) ((op) ? PyObject_IsTrue(op) : -1) nested_callback: user_control = 0; if (node->kind == CB_NODE) { tmp = node->callback; Py_INCREF(tmp); Py_CLEAR(node->callback); node->kind = DONE_NODE; if (tmp == Py_None) { Py_DECREF(tmp); Py_CLEAR(node->overlays); *done = 0; return 0; } result = ask_model__callback(tmp, node); Py_DECREF(tmp); *done = AS_BOOL(result); Py_XDECREF(result); if (*done == -1) return -1; user_control = 1; } else if (self->done) { *done = 1; } else { tmp = tdi_adapter_method( (tdi_adapter_t *)self->model, tdi_g_rendermethod, node->name, node->modelscope, !!(node->flags & NODE_NOAUTO) ); if (!tmp) return -1; if (tmp == Py_None) { Py_DECREF(tmp); *done = 0; } else { result = PyObject_CallFunctionObjArgs(tmp, (PyObject *)node, NULL); Py_DECREF(tmp); *done = AS_BOOL(result); Py_XDECREF(result); if (*done == -1) return -1; user_control = 1; } } #undef AS_BOOL if (node->flags & NODE_REMOVED) { return 1; } else if (node->flags & NODE_REPEATED) { if (!(tmp = repeat(node))) return -1; if (tdi_render_stack_push(&self->stack, tmp, NULL, self->done) == -1) return -1; self->done = 0; return 1; } else if (user_control && node->kind == CB_NODE) { goto nested_callback; } return 0; }
BOOL mem_is_in_use(memory_reservation_t * res) { return AS_BOOL(res->type == MEMORY_RESERVATION_FREE); }