Ticket #3189: boost_python_unsigned_converter_fix.patch

File boost_python_unsigned_converter_fix.patch, 1.2 KB (added by anderson.lizardo@…, 13 years ago)

Patch for bug #3189 (against boost trunk)

  • libs/python/src/converter/builtin_converters.cpp

     
    155155  {
    156156      static T extract(PyObject* intermediate)
    157157      {
    158           return numeric_cast<T>(
    159               PyLong_Check(intermediate)
    160               ? PyLong_AsUnsignedLong(intermediate)
    161               : PyInt_AS_LONG(intermediate));
     158          if (PyLong_Check(intermediate)) {
     159              unsigned long result = PyLong_AsUnsignedLong(intermediate);
     160              if (PyErr_Occurred())
     161                  throw_error_already_set();
     162              return numeric_cast<T>(result);
     163          } else {
     164              long result = PyInt_AS_LONG(intermediate);
     165              if (PyErr_Occurred())
     166                  throw_error_already_set();
     167              if (result < 0) {
     168                  PyErr_SetString(PyExc_ValueError, "argument must not be negative");
     169                  throw_error_already_set();
     170              }
     171              return numeric_cast<T>(result);
     172          }
    162173      }
    163174  };
    164175