Skip to content

Commit

Permalink
Clean up defines and includes for Windows
Browse files Browse the repository at this point in the history
1)  Renamed USE_INLINE to PIL_USE_INLINE to avoid conflicts with
    other headers/libraries.

2)  Replace __WIN32__ and WIN32 with _WIN32

3)  Don't define WIN32 when the compiler is MSVC but not on Windows
    Why would you even...

4)  Don't define strcasecmp if you're not even going to use it.

5)  Don't include Windows.h with undefs for compilers newer than
    1998 everywhere.

6)  Don't surpress warnings for MSVC++ 4.0. People still using
    MSVC++ 4.0 deserve it.

7)  Don't include things that are already included in Windows.h
  • Loading branch information
CounterPillow committed May 9, 2014
1 parent 37bb8ee commit 052ea60
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 71 deletions.
6 changes: 3 additions & 3 deletions _imaging.c
Expand Up @@ -3350,7 +3350,7 @@ extern PyObject* PyImaging_ZipEncoderNew(PyObject* self, PyObject* args);
extern PyObject* PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args);

/* Display support etc (in display.c) */
#ifdef WIN32
#ifdef _WIN32
extern PyObject* PyImaging_CreateWindowWin32(PyObject* self, PyObject* args);
extern PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args);
extern PyObject* PyImaging_DisplayModeWin32(PyObject* self, PyObject* args);
Expand Down Expand Up @@ -3423,14 +3423,14 @@ static PyMethodDef functions[] = {

/* Memory mapping */
#ifdef WITH_MAPPING
#ifdef WIN32
#ifdef _WIN32
{"map", (PyCFunction)PyImaging_Mapper, 1},
#endif
{"map_buffer", (PyCFunction)PyImaging_MapBuffer, 1},
#endif

/* Display support */
#ifdef WIN32
#ifdef _WIN32
{"display", (PyCFunction)PyImaging_DisplayWin32, 1},
{"display_mode", (PyCFunction)PyImaging_DisplayModeWin32, 1},
{"grabscreen", (PyCFunction)PyImaging_GrabScreenWin32, 1},
Expand Down
10 changes: 2 additions & 8 deletions _imagingcms.c
Expand Up @@ -28,12 +28,6 @@ kevin@cazabon.com\n\
#include "Imaging.h"
#include "py3.h"

#ifdef WIN32
#include <windows.h>
#include <windef.h>
#include <wingdi.h>
#endif

#define PYCMSVERSION "1.0.0 pil"

/* version history */
Expand Down Expand Up @@ -450,7 +444,7 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args)
return PyInt_FromLong(result != 0);
}

#ifdef WIN32
#ifdef _WIN32
static PyObject *
cms_get_display_profile_win32(PyObject* self, PyObject* args)
{
Expand Down Expand Up @@ -496,7 +490,7 @@ static PyMethodDef pyCMSdll_methods[] = {
{"createProfile", createProfile, 1},

/* platform specific tools */
#ifdef WIN32
#ifdef _WIN32
{"get_display_profile_win32", cms_get_display_profile_win32, 1},
#endif

Expand Down
3 changes: 0 additions & 3 deletions decode.c
Expand Up @@ -433,9 +433,6 @@ PyImaging_TiffLzwDecoderNew(PyObject* self, PyObject* args)
#include "TiffDecode.h"

#include <string.h>
#ifdef __WIN32__
#define strcasecmp(s1, s2) stricmp(s1, s2)
#endif

PyObject*
PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args)
Expand Down
4 changes: 2 additions & 2 deletions display.c
Expand Up @@ -31,7 +31,7 @@
/* -------------------------------------------------------------------- */
/* Windows DIB support */

#ifdef WIN32
#ifdef _WIN32

#include "ImDib.h"

Expand Down Expand Up @@ -864,4 +864,4 @@ PyImaging_DrawWmf(PyObject* self, PyObject* args)
return buffer;
}

#endif /* WIN32 */
#endif /* _WIN32 */
3 changes: 0 additions & 3 deletions encode.c
Expand Up @@ -670,9 +670,6 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
#include "TiffDecode.h"

#include <string.h>
#ifdef __WIN32__
#define strcasecmp(s1, s2) stricmp(s1, s2)
#endif

