本文整理汇总了C++中PyObject_IsInstance函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_IsInstance函数的具体用法?C++ PyObject_IsInstance怎么用?C++ PyObject_IsInstance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_IsInstance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
PyObject *PyCodec_IgnoreErrors(PyObject *exc)
{
Py_ssize_t end;
if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {
if (PyUnicodeEncodeError_GetEnd(exc, &end))
return NULL;
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {
if (PyUnicodeDecodeError_GetEnd(exc, &end))
return NULL;
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeTranslateError)) {
if (PyUnicodeTranslateError_GetEnd(exc, &end))
return NULL;
}
else {
wrong_exception_type(exc);
return NULL;
}
return Py_BuildValue("(Nn)", PyUnicode_New(0, 0), end);
}
示例2: PyErr_SetString
static PyObject *IOManager_submit(IOManager *self, PyObject *args) {
PyObject *req_s, *iter;
IORequest *item;
Py_ssize_t l;
int rc;
struct iocb **cb, **cb_l;
if (!PyArg_ParseTuple(args, "O", &req_s)) return NULL;
if ((l = PySequence_Size(req_s)) < 0) return NULL;
if (l > (self->nr_events - self->pending_events)) {
PyErr_SetString(PyExc_ValueError, "Queue length exceeded.");
return NULL;
}
cb = self->cbs;
cb_l = cb + (self->nr_events - self->pending_events);
if (!(iter = PyObject_GetIter(req_s))) return NULL;
for (; (item = (IORequest*) PyIter_Next(iter)); cb++) {
if (!PyObject_IsInstance((PyObject*) item, (PyObject*) &IORequestType)) {
Py_DECREF(item);
PyErr_SetString(PyExc_TypeError, "Elements of argument 0 must be of type IORequest.");
return IOM_iocb_cleanup(self, cb+1);
}
if (cb == cb_l) {
Py_DECREF(item);
PyErr_SetString(PyExc_ValueError, "Queue length exceeded (secondary check)");
return IOM_iocb_cleanup(self, cb+1);
}
if (item->submitted) {
Py_DECREF(item);
PyErr_SetString(PyExc_ValueError, "Element of argument 0 had already been submitted earlier.");
return IOM_iocb_cleanup(self, cb+1);
}
item->submitted = 1;
item->iocb.u.c.resfd = self->fd;
*cb = &item->iocb;
}
if (PyErr_Occurred()) return IOM_iocb_cleanup(self, cb);
l = cb - self->cbs;
rc = io_submit(self->ctx, l, self->cbs);
if (rc < 0) {
errno = -rc;
PyErr_SetFromErrno(PyExc_OSError);
return IOM_iocb_cleanup(self, cb);
}
/* Keep one reference to each element read from the iterable, to make sure
they aren't deallocated while we wait for their IO requests to complete
*/
self->pending_events += l;
Py_RETURN_NONE;
}
示例3: rich_compare
static PyObject*
rich_compare(PyObject *a, PyObject *b, int op)
{
if (op == Py_EQ || op == Py_NE)
{
if (! (PyObject_IsInstance(a, (PyObject*)&ChipNameType) &&
PyObject_IsInstance(b, (PyObject*)&ChipNameType)))
{
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
sensors_chip_name *c1 = &((ChipName*)a)->chip_name;
sensors_chip_name *c2 = &((ChipName*)b)->chip_name;
int equal = (((c1->prefix == NULL && c2->prefix == NULL) ||
strcmp(c1->prefix, c2->prefix) == 0) &&
c1->bus.type == c2->bus.type &&
c1->bus.nr == c2->bus.nr &&
c1->addr == c2->addr &&
((c1->path == NULL && c2->path == NULL) ||
strcmp(c1->path, c2->path) == 0));
int ret = op == Py_EQ ? equal : !equal;
if (ret)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
else
{
PyErr_SetString(
PyExc_TypeError,
"ChipName only supports the == and != comparison operators");
return NULL;
}
}
示例4: psyco_conn_cursor
static PyObject *
psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds)
{
const char *name = NULL;
PyObject *obj, *factory = NULL;
static char *kwlist[] = {"name", "cursor_factory", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sO", kwlist,
&name, &factory)) {
return NULL;
}
EXC_IF_CONN_CLOSED(self);
if (self->status != CONN_STATUS_READY &&
self->status != CONN_STATUS_BEGIN) {
PyErr_SetString(OperationalError,
"asynchronous connection attempt underway");
return NULL;
}
if (name != NULL && self->async == 1) {
PyErr_SetString(ProgrammingError,
"asynchronous connections "
"cannot produce named cursors");
return NULL;
}
Dprintf("psyco_conn_cursor: new cursor for connection at %p", self);
Dprintf("psyco_conn_cursor: parameters: name = %s", name);
if (factory == NULL) factory = (PyObject *)&cursorType;
if (name)
obj = PyObject_CallFunction(factory, "Os", self, name);
else
obj = PyObject_CallFunction(factory, "O", self);
if (obj == NULL) return NULL;
if (PyObject_IsInstance(obj, (PyObject *)&cursorType) == 0) {
PyErr_SetString(PyExc_TypeError,
"cursor factory must be subclass of psycopg2._psycopg.cursor");
Py_DECREF(obj);
return NULL;
}
Dprintf("psyco_conn_cursor: new cursor at %p: refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
return obj;
}
示例5: pycbc_multiresult_maybe_raise
/**
* This function raises exceptions from the MultiResult object, as required
*/
int
pycbc_multiresult_maybe_raise(pycbc_MultiResult *self)
{
PyObject *type = NULL, *value = NULL, *traceback = NULL;
if (self->errop == NULL && self->exceptions == NULL) {
return 0;
}
if (self->exceptions) {
PyObject *tuple = PyList_GetItem(self->exceptions, 0);
assert(tuple);
assert(PyTuple_Size(tuple) == 3);
type = PyTuple_GetItem(tuple, 0);
value = PyTuple_GetItem(tuple, 1);
traceback = PyTuple_GetItem(tuple, 2);
PyErr_NormalizeException(&type, &value, &traceback);
Py_XINCREF(type);
Py_XINCREF(value);
Py_XINCREF(traceback);
assert(PyObject_IsInstance(value, pycbc_helpers.default_exception));
} else {
pycbc_Result *res = (pycbc_Result*)self->errop;
/** Craft an exception based on the operation */
PYCBC_EXC_WRAP_KEY(PYCBC_EXC_LCBERR, res->rc, "Operational Error", res->key);
/** Now we have an exception. Let's fetch it back */
PyErr_Fetch(&type, &value, &traceback);
PyObject_SetAttrString(value, "result", (PyObject*)res);
}
PyObject_SetAttrString(value, "all_results", (PyObject*)self);
PyErr_Restore(type, value, traceback);
/**
* This is needed since the exception object will later contain
* a reference to ourselves. If we don't free the original exception,
* then we'll be stuck with a circular reference
*/
Py_XDECREF(self->exceptions);
Py_XDECREF(self->errop);
self->exceptions = NULL;
self->errop = NULL;
return 1;
}
示例6: initSetIteration
/* initSetIteration
*
* Start the set iteration protocol. See the comments at struct SetIteration.
*
* Arguments
* i The address of a SetIteration control struct.
* s The address of the set, bucket, BTree, ..., to be iterated.
* useValues Boolean; if true, and s has values (is a mapping), copy
* them into i->value each time i->next() is called; else
* ignore s's values even if s is a mapping.
*
* Return
* 0 on success; -1 and an exception set if error.
* i.usesValue is set to 1 (true) if s has values and useValues was
* true; else usesValue is set to 0 (false).
* i.set gets a new reference to s, or to some other object used to
* iterate over s.
* i.position is set to 0.
* i.next is set to an appropriate iteration function.
* i.key and i.value are left alone.
*
* Internal
* i.position < 0 means iteration terminated.
* i.position = 0 means iteration hasn't yet begun (next() hasn't
* been called yet).
* In all other cases, i.key, and possibly i.value, own references.
* These must be cleaned up, either by next() routines, or by
* finiSetIteration.
* next() routines must ensure the above. They should return without
* doing anything when i.position < 0.
* It's the responsibility of {init, fini}setIteration to clean up
* the reference in i.set, and to ensure that no stale references
* live in i.key or i.value if iteration terminates abnormally.
* A SetIteration struct has been cleaned up iff i.set is NULL.
*/
static int
initSetIteration(SetIteration *i, PyObject *s, int useValues)
{
i->set = NULL;
i->position = -1; /* set to 0 only on normal return */
i->usesValue = 0; /* assume it's a set or that values aren't iterated */
if (PyObject_IsInstance(s, (PyObject *)&BucketType))
{
i->set = s;
Py_INCREF(s);
if (useValues)
{
i->usesValue = 1;
i->next = nextBucket;
}
else
i->next = nextSet;
}
else if (PyObject_IsInstance(s, (PyObject *)&SetType))
{
i->set = s;
Py_INCREF(s);
i->next = nextSet;
}
else if (PyObject_IsInstance(s, (PyObject *)&BTreeType))
{
i->set = BTree_rangeSearch(BTREE(s), NULL, NULL, 'i');
UNLESS(i->set) return -1;
if (useValues)
{
i->usesValue = 1;
i->next = nextBTreeItems;
}
else
i->next = nextTreeSetItems;
}
示例7: if
PyObject *PyCodec_IgnoreErrors(PyObject *exc)
{
Py_ssize_t end;
if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {
if (PyUnicodeEncodeError_GetEnd(exc, &end))
return NULL;
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {
if (PyUnicodeDecodeError_GetEnd(exc, &end))
return NULL;
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeTranslateError)) {
if (PyUnicodeTranslateError_GetEnd(exc, &end))
return NULL;
}
else {
wrong_exception_type(exc);
return NULL;
}
/* ouch: passing NULL, 0, pos gives None instead of u'' */
return Py_BuildValue("(u#n)", &end, 0, end);
}
示例8: ChecksumV1_update
static PyObject*
ChecksumV1_update(accuraterip_ChecksumV1* self, PyObject *args)
{
PyObject *framelist_obj;
pcm_FrameList *framelist;
unsigned i;
if (!PyArg_ParseTuple(args, "O", &framelist_obj))
return NULL;
/*ensure framelist_obj is a FrameList object*/
if (PyObject_IsInstance(framelist_obj, self->framelist_class)) {
framelist = (pcm_FrameList*)framelist_obj;
} else {
PyErr_SetString(PyExc_TypeError, "objects must be of type FrameList");
return NULL;
}
/*ensure FrameList is CD-formatted*/
if (framelist->channels != 2) {
PyErr_SetString(PyExc_ValueError,
"FrameList must be 2 channels");
return NULL;
}
if (framelist->bits_per_sample != 16) {
PyErr_SetString(PyExc_ValueError,
"FrameList must be 16 bits per sample");
return NULL;
}
/*update CRC with values from FrameList*/
for (i = 0; i < framelist->frames; i++) {
if ((self->track_index >= self->start_offset) &&
(self->track_index <= self->end_offset)) {
const int left_s = framelist->samples[i * 2];
const int right_s = framelist->samples[i * 2 + 1];
const unsigned left_u =
left_s >= 0 ? left_s : (1 << 16) - (-left_s);
const unsigned right_u =
right_s >= 0 ? right_s : (1 << 16) - (-right_s);
const unsigned value = (right_u << 16) | left_u;
self->checksum += (value * self->track_index);
}
self->track_index++;
}
Py_INCREF(Py_None);
return Py_None;
}
示例9: Tokenizer_emit_all
/*
Write a series of tokens to the current stack at once.
*/
int Tokenizer_emit_all(Tokenizer* self, PyObject* tokenlist)
{
int pushed = 0;
PyObject *stack, *token, *left, *right, *text;
Textbuffer* buffer;
Py_ssize_t size;
if (PyList_GET_SIZE(tokenlist) > 0) {
token = PyList_GET_ITEM(tokenlist, 0);
switch (PyObject_IsInstance(token, Text)) {
case 0:
break;
case 1: {
pushed = 1;
buffer = self->topstack->textbuffer;
if (buffer->length == 0)
break;
left = Textbuffer_render(buffer);
if (!left)
return -1;
right = PyObject_GetAttrString(token, "text");
if (!right)
return -1;
text = PyUnicode_Concat(left, right);
Py_DECREF(left);
Py_DECREF(right);
if (!text)
return -1;
if (PyObject_SetAttrString(token, "text", text)) {
Py_DECREF(text);
return -1;
}
Py_DECREF(text);
if (Textbuffer_reset(buffer))
return -1;
break;
}
case -1:
return -1;
}
}
if (!pushed) {
if (Tokenizer_push_textbuffer(self))
return -1;
}
stack = self->topstack->stack;
size = PyList_GET_SIZE(stack);
if (PyList_SetSlice(stack, size, size, tokenlist))
return -1;
return 0;
}
示例10: LDAPConnection_init
/* Initialize the LDAPConnection. */
static int
LDAPConnection_init(LDAPConnection *self, PyObject *args, PyObject *kwds) {
PyObject *async_obj = NULL;
PyObject *client = NULL;
PyObject *ldapclient_type = NULL;
PyObject *tmp = NULL;
PyObject *page_size = NULL, *sort_list = NULL;
static char *kwlist[] = {"client", "async", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O!", kwlist, &client,
&PyBool_Type, &async_obj)) {
return -1;
}
if (async_obj != NULL) self->async = PyObject_IsTrue(async_obj);
ldapclient_type = load_python_object("pyldap.ldapclient", "LDAPClient");
if (ldapclient_type == NULL ||
!PyObject_IsInstance(client, ldapclient_type)) {
return -1;
}
Py_DECREF(ldapclient_type);
if (client) {
tmp = self->client;
Py_INCREF(client);
self->client = client;
Py_XDECREF(tmp);
/* Get page size from the client. */
page_size = PyObject_GetAttrString(self->client, "_LDAPClient__page_size");
if (page_size == NULL) return -1;
self->page_size = (int)PyLong_AsLong(page_size);
Py_DECREF(page_size);
if (PyErr_Occurred()) return -1;
/* Get sort list from the client. */
sort_list = PyObject_GetAttrString(self->client, "_LDAPClient__sort_attrs");
if (PyList_Size(sort_list) > 0) {
self->sort_list = PyList2LDAPSortKeyList(sort_list);
if (self->sort_list == NULL) {
PyErr_BadInternalCall();
return -1;
}
}
return connecting(self);
}
return -1;
}
示例11: set_errors
static void set_errors(Tango::EventData &event_data, boost::python::object &error)
{
PyObject* error_ptr = error.ptr();
if (PyObject_IsInstance(error_ptr, PyTango_DevFailed.ptr()))
{
Tango::DevFailed df;
boost::python::object error_list = error.attr("args");
sequencePyDevError_2_DevErrorList(error_list.ptr(), event_data.errors);
}
else
{
sequencePyDevError_2_DevErrorList(error_ptr, event_data.errors);
}
}
示例12: IsInstanceForThread
bool IsInstanceForThread(PyObject* param, const char* szModule, const char* szClass, PyObject** pcls)
{
// Like PyObject_IsInstance but compares against a class specific to the current thread's
// interpreter, for proper subinterpreter support. Uses GetClassForThread.
//
// If `param` is an instance of the given class, true is returned and a new reference to
// the class, specific to the current thread, is returned via pcls. The caller is
// responsible for decrementing the class.
//
// If `param` is not an instance, true is still returned (!) but *pcls will be zero.
//
// False is only returned when an exception has been raised. (That is, the return value is
// not used to indicate whether the instance check matched or not.)
if (param == 0)
{
*pcls = 0;
return true;
}
PyObject* cls = GetClassForThread(szModule, szClass);
if (!cls)
{
*pcls = 0;
return false;
}
int n = PyObject_IsInstance(param, cls);
// (The checks below can be compressed into just a few lines, but I was concerned it
// wouldn't be clear.)
if (n == 1)
{
// We have a match.
*pcls = cls;
return true;
}
Py_DECREF(cls);
*pcls = 0;
if (n == 0)
{
// No exception, but not a match.
return true;
}
// n == -1; an exception occurred
return false;
}
示例13: _cairo_pattern_to_gvalue
static int
_cairo_pattern_to_gvalue(GValue *value, PyObject *obj)
{
if (obj == Py_None) {
g_value_set_boxed(value, NULL);
return 0;
}
if (!(PyObject_IsInstance(obj, (PyObject *) &PycairoPattern_Type)))
return -1;
g_value_set_boxed(value, ((PycairoPattern*)(obj))->pattern);
return 0;
}
示例14: thunk_ipower
static PyObject *
thunk_ipower(PyObject *a, PyObject *b, PyObject *c)
{
PyObject *val;
if (PyObject_IsInstance(a, (PyObject*) &thunk_type)) {
val = _strict_eval_borrowed(a);
return PyNumber_InPlacePower(val, b, c);
}
else {
val = _strict_eval_borrowed(b);
return PyNumber_InPlacePower(a, val, c);
}
}
示例15: getDerivativeMultiVectorObjectAttr
EpetraExt::ModelEvaluator::DerivativeMultiVector
getDerivativeMultiVectorObjectAttr(PyObject * object, CONST char * name)
{
static
PyObject * classDerivativeMultiVector = NULL;
if (!classDerivativeMultiVector)
{
classDerivativeMultiVector = getClassFromModule(PyTrilinosEpetraExt,
"DerivativeMultiVector");
if (!classDerivativeMultiVector) throw PythonException();
}
PyObject * value = PyObject_GetAttrString(object, name);
if (!value) throw PythonException();
if (!PyObject_IsInstance(value, classDerivativeMultiVector))
{
PyErr_Format(PyExc_TypeError, "Attribute '%s' is not of type DerivativeMultiVector", name);
Py_DECREF(value);
throw PythonException();
}
// multiVector attribute
Teuchos::RCP<Epetra_MultiVector> multiVector =
getEpetraMultiVectorObjectAttr(value, "multiVector");
// orientation attribute
EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation orientation;
CONST char * linearity = getStringObjectAttr(value, "linearity");
if (strncmp(linearity, "mv_by_col", 9) == 0)
orientation = EpetraExt::ModelEvaluator::DERIV_MV_BY_COL;
if (strncmp(linearity, "trans_mv_by_row", 15) == 0)
orientation = EpetraExt::ModelEvaluator::DERIV_TRANS_MV_BY_ROW;
// paramIndexes attribute
PyObject * seq = PyObject_GetAttrString(value, "paramIndexes");
if (!seq) throw PythonException();
Py_ssize_t len = PySequence_Length(seq);
if (len < 0) throw PythonException();
Teuchos::Array<int> paramIndexes(len);
for (Py_ssize_t i = 0; i < len; ++i)
{
PyObject * item = PySequence_GetItem(seq, i);
if (!item) throw PythonException();
paramIndexes[i] = (int) PyInt_AsLong(item);
Py_DECREF(item);
if (PyErr_Occurred()) throw PythonException();
}
Py_DECREF(seq);
Py_DECREF(value);
// Result
return EpetraExt::ModelEvaluator::DerivativeMultiVector(multiVector, orientation,
paramIndexes);
}