本文整理汇总了C++中Py_FatalError函数的典型用法代码示例。如果您正苦于以下问题:C++ Py_FatalError函数的具体用法?C++ Py_FatalError怎么用?C++ Py_FatalError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Py_FatalError函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Py_FrozenMain
int
Py_FrozenMain(int argc, char **argv)
{
_PyInitError err = _PyRuntime_Initialize();
if (_Py_INIT_FAILED(err)) {
fprintf(stderr, "Fatal Python error: %s\n", err.msg);
fflush(stderr);
exit(1);
}
const char *p;
int i, n, sts = 1;
int inspect = 0;
int unbuffered = 0;
char *oldloc = NULL;
wchar_t **argv_copy = NULL;
/* We need a second copies, as Python might modify the first one. */
wchar_t **argv_copy2 = NULL;
if (argc > 0) {
argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
if (!argv_copy || !argv_copy2) {
fprintf(stderr, "out of memory\n");
goto error;
}
}
_PyCoreConfig config = _PyCoreConfig_INIT;
config._frozen = 1; /* Suppress errors from getpath.c */
if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
inspect = 1;
if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
if (unbuffered) {
setbuf(stdin, (char *)NULL);
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
}
oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
if (!oldloc) {
fprintf(stderr, "out of memory\n");
goto error;
}
setlocale(LC_ALL, "");
for (i = 0; i < argc; i++) {
argv_copy[i] = Py_DecodeLocale(argv[i], NULL);
argv_copy2[i] = argv_copy[i];
if (!argv_copy[i]) {
fprintf(stderr, "Unable to decode the command line argument #%i\n",
i + 1);
argc = i;
goto error;
}
}
setlocale(LC_ALL, oldloc);
PyMem_RawFree(oldloc);
oldloc = NULL;
#ifdef MS_WINDOWS
PyInitFrozenExtensions();
#endif /* MS_WINDOWS */
if (argc >= 1)
Py_SetProgramName(argv_copy[0]);
err = _Py_InitializeFromConfig(&config);
/* No need to call _PyCoreConfig_Clear() since we didn't allocate any
memory: program_name is a constant string. */
if (_Py_INIT_FAILED(err)) {
_Py_FatalInitError(err);
}
#ifdef MS_WINDOWS
PyWinFreeze_ExeInit();
#endif
if (Py_VerboseFlag)
fprintf(stderr, "Python %s\n%s\n",
Py_GetVersion(), Py_GetCopyright());
PySys_SetArgv(argc, argv_copy);
n = PyImport_ImportFrozenModule("__main__");
if (n == 0)
Py_FatalError("__main__ not frozen");
if (n < 0) {
PyErr_Print();
sts = 1;
}
else
sts = 0;
if (inspect && isatty((int)fileno(stdin)))
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
#ifdef MS_WINDOWS
//.........这里部分代码省略.........
示例2: qpycore_post_init
// Perform any required post-initialisation.
void qpycore_post_init(PyObject *module_dict)
{
// Add the meta-type to the module dictionary.
if (PyDict_SetItemString(module_dict, "pyqtWrapperType",
(PyObject *)&qpycore_pyqtWrapperType_Type) < 0)
Py_FatalError("PyQt4.QtCore: Failed to set pyqtWrapperType type");
// Initialise the pyqtProperty type and add it to the module dictionary.
if (PyType_Ready(&qpycore_pyqtProperty_Type) < 0)
Py_FatalError("PyQt4.QtCore: Failed to initialise pyqtProperty type");
if (PyDict_SetItemString(module_dict, "pyqtProperty",
(PyObject *)&qpycore_pyqtProperty_Type) < 0)
Py_FatalError("PyQt4.QtCore: Failed to set pyqtProperty type");
// Initialise the pyqtSignal type and add it to the module dictionary.
if (PyType_Ready(&qpycore_pyqtSignal_Type) < 0)
Py_FatalError("PyQt4.QtCore: Failed to initialise pyqtSignal type");
if (PyDict_SetItemString(module_dict, "pyqtSignal",
(PyObject *)&qpycore_pyqtSignal_Type) < 0)
Py_FatalError("PyQt4.QtCore: Failed to set pyqtSignal type");
// Initialise the pyqtBoundSignal type. Don't add it to the module
// dictionary as we don't want it to be explicitly invoked.
qpycore_pyqtBoundSignal_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&qpycore_pyqtBoundSignal_Type) < 0)
Py_FatalError("PyQt4.QtCore: Failed to initialise pyqtBoundSignal type");
// Register the C++ type that wraps Python objects.
PyQt_PyObject::metatype = qRegisterMetaType<PyQt_PyObject>("PyQt_PyObject");
qRegisterMetaTypeStreamOperators<PyQt_PyObject>("PyQt_PyObject");
// Register the lazy attribute getter.
if (sipRegisterAttributeGetter(sipType_QObject, qpycore_get_lazy_attr) < 0)
Py_FatalError("PyQt4.QtCore: Failed to register attribute getter");
// Objectify some strings.
#if PY_MAJOR_VERSION >= 3
qpycore_signature_attr_name = PyUnicode_FromString("__pyqtSignature__");
#else
qpycore_signature_attr_name = PyString_FromString("__pyqtSignature__");
#endif
if (!qpycore_signature_attr_name)
Py_FatalError("PyQt4.QtCore: Failed to objectify '__pyqtSignature__'");
#if PY_MAJOR_VERSION >= 3
qpycore_name_attr_name = PyUnicode_FromString("__name__");
#else
qpycore_name_attr_name = PyString_FromString("__name__");
#endif
if (!qpycore_name_attr_name)
Py_FatalError("PyQt4.QtCore: Failed to objectify '__name__'");
// Create the mutex that serialises access to the signal/slot proxies. We
// don't use a statically initialised one because Qt needs some things to
// be initialised first (at least for Windows) and this is the only way to
// guarantee things are done in the right order.
PyQtProxy::mutex = new QMutex(QMutex::Recursive);
}
示例3: initwarpC
PyMODINIT_FUNC initwarpC(void)
#endif
#endif
{
PyObject *m, *d;
/* PyObject *pystdout; */
PyObject *date;
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
#else
#ifdef MPIPARALLEL
m = Py_InitModule("warpCparallel", warpC_methods);
#else
m = Py_InitModule("warpC", warpC_methods);
#endif
#endif
d = PyModule_GetDict(m);
#ifdef MPIPARALLEL
ErrorObject = PyErr_NewException("warpCparallel.error",NULL,NULL);
#else
ErrorObject = PyErr_NewException("warpC.error",NULL,NULL);
#endif
PyDict_SetItemString(d, "error", ErrorObject);
date = PyUnicode_FromString(GITORIGINDATE);
PyDict_SetItemString(d, "origindate", date);
Py_XDECREF(date);
date = PyUnicode_FromString(GITLOCALDATE);
PyDict_SetItemString(d, "localdate", date);
Py_XDECREF(date);
date = PyUnicode_FromString(GITCOMMITHASH);
PyDict_SetItemString(d, "commithash", date);
Py_XDECREF(date);
if (PyErr_Occurred())
Py_FatalError("can not initialize module warpC");
/* pystdout = PySys_GetObject("stdout"); */
/* PyFile_WriteString("Forthon edition\n",pystdout); */
import_array();
#if PY_MAJOR_VERSION < 3
inittoppy();
initenvpy();
initw3dpy();
initf3dpy();
initwxypy();
initfxypy();
initwrzpy();
initfrzpy();
initcirpy();
initherpy();
initchopy();
initem2dpy();
initem3dpy();
#endif
#if PY_MAJOR_VERSION >= 3
return m;
#else
return;
#endif
}
示例4: Py_NewInterpreter
PyThreadState *
Py_NewInterpreter(void)
{
PyInterpreterState *interp;
PyThreadState *tstate, *save_tstate;
PyObject *bimod, *sysmod;
if (!initialized)
Py_FatalError("Py_NewInterpreter: call Py_Initialize first");
interp = PyInterpreterState_New();
if (interp == NULL)
return NULL;
tstate = PyThreadState_New(interp);
if (tstate == NULL) {
PyInterpreterState_Delete(interp);
return NULL;
}
save_tstate = PyThreadState_Swap(tstate);
/* XXX The following is lax in error checking */
interp->modules = PyDict_New();
bimod = _PyImport_FindExtension("__builtin__", "__builtin__");
if (bimod != NULL) {
interp->builtins = PyModule_GetDict(bimod);
if (interp->builtins == NULL)
goto handle_error;
Py_INCREF(interp->builtins);
}
sysmod = _PyImport_FindExtension("sys", "sys");
if (bimod != NULL && sysmod != NULL) {
interp->sysdict = PyModule_GetDict(sysmod);
if (interp->sysdict == NULL)
goto handle_error;
Py_INCREF(interp->sysdict);
PySys_SetPath(Py_GetPath());
PyDict_SetItemString(interp->sysdict, "modules",
interp->modules);
_PyImportHooks_Init();
initmain();
if (!Py_NoSiteFlag)
initsite();
}
if (!PyErr_Occurred())
return tstate;
handle_error:
/* Oops, it didn't work. Undo it all. */
PyErr_Print();
PyThreadState_Clear(tstate);
PyThreadState_Swap(save_tstate);
PyThreadState_Delete(tstate);
PyInterpreterState_Delete(interp);
return NULL;
}
示例5: PyModule_Create2
PyObject *
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
{
PyObject *d, *v, *n;
PyMethodDef *ml;
const char* name;
PyModuleObject *m;
PyInterpreterState *interp = PyThreadState_Get()->interp;
if (interp->modules == NULL)
Py_FatalError("Python import machinery not initialized");
if (PyType_Ready(&moduledef_type) < 0)
return NULL;
if (module->m_base.m_index == 0) {
max_module_number++;
Py_REFCNT(module) = 1;
Py_TYPE(module) = &moduledef_type;
module->m_base.m_index = max_module_number;
}
name = module->m_name;
if (module_api_version != PYTHON_API_VERSION && module_api_version != PYTHON_ABI_VERSION) {
int err;
err = PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
"Python C API version mismatch for module %.100s: "
"This Python has API version %d, module %.100s has version %d.",
name,
PYTHON_API_VERSION, name, module_api_version);
if (err)
return NULL;
}
/* Make sure name is fully qualified.
This is a bit of a hack: when the shared library is loaded,
the module name is "package.module", but the module calls
PyModule_Create*() with just "module" for the name. The shared
library loader squirrels away the true name of the module in
_Py_PackageContext, and PyModule_Create*() will substitute this
(if the name actually matches).
*/
if (_Py_PackageContext != NULL) {
char *p = strrchr(_Py_PackageContext, '.');
if (p != NULL && strcmp(module->m_name, p+1) == 0) {
name = _Py_PackageContext;
_Py_PackageContext = NULL;
}
}
if ((m = (PyModuleObject*)PyModule_New(name)) == NULL)
return NULL;
if (module->m_size > 0) {
m->md_state = PyMem_MALLOC(module->m_size);
if (!m->md_state) {
PyErr_NoMemory();
Py_DECREF(m);
return NULL;
}
memset(m->md_state, 0, module->m_size);
}
d = PyModule_GetDict((PyObject*)m);
if (module->m_methods != NULL) {
n = PyUnicode_FromString(name);
if (n == NULL) {
Py_DECREF(m);
return NULL;
}
for (ml = module->m_methods; ml->ml_name != NULL; ml++) {
if ((ml->ml_flags & METH_CLASS) ||
(ml->ml_flags & METH_STATIC)) {
PyErr_SetString(PyExc_ValueError,
"module functions cannot set"
" METH_CLASS or METH_STATIC");
Py_DECREF(n);
Py_DECREF(m);
return NULL;
}
v = PyCFunction_NewEx(ml, (PyObject*)m, n);
if (v == NULL) {
Py_DECREF(n);
Py_DECREF(m);
return NULL;
}
if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
Py_DECREF(v);
Py_DECREF(n);
Py_DECREF(m);
return NULL;
}
Py_DECREF(v);
}
Py_DECREF(n);
}
if (module->m_doc != NULL) {
v = PyUnicode_FromString(module->m_doc);
if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {
Py_XDECREF(v);
Py_DECREF(m);
return NULL;
}
Py_DECREF(v);
}
//.........这里部分代码省略.........
示例6: Py_InitializeEx
void
Py_InitializeEx(int install_sigs)
{
PyInterpreterState *interp;
PyThreadState *tstate;
PyObject *bimod, *sysmod;
char *p;
#if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
char *codeset;
char *saved_locale;
PyObject *sys_stream, *sys_isatty;
#endif
extern void _Py_ReadyTypes(void);
if (initialized)
return;
initialized = 1;
if ((p = Py_GETENV("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = add_flag(Py_DebugFlag, p);
if ((p = Py_GETENV("PYTHONVERBOSE")) && *p != '\0')
Py_VerboseFlag = add_flag(Py_VerboseFlag, p);
if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0')
Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p);
interp = PyInterpreterState_New();
if (interp == NULL)
Py_FatalError("Py_Initialize: can't make first interpreter");
tstate = PyThreadState_New(interp);
if (tstate == NULL)
Py_FatalError("Py_Initialize: can't make first thread");
(void) PyThreadState_Swap(tstate);
_Py_ReadyTypes();
if (!_PyFrame_Init())
Py_FatalError("Py_Initialize: can't init frames");
if (!_PyInt_Init())
Py_FatalError("Py_Initialize: can't init ints");
_PyFloat_Init();
interp->modules = PyDict_New();
if (interp->modules == NULL)
Py_FatalError("Py_Initialize: can't make modules dictionary");
#ifdef Py_USING_UNICODE
/* Init Unicode implementation; relies on the codec registry */
_PyUnicode_Init();
#endif
bimod = _PyBuiltin_Init();
if (bimod == NULL)
Py_FatalError("Py_Initialize: can't initialize __builtin__");
interp->builtins = PyModule_GetDict(bimod);
if (interp->builtins == NULL)
Py_FatalError("Py_Initialize: can't initialize builtins dict");
Py_INCREF(interp->builtins);
sysmod = _PySys_Init();
if (sysmod == NULL)
Py_FatalError("Py_Initialize: can't initialize sys");
interp->sysdict = PyModule_GetDict(sysmod);
if (interp->sysdict == NULL)
Py_FatalError("Py_Initialize: can't initialize sys dict");
Py_INCREF(interp->sysdict);
_PyImport_FixupExtension("sys", "sys");
PySys_SetPath(Py_GetPath());
PyDict_SetItemString(interp->sysdict, "modules",
interp->modules);
_PyImport_Init();
/* initialize builtin exceptions */
_PyExc_Init();
_PyImport_FixupExtension("exceptions", "exceptions");
/* phase 2 of builtins */
_PyImport_FixupExtension("__builtin__", "__builtin__");
_PyImportHooks_Init();
if (install_sigs)
initsigs(); /* Signal handling stuff, including initintr() */
initmain(); /* Module __main__ */
if (!Py_NoSiteFlag)
initsite(); /* Module site */
/* auto-thread-state API, if available */
#ifdef WITH_THREAD
_PyGILState_Init(interp, tstate);
#endif /* WITH_THREAD */
warnings_module = PyImport_ImportModule("warnings");
if (!warnings_module)
PyErr_Clear();
//.........这里部分代码省略.........
示例7: GREENLET_NOINLINE
//.........这里部分代码省略.........
return 1;
}
/* start the greenlet */
self->stack_start = NULL;
self->stack_stop = (char*) mark;
if (ts_current->stack_start == NULL) {
/* ts_current is dying */
self->stack_prev = ts_current->stack_prev;
}
else {
self->stack_prev = ts_current;
}
self->top_frame = NULL;
self->exc_type = NULL;
self->exc_value = NULL;
self->exc_traceback = NULL;
self->recursion_depth = PyThreadState_GET()->recursion_depth;
/* restore arguments in case they are clobbered */
ts_target = self;
ts_passaround_args = args;
ts_passaround_kwargs = kwargs;
/* perform the initial switch */
err = g_switchstack();
/* returns twice!
The 1st time with err=1: we are in the new greenlet
The 2nd time with err=0: back in the caller's greenlet
*/
if (err == 1) {
/* in the new greenlet */
PyGreenlet* origin;
#if GREENLET_USE_TRACING
PyObject* tracefunc;
#endif
PyObject* result;
PyGreenlet* parent;
self->stack_start = (char*) 1; /* running */
/* grab origin while we still can */
origin = ts_origin;
ts_origin = NULL;
/* now use run_info to store the statedict */
o = self->run_info;
self->run_info = green_statedict(self->parent);
Py_INCREF(self->run_info);
Py_XDECREF(o);
#if GREENLET_USE_TRACING
if ((tracefunc = PyDict_GetItem(self->run_info, ts_tracekey)) != NULL) {
Py_INCREF(tracefunc);
if (g_calltrace(tracefunc, args ? ts_event_switch : ts_event_throw, origin, self) < 0) {
/* Turn trace errors into switch throws */
Py_CLEAR(kwargs);
Py_CLEAR(args);
}
Py_DECREF(tracefunc);
}
#endif
Py_DECREF(origin);
if (args == NULL) {
/* pending exception */
result = NULL;
} else {
/* call g.run(*args, **kwargs) */
result = PyEval_CallObjectWithKeywords(
run, args, kwargs);
Py_DECREF(args);
Py_XDECREF(kwargs);
}
Py_DECREF(run);
result = g_handle_exit(result);
/* jump back to parent */
self->stack_start = NULL; /* dead */
for (parent = self->parent; parent != NULL; parent = parent->parent) {
result = g_switch(parent, result, NULL);
/* Return here means switch to parent failed,
* in which case we throw *current* exception
* to the next parent in chain.
*/
assert(result == NULL);
}
/* We ran out of parents, cannot continue */
PyErr_WriteUnraisable((PyObject *) self);
Py_FatalError("greenlets cannot continue");
}
/* back in the parent */
if (err < 0) {
/* start failed badly, restore greenlet state */
self->stack_start = NULL;
self->stack_stop = NULL;
self->stack_prev = NULL;
}
return err;
}
示例8: setup_readline
static void
setup_readline(void)
{
#ifdef SAVE_LOCALE
char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
if (!saved_locale)
Py_FatalError("not enough memory to save locale");
#endif
#ifdef __APPLE__
/* the libedit readline emulation resets key bindings etc
* when calling rl_initialize. So call it upfront
*/
if (using_libedit_emulation)
rl_initialize();
/* Detect if libedit's readline emulation uses 0-based
* indexing or 1-based indexing.
*/
add_history("1");
if (history_get(1) == NULL) {
libedit_history_start = 0;
} else {
libedit_history_start = 1;
}
clear_history();
#endif /* __APPLE__ */
using_history();
rl_readline_name = "python";
#if defined(PYOS_OS2) && defined(PYCC_GCC)
/* Allow $if term= in .inputrc to work */
rl_terminal_name = getenv("TERM");
#endif
/* Force rebind of TAB to insert-tab */
rl_bind_key('\t', rl_insert);
/* Bind both ESC-TAB and ESC-ESC to the completion function */
rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
/* Set our hook functions */
rl_startup_hook = on_startup_hook;
#ifdef HAVE_RL_PRE_INPUT_HOOK
rl_pre_input_hook = on_pre_input_hook;
#endif
/* Set our completion function */
rl_attempted_completion_function = flex_complete;
/* Set Python word break characters */
completer_word_break_characters =
rl_completer_word_break_characters =
strdup(" \t\n`[email protected]#$%^&*()-=+[{]}\\|;:'\",<>/?");
/* All nonalphanums except '.' */
begidx = PyGC_RegisterStaticConstant(PyInt_FromLong(0L));
endidx = PyGC_RegisterStaticConstant(PyInt_FromLong(0L));
PyGC_RegisterStaticConstantLocation(&completer);
/* Initialize (allows .inputrc to override)
*
* XXX: A bug in the readline-2.2 library causes a memory leak
* inside this function. Nothing we can do about it.
*/
#ifdef __APPLE__
if (using_libedit_emulation)
rl_read_init_file(NULL);
else
#endif /* __APPLE__ */
rl_initialize();
RESTORE_LOCALE(saved_locale)
}
示例9: read_pth_file
static int
read_pth_file(const wchar_t *path, wchar_t *prefix, int *isolated, int *nosite)
{
FILE *sp_file = _Py_wfopen(path, L"r");
if (sp_file == NULL)
return -1;
wcscpy_s(prefix, MAXPATHLEN+1, path);
reduce(prefix);
*isolated = 1;
*nosite = 1;
size_t bufsiz = MAXPATHLEN;
size_t prefixlen = wcslen(prefix);
wchar_t *buf = (wchar_t*)PyMem_RawMalloc(bufsiz * sizeof(wchar_t));
buf[0] = '\0';
while (!feof(sp_file)) {
char line[MAXPATHLEN + 1];
char *p = fgets(line, MAXPATHLEN + 1, sp_file);
if (!p)
break;
if (*p == '\0' || *p == '#')
continue;
while (*++p) {
if (*p == '\r' || *p == '\n') {
*p = '\0';
break;
}
}
if (strcmp(line, "import site") == 0) {
*nosite = 0;
continue;
} else if (strncmp(line, "import ", 7) == 0) {
Py_FatalError("only 'import site' is supported in ._pth file");
}
DWORD wn = MultiByteToWideChar(CP_UTF8, 0, line, -1, NULL, 0);
wchar_t *wline = (wchar_t*)PyMem_RawMalloc((wn + 1) * sizeof(wchar_t));
wn = MultiByteToWideChar(CP_UTF8, 0, line, -1, wline, wn + 1);
wline[wn] = '\0';
size_t usedsiz = wcslen(buf);
while (usedsiz + wn + prefixlen + 4 > bufsiz) {
bufsiz += MAXPATHLEN;
buf = (wchar_t*)PyMem_RawRealloc(buf, (bufsiz + 1) * sizeof(wchar_t));
if (!buf) {
PyMem_RawFree(wline);
goto error;
}
}
if (usedsiz) {
wcscat_s(buf, bufsiz, L";");
usedsiz += 1;
}
errno_t result;
_Py_BEGIN_SUPPRESS_IPH
result = wcscat_s(buf, bufsiz, prefix);
_Py_END_SUPPRESS_IPH
if (result == EINVAL) {
Py_FatalError("invalid argument during ._pth processing");
} else if (result == ERANGE) {
Py_FatalError("buffer overflow during ._pth processing");
}
wchar_t *b = &buf[usedsiz];
join(b, wline);
PyMem_RawFree(wline);
}
module_search_path = buf;
fclose(sp_file);
return 0;
error:
PyMem_RawFree(buf);
fclose(sp_file);
return -1;
}
示例10: calculate_path
//.........这里部分代码省略.........
bufsz *= wcslen(pythonhome);
}
else
bufsz = 0;
bufsz += wcslen(PYTHONPATH) + 1;
bufsz += wcslen(argv0_path) + 1;
if (userpath)
bufsz += wcslen(userpath) + 1;
if (machinepath)
bufsz += wcslen(machinepath) + 1;
bufsz += wcslen(zip_path) + 1;
if (envpath != NULL)
bufsz += wcslen(envpath) + 1;
module_search_path = buf = PyMem_RawMalloc(bufsz*sizeof(wchar_t));
if (buf == NULL) {
/* We can't exit, so print a warning and limp along */
fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
if (envpath) {
fprintf(stderr, "Using environment $PYTHONPATH.\n");
module_search_path = envpath;
}
else {
fprintf(stderr, "Using default static path.\n");
module_search_path = PYTHONPATH;
}
PyMem_RawFree(machinepath);
PyMem_RawFree(userpath);
return;
}
if (envpath) {
if (wcscpy_s(buf, bufsz - (buf - module_search_path), envpath))
Py_FatalError("buffer overflow in getpathp.c's calculate_path()");
buf = wcschr(buf, L'\0');
*buf++ = DELIM;
}
if (zip_path[0]) {
if (wcscpy_s(buf, bufsz - (buf - module_search_path), zip_path))
Py_FatalError("buffer overflow in getpathp.c's calculate_path()");
buf = wcschr(buf, L'\0');
*buf++ = DELIM;
}
if (userpath) {
if (wcscpy_s(buf, bufsz - (buf - module_search_path), userpath))
Py_FatalError("buffer overflow in getpathp.c's calculate_path()");
buf = wcschr(buf, L'\0');
*buf++ = DELIM;
PyMem_RawFree(userpath);
}
if (machinepath) {
if (wcscpy_s(buf, bufsz - (buf - module_search_path), machinepath))
Py_FatalError("buffer overflow in getpathp.c's calculate_path()");
buf = wcschr(buf, L'\0');
*buf++ = DELIM;
PyMem_RawFree(machinepath);
}
if (pythonhome == NULL) {
if (!skipdefault) {
if (wcscpy_s(buf, bufsz - (buf - module_search_path), PYTHONPATH))
Py_FatalError("buffer overflow in getpathp.c's calculate_path()");
buf = wcschr(buf, L'\0');
*buf++ = DELIM;
}
} else {
wchar_t *p = PYTHONPATH;
示例11: PyObject_HEAD_INIT
/* Implementation of 'ext.sparsehash' */
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyMethodDef __pyx_methods[] = {
{0, 0, 0, 0}
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
#if PY_VERSION_HEX < 0x03020000
{ PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
#else
PyModuleDef_HEAD_INIT,
#endif
__Pyx_NAMESTR("sparsehash"),
0, /* m_doc */
-1, /* m_size */
__pyx_methods /* m_methods */,
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL /* m_free */
};
#endif
static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
{&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
return 0;
}
static int __Pyx_InitCachedConstants(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_InitGlobals(void) {
if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
return 0;
__pyx_L1_error:;
return -1;
}
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initsparsehash(void); /*proto*/
PyMODINIT_FUNC initsparsehash(void)
#else
PyMODINIT_FUNC PyInit_sparsehash(void); /*proto*/
PyMODINIT_FUNC PyInit_sparsehash(void)
#endif
{
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannyDeclarations
#if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
PyErr_Clear();
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
if (!__Pyx_RefNanny)
Py_FatalError("failed to import 'refnanny' module");
}
#endif
__Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_sparsehash(void)", 0);
if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#ifdef __Pyx_CyFunction_USED
if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
#ifdef __Pyx_FusedFunction_USED
if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
#ifdef __Pyx_Generator_USED
if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
/*--- Library function declarations ---*/
/*--- Threads initialization code ---*/
#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
#ifdef WITH_THREAD /* Python build with threading support? */
PyEval_InitThreads();
#endif
#endif
/*--- Module creation code ---*/
#if PY_MAJOR_VERSION < 3
__pyx_m = Py_InitModule4(__Pyx_NAMESTR("sparsehash"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
#else
__pyx_m = PyModule_Create(&__pyx_moduledef);
#endif
if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#if PY_MAJOR_VERSION >= 3
{
PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
//.........这里部分代码省略.........
示例12: setup_readline
static void
setup_readline(readlinestate *mod_state)
{
#ifdef SAVE_LOCALE
char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
if (!saved_locale)
Py_FatalError("not enough memory to save locale");
#endif
#ifdef __APPLE__
/* the libedit readline emulation resets key bindings etc
* when calling rl_initialize. So call it upfront
*/
if (using_libedit_emulation)
rl_initialize();
/* Detect if libedit's readline emulation uses 0-based
* indexing or 1-based indexing.
*/
add_history("1");
if (history_get(1) == NULL) {
libedit_history_start = 0;
} else {
libedit_history_start = 1;
}
clear_history();
#endif /* __APPLE__ */
using_history();
rl_readline_name = "python";
/* Force rebind of TAB to insert-tab */
rl_bind_key('\t', rl_insert);
/* Bind both ESC-TAB and ESC-ESC to the completion function */
rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
/* Set our hook functions */
rl_startup_hook = on_startup_hook;
#ifdef HAVE_RL_PRE_INPUT_HOOK
rl_pre_input_hook = on_pre_input_hook;
#endif
/* Set our completion function */
rl_attempted_completion_function = flex_complete;
/* Set Python word break characters */
completer_word_break_characters =
rl_completer_word_break_characters =
strdup(" \t\n`[email protected]#$%^&*()-=+[{]}\\|;:'\",<>/?");
/* All nonalphanums except '.' */
mod_state->begidx = PyLong_FromLong(0L);
mod_state->endidx = PyLong_FromLong(0L);
#ifndef __APPLE__
if (!isatty(STDOUT_FILENO)) {
/* Issue #19884: stdout is no a terminal. Disable meta modifier
keys to not write the ANSI sequence "\033[1034h" into stdout. On
terminals supporting 8 bit characters like TERM=xterm-256color
(which is now the default Fedora since Fedora 18), the meta key is
used to enable support of 8 bit characters (ANSI sequence
"\033[1034h").
With libedit, this call makes readline() crash. */
rl_variable_bind ("enable-meta-key", "off");
}
#endif
/* Initialize (allows .inputrc to override)
*
* XXX: A bug in the readline-2.2 library causes a memory leak
* inside this function. Nothing we can do about it.
*/
#ifdef __APPLE__
if (using_libedit_emulation)
rl_read_init_file(NULL);
else
#endif /* __APPLE__ */
rl_initialize();
RESTORE_LOCALE(saved_locale)
}
示例13: makedfa
static void
makedfa(nfagrammar *gr, nfa *nf, dfa *d)
{
int nbits = nf->nf_nstates;
bitset ss;
int xx_nstates;
ss_state *xx_state, *yy;
ss_arc *zz;
int istate, jstate, iarc, jarc, ibit;
nfastate *st;
nfaarc *ar;
ss = newbitset(nbits);
addclosure(ss, nf, nf->nf_start);
xx_state = (ss_state *)PyObject_MALLOC(sizeof(ss_state));
if (xx_state == NULL)
Py_FatalError("no mem for xx_state in makedfa");
xx_nstates = 1;
yy = &xx_state[0];
yy->ss_ss = ss;
yy->ss_narcs = 0;
yy->ss_arc = NULL;
yy->ss_deleted = 0;
yy->ss_finish = testbit(ss, nf->nf_finish);
if (yy->ss_finish)
printf("Error: nonterminal '%s' may produce empty.\n",
nf->nf_name);
/* This algorithm is from a book written before
the invention of structured programming... */
/* For each unmarked state... */
for (istate = 0; istate < xx_nstates; ++istate) {
size_t size;
yy = &xx_state[istate];
ss = yy->ss_ss;
/* For all its states... */
for (ibit = 0; ibit < nf->nf_nstates; ++ibit) {
if (!testbit(ss, ibit))
continue;
st = &nf->nf_state[ibit];
/* For all non-empty arcs from this state... */
for (iarc = 0; iarc < st->st_narcs; iarc++) {
ar = &st->st_arc[iarc];
if (ar->ar_label == EMPTY)
continue;
/* Look up in list of arcs from this state */
for (jarc = 0; jarc < yy->ss_narcs; ++jarc) {
zz = &yy->ss_arc[jarc];
if (ar->ar_label == zz->sa_label)
goto found;
}
/* Add new arc for this state */
size = sizeof(ss_arc) * (yy->ss_narcs + 1);
yy->ss_arc = (ss_arc *)PyObject_REALLOC(
yy->ss_arc, size);
if (yy->ss_arc == NULL)
Py_FatalError("out of mem");
zz = &yy->ss_arc[yy->ss_narcs++];
zz->sa_label = ar->ar_label;
zz->sa_bitset = newbitset(nbits);
zz->sa_arrow = -1;
found: ;
/* Add destination */
addclosure(zz->sa_bitset, nf, ar->ar_arrow);
}
}
/* Now look up all the arrow states */
for (jarc = 0; jarc < xx_state[istate].ss_narcs; jarc++) {
zz = &xx_state[istate].ss_arc[jarc];
for (jstate = 0; jstate < xx_nstates; jstate++) {
if (samebitset(zz->sa_bitset,
xx_state[jstate].ss_ss, nbits)) {
zz->sa_arrow = jstate;
goto done;
}
}
size = sizeof(ss_state) * (xx_nstates + 1);
xx_state = (ss_state *)PyObject_REALLOC(xx_state,
size);
if (xx_state == NULL)
Py_FatalError("out of mem");
zz->sa_arrow = xx_nstates;
yy = &xx_state[xx_nstates++];
yy->ss_ss = zz->sa_bitset;
yy->ss_narcs = 0;
yy->ss_arc = NULL;
yy->ss_deleted = 0;
yy->ss_finish = testbit(yy->ss_ss, nf->nf_finish);
done: ;
}
}
if (Py_DebugFlag)
printssdfa(xx_nstates, xx_state, nbits, &gr->gr_ll,
"before minimizing");
simplify(xx_nstates, xx_state);
if (Py_DebugFlag)
//.........这里部分代码省略.........