当前位置: 首页>>代码示例>>C++>>正文


C++ PyThreadState_GET函数代码示例

本文整理汇总了C++中PyThreadState_GET函数的典型用法代码示例。如果您正苦于以下问题:C++ PyThreadState_GET函数的具体用法?C++ PyThreadState_GET怎么用?C++ PyThreadState_GET使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PyThreadState_GET函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getPythonInterpreterStackTrace

// Python interpreter retrieval routine adapted from
// https://stackoverflow.com/a/8706144
std::string getPythonInterpreterStackTrace() {
  std::stringstream stack_trace;
  AutoGIL gil;
  PyThreadState *tstate = PyThreadState_GET();
  if (NULL != tstate && NULL != tstate->frame) {
    PyFrameObject *frame = tstate->frame;

    while (NULL != frame) {
      int line = PyCode_Addr2Line(frame->f_code, frame->f_lasti);
      std::string filename = THPUtils_unpackString(frame->f_code->co_filename);
      std::string funcname = THPUtils_unpackString(frame->f_code->co_name);
      stack_trace << filename << "(" << line << "): " << funcname << "\n";
      frame = frame->f_back;
    }
  }
  return stack_trace.str();
}
开发者ID:gtgalone,项目名称:pytorch,代码行数:19,代码来源:python_tracer.cpp

示例2: FETCH_ERROR_OCCURRED

// Fetch the current error into object variables.
NUITKA_MAY_BE_UNUSED static void FETCH_ERROR_OCCURRED( PyObject **exception_type, PyObject **exception_value, PyTracebackObject **exception_traceback)
{
    PyThreadState *tstate = PyThreadState_GET();

    *exception_type = tstate->curexc_type;
    *exception_value = tstate->curexc_value;
    *exception_traceback = (PyTracebackObject *)tstate->curexc_traceback;

#if _DEBUG_EXCEPTIONS
    PRINT_STRING("FETCH_ERROR_OCCURRED:\n");
    PRINT_EXCEPTION( tstate->curexc_type,  tstate->curexc_value, tstate->curexc_traceback );
#endif

    tstate->curexc_type = NULL;
    tstate->curexc_value = NULL;
    tstate->curexc_traceback = NULL;
}
开发者ID:justus922,项目名称:Nuitka,代码行数:18,代码来源:exceptions.hpp

示例3: PyThreadState_GET

/* Lookup the error handling callback function registered under the
   name error. As a special case NULL can be passed, in which case
   the error handling callback for strict encoding will be returned. */
PyObject *PyCodec_LookupError(const char *name)
{
    PyObject *handler = NULL;

    PyInterpreterState *interp = PyThreadState_GET()->interp;
    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
        return NULL;

    if (name==NULL)
        name = "strict";
    handler = PyDict_GetItemString(interp->codec_error_registry, name);
    if (!handler)
        PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name);
    else
        Py_INCREF(handler);
    return handler;
}
开发者ID:Cartmanfku,项目名称:cpython,代码行数:20,代码来源:codecs.c

示例4: CHANNEL_SEND_EXCEPTION_HEAD

