本文整理汇总了C++中PyFile_WriteString函数的典型用法代码示例。如果您正苦于以下问题:C++ PyFile_WriteString函数的具体用法?C++ PyFile_WriteString怎么用?C++ PyFile_WriteString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyFile_WriteString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: mywrite
static void mywrite(const char* name, FILE* fp, const char* format, va_list va) noexcept {
PyObject* file;
PyObject* error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
file = PySys_GetObject(name);
if (file == NULL || PyFile_AsFile(file) == fp)
vfprintf(fp, format, va);
else {
char buffer[1001];
const int written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
if (PyFile_WriteString(buffer, file) != 0) {
PyErr_Clear();
fputs(buffer, fp);
}
if (written < 0 || (size_t)written >= sizeof(buffer)) {
const char* truncated = "... truncated";
if (PyFile_WriteString(truncated, file) != 0) {
PyErr_Clear();
fputs(truncated, fp);
}
}
}
PyErr_Restore(error_type, error_value, error_traceback);
}
开发者ID:Thooms,项目名称:pyston,代码行数:25,代码来源:sys.cpp
示例2: __Pyx_Print
static int __Pyx_Print(PyObject *arg_tuple, int newline) {
PyObject *f;
PyObject* v;
int i;
if (!(f = __Pyx_GetStdout()))
return -1;
for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
if (PyFile_SoftSpace(f, 1)) {
if (PyFile_WriteString(" ", f) < 0)
return -1;
}
v = PyTuple_GET_ITEM(arg_tuple, i);
if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
return -1;
if (PyString_Check(v)) {
char *s = PyString_AsString(v);
Py_ssize_t len = PyString_Size(v);
if (len > 0 &&
isspace(Py_CHARMASK(s[len-1])) &&
s[len-1] != ' ')
PyFile_SoftSpace(f, 0);
}
}
if (newline) {
if (PyFile_WriteString("\n", f) < 0)
return -1;
PyFile_SoftSpace(f, 0);
}
return 0;
}
开发者ID:wflynny,项目名称:spinwaves_git_final,代码行数:31,代码来源:hellow.c
示例3: print_exception_recursive
static void
print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen)
{
int err = 0, res;
PyObject *cause, *context;
if (seen != NULL) {
/* Exception chaining */
PyObject *value_id = PyLong_FromVoidPtr(value);
if (value_id == NULL || PySet_Add(seen, value_id) == -1)
PyErr_Clear();
else if (PyExceptionInstance_Check(value)) {
PyObject *check_id = NULL;
cause = PyException_GetCause(value);
context = PyException_GetContext(value);
if (cause) {
check_id = PyLong_FromVoidPtr(cause);
if (check_id == NULL) {
res = -1;
} else {
res = PySet_Contains(seen, check_id);
Py_DECREF(check_id);
}
if (res == -1)
PyErr_Clear();
if (res == 0) {
print_exception_recursive(
f, cause, seen);
err |= PyFile_WriteString(
cause_message, f);
}
}
else if (context &&
!((PyBaseExceptionObject *)value)->suppress_context) {
check_id = PyLong_FromVoidPtr(context);
if (check_id == NULL) {
res = -1;
} else {
res = PySet_Contains(seen, check_id);
Py_DECREF(check_id);
}
if (res == -1)
PyErr_Clear();
if (res == 0) {
print_exception_recursive(
f, context, seen);
err |= PyFile_WriteString(
context_message, f);
}
}
Py_XDECREF(context);
Py_XDECREF(cause);
}
Py_XDECREF(value_id);
}
print_exception(f, value);
if (err != 0)
PyErr_Clear();
}
开发者ID:tiran,项目名称:cpython,代码行数:59,代码来源:pythonrun.c
示例4: callback_error
static void
callback_error(const char* handler)
{
PyObject* sys_stderr;
sys_stderr = PySys_GetObject("stderr");
if (sys_stderr) {
PyFile_WriteString("*** ImageWin: error in ", sys_stderr);
PyFile_WriteString((char*) handler, sys_stderr);
PyFile_WriteString(":\n", sys_stderr);
}
PyErr_Print();
PyErr_Clear();
}
开发者ID:Bouke,项目名称:Pillow,代码行数:16,代码来源:display.c
示例5: PyTraceBack_Print
int
PyTraceBack_Print(PyObject *v, PyObject *f)
{
int err;
PyObject *limitv;
long limit = PyTraceBack_LIMIT;
if (v == NULL)
return 0;
if (!PyTraceBack_Check(v)) {
PyErr_BadInternalCall();
return -1;
}
limitv = PySys_GetObject("tracebacklimit");
if (limitv && PyLong_Check(limitv)) {
int overflow;
limit = PyLong_AsLongAndOverflow(limitv, &overflow);
if (overflow > 0) {
limit = LONG_MAX;
}
else if (limit <= 0) {
return 0;
}
}
err = PyFile_WriteString("Traceback (most recent call last):\n", f);
if (!err)
err = tb_printinternal((PyTracebackObject *)v, f, limit);
return err;
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:29,代码来源:traceback.c
示例6: __Pyx_PrintOne
static int __Pyx_PrintOne(PyObject *o) {
PyObject *f;
if (!(f = __Pyx_GetStdout()))
return -1;
if (PyFile_SoftSpace(f, 0)) {
if (PyFile_WriteString(" ", f) < 0)
return -1;
}
if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
return -1;
if (PyFile_WriteString("\n", f) < 0)
return -1;
return 0;
/* the line below is just to avoid compiler
* compiler warnings about unused functions */
return __Pyx_Print(NULL, 0);
}
开发者ID:wflynny,项目名称:spinwaves_git_final,代码行数:17,代码来源:hellow.c
示例7: PyErr_WriteUnraisable
/* Call when an exception has occurred but there is no way for Python
to handle it. Examples: exception in __del__ or during GC. */
void
PyErr_WriteUnraisable(PyObject *obj)
{
PyObject *f, *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb);
f = PySys_GetObject("stderr");
if (f != NULL) {
PyFile_WriteString("Exception ", f);
if (t) {
PyObject* moduleName;
char* className;
assert(PyExceptionClass_Check(t));
className = PyExceptionClass_Name(t);
if (className != NULL) {
char *dot = strrchr(className, '.');
if (dot != NULL)
className = dot+1;
}
moduleName = PyObject_GetAttrString(t, "__module__");
if (moduleName == NULL)
PyFile_WriteString("<unknown>", f);
else {
char* modstr = PyString_AsString(moduleName);
if (modstr &&
strcmp(modstr, "exceptions") != 0)
{
PyFile_WriteString(modstr, f);
PyFile_WriteString(".", f);
}
}
if (className == NULL)
PyFile_WriteString("<unknown>", f);
else
PyFile_WriteString(className, f);
if (v && v != Py_None) {
PyFile_WriteString(": ", f);
PyFile_WriteObject(v, f, 0);
}
Py_XDECREF(moduleName);
}
PyFile_WriteString(" in ", f);
PyFile_WriteObject(obj, f, 0);
PyFile_WriteString(" ignored\n", f);
PyErr_Clear(); /* Just in case */
}
Py_XDECREF(t);
Py_XDECREF(v);
Py_XDECREF(tb);
}
开发者ID:AbnerChang,项目名称:edk2-staging,代码行数:52,代码来源:errors.c
示例8: show_warning
static void
show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
*category, PyObject *sourceline)
{
PyObject *f_stderr;
PyObject *name;
char lineno_str[128];
PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno);
name = PyObject_GetAttrString(category, "__name__");
if (name == NULL) /* XXX Can an object lack a '__name__' attribute? */
return;
f_stderr = PySys_GetObject("stderr");
if (f_stderr == NULL) {
fprintf(stderr, "lost sys.stderr\n");
Py_DECREF(name);
return;
}
/* Print "filename:lineno: category: text\n" */
PyFile_WriteObject(filename, f_stderr, Py_PRINT_RAW);
PyFile_WriteString(lineno_str, f_stderr);
PyFile_WriteObject(name, f_stderr, Py_PRINT_RAW);
PyFile_WriteString(": ", f_stderr);
PyFile_WriteObject(text, f_stderr, Py_PRINT_RAW);
PyFile_WriteString("\n", f_stderr);
Py_XDECREF(name);
/* Print " source_line\n" */
if (sourceline) {
char *source_line_str = PyString_AS_STRING(sourceline);
while (*source_line_str == ' ' || *source_line_str == '\t' ||
*source_line_str == '\014')
source_line_str++;
PyFile_WriteString(source_line_str, f_stderr);
PyFile_WriteString("\n", f_stderr);
}
else
_Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename),
lineno, 2);
PyErr_Clear();
}
开发者ID:GINK03,项目名称:StaticPython,代码行数:45,代码来源:_warnings.c
示例9: __Pyx_PrintNewline
static int __Pyx_PrintNewline(void) {
PyObject *f;
if (!(f = __Pyx_GetStdout()))
return -1;
if (PyFile_WriteString("\n", f) < 0)
return -1;
PyFile_SoftSpace(f, 0);
return 0;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:10,代码来源:excbug.c
示例10: print_error_text
static void
print_error_text(PyObject *f, int offset, const char *text)
{
char *nl;
if (offset >= 0) {
if (offset > 0 && offset == (int)strlen(text))
offset--;
for (;;) {
nl = strchr(text, '\n');
if (nl == NULL || nl-text >= offset)
break;
offset -= (int)(nl+1-text);
text = nl+1;
}
while (*text == ' ' || *text == '\t') {
text++;
offset--;
}
}
PyFile_WriteString(" ", f);
PyFile_WriteString(text, f);
if (*text == '\0' || text[strlen(text)-1] != '\n')
PyFile_WriteString("\n", f);
if (offset == -1)
return;
PyFile_WriteString(" ", f);
offset--;
while (offset > 0) {
PyFile_WriteString(" ", f);
offset--;
}
PyFile_WriteString("^\n", f);
}
开发者ID:hangyan,项目名称:python-source-code,代码行数:33,代码来源:pythonrun.c
示例11: initsite
static void
initsite(void)
{
PyObject *m, *f;
m = PyImport_ImportModule("site");
if (m == NULL) {
f = PySys_GetObject("stderr");
if (Py_VerboseFlag) {
PyFile_WriteString(
"'import site' failed; traceback:\n", f);
PyErr_Print();
}
else {
PyFile_WriteString(
"'import site' failed; use -v for traceback\n", f);
PyErr_Clear();
}
}
else {
Py_DECREF(m);
}
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:22,代码来源:pythonrun.c
示例12: PrintError
static void
PrintError(char *msg, ...)
{
char buf[512];
PyObject *f = PySys_GetObject("stderr");
va_list marker;
va_start(marker, msg);
vsnprintf(buf, sizeof(buf), msg, marker);
va_end(marker);
if (f != NULL && f != Py_None)
PyFile_WriteString(buf, f);
PyErr_Print();
}
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:14,代码来源:callbacks.c
示例13: PyErr_WriteUnraisable
/* Call when an exception has occurred but there is no way for Python
to handle it. Examples: exception in __del__ or during GC. */
void
PyErr_WriteUnraisable(PyObject *obj)
{
PyObject *f, *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb);
f = PySys_GetObject("stderr");
if (f != NULL) {
PyFile_WriteString("Exception ", f);
if (t) {
PyFile_WriteObject(t, f, Py_PRINT_RAW);
if (v && v != Py_None) {
PyFile_WriteString(": ", f);
PyFile_WriteObject(v, f, 0);
}
}
PyFile_WriteString(" in ", f);
PyFile_WriteObject(obj, f, 0);
PyFile_WriteString(" ignored\n", f);
PyErr_Clear(); /* Just in case */
}
Py_XDECREF(t);
Py_XDECREF(v);
Py_XDECREF(tb);
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:26,代码来源:errors.c
示例14: PyCom_StreamMessage
void PyCom_StreamMessage(const char *pszMessageText)
{
#ifndef MS_WINCE
OutputDebugStringA(pszMessageText);
#else
NKDbgPrintfW(pszMessageText);
#endif
// PySys_WriteStderr has an internal 1024 limit due to varargs.
// weve already resolved them, so we gotta do it the hard way
// We can't afford to screw with the Python exception state
PyObject *typ, *val, *tb;
PyErr_Fetch(&typ, &val, &tb);
PyObject *pyfile = PySys_GetObject("stderr");
if (pyfile)
if (PyFile_WriteString((char *)pszMessageText, pyfile)!=0)
// eeek - Python error writing this error - write it to stdout.
fprintf(stdout, "%s", pszMessageText);
PyErr_Restore(typ, val, tb);
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:19,代码来源:ErrorUtils.cpp
示例15: __Pyx_PrintItem
static int __Pyx_PrintItem(PyObject *v) {
PyObject *f;
if (!(f = __Pyx_GetStdout()))
return -1;
if (PyFile_SoftSpace(f, 1)) {
if (PyFile_WriteString(" ", f) < 0)
return -1;
}
if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
return -1;
if (PyString_Check(v)) {
char *s = PyString_AsString(v);
Py_ssize_t len = PyString_Size(v);
if (len > 0 &&
isspace(Py_CHARMASK(s[len-1])) &&
s[len-1] != ' ')
PyFile_SoftSpace(f, 0);
}
return 0;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:21,代码来源:excbug.c
示例16: PyTraceBack_Print
int
PyTraceBack_Print(PyObject *v, PyObject *f)
{
int err;
PyObject *limitv;
long limit = PyTraceBack_LIMIT;
if (v == NULL)
return 0;
if (!PyTraceBack_Check(v)) {
PyErr_BadInternalCall();
return -1;
}
limitv = PySys_GetObject("tracebacklimit");
if (limitv) {
PyObject *exc_type, *exc_value, *exc_tb;
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
limit = PyLong_AsLong(limitv);
if (limit == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
limit = PyTraceBack_LIMIT;
}
else {
Py_XDECREF(exc_type);
Py_XDECREF(exc_value);
Py_XDECREF(exc_tb);
return 0;
}
}
else if (limit <= 0) {
limit = PyTraceBack_LIMIT;
}
PyErr_Restore(exc_type, exc_value, exc_tb);
}
err = PyFile_WriteString("Traceback (most recent call last):\n", f);
if (!err)
err = tb_printinternal((PyTracebackObject *)v, f, limit);
return err;
}
开发者ID:collinanderson,项目名称:ensurepip,代码行数:40,代码来源:traceback.c
示例17: call_sys_exitfunc
static void
call_sys_exitfunc(void)
{
PyObject *exitfunc = PySys_GetObject("exitfunc");
if (exitfunc) {
PyObject *res, *f;
Py_INCREF(exitfunc);
PySys_SetObject("exitfunc", (PyObject *)NULL);
f = PySys_GetObject("stderr");
res = PyEval_CallObject(exitfunc, (PyObject *)NULL);
if (res == NULL) {
if (f)
PyFile_WriteString("Error in sys.exitfunc:\n", f);
PyErr_Print();
}
Py_DECREF(exitfunc);
}
if (Py_FlushLine())
PyErr_Clear();
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:22,代码来源:pythonrun.c
示例18: PyTraceBack_Print
int
PyTraceBack_Print(PyObject *v, PyObject *f)
{
int err;
PyObject *limitv;
int limit = 1000;
if (v == NULL)
return 0;
if (!PyTraceBack_Check(v)) {
PyErr_BadInternalCall();
return -1;
}
limitv = PySys_GetObject("tracebacklimit");
if (limitv && PyInt_Check(limitv)) {
limit = PyInt_AsLong(limitv);
if (limit <= 0)
return 0;
}
err = PyFile_WriteString("Traceback (most recent call last):\n", f);
if (!err)
err = tb_printinternal((tracebackobject *)v, f, limit);
return err;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:23,代码来源:traceback.c
示例19: print_error_text
static void
print_error_text(PyObject *f, int offset, PyObject *text_obj)
{
const char *text;
const char *nl;
text = PyUnicode_AsUTF8(text_obj);
if (text == NULL)
return;
if (offset >= 0) {
if (offset > 0 && (size_t)offset == strlen(text) && text[offset - 1] == '\n')
offset--;
for (;;) {
nl = strchr(text, '\n');
if (nl == NULL || nl-text >= offset)
break;
offset -= (int)(nl+1-text);
text = nl+1;
}
while (*text == ' ' || *text == '\t' || *text == '\f') {
text++;
offset--;
}
}
PyFile_WriteString(" ", f);
PyFile_WriteString(text, f);
if (*text == '\0' || text[strlen(text)-1] != '\n')
PyFile_WriteString("\n", f);
if (offset == -1)
return;
PyFile_WriteString(" ", f);
while (--offset > 0)
PyFile_WriteString(" ", f);
PyFile_WriteString("^\n", f);
}
开发者ID:tiran,项目名称:cpython,代码行数:36,代码来源:pythonrun.c
示例20: tb_displayline
static int
tb_displayline(PyObject *f, char *filename, int lineno, char *name)
{
int err = 0;
FILE *xfp;
char linebuf[2000];
int i;
if (filename == NULL || name == NULL)
return -1;
#ifdef MPW
/* This is needed by MPW's File and Line commands */
#define FMT " File \"%.500s\"; line %d # in %.500s\n"
#else
/* This is needed by Emacs' compile command */
#define FMT " File \"%.500s\", line %d, in %.500s\n"
#endif
xfp = fopen(filename, "r" PY_STDIOTEXTMODE);
if (xfp == NULL) {
/* Search tail of filename in sys.path before giving up */
PyObject *path;
char *tail = strrchr(filename, SEP);
if (tail == NULL)
tail = filename;
else
tail++;
path = PySys_GetObject("path");
if (path != NULL && PyList_Check(path)) {
int npath = PyList_Size(path);
size_t taillen = strlen(tail);
char namebuf[MAXPATHLEN+1];
for (i = 0; i < npath; i++) {
PyObject *v = PyList_GetItem(path, i);
if (v == NULL) {
PyErr_Clear();
break;
}
if (PyString_Check(v)) {
size_t len;
len = PyString_Size(v);
if (len + 1 + taillen >= MAXPATHLEN)
continue; /* Too long */
strcpy(namebuf, PyString_AsString(v));
if (strlen(namebuf) != len)
continue; /* v contains '\0' */
if (len > 0 && namebuf[len-1] != SEP)
namebuf[len++] = SEP;
strcpy(namebuf+len, tail);
xfp = fopen(namebuf, "r" PY_STDIOTEXTMODE);
if (xfp != NULL) {
filename = namebuf;
break;
}
}
}
}
}
PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name);
err = PyFile_WriteString(linebuf, f);
if (xfp == NULL || err != 0)
return err;
for (i = 0; i < lineno; i++) {
char* pLastChar = &linebuf[sizeof(linebuf)-2];
do {
*pLastChar = '\0';
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, xfp, NULL) == NULL)
break;
/* fgets read *something*; if it didn't get as
far as pLastChar, it must have found a newline
or hit the end of the file; if pLastChar is \n,
it obviously found a newline; else we haven't
yet seen a newline, so must continue */
} while (*pLastChar != '\0' && *pLastChar != '\n');
}
if (i == lineno) {
char *p = linebuf;
while (*p == ' ' || *p == '\t' || *p == '\014')
p++;
err = PyFile_WriteString(" ", f);
if (err == 0) {
err = PyFile_WriteString(p, f);
if (err == 0 && strchr(p, '\n') == NULL)
err = PyFile_WriteString("\n", f);
}
}
fclose(xfp);
return err;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:87,代码来源:traceback.c
注:本文中的PyFile_WriteString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论