PyObject*
PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
Expand Down
4 changes: 2 additions & 2 deletions libImaging/Dib.c
Expand Up @@ -22,7 +22,7 @@

#include "Imaging.h"

#ifdef WIN32
#ifdef _WIN32

#include "ImDib.h"

Expand Down Expand Up @@ -308,4 +308,4 @@ ImagingDeleteDIB(ImagingDIB dib)
free(dib->info);
}

#endif /* WIN32 */
#endif /* _WIN32 */
15 changes: 2 additions & 13 deletions libImaging/ImDib.h
Expand Up @@ -10,20 +10,9 @@
* See the README file for information on usage and redistribution.
*/

#ifdef WIN32
#ifdef _WIN32

#if (defined(_MSC_VER) && _MSC_VER >= 1200) || (defined __GNUC__)
/* already defined in basetsd.h */
#undef INT8
#undef UINT8
#undef INT16
#undef UINT16
#undef INT32
#undef INT64
#undef UINT32
#endif

#include <windows.h>
#include "ImPlatform.h"

#if defined(__cplusplus)
extern "C" {
Expand Down
41 changes: 20 additions & 21 deletions libImaging/ImPlatform.h
Expand Up @@ -17,27 +17,22 @@
#error Sorry, this library requires ANSI header files.
#endif

#if defined(_MSC_VER)
#ifndef WIN32
#define WIN32
#endif
/* VC++ 4.0 is a bit annoying when it comes to precision issues (like
claiming that "float a = 0.0;" would lead to loss of precision). I
don't like to see warnings from my code, but since I still want to
keep it readable, I simply switch off a few warnings instead of adding
the tons of casts that VC++ seem to require. This code is compiled
with numerous other compilers as well, so any real errors are likely
to be catched anyway. */
#pragma warning(disable: 4244) /* conversion from 'float' to 'int' */
#endif

#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__GNUC__)
#define inline __inline
#endif
#if !defined(USE_INLINE)
#define inline

#if !defined(PIL_USE_INLINE)
#define inline
#endif

#ifdef _WIN32

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

#else
/* For System that are not Windows, we'll need to define these. */

#if SIZEOF_SHORT == 2
#define INT16 short
#elif SIZEOF_INT == 2
Expand All @@ -62,12 +57,16 @@
#define INT64 long
#endif

/* assume IEEE; tweak if necessary (patches are welcome) */
#define FLOAT32 float
#define FLOAT64 double

#define INT8 signed char
#define UINT8 unsigned char

#define UINT16 unsigned INT16
#define UINT32 unsigned INT32

#endif

/* assume IEEE; tweak if necessary (patches are welcome) */
#define FLOAT32 float
#define FLOAT64 double


1 change: 0 additions & 1 deletion libImaging/Incremental.c
Expand Up @@ -41,7 +41,6 @@
two cases. */

#ifdef _WIN32
#include <windows.h>
#include <process.h>
#else
#include <pthread.h>
Expand Down
18 changes: 3 additions & 15 deletions map.c
Expand Up @@ -22,18 +22,6 @@

#include "Imaging.h"

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#undef INT8
#undef UINT8
#undef INT16
#undef UINT16
#undef INT32
#undef INT64
#undef UINT32
#include "windows.h"
#endif

#include "py3.h"

/* compatibility wrappers (defined in _imaging.c) */
Expand All @@ -48,7 +36,7 @@ typedef struct {
char* base;
int size;
int offset;
#ifdef WIN32
#ifdef _WIN32
HANDLE hFile;
HANDLE hMap;
#endif
Expand All @@ -71,7 +59,7 @@ PyImaging_MapperNew(const char* filename, int readonly)
mapper->base = NULL;
mapper->size = mapper->offset = 0;

#ifdef WIN32
#ifdef _WIN32
mapper->hFile = (HANDLE)-1;
mapper->hMap = (HANDLE)-1;

Expand Down Expand Up @@ -114,7 +102,7 @@ PyImaging_MapperNew(const char* filename, int readonly)
static void
mapping_dealloc(ImagingMapperObject* mapper)
{
#ifdef WIN32
#ifdef _WIN32
if (mapper->base != 0)
UnmapViewOfFile(mapper->base);
if (mapper->hMap != (HANDLE)-1)
Expand Down

0 comments on commit 052ea60

Please sign in to comment.