本文整理汇总了C++中PyFloat_FromDouble函数的典型用法代码示例。如果您正苦于以下问题:C++ PyFloat_FromDouble函数的具体用法?C++ PyFloat_FromDouble怎么用?C++ PyFloat_FromDouble使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyFloat_FromDouble函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: describe_plugin
static PyObject *
describe_plugin(PyObject * mod, PyObject * args)
{
char * libname = NULL;
int plug_id;
int port_num;
void * dlfile;
LADSPA_Descriptor * (* descrip_func)(unsigned long);
LADSPA_Descriptor * descrip;
PyObject * dict = NULL;
PyObject * ports = NULL;
PyObject * portinfo = NULL;
PyArg_ParseTuple(args, "si", &libname, &plug_id);
if (libname == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
dlfile = dlopen(libname, RTLD_NOW);
if (dlfile == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
descrip_func = dlsym(dlfile, "ladspa_descriptor");
descrip = descrip_func(plug_id);
if (descrip == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
dict = PyDict_New();
PyDict_SetItemString(dict, "lib_name", PyString_FromString(libname));
PyDict_SetItemString(dict, "lib_type", PyString_FromString("ladspa"));
PyDict_SetItemString(dict, "lib_index", PyInt_FromLong(plug_id));
PyDict_SetItemString(dict, "unique_id", PyInt_FromLong(descrip->UniqueID));
PyDict_SetItemString(dict, "properties", PyInt_FromLong(descrip->Properties));
PyDict_SetItemString(dict, "label", PyString_FromString(descrip->Label));
PyDict_SetItemString(dict, "name", PyString_FromString(descrip->Name));
PyDict_SetItemString(dict, "maker", PyString_FromString(descrip->Maker));
PyDict_SetItemString(dict, "copyright", PyString_FromString(descrip->Copyright));
ports = PyList_New(descrip->PortCount);
for(port_num=0; port_num < descrip->PortCount; port_num++) {
portinfo = PyDict_New();
PyDict_SetItemString(portinfo, "descriptor",
PyInt_FromLong(descrip->PortDescriptors[port_num]));
PyDict_SetItemString(portinfo, "name",
PyString_FromString(descrip->PortNames[port_num]));
PyDict_SetItemString(portinfo, "hint_type",
PyInt_FromLong(descrip->PortRangeHints[port_num].HintDescriptor));
PyDict_SetItemString(portinfo, "hint_lower",
PyFloat_FromDouble(descrip->PortRangeHints[port_num].LowerBound));
PyDict_SetItemString(portinfo, "hint_upper",
PyFloat_FromDouble(descrip->PortRangeHints[port_num].UpperBound));
PyList_SetItem(ports, port_num, portinfo);
}
PyDict_SetItemString(dict, "ports", ports);
dlclose(dlfile);
Py_INCREF(dict);
return dict;
}
开发者ID:wrl,项目名称:mfp,代码行数:66,代码来源:pluginfo.c
示例2: Object_newDouble
JSOBJ Object_newDouble(double value)
{
return PyFloat_FromDouble(value);
}
开发者ID:bozhidarc,项目名称:ultrajson,代码行数:4,代码来源:JSONtoObj.c
示例3: Py_INCREF
//-------------------------------------------------------------------------------------
PyObject* ScriptVector3::seq_slice(PyObject* self, Py_ssize_t startIndex, Py_ssize_t endIndex)
{
if(startIndex < 0)
startIndex = 0;
if(endIndex > VECTOR_SIZE)
endIndex = VECTOR_SIZE;
if(endIndex < startIndex)
endIndex = startIndex;
ScriptVector3* sv = static_cast<ScriptVector3*>(self);
Vector3& my_v = sv->getVector();
PyObject* pyResult = NULL;
int length = (int)(endIndex - startIndex);
if (length == VECTOR_SIZE)
{
pyResult = sv;
Py_INCREF(pyResult);
}
else
switch(length)
{
case 0:
pyResult = PyTuple_New(0);
break;
case 1:
pyResult = PyTuple_New(1);
PyTuple_SET_ITEM(pyResult, 0, PyFloat_FromDouble(sv->getVector()[static_cast<int>(startIndex)]));
break;
case 2:
{
Vector2 v;
for (int i = (int)startIndex; i < (int)endIndex; ++i){
v[i - static_cast<int>(startIndex)] = my_v[i];
}
pyResult = new ScriptVector2(v);
break;
}
case 3:
{
Vector3 v;
for (int i = (int)startIndex; i < (int)endIndex; ++i){
v[i - static_cast<int>(startIndex)] = my_v[i];
}
pyResult = new ScriptVector3(v);
break;
}
default:
PyErr_Format(PyExc_IndexError, "Bad slice indexes [%d, %d] for Vector%d", startIndex, endIndex, VECTOR_SIZE);
PyErr_PrintEx(0);
break;
}
return pyResult;
}
开发者ID:1564143452,项目名称:kbengine,代码行数:62,代码来源:vector3.cpp
示例4: CameraInfo_GetFocalLength
static PyObject* CameraInfo_GetFocalLength(CameraInfoObj* self, void* closure)
{
return PyFloat_FromDouble(self->instance.flen);
}
开发者ID:Jus80687,项目名称:py-mve,代码行数:4,代码来源:camera.cpp
示例5: srd_inst_option_set
/**
* Set one or more options in a decoder instance.
*
* Handled options are removed from the hash.
*
* @param di Decoder instance.
* @param options A GHashTable of options to set.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*
* @since 0.1.0
*/
SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
GHashTable *options)
{
struct srd_decoder_option *sdo;
PyObject *py_di_options, *py_optval;
GVariant *value;
GSList *l;
double val_double;
gint64 val_int;
int ret;
const char *val_str;
if (!di) {
srd_err("Invalid decoder instance.");
return SRD_ERR_ARG;
}
if (!options) {
srd_err("Invalid options GHashTable.");
return SRD_ERR_ARG;
}
if (!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
/* Decoder has no options. */
if (g_hash_table_size(options) == 0) {
/* No options provided. */
return SRD_OK;
} else {
srd_err("Protocol decoder has no options.");
return SRD_ERR_ARG;
}
return SRD_OK;
}
ret = SRD_ERR_PYTHON;
py_optval = NULL;
/*
* The 'options' tuple is a class variable, but we need to
* change it. Changing it directly will affect the entire class,
* so we need to create a new object for it, and populate that
* instead.
*/
if (!(py_di_options = PyObject_GetAttrString(di->py_inst, "options")))
goto err_out;
Py_DECREF(py_di_options);
py_di_options = PyDict_New();
PyObject_SetAttrString(di->py_inst, "options", py_di_options);
for (l = di->decoder->options; l; l = l->next) {
sdo = l->data;
if ((value = g_hash_table_lookup(options, sdo->id))) {
/* A value was supplied for this option. */
if (!g_variant_type_equal(g_variant_get_type(value),
g_variant_get_type(sdo->def))) {
srd_err("Option '%s' should have the same type "
"as the default value.", sdo->id);
goto err_out;
}
} else {
/* Use default for this option. */
value = sdo->def;
}
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
val_str = g_variant_get_string(value, NULL);
if (!(py_optval = PyUnicode_FromString(val_str))) {
/* Some UTF-8 encoding error. */
PyErr_Clear();
srd_err("Option '%s' requires a UTF-8 string value.", sdo->id);
goto err_out;
}
} else if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT64)) {
val_int = g_variant_get_int64(value);
if (!(py_optval = PyLong_FromLong(val_int))) {
/* ValueError Exception */
PyErr_Clear();
srd_err("Option '%s' has invalid integer value.", sdo->id);
goto err_out;
}
} else if (g_variant_is_of_type(value, G_VARIANT_TYPE_DOUBLE)) {
val_double = g_variant_get_double(value);
if (!(py_optval = PyFloat_FromDouble(val_double))) {
/* ValueError Exception */
PyErr_Clear();
srd_err("Option '%s' has invalid float value.",
sdo->id);
goto err_out;
}
//.........这里部分代码省略.........
开发者ID:zeldin,项目名称:libsigrokdecode,代码行数:101,代码来源:instance.c
示例6: pyAffineParts_getF
static PyObject* pyAffineParts_getF(pyAffineParts* self, void*) {
return PyFloat_FromDouble(self->fThis->fF);
}
开发者ID:NadnerbD,项目名称:libhsplasma,代码行数:3,代码来源:pyAffineParts.cpp
示例7: switch
PyObject *PyMAPIObject_FromSPropValue(SPropValue *pv)
{
PyObject *val;
ULONG i;
switch (PROP_TYPE(pv->ulPropTag)) {
case PT_I2: // case PT_SHORT:
val = PyInt_FromLong(pv->Value.i);
break;
case PT_I4: // case PT_LONG:
val = PyInt_FromLong(pv->Value.l);
break;
case PT_R4: // case PT_FLOAT:
val = PyFloat_FromDouble(pv->Value.flt);
break;
case PT_R8: // case PT_DOUBLE:
val = PyFloat_FromDouble(pv->Value.dbl);
break;
case PT_BOOLEAN:
val = pv->Value.b ? Py_True : Py_False;
Py_INCREF(val);
break;
/*
case PT_CURRENCY:
pv->Value.cur??
break;
*/
case PT_APPTIME :
val = PyWinObject_FromDATE(pv->Value.at);
break;
case PT_SYSTIME:
val = PyWinObject_FromFILETIME(pv->Value.ft);
break;
case PT_STRING8:
val = PyString_FromString(pv->Value.lpszA);
break;
case PT_UNICODE:
val = PyWinObject_FromWCHAR(pv->Value.lpszW);
break;
case PT_BINARY:
val = PyString_FromStringAndSize((char *)pv->Value.bin.lpb, pv->Value.bin.cb);
break;
case PT_CLSID:
val = PyWinObject_FromIID(*pv->Value.lpguid);
break;
case PT_I8:
// case PT_LONGLONG:
val = PyWinObject_FromLARGE_INTEGER(pv->Value.li);
break;
case PT_ERROR:
val = PyInt_FromLong(pv->Value.err);
break;
case PT_NULL:
val = Py_None;
Py_INCREF(Py_None);
break;
case PT_MV_I2:
val = PyTuple_New(pv->Value.MVi.cValues);
if (val) {
for (i=0;i<pv->Value.MVi.cValues;i++)
PyTuple_SET_ITEM(val, i, PyInt_FromLong(pv->Value.MVi.lpi[i]));
}
break;
case PT_MV_LONG:
val = PyTuple_New(pv->Value.MVi.cValues);
if (val) {
for (i=0;i<pv->Value.MVl.cValues;i++)
PyTuple_SET_ITEM(val, i, PyInt_FromLong(pv->Value.MVl.lpl[i]));
}
break;
case PT_MV_R4:
val = PyTuple_New(pv->Value.MVflt.cValues);
if (val) {
for (i=0;i<pv->Value.MVflt.cValues;i++)
PyTuple_SET_ITEM(val, i, PyFloat_FromDouble(pv->Value.MVflt.lpflt[i]));
}
break;
case PT_MV_DOUBLE :
val = PyTuple_New(pv->Value.MVdbl.cValues);
if (val) {
for (i=0;i<pv->Value.MVdbl.cValues;i++)
PyTuple_SET_ITEM(val, i, PyFloat_FromDouble(pv->Value.MVdbl.lpdbl[i]));
}
break;
/*
case PT_MV_CURRENCY:
MVcur
SCurrencyArray
*/
case PT_MV_APPTIME :
val = PyTuple_New(pv->Value.MVat.cValues);
if (val) {
for (i=0;i<pv->Value.MVat.cValues;i++)
PyTuple_SET_ITEM(val, i, PyWinObject_FromDATE(pv->Value.MVat.lpat[i]));
}
break;
case PT_MV_SYSTIME:
//.........这里部分代码省略.........
开发者ID:GreatFruitOmsk,项目名称:pywin32,代码行数:101,代码来源:mapiutil.cpp
示例8: switch
PyObject* PythonQtConv::ConvertQtValueToPythonInternal(int type, const void* data) {
switch (type) {
case QMetaType::Void:
Py_INCREF(Py_None);
return Py_None;
case QMetaType::Char:
return PyInt_FromLong(*((char*)data));
case QMetaType::UChar:
return PyInt_FromLong(*((unsigned char*)data));
case QMetaType::Short:
return PyInt_FromLong(*((short*)data));
case QMetaType::UShort:
return PyInt_FromLong(*((unsigned short*)data));
case QMetaType::Long:
return PyInt_FromLong(*((long*)data));
case QMetaType::ULong:
// does not fit into simple int of python
return PyLong_FromUnsignedLong(*((unsigned long*)data));
case QMetaType::Bool:
return PythonQtConv::GetPyBool(*((bool*)data));
case QMetaType::Int:
return PyInt_FromLong(*((int*)data));
case QMetaType::UInt:
// does not fit into simple int of python
return PyLong_FromUnsignedLong(*((unsigned int*)data));
case QMetaType::QChar:
return PyInt_FromLong(*((short*)data));
case QMetaType::Float:
return PyFloat_FromDouble(*((float*)data));
case QMetaType::Double:
return PyFloat_FromDouble(*((double*)data));
case QMetaType::LongLong:
return PyLong_FromLongLong(*((qint64*)data));
case QMetaType::ULongLong:
return PyLong_FromUnsignedLongLong(*((quint64*)data));
// implicit conversion from QByteArray to str has been removed:
//case QMetaType::QByteArray: {
// QByteArray* v = (QByteArray*) data;
// return PyString_FromStringAndSize(*v, v->size());
// }
case QMetaType::QVariantMap:
return PythonQtConv::QVariantMapToPyObject(*((QVariantMap*)data));
case QMetaType::QVariantList:
return PythonQtConv::QVariantListToPyObject(*((QVariantList*)data));
case QMetaType::QString:
return PythonQtConv::QStringToPyObject(*((QString*)data));
case QMetaType::QStringList:
return PythonQtConv::QStringListToPyObject(*((QStringList*)data));
case PythonQtMethodInfo::Variant:
return PythonQtConv::QVariantToPyObject(*((QVariant*)data));
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
return PythonQt::priv()->wrapQObject(*((QObject**)data));
default:
if (PythonQt::priv()->isPythonQtObjectPtrMetaId(type)) {
// special case, it is a PythonQtObjectPtr which contains a PyObject, take it directly:
PyObject* o = ((PythonQtObjectPtr*)data)->object();
Py_INCREF(o);
return o;
} else {
if (type > 0) {
// if the type is known, we can construct it via QMetaType::construct
void* newCPPObject = QMetaType::construct(type, data);
// XXX this could be optimized by using metatypeid directly
PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv()->wrapPtr(newCPPObject, QMetaType::typeName(type));
wrap->_ownedByPythonQt = true;
wrap->_useQMetaTypeDestroy = true;
return (PyObject*)wrap;
}
std::cerr << "Unknown type that can not be converted to Python: " << type << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
}
}
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:dimitarm1,项目名称:Lorris,代码行数:77,代码来源:PythonQtConversion.cpp
示例9: PyFloat_FromDouble
static PyObject *PyAsap_ParamProvMaxCutoff(PyAsap_EMTParamProvObject *self,
PyObject *noargs)
{
double cutoff = self->cobj->GetMaxListCutoffDistance();
return PyFloat_FromDouble(cutoff);
}
开发者ID:auag92,项目名称:n2dm,代码行数:6,代码来源:EMTParameterProviderInterface.cpp
示例10: to_python
inline PyObject* to_python(double d)
{
return PyFloat_FromDouble(d);
}
开发者ID:metashell,项目名称:headers,代码行数:4,代码来源:conversions.hpp
示例11: math_pow
static PyObject *
math_pow(PyObject *self, PyObject *args)
{
PyObject *ox, *oy;
double r, x, y;
int odd_y;
if (! PyArg_UnpackTuple(args, "pow", 2, 2, &ox, &oy))
return NULL;
x = PyFloat_AsDouble(ox);
y = PyFloat_AsDouble(oy);
if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
return NULL;
/* deal directly with IEEE specials, to cope with problems on various
platforms whose semantics don't exactly match C99 */
r = 0.; /* silence compiler warning */
if (!Py_IS_FINITE(x) || !Py_IS_FINITE(y)) {
errno = 0;
if (Py_IS_NAN(x))
r = y == 0. ? 1. : x; /* NaN**0 = 1 */
else if (Py_IS_NAN(y))
r = x == 1. ? 1. : y; /* 1**NaN = 1 */
else if (Py_IS_INFINITY(x)) {
odd_y = Py_IS_FINITE(y) && fmod(fabs(y), 2.0) == 1.0;
if (y > 0.)
r = odd_y ? x : fabs(x);
else if (y == 0.)
r = 1.;
else /* y < 0. */
r = odd_y ? copysign(0., x) : 0.;
}
else if (Py_IS_INFINITY(y)) {
if (fabs(x) == 1.0)
r = 1.;
else if (y > 0. && fabs(x) > 1.0)
r = y;
else if (y < 0. && fabs(x) < 1.0) {
r = -y; /* result is +inf */
if (x == 0.) /* 0**-inf: divide-by-zero */
errno = EDOM;
}
else
r = 0.;
}
}
else {
/* let libm handle finite**finite */
errno = 0;
PyFPE_START_PROTECT("in math_pow", return 0);
r = pow(x, y);
PyFPE_END_PROTECT(r);
/* a NaN result should arise only from (-ve)**(finite
non-integer); in this case we want to raise ValueError. */
if (!Py_IS_FINITE(r)) {
if (Py_IS_NAN(r)) {
errno = EDOM;
}
/*
an infinite result here arises either from:
(A) (+/-0.)**negative (-> divide-by-zero)
(B) overflow of x**y with x and y finite
*/
else if (Py_IS_INFINITY(r)) {
if (x == 0.)
errno = EDOM;
else
errno = ERANGE;
}
}
}
if (errno && is_error(r))
return NULL;
else
return PyFloat_FromDouble(r);
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:77,代码来源:mathmodule.c
示例12: math_ldexp
static PyObject *
math_ldexp(PyObject *self, PyObject *args)
{
double x, r;
PyObject *oexp;
long exp;
if (! PyArg_ParseTuple(args, "dO:ldexp", &x, &oexp))
return NULL;
if (PyLong_Check(oexp)) {
/* on overflow, replace exponent with either LONG_MAX
or LONG_MIN, depending on the sign. */
exp = PyLong_AsLong(oexp);
if (exp == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
if (Py_SIZE(oexp) < 0) {
exp = LONG_MIN;
}
else {
exp = LONG_MAX;
}
PyErr_Clear();
}
else {
/* propagate any unexpected exception */
return NULL;
}
}
}
else {
PyErr_SetString(PyExc_TypeError,
"Expected an int or long as second argument "
"to ldexp.");
return NULL;
}
if (x == 0. || !Py_IS_FINITE(x)) {
/* NaNs, zeros and infinities are returned unchanged */
r = x;
errno = 0;
} else if (exp > INT_MAX) {
/* overflow */
r = copysign(Py_HUGE_VAL, x);
errno = ERANGE;
} else if (exp < INT_MIN) {
/* underflow to +-0 */
r = copysign(0., x);
errno = 0;
} else {
errno = 0;
PyFPE_START_PROTECT("in math_ldexp", return 0);
r = ldexp(x, (int)exp);
PyFPE_END_PROTECT(r);
if (Py_IS_INFINITY(r))
errno = ERANGE;
}
if (errno && is_error(r))
return NULL;
return PyFloat_FromDouble(r);
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:61,代码来源:mathmodule.c
示例13: math_fsum
static PyObject*
math_fsum(PyObject *self, PyObject *seq)
{
PyObject *item, *iter, *sum = NULL;
Py_ssize_t i, j, n = 0, m = NUM_PARTIALS;
double x, y, t, ps[NUM_PARTIALS], *p = ps;
double xsave, special_sum = 0.0, inf_sum = 0.0;
volatile double hi, yr, lo;
iter = PyObject_GetIter(seq);
if (iter == NULL)
return NULL;
PyFPE_START_PROTECT("fsum", Py_DECREF(iter); return NULL)
for(;;) { /* for x in iterable */
assert(0 <= n && n <= m);
assert((m == NUM_PARTIALS && p == ps) ||
(m > NUM_PARTIALS && p != NULL));
item = PyIter_Next(iter);
if (item == NULL) {
if (PyErr_Occurred())
goto _fsum_error;
break;
}
x = PyFloat_AsDouble(item);
Py_DECREF(item);
if (PyErr_Occurred())
goto _fsum_error;
xsave = x;
for (i = j = 0; j < n; j++) { /* for y in partials */
y = p[j];
if (fabs(x) < fabs(y)) {
t = x; x = y; y = t;
}
hi = x + y;
yr = hi - x;
lo = y - yr;
if (lo != 0.0)
p[i++] = lo;
x = hi;
}
n = i; /* ps[i:] = [x] */
if (x != 0.0) {
if (! Py_IS_FINITE(x)) {
/* a nonfinite x could arise either as
a result of intermediate overflow, or
as a result of a nan or inf in the
summands */
if (Py_IS_FINITE(xsave)) {
PyErr_SetString(PyExc_OverflowError,
"intermediate overflow in fsum");
goto _fsum_error;
}
if (Py_IS_INFINITY(xsave))
inf_sum += xsave;
special_sum += xsave;
/* reset partials */
n = 0;
}
else if (n >= m && _fsum_realloc(&p, n, ps, &m))
goto _fsum_error;
else
p[n++] = x;
}
}
if (special_sum != 0.0) {
if (Py_IS_NAN(inf_sum))
PyErr_SetString(PyExc_ValueError,
"-inf + inf in fsum");
else
sum = PyFloat_FromDouble(special_sum);
goto _fsum_error;
}
hi = 0.0;
if (n > 0) {
hi = p[--n];
/* sum_exact(ps, hi) from the top, stop when the sum becomes
inexact. */
while (n > 0) {
x = hi;
y = p[--n];
assert(fabs(y) < fabs(x));
hi = x + y;
yr = hi - x;
lo = y - yr;
if (lo != 0.0)
break;
}
/* Make half-even rounding work across multiple partials.
Needed so that sum([1e-16, 1, 1e16]) will round-up the last
digit to two instead of down to zero (the 1e-16 makes the 1
slightly closer to two). With a potential 1 ULP rounding
error fixed-up, math.fsum() can guarantee commutativity. */
if (n > 0 && ((lo < 0.0 && p[n-1] < 0.0) ||
//.........这里部分代码省略.........
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:101,代码来源:mathmodule.c
示例14: PyNeighbor_getradius
static PyObject*
PyNeighbor_getradius(PyNeighbor* self, void* closure)
{
float value = self->neighbor.radius;
return PyFloat_FromDouble((double)value);
}
开发者ID:DavidCain,项目名称:biopython,代码行数:6,代码来源:KDTreemodule.c
示例15: next_token
static PyObject *next(PyObject *self)
{
ligolw_Tokenizer *tokenizer = (ligolw_Tokenizer *) self;
PyObject *type;
PyObject *token;
Py_UNICODE *start, *end;
/*
* Identify the start and end of the next token.
*/
do {
type = next_token(tokenizer, &start, &end);
if(!type)
return NULL;
} while(type == Py_None);
/*
* Extract token as desired type.
*/
if(start == NULL) {
/*
* unquoted zero-length string == None
*/
Py_INCREF(Py_None);
token = Py_None;
} else if(type == (PyObject *) &PyFloat_Type) {
char ascii_buffer[end - start + 1];
char *ascii_end;
if(PyUnicode_EncodeDecimal(start, end - start, ascii_buffer, NULL))
return NULL;
token = PyFloat_FromDouble(strtod(ascii_buffer, &ascii_end));
if(ascii_end == ascii_buffer || *ascii_end != 0) {
/*
* strtod() couldn't convert the token, emulate
* float()'s error message
*/
Py_XDECREF(token);
PyErr_Format(PyExc_ValueError, "invalid literal for float(): '%s'", ascii_buffer);
token = NULL;
}
} else if(type == (PyObject *) &PyUnicode_Type) {
token = PyUnicode_FromUnicode(start, end - start);
} else if(type == (PyObject *) &PyString_Type) {
token = PyUnicode_Encode(start, end - start, NULL, NULL);
} else if(type == (PyObject *) &PyInt_Type) {
token = PyInt_FromUnicode(start, end - start, 0);
} else if(type == (PyObject *) &PyLong_Type) {
token = PyLong_FromUnicode(start, end - start, 0);
} else {
token = PyObject_CallFunction(type, "u#", start, end - start);
}
/*
* Done.
*/
return token;
}
开发者ID:smirshekari,项目名称:lalsuite,代码行数:62,代码来源:tokenizer.Tokenizer.c
示例16: ctrlp_fuzzycomt_match
PyObject* ctrlp_fuzzycomt_match(PyObject* self, PyObject* args) {
PyObject *paths, *abbrev, *returnlist;
Py_ssize_t limit;
char *mmode;
int i;
int max;
if (!PyArg_ParseTuple(args, "OOns", &paths, &abbrev, &limit, &mmode)) {
return NULL;
}
returnlist = PyList_New(0);
// Type checking
if (PyList_Check(paths) != 1) {
PyErr_SetString(PyExc_TypeError,"expected a list");
return 0;
}
if (PyString_Check(abbrev) != 1) {
PyErr_SetString(PyExc_TypeError,"expected a string");
return 0;
}
matchobj_t matches[PyList_Size(paths)];
if ( (limit > PyList_Size(paths)) || (limit == 0) ) {
limit = PyList_Size(paths);
}
if ( PyString_Size(abbrev) == 0) {
// if string is empty - just return first (:param limit) lines
PyObject *initlist;
initlist = PyList_GetSlice(paths,0,limit);
return initlist;
}
else {
// find matches and place them into matches array.
ctrlp_get_line_matches(paths,abbrev, matches, mmode);
// sort array of struct by struct.score key
qsort(matches, PyList_Size(paths),
sizeof(matchobj_t),
ctrlp_comp_score_alpha);
}
for (i = 0, max = PyList_Size(paths); i < max; i++) {
if (i == limit)
break;
// generate python dicts { 'line' : line, 'value' : value }
// and place dicts to list
PyObject *container;
container = PyDict_New();
// TODO it retuns non-encoded string. So cyrillic literals
// arent properly showed.
// There are PyString_AsDecodedObject, it works in interactive
// session but it fails in Vim for some reason
// (probably because we dont know what encoding vim returns)
PyDict_SetItemString(container, "line", matches[i].str);
PyDict_SetItemString(container,
"value",
PyFloat_FromDouble(matches[i].score));
PyList_Append(returnlist,container);
}
return returnlist;
}
开发者ID:JazzCore,项目名称:ctrlp-cmatcher,代码行数:67,代码来源:fuzzycomt.c
示例17: PyFloat_FromDouble
static PyObject *SVertexIterator_u_get(BPy_SVertexIterator *self, void *UNUSED(closure))
{
return PyFloat_FromDouble(self->sv_it->u());
}
开发者ID:dfelinto,项目名称:blender,代码行数:4,代码来源:BPy_SVertexIterator.cpp
示例18: PyMember_GetOne
PyObject *
PyMember_GetOne(char *addr, PyMemberDef *l)
{
PyObject *v;
// if ((l->flags & READ_RESTRICTED) &&
// PyEval_GetRestricted()) {
// PyErr_SetString(PyExc_RuntimeError, "restricted attribute");
// return NULL;
// }
addr += l->offset;
switch (l->type) {
case T_BYTE:
v = PyInt_FromLong(
(long) (((*(char*)addr & 0xff) ^ 0x80) - 0x80));
break;
case T_UBYTE:
v = PyInt_FromLong((long) *(char*)addr & 0xff);
break;
case T_SHORT:
v = PyInt_FromLong((long) *(short*)addr);
break;
case T_USHORT:
v = PyInt_FromLong((long) *(unsigned short*)addr);
break;
case T_INT:
v = PyInt_FromLong((long) *(int*)addr);
break;
case T_UINT:
v = PyInt_FromLong((long) *(unsigned int*)addr);
break;
case T_LONG:
v = PyInt_FromLong(*(long*)addr);
break;
case T_ULONG:
v = PyLong_FromDouble((double) *(unsigned long*)addr);
break;
case T_FLOAT:
v = PyFloat_FromDouble((double)*(float*)addr);
break;
case T_DOUBLE:
v = PyFloat_FromDouble(*(double*)addr);
break;
case T_STRING:
if (*(char**)addr == NULL) {
Py_INCREF(Py_None);
v = Py_None;
}
else
v = PyString_FromString(*(char**)addr);
break;
case T_STRING_INPLACE:
v = PyString_FromString((char*)addr);
break;
#ifdef macintosh
case T_PSTRING:
if (*(char**)addr == NULL) {
Py_INCREF(Py_None);
v = Py_None;
}
else
v = PyString_FromStringAndSize(
(*(char**)addr)+1,
**(unsigned char**)addr);
break;
case T_PSTRING_INPLACE:
v = PyString_FromStringAndSize(
((char*)addr)+1,
*(unsigned char*)addr);
break;
#endif /* macintosh */
case T_CHAR:
v = PyString_FromStringAndSize((char*)addr, 1);
break;
case T_OBJECT:
v = *(PyObject **)addr;
if (v == NULL)
v = Py_None;
Py_INCREF(v);
break;
case T_OBJECT_EX:
v = *(PyObject **)addr;
if (v == NULL)
PyErr_SetString(PyExc_AttributeError, l->name);
Py_XINCREF(v);
break;
default:
PyErr_SetString(PyExc_SystemError, "bad memberdescr type");
v = NULL;
}
return v;
}
开发者ID:MatiasNAmendola,项目名称:cleese,代码行数:91,代码来源:structmember.c
示例19: DCDynamicsSceneFixedFrameRate
static PyObject* DCDynamicsSceneFixedFrameRate(DCDynamicsScene* self, void*)
{
DCOBJECT_VALIDATE(self->scene, NULL);
return PyFloat_FromDouble(self->scene->FixedFrameRate());
}
开发者ID:hhg128,项目名称:DKGL,代码行数:5,代码来源:DCDynamicsScene.cpp
示例20: pyg_value_as_pyobject
/**
* pyg_value_as_pyobject:
* @value: the GValue object.
* @copy_boxed: true if boxed values should be copied.
*
* This function creates/returns a Python wrapper object that
* represents the GValue passed as an argument.
*
* Returns: a PyObject representing the value.
*/
PyObject *
pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
{
gchar buf[128];
switch (G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value))) {
case G_TYPE_INTERFACE:
if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT))
return pygobject_new(g_value_get_object(value));
else
break;
case G_TYPE_CHAR: {
gint8 val = g_value_get_char(value);
return PYGLIB_PyUnicode_FromStringAndSize((char *)&val, 1);
}
case G_TYPE_UCHAR: {
guint8 val = g_value_get_uchar(value);
return PYGLIB_PyBytes_FromStringAndSize((char *)&val, 1);
}
case G_TYPE_BOOLEAN: {
return PyBool_FromLong(g_value_get_boolean(value));
}
case G_TYPE_INT:
return PYGLIB_PyLong_FromLong(g_value_get_int(value));
case G_TYPE_UINT:
{
/* in Python, the Int object is backed by a long. If a
long can hold the whole value of an unsigned int, use
an Int. Otherwise, use a Long object to avoid overflow.
This matches the ULongArg behavior in codegen/argtypes.h */
#if (G_MAXUINT <= G_MAXLONG)
return PYGLIB_PyLong_FromLong((glong) g_value_get_uint(value));
#else
return PyLong_FromUnsignedLong((gulong) g_value_get_uint(value));
#endif
}
case G_TYPE_LONG:
return PYGLIB_PyLong_FromLong(g_value_get_long(value));
case G_TYPE_ULONG:
{
gulong val = g_value_get_ulong(value);
if (val <= G_MAXLONG)
return PYGLIB_PyLong_FromLong((glong) val);
else
return PyLong_FromUnsignedLong(val);
}
case G_TYPE_INT64:
{
gint64 val = g_value_get_int64(value);
if (G_MINLONG <= val && val <= G_MAXLONG)
return PYGLIB_PyLong_FromLong((glong) val);
else
return PyLong_FromLongLong(val);
}
case G_TYPE_UINT64:
{
guint64 val = g_value_get_uint64(value);
if (val <= G_MAXLONG)
return PYGLIB_PyLong_FromLong((glong) val);
else
return PyLong_FromUnsignedLongLong(val);
}
case G_TYPE_ENUM:
return pyg_enum_from_gtype(G_VALUE_TYPE(value), g_value_get_enum(value));
case G_TYPE_FLAGS:
return pyg_flags_from_gtype(G_VALUE_TYPE(value), g_value_get_flags(value));
case G_TYPE_FLOAT:
return PyFloat_FromDouble(g_value_get_float(value));
case G_TYPE_DOUBLE:
return PyFloat_FromDouble(g_value_get_double(value));
case G_TYPE_STRING:
{
const gchar *str = g_value_get_string(value);
if (str)
return PYGLIB_PyUnicode_FromString(str);
Py_INCREF(Py_None);
return Py_None;
}
case G_TYPE_POINTER:
return pyg_pointer_new(G_VALUE_TYPE(value),
g_value_get_pointer(value));
case G_TYPE_BOXED: {
PyGTypeMarshal *bm;
if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT)) {
PyObject *ret = (PyObject *)g_value_dup_boxed(value);
//.........这里部分代码省略.........
开发者ID:nzjrs,项目名称:pygobject,代码行数:101,代码来源:pygtype.c
注:本文中的PyFloat_FromDouble函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论