double x;
if (PyFloat_Check(o))
x=PyFloat_AS_DOUBLE(o);
- else if (PyInt_Check(o))
- x=PyInt_AS_LONG(o);
else if(PyLong_Check(o))
x=PyLong_AsLong(o);
else
static inline long convert(const TypeCode *t,PyObject* o,void*)
{
long l;
- if (PyInt_Check(o))
- l=PyInt_AS_LONG(o);
- else if(PyLong_Check(o))
+ if(PyLong_Check(o))
l=PyLong_AsLong(o);
else
{
static inline std::string convert(const TypeCode *t,PyObject* o,void*)
{
std::string s;
- if (PyString_Check(o))
- s= PyString_AS_STRING(o);
+ if (PyBytes_Check(o))
+ s= PyBytes_AS_STRING(o);
else
{
stringstream msg;
bool l;
if (PyBool_Check(o))
l=(o==Py_True);
- else if (PyInt_Check(o))
- l=(PyInt_AS_LONG(o)!=0);
else if(PyLong_Check(o))
l=(PyLong_AsLong(o)!=0);
else
{
static inline std::string convert(const TypeCode *t,PyObject* o,void*,int protocol)
{
- if (PyString_Check(o) && strncmp(t->id(),"python",6)!=0)
+ if (PyBytes_Check(o) && strncmp(t->id(),"python",6)!=0)
{
// the objref is used by Python as a string (prefix:value) keep it as a string
- return PyString_AS_STRING(o);
+ return PyBytes_AS_STRING(o);
}
if(strncmp(t->id(),"python",6)==0)
{
// It's a native Python object pickle it
- PyObject* mod=PyImport_ImportModule("cPickle");
+ PyObject* mod=PyImport_ImportModule("pickle");
PyObject *pickled=PyObject_CallMethod(mod,(char *)"dumps",(char *)"Oi",o,protocol);
DEBTRACE(PyObject_REPR(pickled) );
Py_DECREF(mod);
PyErr_Print();
throw YACS::ENGINE::ConversionException("Problem in convertToYacsObjref<PYTHONImpl");
}
- std::string mystr(PyString_AsString(pickled),PyString_Size(pickled));
+ std::string mystr(PyBytes_AsString(pickled),PyBytes_Size(pickled));
Py_DECREF(pickled);
return mystr;
}
PyErr_Print();
throw YACS::ENGINE::ConversionException("Problem in convertToYacsObjref<PYTHONImpl");
}
- std::string mystr=PyString_AsString(pickled);
+ std::string mystr=PyBytes_AsString(pickled);
Py_DECREF(pickled);
return mystr;
}
PyErr_Print();
throw YACS::ENGINE::ConversionException("Problem in convertToYacsObjref<PYTHONImpl");
}
- std::string mystr=PyString_AsString(pystring);
+ std::string mystr=PyBytes_AsString(pystring);
Py_DECREF(pystring);
return mystr;
}
{
static inline PyObject* convert(const TypeCode *t,std::string& o)
{
- return PyString_FromString(o.c_str());
+ return PyBytes_FromString(o.c_str());
}
};
template <>
if(t->isA(Runtime::_tc_file))
{
//It's an objref file. Convert it specially
- return PyString_FromString(o.c_str());
+ return PyBytes_FromString(o.c_str());
}
if(strncmp(t->id(),"python",6)==0)
{
//It's a python pickled object, unpickled it
- PyObject* mod=PyImport_ImportModule("cPickle");
+ PyObject* mod=PyImport_ImportModule("pickle");
PyObject *ob=PyObject_CallMethod(mod,(char *)"loads",(char *)"s#",o.c_str(),o.length());
DEBTRACE(PyObject_REPR(ob));
Py_DECREF(mod);
}
PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject* mod=PyImport_ImportModule("cPickle");
+ PyObject* mod=PyImport_ImportModule("pickle");
PyObject *ob=PyObject_CallMethod(mod,(char *)"loads",(char *)"s#",s,buffer->length());
PyObject *pickled=PyObject_CallMethod(mod,(char *)"dumps",(char *)"Oi",ob,protocol);
DEBTRACE(PyObject_REPR(pickled));
- std::string mystr=PyString_AsString(pickled);
+ std::string mystr=PyBytes_AsString(pickled);
Py_DECREF(mod);
Py_DECREF(ob);
Py_DECREF(pickled);
PyObject *s;
PyGILState_STATE gstate = PyGILState_Ensure();
s=PyObject_Str(ob);
- std::string ss(PyString_AsString(s),PyString_Size(s));
+ std::string ss(PyBytes_AsString(s),PyBytes_Size(s));
Py_DECREF(s);
PyGILState_Release(gstate);
return ss;
{
if (PyFloat_Check(o))
return true;
- else if (PyInt_Check(o))
- return true;
else if(PyLong_Check(o))
return true;
else
template<>
inline bool checkInt<PYTHONImpl,PyObject*,void*>(const TypeCode *t,PyObject* o,void* aux)
{
- if (PyInt_Check(o) || PyLong_Check(o))
+ if (PyLong_Check(o))
return true;
else
{
{
if (PyBool_Check(o))
return true;
- else if (PyInt_Check(o))
- return true;
else if(PyLong_Check(o))
return true;
else
template<>
inline bool checkString<PYTHONImpl,PyObject*,void*>(const TypeCode *t,PyObject* o,void* aux)
{
- if (PyString_Check(o))
+ if (PyBytes_Check(o))
return true;
else
{
template<>
inline bool checkObjref<PYTHONImpl,PyObject*,void*>(const TypeCode *t,PyObject* o,void* aux)
{
- if (PyString_Check(o))
+ if (PyBytes_Check(o))
return true;
if(strncmp(t->id(),"python",6)==0) // a Python object is expected (it's always true)
return true;