Skip to content
This repository

Fix compiler warnings #1725

Merged
merged 1 commit into from about 1 year ago

4 participants

Damon McDougall Thomas A Caswell Phil Elson Michael Droettboom
Damon McDougall
Collaborator

Some of the compiler warnings started to bug me, so I tried to fix them. They're usually harmless, but sometimes they are not, as I will explain.

Currently, these are the warnings that are thrown during a python2.7 build of matplotlib (clang on a mac is used here)

After this patch is applied, these are the warnings that are still left. The first four are due to a 'bug' in the python API; treating string literals as char * rather than const char *. There is a patch upstream for it, but I'm not sure if it will be back-ported to python 2.7.4.

The last bunch of Tcl/Tk warnings are because the compiler is being handed both a -c flag and a -framework T{cl,k} flag, which are meant solely for the compilation and linking steps, respectively. To fix them, one would need to separate out the compile and link steps, but I don't know how to do that with distutils, and they only appear on the mac. Linux and windows compilers do not support the -framework flag.

I have tested this patch and I get a successful build with both Apple's builds of gcc and clang. All the tests pass locally with python 2.7. It would be nice to have these tested with python3, and a linux flavour of compiler.

I also fixed a typo in a comment.

Damon McDougall
Collaborator

I didn't target 1.2.x on purpose. These don't fix bugs, and I didn't want them in 1.2.x 'just in case' they broke something I didn't think about.

Damon McDougall dmcdougall commented on the diff January 30, 2013
src/_backend_agg.cpp
@@ -2048,7 +2055,9 @@ class QuadMeshGenerator
2048 2055
     {
2049 2056
         if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES)
