static PyObject *ffi_dlclose(PyObject *self, PyObject *args) { LibObject *lib; void *libhandle; if (!PyArg_ParseTuple(args, "O!", &Lib_Type, &lib)) return NULL; libhandle = lib->l_libhandle; lib->l_libhandle = NULL; if (libhandle == NULL) { PyErr_Format(FFIError, "library '%s' is already closed " "or was not created with ffi.dlopen()", PyText_AS_UTF8(lib->l_libname)); return NULL; } /* Clear the dict to force further accesses to do cdlopen_fetch() again, and fail because the library was closed. */ PyDict_Clear(lib->l_dict); if (cdlopen_close(lib->l_libname, libhandle) < 0) return NULL; Py_INCREF(Py_None); return Py_None; }
void initRegNamespace(PyObject* registersDict) { PyDict_Clear(registersDict); PyObject* x86RegistersDict = xPyDict_New(); PyObject* x86RegistersDictClass = xPyClass_New(nullptr, x86RegistersDict, xPyString_FromString("X86")); xPyDict_SetItemString(registersDict, "X86", x86RegistersDictClass); // Init X86 REG namespace #define REG_SPEC(UPPER_NAME, LOWER_NAME, X86_64_UPPER, X86_64_LOWER, X86_64_PARENT, X86_UPPER, X86_LOWER, X86_PARENT, X86_AVAIL) \ if (X86_AVAIL) \ xPyDict_SetItemString(x86RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_##UPPER_NAME)); // Use REG not available in capstone as normal register #define REG_SPEC_NO_CAPSTONE REG_SPEC #include "triton/x86.spec" PyObject* x8664RegistersDict = xPyDict_New(); PyObject* x8664RegistersDictClass = xPyClass_New(nullptr, x8664RegistersDict, xPyString_FromString("X86_64")); xPyDict_SetItemString(registersDict, "X86_64", x8664RegistersDictClass); // Init X86_64 REG namespace #define REG_SPEC(UPPER_NAME, LOWER_NAME, X86_64_UPPER, X86_64_LOWER, X86_64_PARENT, X86_UPPER, X86_LOWER, X86_PARENT, X86_AVAIL) \ xPyDict_SetItemString(x8664RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_##UPPER_NAME)); // Use REG not available in capstone as normal register #define REG_SPEC_NO_CAPSTONE REG_SPEC #include "triton/x86.spec" }
/* atexit() handler that'll call unload_add_on() for every item in the * dictionary. */ static void beos_cleanup_dyn( void ) { if( beos_dyn_images ) { int idx; int list_size; PyObject *id_list; #ifdef WITH_THREAD PyThread_acquire_lock( beos_dyn_lock, 1 ); #endif id_list = PyDict_Values( beos_dyn_images ); list_size = PyList_Size( id_list ); for( idx = 0; idx < list_size; idx++ ) { PyObject *the_item; the_item = PyList_GetItem( id_list, idx ); beos_nuke_dyn( the_item ); } PyDict_Clear( beos_dyn_images ); #ifdef WITH_THREAD PyThread_free_lock( beos_dyn_lock ); #endif } }
static inline void clean_cli(client_t *client) { write_access_log(client, log_fd, log_path); if(client->req){ free_request(client->req); client->req = NULL; } Py_CLEAR(client->http_status); Py_CLEAR(client->headers); Py_CLEAR(client->response_iter); Py_CLEAR(client->response); #ifdef DEBUG printf("clean_cli environ status_code %d address %p \n", client->status_code, client->environ); #endif if(client->environ){ PyDict_Clear(client->environ); Py_DECREF(client->environ); } if(client->body){ if(client->body_type == BODY_TYPE_TMPFILE){ fclose(client->body); }else{ free_buffer(client->body); } client->body = NULL; } client->header_done = 0; client->response_closed = 0; client->chunked_response = 0; client->content_length_set = 0; client->content_length = 0; client->write_bytes = 0; }
PyObject *SCA_PythonKeyboard::pyattr_get_active_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v); PyDict_Clear(self->m_event_dict); for (int i=SCA_IInputDevice::BEGINKEY; i<=SCA_IInputDevice::ENDKEY; i++) { SCA_InputEvent& input = self->m_keyboard->GetInput((SCA_IInputDevice::SCA_EnumInputs)i); if (input.Find(SCA_InputEvent::ACTIVE)) { int event = 0; if (input.m_queue.size() > 0) { event = input.m_queue[input.m_queue.size() - 1]; } else { event = input.m_status[input.m_status.size() - 1]; } PyObject *key = PyLong_FromLong(i); PyObject *value = PyLong_FromLong(event); PyDict_SetItem(self->m_event_dict, key, value); Py_DECREF(key); Py_DECREF(value); } } Py_INCREF(self->m_event_dict); return self->m_event_dict; }
PyObject * convertToDistArray(Domi::MDVector< Scalar > & mdVector) { PyObject * distArrayProtocol; PyObject * buffer; PyObject * dimData; distArrayProtocol = PyDict_New(); if (!distArrayProtocol) goto fail; if (PyDict_SetItemString(distArrayProtocol, "__version__", Py_BuildValue("s","0.10.0")) == -1) goto fail; buffer = convertToNumPyArray(mdVector.getDataNonConst()); if (!buffer) goto fail; if (PyDict_SetItemString(distArrayProtocol, "buffer", buffer) == -1) goto fail; dimData = convertToDimData(mdVector.getMDMap()); if (!dimData) goto fail; if (PyDict_SetItemString(distArrayProtocol, "dim_data", dimData) == -1) goto fail; Py_DECREF(buffer); Py_DECREF(dimData); return distArrayProtocol; fail: if (distArrayProtocol) PyDict_Clear(distArrayProtocol); Py_XDECREF(distArrayProtocol); Py_XDECREF(buffer); Py_XDECREF(dimData); return NULL; }
SCA_PythonKeyboard::~SCA_PythonKeyboard() { #ifdef WITH_PYTHON PyDict_Clear(m_event_dict); Py_DECREF(m_event_dict); #endif }
SCA_PythonMouse::~SCA_PythonMouse() { #ifdef WITH_PYTHON PyDict_Clear(m_event_dict); Py_DECREF(m_event_dict); #endif }
void dict_base::clear() { if (check_exact(this)) PyDict_Clear(this->ptr()); else this->attr("clear")(); }
void XsltRoot_Fini(void) { Py_DECREF(setup_string); Py_DECREF(validate_string); Py_DECREF(prime_string); Py_DECREF(teardown_string); PyDict_Clear(XsltRoot_Type.tp_dict); }
static void planner_python_env_free (PlannerPythonEnv *env) { g_free (env->filename); PyDict_Clear (env->globals); Py_DECREF (env->globals); g_free (env); }
SCPyDictArg::~SCPyDictArg() { PYLOCK; if (NULL != pPyObject) { PyDict_Clear(pPyObject); } Py_XDECREF(pPyObject); }
static PyObject * pyGetRecords(PyObject *self, PyObject *args) { // retrieve 2 input parameters in char * format char *searchKey, *searchVal; if (!PyArg_ParseTuple(args, "ss", &searchKey, &searchVal)) { return Py_BuildValue("i", 1); // ERROR - PyArg_ParseTuple } // get all recID that matches the searckKey and searchVal int *allId; unsigned recCount; MEsearchId(dbhandle, searchKey, searchVal, &allId, &recCount); if (recCount == 0) { return Py_BuildValue("i", 2); // ERROR - no record found } // build output dict object int rc, i, j; unsigned size; long recid, dict_size; char *allData, *key, *val; PyObject* py_rdict; PyObject* py_adict; PyObject* py_key; PyObject* py_val; py_rdict = PyDict_New(); py_adict = PyDict_New(); // loop through all recIDs for ( i=0; i<recCount; ++i ) { recid = *(allId+i); PyDict_Clear(py_adict); // create kv and add to py_dict (recid: recid[searchKey]) MEgetAllFieldsById(dbhandle, recid, &allData, &size); for (j=0; j<size; j+=2) { key = allData+j*ME_STRING_MAX_LENGTH; val = allData+(j+1)*ME_STRING_MAX_LENGTH; if (debugMode) { printf( "%i: %s %s\n", recid, key, val); } py_key = PyString_FromString(key); py_val = PyString_FromString(val); PyDict_SetItem(py_adict, py_key, py_val); } py_key = PyInt_FromLong(recid); PyDict_SetItem(py_rdict, py_key, PyDict_Copy(py_adict)); free(allData); } free(allId); if (debugMode) { printf("pyGetRecords: records retrieved: %i\n", recCount); } // return 2 parameters: rc, dict return Py_BuildValue("iO", 0, py_rdict); }
/** * Execute the current script * We are now in the thread. */ void PyApi::ExecuteInThread() const { assert(Py_IsInitialized() ); // get the lock so we can change things. PyEval_AcquireLock(); // make sure that the main thread is the active one. const auto mainInterpreterState = _mainThreadState->interp; PyThreadState_Swap(_mainThreadState); // create a new thread. const auto myThreadState = PyThreadState_New(mainInterpreterState); // make sure that the new thread has control // https://docs.python.org/3/c-api/init.html PyThreadState_Swap(myThreadState); // execute it... { const auto main_module = PyImport_AddModule("__main__"); const auto main_dict = PyModule_GetDict(main_module); Py_XINCREF(main_module); const auto local_dic = PyDict_New(); Py_XINCREF(local_dic); // we can now run our script const auto s = _script.c_str(); const auto pyRes = PyRun_String(s, Py_file_input, main_dict, local_dic); CheckForPythonErrors(); PyDict_Clear(local_dic); Py_XDECREF(local_dic); // pending calls must be cleared out Py_XDECREF(main_module); } // swap back to this thread. PyThreadState_Swap(myThreadState); // clear anything left behind. PyThreadState_Clear(myThreadState); PyThreadState_Swap(nullptr); // delete my thread. PyThreadState_Delete(myThreadState); // give control back to main thread PyThreadState_Swap(_mainThreadState); // release the lock one last time. PyEval_ReleaseLock(); }
void pyscript_clear_modules(PyObject *script) { PyScript *self; g_return_if_fail(pyscript_check(script)); self = (PyScript *) script; PyDict_Clear(self->modules); }
static PyObject * lru_cache_cache_clear(lru_cache_object *self, PyObject *unused) { lru_list_elem *list = lru_cache_unlink_list(self); self->hits = self->misses = 0; self->full = 0; PyDict_Clear(self->cache); lru_cache_clear_list(list); Py_RETURN_NONE; }
static PyObject * pickle___setstate__(PyObject *self, PyObject *state) { PyObject *slots=NULL; if (PyTuple_Check(state)) { if (!PyArg_ParseTuple(state, "OO:__setstate__", &state, &slots)) return NULL; } if (state != Py_None) { PyObject **dict; PyObject *d_key, *d_value; Py_ssize_t i; dict = _PyObject_GetDictPtr(self); if (!dict) { PyErr_SetString(PyExc_TypeError, "this object has no instance dictionary"); return NULL; } if (!*dict) { *dict = PyDict_New(); if (!*dict) return NULL; } PyDict_Clear(*dict); i = 0; while (PyDict_Next(state, &i, &d_key, &d_value)) { /* normally the keys for instance attributes are interned. we should try to do that here. */ if (NATIVE_CHECK_EXACT(d_key)) { Py_INCREF(d_key); INTERN_INPLACE(&d_key); Py_DECREF(d_key); } if (PyObject_SetItem(*dict, d_key, d_value) < 0) return NULL; } } if (slots && pickle_setattrs_from_dict(self, slots) < 0) return NULL; Py_INCREF(Py_None); return Py_None; }
/* * fcgi_Request methods */ static PyObject * fcgi_Request_accept(fcgi_Request *self) { int rc; char **e; Py_BEGIN_ALLOW_THREADS rc = FCGX_Accept_r(&self->r); Py_END_ALLOW_THREADS if (rc < 0) { /* * FCGX_Accept_r returns (0 - errno) on error, * so PyErr_SetFromErrno should work just fine */ PyErr_SetFromErrno(PyExc_IOError); return NULL; } /* clear any existing environment */ PyDict_Clear(self->env); if (self->r.envp == NULL) { Py_RETURN_NONE; } /* fill in the environment */ for (e = self->r.envp; *e != NULL; e++) { PyObject *k, *v; char *p = strchr(*e, '='); if (p == NULL) continue; k = PyString_FromStringAndSize(*e, (int)(p-*e)); if (k == NULL) { PyErr_Clear(); continue; } v = PyString_FromString(p + 1); if (v == NULL) { PyErr_Clear(); Py_DECREF(k); continue; } if (PyDict_SetItem(self->env, k, v) != 0) PyErr_Clear(); Py_DECREF(k); Py_DECREF(v); } Py_RETURN_NONE; }
SCA_PythonJoystick::~SCA_PythonJoystick() { // The joystick reference we got in the constructor was a new instance, // so we release it here m_joystick->ReleaseInstance(); #ifdef WITH_PYTHON PyDict_Clear(m_event_dict); Py_DECREF(m_event_dict); #endif }
void * pbs_python_ext_namespace_init( struct python_interpreter_data *interp_data) { static char func_id[] = "pbs_python_namespace_init"; #ifdef PYTHON /* --- BEGIN PYTHON BLOCK --- */ PyObject *namespace_dict = (PyObject *) NULL; namespace_dict = PyDict_New(); /* New Refrence MUST Decref */ if (!namespace_dict) { pbs_python_write_error_to_log(func_id); goto ERROR_EXIT; } /* * setup our namespace, by including all the modules that are needed to * run the python scripts */ if ((PyDict_SetItemString(namespace_dict, "__builtins__", PyEval_GetBuiltins()) == -1) ) { pbs_python_write_error_to_log(func_id); goto ERROR_EXIT; } /* * Now, add our extension object/module to the namespace. */ if ((PyDict_SetItemString(namespace_dict, PBS_PYTHON_V1_MODULE_EXTENSION_NAME, pbs_v1_module_init()) == -1) ) { snprintf(log_buffer, LOG_BUF_SIZE-1, "%s|adding extension object", func_id); log_buffer[LOG_BUF_SIZE-1] = '\0'; pbs_python_write_error_to_log(func_id); goto ERROR_EXIT; } return namespace_dict; ERROR_EXIT: if (namespace_dict) { PyDict_Clear(namespace_dict); Py_CLEAR(namespace_dict); } return namespace_dict; #else /* !PYTHON */ return (void *) NULL; #endif /* --- END PYTHON BLOCK --- */ }
static PyObject *entity_setstate(PyObject *self, PyObject *state) { PyObject *dict, *public_id, *system_id, *unparsed_entities, *children, *temp; Py_ssize_t i, n; if (!PyArg_UnpackTuple(state, NULL, 5, 5, &dict, &public_id, &system_id, &unparsed_entities, &children)) return NULL; if (!convert_arg(0, &PyDict_Type, &dict)) return NULL; if (!convert_arg(3, &PyDict_Type, &unparsed_entities)) return NULL; if (!convert_arg(4, &PyTuple_Type, &children)) return NULL; if (dict) { if (PyType_HasFeature(self->ob_type, Py_TPFLAGS_HEAPTYPE)) { temp = PyObject_GetAttrString(self, "__dict__"); if (temp == NULL) return NULL; if (PyDict_Update(temp, dict) < 0) { Py_DECREF(temp); return NULL; } Py_DECREF(temp); } } temp = Entity_GET_PUBLIC_ID(self); Entity_SET_PUBLIC_ID(self, public_id); Py_INCREF(public_id); Py_DECREF(temp); temp = Entity_GET_SYSTEM_ID(self); Entity_SET_SYSTEM_ID(self, system_id); Py_INCREF(system_id); Py_DECREF(temp); if (unparsed_entities) { temp = Entity_GET_UNPARSED_ENTITIES(self); PyDict_Clear(temp); if (PyDict_Update(temp, unparsed_entities) < 0) return NULL; } if (children) { for (i = 0, n = PyTuple_GET_SIZE(children); i < n; i++) { NodeObject *node = (NodeObject *)PyTuple_GET_ITEM(children, i); if (Container_Append((NodeObject *)self, node) < 0) return NULL; } } Py_RETURN_NONE; }
void initX86PrefixesNamespace(void) { if (!triton::bindings::python::initialized) return; PyDict_Clear(triton::bindings::python::prefixesDict); PyDict_SetItemString(triton::bindings::python::prefixesDict, "INVALID", PyLong_FromUint(triton::arch::x86::ID_PREFIX_INVALID)); PyDict_SetItemString(triton::bindings::python::prefixesDict, "LOCK", PyLong_FromUint(triton::arch::x86::ID_PREFIX_LOCK)); PyDict_SetItemString(triton::bindings::python::prefixesDict, "REP", PyLong_FromUint(triton::arch::x86::ID_PREFIX_REP)); PyDict_SetItemString(triton::bindings::python::prefixesDict, "REPE", PyLong_FromUint(triton::arch::x86::ID_PREFIX_REPE)); PyDict_SetItemString(triton::bindings::python::prefixesDict, "REPNE", PyLong_FromUint(triton::arch::x86::ID_PREFIX_REPNE)); }
SCA_PythonController::~SCA_PythonController() { #ifdef WITH_PYTHON Py_XDECREF(m_bytecode); Py_XDECREF(m_function); if (m_pythondictionary) { // break any circular references in the dictionary PyDict_Clear(m_pythondictionary); Py_DECREF(m_pythondictionary); } #endif }
static PyObject *t_lm_dict_clear(t_lm *self, PyObject *args) { PyDict_Clear(self->dict); if (self->aliases != Nil) { Py_DECREF(self->aliases); self->aliases = Nil; Py_INCREF(Nil); } t_lm___setFirstKey(self, Py_None, NULL); t_lm___setLastKey(self, Py_None, NULL); Py_RETURN_NONE; }
void SCA_PythonController::SetNamespace(PyObject* pythondictionary) { if (m_pythondictionary) { PyDict_Clear(m_pythondictionary); Py_DECREF(m_pythondictionary); } m_pythondictionary = PyDict_Copy(pythondictionary); /* new reference */ /* Without __file__ set the sys.argv[0] is used for the filename * which ends up with lines from the blender binary being printed in the console */ PyDict_SetItemString(m_pythondictionary, "__file__", PyUnicode_FromString(m_scriptName.Ptr())); }
static PyObject * GlobalHotkey_unbind_all (GlobalHotkey *self) { PyObject *key, *value; Py_ssize_t pos = 0; char *str_key; while (PyDict_Next (self->binded, &pos, &key, &value)) { str_key = PyString_AsString (key); keybinder_unbind (str_key, caller); } PyDict_Clear (self->binded); return Py_BuildValue ("i", 1); }
static PyObject * LRU_clear(LRU *self) { Node *c = self->first; while (c) { Node* n = c; c = c->next; lru_remove_node(self, n); } PyDict_Clear(self->dict); self->hits = 0; self->misses = 0; Py_RETURN_NONE; }
PyObject* SCA_PythonKeyboard::pyattr_get_active_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v); PyDict_Clear(self->m_event_dict); for (int i=SCA_IInputDevice::KX_BEGINKEY; i<=SCA_IInputDevice::KX_ENDKEY; i++) { const SCA_InputEvent & inevent = self->m_keyboard->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i); if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS) PyDict_SetItem(self->m_event_dict, PyLong_FromSsize_t(i), PyLong_FromSsize_t(inevent.m_status)); } Py_INCREF(self->m_event_dict); return self->m_event_dict; }
/* Update function, it gets rid of pydrivers global dictionary, forcing * BPY_driver_exec to recreate it. This function is used to force * reloading the Blender text module "pydrivers.py", if available, so * updates in it reach pydriver evaluation. */ void BPY_driver_reset(void) { PyGILState_STATE gilstate; int use_gil= 1; // (PyThreadState_Get()==NULL); if(use_gil) gilstate = PyGILState_Ensure(); if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */ PyDict_Clear(bpy_pydriver_Dict); Py_DECREF(bpy_pydriver_Dict); bpy_pydriver_Dict = NULL; } if(use_gil) PyGILState_Release(gilstate); return; }
static PyObject * pickle___setstate__(PyObject *self, PyObject *state) { PyObject *slots=NULL; if (PyTuple_Check(state)) { if (! PyArg_ParseTuple(state, "OO", &state, &slots)) return NULL; } if (state != Py_None) { PyObject **dict; dict = _PyObject_GetDictPtr(self); if (dict) { if (*dict == NULL) { *dict = PyDict_New(); if (*dict == NULL) return NULL; } } if (*dict != NULL) { PyDict_Clear(*dict); if (PyDict_Update(*dict, state) < 0) return NULL; } else if (pickle_setattrs_from_dict(self, state) < 0) return NULL; } if (slots != NULL && pickle_setattrs_from_dict(self, slots) < 0) return NULL; Py_INCREF(Py_None); return Py_None; }