Skip to content

Commit 4057267

Browse files
committed
Change qhull FILE* handling to work on Windows
1 parent a65066d commit 4057267

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

setupext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,8 @@ class QhullWrap(SetupPackage):
10461046

10471047
def get_extension(self):
10481048
sources = ['src/qhull_wrap.c']
1049-
ext = make_extension('matplotlib._qhull', sources)
1049+
ext = make_extension('matplotlib._qhull', sources,
1050+
define_macros=[('MPL_DEVNULL', os.devnull)])
10501051
Numpy().add_flags(ext)
10511052
Qhull().add_flags(ext)
10521053
return ext

src/qhull_wrap.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
#define PY3K 0
1818
#endif
1919

20+
#ifndef MPL_DEVNULL
21+
#error "MPL_DEVNULL must be defined as the OS-equivalent of /dev/null"
22+
#endif
23+
24+
#define STRINGIFY(x) STR(x)
25+
#define STR(x) #x
26+
2027

2128
static const char* qhull_error_msg[6] = {
2229
"", /* 0 = qh_ERRnone */
@@ -118,11 +125,13 @@ delaunay_impl(int npoints, const double* x, const double* y,
118125

119126
/* qhull expects a FILE* to write errors to. */
120127
if (hide_qhull_errors) {
121-
/* qhull errors written to temporary file and ignored. */
122-
error_file = tmpfile();
128+
/* qhull errors are ignored by writing to OS-equivalent of /dev/null.
129+
* Rather than have OS-specific code here, instead it is determined by
130+
* setupext.py and passed in via the macro MPL_DEVNULL. */
131+
error_file = fopen(STRINGIFY(MPL_DEVNULL), "w");
123132
if (error_file == NULL) {
124-
PyErr_SetString(PyExc_MemoryError,
125-
"Could not create temporary file in qhull.delaunay");
133+
PyErr_SetString(PyExc_RuntimeError,
134+
"Could not open devnull in qhull.delaunay");
126135
goto error_before_qhull;
127136
}
128137
}

0 commit comments

Comments
 (0)