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

C++ PyArg_UnpackTuple函数代码示例

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

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



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

示例1: range

/* XXX(nnorwitz): should we error check if the user passes any empty ranges?
   range(-10)
   range(0, -5)
   range(0, 5, -1)
*/
static PyObject *
range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
    rangeobject *obj;
    PyObject *start = NULL, *stop = NULL, *step = NULL;

    if (!_PyArg_NoKeywords("range()", kw))
        return NULL;

    if (PyTuple_Size(args) <= 1) {
        if (!PyArg_UnpackTuple(args, "range", 1, 1, &stop))
            return NULL;
        stop = PyNumber_Index(stop);
        if (!stop)
            return NULL;
        start = PyLong_FromLong(0);
        if (!start) {
            Py_DECREF(stop);
            return NULL;
        }
        step = PyLong_FromLong(1);
        if (!step) {
            Py_DECREF(stop);
            Py_DECREF(start);
            return NULL;
        }
    }
    else {
        if (!PyArg_UnpackTuple(args, "range", 2, 3,
                               &start, &stop, &step))
            return NULL;

        /* Convert borrowed refs to owned refs */
        start = PyNumber_Index(start);
        if (!start)
            return NULL;
        stop = PyNumber_Index(stop);
        if (!stop) {
            Py_DECREF(start);
            return NULL;
        }
        step = validate_step(step);    /* Caution, this can clear exceptions */
        if (!step) {
            Py_DECREF(start);
            Py_DECREF(stop);
            return NULL;
        }
    }

    obj = make_range_object(type, start, stop, step);
    if (obj != NULL)
        return (PyObject *) obj;

    /* Failed to create object, release attributes */
    Py_XDECREF(start);
    Py_XDECREF(stop);
    Py_XDECREF(step);
    return NULL;
}
开发者ID:PiJoules,项目名称:cpython-modified,代码行数:64,代码来源:rangeobject.c


示例2: math_log