2050 2057
         {
2051  
-            npy_PyFile_DupClose(py_file, fp);
  2058
+            if (npy_PyFile_DupClose(py_file, fp)) {
  2059
+              throw Py::RuntimeError("Error closing dupe file handle");
  2060
+            }
1
Damon McDougall Collaborator

All this block does is make use of the value npy_PyFile_DupClose returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Damon McDougall dmcdougall commented on the diff January 30, 2013
src/_image.cpp
@@ -406,10 +406,6 @@
406 406
 
407 407
     typedef agg::span_allocator<agg::rgba8> span_alloc_type;
408 408
     span_alloc_type sa;
409  
-    agg::rgba8 background(agg::rgba8(int(255*bg.r),
410  
-                                     int(255*bg.g),
411  
-                                     int(255*bg.b),
412  
-                                     int(255*bg.a)));
1
Damon McDougall Collaborator

The compiler told me this was unused, so I removed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Thomas A Caswell
Collaborator

debian sid, gcc 4.7.2, python 2.7.3

warnings on master https://gist.github.com/4683894

Warnings on this branch https://gist.github.com/4683594

Phil Elson pelson commented on the diff February 04, 2013
src/_backend_agg.cpp
@@ -39,6 +39,13 @@
39 39
 
40 40
 #include "numpy/arrayobject.h"
41 41
 #include "agg_py_transforms.h"
  42
+
  43
+// This C function resides in npy_3kcompat.h and is unused by
  44
+// matplotlib. This is here so that the compiler doesn't complain
  45
+// that it is unused.
  46
+extern "C" {
  47
+__attribute__((unused)) static void simple_capsule_dtor(void *ptr);
2
Phil Elson Collaborator
pelson added a note February 04, 2013

Personally, I have absolutely no idea what this does (black magic :smile:). Could somebody who does give it the :+1: please?

Michael Droettboom Owner
mdboom added a note February 04, 2013

Seems fine, except I wish there were a cleaner way to hide this warning... Don't know what that would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Phil Elson
Collaborator

Other than my lack of understanding which I have pointed out, I'd be happy enough to merge this. Your right about targetting v1.3.x - I would be very uncomfortable with this kind of change slipping into v1.2.x as we could easily be introducing a subtle regression...

Michael Droettboom
Owner

Looks fine -- but I may have some further changes shortly for some more warnings I'm still getting on my platform.

Damon McDougall
Collaborator

@mdboom Go for it! :)

Michael Droettboom
Owner

I'm not seeing the compiler warnings I was seeing before -- perhaps I hadn't enough coffee that day. I think this is good to merge...

Michael Droettboom mdboom merged commit 091c149 into from February 20, 2013
Michael Droettboom mdboom closed this February 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 30, 2013
Damon McDougall Fix compiler warnings e1e771f
This page is out of date. Refresh to see the latest.
2  setupext.py
@@ -1030,7 +1030,7 @@ def add_tk_flags(module):
1030 1030
                 if not exists(join(F, fw + '.framework')):
1031 1031
                     break
1032 1032
             else:
1033  
-                # ok, F is now directory with both frameworks. Continure
  1033
+                # ok, F is now directory with both frameworks. Continue
1034 1034
                 # building
1035 1035
                 tk_framework_found = 1
1036 1036
                 break
15  src/_backend_agg.cpp
@@ -39,6 +39,13 @@
39 39
 
40 40
 #include "numpy/arrayobject.h"
41 41
 #include "agg_py_transforms.h"
  42
+
  43
+// This C function resides in npy_3kcompat.h and is unused by
  44
+// matplotlib. This is here so that the compiler doesn't complain
  45
+// that it is unused.
  46
+extern "C" {
  47
+__attribute__((unused)) static void simple_capsule_dtor(void *ptr);
  48
+}
42 49
 #include "file_compat.h"
43 50
 
44 51
 #ifndef M_PI
@@ -2048,7 +2055,9 @@ RendererAgg::write_rgba(const Py::Tuple& args)
2048 2055
     {
2049 2056
         if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES)
2050 2057
         {
2051  
-            npy_PyFile_DupClose(py_file, fp);
  2058
+            if (npy_PyFile_DupClose(py_file, fp)) {
  2059
+              throw Py::RuntimeError("Error closing dupe file handle");
  2060
+            }
2052 2061
 
2053 2062
             if (close_file) {
2054 2063
                 npy_PyFile_CloseFile(py_file);
@@ -2058,7 +2067,9 @@ RendererAgg::write_rgba(const Py::Tuple& args)
2058 2067
             throw Py::RuntimeError("Error writing to file");
2059 2068
         }
2060 2069
 
2061  
-        npy_PyFile_DupClose(py_file, fp);
  2070
+        if (npy_PyFile_DupClose(py_file, fp)) {
  2071
+          throw Py::RuntimeError("Error closing dupe file handle");
  2072
+        }
2062 2073
 
2063 2074
         if (close_file) {
2064 2075
             npy_PyFile_CloseFile(py_file);
4  src/_image.cpp
@@ -406,10 +406,6 @@ Image::resize(const Py::Tuple& args, const Py::Dict& kwargs)
406 406
 
407 407
     typedef agg::span_allocator<agg::rgba8> span_alloc_type;
408 408
     span_alloc_type sa;
409  
-    agg::rgba8 background(agg::rgba8(int(255*bg.r),
410  
-                                     int(255*bg.g),
411  
-                                     int(255*bg.b),
412  
-                                     int(255*bg.a)));
413 409
 
414 410
     // the image path
415 411
     agg::path_storage path;
19  src/_png.cpp
@@ -27,6 +27,13 @@
27 27
 #include "CXX/Extensions.hxx"
28 28
 #include "numpy/arrayobject.h"
29 29
 #include "mplutils.h"
  30
+
  31
+// This C function resides in npy_3kcompat.h and is unused by
  32
+// matplotlib. This is here so that the compiler doesn't complain
  33
+// that it is unused.
  34
+extern "C" {
  35
+__attribute__((unused)) static void simple_capsule_dtor(void *ptr);
  36
+}
30 37
 #include "file_compat.h"
31 38
 
32 39
 // As reported in [3082058] build _png.so on aix
@@ -239,7 +246,9 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
239 246
 
240 247
         if (close_dup_file)
241 248
         {
242  
-            npy_PyFile_DupClose(py_file, fp);
  249
+            if (npy_PyFile_DupClose(py_file, fp)) {
  250
+              throw Py::RuntimeError("Error closing dupe file handle");
  251
+            }
243 252
         }
244 253
 
245 254
         if (close_file)
@@ -258,7 +267,9 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
258 267
     delete [] row_pointers;
259 268
     if (close_dup_file)
260 269
     {
261  
-        npy_PyFile_DupClose(py_file, fp);
  270
+        if (npy_PyFile_DupClose(py_file, fp)) {
  271
+          throw Py::RuntimeError("Error closing dupe file handle");
  272
+        }
262 273
     }
263 274
 
264 275
     if (close_file)
@@ -569,7 +580,9 @@ _png_module::_read_png(const Py::Object& py_fileobj, const bool float_result,
569 580
 #endif
570 581
     if (close_dup_file)
571 582
     {
572  
-        npy_PyFile_DupClose(py_file, fp);
  583
+        if (npy_PyFile_DupClose(py_file, fp)) {
  584
+          throw Py::RuntimeError("Error closing dupe file handle");
  585
+        }
573 586
     }
574 587
 
575 588
     if (close_file)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.