Commit e2ce0682 authored by Thomas Moulard's avatar Thomas Moulard
Browse files

Fix Ubuntu 12.04 (64 bits) portability issues.

parent 06e09ad4
......@@ -62,10 +62,10 @@ namespace dynamicgraph {
std::string svalue;
Vector v;
Matrix m;
unsigned int nCols;
unsigned int size;
Py_ssize_t nCols;
Py_ssize_t size;
PyObject* row;
unsigned int nRows;
Py_ssize_t nRows;
switch (valueType) {
case (Value::BOOL) :
......@@ -81,7 +81,7 @@ namespace dynamicgraph {
throw ExceptionPython(ExceptionPython::VALUE_PARSING,
"unsigned int");
}
uvalue = PyInt_AsUnsignedLongMask(pyObject);
uvalue = (unsigned int)PyInt_AsUnsignedLongMask(pyObject);
return Value(uvalue);
break;
case (Value::INT) :
......@@ -109,7 +109,7 @@ namespace dynamicgraph {
dvalue = PyFloat_AsDouble(pyObject);
return Value(dvalue);
} else if (PyInt_Check(pyObject)) {
dvalue = 0.0+PyInt_AS_LONG(pyObject);
dvalue = (double)PyInt_AS_LONG(pyObject);
return Value(dvalue);
} else {
throw ExceptionPython(ExceptionPython::VALUE_PARSING,
......@@ -162,7 +162,7 @@ namespace dynamicgraph {
}
nCols = PyTuple_Size(row);
m.resize(nRows, nCols);
m.resize((unsigned int)nRows, (unsigned int)nCols);
fillMatrixRow(m, 0, row);
for (unsigned int iRow=1; iRow<nRows; iRow++) {
......
......@@ -193,7 +193,7 @@ namespace dynamicgraph {
PyErr_SetString(PyExc_TypeError, "third argument is not a tuple");
return NULL;
}
unsigned int size = PyTuple_Size(argTuple);
Py_ssize_t size = PyTuple_Size(argTuple);
std::map<const std::string, Command*> commandMap =
entity->getNewStyleCommandMap();
......@@ -208,13 +208,14 @@ namespace dynamicgraph {
Command* command = commandMap[std::string(commandName)];
// Check that tuple size is equal to command number of arguments
const std::vector<Value::Type> typeVector = command->valueTypes();
if (size != typeVector.size()) {
std::stringstream ss;
ss << "command takes " << typeVector.size()
<< " parameters, " << size << " given.";
PyErr_SetString(dgpyError, ss.str().c_str());
return NULL;
}
if ((unsigned)size != typeVector.size())
{
std::stringstream ss;
ss << "command takes " << typeVector.size()
<< " parameters, " << size << " given.";
PyErr_SetString(dgpyError, ss.str().c_str());
return NULL;
}
std::vector<Value> valueVector;
for (unsigned int iParam=0; iParam<size; iParam++) {
......@@ -257,9 +258,10 @@ namespace dynamicgraph {
}
void* pointer = PyCObject_AsVoidPtr(object);
Entity* entity = (Entity*)pointer;
typedef std::map<const std::string, command::Command*> CommandMap;
typedef std::map<const std::string, command::Command*>
CommandMap;
CommandMap map = entity->getNewStyleCommandMap();
unsigned int nbCommands = map.size();
Py_ssize_t nbCommands = (Py_ssize_t)map.size();
// Create a tuple of same size as the command map
PyObject* result = PyTuple_New(nbCommands);
unsigned int count = 0;
......
......@@ -34,15 +34,20 @@ namespace dynamicgraph {
return NULL;
std::vector <std::string> classNames;
dynamicgraph::FactoryStorage::getInstance()->listEntities(classNames);
unsigned int classNumber = classNames.size();
dynamicgraph::FactoryStorage::getInstance()
->listEntities(classNames);
Py_ssize_t classNumber = classNames.size();
// Build a tuple object
PyObject* classTuple = PyTuple_New(classNumber);
for (unsigned int iEntity = 0; iEntity < classNames.size(); iEntity++) {
PyObject* className = Py_BuildValue("s", classNames[iEntity].c_str());
PyTuple_SetItem(classTuple, iEntity, className);
}
for (Py_ssize_t iEntity = 0;
iEntity < (Py_ssize_t)classNames.size(); ++iEntity)
{
PyObject* className =
Py_BuildValue("s", classNames[iEntity].c_str());
PyTuple_SetItem(classTuple, iEntity, className);
}
return Py_BuildValue("O", classTuple);
}
......
......@@ -68,11 +68,12 @@ bool HandleErr(std::string & err,
PyTuple_SET_ITEM(args, 2, ptraceback);
pyerr = PyObject_CallObject(traceback_format_exception, args);
assert(PyList_Check(pyerr));
unsigned int size = PyList_GET_SIZE(pyerr);
Py_ssize_t size = PyList_GET_SIZE(pyerr);
std::string stringRes;
for (unsigned int i=0; i<size; i++) {
stringRes += std::string(PyString_AsString(PyList_GET_ITEM(pyerr, i)));
}
for (Py_ssize_t i=0; i<size; ++i)
stringRes += std::string
(PyString_AsString(PyList_GET_ITEM(pyerr, i)));
pyerr = PyString_FromString(stringRes.c_str());
err = PyString_AsString(pyerr);
dgDEBUG(15) << "err: " << err << std::endl;
......
......@@ -29,13 +29,15 @@ namespace dynamicgraph {
return NULL;
std::vector<std::string> typeList =
dynamicgraph::SignalCaster::getInstance()->listTypenames();
unsigned int typeNumber = typeList.size();
Py_ssize_t typeNumber = typeList.size();
// Build a tuple object
PyObject* typeTuple = PyTuple_New(typeNumber);
for (unsigned int iType = 0; iType < typeNumber; iType++) {
PyObject* className = Py_BuildValue("s", typeList[iType].c_str());
PyTuple_SetItem(typeTuple, iType, className);
for (Py_ssize_t iType = 0; iType < typeNumber; ++iType)
{
PyObject* className =
Py_BuildValue("s", typeList[iType].c_str());
PyTuple_SetItem(typeTuple, iType, className);
}
return Py_BuildValue("O", typeTuple);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment