本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}