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


C++ PyArg_UnpackTuple函数代码示例

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


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


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