static PyObject *
math_log(PyObject *self, PyObject *args)
{
	PyObject *arg;
	PyObject *base = NULL;
	PyObject *num, *den;
	PyObject *ans;

	if (!PyArg_UnpackTuple(args, "log", 1, 2, &arg, &base))
		return NULL;

	num = loghelper(arg, log, "log");
	if (num == NULL || base == NULL)
		return num;

	den = loghelper(base, log, "log");
	if (den == NULL) {
		Py_DECREF(num);
		return NULL;
	}

	ans = PyNumber_TrueDivide(num, den);
	Py_DECREF(num);
	Py_DECREF(den);
	return ans;
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:26,代码来源:mathmodule.c


示例3: math_2

static PyObject *
math_2(PyObject *args, double (*func) (double, double), char *funcname)
{
	PyObject *ox, *oy;
	double x, y, r;
	if (! PyArg_UnpackTuple(args, funcname, 2, 2, &ox, &oy))
		return NULL;
	x = PyFloat_AsDouble(ox);
	y = PyFloat_AsDouble(oy);
	if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
		return NULL;
	errno = 0;
	PyFPE_START_PROTECT("in math_2", return 0);
	r = (*func)(x, y);
	PyFPE_END_PROTECT(r);
	if (Py_IS_NAN(r)) {
		if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
			errno = EDOM;
		else
			errno = 0;
	}
	else if (Py_IS_INFINITY(r)) {
		if (Py_IS_FINITE(x) && Py_IS_FINITE(y))
			errno = ERANGE;
		else
			errno = 0;
	}
	if (errno && is_error(r))
		return NULL;
	else
		return PyFloat_FromDouble(r);
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:32,代码来源:mathmodule.c


示例4: sophia_db_get

static PyObject *
sophia_db_get(SophiaDB *db, PyObject *args)
{
    char *key;
    PyObject *pkey, *pvalue = NULL;
    void *value;
    Py_ssize_t ksize;
    size_t vsize;
    
    ensure_is_opened(db, NULL);
    
    if (!PyArg_UnpackTuple(args, "get", 1, 2, &pkey, &pvalue)
        || PyBytes_AsStringAndSize(pkey, &key, &ksize) == -1)
        return NULL;
        
    int rv = sp_get(db->db, key, (size_t)ksize, &value, &vsize);
    switch (rv) {
        case 1:
            pvalue = PyBytes_FromStringAndSize(value, (Py_ssize_t)vsize);
            free(value);
            return pvalue;
        case 0:
            if (pvalue)
                return pvalue;
            Py_RETURN_NONE;
        default:
            PyErr_SetString(SophiaError, sp_error(db->db));
            return NULL;
    }
}
开发者ID:david-furminieux,项目名称:python-sophia,代码行数:30,代码来源:pysophia.c


示例5: _cffi_f_cvCreateMat

static PyObject *
_cffi_f_cvCreateMat(PyObject *self, PyObject *args)
{
  int x0;
  int x1;
  int x2;
  CvMat * result;
  PyObject *arg0;
  PyObject *arg1;
  PyObject *arg2;

  if (!PyArg_UnpackTuple(args, "cvCreateMat", 3, 3, &arg0, &arg1, &arg2))
    return NULL;

  x0 = _cffi_to_c_int(arg0, int);
  if (x0 == (int)-1 && PyErr_Occurred())
    return NULL;

  x1 = _cffi_to_c_int(arg1, int);
  if (x1 == (int)-1 && PyErr_Occurred())
    return NULL;

  x2 = _cffi_to_c_int(arg2, int);
  if (x2 == (int)-1 && PyErr_Occurred())
    return NULL;

  Py_BEGIN_ALLOW_THREADS
  _cffi_restore_errno();
  { result = cvCreateMat(x0, x1, x2); }
  _cffi_save_errno();
  Py_END_ALLOW_THREADS

  (void)self; /* unused */
  return _cffi_from_c_pointer((char *)result, _cffi_type(12));
}
开发者ID:XuChongBo,项目名称:cxxdemo,代码行数:35,代码来源:_mycv.c


示例6: hashsplit_read_chunk

static PyObject * hashsplit_read_chunk(PyObject *self, PyObject *args) {
    PyObject *source_file = NULL; //gcc complains if these aren't initialized
    PyObject *max_chunk_size = NULL;
    long MAX_CHUNK_SIZE;
    PyObject *result = NULL;
    Chunk *chunk;
    FILE *source;

    if (!PyArg_UnpackTuple(args, "read_chunk", 1, 2, &source_file, &max_chunk_size))
        return NULL;
    if (!(source = PyFile_AsFile(source_file))) {
        PyErr_SetString(PyExc_TypeError, "Expected file or file descriptor");
        return NULL;
    }
    if (!max_chunk_size || max_chunk_size == Py_None) {
        MAX_CHUNK_SIZE = DEFAULT_MAX_CHUNK_SIZE;
    } else if ((MAX_CHUNK_SIZE = PyInt_AsLong(max_chunk_size))==-1 && PyErr_Occurred()) {
        PyErr_SetString(PyExc_TypeError, "max_chunk_size should be an integer");
        return NULL;
    }
    if (MAX_CHUNK_SIZE < MIN_CHUNK_SIZE) {
        PyErr_SetString(PyExc_ValueError, "max_chunk_size must be larger than MIN_CHUNK_SIZE");
        return NULL;
    }
    if (!(chunk = chunk_new(MAX_CHUNK_SIZE))) return PyErr_NoMemory();
    if (!read_chunk(source, chunk, MAX_CHUNK_SIZE)) {
        PyErr_SetString(PyExc_EOFError, "");
    } else {
        result = PyString_FromStringAndSize((char*)chunk->data, chunk->length);
    }
    chunk_delete(chunk);
    return result;
}
开发者ID:orbnauticus,项目名称:CloneServer,代码行数:33,代码来源:hashsplitmodule.c


示例7: math_fmod

static PyObject *
math_fmod(PyObject *self, PyObject *args)
{
	PyObject *ox, *oy;
	double r, x, y;
	if (! PyArg_UnpackTuple(args, "fmod", 2, 2, &ox, &oy))
		return NULL;
	x = PyFloat_AsDouble(ox);
	y = PyFloat_AsDouble(oy);
	if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
		return NULL;
	/* fmod(x, +/-Inf) returns x for finite x. */
	if (Py_IS_INFINITY(y) && Py_IS_FINITE(x))
		return PyFloat_FromDouble(x);
	errno = 0;
	PyFPE_START_PROTECT("in math_fmod", return 0);
	r = fmod(x, y);
	PyFPE_END_PROTECT(r);
	if (Py_IS_NAN(r)) {
		if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
			errno = EDOM;
		else
			errno = 0;
	}
	if (errno && is_error(r))
		return NULL;
	else
		return PyFloat_FromDouble(r);
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:29,代码来源:mathmodule.c


示例8: LDAPEntry_Update

/*	Updating LDAPEntry. Pretty much same as PyDict_Update function's codebase. */
static PyObject *
LDAPEntry_Update(LDAPEntry *self, PyObject *args, PyObject *kwds) {
	int rc = 0;
	PyObject *arg = NULL;

	if (!PyArg_UnpackTuple(args, "update", 0, 1, &arg)) {
		rc = -1;
	} else if (arg != NULL) {
		if (PyObject_HasAttrString(arg, "keys") || PyDict_Check(arg)) {
			/* If argument is a dict, use own function to update. */
			rc = LDAPEntry_UpdateFromDict(self, arg);
		} else {
			/* If argument is a sequence type, use own function to update. */
			rc = LDAPEntry_UpdateFromSeq2(self, arg);
		}
	}
	if (rc == 0 && kwds != NULL) {
		if (PyArg_ValidateKeywordArguments(kwds)) {
			/* If arguments are keywords, use own function to update. */
			rc = LDAPEntry_UpdateFromDict(self, kwds);
		} else {
			rc = -1;
		}
	}
	if (rc != -1) {
		Py_INCREF(Py_None); //Why?
		return Py_None;
	}
	return NULL;
}
开发者ID:KarapulYa,项目名称:pyLDAP,代码行数:31,代码来源:ldapentry.c


示例9: _tnetstring_dumps

static PyObject*
_tnetstring_dumps(PyObject* self, PyObject *args, PyObject *kwds) 
{
  PyObject *object, *string;
  char *output, *odata, *sdata;
  size_t len=0;

  if(!PyArg_UnpackTuple(args, "dumps", 1, 1, &object)) {
      return NULL;
  }
  Py_INCREF(object);

  output = tns_render_reversed(object, &len);
  Py_DECREF(object);
  if(output == NULL) {
      return NULL;
  }

  string = PyString_FromStringAndSize(NULL,len);
  if(string == NULL) {
      return NULL;
  }
  sdata = PyString_AS_STRING(string);
  odata = output + len - 1;
  while(odata >= output) {
      *sdata = *odata;
      odata--;
      sdata++;
  }
  free(output);
  return string;
}
开发者ID:Tordek,项目名称:tnetstring,代码行数:32,代码来源:_tnetstring.c


示例10: csv_register_dialect

static PyObject *
csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
{
    PyObject *name_obj, *dialect_obj = NULL;
    PyObject *dialect;

    if (!PyArg_UnpackTuple(args, "", 1, 2, &name_obj, &dialect_obj))
        return NULL;
    if (!PyUnicode_Check(name_obj)) {
        PyErr_SetString(PyExc_TypeError,
                        "dialect name must be a string");
        return NULL;
    }
    if (PyUnicode_READY(name_obj) == -1)
        return NULL;
    dialect = _call_dialect(dialect_obj, kwargs);
    if (dialect == NULL)
        return NULL;
    if (PyDict_SetItem(_csvstate_global->dialects, name_obj, dialect) < 0) {
        Py_DECREF(dialect);
        return NULL;
    }
    Py_DECREF(dialect);
    Py_RETURN_NONE;
}
开发者ID:1st1,项目名称:cpython,代码行数:25,代码来源:_csv.c


示例11: parse_weakref_init_args

static int
parse_weakref_init_args(char *funcname, PyObject *args, PyObject *kwargs,
                        PyObject **obp, PyObject **callbackp)
{
    /* XXX Should check that kwargs == NULL or is empty. */
    return PyArg_UnpackTuple(args, funcname, 1, 2, obp, callbackp);
}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:7,代码来源:weakrefobject.c


示例12: time_ctime

static PyObject *
time_ctime(PyObject *self, PyObject *args)
{
    PyObject *ot = NULL;
    time_t tt;
    struct tm *timeptr;

    if (!PyArg_UnpackTuple(args, "ctime", 0, 1, &ot))
        return NULL;
    if (ot == NULL || ot == Py_None)
        tt = time(NULL);
    else {
        double dt = PyFloat_AsDouble(ot);
        if (PyErr_Occurred())
            return NULL;
        tt = _PyTime_DoubleToTimet(dt);
        if (tt == (time_t)-1 && PyErr_Occurred())
            return NULL;
    }
    timeptr = localtime(&tt);
    if (timeptr == NULL) {
        PyErr_SetString(PyExc_ValueError, "unconvertible time");
        return NULL;
    }
    return _asctime(timeptr);
}
开发者ID:469306621,项目名称:Languages,代码行数:26,代码来源:timemodule.c


示例13: wrap_init

static int
wrap_init(PyObject *self, PyObject *args, PyObject *kwds)
{
    int result = -1;
    PyObject *object;

    if (PyArg_UnpackTuple(args, "__init__", 1, 1, &object)) {
        ProxyObject *wrapper = (ProxyObject *)self;
        if (kwds != NULL && PyDict_Size(kwds) != 0) {
            PyErr_SetString(PyExc_TypeError,
                            "proxy.__init__ does not accept keyword args");
            return -1;
        }
        /* If the object in this proxy is not the one we
         * received in args, replace it with the new one.
         */
        if (wrapper->proxy_object != object) {
            PyObject *temp = wrapper->proxy_object;
            Py_INCREF(object);
            wrapper->proxy_object = object;
            Py_DECREF(temp);
        }
        result = 0;
    }
    return result;
}
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:26,代码来源:_zope_proxy_proxy.c


示例14: cycle_new

static PyObject *
cycle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
	PyObject *it;
	PyObject *iterable;
	PyObject *saved;
	cycleobject *lz;

	if (!PyArg_UnpackTuple(args, "cycle", 1, 1, &iterable))
		return NULL;

	/* Get iterator. */
	it = PyObject_GetIter(iterable);
	if (it == NULL)
		return NULL;

	saved = PyList_New(0);
	if (saved == NULL) {
		Py_DECREF(it);
		return NULL;
	}

	/* create cycleobject structure */
	lz = (cycleobject *)type->tp_alloc(type, 0);
	if (lz == NULL) {
		Py_DECREF(it);
		Py_DECREF(saved);
		return NULL;
	}
	lz->it = it;
	lz->saved = saved;
	lz->firstpass = 0;

	return (PyObject *)lz;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:35,代码来源:itertoolsmodule.c


示例15: starmap_new

static PyObject *
starmap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
	PyObject *func, *seq;
	PyObject *it;
	starmapobject *lz;

	if (!PyArg_UnpackTuple(args, "starmap", 2, 2, &func, &seq))
		return NULL;

	/* Get iterator. */
	it = PyObject_GetIter(seq);
	if (it == NULL)
		return NULL;

	/* create starmapobject structure */
	lz = (starmapobject *)type->tp_alloc(type, 0);
	if (lz == NULL) {
		Py_DECREF(it);
		return NULL;
	}
	Py_INCREF(func);
	lz->func = func;
	lz->it = it;

	return (PyObject *)lz;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:27,代码来源:itertoolsmodule.c


示例16: reversed_new

static PyObject *
reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
	Py_ssize_t n;
	PyObject *seq;
	reversedobject *ro;

	if (type == &PyReversed_Type && !_PyArg_NoKeywords("reversed()", kwds))
		return NULL;

	if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq) )
		return NULL;

	if (PyObject_HasAttrString(seq, "__reversed__"))
		return PyObject_CallMethod(seq, "__reversed__", NULL);

	if (!PySequence_Check(seq)) {
		PyErr_SetString(PyExc_TypeError,
				"argument to reversed() must be a sequence");
		return NULL;
	}

	n = PySequence_Size(seq);
	if (n == -1)
		return NULL;

	ro = (reversedobject *)type->tp_alloc(type, 0);
	if (ro == NULL)
		return NULL;

	ro->index = n-1;
	Py_INCREF(seq);
	ro->seq = seq;
	return (PyObject *)ro;
}
开发者ID:Vignesh2736,项目名称:IncPy,代码行数:35,代码来源:enumobject.c


