comparison oct-py-types.cc @ 328:5782d7932529

Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56) * oct-py-types.cc, oct-py-types.h (pytave::extract_py_int64): New function. * python_to_octave.cc (pytave::pyobj_to_octvalue): Convert Python 2 'int' to Octave int64 type. * @py/py.m, pycall.cc: Add %!tests for Python 'int' and 'long' type handling, conditional on Python version.
author Mike Miller <mtmiller@octave.org>
date Sat, 13 Aug 2016 23:52:57 -0700
parents fd5881d48238
children c081e30c2f64
comparison
equal deleted inserted replaced
327:15c20ab4b80a 328:5782d7932529
66 } 66 }
67 67
68 return dict; 68 return dict;
69 } 69 }
70 70
71 int64_t
72 extract_py_int64 (PyObject *obj)
73 {
74 if (! obj)
75 throw object_convert_exception ("failed to extract integer: null object");
76
77 if (PyLong_Check (obj))
78 return PyLong_AsLong (obj);
79 #if PY_VERSION_HEX < 0x03000000
80 else if (PyInt_Check (obj))
81 return PyInt_AsLong (obj);
82 #endif
83 else
84 throw object_convert_exception ("failed to extract integer: wrong type");
85
86 return 0;
87 }
88
71 std::string 89 std::string
72 extract_py_str (PyObject *obj) 90 extract_py_str (PyObject *obj)
73 { 91 {
74 std::string retval; 92 std::string retval;
75 93