static CHANNEL_SEND_EXCEPTION_HEAD(impl_channel_send_exception)
{
	STACKLESS_GETARG();
	PyThreadState *ts = PyThreadState_GET();
	PyObject *bomb, *ret = NULL;

	assert(PyChannel_Check(self));
	if (ts->st.main == NULL)
		return PyChannel_SendException_M(self, klass, args);

	bomb = slp_make_bomb(klass, args, "channel.send_exception");
	if (bomb != NULL) {
		ret = generic_channel_action(self, bomb, 1, stackless);
		Py_DECREF(bomb);
	}
	return ret;
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:17,代码来源:channelobject.c

示例5: toPython

    inline void toPython()
    {
        PyErr_Restore( this->exception_type, this->exception_value, (PyObject *)this->exception_tb );

        assert( this->exception_type );

#ifndef __NUITKA_NO_ASSERT__
        PyThreadState *thread_state = PyThreadState_GET();
#endif

        assert( this->exception_type == thread_state->curexc_type );
        assert( thread_state->curexc_type );

        this->exception_type  = NULL;
        this->exception_value = NULL;
        this->exception_tb    = NULL;
    }
开发者ID:linkerlin,项目名称:Nuitka,代码行数:17,代码来源:exceptions.hpp

示例6: _PyStackless_Init

void
_PyStackless_Init(void)
{
	PyObject *dict;
	PyObject *modules;
	char *name = "stackless";
	PySlpModuleObject *m;

	if (init_slpmoduletype())
		return;

	/* record the thread state for thread support */
	slp_initial_tstate = PyThreadState_GET();

	/* Create the module and add the functions */
	slp_module = PyModule_Create(&stacklessmodule);
	if (slp_module == NULL)
		return; /* errors handled by caller */

	modules = PyImport_GetModuleDict();
	if (PyDict_SetItemString(modules, name, slp_module)) {
		Py_DECREF(slp_module);
		return;
	}
	Py_DECREF(slp_module); /* Yes, it still exists, in modules! */

	if (init_prickelpit()) return;

	dict = PyModule_GetDict(slp_module);

#define INSERT(name, object) \
	if (PyDict_SetItemString(dict, name, (PyObject*)object) < 0) return

	INSERT("slpmodule", PySlpModule_TypePtr);
	INSERT("cframe",    &PyCFrame_Type);
	INSERT("cstack",    &PyCStack_Type);
	INSERT("bomb",	    &PyBomb_Type);
	INSERT("tasklet",   &PyTasklet_Type);
	INSERT("channel",   &PyChannel_Type);
	INSERT("stackless", slp_module);

	m = (PySlpModuleObject *) slp_module;
	slpmodule_set__tasklet__(m, &PyTasklet_Type, NULL);
	slpmodule_set__channel__(m, &PyChannel_Type, NULL);
}
开发者ID:d11,项目名称:rts,代码行数:45,代码来源:stacklessmodule.c

示例7: impl_channel_send_throw

static PyObject *
impl_channel_send_throw(PyChannelObject *self, PyObject *exc, PyObject *val, PyObject *tb)
{
    STACKLESS_GETARG();
    PyThreadState *ts = PyThreadState_GET();
    PyObject *bomb, *ret = NULL;

    assert(PyChannel_Check(self));
    if (ts->st.main == NULL)
        return PyChannel_SendThrow_M(self, exc, val, tb);

    bomb = slp_exc_to_bomb(exc, val, tb);
    if (bomb != NULL) {
        ret = generic_channel_action(self, bomb, 1, stackless);
        Py_DECREF(bomb);
    }
    return ret;
}
开发者ID:Whosemario,项目名称:stackless-python,代码行数:18,代码来源:channelobject.c

示例8: __Pyx_ErrRestore

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
开发者ID:Huskyeder,项目名称:cython,代码行数:18,代码来源:Exceptions.c

示例9: PyThreadState_GET

PyObject *GPU_initPython(void)
{
	PyObject *module;
	PyObject *submodule;
	PyObject *sys_modules = PyThreadState_GET()->interp->modules;

	module = PyInit_gpu();

	PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));

	/* gpu.offscreen */
	PyModule_AddObject(module, "offscreen", (submodule = BPyInit_gpu_offscreen()));
	PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
	Py_INCREF(submodule);

	PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module);
	return module;
}
开发者ID:UPBGE,项目名称:blender,代码行数:18,代码来源:gpu.c

示例10: PyState_FindModule

PyObject*
PyState_FindModule(struct PyModuleDef* module)
{
    Py_ssize_t index = module->m_base.m_index;
    PyInterpreterState *state = PyThreadState_GET()->interp;
    PyObject *res;
    if (module->m_slots) {
        return NULL;
    }
    if (index == 0)
        return NULL;
    if (state->modules_by_index == NULL)
        return NULL;
    if (index >= PyList_GET_SIZE(state->modules_by_index))
        return NULL;
    res = PyList_GET_ITEM(state->modules_by_index, index);
    return res==Py_None ? NULL : res;
}
开发者ID:Alkalit,项目名称:cpython,代码行数:18,代码来源:pystate.c

示例11: PyErr_SetExcInfo

void
PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback)
{
    PyObject *oldtype, *oldvalue, *oldtraceback;
    PyThreadState *tstate = PyThreadState_GET();

    oldtype = tstate->exc_type;
    oldvalue = tstate->exc_value;
    oldtraceback = tstate->exc_traceback;

    tstate->exc_type = p_type;
    tstate->exc_value = p_value;
    tstate->exc_traceback = p_traceback;

    Py_XDECREF(oldtype);
    Py_XDECREF(oldvalue);
    Py_XDECREF(oldtraceback);
}
开发者ID:cpcloud,项目名称:cpython,代码行数:18,代码来源:errors.c

