本文整理汇总了C++中PyObject_IsTrue函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_IsTrue函数的具体用法?C++ PyObject_IsTrue怎么用?C++ PyObject_IsTrue使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_IsTrue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: arrayflags_writebackifcopy_set
/* relies on setflags order being write, align, uic */
static int
arrayflags_writebackifcopy_set(PyArrayFlagsObject *self, PyObject *obj)
{
PyObject *res;
if (obj == NULL) {
PyErr_SetString(PyExc_AttributeError,
"Cannot delete flags writebackifcopy attribute");
return -1;
}
if (self->arr == NULL) {
PyErr_SetString(PyExc_ValueError,
"Cannot set flags on array scalars.");
return -1;
}
res = PyObject_CallMethod(self->arr, "setflags", "OOO", Py_None, Py_None,
(PyObject_IsTrue(obj) ? Py_True : Py_False));
if (res == NULL) {
return -1;
}
Py_DECREF(res);
return 0;
}
示例2: handle_boolean
static PyObject *
handle_boolean(lcb_t instance,
int cmd, int mode, PyObject *val, lcb_error_t *err)
{
int cval;
PyObject *ret;
if (val != NULL) {
cval = PyObject_IsTrue(val);
}
if ( (*err = lcb_cntl(instance, mode, cmd, &cval)) != LCB_SUCCESS) {
return NULL;
}
if (cval) {
ret = Py_True;
} else {
ret = Py_False;
}
Py_INCREF(ret);
return ret;
}
示例3: load
static PyObject *
load(XLPyBook *self, PyObject *args)
{
const char* fileName;
int size;
PyObject *raw = NULL;
if(!PyArg_ParseTuple(args, "s#|O!", &fileName, &size, &PyBool_Type, &raw))
return NULL;
if (raw && PyObject_IsTrue(raw)) {
// fileName is treated as the buffer
if(!xlBookLoadRaw(self->handler, fileName, size)) {
Py_RETURN_FALSE;
}
}
else {
if(!xlBookLoad(self->handler, fileName)) {
Py_RETURN_FALSE;
}
}
Py_RETURN_TRUE;
}
示例4: py2scm_exception
static void py2scm_exception(void)
{
PyObject *ptype = NULL, *pvalue = NULL, *ptraceback = NULL;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
PyObject *pvalue_str = NULL;
if (pvalue) {
pvalue_str = PyObject_Str(pvalue);
if (pvalue_str == NULL)
PyErr_Clear();
}
scm_throw(scm_from_utf8_symbol("python-exception"),
scm_list_2(scm_from_locale_string(
((PyTypeObject *)ptype)->tp_name),
pvalue_str != NULL && PyObject_IsTrue(pvalue_str)
? scm_from_locale_string(
PyString_AsString(pvalue_str))
: SCM_BOOL_F));
/* does not return */
fprintf(stderr, "*** scm_error shouldn't have returned ***\n");
}
示例5: recursive_get_files
static int recursive_get_files(LIBMTP_mtpdevice_t *dev, uint32_t storage_id, uint32_t parent_id, PyObject *ans, PyObject *errs, PyObject *callback, unsigned int level) {
LIBMTP_file_t *f, *files;
PyObject *entry, *r;
int ok = 1, recurse;
Py_BEGIN_ALLOW_THREADS;
files = LIBMTP_Get_Files_And_Folders(dev, storage_id, parent_id);
Py_END_ALLOW_THREADS;
if (files == NULL) return ok;
for (f = files; ok && f != NULL; f = f->next) {
entry = build_file_metadata(f, storage_id);
if (entry == NULL) { ok = 0; }
else {
r = PyObject_CallFunction(callback, "OI", entry, level);
recurse = (r != NULL && PyObject_IsTrue(r)) ? 1 : 0;
Py_XDECREF(r);
if (PyList_Append(ans, entry) != 0) { ok = 0; }
Py_DECREF(entry);
}
if (ok && recurse && f->filetype == LIBMTP_FILETYPE_FOLDER) {
if (!recursive_get_files(dev, storage_id, f->item_id, ans, errs, callback, level+1)) {
ok = 0;
}
}
}
// Release memory
f = files;
while (f != NULL) {
files = f; f = f->next; LIBMTP_destroy_file_t(files);
}
return ok;
}
示例6: session_scp_recv
static PyObject *
session_scp_recv(SSH2_SessionObj *self, PyObject *args, PyObject *kwds)
{
char *path;
LIBSSH2_CHANNEL *channel;
struct stat sb;
PyObject* get_stat = NULL;
int get_stat_is_true = 0;
PyObject* chan;
static char *kwlist[] = {"path", "get_stat", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O:scp_recv", kwlist,
&path, &get_stat))
return NULL;
if (get_stat && (get_stat_is_true = PyObject_IsTrue(get_stat)) < 0)
return NULL;
Py_BEGIN_ALLOW_THREADS
channel = libssh2_scp_recv(self->session, path,
get_stat_is_true ? &sb : 0);
Py_END_ALLOW_THREADS
CHECK_RETURN_POINTER(channel, self)
/* Return a tuple of the channel and (size, mode, mtime, atime)
* of the remote file if the get_stat argument is true else return
* a tuple of the channel and None. */
chan = (PyObject *)SSH2_Channel_New(channel, self);
if (!get_stat_is_true)
return Py_BuildValue("(OO)", chan, Py_None);
return Py_BuildValue("(O(LlLL))", chan,
(PY_LONG_LONG)sb.st_size,
(long)sb.st_mode,
(PY_LONG_LONG)sb.st_mtime,
(PY_LONG_LONG)sb.st_atime);
}
示例7: PyDict_GetItem
static t_link *_t_lm__get(t_lm *self, PyObject *key, int load, int noError)
{
PyObject *link = PyDict_GetItem(self->dict, key);
if (link == NULL)
{
if (load && self->flags & LM_LOAD)
{
PyObject *loaded =
PyObject_CallMethodObjArgs((PyObject *) self, _load_NAME,
key, NULL);
if (!loaded)
return NULL;
if (PyObject_IsTrue(loaded))
link = PyDict_GetItem(self->dict, key);
Py_DECREF(loaded);
}
if (link == NULL)
{
if (!noError)
PyErr_SetObject(PyExc_KeyError, key);
return NULL;
}
}
if (!PyObject_TypeCheck(link, &LinkType))
{
PyErr_SetObject(PyExc_TypeError, link);
return NULL;
}
return (t_link *) link;
}
示例8: bppy_set_enabled
/* Python function to set the enabled state of a breakpoint. */
static int
bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
{
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
int cmp;
BPPY_SET_REQUIRE_VALID (self_bp);
if (newvalue == NULL)
{
PyErr_SetString (PyExc_TypeError,
_("Cannot delete `enabled' attribute."));
return -1;
}
else if (! PyBool_Check (newvalue))
{
PyErr_SetString (PyExc_TypeError,
_("The value of `enabled' must be a boolean."));
return -1;
}
cmp = PyObject_IsTrue (newvalue);
if (cmp < 0)
return -1;
TRY
{
if (cmp == 1)
enable_breakpoint (self_bp->bp);
else
disable_breakpoint (self_bp->bp);
}
CATCH (except, RETURN_MASK_ALL)
{
GDB_PY_SET_HANDLE_EXCEPTION (except);
}
示例9: igraphmodule_EdgeSeq_find
/**
* \ingroup python_interface_edgqseq
* \brief Selects a single edge from the edge sequence based on some criteria
*/
PyObject* igraphmodule_EdgeSeq_find(igraphmodule_EdgeSeqObject *self, PyObject *args) {
PyObject *item;
long int i, n;
if (!PyArg_ParseTuple(args, "O", &item))
return NULL;
if (PyCallable_Check(item)) {
/* Call the callable for every edge in the current sequence and return
* the first one for which it evaluates to True */
n = PySequence_Size((PyObject*)self);
for (i=0; i<n; i++) {
PyObject *edge = PySequence_GetItem((PyObject*)self, i);
PyObject *call_result;
if (edge == 0)
return NULL;
call_result = PyObject_CallFunctionObjArgs(item, edge, NULL);
if (call_result == 0) {
Py_DECREF(edge);
return NULL;
}
if (PyObject_IsTrue(call_result)) {
Py_DECREF(call_result);
return edge; /* reference passed to caller */
}
Py_DECREF(call_result);
Py_DECREF(edge);
}
} else if (PyInt_Check(item)) {
/* Integers are interpreted as indices on the edge set and NOT on the
* original, untouched edge sequence of the graph */
return PySequence_GetItem((PyObject*)self, PyInt_AsLong(item));
}
PyErr_SetString(PyExc_IndexError, "no such edge");
return NULL;
}
示例10: if
static PyObject *Py_convert_to_svg(PyObject *self, PyObject *args, PyObject *kwds)
{
py::PathIterator path;
agg::trans_affine trans;
agg::rect_d cliprect;
PyObject *simplifyobj;
bool simplify = false;
int precision;
if (!PyArg_ParseTuple(args,
"O&O&O&Oi:convert_to_svg",
&convert_path,
&path,
&convert_trans_affine,
&trans,
&convert_rect,
&cliprect,
&simplifyobj,
&precision)) {
return NULL;
}
if (simplifyobj == Py_None) {
simplify = path.should_simplify();
} else if (PyObject_IsTrue(simplifyobj)) {
simplify = true;
}
size_t buffersize = path.total_vertices() * (precision + 5) * 4;
std::string buffer;
buffer.reserve(buffersize);
CALL_CPP("convert_to_svg",
(convert_to_svg(path, trans, cliprect, simplify, precision, &buffer[0], &buffersize)));
return PyUnicode_DecodeASCII(&buffer[0], buffersize, "");
}
示例11: already_warned
static int
already_warned(PyObject *registry, PyObject *key, int should_set)
{
PyObject *version_obj, *already_warned;
_Py_IDENTIFIER(version);
if (key == NULL)
return -1;
version_obj = _PyDict_GetItemId(registry, &PyId_version);
if (version_obj == NULL
|| !PyLong_CheckExact(version_obj)
|| PyLong_AsLong(version_obj) != _filters_version) {
PyDict_Clear(registry);
version_obj = PyLong_FromLong(_filters_version);
if (version_obj == NULL)
return -1;
if (_PyDict_SetItemId(registry, &PyId_version, version_obj) < 0) {
Py_DECREF(version_obj);
return -1;
}
Py_DECREF(version_obj);
}
else {
already_warned = PyDict_GetItem(registry, key);
if (already_warned != NULL) {
int rc = PyObject_IsTrue(already_warned);
if (rc != 0)
return rc;
}
}
/* This warning wasn't found in the registry, set it. */
if (should_set)
return PyDict_SetItem(registry, key, Py_True);
return 0;
}
示例12: ConditionObject_is_owned
static PyObject*
ConditionObject_is_owned(ConditionObject *self, PyObject *args)
{
PyObject *res, *res2;
DEBUG("self:%p", self);
res = call_method_args1(self->lock, "acquire", Py_False);
if (res == NULL) {
return NULL;
}
if (PyObject_IsTrue(res)) {
Py_DECREF(res);
res2 = call_method(self->lock, "release");
if (res2 == NULL) {
return NULL;
}
Py_DECREF(res2);
Py_RETURN_FALSE;
} else {
Py_DECREF(res);
Py_RETURN_TRUE;
}
}
示例13: assert
/**
* APPisUserFeasible callback
*
* Called by DIP, we interface with Python
*/
bool DippyDecompApp::APPisUserFeasible(const double* x, const int n_cols, const double tolZero)
{
assert(n_cols == m_modelCore.getModel()->getColNames().size());
PyObject* pSolutionList = pyTupleList_FromDoubleArray(x, m_colList);
PyObject* pTolZero = PyFloat_FromDouble(tolZero);
if (!m_pyIsUserFeasible) {
return true;
}
PyObject* pResult = PyObject_CallMethod(m_pProb, "isUserFeasible", "Od", pSolutionList, pTolZero);
if (pResult == NULL) {
throw UtilException("Error calling method prob.isUserFeasible()", "APPisUserFeasible", "DippyDecompApp");
}
// This should not happen as having isUserFeasible present but not returning a boolean is not good
if (pResult == Py_None) {
// method exists, but not implemented, return true
return true;
}
return (bool)PyObject_IsTrue(pResult);
}
示例14: __pyx_init_filenames
/* Implementation of behnel3 */
static struct PyMethodDef __pyx_methods[] = {
{0, 0, 0, 0}
};
static void __pyx_init_filenames(void); /*proto*/
PyMODINIT_FUNC initbehnel3(void); /*proto*/
PyMODINIT_FUNC initbehnel3(void) {
PyObject *__pyx_1 = 0;
int __pyx_2;
__pyx_init_filenames();
__pyx_m = Py_InitModule4("behnel3", __pyx_methods, 0, 0, PYTHON_API_VERSION);
if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
Py_INCREF(__pyx_m);
__pyx_b = PyImport_AddModule("__builtin__");
if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
__pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_y); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}
__pyx_2 = PyObject_IsTrue(__pyx_1); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}
if (!__pyx_2) {
Py_DECREF(__pyx_1); __pyx_1 = 0;
__pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}
}
if (PyObject_SetAttr(__pyx_m, __pyx_n_x, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
return;
__pyx_L1:;
Py_XDECREF(__pyx_1);
__Pyx_AddTraceback("behnel3");
}
示例15: PySfImage_Copy
static PyObject *
PySfImage_Copy(PySfImage* self, PyObject *args, PyObject *kwds)
{
const char *kwlist[] = {"Source", "DestX", "DestY", "SourceRect", "ApplyAlpha", NULL};
PySfIntRect *SourceRect = NULL;
PySfImage *Source = NULL;
unsigned int DestX, DestY;
PyObject *PyApplyAlpha = NULL;
bool ApplyAlpha = false;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!II|O!O:Image.Copy", (char **)kwlist, &PySfImageType, &Source, &DestX, &DestY, &PySfIntRectType, &SourceRect, &PyApplyAlpha))
return NULL;
if (PyApplyAlpha)
if (PyObject_IsTrue(PyApplyAlpha))
ApplyAlpha = true;
if (SourceRect)
self->obj->Copy(*(Source->obj), DestX, DestY, *(SourceRect->obj), ApplyAlpha);
else
self->obj->Copy(*(Source->obj), DestX, DestY, sf::IntRect(0, 0, 0, 0), ApplyAlpha);
Py_RETURN_NONE;
}