• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyCFunction_Check函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了PyCFunction_Check函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:0xcc,项目名称:python-read,代码行数:33,代码来源:methodobject.c


示例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;
}
开发者ID:LesyaMazurevich,项目名称:python-1,代码行数:25,代码来源:methodobject.c


示例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;
}
开发者ID:renatofilho,项目名称:PySide,代码行数:26,代码来源:qobject_connect.cpp


示例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;
}
开发者ID:abed-hawa,项目名称:amara,代码行数:32,代码来源:handler.c


示例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;
}
开发者ID:abed-hawa,项目名称:amara,代码行数:33,代码来源:handler.c


示例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;
}
开发者ID:abed-hawa,项目名称:amara,代码行数:35,代码来源:handler.c


示例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;
}
开发者ID:abed-hawa,项目名称:amara,代码行数:35,代码来源:handler.c


示例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);
}
开发者ID:esc,项目名称:numba,代码行数:59,代码来源:_dispatcher.c


示例9: PyCFunction_GetFlags

int
PyCFunction_GetFlags(PyObject *op)
{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return PyCFunction_GET_FLAGS(op);
}
开发者ID:LesyaMazurevich,项目名称:python-1,代码行数:9,代码来源:methodobject.c


示例10: PyCFunction_GetSelf

PyObject *
PyCFunction_GetSelf(PyObject *op)
{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return PyCFunction_GET_SELF(op);
}
开发者ID:LesyaMazurevich,项目名称:python-1,代码行数:9,代码来源:methodobject.c


示例11: PyCFunction_GetFlags

int
PyCFunction_GetFlags(PyObject *op)
{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return ((PyCFunctionObject *)op) -> m_ml -> ml_flags;
}
开发者ID:0xcc,项目名称:python-read,代码行数:9,代码来源:methodobject.c


示例12: PyCFunction_GetFunction

PyCFunction
PyCFunction_GetFunction(PyObject *op)
{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return PyCFunction_GET_FUNCTION(op);
}
开发者ID:LesyaMazurevich,项目名称:python-1,代码行数:9,代码来源:methodobject.c


示例13: PyCFunction_GetSelf

PyObject *
PyCFunction_GetSelf(PyObject *op)
{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyCFunctionObject *)op) -> m_self;
}
开发者ID:0xcc,项目名称:python-read,代码行数:9,代码来源:methodobject.c


示例14: PyCFunction_GetFunction

PyCFunction
PyCFunction_GetFunction(PyObject *op)
{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyCFunctionObject *)op) -> m_ml -> ml_meth;
}
开发者ID:0xcc,项目名称:python-read,代码行数:9,代码来源:methodobject.c


示例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;
}
开发者ID:10to8,项目名称:lunatic-python,代码行数:55,代码来源:pythoninlua.c


示例16: wxPyGetMethod

static PyObject* wxPyGetMethod(PyObject* py, char* name)
{
    if (!PyObject_HasAttrString(py, name))
        return NULL;
    PyObject* o = PyObject_GetAttrString(py, name);
    if (!PyMethod_Check(o) && !PyCFunction_Check(o)) {
        Py_DECREF(o);
        return NULL;
    }
    return o;
}
开发者ID:KenTsui,项目名称:Phoenix,代码行数:11,代码来源:stream_input.cpp


示例17: PyObject_CallAsPyString