示例12: PyCodec_Register

int PyCodec_Register(PyObject *search_function)
{
    PyInterpreterState *interp = PyThreadState_GET()->interp;
    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
        goto onError;
    if (search_function == NULL) {
        PyErr_BadArgument();
        goto onError;
    }
    if (!PyCallable_Check(search_function)) {
        PyErr_SetString(PyExc_TypeError, "argument must be callable");
        goto onError;
    }
    return PyList_Append(interp->codec_search_path, search_function);

 onError:
    return -1;
}
开发者ID:0xcc,项目名称:python-read,代码行数:18,代码来源:codecs.c

示例13: _PyState_AddModule

int
_PyState_AddModule(PyObject* module, struct PyModuleDef* def)
{
    PyInterpreterState *state = PyThreadState_GET()->interp;
    if (!def)
        return -1;
    if (!state->modules_by_index) {
        state->modules_by_index = PyList_New(0);
        if (!state->modules_by_index)
            return -1;
    }
    while(PyList_GET_SIZE(state->modules_by_index) <= def->m_base.m_index)
        if (PyList_Append(state->modules_by_index, Py_None) < 0)
            return -1;
    Py_INCREF(module);
    return PyList_SetItem(state->modules_by_index,
                          def->m_base.m_index, module);
}
开发者ID:packages,项目名称:python,代码行数:18,代码来源:pystate.c

示例14: DEBUG

//=============================================================================
// METHOD    : SPELLwsWarmStartImpl::fixState()
//=============================================================================
PyFrameObject* SPELLwsWarmStartImpl::fixState()
{
	DEBUG("[WS] Fixing state ==============================================");

	// Synchronize so that nothing can be done while saving
	SPELLmonitor m(m_lock);

	// Get the head interpreter state
	PyInterpreterState* istate = PyInterpreterState_Head();

	// Get the current thread state
	PyThreadState* oldState = PyThreadState_GET();
	DEBUG("[WS] Old state: " + PSTR(oldState));
	DEBUG("[WS] Interpreter head: " + PSTR(istate->tstate_head));
	DEBUG("[WS] Interpreter next: " + PSTR(istate->next));
	DEBUG("[WS] State recursion depth: " + ISTR(oldState->recursion_depth));
	DEBUG("[WS] State next: " + PSTR(oldState->next));

	// Create a fresh thread state
	PyThreadState* newState = PyThreadState_New(istate);
	istate->tstate_head = newState;

	newState->recursion_depth = oldState->recursion_depth;
	newState->tracing = oldState->tracing;
	newState->use_tracing = oldState->use_tracing;
	newState->tick_counter = oldState->tick_counter;
	newState->gilstate_counter = oldState->gilstate_counter;
	newState->dict = PyDict_Copy(oldState->dict);

	FrameList::iterator it;
	unsigned int frameCount = m_frames.size();
	DEBUG("[WS] Total frames to fix " + ISTR(frameCount));
	m_topFrame = NULL;
	for( unsigned int index = 0; index < frameCount; index++)
	{
		bool isHead = (index == (frameCount-1));
		DEBUG("[WS] Fix state on frame index " + ISTR(index) + " frame=" + PYCREPR(m_frames[index]));
		m_topFrame = m_frames[index];
		m_topFrame->fixState(newState, isHead);
	}
	DEBUG("[WS] State fixed ===============================================");
	PyErr_Clear();
	return m_topFrame->getFrameObject();
}
开发者ID:unnch,项目名称:spell-sat,代码行数:47,代码来源:SPELLwsWarmStartImpl.C

示例15: __Pyx_GetException

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
    if (unlikely(tstate->curexc_type))
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
        goto bad;
    #endif
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
    Py_INCREF(local_type);
    Py_INCREF(local_value);
    Py_INCREF(local_tb);
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    /* Make sure tstate is in a consistent state when we XDECREF
       these objects (XDECREF may run arbitrary code). */
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}
开发者ID:dynamicgl,项目名称:CythonCTypesBackend,代码行数:44,代码来源:Exceptions.c


注:本文中的PyThreadState_GET函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。