comparison oct-py-types.cc @ 420:7864849e84c2

Eliminate some compiler warnings * Makefile.am (AM_CXXFLAGS): Build with -W -Wall by default. * __py_struct_from_dict__.cc (F__py_int64_scalar_value__, F__py_uint64_scalar_value__, F__py_is_none__, F__py_isinstance__, F__py_objstore_del__, F__py_objstore_get__, F__py_objstore_put__, F__py_string_value__, F__py_struct_from_dict__): Remove unused parameter to eliminate -Wunused-parameter warning. * pyexec.cc (Fpyexec): Likewise. * oct-py-init.cc (pytave::py_init): Declare argv array correctly to eliminate -Wwrite-strings warning. * oct-py-types.cc (pytave::make_py_bool): Explicitly increment and return value to eliminate -Wstrict-aliasing warning. (pytave::make_py_complex, pytave::extract_py_complex): Copy complex values between C++ and Python types to eliminate -Wstrict-aliasing warning. (pytave::extract_py_int64): Add braces to nested if block to eliminate -Wparentheses warning.
author Mike Miller <mtmiller@octave.org>
date Thu, 04 May 2017 12:31:07 -0700
parents 9bf8ba050122
children 24555fba9964
comparison
equal deleted inserted replaced
419:2011e0d2f926 420:7864849e84c2
40 { 40 {
41 41
42 PyObject * 42 PyObject *
43 make_py_bool (bool value) 43 make_py_bool (bool value)
44 { 44 {
45 if (value) 45 python_object retval = value ? Py_True : Py_False;
46 Py_RETURN_TRUE; 46 Py_INCREF (retval);
47 else 47 return retval.release ();
48 Py_RETURN_FALSE;
49 } 48 }
50 49
51 PyObject * 50 PyObject *
52 make_py_complex (std::complex<double> value) 51 make_py_complex (std::complex<double> value)
53 { 52 {
54 Py_complex& py_complex_value = reinterpret_cast<Py_complex&> (value); 53 Py_complex py_complex_value {value.real (), value.imag ()};
55 return PyComplex_FromCComplex (py_complex_value); 54 return PyComplex_FromCComplex (py_complex_value);
56 } 55 }
57 56
58 PyObject * 57 PyObject *
59 make_py_float (double value) 58 make_py_float (double value)
81 80
82 if (! PyComplex_Check (obj)) 81 if (! PyComplex_Check (obj))
83 throw object_convert_exception ("failed to extract complex: wrong type"); 82 throw object_convert_exception ("failed to extract complex: wrong type");
84 83
85 Py_complex value = PyComplex_AsCComplex (obj); 84 Py_complex value = PyComplex_AsCComplex (obj);
86 return reinterpret_cast<std::complex<double>&> (value); 85 return std::complex<double> {value.real, value.imag};
87 } 86 }
88 87
89 double 88 double
90 extract_py_float (PyObject *obj) 89 extract_py_float (PyObject *obj)
91 { 90 {
373 PY_LONG_LONG value = PyLong_AsLongLongAndOverflow (obj, &overflow); 372 PY_LONG_LONG value = PyLong_AsLongLongAndOverflow (obj, &overflow);
374 #else 373 #else
375 long value = PyLong_AsLongAndOverflow (obj, &overflow); 374 long value = PyLong_AsLongAndOverflow (obj, &overflow);
376 #endif 375 #endif
377 if (overflow) 376 if (overflow)
378 if (overflow > 0) 377 {
379 value = std::numeric_limits<int64_t>::max (); 378 if (overflow > 0)
380 else 379 value = std::numeric_limits<int64_t>::max ();
381 value = std::numeric_limits<int64_t>::min (); 380 else
381 value = std::numeric_limits<int64_t>::min ();
382 }
382 return static_cast<int64_t> (value); 383 return static_cast<int64_t> (value);
383 } 384 }
384 #if PY_VERSION_HEX < 0x03000000 385 #if PY_VERSION_HEX < 0x03000000
385 else if (PyInt_Check (obj)) 386 else if (PyInt_Check (obj))
386 return PyInt_AsLong (obj); 387 return PyInt_AsLong (obj);