Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Python C interface PyArg_ParseTuple failing
  2. def SetPowerSupply(voltage, current, supply):
  3.        
  4. float voltage, current;
  5. int supply;
  6.  
  7. if (!PyArg_ParseTuple(args, "ffi", &voltage, &current, &supply))
  8. {
  9.     // Failed to parse
  10.     // ...
  11. }
  12.        
  13. PyObject *num = PyNumber_Float(PyTuple_GetItem(args, 0));
  14. voltage = PyFloat_AsDouble(num);
  15. Py_XDECREF(num);
  16.  
  17. num = PyNumber_Float(PyTuple_GetItem(args, 1));
  18. current = PyFloat_AsDouble(num);
  19. Py_XDECREF(num);
  20.  
  21. num = PyNumber_Int(PyTuple_GetItem(args, 2));
  22. supply = PyLong_AsLong(num);
  23. Py_XDECREF(num);
  24.        
  25. SetPowerSupply(37.5, 0.5, 1)
  26. SetPowerSupply(0, 0, 1)
  27.        
  28. if(!PyArg_ParseTuple(args, "s|siss", &board, &component, &pin, &colorStr, &msg))
  29. {
  30.     // Parsing the pin as an int failed, try as a string
  31.     if(!PyArg_ParseTuple(args, "s|ssss", &board, &component, &sPin, &colorStr, &msg))
  32.     {
  33.         // ...
  34.        
  35. if(!PyArg_ParseTuple(args, "s|siss", &board, &component, &pin, &colorStr, &msg))
  36. {
  37.     PyErr_Clear();
  38.  
  39.     // Parsing the pin as an int failed, try as a string
  40.     if(!PyArg_ParseTuple(args, "s|ssss", &board, &component, &sPin, &colorStr, &msg))
  41.     {
  42.         // ...