static CallbackArgType _py_map_typehint(PyObject *annotations, PyObject *key) { CallbackArgType type = CALLBACK_ARG_TYPE_UNDEFINED; assert(annotations != NULL); assert(PyMapping_Check(annotations)); assert(key != NULL); assert(PyUnicode_Check(key)); if(PyMapping_HasKey(annotations, key)) { PyObject *typehint = PyObject_GetItem(annotations, key); if(PyType_Check(typehint)) { if((PyTypeObject *)typehint == &PyLong_Type) { type = CALLBACK_ARG_TYPE_INTEGER; } else if((PyTypeObject *)typehint == &PyUnicode_Type) { type = CALLBACK_ARG_TYPE_STRING; } } else { DEBUG("python", "Type of found type-hint is invalid."); } Py_XDECREF(typehint); } return type; }
static long _adbobj_have_possible_break(AdbObject *self, PyFrameObject *frame) { PyObject *filename; PyObject *tuple; int haveFileBP; #ifdef DEBUG_PRINT fprintf(stderr, "_adbobj_have_possible_break...\n"); #endif if (PyDict_Size(__adb_breakpointList) < 1) { // no breakpoints, no possible break return 0; } if (PyMapping_HasKey(__adb_canonicCache, frame->f_code->co_filename)==0) { // filename has not been mapped, so force a call to effective return 1; } filename = PyDict_GetItem(__adb_canonicCache, frame->f_code->co_filename); if (PyMapping_HasKey(__adb_breakpointFileList, filename)==1) { // we have breakpoints for this file, do we have one for this line // or a file global breakpoint? tuple = Py_BuildValue("(Oi)", filename, frame->f_lineno); haveFileBP = PyDict_GetItem(__adb_breakpointList, tuple) != NULL; Py_DECREF(tuple); if (haveFileBP) { return 1; } // check for file global breakpoints tuple = Py_BuildValue("(Oi)", filename, 0); haveFileBP = PyDict_GetItem(__adb_breakpointList, tuple) != NULL; Py_DECREF(tuple); if (haveFileBP) { return 1; } } // check for global breakpoints return PyMapping_HasKeyString(__adb_breakpointFileList, ""); }
// Determine if a gateway has been registered. int PyCom_IsGatewayRegistered(REFIID iid) { PyObject *keyObject = PyWinObject_FromIID(iid); if (!keyObject) { return 0; } int rc = PyMapping_HasKey(g_obPyCom_MapServerIIDToGateway, keyObject); Py_DECREF(keyObject); return rc; }
JSBool resolve(JSContext* jscx, JSObject* jsobj, jsval key) { Context* pycx = NULL; PyObject* pykey = NULL; jsid pid; JSBool ret = JS_FALSE; pycx = (Context*) JS_GetContextPrivate(jscx); if(pycx == NULL) { JS_ReportError(jscx, "Failed to get Python context."); goto done; } // Bail if there's no registered global handler. if(pycx->global == NULL) { ret = JS_TRUE; goto done; } pykey = js2py(pycx, key); if(pykey == NULL) goto done; if(Context_has_access(pycx, jscx, pycx->global, pykey) <= 0) goto done; if(!PyMapping_HasKey(pycx->global, pykey)) { ret = JS_TRUE; goto done; } if(!JS_ValueToId(jscx, key, &pid)) { JS_ReportError(jscx, "Failed to convert property id."); goto done; } if(!js_DefineProperty(jscx, pycx->root, pid, JSVAL_VOID, NULL, NULL, JSPROP_SHARED, NULL)) { JS_ReportError(jscx, "Failed to define property."); goto done; } ret = JS_TRUE; done: Py_XDECREF(pykey); return ret; }
static PyObject * PyShm_semaphore( PyObject *self, PyObject *args) { int semid; PyShmSemObj *o; PyObject *keyo; semctl_arg arg; if (!PyArg_ParseTuple(args, "i", &semid)) return NULL; keyo = PyInt_FromLong(semid); /* get the object from the dictionary */ if (PyMapping_HasKey(sem_dict, keyo)) { o = (PyShmSemObj *)PyDict_GetItem(sem_dict, keyo); Py_INCREF(o); } else { /* not found, create it */ if ((o = PyObject_NEW(PyShmSemObj, &PyShmSemaphore_Type)) == NULL) return NULL; o->semid = semid; o->opflag = 0; /* sem_dict[semid] = o */ if (PyDict_SetItem(sem_dict, keyo, (PyObject *)o) == -1) { Py_DECREF(o); PyErr_SetString(PyShm_Error, "can't initialize semaphore object"); return NULL; } Py_DECREF(o); /* the owned reference in sem_dict doesn't count! */ } /* set up the status data */ arg.buf = &(o->ds); if (semctl(o->semid, 0, IPC_STAT, arg) == -1) { Py_DECREF(o); PyErr_SetString(PyShm_Error, "can't access semaphore"); return NULL; } return (PyObject *)o; }
static PyObject * PyShm_memory( PyObject *self, PyObject *args) { int shmid; PyShmObj *o; PyObject *keyo; if (!PyArg_ParseTuple(args, "i", &shmid)) return NULL; keyo = PyInt_FromLong(shmid); /* get the object from the dictionary */ if (PyMapping_HasKey(shm_dict, keyo)) { o = (PyShmObj *)PyDict_GetItem(shm_dict, keyo); Py_INCREF(o); } else { /* not found, create it */ if ((o = PyObject_NEW(PyShmObj, &PyShmMemory_Type)) == NULL) return NULL; o->shmid = shmid; o->addr = NULL; o->mode = 0; /* shm_dict[shmid] = o */ if (PyDict_SetItem(shm_dict, keyo, (PyObject *)o) == -1) { Py_DECREF(o); PyErr_SetString(PyShm_Error, "can't initialize shared memory object"); return NULL; } Py_DECREF(o); /* the owned reference in shm_dict doesn't count! */ } /* set up the status data */ if (shmctl(o->shmid, IPC_STAT, &(o->ds)) == -1) { Py_DECREF(o); PyErr_SetString(PyShm_Error, "can't access shared memory segment"); return NULL; } return (PyObject *)o; }