本文整理汇总了C++中PyCFunction_Check函数的典型用法代码示例。如果您正苦于以下问题:C++ PyCFunction_Check函数的具体用法?C++ PyCFunction_Check怎么用?C++ PyCFunction_Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyCFunction_Check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: meth_richcompare
static PyObject *
meth_richcompare(PyObject *self, PyObject *other, int op)
{
PyCFunctionObject *a, *b;
PyObject *res;
int eq;
if (op != Py_EQ && op != Py_NE) {
/* Py3K warning if comparison isn't == or !=. */
if (PyErr_WarnPy3k("builtin_function_or_method order "
"comparisons not supported in 3.x", 1) < 0) {
return NULL;
}
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
else if (!PyCFunction_Check(self) || !PyCFunction_Check(other)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
a = (PyCFunctionObject *)self;
b = (PyCFunctionObject *)other;
eq = a->m_self == b->m_self;
if (eq)
eq = a->m_ml->ml_meth == b->m_ml->ml_meth;
if (op == Py_EQ)
res = eq ? Py_True : Py_False;
else
res = eq ? Py_False : Py_True;
Py_INCREF(res);
return res;
}
示例2: meth_richcompare
static PyObject *
meth_richcompare(PyObject *self, PyObject *other, int op)
{
PyCFunctionObject *a, *b;
PyObject *res;
int eq;
if ((op != Py_EQ && op != Py_NE) ||
!PyCFunction_Check(self) ||
!PyCFunction_Check(other))
{
Py_RETURN_NOTIMPLEMENTED;
}
a = (PyCFunctionObject *)self;
b = (PyCFunctionObject *)other;
eq = a->m_self == b->m_self;
if (eq)
eq = a->m_ml->ml_meth == b->m_ml->ml_meth;
if (op == Py_EQ)
res = eq ? Py_True : Py_False;
else
res = eq ? Py_False : Py_True;
Py_INCREF(res);
return res;
}
示例3: getReceiver
static bool getReceiver(QObject *source, PyObject* callback, QObject** receiver, PyObject** self)
{
bool forceGlobalReceiver = false;
if (PyMethod_Check(callback)) {
*self = PyMethod_GET_SELF(callback);
if (Shiboken::Converter<QObject*>::checkType(*self))
*receiver = Shiboken::Converter<QObject*>::toCpp(*self);
forceGlobalReceiver = isDecorator(callback, *self);
} else if (PyCFunction_Check(callback)) {
*self = PyCFunction_GET_SELF(callback);
if (*self && Shiboken::Converter<QObject*>::checkType(*self))
*receiver = Shiboken::Converter<QObject*>::toCpp(*self);
} else if (PyCallable_Check(callback)) {
// Ok, just a callable object
*receiver = 0;
*self = 0;
}
bool usingGlobalReceiver = !*receiver || forceGlobalReceiver;
if (usingGlobalReceiver) {
PySide::SignalManager& signalManager = PySide::SignalManager::instance();
*receiver = signalManager.globalReceiver(source, callback);
}
return usingGlobalReceiver;
}
示例4: handler_Whitespace
static ExpatStatus
handler_Whitespace(void *arg, PyObject *data)
{
PyObject *self = (PyObject *)arg;
PyObject *handler, *args, *result;
handler = PyObject_GetAttrString(self, "whitespace");
if (handler == NULL)
return EXPAT_STATUS_ERROR;
/* if the method was not overriden, save some cycles and just return */
if (PyCFunction_Check(handler) &&
PyCFunction_GET_FUNCTION(handler) == handler_noop) {
Py_DECREF(handler);
return EXPAT_STATUS_OK;
}
args = PyTuple_Pack(1, data);
if (args == NULL) {
Py_DECREF(handler);
return EXPAT_STATUS_ERROR;
}
result = PyTrace_CallObject(getcode(Whitespace), handler, args);
Py_DECREF(args);
if (result == NULL) {
Py_DECREF(handler);
return EXPAT_STATUS_ERROR;
}
Py_DECREF(result);
Py_DECREF(handler);
return EXPAT_STATUS_OK;
}
示例5: handler_EndElement
static ExpatStatus
handler_EndElement(void *arg, ExpatName *name)
{
PyObject *self = (PyObject *)arg;
PyObject *handler, *args, *result;
handler = PyObject_GetAttrString(self, "end_element");
if (handler == NULL)
return EXPAT_STATUS_ERROR;
/* if the method was not overriden, save some cycles and just return */
if (PyCFunction_Check(handler) &&
PyCFunction_GET_FUNCTION(handler) == handler_noop) {
Py_DECREF(handler);
return EXPAT_STATUS_OK;
}
args = Py_BuildValue("(OO)O", name->namespaceURI, name->localName,
name->qualifiedName);
if (args == NULL) {
Py_DECREF(handler);
return EXPAT_STATUS_ERROR;
}
result = PyTrace_CallObject(getcode(EndElement), handler, args);
Py_DECREF(args);
if (result == NULL) {
Py_DECREF(handler);
return EXPAT_STATUS_ERROR;
}
Py_DECREF(result);
Py_DECREF(handler);
return EXPAT_STATUS_OK;
}
示例6: handler_StartElement
static ExpatStatus
handler_StartElement(void *arg, ExpatName *name, ExpatAttribute atts[],
size_t natts)
{
HandlerObject *self = (HandlerObject *)arg;
PyObject *handler, *args, *result;
handler = PyObject_GetAttrString((PyObject *)self, "start_element");
if (handler == NULL)
return EXPAT_STATUS_ERROR;
/* if the method was not overriden, save some cycles and just return */
if (PyCFunction_Check(handler) &&
PyCFunction_GET_FUNCTION(handler) == handler_noop) {
Py_DECREF(handler);
return EXPAT_STATUS_OK;
}
args = Py_BuildValue("(OO)OON", name->namespaceURI, name->localName,
name->qualifiedName, self->new_namespaces,
Attributes_New(atts, natts));
if (args == NULL) {
PyDict_CLEAR(self->new_namespaces);
Py_DECREF(handler);
return EXPAT_STATUS_ERROR;
}
result = PyTrace_CallObject(getcode(StartElement), handler, args);
PyDict_CLEAR(self->new_namespaces);
Py_DECREF(args);
Py_DECREF(handler);
if (result == NULL)
return EXPAT_STATUS_ERROR;
Py_DECREF(result);
return EXPAT_STATUS_OK;
}
示例7: handler_StartDocument
static ExpatStatus
handler_StartDocument(void *arg)
{
PyObject *self = (PyObject *)arg;
PyObject *handler, *args, *result;
PyObject_Print(self, stdout, 0);
fflush(stdout);
handler = PyObject_GetAttrString(self, "start_document");
if (handler == NULL)
return EXPAT_STATUS_ERROR;
/* if the method was not overriden, save some cycles and just return */
if (PyCFunction_Check(handler) &&
PyCFunction_GET_FUNCTION(handler) == handler_noop) {
Py_DECREF(handler);
return EXPAT_STATUS_OK;
}
args = PyTuple_New(0);
if (args == NULL) {
Py_DECREF(handler);
return EXPAT_STATUS_ERROR;
}
result = PyTrace_CallObject(getcode(StartDocument), handler, args);
Py_DECREF(args);
if (result == NULL) {
Py_DECREF(handler);
return EXPAT_STATUS_ERROR;
}
Py_DECREF(result);
Py_DECREF(handler);
return EXPAT_STATUS_OK;
}
示例8: call_cfunc
/* A custom, fast, inlinable version of PyCFunction_Call() */
static PyObject *
call_cfunc(DispatcherObject *self, PyObject *cfunc, PyObject *args, PyObject *kws, PyObject *locals)
{
PyCFunctionWithKeywords fn;
PyThreadState *tstate;
assert(PyCFunction_Check(cfunc));
assert(PyCFunction_GET_FLAGS(cfunc) == METH_VARARGS | METH_KEYWORDS);
fn = (PyCFunctionWithKeywords) PyCFunction_GET_FUNCTION(cfunc);
tstate = PyThreadState_GET();
if (tstate->use_tracing && tstate->c_profilefunc)
{
/*
* The following code requires some explaining:
*
* We want the jit-compiled function to be visible to the profiler, so we
* need to synthesize a frame for it.
* The PyFrame_New() constructor doesn't do anything with the 'locals' value if the 'code's
* 'CO_NEWLOCALS' flag is set (which is always the case nowadays).
* So, to get local variables into the frame, we have to manually set the 'f_locals'
* member, then call `PyFrame_LocalsToFast`, where a subsequent call to the `frame.f_locals`
* property (by virtue of the `frame_getlocals` function in frameobject.c) will find them.
*/
PyCodeObject *code = (PyCodeObject*)PyObject_GetAttrString((PyObject*)self, "__code__");
PyObject *globals = PyDict_New();
PyObject *builtins = PyEval_GetBuiltins();
PyFrameObject *frame = NULL;
PyObject *result = NULL;
if (!code) {
PyErr_Format(PyExc_RuntimeError, "No __code__ attribute found.");
goto error;
}
/* Populate builtins, which is required by some JITted functions */
if (PyDict_SetItemString(globals, "__builtins__", builtins)) {
goto error;
}
frame = PyFrame_New(tstate, code, globals, NULL);
if (frame == NULL) {
goto error;
}
/* Populate the 'fast locals' in `frame` */
Py_XDECREF(frame->f_locals);
frame->f_locals = locals;
Py_XINCREF(frame->f_locals);
PyFrame_LocalsToFast(frame, 0);
tstate->frame = frame;
C_TRACE(result, fn(PyCFunction_GET_SELF(cfunc), args, kws));
tstate->frame = frame->f_back;
error:
Py_XDECREF(frame);
Py_XDECREF(globals);
Py_XDECREF(code);
return result;
}
else
return fn(PyCFunction_GET_SELF(cfunc), args, kws);
}
示例9: PyCFunction_GetFlags
int
PyCFunction_GetFlags(PyObject *op)
{
if (!PyCFunction_Check(op)) {
PyErr_BadInternalCall();
return -1;
}
return PyCFunction_GET_FLAGS(op);
}
示例10: PyCFunction_GetSelf
PyObject *
PyCFunction_GetSelf(PyObject *op)
{
if (!PyCFunction_Check(op)) {
PyErr_BadInternalCall();
return NULL;
}
return PyCFunction_GET_SELF(op);
}
示例11: PyCFunction_GetFlags
int
PyCFunction_GetFlags(PyObject *op)
{
if (!PyCFunction_Check(op)) {
PyErr_BadInternalCall();
return -1;
}
return ((PyCFunctionObject *)op) -> m_ml -> ml_flags;
}
示例12: PyCFunction_GetFunction
PyCFunction
PyCFunction_GetFunction(PyObject *op)
{
if (!PyCFunction_Check(op)) {
PyErr_BadInternalCall();
return NULL;
}
return PyCFunction_GET_FUNCTION(op);
}
示例13: PyCFunction_GetSelf
PyObject *
PyCFunction_GetSelf(PyObject *op)
{
if (!PyCFunction_Check(op)) {
PyErr_BadInternalCall();
return NULL;
}
return ((PyCFunctionObject *)op) -> m_self;
}
示例14: PyCFunction_GetFunction
PyCFunction
PyCFunction_GetFunction(PyObject *op)
{
if (!PyCFunction_Check(op)) {
PyErr_BadInternalCall();
return NULL;
}
return ((PyCFunctionObject *)op) -> m_ml -> ml_meth;
}
示例15: py_convert
int py_convert(lua_State *L, PyObject *o, int withnone)
{
int ret = 0;
if (o == Py_None) {
if (withnone) {
lua_pushliteral(L, "Py_None");
lua_rawget(L, LUA_REGISTRYINDEX);
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
luaL_error(L, "lost none from registry");
}
} else {
/* Not really needed, but this way we may check
* for errors with ret == 0. */
lua_pushnil(L);
ret = 1;
}
} else if (o == Py_True) {
lua_pushboolean(L, 1);
ret = 1;
} else if (o == Py_False) {
lua_pushboolean(L, 0);
ret = 1;
#if PY_MAJOR_VERSION >= 3
} else if (PyUnicode_Check(o)) {
Py_ssize_t len;
char *s = PyUnicode_AsUTF8AndSize(o, &len);
#else
} else if (PyString_Check(o)) {
Py_ssize_t len;
char *s;
PyString_AsStringAndSize(o, &s, &len);
#endif
lua_pushlstring(L, s, len);
ret = 1;
} else if (PyLong_Check(o)) {
lua_pushnumber(L, (lua_Number)PyLong_AsLong(o));
ret = 1;
} else if (PyFloat_Check(o)) {
lua_pushnumber(L, (lua_Number)PyFloat_AsDouble(o));
ret = 1;
} else if (LuaObject_Check(o)) {
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)o)->ref);
ret = 1;
} else {
int asindx = 0;
if (PyDict_Check(o) || PyList_Check(o) || PyTuple_Check(o))
asindx = 1;
ret = py_convert_custom(L, o, asindx);
if (ret && !asindx &&
(PyFunction_Check(o) || PyCFunction_Check(o)))
lua_pushcclosure(L, py_asfunc_call, 1);
}
return ret;
}