PyObject* PyObject_CallAsPyString(PyObject* object) {
    PyObject *result, *module, *module_tmp, *self;
    PyObject *function, *function_tmp, *class;
    if (PyFunction_Check(object)) {
        module = ModuleAsPyString(((PyFunctionObject*)object)->func_module);
        function = ((PyFunctionObject*)object)->func_name;
        result = PyString_JoinWithDots(module, function);
        //Py_XDECREF(module);
        return result;
    } else if (PyCFunction_Check(object)) {
        module = ModuleAsPyString(((PyCFunctionObject*)object)->m_module);
        self = PyObject_AsPyString(((PyCFunctionObject*)object)->m_self);
        function = PyString_FromString(((PyCFunctionObject*)object)->m_ml->ml_name);
        result = PyString_JoinWithDots(module, self, function);
        //Py_XDECREF(module);
        Py_XDECREF(self);
        Py_DECREF(function);
        return result;
    } else if (PyMethod_Check(object)) {
        // See the implementation of instancemethod_repr
        class = NULL;
        if (PyMethod_GET_CLASS(object) != NULL) {
            class = PyObject_CallAsPyString(PyMethod_GET_CLASS(object));
        }
        if (PyFunction_Check(PyMethod_GET_FUNCTION(object))) {
            function = ((PyFunctionObject*)PyMethod_GET_FUNCTION(object))->func_name;
            Py_XINCREF(function);
        } else {
            function = PyString_InternFromString("???");
        }
        if (PyMethod_GET_SELF(object) == NULL) {
            // Unbounded method
            function_tmp = function;
            function = PyString_FromFormat("%s<U>",
                                           PyString_AsString(function_tmp));
            Py_DECREF(function_tmp);
        }
        result = PyString_JoinWithDots(class, function);
        Py_XDECREF(class);
        Py_XDECREF(function);
        return result;
    } else if (PyType_Check(object)) {
开发者ID:sk-,项目名称:python2.7-type-annotator,代码行数:42,代码来源:typeannotations.c


示例18: sip_api_same_slot

/*
 * Compare two slots to see if they are the same.
 */
int sip_api_same_slot(const sipSlot *sp, PyObject *rxObj, const char *slot)
{
    assert(sipQtSupport);
    assert(sipQtSupport->qt_same_name);

    /* See if they are signals or Qt slots, ie. they have a name. */
    if (slot != NULL)
    {
        if (sp->name == NULL || sp->name[0] == '\0')
            return 0;

        return (sipQtSupport->qt_same_name(sp->name, slot) && sp->pyobj == rxObj);
    }

    /* See if they are pure Python methods. */
    if (PyMethod_Check(rxObj))
    {
        if (sp->pyobj != NULL)
            return 0;

        return (sp->meth.mfunc == PyMethod_GET_FUNCTION(rxObj)
                && sp->meth.mself == PyMethod_GET_SELF(rxObj)
#if PY_MAJOR_VERSION < 3
                && sp->meth.mclass == PyMethod_GET_CLASS(rxObj)
#endif
                );
    }

    /* See if they are wrapped C++ methods. */
    if (PyCFunction_Check(rxObj))
    {
        if (sp->name == NULL || sp->name[0] != '\0')
            return 0;

        return (sp->pyobj == PyCFunction_GET_SELF(rxObj) &&
                strcmp(&sp->name[1], ((PyCFunctionObject *)rxObj)->m_ml->ml_name) == 0);
    }

    /* The objects must be the same. */
    return (sp->pyobj == rxObj);
}
开发者ID:CarlosAndres12,项目名称:pyqt5,代码行数:44,代码来源:qtlib.c


示例19: do_multi_setopt

static PyObject *
do_multi_setopt(CurlMultiObject *self, PyObject *args)
{
    int option, which;
    PyObject *obj;

    if (!PyArg_ParseTuple(args, "iO:setopt", &option, &obj))
        return NULL;
    if (check_multi_state(self, 1 | 2, "setopt") != 0)
        return NULL;

    /* Early checks of option value */
    if (option <= 0)
        goto error;
    if (option >= (int)CURLOPTTYPE_OFF_T + MOPTIONS_SIZE)
        goto error;
    if (option % 10000 >= MOPTIONS_SIZE)
        goto error;

    /* Handle the case of integer arguments */
    if (PyInt_Check(obj)) {
        return do_multi_setopt_int(self, option, obj);
    }

    /* Handle the case of list or tuple objects */
    which = PyListOrTuple_Check(obj);
    if (which) {
        return do_multi_setopt_list(self, option, which, obj);
    }

    if (PyFunction_Check(obj) || PyCFunction_Check(obj) ||
        PyCallable_Check(obj) || PyMethod_Check(obj)) {
        return do_multi_setopt_callable(self, option, obj);
    }

    /* Failed to match any of the function signatures -- return error */
error:
    PyErr_SetString(PyExc_TypeError, "invalid arguments to setopt");
    return NULL;
}
开发者ID:Charlesdong,项目名称:pycurl,代码行数:40,代码来源:multi.c


示例20: TRACE

CVirtualHelper::CVirtualHelper(const char *iname, void *iassoc, EnumVirtualErrorHandling veh/* = VEH_PRINT_ERROR */)
{
	handler=NULL;
	py_ob = NULL;
	retVal=NULL;
	csHandlerName = iname;
	vehErrorHandling = veh;
	if (bInFatalShutdown)
		return;
	CEnterLeavePython _celp;
	ui_assoc_object *py_bob = ui_assoc_object::handleMgr.GetAssocObject( iassoc );
	if (py_bob==NULL)
		return;
	if (!py_bob->is_uiobject( &ui_assoc_object::type)) {
		TRACE("CVirtualHelper::CVirtualHelper Error: Call object is not of required type\n");
		Py_DECREF(py_bob);
		return;
	}
	// ok - have the python data type - now see if it has an override.
	if (py_bob->virtualInst) {
		PyObject *t, *v, *tb;
		PyErr_Fetch(&t,&v,&tb);
		handler = PyObject_GetAttrString(py_bob->virtualInst, (char *)iname);
		if (handler) {
			// explicitely check a method returned, else the classes
			// delegation may cause a circular call chain.
			if (!PyMethod_Check(handler)) {
				if (!PyCFunction_Check(handler)) {
					TRACE("Handler for object is not a method!\n");
				}
				DODECREF(handler);
				handler = NULL;
			}
		}
		PyErr_Restore(t,v,tb);
	}
	py_ob = py_bob;
	// reference on 'py_bob' now owned by 'py_ob'
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:39,代码来源:win32virt.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyCFunction_New函数代码示例发布时间:2022-05-30
下一篇:
C++ PyBytes_Size函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap