From 088c752e4049767b3575fb8bb3c24b1190c5ad62 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Apr 2013 21:43:15 -0700 Subject: [PATCH] basic sanity check that the version of the _imaging.c and Image.py files are the same --- PIL/Image.py | 8 ++++++++ _imaging.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/PIL/Image.py b/PIL/Image.py index a8a34d59b..9a1fda875 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -27,6 +27,7 @@ from __future__ import print_function VERSION = "1.1.7" +PILLOW_VERSION = "2.0.0" try: import warnings @@ -54,6 +55,11 @@ try: # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. from PIL import _imaging as core + if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None): + raise ImportError("The _imaging extension was built for another " + " version of Pillow or PIL. Most PIL functions " + " will be disabled ") + except ImportError as v: core = _imaging_not_installed() if str(v)[:20] == "Module use of python" and warnings: @@ -65,6 +71,8 @@ except ImportError as v: "of Python; most PIL functions will be disabled", RuntimeWarning ) + if str(v).startswith("The _imaging extension") and warnings: + warnings.warn(str(v), RuntimeWarning) try: import builtins diff --git a/_imaging.c b/_imaging.c index c9d3c8247..b58a18d11 100644 --- a/_imaging.c +++ b/_imaging.c @@ -71,6 +71,7 @@ * See the README file for information on usage and redistribution. */ +#define PILLOW_VERSION "2.0.0" #include "Python.h" @@ -3431,6 +3432,8 @@ setup_module(PyObject* m) { } #endif + PyDict_SetItemString(d, "PILLOW_VERSION", PyUnicode_FromString(PILLOW_VERSION)); + return 0; }