示例17: dict_setdefault

static PyObject *
dict_setdefault(PyObject *_self, PyObject *args)
{
	attr_dir_object *self = (attr_dir_object*)_self;
	PyObject *key, *failobj;
	PyObject *val = NULL;
	kdump_ctx *ctx;
	kdump_attr_ref_t ref;
	kdump_attr_t attr;
	kdump_status status;

	failobj = Py_None;
	if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj))
		return NULL;

	if (get_attribute(self, key, &ref) <= 0)
		return NULL;

	ctx = self->kdumpfile->ctx;
	status = kdump_attr_ref_get(ctx, &ref, &attr);
	if (status == kdump_ok)
		val = attr_new(self->kdumpfile, &ref, &attr);
	else if (status == kdump_nodata)
		val = (set_attribute(self, &ref, failobj) == 0)
			? failobj
			: NULL;
	else {
		PyErr_SetString(exception_map(status), kdump_err_str(ctx));
		val = NULL;
	}
	kdump_attr_unref(ctx, &ref);

	Py_XINCREF(val);
	return val;
}
开发者ID:jeffmahoney,项目名称:libkdumpfile,代码行数:35,代码来源:kdumpfile.c


示例18: sllist_insertbefore

static PyObject* sllist_insertbefore(SLListObject* self, PyObject* arg)
{

    PyObject* value = NULL;
    PyObject* after = NULL;
    PyObject* list_ref;

    SLListNodeObject* new_node;
    SLListNodeObject* prev;

    if (!PyArg_UnpackTuple(arg, "insertbefore", 2, 2, &value, &after))
        return NULL;

    if (!PyObject_TypeCheck(after, &SLListNodeType))
    {
        PyErr_SetString(PyExc_TypeError, "Argument is not an sllistnode");
        return NULL;
    }
    if (PyObject_TypeCheck(value, &SLListNodeType))
        value = ((SLListNodeObject*)value)->value;

    if (after == Py_None)
    {
        PyErr_SetString(PyExc_ValueError,
            "sllistnode does not belong to a list");
        return NULL;
    }

    list_ref = PyWeakref_GetObject(
        ((SLListNodeObject*)after)->list_weakref);
    if (list_ref != (PyObject*)self)
    {
        PyErr_SetString(PyExc_ValueError,
            "sllistnode belongs to another list");
        return NULL;
    }
    new_node = sllistnode_create(Py_None,
                                 value,
                                 (PyObject*)self);

    /* getting prev node for this from arg*/
    prev = sllist_get_prev(self, (SLListNodeObject*)after);

    /* putting new node in created gap, not first and exists */
    if((PyObject*)prev != Py_None && prev != NULL)
    {
        ((SLListNodeObject*)prev)->next = (PyObject*)new_node;
        new_node->next = after;
    }
    else
    {
        new_node->next = after;
        self->first = (PyObject*)new_node;
    }
    /* new_node->next = ((SLListNodeObject*)after)->next; */
    /* ((SLListNodeObject*)before)->next = (PyObject*)new_node; */
    ++self->size;
    Py_INCREF((PyObject*)new_node);
    return (PyObject*)new_node;
}
开发者ID:ajakubek,项目名称:python-llist,代码行数:60,代码来源:sllist.c


