本文整理汇总了C++中PySys_WriteStderr函数的典型用法代码示例。如果您正苦于以下问题:C++ PySys_WriteStderr函数的具体用法?C++ PySys_WriteStderr怎么用?C++ PySys_WriteStderr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PySys_WriteStderr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _PyModule_Clear
void
_PyModule_Clear(PyObject *m)
{
/* To make the execution order of destructors for global
objects a bit more predictable, we first zap all objects
whose name starts with a single underscore, before we clear
the entire dictionary. We zap them by replacing them with
None, rather than deleting them from the dictionary, to
avoid rehashing the dictionary (to some extent). */
Py_ssize_t pos;
PyObject *key, *value;
PyObject *d;
d = ((PyModuleObject *)m)->md_dict;
if (d == NULL)
return;
/* First, clear only names starting with a single underscore */
pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) {
if (PyUnicode_READ_CHAR(key, 0) == '_' &&
PyUnicode_READ_CHAR(key, 1) != '_') {
if (Py_VerboseFlag > 1) {
const char *s = _PyUnicode_AsString(key);
if (s != NULL)
PySys_WriteStderr("# clear[1] %s\n", s);
else
PyErr_Clear();
}
PyDict_SetItem(d, key, Py_None);
}
}
}
/* Next, clear all names except for __builtins__ */
pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) {
if (PyUnicode_READ_CHAR(key, 0) != '_' ||
PyUnicode_CompareWithASCIIString(key, "__builtins__") != 0)
{
if (Py_VerboseFlag > 1) {
const char *s = _PyUnicode_AsString(key);
if (s != NULL)
PySys_WriteStderr("# clear[2] %s\n", s);
else
PyErr_Clear();
}
PyDict_SetItem(d, key, Py_None);
}
}
}
/* Note: we leave __builtins__ in place, so that destructors
of non-global objects defined in this module can still use
builtins, in particularly 'None'. */
}
示例2: PrintValidation
hlVoid PrintValidation(HLValidation eValidation)
{
switch(eValidation)
{
case HL_VALIDATES_ASSUMED_OK:
PySys_WriteStdout("Assumed OK");
break;
case HL_VALIDATES_OK:
PySys_WriteStdout("OK");
break;
case HL_VALIDATES_INCOMPLETE:
PySys_WriteStderr("Incomplete");
break;
case HL_VALIDATES_CORRUPT:
PySys_WriteStderr("Corrupt");
break;
case HL_VALIDATES_CANCELED:
PySys_WriteStderr("Canceled");
break;
case HL_VALIDATES_ERROR:
PySys_WriteStderr("Error");
break;
default:
PySys_WriteStderr("Unknown");
break;
}
}
示例3: PyObject_GetAttrString
QString PythonMapFormat::shortName() const
{
QString ret;
// find fun
PyObject *pfun = PyObject_GetAttrString(mClass, "shortName");
if (!pfun || !PyCallable_Check(pfun)) {
PySys_WriteStderr("Plugin extension doesn't define \"shortName\". Falling back to \"nameFilter\"\n");
return nameFilter();
}
// have fun
PyObject *pinst = PyEval_CallFunction(pfun, "()");
if (!pinst) {
PySys_WriteStderr("** Uncaught exception in script **\n");
} else {
ret = PyString_AsString(pinst);
Py_DECREF(pinst);
}
handleError();
Py_DECREF(pfun);
return ret;
}
示例4: handle_uncaught_exception
/* handle uncausht exception in a callback */
static void
handle_uncaught_exception(Loop *loop)
{
PyObject *excepthook, *exc, *value, *tb, *result;
Bool exc_in_hook = False;
ASSERT(loop);
ASSERT(PyErr_Occurred());
PyErr_Fetch(&exc, &value, &tb);
excepthook = PyObject_GetAttrString((PyObject *)loop, "excepthook");
if (excepthook == NULL) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
PySys_WriteStderr("Exception while getting excepthook\n");
PyErr_PrintEx(0);
exc_in_hook = True;
}
PyErr_Restore(exc, value, tb);
} else if (excepthook == Py_None) {
PyErr_Restore(exc, value, tb);
} else {
PyErr_NormalizeException(&exc, &value, &tb);
if (!value)
PYUV_SET_NONE(value);
if (!tb)
PYUV_SET_NONE(tb);
result = PyObject_CallFunctionObjArgs(excepthook, exc, value, tb, NULL);
if (result == NULL) {
PySys_WriteStderr("Unhandled exception in excepthook\n");
PyErr_PrintEx(0);
exc_in_hook = True;
PyErr_Restore(exc, value, tb);
} else {
Py_DECREF(exc);
Py_DECREF(value);
Py_DECREF(tb);
}
Py_XDECREF(result);
}
Py_XDECREF(excepthook);
/* Exception still pending, print it to stderr */
if (PyErr_Occurred()) {
if (exc_in_hook)
PySys_WriteStderr("\n");
PySys_WriteStderr("Unhandled exception in callback\n");
PyErr_PrintEx(0);
}
}
示例5: Tcl_AppInit
int
Tcl_AppInit(Tcl_Interp *interp)
{
Tk_Window main;
main = Tk_MainWindow(interp);
if (Tcl_Init(interp) == TCL_ERROR) {
PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp));
return TCL_ERROR;
}
if (Tk_Init(interp) == TCL_ERROR) {
PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp));
return TCL_ERROR;
}
return TCL_OK;
}
示例6: dragglue_SendData
static pascal OSErr
dragglue_SendData(FlavorType theType, void *dragSendRefCon,
ItemReference theItem, DragReference theDrag)
{
DragObjObject *self = (DragObjObject *)dragSendRefCon;
PyObject *args, *rv;
int i;
if ( self->sendproc == NULL )
return -1;
args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
if ( args == NULL )
return -1;
rv = PyEval_CallObject(self->sendproc, args);
Py_DECREF(args);
if ( rv == NULL ) {
PySys_WriteStderr("Drag: Exception in SendDataHandler\n");
PyErr_Print();
return -1;
}
i = -1;
if ( rv == Py_None )
i = 0;
else
PyArg_Parse(rv, "l", &i);
Py_DECREF(rv);
return i;
}
示例7: dragglue_ReceiveHandler
static pascal OSErr
dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
DragReference theDrag)
{
PyObject *args, *rv;
int i;
args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
if ( args == NULL )
return -1;
rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
Py_DECREF(args);
if ( rv == NULL ) {
PySys_WriteStderr("Drag: Exception in ReceiveHandler\n");
PyErr_Print();
return -1;
}
i = -1;
if ( rv == Py_None )
i = 0;
else
PyArg_Parse(rv, "l", &i);
Py_DECREF(rv);
return i;
}
示例8: do_import
int do_import(FARPROC init_func, char *modname)
{
PyObject *m;
char *oldcontext;
if ((m = _PyImport_FindExtension(modname, modname)) != NULL) {
return -1;
}
if (init_func == NULL) {
PyErr_Format(PyExc_ImportError,
"dynamic module does not define init function (init%.200s)",
modname);
return -1;
}
oldcontext = _Py_PackageContext;
_Py_PackageContext = modname;
(*init_func)();
_Py_PackageContext = oldcontext;
if (PyErr_Occurred()) {
return -1;
}
if (_PyImport_FixupExtension(modname, modname) == NULL)
return -1;
if (Py_VerboseFlag)
PySys_WriteStderr(
"import %s # dynamically loaded from zipfile\n",
modname);
return 0;
}
示例9: QString
bool PythonMapFormat::write(const Tiled::Map *map, const QString &fileName)
{
mError = QString();
mPlugin.log(tr("-- Using script %1 to write %2").arg(mScriptFile, fileName));
PyObject *pmap = _wrap_convert_c2py__Tiled__Map_const(map);
if (!pmap)
return false;
PyObject *pinst = PyObject_CallMethod(mClass,
(char *)"write", (char *)"(Ns)",
pmap,
fileName.toUtf8().constData());
if (!pinst) {
PySys_WriteStderr("** Uncaught exception in script **\n");
mError = tr("Uncaught exception in script. Please check console.");
} else {
bool ret = PyObject_IsTrue(pinst);
Py_DECREF(pinst);
if (!ret)
mError = tr("Script returned false. Please check console.");
return ret;
}
handleError();
return false;
}
示例10: _PyGC_Fini
void
_PyGC_Fini(void)
{
if (!(debug & DEBUG_SAVEALL)
&& garbage != NULL && PyList_GET_SIZE(garbage) > 0) {
char *message;
if (debug & DEBUG_UNCOLLECTABLE)
message = "gc: %zd uncollectable objects at " \
"shutdown";
else
message = "gc: %zd uncollectable objects at " \
"shutdown; use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them";
if (PyErr_WarnFormat(PyExc_ResourceWarning, 0, message,
PyList_GET_SIZE(garbage)) < 0)
PyErr_WriteUnraisable(NULL);
if (debug & DEBUG_UNCOLLECTABLE) {
PyObject *repr = NULL, *bytes = NULL;
repr = PyObject_Repr(garbage);
if (!repr || !(bytes = PyUnicode_EncodeFSDefault(repr)))
PyErr_WriteUnraisable(garbage);
else {
PySys_WriteStderr(
" %s\n",
PyBytes_AS_STRING(bytes)
);
}
Py_XDECREF(repr);
Py_XDECREF(bytes);
}
}
}
示例11: MatrixPointer_setY
static PyObject *
MatrixPointer_setY(MatrixPointer *self, PyObject *arg)
{
PyObject *tmp, *streamtmp;
if (arg == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
int isNumber = PyNumber_Check(arg);
if (isNumber == 1) {
PySys_WriteStderr("MatrixPointer y attributes must be a PyoObject.\n");
if (PyInt_AsLong(PyObject_CallMethod(self->server, "getIsBooted", NULL))) {
PyObject_CallMethod(self->server, "shutdown", NULL);
}
Py_Exit(1);
}
tmp = arg;
Py_INCREF(tmp);
Py_XDECREF(self->y);
self->y = tmp;
streamtmp = PyObject_CallMethod((PyObject *)self->y, "_getStream", NULL);
Py_INCREF(streamtmp);
Py_XDECREF(self->y_stream);
self->y_stream = (Stream *)streamtmp;
Py_INCREF(Py_None);
return Py_None;
}
示例12: get_decompress_func
/* Return the zlib.decompress function object, or NULL if zlib couldn't
be imported. The function is cached when found, so subsequent calls
don't import zlib again. Returns a *borrowed* reference.
XXX This makes zlib.decompress immortal. */
static PyObject *
get_decompress_func(void)
{
static PyObject *decompress = NULL;
if (decompress == NULL) {
PyObject *zlib;
static int importing_zlib = 0;
if (importing_zlib != 0)
/* Someone has a zlib.py[co] in their Zip file;
let's avoid a stack overflow. */
return NULL;
importing_zlib = 1;
zlib = PyImport_ImportModuleNoBlock("zlib");
importing_zlib = 0;
if (zlib != NULL) {
decompress = PyObject_GetAttrString(zlib,
"decompress");
Py_DECREF(zlib);
}
else
PyErr_Clear();
if (Py_VerboseFlag)
PySys_WriteStderr("# zipimport: zlib %s\n",
zlib != NULL ? "available": "UNAVAILABLE");
}
return decompress;
}
示例13: t_bootstrap
static void
t_bootstrap(void *boot_raw)
{
struct bootstate *boot = (struct bootstate *) boot_raw;
PyThreadState *tstate;
PyObject *res;
tstate = PyThreadState_New(boot->interp);
PyEval_AcquireThread(tstate);
res = PyEval_CallObjectWithKeywords(
boot->func, boot->args, boot->keyw);
Py_DECREF(boot->func);
Py_DECREF(boot->args);
Py_XDECREF(boot->keyw);
PyMem_DEL(boot_raw);
if (res == NULL) {
if (PyErr_ExceptionMatches(PyExc_SystemExit))
PyErr_Clear();
else {
PySys_WriteStderr("Unhandled exception in thread:\n");
PyErr_PrintEx(0);
}
}
else
Py_DECREF(res);
PyThreadState_Clear(tstate);
PyThreadState_DeleteCurrent();
PyThread_exit_thread();
}
示例14: match
/* Given the contents of a .py[co] file in a buffer, unmarshal the data
and return the code object. Return None if it the magic word doesn't
match (we do this instead of raising an exception as we fall back
to .py if available and we don't want to mask other errors).
Returns a new reference. */
static PyObject *
unmarshal_code(char *pathname, PyObject *data)
{
PyObject *code;
char *buf = PyBytes_AsString(data);
Py_ssize_t size = PyBytes_Size(data);
if (size <= 9) {
PyErr_SetString(PyExc_TypeError,
"bad pyc data");
return NULL;
}
if (get_long((unsigned char *)buf) != PyImport_GetMagicNumber()) {
if (Py_VerboseFlag)
PySys_WriteStderr("# %s has bad magic\n",
pathname);
Py_INCREF(Py_None);
return NULL;
}
code = PyMarshal_ReadObjectFromString(buf + 8, size - 8);
if (code == NULL)
return NULL;
if (!PyCode_Check(code)) {
Py_DECREF(code);
PyErr_Format(PyExc_TypeError,
"compiled module %.200s is not a code object",
pathname);
return NULL;
}
return code;
}
示例15: PyErr_Warn
/* Function to issue a warning message; may raise an exception. */
int
PyErr_Warn(PyObject *category, char *message)
{
PyObject *dict, *func = NULL;
PyObject *warnings_module = PyModule_GetWarningsModule();
if (warnings_module != NULL) {
dict = PyModule_GetDict(warnings_module);
func = PyDict_GetItemString(dict, "warn");
}
if (func == NULL) {
PySys_WriteStderr("warning: %s\n", message);
return 0;
}
else {
PyObject *args, *res;
if (category == NULL)
category = PyExc_RuntimeWarning;
args = Py_BuildValue("(sO)", message, category);
if (args == NULL)
return -1;
res = PyEval_CallObject(func, args);
Py_DECREF(args);
if (res == NULL)
return -1;
Py_DECREF(res);
return 0;
}
}