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

C++ PyErr_BadArgument函数代码示例

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

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



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

示例1: sv_LoadMap

static PyObject *
sv_LoadMap(svobject *self, PyObject *args)
{
	PyObject *rgb;
	PyObject *res = NULL;
	rgb_tuple *mapp = NULL;
	int maptype;
	int i, j;			     /* indices */

	if (!PyArg_Parse(args, "(iO)", &maptype, &rgb))
		return NULL;

	if (!PyList_Check(rgb) || PyList_Size(rgb) != 256) {
		PyErr_BadArgument();
		return NULL;
	}

	if (!(mapp = PyMem_NEW(rgb_tuple, 256)))
		return PyErr_NoMemory();

	for (i = 0; i < 256; i++) {
		PyObject* v = PyList_GetItem(rgb, i);
		if (!v)
			goto finally;

		if (!PyTuple_Check(v) || PyTuple_Size(v) != 3) {
			PyErr_BadArgument();
			goto finally;
		}
		for (j = 0; j < 3; j++) {
			PyObject* cell = PyTuple_GetItem(v, j);
			if (!cell)
				goto finally;

			if (!PyInt_Check(cell)) {
				PyErr_BadArgument();
				goto finally;
			}
			switch (j) {
			case 0: mapp[i].red = PyInt_AsLong(cell); break;
			case 1: mapp[i].blue = PyInt_AsLong(cell); break;
			case 2: mapp[i].green = PyInt_AsLong(cell); break;
			}
			if (PyErr_Occurred())
				goto finally;
		}
	}

	if (svLoadMap(self->ob_svideo, maptype, mapp)) {
		res = sv_error();
		goto finally;
	}

	Py_INCREF(Py_None);
	res = Py_None;

  finally:
	PyMem_DEL(mapp);
	return res;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:60,代码来源:svmodule.c


示例2: wpSocket_sendpacket

// DEPRECATED
static PyObject* wpSocket_sendpacket( wpSocket* self, PyObject* args )
{
	if ( PyTuple_Size( args ) != 1 )
	{
		PyErr_BadArgument();
		return 0;
	}

	PyObject* list = PyTuple_GetItem( args, 0 );

	if ( !PyList_Check( list ) )
	{
		PyErr_BadArgument();
		return 0;
	}

	// Build a packet
	int packetLength = PyList_Size( list );

	QByteArray buffer( packetLength );

	for ( int i = 0; i < packetLength; ++i )
		buffer[i] = PyInt_AsLong( PyList_GetItem( list, i ) );

	cUOPacket packet( buffer );
	self->pSock->send( &packet );

	Py_RETURN_NONE;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:30,代码来源:socket.cpp


示例3: wpSocket_sendpacket

// DEPRECATED
static PyObject* wpSocket_sendpacket( wpSocket* self, PyObject* args )
{
	if ( PyTuple_Size( args ) != 1 )
	{
		PyErr_BadArgument();
		return 0;
	}

	PyObject* list = PyTuple_GetItem( args, 0 );

	if ( !PyList_Check( list ) )
	{
		PyErr_BadArgument();
		return 0;
	}

	PyErr_Format( PyExc_DeprecationWarning, "socket.sendpacket is deprecated, please use something instead" );

	// Build a packet
	int packetLength = PyList_Size( list );

	QByteArray buffer( packetLength, 0 );

	for ( int i = 0; i < packetLength; ++i )
		buffer[i] = PyInt_AsLong( PyList_GetItem( list, i ) );

	cUOPacket packet( buffer );
	self->pSock->send( &packet );

	Py_RETURN_NONE;
}
开发者ID:Mutilador,项目名称:Wolfpack,代码行数:32,代码来源:socket.cpp


示例4: PyGreenlet_Switch

static PyObject *
PyGreenlet_Switch(PyGreenlet *g, PyObject *args, PyObject *kwargs)
{
	PyGreenlet *self = (PyGreenlet *) g;

	if (!PyGreenlet_Check(self)) {
		PyErr_BadArgument();
		return NULL;
	}

	if (args == NULL) {
		args = Py_BuildValue("()");
	}
	else {
		Py_INCREF(args);
	}

	if (kwargs != NULL && PyDict_Check(kwargs)) {
		Py_INCREF(kwargs);
	}
	else {
		kwargs = NULL;
	}

	return single_result(g_switch(self, args, kwargs));
}
开发者ID:vietlq,项目名称:greenlet,代码行数:26,代码来源:greenlet.c


示例5: pyext_epoll_modify

static PyObject* pyext_epoll_modify(PyObject *self,PyObject *args){
    int epfd;
    int fd;
    uint32_t events;

    struct pyep_data *pyep;
    struct ev_header *evhdr;

    if(!PyArg_ParseTuple(args,"iiI",&epfd,&fd,&events)){
        PyErr_BadArgument();
        return NULL;
    }
    if((pyep = pyep_getby_epfd(epfd)) == NULL){
        PyErr_SetString(PyExc_KeyError,"epoll file descriptor not found");
        return NULL;
    }
    if((evhdr = evhdr_getby_fd(pyep->evhdr_ht,fd)) == NULL){
        PyErr_SetString(PyExc_KeyError,"file descriptor not found");
        return NULL;
    }

    if(ev_mod(&pyep->evdata,evhdr,events)){
        PyErr_SetString(PyExc_SystemError,"modify event failed");
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:pzread,项目名称:sdup,代码行数:29,代码来源:pyext.c


示例6: pyext_epoll_unregister

static PyObject* pyext_epoll_unregister(PyObject *self,PyObject *args){
    khiter_t hit;

    int epfd;
    int fd;

    struct pyep_data *pyep;
    struct ev_header *evhdr;

    if(!PyArg_ParseTuple(args,"ii",&epfd,&fd)){
        PyErr_BadArgument();
        return NULL;
    }
    if((pyep = pyep_getby_epfd(epfd)) == NULL){
        PyErr_SetString(PyExc_KeyError,"epoll file descriptor not found");
        return NULL;
    }
    if((evhdr = evhdr_getby_fd(pyep->evhdr_ht,fd)) == NULL){
        PyErr_SetString(PyExc_KeyError,"file descriptor not found");
        return NULL;
    }

    if(ev_del(&pyep->evdata,evhdr)){
        PyErr_SetString(PyExc_SystemError,"unregister event failed");
        return NULL;
    }
    
    hit = kh_get(ptr,pyep->evhdr_ht,fd);
    kh_del(ptr,pyep->evhdr_ht,hit);

    free(evhdr);

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:pzread,项目名称:sdup,代码行数:35,代码来源:pyext.c


示例7: wpMulti_gettag

/*!
	Returns the custom tag passed
*/
static PyObject* wpMulti_gettag( wpMulti* self, PyObject* args )
{
	if( !self->pMulti || self->pMulti->free )
	{
		Py_INCREF( Py_None );
		return Py_None;
	}

	if( PyTuple_Size( args ) < 1 || !checkArgStr( 0 ) )
	{
		PyErr_BadArgument();
		return NULL;
	}

	QString key = PyString_AsString( PyTuple_GetItem( args, 0 ) );
	cVariant value = self->pMulti->getTag( key );

	if( value.type() == cVariant::String )
	{
		QString strValue = value.asString();

		if( !strValue.isNull() )
			return PyString_FromString( strValue.latin1() );
		else
			return PyString_FromString( "" );
	}
	else if( value.type() == cVariant::Int )
		return PyInt_FromLong( value.asInt() );

	Py_INCREF( Py_None );
	return Py_None;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:35,代码来源:multi.cpp


示例8: wpMulti_sendcustomhouse

/*!
	Sends custom house to client
*/
static PyObject* wpMulti_sendcustomhouse( wpMulti* self, PyObject* args )
{
	Q_UNUSED(args);	
	if( !self->pMulti || self->pMulti->free || !self->pMulti->ishouse() )
		return PyFalse;
	
	if( !checkArgChar( 0 ) )
	{
		PyErr_BadArgument();
		return NULL;
	}
	P_PLAYER player = dynamic_cast<P_PLAYER>( getArgChar( 0 ) );
	if ( !player )
		return PyFalse;

//	self->pMulti->sendCH( player->socket() );
	cUOTxAskCustomHouse askch;

	askch.setSerial( self->pMulti->serial() );
	askch.setId( self->pMulti->revision() );

	player->socket()->send( &askch );

	return PyTrue;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:28,代码来源:multi.cpp


示例9: Sbk_Double2DTupleFunc___getitem__

PyObject* Sbk_Double2DTupleFunc___getitem__(PyObject* self, Py_ssize_t _i)
{
    if (!Shiboken::Object::isValid(self))
        return 0;
    ::Double2DTuple* cppSelf = 0;
    SBK_UNUSED(cppSelf)
    if (!Shiboken::Object::isValid(self))
        return 0;
    cppSelf = ((::Double2DTuple*)Shiboken::Conversions::cppPointer(SbkNatronEngineTypes[SBK_DOUBLE2DTUPLE_IDX], (SbkObject*)self));
    // Begin code injection

    if (_i < 0 || _i >= 2) {
    PyErr_BadArgument();
    return 0;
    } else {
    double ret;
    switch (_i) {
    case 0:
    ret = cppSelf->x;
    break;
    case 1:
    ret = cppSelf->y;
    break;
    }
    return  Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<double>(), &ret);
    }

    // End of code injection
}
开发者ID:ChristianHeckl,项目名称:Natron,代码行数:29,代码来源:double2dtuple_wrapper.cpp


示例10: PyErr_BadArgument

PyObject *PyString_AsEncodedObject(PyObject *str,
                                   const char *encoding,
                                   const char *errors)
{
    PyObject *v;

    if (!PyString_Check(str)) {
        PyErr_BadArgument();
        goto onError;
    }

    if (encoding == NULL) {
#ifdef Py_USING_UNICODE
        encoding = PyUnicode_GetDefaultEncoding();
#else
        PyErr_SetString(PyExc_ValueError, "no encoding specified");
        goto onError;
#endif
    }

    /* Encode via the codec registry */
    v = PyCodec_Encode(str, encoding, errors);
    if (v == NULL)
        goto onError;

    return v;

 onError:
    return NULL;
}
开发者ID:KrishMunot,项目名称:pyston,代码行数:30,代码来源:stringobject.c


示例11: mp_log_error

static PyObject * mp_log_error(PyObject *self, PyObject *args)
{

    int level = 0;
    char *message = NULL;
    serverobject *server = NULL;
    server_rec *serv_rec;

    if (! PyArg_ParseTuple(args, "z|iO", &message, &level, &server))
        return NULL; /* error */

    if (message) {

        if (! level)
            level = APLOG_ERR;

        if (!server || (PyObject *)server == Py_None)
            serv_rec = NULL;
        else {
            if (! MpServer_Check(server)) {
                PyErr_BadArgument();
                return NULL;
            }
            serv_rec = server->server;
        }
        Py_BEGIN_ALLOW_THREADS
        ap_log_error(APLOG_MARK, level, 0, serv_rec, "%s", message);
        Py_END_ALLOW_THREADS
    }

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:AlfiyaZi,项目名称:mod_python,代码行数:33,代码来源:_apachemodule.c


示例12: range_richcompare

static PyObject *
range_richcompare(PyObject *self, PyObject *other, int op)
{
    int result;

    if (!PyRange_Check(other))
        Py_RETURN_NOTIMPLEMENTED;
    switch (op) {
    case Py_NE:
    case Py_EQ:
        result = range_equals((rangeobject*)self, (rangeobject*)other);
        if (result == -1)
            return NULL;
        if (op == Py_NE)
            result = !result;
        if (result)
            Py_RETURN_TRUE;
        else
            Py_RETURN_FALSE;
    case Py_LE:
    case Py_GE:
    case Py_LT:
    case Py_GT:
        Py_RETURN_NOTIMPLEMENTED;
    default:
        PyErr_BadArgument();
        return NULL;
    }
}
开发者ID:PiJoules,项目名称:cpython-modified,代码行数:29,代码来源:rangeobject.c


示例13: Color_richcmpr

//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true
static PyObject* Color_richcmpr(PyObject *a, PyObject *b, int op)
{
	PyObject *res;
	int ok= -1; /* zero is true */

	if (ColorObject_Check(a) && ColorObject_Check(b)) {
		ColorObject *colA= (ColorObject*)a;
		ColorObject *colB= (ColorObject*)b;

		if (BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1)
			return NULL;

		ok= EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1) ? 0 : -1;
	}

	switch (op) {
	case Py_NE:
		ok = !ok; /* pass through */
	case Py_EQ:
		res = ok ? Py_False : Py_True;
		break;

	case Py_LT:
	case Py_LE:
	case Py_GT:
	case Py_GE:
		res = Py_NotImplemented;
		break;
	default:
		PyErr_BadArgument();
		return NULL;
	}

	return Py_INCREF(res), res;
}
开发者ID:mik0001,项目名称:Blender,代码行数:37,代码来源:mathutils_Color.c


示例14: wpMulti_setAttr

static int wpMulti_setAttr( wpMulti *self, char *name, PyObject *value )
{
	if( !strcmp( "events", name ) )
	{
		if( !PyList_Check( value ) )
		{
			PyErr_BadArgument();
			return -1;
		}

		self->pMulti->clearEvents();
		int i;
		for( i = 0; i < PyList_Size( value ); ++i )
		{
			if( !PyString_Check( PyList_GetItem( value, i ) ) )
				continue;

			cPythonScript *script = ScriptManager::instance()->find( PyString_AsString( PyList_GetItem( value, i ) ) );
			if( script )
				self->pMulti->addEvent( script );
		}
	}
	else
	{
		cVariant val;
		if( PyString_Check( value ) )
			val = cVariant( PyString_AsString( value ) );
		else if( PyInt_Check( value ) )
			val = cVariant( PyInt_AsLong( value ) );
		else if( checkWpItem( value ) )
			val = cVariant( getWpItem( value ) );
		else if( checkWpChar( value ) )
			val = cVariant( getWpChar( value ) );
		else if( checkWpCoord( value ) )
			val = cVariant( getWpCoord( value ) );
		else if( PyFloat_Check( value ) )
			val = cVariant( PyFloat_AsDouble( value ) );

		if( !val.isValid() )
		{
			if( value->ob_type )
				PyErr_Format( PyExc_TypeError, "Unsupported object type: %s", value->ob_type->tp_name );
			else
				PyErr_Format( PyExc_TypeError, "Unknown object type" );
			return 0;
		}

		stError *error = self->pMulti->setProperty( name, val );

		if( error )
		{
			PyErr_Format( PyExc_TypeError, "Error while setting attribute '%s': %s", name, error->text.latin1() );
			delete error;
			return 0;
		}
	}

	return 0;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:59,代码来源:multi.cpp


示例15: buffer_ass_slice

static int
buffer_ass_slice(PyBufferObject *self, Py_ssize_t left, Py_ssize_t right, PyObject *other)
{
    PyBufferProcs *pb;
    void *ptr1, *ptr2;
    Py_ssize_t size;
    Py_ssize_t slice_len;
    Py_ssize_t count;

    if ( self->b_readonly ) {
        PyErr_SetString(PyExc_TypeError,
                        "buffer is read-only");
        return -1;
    }

    pb = other ? other->ob_type->tp_as_buffer : NULL;
    if ( pb == NULL ||
         pb->bf_getreadbuffer == NULL ||
         pb->bf_getsegcount == NULL )
    {
        PyErr_BadArgument();
        return -1;
    }
    if ( (*pb->bf_getsegcount)(other, NULL) != 1 )
    {
        /* ### use a different exception type/message? */
        PyErr_SetString(PyExc_TypeError,
                        "single-segment buffer object expected");
        return -1;
    }
    if (!get_buf(self, &ptr1, &size, ANY_BUFFER))
        return -1;
    if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
        return -1;

    if ( left < 0 )
        left = 0;
    else if ( left > size )
        left = size;
    if ( right < left )
        right = left;
    else if ( right > size )
        right = size;
    slice_len = right - left;

    if ( count != slice_len ) {
        PyErr_SetString(
            PyExc_TypeError,
            "right operand length must match slice length");
        return -1;
    }

    if ( slice_len )
        memcpy((char *)ptr1 + left, ptr2, slice_len);

    return 0;
}
开发者ID:756613351,项目名称:python-source-code,代码行数:57,代码来源:bufferobject.c


示例16: PyModule_GetState

void*
PyModule_GetState(PyObject* m)
{
    if (!PyModule_Check(m)) {
        PyErr_BadArgument();
        return NULL;
    }
    return ((PyModuleObject *)m)->md_state;
}
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:9,代码来源:moduleobject.c


示例17: PyModule_GetDef

PyModuleDef*
PyModule_GetDef(PyObject* m)
{
    if (!PyModule_Check(m)) {
        PyErr_BadArgument();
        return NULL;
    }
    return ((PyModuleObject *)m)->md_def;
}
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:9,代码来源:moduleobject.c


示例18: SP_CLASS_ATTR_GET

SP_CLASS_ATTR_GET(Vector3,z)(PyObject *self, void*)
{
    Vector3* obj=dynamic_cast<Vector3*>(((PyPtr<Vector3>*)self)->object);
    if (!obj)
    {
        PyErr_BadArgument();
        return 0;
    }
    return PyFloat_FromDouble(obj->z());
}
开发者ID:mhdsedighi,项目名称:SOFA,代码行数:10,代码来源:Binding_Vector.cpp


示例19: PaxFont_AsFontStruct

XFontStruct *
PaxFont_AsFontStruct(PyObject *self)
{
    if (self->ob_type != &PaxFontType)
    {
	PyErr_BadArgument();
	return 0;
    }
    return ((PaxFontObject *) self)->font_struct;
}
开发者ID:kindlychung,项目名称:sk1,代码行数:10,代码来源:fontobject.c


示例20: PyConvertSocket

int PyConvertSocket( PyObject* object, cUOSocket** sock )
{
	if ( object->ob_type != &wpSocketType )
	{
		PyErr_BadArgument();
		return 0;
	}

	*sock = ( ( wpSocket * ) object )->pSock;
	return 1;
}
开发者ID:Mutilador,项目名称:Wolfpack,代码行数:11,代码来源:socket.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyErr_BadInternalCall函数代码示例发布时间:2022-05-30
下一篇:
C++ PyDoc_STR函数代码示例发布时间: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