本文整理汇总了C++中PyLong_Check函数的典型用法代码示例。如果您正苦于以下问题:C++ PyLong_Check函数的具体用法?C++ PyLong_Check怎么用?C++ PyLong_Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyLong_Check函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: PyErr_Format
static PyObject *Triton_getRegValue(PyObject *self, PyObject *regId) {
RegisterOperand reg;
uint64 tritonReg;
if (!PyLong_Check(regId) && !PyInt_Check(regId))
return PyErr_Format(PyExc_TypeError, "getRegValue(): expected a register id (IDREF.REG) as argument");
if (!ap.getCurrentCtxH())
return PyErr_Format(PyExc_TypeError, "getRegValue(): Can't call getRegValue() right now. You must run the program before.");
tritonReg = PyLong_AsLong(regId);
reg = createTmpReg(tritonReg);
if (tritonReg >= ID_XMM0 && tritonReg <= ID_XMM15){
uint128 value = ap.getSSERegisterValue(reg);
return uint128ToPyLongObject(value);
}
return Py_BuildValue("k", ap.getRegisterValue(reg));
}
开发者ID:killbug2004,项目名称:Triton,代码行数:20,代码来源:tritonCallbacks.cpp
示例2: validItem
static int validItem(rpmTagClass tclass, PyObject *item)
{
int rc;
switch (tclass) {
case RPM_NUMERIC_CLASS:
rc = (PyLong_Check(item) || PyInt_Check(item));
break;
case RPM_STRING_CLASS:
rc = (PyBytes_Check(item) || PyUnicode_Check(item));
break;
case RPM_BINARY_CLASS:
rc = PyBytes_Check(item);
break;
default:
rc = 0;
break;
}
return rc;
}
开发者ID:kaltsi,项目名称:rpm,代码行数:20,代码来源:header-py.c
示例3: convert_to_double
/* adapted from Python source, floatobject.c:convert_to_double */
int
convert_to_double(PyObject *obj, double *dbl)
{
if (PyFloat_Check(obj)) {
*dbl = PyFloat_AS_DOUBLE(obj);
#ifndef IS_PY3K
} else if (PyInt_Check(obj)) {
*dbl = (double)PyInt_AS_LONG(obj);
#endif
} else if (PyLong_Check(obj)) {
*dbl = PyLong_AsDouble(obj);
if (*dbl == -1.0 && PyErr_Occurred()) {
return 0;
}
} else {
PyErr_SetString(PyExc_ValueError, "Expected a number");
return 0;
}
return 1;
}
开发者ID:shengtu,项目名称:pypybox2d,代码行数:21,代码来源:commonmodule.c
示例4: AerospikePredicates_Equals
static PyObject * AerospikePredicates_Equals(PyObject * self, PyObject * args)
{
PyObject * py_bin = NULL;
PyObject * py_val = NULL;
if (PyArg_ParseTuple(args, "OO:equals",
&py_bin, &py_val) == false) {
goto exit;
}
if (PyInt_Check(py_val) || PyLong_Check(py_val)) {
return Py_BuildValue("iiOO", AS_PREDICATE_EQUAL, AS_INDEX_NUMERIC, py_bin, py_val);
} else if (PyString_Check(py_val) || PyUnicode_Check(py_val)) {
return Py_BuildValue("iiOO", AS_PREDICATE_EQUAL, AS_INDEX_STRING, py_bin, py_val);
}
exit:
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:anuranjit,项目名称:aerospike-client-python,代码行数:20,代码来源:predicates.c
示例5: get_ulonglong
static int
get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
{
unsigned PY_LONG_LONG x;
v = get_pylong(v);
if (v == NULL)
return -1;
assert(PyLong_Check(v));
x = PyLong_AsUnsignedLongLong(v);
Py_DECREF(v);
if (x == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_SetString(StructError,
"argument out of range");
return -1;
}
*p = x;
return 0;
}
开发者ID:sys-git,项目名称:pyopencl,代码行数:20,代码来源:_pvt_struct_v3.cpp
示例6: ptorLong
VALUE ptorLong(PyObject* pNum)
{
if(!PyLong_Check(pNum)) return Qnil;
VALUE rNum;
long cNum;
cNum = PyLong_AsLong(pNum);
if(PyErr_ExceptionMatches(PyExc_OverflowError))
{
rpPythonError();
return Qnil;
}
rNum = INT2NUM(cNum);
return rNum;
}
开发者ID:hltbra,项目名称:rubypython,代码行数:20,代码来源:ptor.c
示例7: BufferObj_set_cfa
static int BufferObj_set_cfa(Buffer *self, PyObject *value, void *_)
{
long cfa_id;
if (PyInt_Check(value))
cfa_id = PyInt_AS_LONG(value);
else if (PyLong_Check(value))
cfa_id = PyLong_AsLong(value);
else
return -1;
if (cfa_id >= _PLDRAW_CFA_N_) {
PyErr_SetString(PyExc_ValueError, "Invalid CFA identifier");
return -1;
}
pldraw_set_cfa(self->pldraw, cfa_id);
return Buffer_update_cached_colors(self);
}
开发者ID:plasticlogic,项目名称:pyplsdk,代码行数:20,代码来源:_plsdk.c
示例8: NumberVar_SetValue
//-----------------------------------------------------------------------------
// NumberVar_SetValue()
// Set the value of the variable.
//-----------------------------------------------------------------------------
static int NumberVar_SetValue(
udt_NumberVar *var, // variable to set value for
unsigned pos, // array position to set
PyObject *value) // value to set
{
#if PY_MAJOR_VERSION < 3
if (PyInt_Check(value))
return NumberVar_SetValueFromInteger(var, pos, value);
#endif
if (PyLong_Check(value))
return NumberVar_SetValueFromLong(var, pos, value);
if (PyBool_Check(value))
return NumberVar_SetValueFromBoolean(var, pos, value);
if (PyFloat_Check(value))
return NumberVar_SetValueFromFloat(var, pos, value);
if (Py_TYPE(value) == g_DecimalType)
return NumberVar_SetValueFromDecimal(var, pos, value);
PyErr_SetString(PyExc_TypeError, "expecting numeric data");
return -1;
}
开发者ID:15580056814,项目名称:hue,代码行数:24,代码来源:NumberVar.c
示例9: get_size_t
static int
get_size_t(PyObject *v, size_t *p)
{
size_t x;
v = get_pylong(v);
if (v == NULL)
return -1;
assert(PyLong_Check(v));
x = PyLong_AsSize_t(v);
Py_DECREF(v);
if (x == (size_t)-1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_SetString(StructError,
"argument out of range");
return -1;
}
*p = x;
return 0;
}
开发者ID:sys-git,项目名称:pyopencl,代码行数:20,代码来源:_pvt_struct_v3.cpp
示例10: PyImport_AddModule
bool ChPythonEngine::GetInteger(const char* variable, int& return_val)
{
PyObject * module = PyImport_AddModule("__main__"); // borrowed reference
assert(module); // __main__ should always exist
PyObject * dictionary = PyModule_GetDict(module); // borrowed reference
assert(dictionary); // __main__ should have a dictionary
PyObject * result = PyDict_GetItemString(dictionary, variable); // borrowed reference
if (!result)
return false;
if (PyLong_Check(result))
{
return_val = PyLong_AsLong(result);
return true;
}
return false;
}
开发者ID:DavidHammen,项目名称:chrono,代码行数:20,代码来源:ChPython.cpp
示例11: ReplicateAttributes_SetNewPeriodicOrigin
/*static*/ PyObject *
ReplicateAttributes_SetNewPeriodicOrigin(PyObject *self, PyObject *args)
{
ReplicateAttributesObject *obj = (ReplicateAttributesObject *)self;
double *dvals = obj->data->GetNewPeriodicOrigin();
if(!PyArg_ParseTuple(args, "ddd", &dvals[0], &dvals[1], &dvals[2]))
{
PyObject *tuple;
if(!PyArg_ParseTuple(args, "O", &tuple))
return NULL;
if(PyTuple_Check(tuple))
{
if(PyTuple_Size(tuple) != 3)
return NULL;
PyErr_Clear();
for(int i = 0; i < PyTuple_Size(tuple); ++i)
{
PyObject *item = PyTuple_GET_ITEM(tuple, i);
if(PyFloat_Check(item))
dvals[i] = PyFloat_AS_DOUBLE(item);
else if(PyInt_Check(item))
dvals[i] = double(PyInt_AS_LONG(item));
else if(PyLong_Check(item))
dvals[i] = PyLong_AsDouble(item);
else
dvals[i] = 0.;
}
}
else
return NULL;
}
// Mark the newPeriodicOrigin in the object as modified.
obj->data->SelectNewPeriodicOrigin();
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:HarinarayanKrishnan,项目名称:VisIt28RC_Trunk,代码行数:41,代码来源:PyReplicateAttributes.C
示例12: get_addr_from_python
int
get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
{
if (gdbpy_is_value_object (obj))
*addr = value_as_address (value_object_to_value (obj));
else if (PyLong_Check (obj))
{
/* Assume CORE_ADDR corresponds to unsigned long. */
*addr = PyLong_AsUnsignedLong (obj);
if (PyErr_Occurred () != NULL)
return 0;
}
else if (PyInt_Check (obj))
{
long val;
/* Assume CORE_ADDR corresponds to unsigned long. */
val = PyInt_AsLong (obj);
if (val >= 0)
*addr = val;
else
{
/* If no error ocurred, VAL is indeed negative. */
if (PyErr_Occurred () != NULL)
return 0;
PyErr_SetString (PyExc_ValueError,
_("Supplied address is negative."));
return 0;
}
}
else
{
PyErr_SetString (PyExc_TypeError,
_("Invalid type for address."));
return 0;
}
return 1;
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.toolchain,代码行数:41,代码来源:py-utils.c
示例13: TransferFunctionWidget_SetPosition
/*static*/ PyObject *
TransferFunctionWidget_SetPosition(PyObject *self, PyObject *args)
{
TransferFunctionWidgetObject *obj = (TransferFunctionWidgetObject *)self;
float *fvals = obj->data->GetPosition();
if(!PyArg_ParseTuple(args, "ffffffff", &fvals[0], &fvals[1], &fvals[2], &fvals[3], &fvals[4], &fvals[5], &fvals[6], &fvals[7]))
{
PyObject *tuple;
if(!PyArg_ParseTuple(args, "O", &tuple))
return NULL;
if(PyTuple_Check(tuple))
{
if(PyTuple_Size(tuple) != 8)
return NULL;
PyErr_Clear();
for(int i = 0; i < PyTuple_Size(tuple); ++i)
{
PyObject *item = PyTuple_GET_ITEM(tuple, i);
if(PyFloat_Check(item))
fvals[i] = float(PyFloat_AS_DOUBLE(item));
else if(PyInt_Check(item))
fvals[i] = float(PyInt_AS_LONG(item));
else if(PyLong_Check(item))
fvals[i] = float(PyLong_AsDouble(item));
else
fvals[i] = 0.;
}
}
else
return NULL;
}
// Mark the Position in the object as modified.
obj->data->SelectPosition();
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:HarinarayanKrishnan,项目名称:VisIt28RC_Trunk,代码行数:41,代码来源:PyTransferFunctionWidget.C
示例14: music_delivery
static int
music_delivery(sp_session * session, const sp_audioformat * format,
const void *frames, int num_frames)
{
PyGILState_STATE gstate;
PyObject *res, *method;
#ifdef DEBUG
fprintf(stderr, "[DEBUG]-session- >> music_delivery called\n");
#endif
gstate = PyGILState_Ensure();
int siz = frame_size(format);
PyObject *pyframes = PyBuffer_FromMemory((void *)frames, num_frames * siz);
Session *psession =
(Session *) PyObject_CallObject((PyObject *)&SessionType, NULL);
psession->_session = session;
PyObject *client = (PyObject *)sp_session_userdata(session);
method = PyObject_GetAttrString(client, "music_delivery");
res =
PyObject_CallFunction(method, "OOiiiii", psession,
pyframes, siz, num_frames, format->sample_type,
format->sample_rate, format->channels);
int consumed = num_frames; // assume all consumed
if (!res)
PyErr_WriteUnraisable(method);
if (PyInt_Check(res))
consumed = (int)PyInt_AsLong(res);
else if (PyLong_Check(res))
consumed = (int)PyLong_AsLong(res);
else {
PyErr_SetString(PyExc_TypeError,
"music_delivery must return an integer");
PyErr_WriteUnraisable(method);
}
Py_DECREF(pyframes);
Py_DECREF(psession);
Py_XDECREF(res);
Py_DECREF(method);
PyGILState_Release(gstate);
return consumed;
}
开发者ID:JoeConyers,项目名称:SpotifyRemote,代码行数:41,代码来源:session.c
示例15: RadialResampleAttributes_SetCenter
/*static*/ PyObject *
RadialResampleAttributes_SetCenter(PyObject *self, PyObject *args)
{
RadialResampleAttributesObject *obj = (RadialResampleAttributesObject *)self;
float *fvals = obj->data->GetCenter();
if(!PyArg_ParseTuple(args, "fff", &fvals[0], &fvals[1], &fvals[2]))
{
PyObject *tuple;
if(!PyArg_ParseTuple(args, "O", &tuple))
return NULL;
if(PyTuple_Check(tuple))
{
if(PyTuple_Size(tuple) != 3)
return NULL;
PyErr_Clear();
for(int i = 0; i < PyTuple_Size(tuple); ++i)
{
PyObject *item = PyTuple_GET_ITEM(tuple, i);
if(PyFloat_Check(item))
fvals[i] = float(PyFloat_AS_DOUBLE(item));
else if(PyInt_Check(item))
fvals[i] = float(PyInt_AS_LONG(item));
else if(PyLong_Check(item))
fvals[i] = float(PyLong_AsDouble(item));
else
fvals[i] = 0.;
}
}
else
return NULL;
}
// Mark the center in the object as modified.
obj->data->SelectCenter();
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:41,代码来源:PyRadialResampleAttributes.C
示例16: Py_INCREF
PyObject* pyInfoTree::graft(pyInfoTreeObject* self, PyObject* args, PyObject* kwds) {
const char* path = nullptr;
PyObject* val = 0;
static char* kwlist[] = {(char*)"path", (char*)"value", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", kwlist, &path, &val)) {
Py_INCREF(Py_False);
return Py_False;
}
if (PyBool_Check(val)) {
if (!self->tree->graft(path, InfoTree::make(PyObject_IsTrue(val) ? true : false))) {
Py_INCREF(Py_False);
return Py_False;
}
} else if (PyLong_Check(val)) {
if (!self->tree->graft(path, InfoTree::make(PyLong_AsLong(val)))) {
Py_INCREF(Py_False);
return Py_False;
}
} else if (PyFloat_Check(val)) {
if (!self->tree->graft(path, InfoTree::make(PyFloat_AsDouble(val)))) {
Py_INCREF(Py_False);
return Py_False;
}
} else if (PyUnicode_Check(val)) {
if (!self->tree->graft(path, InfoTree::make(PyUnicode_AsUTF8(val)))) {
Py_INCREF(Py_False);
return Py_False;
}
} else if (PyObject_IsInstance(val, reinterpret_cast<PyObject*>(&pyInfoTree::pyType))) {
if (!self->tree->graft(path, reinterpret_cast<pyInfoTree::pyInfoTreeObject*>(val)->keepAlive)) {
Py_INCREF(Py_False);
return Py_False;
}
} else { // unsorted PyObject type
Py_INCREF(Py_False);
return Py_False;
}
// return true if everything went well
Py_INCREF(Py_True);
return Py_True;
}
开发者ID:nicobou,项目名称:switcher,代码行数:41,代码来源:pyinfotree.cpp
示例17: SpiDev_set_mode
static int
SpiDev_set_mode(SpiDevObject *self, PyObject *val, void *closure)
{
uint8_t mode, tmp;
if (val == NULL) {
PyErr_SetString(PyExc_TypeError,
"Cannot delete attribute");
return -1;
}
#if PY_MAJOR_VERSION < 3
if (PyInt_Check(val)) {
mode = PyInt_AS_LONG(val);
} else
#endif
{
if (PyLong_Check(val)) {
mode = PyLong_AS_LONG(val);
} else {
PyErr_SetString(PyExc_TypeError,
"The mode attribute must be an integer");
return -1;
}
}
if ( mode > 3 ) {
PyErr_SetString(PyExc_TypeError,
"The mode attribute must be an integer"
"between 0 and 3.");
return -1;
}
// clean and set CPHA and CPOL bits
tmp = ( self->mode & ~(SPI_CPHA | SPI_CPOL) ) | mode ;
__spidev_set_mode(self->fd, tmp);
self->mode = tmp;
return 0;
}
开发者ID:Gadgetoid,项目名称:py-spidev,代码行数:41,代码来源:spidev_module.c
示例18:
PyObject *KX_VertexProxy::PySetRGBA(PyObject *value)
{
if (PyLong_Check(value)) {
int rgba = PyLong_AsLong(value);
m_vertex->SetRGBA(rgba);
m_mesh->SetMeshModified(true);
Py_RETURN_NONE;
}
else {
MT_Vector4 vec;
if (PyVecTo(value, vec))
{
m_vertex->SetRGBA(vec);
m_mesh->SetMeshModified(true);
Py_RETURN_NONE;
}
}
PyErr_SetString(PyExc_TypeError, "vert.setRGBA(value): KX_VertexProxy, expected a 4D vector or an int");
return NULL;
}
开发者ID:danielmarg,项目名称:blender-main,代码行数:21,代码来源:KX_VertexProxy.cpp
示例19: to_object
Object to_object(PyObject *obj){
if (PyBool_Check(obj))
return AB::to_object( obj == Py_True );
if (PyFloat_Check(obj))
return AB::to_object( PyFloat_AsDouble(obj) );
if (PyLong_Check(obj))
return AB::to_object( (int)PyLong_AsLong(obj) );
if (PyInt_Check(obj))
return AB::to_object( (int)PyInt_AsLong(obj) );
if (PyUnicode_Check(obj)){
Py_ssize_t size;
const char *str;
PyObject_AsCharBuffer(obj, &str, &size);
std::string str8{str};
PyMem_Free((void*)str);
return AB::to_object( str8 );
}
throw(AB::object_not_convertible( obj->ob_type->tp_name, "Object"));
}
开发者ID:davidmoreno,项目名称:behaviours,代码行数:21,代码来源:ab_module.cpp
示例20: RangeSubscript
static PyObject *
RangeSubscript(PyObject *self, PyObject* idx)
{
if (PyLong_Check(idx)) {
long _idx = PyLong_AsLong(idx);
return RangeItem((RangeObject *)(self), _idx);
} else if (PySlice_Check(idx)) {
Py_ssize_t start, stop, step, slicelen;
if (PySlice_GetIndicesEx((PySliceObject_T *)idx,
((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
&start, &stop,
&step, &slicelen) < 0) {
return NULL;
}
return RangeSlice((RangeObject *)(self), start, stop);
} else {
RAISE_INVALID_INDEX_TYPE(idx);
return NULL;
}
}
开发者ID:tonymagro,项目名称:viw,代码行数:21,代码来源:if_python3.c
注:本文中的PyLong_Check函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论