本文整理汇总了C++中PyLong_AsLongLong函数的典型用法代码示例。如果您正苦于以下问题:C++ PyLong_AsLongLong函数的具体用法?C++ PyLong_AsLongLong怎么用?C++ PyLong_AsLongLong使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyLong_AsLongLong函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convert_meta
static int convert_meta(struct srd_proto_data *pdata, PyObject *obj)
{
long long intvalue;
double dvalue;
if (pdata->pdo->meta_type == G_VARIANT_TYPE_INT64) {
if (!PyLong_Check(obj)) {
PyErr_Format(PyExc_TypeError, "This output was registered "
"as 'int', but something else was passed.");
return SRD_ERR_PYTHON;
}
intvalue = PyLong_AsLongLong(obj);
if (PyErr_Occurred())
return SRD_ERR_PYTHON;
pdata->data = g_variant_new_int64(intvalue);
} else if (pdata->pdo->meta_type == G_VARIANT_TYPE_DOUBLE) {
if (!PyFloat_Check(obj)) {
PyErr_Format(PyExc_TypeError, "This output was registered "
"as 'float', but something else was passed.");
return SRD_ERR_PYTHON;
}
dvalue = PyFloat_AsDouble(obj);
if (PyErr_Occurred())
return SRD_ERR_PYTHON;
pdata->data = g_variant_new_double(dvalue);
}
return SRD_OK;
}
示例2: CListValue
CValue* CValue::ConvertPythonToValue(PyObject* pyobj, const char *error_prefix)
{
CValue* vallie = NULL;
/* refcounting is broking here! - this crashes anyway, just store a python list for KX_GameObject */
#if 0
if (PyList_Check(pyobj))
{
CListValue* listval = new CListValue();
bool error = false;
int i;
int numitems = PyList_Size(pyobj);
for (i=0;i<numitems;i++)
{
PyObject* listitem = PyList_GetItem(pyobj,i); /* borrowed ref */
CValue* listitemval = ConvertPythonToValue(listitem, error_prefix);
if (listitemval)
{
listval->Add(listitemval);
} else
{
error = true;
}
}
if (!error)
{
// jippie! could be converted
vallie = listval;
} else
{
// list could not be converted... bad luck
listval->Release();
}
} else
#endif
if (PyFloat_Check(pyobj))
{
vallie = new CFloatValue( (float)PyFloat_AsDouble(pyobj) );
} else
if (PyLong_Check(pyobj))
{
vallie = new CIntValue( (cInt)PyLong_AsLongLong(pyobj) );
} else
if (PyUnicode_Check(pyobj))
{
vallie = new CStringValue(_PyUnicode_AsString(pyobj),"");
} else
if (PyObject_TypeCheck(pyobj, &CValue::Type)) /* Note, dont let these get assigned to GameObject props, must check elsewhere */
{
vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef();
} else
{
/* return an error value from the caller */
PyErr_Format(PyExc_TypeError, "%scould convert python value to a game engine property", error_prefix);
}
return vallie;
}
示例3: pyobject_to_ligotimegps
static int pyobject_to_ligotimegps(PyObject *obj, LIGOTimeGPS *gps)
{
if(pylal_LIGOTimeGPS_Check(obj)) {
*gps = ((pylal_LIGOTimeGPS *) obj)->gps;
} else if(PyInt_Check(obj)) {
XLALGPSSet(gps, PyInt_AsLong(obj), 0);
} else if(PyLong_Check(obj)) {
XLALGPSSet(gps, PyLong_AsLongLong(obj), 0);
} else if(PyFloat_Check(obj)) {
XLALGPSSetREAL8(gps, PyFloat_AsDouble(obj));
} else if(PyComplex_Check(obj)) {
if(PyComplex_ImagAsDouble(obj) != 0.0) {
XLALGPSSet(gps, 0, 0);
PyErr_SetObject(PyExc_ValueError, obj);
return 0;
}
XLALGPSSetREAL8(gps, PyComplex_RealAsDouble(obj));
} else {
PyObject *s_attr = PyObject_GetAttrString(obj, "seconds");
PyObject *n_attr = PyObject_GetAttrString(obj, "nanoseconds");
XLALGPSSet(gps, PyInt_AsLong(s_attr), PyInt_AsLong(n_attr));
Py_XDECREF(s_attr);
Py_XDECREF(n_attr);
if(PyErr_Occurred()) {
PyErr_SetObject(PyExc_TypeError, obj);
return 0;
}
}
return 1;
}
示例4: PyErr_Format
static PyObject *Triton_stopAnalysisFromAddr(PyObject *self, PyObject *addr) {
if (!PyLong_Check(addr) && !PyInt_Check(addr))
return PyErr_Format(PyExc_TypeError, "stopAnalysisFromAddr(): expected an address (integer) as argument");
PyTritonOptions::stopAnalysisFromAddr.insert(PyLong_AsLongLong(addr));
Py_INCREF(Py_None);
return Py_None;
}
示例5: convert_binop
static int convert_binop(PyObject *v, PyObject *w, LONG_LONG *a, LONG_LONG *b)
{
if (PgInt8_Check(v))
{
*a = PgInt8_AS_LONGLONG(v);
}
else if (PyLong_Check(v))
{
*a = PyLong_AsLongLong(v);
if (*a == -1 && PyErr_Occurred())
return 0;
}
else if (PyInt_Check(v)) {
*a = (LONG_LONG)(PyInt_AS_LONG(v));
}
else
{
return 0;
}
if (w == Py_None)
return 1;
else if (PgInt8_Check(w))
{
*b = PgInt8_AS_LONGLONG(w);
}
else if (PyLong_Check(w))
{
*b = PyLong_AsLongLong(w);
if (*b == -1 && PyErr_Occurred())
return 0;
}
else if (PyInt_Check(w))
{
*b = (LONG_LONG)(PyInt_AS_LONG(w));
}
else
{
return 0;
}
return 1;
}
示例6: _extract
void _extract(PyObject *obj, unsigned long long &val)
{
if (PyInt_Check(obj))
val = (unsigned long long)PyInt_AsUnsignedLongLongMask(obj);
else if (PyFloat_Check(obj))
val = (unsigned long long)PyFloat_AsDouble(obj);
else
val = (unsigned long long)PyLong_AsLongLong(obj);
}
示例7: extra_read_post
PyObject* extra_read_post(Reader* r, PyObject* extra, int version) {
PyObject* result = NULL;
if (PyDict_Check(extra)) {
if (is_listlike_dict(extra)) {
result = PyList_New(PyDict_Size(extra));
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(extra, &pos, &key, &value)) {
// is_listlike_dict already checked for overflow.
int64_t idx = PyLong_AsLongLong(key);
PyObject* new_value = extra_read_post(r, value, version);
FAIL_IF(new_value == NULL);
// Subtract 1 to adjust for Lua's 1-based lists.
if (PyList_SetItem(result, idx - 1, new_value) < 0) {
Py_DECREF(new_value);
goto fail;
}
}
} else {
result = PyDict_New();
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(extra, &pos, &key, &value)) {
PyObject* new_value = extra_read_post(r, value, version);
FAIL_IF(new_value == NULL);
// Subtract 1 to adjust for Lua's 1-based lists.
if (PyDict_SetItem(result, key, new_value) < 0) {
Py_DECREF(new_value);
goto fail;
}
}
}
} else if (PyObject_TypeCheck(extra, &ClientIdType) ||
PyObject_TypeCheck(extra, &EntityIdType) ||
PyObject_TypeCheck(extra, &InventoryIdType) ||
PyObject_TypeCheck(extra, &StructureIdType)) {
uint32_t id = ((AnyId*)extra)->id;
result = read_find_object(r, id);
FAIL_IF(result == NULL);
Py_INCREF(result);
} else {
result = extra;
Py_INCREF(result);
}
return result;
fail:
SET_EXC();
Py_XDECREF(result);
return NULL;
}
示例8: PyTuple_Size
// Register a timed callback.
// First argument should be the time in picoseconds
// Second argument is the function to call
// Remaining arguments and keyword arguments are to be passed to the callback
static PyObject *register_timed_callback(PyObject *self, PyObject *args)
{
FENTER
PyObject *fArgs;
PyObject *function;
gpi_sim_hdl hdl;
uint64_t time_ps;
p_callback_data callback_data_p;
Py_ssize_t numargs = PyTuple_Size(args);
if (numargs < 2) {
fprintf(stderr, "Attempt to register timed callback without enough arguments!\n");
return NULL;
}
// Extract the time
PyObject *pTime = PyTuple_GetItem(args, 0);
time_ps = PyLong_AsLongLong(pTime);
// Extract the callback function
function = PyTuple_GetItem(args, 1);
if (!PyCallable_Check(function)) {
fprintf(stderr, "Attempt to register timed callback without passing a callable callback!\n");
return NULL;
}
Py_INCREF(function);
// Remaining args for function
fArgs = PyTuple_GetSlice(args, 2, numargs); // New reference
if (fArgs == NULL) {
return NULL;
}
callback_data_p = (p_callback_data)malloc(sizeof(s_callback_data));
if (callback_data_p == NULL) {
return PyErr_NoMemory();
}
// Set up the user data (no more python API calls after this!)
callback_data_p->_saved_thread_state = PyThreadState_Get();
callback_data_p->id_value = COCOTB_ACTIVE_ID;
callback_data_p->function = function;
callback_data_p->args = fArgs;
callback_data_p->kwargs = NULL;
hdl = gpi_register_timed_callback((gpi_function_t)handle_gpi_callback, callback_data_p, time_ps);
// Check success
PyObject *rv = PyLong_FromVoidPtr(hdl);
FEXIT
return rv;
}
示例9: to_td_val
static void to_td_val(td_val_t *out, PyObject *pVal)
{
PyObject *pStr;
td_array_t *arr;
PyArrayObject *pArr;
td_tag_t tag = py_type_to_td(pVal);
switch (tag) {
case TD_INT32:
out->tag = TD_INT32;
if (PyInt_Check(pVal))
out->int32_val = PyInt_AS_LONG(pVal);
else
out->int32_val = PyLong_AsLong(pVal);
break;
case TD_UINT32:
out->tag = TD_UINT32;
out->uint32_val = PyLong_AsUnsignedLong(pVal);
break;
case TD_INT64:
out->tag = TD_INT64;
out->int64_val = PyLong_AsLongLong(pVal);
break;
case TD_UINT64:
out->tag = TD_UINT64;
out->uint64_val = PyLong_AsUnsignedLongLong(pVal);
break;
case TD_DOUBLE:
out->tag = TD_DOUBLE;
out->double_val = PyFloat_AsDouble(pVal);
break;
case TD_UTF8:
pStr = pVal;
if (PyUnicode_Check(pStr)) pStr = PyUnicode_AsUTF8String(pStr);
size_t len = PyString_Size(pStr);
char* data = malloc((len+1)*sizeof(char));
strcpy(PyString_AsString(pStr), data);
td_string_t *obj = malloc(sizeof(td_string_t));
obj->length = len;
obj->data = (void*) data;
out->tag = TD_UTF8;
out->object = (void*) obj;
break;
case TD_ARRAY:
arr = (td_array_t *)malloc(sizeof(td_array_t));
pArr = (PyArrayObject *) pVal;
arr->data = PyArray_DATA(pArr);
arr->length = PyArray_SIZE(pArr);
arr->eltype = numpy_type_to_td(PyArray_TYPE(pArr));
arr->ndims = PyArray_NDIM(pArr);
break;
default:
out->tag = TD_OBJECT;
out->owner = td_env_python(NULL, NULL);
out->object = pVal;
}
}
示例10: AerospikeClient_CheckForMeta
/**
*******************************************************************************************************
* This function checks for metadata and if present set it into the
* as_operations.
*
* @param py_meta The dictionary of metadata.
* @param ops The as_operations object.
* @param err The as_error to be populated by the function
* with the encountered error if any.
*
* Returns nothing.
*******************************************************************************************************
*/
static
void AerospikeClient_CheckForMeta(PyObject * py_meta, as_operations * ops, as_error *err)
{
if ( py_meta && PyDict_Check(py_meta) ) {
PyObject * py_gen = PyDict_GetItemString(py_meta, "gen");
PyObject * py_ttl = PyDict_GetItemString(py_meta, "ttl");
uint32_t ttl = 0;
uint16_t gen = 0;
if ( py_ttl != NULL ){
if ( PyInt_Check(py_ttl) ) {
ttl = (uint32_t) PyInt_AsLong(py_ttl);
} else if ( PyLong_Check(py_ttl) ) {
ttl = (uint32_t) PyLong_AsLongLong(py_ttl);
} else {
as_error_update(err, AEROSPIKE_ERR_PARAM, "Ttl should be an int or long");
}
if((uint32_t)-1 == ttl) {
as_error_update(err, AEROSPIKE_ERR_PARAM, "integer value for ttl exceeds sys.maxsize");
return;
}
ops->ttl = ttl;
}
if( py_gen != NULL ){
if ( PyInt_Check(py_gen) ) {
gen = (uint16_t) PyInt_AsLong(py_gen);
} else if ( PyLong_Check(py_gen) ) {
gen = (uint16_t) PyLong_AsLongLong(py_gen);
} else {
as_error_update(err, AEROSPIKE_ERR_PARAM, "Generation should be an int or long");
}
if((uint16_t)-1 == gen) {
as_error_update(err, AEROSPIKE_ERR_PARAM, "integer value for gen exceeds sys.maxsize");
return;
}
ops->gen = gen;
}
} else {
as_error_update(err, AEROSPIKE_ERR_PARAM, "Metadata should be of type dictionary");
}
}
示例11: PyArg_ParseTuple
static PyObject *smt2lib_extract(PyObject *self, PyObject *args) {
PyObject *op1 = nullptr;
PyObject *op2 = nullptr;
PyObject *op3 = nullptr;
/* Extract arguments */
PyArg_ParseTuple(args, "|OOO", &op1, &op2, &op3);
if (op1 == nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
return PyErr_Format(PyExc_TypeError, "extract(): expected an integer as first argument");
if (op2 == nullptr || (!PyLong_Check(op2) && !PyInt_Check(op2)))
return PyErr_Format(PyExc_TypeError, "extract(): expected an integer as second argument");
if (op3 == nullptr || !PySmtAstNode_Check(op3))
return PyErr_Format(PyExc_TypeError, "extract(): expected a SmtAstNode as third argument");
return PySmtAstNode(smt2lib::extract(PyLong_AsLongLong(op1), PyLong_AsLongLong(op2), PySmtAstNode_AsSmtAstNode(op3)));
}
示例12: pylong_to_int64
long long
pylong_to_int64(PyObject *pyid)
{
long long id;
id = PyLong_AsLongLong(pyid);
if (id < 1 && !PyErr_Occurred()) {
set_error(PyExc_OverflowError, "key is lesser than minimum");
}
return id;
}
示例13: py_type_to_td
static td_tag_t py_type_to_td(PyObject *pVal)
{
if (PyInt_Check(pVal)){
#if INT32_MAX==LONG_MAX
return TD_INT32;
#else
return longlong_to_td(PyInt_AS_LONG(pVal));
#endif
}
else if (PyLong_Check(pVal)){
PyObject *pErr;
long long v;
v = PyLong_AsLongLong(pVal);
if ( v == -1 && PyErr_Occurred()) {
// could not eval as long long try unsigned long long later
PyErr_Clear();
}
else {
return longlong_to_td(PyInt_AS_LONG(v));
}
unsigned long long vv;
vv = PyLong_AsUnsignedLongLong(pVal);
if ( v == (unsigned long long) -1 && PyErr_Occurred() ) {
PyErr_Clear();
return TD_OBJECT;
}
else {
return TD_UINT64;
}
}
else if (PyFloat_Check(pVal)) {
return TD_DOUBLE;
}
else if (PyUnicode_Check(pVal)){
PyObject *pStr;
pStr = PyUnicode_AsUTF8String(pVal);
if ( pStr && PyErr_Occurred() ){
PyErr_Clear();
return TD_OBJECT;
}
else {
return TD_UTF8;
}
}
else if (PyString_Check(pVal)) {
return TD_UTF8;
}
else if (PyArray_Check(pVal)) {
return TD_ARRAY;
}
return TD_OBJECT;
}
示例14: PyObject_CallMethod
static void *PyDateTimeToINT64(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
PyObject *obj = (PyObject *) _obj;
PyObject* timetuple = PyObject_CallMethod(obj, "utctimetuple", NULL);
PyObject* unixTimestamp = PyObject_CallMethodObjArgs(mod_calendar, meth_timegm, timetuple, NULL);
*( (JSINT64 *) outValue) = PyLong_AsLongLong (unixTimestamp);
Py_DECREF(timetuple);
Py_DECREF(unixTimestamp);
return NULL;
}
示例15: pyobject_to_int64
int64_t pyobject_to_int64(PyObject * py_obj)
{
if ( PyInt_Check(py_obj) ) {
return PyInt_AsLong(py_obj);
}
else if ( PyLong_Check(py_obj) ) {
return PyLong_AsLongLong(py_obj);
}
else {
return 0;
}
}