short BPy_errors_to_report(ReportList *reports) { PyObject *pystring; PyObject *pystring_format= NULL; // workaround, see below char *cstring; const char *filename; int lineno; if (!PyErr_Occurred()) return 1; /* less hassle if we allow NULL */ if (reports==NULL) { PyErr_Print(); PyErr_Clear(); return 1; } pystring= PyC_ExceptionBuffer(); if (pystring==NULL) { BKE_report(reports, RPT_ERROR, "unknown py-exception, couldn't convert"); return 0; } PyC_FileAndNum(&filename, &lineno); if (filename==NULL) filename= "<unknown location>"; cstring= _PyUnicode_AsString(pystring); #if 0 // ARG!. workaround for a bug in blenders use of vsnprintf BKE_reportf(reports, RPT_ERROR, "%s\nlocation:%s:%d\n", cstring, filename, lineno); #else pystring_format= PyUnicode_FromFormat("%s\nlocation:%s:%d\n", cstring, filename, lineno); cstring= _PyUnicode_AsString(pystring_format); BKE_report(reports, RPT_ERROR, cstring); #endif fprintf(stderr, "%s\nlocation:%s:%d\n", cstring, filename, lineno); // not exactly needed. just for testing Py_DECREF(pystring); Py_DECREF(pystring_format); // workaround return 1; }
/* The guts of "find_loader" and "find_module". */ static find_loader_result find_loader(ZipImporter *self, PyObject *fullname, PyObject **namespace_portion) { enum zi_module_info mi; *namespace_portion = NULL; mi = get_module_info(self, fullname); if (mi == MI_ERROR) return FL_ERROR; if (mi == MI_NOT_FOUND) { /* Not a module or regular package. See if this is a directory, and therefore possibly a portion of a namespace package. */ find_loader_result result = FL_NOT_FOUND; PyObject *subname; int is_dir; /* We're only interested in the last path component of fullname; earlier components are recorded in self->prefix. */ subname = get_subname(fullname); if (subname == NULL) { return FL_ERROR; } is_dir = check_is_directory(self, self->prefix, subname); if (is_dir < 0) result = FL_ERROR; else if (is_dir) { /* This is possibly a portion of a namespace package. Return the string representing its path, without a trailing separator. */ *namespace_portion = PyUnicode_FromFormat("%U%c%U%U", self->archive, SEP, self->prefix, subname); if (*namespace_portion == NULL) result = FL_ERROR; else result = FL_NS_FOUND; } Py_DECREF(subname); return result; } /* This is a module or package. */ return FL_MODULE_FOUND; }
static PyObject *make_oiio_info(void) { PyObject *oiio_info; int pos = 0; #ifdef WITH_OPENIMAGEIO int curversion; #endif oiio_info = PyStructSequence_New(&BlenderAppOIIOType); if (oiio_info == NULL) { return NULL; } #ifndef WITH_OPENIMAGEIO #define SetStrItem(str) \ PyStructSequence_SET_ITEM(oiio_info, pos++, PyUnicode_FromString(str)) #endif #define SetObjItem(obj) \ PyStructSequence_SET_ITEM(oiio_info, pos++, obj) #ifdef WITH_OPENIMAGEIO curversion = OIIO_getVersionHex(); SetObjItem(PyBool_FromLong(1)); SetObjItem(Py_BuildValue("(iii)", curversion / 10000, (curversion / 100) % 100, curversion % 100)); SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100)); #else SetObjItem(PyBool_FromLong(0)); SetObjItem(Py_BuildValue("(iii)", 0, 0, 0)); SetStrItem("Unknown"); #endif if (PyErr_Occurred()) { Py_CLEAR(oiio_info); return NULL; } #undef SetStrItem #undef SetObjItem return oiio_info; }
static void _trie_keys_helper(const char *key, const void *value, void *data) { PyObject *py_list = (PyObject *)data; PyObject *py_key; if(PyErr_Occurred()) return; #ifdef IS_PY3K if(!(py_key = PyUnicode_FromFormat(key))) #else if(!(py_key = PyString_FromString(key))) #endif return; PyList_Append(py_list, py_key); Py_DECREF(py_key); }
static int tb_displayline(PyObject *f, PyObject *filename, int lineno, PyObject *name) { int err; PyObject *line; if (filename == NULL || name == NULL) return -1; line = PyUnicode_FromFormat(" File \"%U\", line %d, in %U\n", filename, lineno, name); if (line == NULL) return -1; err = PyFile_WriteObject(line, f, Py_PRINT_RAW); Py_DECREF(line); if (err != 0) return err; return _Py_DisplaySourceLine(f, filename, lineno, 4); }
static PyObject * capsule_repr(PyObject *o) { PyCapsule *capsule = (PyCapsule *)o; const char *name; const char *quote; if (capsule->name) { quote = "\""; name = capsule->name; } else { quote = ""; name = "NULL"; } return PyUnicode_FromFormat("<capsule object %s%s%s at %p>", quote, name, quote, capsule); }
static int setup_module(PyObject* m) { PyObject *d; PyObject *v; d = PyModule_GetDict(m); /* Ready object types */ PyType_Ready(&CmsProfile_Type); PyType_Ready(&CmsTransform_Type); d = PyModule_GetDict(m); v = PyUnicode_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100); PyDict_SetItemString(d, "littlecms_version", v); return 0; }
// tp_repr slot, decide how a function shall be output static PyObject *Nuitka_Frame_tp_repr(struct Nuitka_FrameObject *nuitka_frame) { #if PYTHON_VERSION < 300 return PyString_FromFormat( #else return PyUnicode_FromFormat( #endif #if PYTHON_VERSION >= 370 "<compiled_frame at %p, file %R, line %d, code %S>", nuitka_frame, nuitka_frame->m_frame.f_code->co_filename, nuitka_frame->m_frame.f_lineno, nuitka_frame->m_frame.f_code->co_name #elif _DEBUG_FRAME || _DEBUG_REFRAME || _DEBUG_EXCEPTIONS "<compiled_frame object for %s at %p>", Nuitka_String_AsString(nuitka_frame->m_frame.f_code->co_name), nuitka_frame #else "<compiled_frame object at %p>", nuitka_frame #endif ); }
static PyObject *slot_QVector3D___repr__(PyObject *sipSelf) { QVector3D *sipCpp = reinterpret_cast<QVector3D *>(sipGetCppPtr((sipSimpleWrapper *)sipSelf,sipType_QVector3D)); if (!sipCpp) return 0; { { PyObject * sipRes = 0; #line 48 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\sip/QtGui/qvector3d.sip" PyObject *x = PyFloat_FromDouble(sipCpp->x()); PyObject *y = PyFloat_FromDouble(sipCpp->y()); PyObject *z = PyFloat_FromDouble(sipCpp->z()); if (x && y && z) { #if PY_MAJOR_VERSION >= 3 sipRes = PyUnicode_FromFormat("PyQt5.QtGui.QVector3D(%R, %R, %R)", x, y, z); #else sipRes = PyString_FromString("PyQt5.QtGui.QVector3D("); PyString_ConcatAndDel(&sipRes, PyObject_Repr(x)); PyString_ConcatAndDel(&sipRes, PyString_FromString(", ")); PyString_ConcatAndDel(&sipRes, PyObject_Repr(y)); PyString_ConcatAndDel(&sipRes, PyString_FromString(", ")); PyString_ConcatAndDel(&sipRes, PyObject_Repr(z)); PyString_ConcatAndDel(&sipRes, PyString_FromString(")")); #endif } Py_XDECREF(x); Py_XDECREF(y); Py_XDECREF(z); #line 1135 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\QtGui/sipQtGuiQVector3D.cpp" return sipRes; } } return 0; }
PyMODINIT_FUNC PyInit__imagingcms(void) { PyObject *m; PyObject *d; PyObject *v; /* Patch up object types */ Py_TYPE(&CmsProfile_Type) = &PyType_Type; Py_TYPE(&CmsTransform_Type) = &PyType_Type; m = PyModule_Create(&_imagingcms_module); d = PyModule_GetDict(m); v = PyUnicode_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100); PyDict_SetItemString(d, "littlecms_version", v); return m; }
static PyObject * _asctime(struct tm *timeptr) { /* Inspired by Open Group reference implementation available at * http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html */ static char wday_name[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; static char mon_name[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; return PyUnicode_FromFormat( "%s %s%3d %.2d:%.2d:%.2d %d", wday_name[timeptr->tm_wday], mon_name[timeptr->tm_mon], timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, 1900 + timeptr->tm_year); }
static PyObject *Nuitka_Generator_tp_repr( struct Nuitka_GeneratorObject *generator ) { #if PYTHON_VERSION < 300 return PyString_FromFormat( "<compiled_generator object %s at %p>", Nuitka_String_AsString( generator->m_name ), generator ); #else return PyUnicode_FromFormat( "<compiled_generator object %s at %p>", #if PYTHON_VERSION < 350 Nuitka_String_AsString( generator->m_name ), #else Nuitka_String_AsString( generator->m_qualname ), #endif generator ); #endif }
static PyObject *ncSessionGetVersion(ncSessionObject *self, void *closure) { int ver; const char* ver_s; ver = nc_session_get_version(self->session); switch(ver) { case 0: ver_s = "1.0"; break; case 1: ver_s = "1.1"; break; default: ver_s = "unknown"; break; } return PyUnicode_FromFormat("%s", ver_s); }
/* Return some information about a module. */ static enum zi_module_info get_module_info(ZipImporter *self, PyObject *fullname) { PyObject *subname; PyObject *path, *fullpath, *item; struct st_zip_searchorder *zso; if (self->prefix == NULL) { PyErr_SetString(PyExc_ValueError, "zipimporter.__init__() wasn't called"); return MI_ERROR; } subname = get_subname(fullname); if (subname == NULL) return MI_ERROR; path = make_filename(self->prefix, subname); Py_DECREF(subname); if (path == NULL) return MI_ERROR; for (zso = zip_searchorder; *zso->suffix; zso++) { fullpath = PyUnicode_FromFormat("%U%s", path, zso->suffix); if (fullpath == NULL) { Py_DECREF(path); return MI_ERROR; } item = PyDict_GetItem(self->files, fullpath); Py_DECREF(fullpath); if (item != NULL) { Py_DECREF(path); if (zso->type & IS_PACKAGE) return MI_PACKAGE; else return MI_MODULE; } } Py_DECREF(path); return MI_NOT_FOUND; }
static PyObject *ncSessionGetCapabilities(ncSessionObject *self, void *closure) { struct nc_cpblts* cpblts; PyObject *list; const char *item; ssize_t pos; cpblts = nc_session_get_cpblts(self->session); if (cpblts == NULL) { return (NULL); } list = PyList_New(nc_cpblts_count(cpblts)); nc_cpblts_iter_start(cpblts); for (pos = 0; pos < nc_cpblts_count(cpblts); pos++) { item = nc_cpblts_iter_next(cpblts); PyList_SetItem(list, pos, PyUnicode_FromFormat("%s", item)); } return list; }
static PyObject *bpy_bmesh_op_doc_get(BPy_BMeshOpFunc *self, void *UNUSED(closure)) { PyObject *ret; char *slot_in; char *slot_out; int i; i = BMO_opcode_from_opname(self->opname); slot_in = bmp_slots_as_args(bmo_opdefines[i]->slot_types_in, false); slot_out = bmp_slots_as_args(bmo_opdefines[i]->slot_types_out, true); ret = PyUnicode_FromFormat("%.200s bmesh.ops.%.200s(bmesh, %s)\n -> dict(%s)", Py_TYPE(self)->tp_name, self->opname, slot_in, slot_out); MEM_freeN(slot_in); MEM_freeN(slot_out); return ret; }
static int tb_displayline(PyObject *f, PyObject *filename, int lineno, PyObject *name) { int err; PyObject *line; if (filename == NULL || name == NULL) return -1; line = PyUnicode_FromFormat(" File \"%U\", line %d, in %U\n", filename, lineno, name); if (line == NULL) return -1; err = PyFile_WriteObject(line, f, Py_PRINT_RAW); Py_DECREF(line); if (err != 0) return err; /* ignore errors since we can't report them, can we? */ if (_Py_DisplaySourceLine(f, filename, lineno, 4)) PyErr_Clear(); return err; }
static PyObject * fortran_repr(PyFortranObject *fp) { PyObject *name = NULL, *repr = NULL; name = PyObject_GetAttrString((PyObject *)fp, "__name__"); PyErr_Clear(); #if PY_VERSION_HEX >= 0x03000000 if (name != NULL && PyUnicode_Check(name)) { repr = PyUnicode_FromFormat("<fortran %U>", name); } else { repr = PyUnicode_FromString("<fortran object>"); } #else if (name != NULL && PyString_Check(name)) { repr = PyString_FromFormat("<fortran %s>", PyString_AsString(name)); } else { repr = PyString_FromString("<fortran object>"); } #endif Py_XDECREF(name); return repr; }
PyObject * init_pyaio(void) { PyObject *m; PyObject *__version__; /* We will be using threads */ PyEval_InitThreads(); #if PY_MAJOR_VERSION >= 3 __version__ = PyUnicode_FromFormat("%s", PYAIO_VERSION); #else __version__ = PyString_FromFormat("%s", PYAIO_VERSION); #endif if (!__version__) { return NULL; } #if PY_MAJOR_VERSION >= 3 m = PyModule_Create(&moduledef); #else m = Py_InitModule3("core", PyaioMethods, NULL); #endif if (!m) { Py_DECREF(__version__); return NULL; } if (PyModule_AddObject(m, "__version__", __version__)) { Py_DECREF(__version__); Py_DECREF(m); return NULL; } return m; }
static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno, int __pyx_lineno, const char *__pyx_filename) { PyObject *py_srcfile = 0; PyObject *py_funcname = 0; PyObject *py_globals = 0; PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(__pyx_filename); #else py_srcfile = PyUnicode_FromString(__pyx_filename); #endif if (!py_srcfile) goto bad; if (__pyx_clineno) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_globals = PyModule_GetDict(__pyx_m); if (!py_globals) goto bad; py_code = PyCode_New( 0, /*int argcount,*/ #if PY_MAJOR_VERSION >= 3 0, /*int kwonlyargcount,*/ #endif 0, /*int nlocals,*/ 0, /*int stacksize,*/ 0, /*int flags,*/ __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ __pyx_lineno, /*int firstlineno,*/ __pyx_empty_bytes /*PyObject *lnotab*/ ); if (!py_code) goto bad; py_frame = PyFrame_New( PyThreadState_GET(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = __pyx_lineno; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); Py_XDECREF(py_code); Py_XDECREF(py_frame); }
static PyObject *ncSessionGetTransport(ncSessionObject *self, void *closure) { NC_TRANSPORT t = nc_session_get_transport(self->session); return PyUnicode_FromFormat("%s", (t == NC_TRANSPORT_TLS) ? "TLS" : "SSH"); }
static PyObject *ncSessionGetUser(ncSessionObject *self, void *closure) { return PyUnicode_FromFormat("%s", nc_session_get_user(self->session)); }
static PyObject *ue_PyFSocket_str(ue_PyFSocket *self) { return PyUnicode_FromFormat("<unreal_engine.FSocket '%s'>", TCHAR_TO_UTF8(*self->sock->GetDescription())); }
static PyObject* PyBoostMt19937_Repr(PyBoostMt19937Object* self) { return PyUnicode_FromFormat("%s()", Py_TYPE(self)->tp_name); }
PyObject *PyErr_SetExcFromWindowsErrWithFilenameObjects( PyObject *exc, int ierr, PyObject *filenameObject, PyObject *filenameObject2) { int len; WCHAR *s_buf = NULL; /* Free via LocalFree */ PyObject *message; PyObject *args, *v; DWORD err = (DWORD)ierr; if (err==0) err = GetLastError(); len = FormatMessageW( /* Error API error */ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, /* no message source */ err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ (LPWSTR) &s_buf, 0, /* size not used */ NULL); /* no args */ if (len==0) { /* Only seen this in out of mem situations */ message = PyUnicode_FromFormat("Windows Error 0x%x", err); s_buf = NULL; } else { /* remove trailing cr/lf and dots */ while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.')) s_buf[--len] = L'\0'; message = PyUnicode_FromWideChar(s_buf, len); } if (message == NULL) { LocalFree(s_buf); return NULL; } if (filenameObject == NULL) { assert(filenameObject2 == NULL); filenameObject = filenameObject2 = Py_None; } else if (filenameObject2 == NULL) filenameObject2 = Py_None; /* This is the constructor signature for OSError. The POSIX translation will be figured out by the constructor. */ args = Py_BuildValue("(iOOiO)", 0, message, filenameObject, err, filenameObject2); Py_DECREF(message); if (args != NULL) { v = PyObject_Call(exc, args, NULL); Py_DECREF(args); if (v != NULL) { PyErr_SetObject((PyObject *) Py_TYPE(v), v); Py_DECREF(v); } } LocalFree(s_buf); return NULL; }
PyObject * PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, PyObject *filenameObject2) { PyObject *message; PyObject *v, *args; int i = errno; #ifdef MS_WINDOWS WCHAR *s_buf = NULL; #endif /* Unix/Windows */ #ifdef EINTR if (i == EINTR && PyErr_CheckSignals()) return NULL; #endif #ifndef MS_WINDOWS if (i != 0) { char *s = strerror(i); message = PyUnicode_DecodeLocale(s, "surrogateescape"); } else { /* Sometimes errno didn't get set */ message = PyUnicode_FromString("Error"); } #else if (i == 0) message = PyUnicode_FromString("Error"); /* Sometimes errno didn't get set */ else { /* Note that the Win32 errors do not lineup with the errno error. So if the error is in the MSVC error table, we use it, otherwise we assume it really _is_ a Win32 error code */ if (i > 0 && i < _sys_nerr) { message = PyUnicode_FromString(_sys_errlist[i]); } else { int len = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, /* no message source */ i, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ (LPWSTR) &s_buf, 0, /* size not used */ NULL); /* no args */ if (len==0) { /* Only ever seen this in out-of-mem situations */ s_buf = NULL; message = PyUnicode_FromFormat("Windows Error 0x%x", i); } else { /* remove trailing cr/lf and dots */ while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.')) s_buf[--len] = L'\0'; message = PyUnicode_FromWideChar(s_buf, len); } } } #endif /* Unix/Windows */ if (message == NULL) { #ifdef MS_WINDOWS LocalFree(s_buf); #endif return NULL; } if (filenameObject != NULL) { if (filenameObject2 != NULL) args = Py_BuildValue("(iOOiO)", i, message, filenameObject, 0, filenameObject2); else args = Py_BuildValue("(iOO)", i, message, filenameObject); } else { assert(filenameObject2 == NULL); args = Py_BuildValue("(iO)", i, message); } Py_DECREF(message); if (args != NULL) { v = PyObject_Call(exc, args, NULL); Py_DECREF(args); if (v != NULL) { PyErr_SetObject((PyObject *) Py_TYPE(v), v); Py_DECREF(v); } } #ifdef MS_WINDOWS LocalFree(s_buf); #endif return NULL; }
static PyObject *IDGroup_Iter_repr(BPy_IDGroup_Iter *self) { return PyUnicode_FromFormat("(ID Property Group Iter \"%s\")", self->group->prop->name); }
static PyObject * namespace_repr(PyObject *ns) { int i, loop_error = 0; PyObject *pairs = NULL, *d = NULL, *keys = NULL, *keys_iter = NULL; PyObject *key; PyObject *separator, *pairsrepr, *repr = NULL; const char * name; name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace" : ns->ob_type->tp_name; i = Py_ReprEnter(ns); if (i != 0) { return i > 0 ? PyUnicode_FromFormat("%s(...)", name) : NULL; } pairs = PyList_New(0); if (pairs == NULL) goto error; d = ((_PyNamespaceObject *)ns)->ns_dict; assert(d != NULL); Py_INCREF(d); keys = PyDict_Keys(d); if (keys == NULL) goto error; if (PyList_Sort(keys) != 0) goto error; keys_iter = PyObject_GetIter(keys); if (keys_iter == NULL) goto error; while ((key = PyIter_Next(keys_iter)) != NULL) { if (PyUnicode_Check(key) && PyUnicode_GET_LENGTH(key) > 0) { PyObject *value, *item; value = PyDict_GetItem(d, key); assert(value != NULL); item = PyUnicode_FromFormat("%S=%R", key, value); if (item == NULL) { loop_error = 1; } else { loop_error = PyList_Append(pairs, item); Py_DECREF(item); } } Py_DECREF(key); if (loop_error) goto error; } separator = PyUnicode_FromString(", "); if (separator == NULL) goto error; pairsrepr = PyUnicode_Join(separator, pairs); Py_DECREF(separator); if (pairsrepr == NULL) goto error; repr = PyUnicode_FromFormat("%s(%S)", name, pairsrepr); Py_DECREF(pairsrepr); error: Py_XDECREF(pairs); Py_XDECREF(d); Py_XDECREF(keys); Py_XDECREF(keys_iter); Py_ReprLeave(ns); return repr; }
static PyObject *Interface1D_repr(BPy_Interface1D *self) { return PyUnicode_FromFormat("type: %s - address: %p", self->if1D->getExactTypeName().c_str(), self->if1D); }
static PyObject *BPy_IDGroup_repr(BPy_IDProperty *self) { return PyUnicode_FromFormat("<bpy id prop: owner=\"%s\", name=\"%s\", address=%p>", self->id ? self->id->name : "<NONE>", self->prop->name, self->prop); }