本文整理汇总了C++中PyTuple_Pack函数的典型用法代码示例。如果您正苦于以下问题:C++ PyTuple_Pack函数的具体用法?C++ PyTuple_Pack怎么用?C++ PyTuple_Pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyTuple_Pack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: KX_PythonComponent
PyObject *KX_PythonComponent::py_component_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
KX_PythonComponent *comp = new KX_PythonComponent(type->tp_name);
PyObject *proxy = py_base_new(type, PyTuple_Pack(1, comp->GetProxy()), kwds);
if (!proxy) {
delete comp;
return NULL;
}
return proxy;
}
示例2: umpyew_utime
static long umpyew_utime(char *path, struct utimbuf *buf)
{
PYINSYS(utime, 2);
PYARG(0, PyString_FromString(path));
if (buf)
PYARG(1, PyTuple_Pack(2, PyInt_FromLong(buf->actime), PyInt_FromLong(buf->modtime)));
else
PYARG(1, Py_None);
PYCALL;
PYOUT;
return retval;
}
示例3: create_filter
static PyObject *
create_filter(PyObject *category, _Py_Identifier *id)
{
PyObject *action_str = _PyUnicode_FromId(id);
if (action_str == NULL) {
return NULL;
}
/* This assumes the line number is zero for now. */
return PyTuple_Pack(5, action_str, Py_None,
category, Py_None, _PyLong_Zero);
}
示例4: update_registry
static int
update_registry(PyObject *registry, PyObject *text, PyObject *category,
int add_zero)
{
PyObject *altkey, *zero = NULL;
int rc;
if (add_zero) {
zero = PyInt_FromLong(0);
if (zero == NULL)
return -1;
altkey = PyTuple_Pack(3, text, category, zero);
}
else
altkey = PyTuple_Pack(2, text, category);
rc = already_warned(registry, altkey, 1);
Py_XDECREF(zero);
Py_XDECREF(altkey);
return rc;
}
示例5: KyotoDB_iteritems
static PyObject *
KyotoDB_iteritems(KyotoDB *self)
{
KyotoCursor *cursor = PyObject_New(KyotoCursor, &yakc_CursorType);
APR type(PyInt_FromLong((long)KYOTO_ITEMS));
APR tuple(PyTuple_Pack(2, self, type.get()));
int re = Cursor_init(cursor, tuple.get(), NULL);
if (re == 0)
return (PyObject *)cursor;
PyErr_SetString(PyExc_RuntimeError, "Cannot create cursor");
return NULL;
}
示例6: PyDict_New
static PyObject *PyKAdminPrincipal_get_keys(PyKAdminPrincipalObject *self, void *closure) {
/*
key structure:
{
kvno: [("enctype", "salt"), ("enctype", "salt")],
kvno: ...
}
*/
PyObject *kvno = NULL;
PyObject *enctype = NULL;
PyObject *salttype = NULL;
PyObject *tuple = NULL;
PyObject *list = NULL;
PyObject *keys = PyDict_New();
ssize_t index = 0;
for (; index < self->entry.n_key_data; index++) {
krb5_key_data *key_data = &self->entry.key_data[index];
kvno = PyUnifiedLongInt_FromLong(key_data->key_data_kvno);
enctype = pykadmin_key_enctype_name(key_data);
salttype = pykadmin_key_salttype_name(key_data);
tuple = PyTuple_Pack(2, enctype, salttype);
if (kvno) {
if (PyDict_Contains(keys, kvno)) {
list = PyDict_GetItem(keys, kvno);
} else {
list = PyList_New(0);
PyDict_SetItem(keys, kvno, list);
}
}
if (list && tuple) {
PyList_Append(list, tuple);
}
}
return keys;
}
示例7: objToJSONFile
PyObject* objToJSONFile(PyObject* self, PyObject *args)
{
PyObject *data;
PyObject *file;
PyObject *string;
PyObject *write;
PyObject *argtuple;
if (!PyArg_ParseTuple (args, "OO", &data, &file)) {
return NULL;
}
if (!PyObject_HasAttrString (file, "write"))
{
PyErr_Format (PyExc_TypeError, "expected file");
return NULL;
}
write = PyObject_GetAttrString (file, "write");
if (!PyCallable_Check (write)) {
Py_XDECREF(write);
PyErr_Format (PyExc_TypeError, "expected file");
return NULL;
}
string = objToJSON (self, data);
if (string == NULL)
{
Py_XDECREF(write);
return NULL;
}
argtuple = PyTuple_Pack (1, string);
if (argtuple == NULL)
{
Py_XDECREF(write);
return NULL;
}
if (PyObject_CallObject (write, argtuple) == NULL)
{
Py_XDECREF(write);
Py_XDECREF(argtuple);
return NULL;
}
Py_XDECREF(write);
Py_XDECREF(argtuple);
Py_XDECREF(string);
Py_RETURN_NONE;
}
示例8: prop_descr_set
int prop_descr_set(PyObject *self, PyObject *obj, PyObject *value)
{
int res;
if (value != NULL) {
PyObject *result = PyTuple_Pack(2, self, value);
res = PyObject_SetAttrString(obj, "y", result);
Py_DECREF(result);
}
else {
res = PyObject_SetAttrString(obj, "z", self);
}
return res;
}
示例9: set_reduce
static PyObject* set_reduce(BoxedSet* so) noexcept {
PyObject* keys = NULL, * args = NULL, * result = NULL, * dict = NULL;
keys = PySequence_List((PyObject*)so);
if (keys == NULL)
goto done;
args = PyTuple_Pack(1, keys);
if (args == NULL)
goto done;
dict = PyObject_GetAttrString((PyObject*)so, "__dict__");
if (dict == NULL) {
PyErr_Clear();
dict = Py_None;
Py_INCREF(dict);
}
result = PyTuple_Pack(3, Py_TYPE(so), args, dict);
done:
Py_XDECREF(args);
Py_XDECREF(keys);
Py_XDECREF(dict);
return result;
}
示例10: __pycomps_dict_pair_out
PyObject* __pycomps_dict_pair_out(COMPS_HSListItem *hsit) {
PyObject *key, *val, *tuple;
char *x;
key = PyUnicode_FromString((char*) ((COMPS_ObjRTreePair*)hsit->data)->key);
x = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
val = PyUnicode_FromString(x);
free(x);
tuple = PyTuple_Pack(2, key, val);
Py_DECREF(key);
Py_DECREF(val);
return tuple;
}
示例11: PyErr_SetObject
static PyObject *t_descriptor_isValueRequired(t_descriptor *self, t_item *item)
{
t_attribute *attr = self->attr;
if (!PyObject_TypeCheck(item, CItem))
{
PyErr_SetObject(PyExc_TypeError, (PyObject *) item);
return NULL;
}
if (attr)
{
int flags = attr->flags;
t_values *attrDict = get_attrdict(item, flags);
return PyTuple_Pack(2,
attrDict ? (PyObject *) attrDict : Py_None,
attrDict && flags & A_REQUIRED ? Py_True : Py_False);
}
else
return PyTuple_Pack(2, Py_None, Py_False);
}
示例12: math_log
static PyObject *
math_log(PyObject *self, PyObject *args)
{
PyObject *arg;
PyObject *base = NULL;
PyObject *num, *den;
PyObject *ans;
PyObject *newargs;
if (!PyArg_UnpackTuple(args, "log", 1, 2, &arg, &base))
return NULL;
if (base == NULL)
return loghelper(args, log, "d:log", arg);
newargs = PyTuple_Pack(1, arg);
if (newargs == NULL)
return NULL;
num = loghelper(newargs, log, "d:log", arg);
Py_DECREF(newargs);
if (num == NULL)
return NULL;
newargs = PyTuple_Pack(1, base);
if (newargs == NULL) {
Py_DECREF(num);
return NULL;
}
den = loghelper(newargs, log, "d:log", base);
Py_DECREF(newargs);
if (den == NULL) {
Py_DECREF(num);
return NULL;
}
ans = PyNumber_Divide(num, den);
Py_DECREF(num);
Py_DECREF(den);
return ans;
}
示例13: HasOwnership
static bool HasOwnership(PyObject* obj) {
PyObject* addr = GetPointer(obj);
PyObject* name = GetName(obj);
auto_pyobject nameaddr = PyTuple_Pack(2, name, addr);
Py_DECREF(name);
Py_DECREF(addr);
PyObject* dtor = PyDict_GetItem(GetAddrDtorDict(), *nameaddr);
if (!dtor || dtor == Py_None) {
return false;
} else {
return true;
}
}
示例14: KyotoDB_array
static PyObject *
KyotoDB_array(KyotoDB *self, int type)
{
PyObject *result = PyList_New(self->m_db->count());
Py_ssize_t i = 0;
kyotocabinet::BasicDB::Cursor *cursor = self->m_db->cursor();
cursor->jump();
std::string key;
std::string value;
while (cursor->get(&key, &value, true)) {
switch (type) {
case 0: {
PyObject *pkey = KyotoDB_load(key, self->use_pickle);
if (pkey == NULL)
goto onerror;
PyList_SetItem(result, i++, pkey);
break;
}
case 1: {
PyObject *pvalue = KyotoDB_load(value, self->use_pickle);
if (pvalue == NULL)
goto onerror;
PyList_SetItem(result, i++, pvalue);
break;
}
case 2: {
APR pkey(KyotoDB_load(key, self->use_pickle));
if (pkey == NULL)
goto onerror;
APR pvalue(KyotoDB_load(value, self->use_pickle));
if (pvalue == NULL)
goto onerror;
PyList_SetItem(result, i++,
PyTuple_Pack(2, (PyObject *)pkey, (PyObject *)pvalue));
break;
}
}
}
delete cursor;
return result;
onerror:
for (Py_ssize_t j = 0; j < i; j++) {
PyObject *obj = PyList_GetItem(result, j);
Py_DECREF(obj);
}
delete cursor;
return NULL;
}
示例15: range_index
static PyObject *
range_index(rangeobject *r, PyObject *ob)
{
PyObject *idx, *tmp;
int contains;
PyObject *format_tuple, *err_string;
static PyObject *err_format = NULL;
if (!PyLong_CheckExact(ob) && !PyBool_Check(ob)) {
Py_ssize_t index;
index = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_INDEX);
if (index == -1)
return NULL;
return PyLong_FromSsize_t(index);
}
contains = range_contains_long(r, ob);
if (contains == -1)
return NULL;
if (!contains)
goto value_error;
tmp = PyNumber_Subtract(ob, r->start);
if (tmp == NULL)
return NULL;
/* idx = (ob - r.start) // r.step */
idx = PyNumber_FloorDivide(tmp, r->step);
Py_DECREF(tmp);
return idx;
value_error:
/* object is not in the range */
if (err_format == NULL) {
err_format = PyUnicode_FromString("%r is not in range");
if (err_format == NULL)
return NULL;
}
format_tuple = PyTuple_Pack(1, ob);
if (format_tuple == NULL)
return NULL;
err_string = PyUnicode_Format(err_format, format_tuple);
Py_DECREF(format_tuple);
if (err_string == NULL)
return NULL;
PyErr_SetObject(PyExc_ValueError, err_string);
Py_DECREF(err_string);
return NULL;
}