示例19: sllistiterator_new

static PyObject* sllistiterator_new(PyTypeObject* type,
                                    PyObject* args,
                                    PyObject* kwds)
{
    SLListIteratorObject* self;
    PyObject* owner_list = NULL;

    if (!PyArg_UnpackTuple(args, "__new__", 1, 1, &owner_list))
        return NULL;

    if (!PyObject_TypeCheck(owner_list, &SLListType))
    {
        PyErr_SetString(PyExc_TypeError, "sllist argument expected");
        return NULL;
    }

    self = (SLListIteratorObject*)type->tp_alloc(type, 0);
    if (self == NULL)
        return NULL;

    self->list = (SLListObject*)owner_list;
    self->current_node = self->list->first;

    Py_INCREF(self->list);
    Py_INCREF(self->current_node);

    return (PyObject*)self;
}
开发者ID:ajakubek,项目名称:python-llist,代码行数:28,代码来源:sllist.c


示例20: BaseRowProxy_init

static int
BaseRowProxy_init(BaseRowProxy *self, PyObject *args, PyObject *kwds)
{
    PyObject *parent, *row, *processors, *keymap;

    if (!PyArg_UnpackTuple(args, "BaseRowProxy", 4, 4,
                           &parent, &row, &processors, &keymap))
        return -1;

    Py_INCREF(parent);
    self->parent = parent;

    if (!PySequence_Check(row)) {
        PyErr_SetString(PyExc_TypeError, "row must be a sequence");
        return -1;
    }
    Py_INCREF(row);
    self->row = row;

    if (!PyList_CheckExact(processors)) {
        PyErr_SetString(PyExc_TypeError, "processors must be a list");
        return -1;
    }
    Py_INCREF(processors);
    self->processors = processors;

    if (!PyDict_CheckExact(keymap)) {
        PyErr_SetString(PyExc_TypeError, "keymap must be a dict");
        return -1;
    }
    Py_INCREF(keymap);
    self->keymap = keymap;

    return 0;
}
开发者ID:acbart,项目名称:WebInACan,代码行数:35,代码来源:resultproxy.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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