changeset 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 2011e0d2f926
children 24555fba9964
files Makefile.am __py_struct_from_dict__.cc oct-py-init.cc oct-py-types.cc pyexec.cc
diffstat 5 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Thu May 04 09:41:40 2017 -0700
+++ b/Makefile.am	Thu May 04 12:31:07 2017 -0700
@@ -23,6 +23,7 @@
 ACLOCAL_AMFLAGS = -I m4
 
 AM_CPPFLAGS = $(OCTAVE_CPPFLAGS) $(PYTHON_CPPFLAGS)
+AM_CXXFLAGS = -W -Wall
 
 INCFLAGS = $(DEFAULT_INCLUDES)
 export INCFLAGS
--- a/__py_struct_from_dict__.cc	Thu May 04 09:41:40 2017 -0700
+++ b/__py_struct_from_dict__.cc	Thu May 04 12:31:07 2017 -0700
@@ -71,7 +71,7 @@
 %!error __py_class_name__ (1, 2)
 */
 
-DEFUN_DLD (__py_int64_scalar_value__, args, nargout,
+DEFUN_DLD (__py_int64_scalar_value__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn {} {} __py_int64_scalar_value__ (@var{x})\n\
 Extract a scalar int64 value from the Python integer @var{x}.\n\
@@ -123,7 +123,7 @@
 %!error __py_int64_scalar_value__ (1, 2)
 */
 
-DEFUN_DLD (__py_uint64_scalar_value__, args, nargout,
+DEFUN_DLD (__py_uint64_scalar_value__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn {} {} __py_uint64_scalar_value__ (@var{x})\n\
 Extract a scalar uint64 value from the Python integer @var{x}.\n\
@@ -174,7 +174,7 @@
 %!error __py_uint64_scalar_value__ (1, 2)
 */
 
-DEFUN_DLD (__py_is_none__, args, nargout,
+DEFUN_DLD (__py_is_none__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn  {} {} __py_is_none__ (@var{x})\n\
 Check whether the Python object @var{obj} is the @code{None} object.\n\
@@ -204,7 +204,7 @@
 %!error __py_is_none__ (1, 2)
 */
 
-DEFUN_DLD (__py_isinstance__, args, nargout,
+DEFUN_DLD (__py_isinstance__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn  {} {} __py_isinstance__ (@var{x})\n\
 Check whether the Python object @var{obj} is an instance of a Python type\n\
@@ -242,7 +242,7 @@
   return retval;
 }
 
-DEFUN_DLD (__py_objstore_del__, args, nargout,
+DEFUN_DLD (__py_objstore_del__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn {} {} __py_objstore_del__ (@var{key})\n\
 Delete the Python object stored under @var{key} from the object store.\n\
@@ -261,7 +261,7 @@
   return ovl ();
 }
 
-DEFUN_DLD (__py_objstore_get__, args, nargout,
+DEFUN_DLD (__py_objstore_get__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn {} {} __py_objstore_get__ (@var{key})\n\
 Get the Python object stored under @var{key} from the object store.\n\
@@ -285,7 +285,7 @@
   return ovl (retval);
 }
 
-DEFUN_DLD (__py_objstore_put__, args, nargout,
+DEFUN_DLD (__py_objstore_put__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn {} {} __py_objstore_put__ (@var{value})\n\
 Convert @var{value} to a Python value and store in the object store.\n\
@@ -308,7 +308,7 @@
   return ovl (octave_uint64 (key));
 }
 
-DEFUN_DLD (__py_string_value__, args, nargout,
+DEFUN_DLD (__py_string_value__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn {} {} __py_string_value__ (@var{obj})\n\
 Return the string value or representation of the Python object @var{obj}.\n\
@@ -343,7 +343,7 @@
   return ovl (str);
 }
 
-DEFUN_DLD (__py_struct_from_dict__, args, nargout,
+DEFUN_DLD (__py_struct_from_dict__, args, ,
            "-*- texinfo -*-\n\
 @deftypefn  {} {} __py_struct_from_dict__ (@var{dict})\n\
 Extract a scalar struct from the Python dict @var{dict}.\n\
--- a/oct-py-init.cc	Thu May 04 09:41:40 2017 -0700
+++ b/oct-py-init.cc	Thu May 04 12:31:07 2017 -0700
@@ -32,9 +32,11 @@
 {
 
 #if PY_VERSION_HEX >= 0x03000000
-  wchar_t *sys_argv[] { L"", nullptr };
+  static wchar_t sys_argv0[] {L'\0'};
+  static wchar_t *sys_argv[] {sys_argv0, nullptr};
 #else
-  char *sys_argv[] { "", nullptr };
+  static char sys_argv0[] {'\0'};
+  static char *sys_argv[] {sys_argv0, nullptr};
 #endif
 
   void
--- a/oct-py-types.cc	Thu May 04 09:41:40 2017 -0700
+++ b/oct-py-types.cc	Thu May 04 12:31:07 2017 -0700
@@ -42,16 +42,15 @@
   PyObject *
   make_py_bool (bool value)
   {
-    if (value)
-      Py_RETURN_TRUE;
-    else
-      Py_RETURN_FALSE;
+    python_object retval = value ? Py_True : Py_False;
+    Py_INCREF (retval);
+    return retval.release ();
   }
 
   PyObject *
   make_py_complex (std::complex<double> value)
   {
-    Py_complex& py_complex_value = reinterpret_cast<Py_complex&> (value);
+    Py_complex py_complex_value {value.real (), value.imag ()};
     return PyComplex_FromCComplex (py_complex_value);
   }
 
@@ -83,7 +82,7 @@
       throw object_convert_exception ("failed to extract complex: wrong type");
 
     Py_complex value = PyComplex_AsCComplex (obj);
-    return reinterpret_cast<std::complex<double>&> (value);
+    return std::complex<double> {value.real, value.imag};
   }
 
   double
@@ -375,10 +374,12 @@
         long value = PyLong_AsLongAndOverflow (obj, &overflow);
 #endif
         if (overflow)
-          if (overflow > 0)
-            value = std::numeric_limits<int64_t>::max ();
-          else
-            value = std::numeric_limits<int64_t>::min ();
+          {
+            if (overflow > 0)
+              value = std::numeric_limits<int64_t>::max ();
+            else
+              value = std::numeric_limits<int64_t>::min ();
+          }
         return static_cast<int64_t> (value);
       }
 #if PY_VERSION_HEX < 0x03000000
--- a/pyexec.cc	Thu May 04 09:41:40 2017 -0700
+++ b/pyexec.cc	Thu May 04 12:31:07 2017 -0700
@@ -31,7 +31,7 @@
 #include "oct-py-init.h"
 #include "oct-py-util.h"
 
-DEFUN_DLD (pyexec, args, nargout,
+DEFUN_DLD (pyexec, args, ,
            "-*- texinfo -*-\n\
 @deftypefn  {} {} pyexec (@var{expr})\n\
 @deftypefnx {} {} pyexec (@var{expr}, @var{localns})\n\