dbus_bool_t dbus_py_init_abstract(void) { _dbus_py_variant_levels = PyDict_New(); if (!_dbus_py_variant_levels) return 0; dbus_py__dbus_object_path__const = PyString_InternFromString("__dbus_object_path__"); if (!dbus_py__dbus_object_path__const) return 0; dbus_py_variant_level_const = PyString_InternFromString("variant_level"); if (!dbus_py_variant_level_const) return 0; dbus_py_signature_const = PyString_InternFromString("signature"); if (!dbus_py_signature_const) return 0; DBusPyIntBase_Type.tp_base = &PyInt_Type; if (PyType_Ready(&DBusPyIntBase_Type) < 0) return 0; /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as desired */ DBusPyIntBase_Type.tp_print = NULL; DBusPyFloatBase_Type.tp_base = &PyFloat_Type; if (PyType_Ready(&DBusPyFloatBase_Type) < 0) return 0; DBusPyFloatBase_Type.tp_print = NULL; DBusPyLongBase_Type.tp_base = &PyLong_Type; if (PyType_Ready(&DBusPyLongBase_Type) < 0) return 0; DBusPyLongBase_Type.tp_print = NULL; DBusPyStrBase_Type.tp_base = &PyString_Type; if (PyType_Ready(&DBusPyStrBase_Type) < 0) return 0; DBusPyStrBase_Type.tp_print = NULL; return 1; }
PyMODINIT_FUNC init_template(void) { // Set interned strings. Skip_Filter_PyString = PyString_InternFromString("skip_filter"); filter_function_name = PyString_InternFromString("_filter_function"); // Get SanitizedPlaceholder from the baked module. PyObject *baked_module = PyImport_ImportModule("spitfire.runtime.baked"); if (baked_module == NULL) return; baked_SanitizedPlaceholder = (struct _typeobject *) PyObject_GetAttrString(baked_module, "SanitizedPlaceholder"); Py_DECREF(baked_module); if (baked_SanitizedPlaceholder == NULL) return; // Setup module and class. PyObject *m; BaseSpitfireTemplateType.tp_new = PyType_GenericNew; if (PyType_Ready(&BaseSpitfireTemplateType) < 0) return; m = Py_InitModule3("_template", module_methods, "Template Module"); if (m == NULL) return; Py_INCREF(&BaseSpitfireTemplateType); PyModule_AddObject(m, "BaseSpitfireTemplate", (PyObject *)&BaseSpitfireTemplateType); }
int _SKCurve_InitCurveObject(void) { set_nodes_and_segments_string = PyString_InternFromString("_set_nodes_and_segments"); undo_close_string = PyString_InternFromString("_undo_close"); return 1; }
static PyObject * bool_repr(PyBoolObject *self) { PyObject *s; if (self->ob_ival) s = true_str ? true_str : (true_str = PyString_InternFromString("True")); else s = false_str ? false_str : (false_str = PyString_InternFromString("False")); Py_XINCREF(s); return s; }
PyObject * PyObject_Unicode(PyObject *v) { PyObject *res; PyObject *func; PyObject *str; static PyObject *unicodestr; if (v == NULL) { res = PyString_FromString("<NULL>"); if (res == NULL) return NULL; str = PyUnicode_FromEncodedObject(res, NULL, "strict"); Py_DECREF(res); return str; } else if (PyUnicode_CheckExact(v)) { Py_INCREF(v); return v; } /* XXX As soon as we have a tp_unicode slot, we should check this before trying the __unicode__ method. */ if (unicodestr == NULL) { unicodestr= PyString_InternFromString("__unicode__"); if (unicodestr == NULL) return NULL; } func = PyObject_GetAttr(v, unicodestr); if (func != NULL) { res = PyEval_CallObject(func, (PyObject *)NULL); Py_DECREF(func); } else { PyErr_Clear(); if (PyUnicode_Check(v)) { /* For a Unicode subtype that's didn't overwrite __unicode__, return a true Unicode object with the same data. */ return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v), PyUnicode_GET_SIZE(v)); } if (PyString_CheckExact(v)) { Py_INCREF(v); res = v; } else { if (v->ob_type->tp_str != NULL) res = (*v->ob_type->tp_str)(v); else res = PyObject_Repr(v); } } if (res == NULL) return NULL; if (!PyUnicode_Check(res)) { str = PyUnicode_FromEncodedObject(res, NULL, "strict"); Py_DECREF(res); res = str; } return res; }
static PyObject* get_inprogress_dict(void) { static PyObject *key; PyObject *tstate_dict, *inprogress; if (key == NULL) { key = PyString_InternFromString("cmp_state"); if (key == NULL) return NULL; } tstate_dict = PyThreadState_GetDict(); if (tstate_dict == NULL) { PyErr_BadInternalCall(); return NULL; } inprogress = PyDict_GetItem(tstate_dict, key); if (inprogress == NULL) { inprogress = PyDict_New(); if (inprogress == NULL) return NULL; if (PyDict_SetItem(tstate_dict, key, inprogress) == -1) { Py_DECREF(inprogress); return NULL; } Py_DECREF(inprogress); } return inprogress; }
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else /* Python 3+ has unicode identifiers */ if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; ++t; } return 0; }
static void propertyDocCopy(BoxedProperty* prop, Box* fget) { assert(prop); assert(fget); Box* get_doc; static BoxedString* doc_str = static_cast<BoxedString*>(PyString_InternFromString("__doc__")); try { get_doc = getattrInternal(fget, doc_str, NULL); } catch (ExcInfo e) { if (!e.matches(Exception)) { throw e; } get_doc = NULL; } if (get_doc) { if (prop->cls == property_cls) { prop->prop_doc = get_doc; } else { /* If this is a property subclass, put __doc__ in dict of the subclass instance instead, otherwise it gets shadowed by __doc__ in the class's dict. */ setattr(prop, doc_str, get_doc); } prop->getter_doc = true; } }
static PyObject * try_complex_special_method(PyObject *op) { PyObject *f; static PyObject *complexstr; if (complexstr == NULL) { complexstr = PyString_InternFromString("__complex__"); if (complexstr == NULL) return NULL; } if (PyInstance_Check(op)) { f = PyObject_GetAttr(op, complexstr); if (f == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) PyErr_Clear(); else return NULL; } } else { f = _PyObject_LookupSpecial(op, "__complex__", &complexstr); if (f == NULL && PyErr_Occurred()) return NULL; } if (f != NULL) { PyObject *res = PyObject_CallFunctionObjArgs(f, NULL); Py_DECREF(f); return res; } return NULL; }
int _PyFrame_Init() { builtin_object = PyString_InternFromString("__builtins__"); if (builtin_object == NULL) return 0; return 1; }
static PyObject *Proxy_getattro( ProxyObject *self, PyObject *name) { PyObject *object = NULL; PyObject *result = NULL; static PyObject *getattr_str = NULL; object = PyObject_GenericGetAttr((PyObject *)self, name); if (object) return object; PyErr_Clear(); if (!getattr_str) { #if PY_MAJOR_VERSION >= 3 getattr_str = PyUnicode_InternFromString("__getattr__"); #else getattr_str = PyString_InternFromString("__getattr__"); #endif } object = PyObject_GenericGetAttr((PyObject *)self, getattr_str); if (!object) return NULL; result = PyObject_CallFunctionObjArgs(object, name, NULL); Py_DECREF(object); return result; }
PyMODINIT_FUNC _PyWarnings_Init(void) { PyObject *m, *default_action; m = Py_InitModule3(MODULE_NAME, warnings_functions, warnings__doc__); if (m == NULL) return; _filters = init_filters(); if (_filters == NULL) return; Py_INCREF(_filters); if (PyModule_AddObject(m, "filters", _filters) < 0) return; _once_registry = PyDict_New(); if (_once_registry == NULL) return; Py_INCREF(_once_registry); if (PyModule_AddObject(m, "once_registry", _once_registry) < 0) return; default_action = PyString_InternFromString("default"); if (default_action == NULL) return; if (PyModule_AddObject(m, DEFAULT_ACTION_NAME, default_action) < 0) return; }
long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) { PyObject *mod, *func, *result; long retval; static PyObject *context; if (context == NULL) context = PyString_InternFromString("_ctypes.DllGetClassObject"); mod = PyImport_ImportModuleNoBlock("ctypes"); if (!mod) { PyErr_WriteUnraisable(context ? context : Py_None); /* There has been a warning before about this already */ return E_FAIL; } func = PyObject_GetAttrString(mod, "DllGetClassObject"); Py_DECREF(mod); if (!func) { PyErr_WriteUnraisable(context ? context : Py_None); return E_FAIL; } { PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid); PyObject *py_riid = PyLong_FromVoidPtr((void *)riid); PyObject *py_ppv = PyLong_FromVoidPtr(ppv); if (!py_rclsid || !py_riid || !py_ppv) { Py_XDECREF(py_rclsid); Py_XDECREF(py_riid); Py_XDECREF(py_ppv); Py_DECREF(func); PyErr_WriteUnraisable(context ? context : Py_None); return E_FAIL; } result = PyObject_CallFunctionObjArgs(func, py_rclsid, py_riid, py_ppv, NULL); Py_DECREF(py_rclsid); Py_DECREF(py_riid); Py_DECREF(py_ppv); } Py_DECREF(func); if (!result) { PyErr_WriteUnraisable(context ? context : Py_None); return E_FAIL; } retval = PyInt_AsLong(result); if (PyErr_Occurred()) { PyErr_WriteUnraisable(context ? context : Py_None); retval = E_FAIL; } Py_DECREF(result); return retval; }
static PyObject * create_filter(PyObject *category, const char *action) { static PyObject *ignore_str = NULL; static PyObject *error_str = NULL; static PyObject *default_str = NULL; PyObject *action_obj = NULL; PyObject *lineno, *result; if (!strcmp(action, "ignore")) { if (ignore_str == NULL) { ignore_str = PyString_InternFromString("ignore"); if (ignore_str == NULL) return NULL; } action_obj = ignore_str; } else if (!strcmp(action, "error")) { if (error_str == NULL) { error_str = PyString_InternFromString("error"); if (error_str == NULL) return NULL; } action_obj = error_str; } else if (!strcmp(action, "default")) { if (default_str == NULL) { default_str = PyString_InternFromString("default"); if (default_str == NULL) return NULL; } action_obj = default_str; } else { Py_FatalError("unknown action"); } /* This assumes the line number is zero for now. */ lineno = PyInt_FromLong(0); if (lineno == NULL) return NULL; result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno); Py_DECREF(lineno); return result; }
static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) { while (t->p) { *t->p = PyString_InternFromString(t->s); if (!*t->p) return -1; ++t; } return 0; }
static PyObject* GetClassName(PyObject* obj) { CapsuleContext* context = GetContext(obj); if (!context) { return NULL; } else { return PyString_InternFromString(context->className); } }
//pycodeobject 对象和 global名字空间传进来 PyObject * PyFunction_New(PyObject *code, PyObject *globals) { PyFunctionObject *op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type); static PyObject *__name__ = 0; if (op != NULL) { PyObject *doc; PyObject *consts; PyObject *module; op->func_weakreflist = NULL; Py_INCREF(code); op->func_code = code;//PyCodeObject 设置上去 Py_INCREF(globals); op->func_globals = globals; op->func_name = ((PyCodeObject *)code)->co_name; Py_INCREF(op->func_name); //默认参数 op->func_defaults = NULL; /* No default arguments */ //闭包数据 op->func_closure = NULL; consts = ((PyCodeObject *)code)->co_consts; if (PyTuple_Size(consts) >= 1) { //第0项一定是doc了.... doc = PyTuple_GetItem(consts, 0); if (!PyString_Check(doc) && !PyUnicode_Check(doc)) doc = Py_None; } else doc = Py_None; Py_INCREF(doc); op->func_doc = doc; op->func_dict = NULL; op->func_module = NULL; /* __module__: If module name is in globals, use it. Otherwise, use None. */ if (!__name__) { __name__ = PyString_InternFromString("__name__"); if (!__name__) { Py_DECREF(op); return NULL; } } module = PyDict_GetItem(globals, __name__); if (module) { Py_INCREF(module); op->func_module = module; } } else return NULL; _PyObject_GC_TRACK(op); return (PyObject *)op; }
bool iterwrapperHasnextUnboxed(Box* s) { RELEASE_ASSERT(s->cls == iterwrapper_cls, ""); BoxedIterWrapper* self = static_cast<BoxedIterWrapper*>(s); static BoxedString* next_str = static_cast<BoxedString*>(PyString_InternFromString("next")); Box* next; try { next = callattr(self->iter, next_str, CallattrFlags({.cls_only = true, .null_on_nonexistent = false }), ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL); } catch (ExcInfo e) {
void initpax(void) { int i; PyObject * d, *m, *v; m = Py_InitModule("pax", pax_methods); d = PyModule_GetDict(m); #define ADD_INT(name) add_int(d, name, #name) ADD_INT(TCL_WINDOW_EVENTS); ADD_INT(TCL_FILE_EVENTS); ADD_INT(TCL_TIMER_EVENTS); ADD_INT(TCL_IDLE_EVENTS); ADD_INT(TCL_ALL_EVENTS); ADD_INT(TCL_DONT_WAIT); ADD_INT(TK_RELIEF_RAISED); ADD_INT(TK_RELIEF_SUNKEN); ADD_INT(TK_RELIEF_GROOVE); ADD_INT(TK_RELIEF_RIDGE); ADD_INT(TK_RELIEF_FLAT); ADD_INT(TK_3D_FLAT_GC); ADD_INT(TK_3D_LIGHT_GC); ADD_INT(TK_3D_DARK_GC); add_string(d, TK_VERSION, "TK_VERSION"); add_string(d, TCL_VERSION, "TCL_VERSION"); for (i = 0; i < NUM_METHOD_NAMES; i++) { /* Python 1.5! */ PyObject * string = PyString_InternFromString(method_names[i]); if (!string) { Py_FatalError("pax: Cannot create string objects"); } method_names_obj[i] = string; } object_registry = PyDict_New(); PyDict_SetItemString(d, "object_registry", object_registry); v = PyCObject_FromVoidPtr(&pax_functions, NULL); PyDict_SetItemString(d, "Pax_Functions", v); #define ADD_TYPE(type) PyDict_SetItemString(d, #type, (PyObject*)(&type)) ADD_TYPE(TkWinType); ADD_TYPE(PaxPixmapType); ADD_TYPE(PaxImageType); ADD_TYPE(PaxRegionType); ADD_TYPE(PaxCMapType); ADD_TYPE(PaxFontType); ADD_TYPE(PaxGCType); ADD_TYPE(PaxBorderType); }
static PyObject* function_get_name(PyObject* op, void*) { function* f = downcast<function>(op); if (f->name().is_none()) #if PY_VERSION_HEX >= 0x03000000 return PyUnicode_InternFromString("<unnamed Boost.Python function>"); #else return PyString_InternFromString("<unnamed Boost.Python function>"); #endif else return python::incref(f->name().ptr());
/* Module */ PyObject * init_fibers(void) { PyObject *fibers; /* Main module */ #if PY_MAJOR_VERSION >= 3 fibers = PyModule_Create(&fibers_module); #else fibers = Py_InitModule("fibers._cfibers", fibers_methods); #endif /* keys for per-thread dictionary */ #if PY_MAJOR_VERSION >= 3 main_fiber_key = PyUnicode_InternFromString("__fibers_main"); current_fiber_key = PyUnicode_InternFromString("__fibers_current"); #else main_fiber_key = PyString_InternFromString("__fibers_main"); current_fiber_key = PyString_InternFromString("__fibers_current"); #endif if ((current_fiber_key == NULL) || (main_fiber_key == NULL)) { goto fail; } /* Exceptions */ PyExc_FiberError = PyErr_NewException("fibers._cfibers.error", NULL, NULL); MyPyModule_AddType(fibers, "error", (PyTypeObject *)PyExc_FiberError); /* Types */ MyPyModule_AddType(fibers, "Fiber", &FiberType); return fibers; fail: #if PY_MAJOR_VERSION >= 3 Py_DECREF(fibers); #endif return NULL; }
static PyObject * __Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op) { if (op->func_name == NULL) { #if PY_MAJOR_VERSION >= 3 op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name); #else op->func_name = PyString_InternFromString(op->func.m_ml->ml_name); #endif } Py_INCREF(op->func_name); return op->func_name; }
/** * Checks that an object can be a module name. * * If the name is empty or __builtin__, it returns NULL. */ PyObject* ModuleAsPyString(PyObject* object) { if(object != NULL && PyString_Check(object) && PyString_Size(object) != 0) { PyObject* builtin_str = PyString_InternFromString("__builtin__"); int is_builtin = _PyString_Eq(object, builtin_str); Py_DECREF(builtin_str); if (is_builtin) { return NULL; } //Py_INCREF(object); return object; } return NULL; }
void initstatesaver(void) { PyObject* m; m = Py_InitModule("statesaver", StateSaverMethods); if (m == NULL) return; keytype.ob_type = &PyType_Type; str_inst_build = PyString_InternFromString("inst_build"); m = PyImport_ImportModule("types"); if (!m) return; GeneratorType = (PyTypeObject*) PyObject_GetAttrString(m, "GeneratorType"); if (!GeneratorType) return; }
BoxedLong* _longNew(Box* val, Box* _base) { BoxedLong* rtn = new BoxedLong(); if (_base) { if (!isSubclass(_base->cls, int_cls)) raiseExcHelper(TypeError, "an integer is required"); int base = static_cast<BoxedInt*>(_base)->n; if (!isSubclass(val->cls, str_cls)) raiseExcHelper(TypeError, "long() can't convert non-string with explicit base"); BoxedString* s = static_cast<BoxedString*>(val); rtn = (BoxedLong*)PyLong_FromString(s->data(), NULL, base); checkAndThrowCAPIException(); } else { if (isSubclass(val->cls, long_cls)) { BoxedLong* l = static_cast<BoxedLong*>(val); if (val->cls == long_cls) return l; BoxedLong* rtn = new BoxedLong(); mpz_init_set(rtn->n, l->n); return rtn; } else if (isSubclass(val->cls, int_cls)) { mpz_init_set_si(rtn->n, static_cast<BoxedInt*>(val)->n); } else if (val->cls == str_cls) { llvm::StringRef s = static_cast<BoxedString*>(val)->s(); assert(s.data()[s.size()] == '\0'); int r = mpz_init_set_str(rtn->n, s.data(), 10); RELEASE_ASSERT(r == 0, ""); } else if (val->cls == float_cls) { mpz_init_set_si(rtn->n, static_cast<BoxedFloat*>(val)->d); } else { static BoxedString* long_str = static_cast<BoxedString*>(PyString_InternFromString("__long__")); Box* r = callattr(val, long_str, CallattrFlags({.cls_only = true, .null_on_nonexistent = true }), ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL); if (!r) { fprintf(stderr, "TypeError: long() argument must be a string or a number, not '%s'\n", getTypeName(val)); raiseExcHelper(TypeError, ""); } if (isSubclass(r->cls, int_cls)) { mpz_init_set_si(rtn->n, static_cast<BoxedInt*>(r)->n); } else if (!isSubclass(r->cls, long_cls)) { raiseExcHelper(TypeError, "__long__ returned non-long (type %s)", r->cls->tp_name); } else { return static_cast<BoxedLong*>(r); } } }
PyObject * PyObject_GetAttrString(PyObject *v, char *name) { PyObject *w, *res; if (v->ob_type->tp_getattr != NULL) return (*v->ob_type->tp_getattr)(v, name); w = PyString_InternFromString(name); if (w == NULL) return NULL; res = PyObject_GetAttr(v, w); Py_XDECREF(w); return res; }
FunctionParameter::FunctionParameter(const std::string& fmt, bool keyword_only) : optional(false) , allow_none(false) , keyword_only(keyword_only) , size(0) , default_scalar(0) { auto space = fmt.find(' '); if (space == std::string::npos) { throw std::runtime_error("FunctionParameter(): missing type: " + fmt); } auto type_str = fmt.substr(0, space); auto question = type_str.find('?'); if (question != std::string::npos) { allow_none = true; type_str = type_str.substr(0, question); } // Parse and remove brackets from type_str auto bracket = type_str.find('['); if (bracket != std::string::npos) { auto size_str = type_str.substr(bracket + 1, type_str.length() - bracket - 2); size = atoi(size_str.c_str()); type_str = type_str.substr(0, bracket); } auto name_str = fmt.substr(space + 1); auto it = type_map.find(type_str); if (it == type_map.end()) { throw std::runtime_error("FunctionParameter(): invalid type string: " + type_str); } type_ = it->second; auto eq = name_str.find('='); if (eq != std::string::npos) { name = name_str.substr(0, eq); optional = true; set_default_str(name_str.substr(eq + 1)); } else { name = name_str; } #if PY_MAJOR_VERSION == 2 python_name = PyString_InternFromString(name.c_str()); #else python_name = PyUnicode_InternFromString(name.c_str()); #endif }
int _PyFrame_Init() { builtin_object = PyString_InternFromString("__builtins__"); if (builtin_object == NULL) return 0; /* Traceback objects are not created the normal way (through calling the type), so PyType_Ready has to be called here. */ if (PyType_Ready(&PyTraceBack_Type)) { Py_DECREF(builtin_object); return 0; } return 1; }
int PyObject_SetAttrString(PyObject *v, char *name, PyObject *w) { PyObject *s; int res; if (v->ob_type->tp_setattr != NULL) return (*v->ob_type->tp_setattr)(v, name, w); s = PyString_InternFromString(name); if (s == NULL) return -1; res = PyObject_SetAttr(v, s, w); Py_XDECREF(s); return res; }
static int symtable_new_tmpname(struct symtable *st) { char tmpname[256]; identifier tmp; PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", ++st->st_cur->ste_tmpname); tmp = PyString_InternFromString(tmpname); if (!tmp) return 0; if (!symtable_add_def(st, tmp, DEF_LOCAL)) return 0; Py_DECREF(tmp); return 1; }