gimp r26045 - in branches/gimp-2-4: . plug-ins/pygimp



Author: larsc
Date: Thu Jul  3 11:43:23 2008
New Revision: 26045
URL: http://svn.gnome.org/viewvc/gimp?rev=26045&view=rev

Log:
2008-07-03  Lars-Peter Clausen  <lars metafoo de>

	Merged from trunk:
	
	* plug-ins/pygimp/pygimp-drawable.c
	* plug-ins/pygimp/pygimp-vectors.c
	* plug-ins/pygimp/pygimp-display.c
	* plug-ins/pygimp/pygimp-image.c: Added checks to ensure that a python
	object only is created if its id is valid. Fixes bug #536403.
	* plug-ins/pygimp/pygimp-pdb.c
	* plug-ins/pygimp/pygimp-tile.c
	* plug-ins/pygimp/pygimp-colors.c
	* plug-ins/pygimp/pygimp.h: Fix crashing when pygimp is used with
	python-2.5 on 64 bit systems. Fixes bug #540629.



Modified:
   branches/gimp-2-4/ChangeLog
   branches/gimp-2-4/plug-ins/pygimp/pygimp-colors.c
   branches/gimp-2-4/plug-ins/pygimp/pygimp-display.c
   branches/gimp-2-4/plug-ins/pygimp/pygimp-drawable.c
   branches/gimp-2-4/plug-ins/pygimp/pygimp-image.c
   branches/gimp-2-4/plug-ins/pygimp/pygimp-pdb.c
   branches/gimp-2-4/plug-ins/pygimp/pygimp-tile.c
   branches/gimp-2-4/plug-ins/pygimp/pygimp-vectors.c
   branches/gimp-2-4/plug-ins/pygimp/pygimp.h

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp-colors.c
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp-colors.c	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp-colors.c	Thu Jul  3 11:43:23 2008
@@ -20,6 +20,7 @@
 
 #define NO_IMPORT_PYGOBJECT
 
+#include "pygimp.h"
 #include "pygimpcolor.h"
 
 #include <libgimpmath/gimpmath.h>
@@ -459,14 +460,14 @@
     { NULL, (getter)0, (setter)0 },
 };
 
-static int
+static Py_ssize_t 
 rgb_length(PyObject *self)
 {
     return 4;
 }
 
 static PyObject *
-rgb_getitem(PyObject *self, int pos)
+rgb_getitem(PyObject *self, Py_ssize_t pos)
 {
     GimpRGB *rgb;
     double val;
@@ -495,7 +496,7 @@
 }
 
 static int
-rgb_setitem(PyObject *self, int pos, PyObject *value)
+rgb_setitem(PyObject *self, Py_ssize_t pos, PyObject *value)
 {
     if (pos < 0)
         pos += 4;
@@ -517,10 +518,10 @@
 }
 
 static PyObject *
-rgb_slice(PyObject *self, int start, int end)
+rgb_slice(PyObject *self, Py_ssize_t start, Py_ssize_t end)
 {
     PyTupleObject *ret;
-    int i;
+    Py_ssize_t i;
 
     if (start < 0)
 	start = 0;
@@ -540,13 +541,13 @@
 }
 
 static PySequenceMethods rgb_as_sequence = {
-    (inquiry)rgb_length,
+    rgb_length,
     (binaryfunc)0,
-    (intargfunc)0,
-    (intargfunc)rgb_getitem,
-    (intintargfunc)rgb_slice,
-    (intobjargproc)rgb_setitem,
-    (intintobjargproc)0,
+    0,
+    rgb_getitem,
+    rgb_slice,
+    rgb_setitem,
+    0,
     (objobjproc)0,
 };
 
@@ -562,7 +563,7 @@
 	    return NULL;
 	return rgb_getitem(self, i);
     } else if (PySlice_Check(item)) {
-	int start, stop, step, slicelength, cur, i;
+	Py_ssize_t start, stop, step, slicelength, cur, i;
 	PyObject *ret;
 
 	if (PySlice_GetIndicesEx((PySliceObject*)item, 4,
@@ -608,7 +609,7 @@
 }
 
 static PyMappingMethods rgb_as_mapping = {
-    (inquiry)rgb_length,
+    rgb_length,
     (binaryfunc)rgb_subscript,
     (objobjargproc)0
 };
@@ -982,14 +983,14 @@
     { NULL, (getter)0, (setter)0 },
 };
 
-static int
+static Py_ssize_t 
 hsv_length(PyObject *self)
 {
     return 4;
 }
 
 static PyObject *
-hsv_getitem(PyObject *self, int pos)
+hsv_getitem(PyObject *self, Py_ssize_t pos)
 {
     GimpHSV *hsv;
     double val, scale_factor;
@@ -1040,10 +1041,10 @@
 }
 
 static PyObject *
-hsv_slice(PyObject *self, int start, int end)
+hsv_slice(PyObject *self, Py_ssize_t start, Py_ssize_t end)
 {
     PyTupleObject *ret;
-    int i;
+    Py_ssize_t i;
 
     if (start < 0)
 	start = 0;
@@ -1063,13 +1064,13 @@
 }
 
 static PySequenceMethods hsv_as_sequence = {
-    (inquiry)hsv_length,
+    hsv_length,
     (binaryfunc)0,
-    (intargfunc)0,
-    (intargfunc)hsv_getitem,
-    (intintargfunc)hsv_slice,
-    (intobjargproc)hsv_setitem,
-    (intintobjargproc)0,
+    0,
+    hsv_getitem,
+    hsv_slice,
+    hsv_setitem,
+    0,
     (objobjproc)0,
 };
 
@@ -1085,7 +1086,7 @@
 	    return NULL;
 	return hsv_getitem(self, i);
     } else if (PySlice_Check(item)) {
-	int start, stop, step, slicelength, cur, i;
+	Py_ssize_t start, stop, step, slicelength, cur, i;
 	PyObject *ret;
 
 	if (PySlice_GetIndicesEx((PySliceObject*)item, 4,
@@ -1131,7 +1132,7 @@
 }
 
 static PyMappingMethods hsv_as_mapping = {
-    (inquiry)hsv_length,
+    hsv_length,
     (binaryfunc)hsv_subscript,
     (objobjargproc)0
 };
@@ -1495,14 +1496,14 @@
     { NULL, (getter)0, (setter)0 },
 };
 
-static int
+static Py_ssize_t
 hsl_length(PyObject *self)
 {
     return 4;
 }
 
 static PyObject *
-hsl_getitem(PyObject *self, int pos)
+hsl_getitem(PyObject *self, Py_ssize_t pos)
 {
     GimpHSL *hsl;
     double val, scale_factor;
@@ -1553,10 +1554,10 @@
 }
 
 static PyObject *
-hsl_slice(PyObject *self, int start, int end)
+hsl_slice(PyObject *self, Py_ssize_t start, Py_ssize_t end)
 {
     PyTupleObject *ret;
-    int i;
+    Py_ssize_t i;
 
     if (start < 0)
         start = 0;
@@ -1576,13 +1577,13 @@
 }
 
 static PySequenceMethods hsl_as_sequence = {
-    (inquiry)hsl_length,
+    hsl_length,
     (binaryfunc)0,
-    (intargfunc)0,
-    (intargfunc)hsl_getitem,
-    (intintargfunc)hsl_slice,
-    (intobjargproc)hsl_setitem,
-    (intintobjargproc)0,
+    0,
+    hsl_getitem,
+    hsl_slice,
+    hsl_setitem,
+    0,
     (objobjproc)0,
 };
 
@@ -1598,7 +1599,7 @@
             return NULL;
         return hsl_getitem(self, i);
     } else if (PySlice_Check(item)) {
-        int start, stop, step, slicelength, cur, i;
+        Py_ssize_t start, stop, step, slicelength, cur, i;
         PyObject *ret;
 
         if (PySlice_GetIndicesEx((PySliceObject*)item, 4,
@@ -1644,7 +1645,7 @@
 }
 
 static PyMappingMethods hsl_as_mapping = {
-    (inquiry)hsl_length,
+    hsl_length,
     (binaryfunc)hsl_subscript,
     (objobjargproc)0
 };
@@ -1999,14 +2000,14 @@
     { NULL, (getter)0, (setter)0 },
 };
 
-static int
+static Py_ssize_t
 cmyk_length(PyObject *self)
 {
     return 5;
 }
 
 static PyObject *
-cmyk_getitem(PyObject *self, int pos)
+cmyk_getitem(PyObject *self, Py_ssize_t pos)
 {
     GimpCMYK *cmyk;
     double val;
@@ -2059,10 +2060,10 @@
 }
 
 static PyObject *
-cmyk_slice(PyObject *self, int start, int end)
+cmyk_slice(PyObject *self, Py_ssize_t start, Py_ssize_t end)
 {
     PyTupleObject *ret;
-    int i;
+    Py_ssize_t i;
 
     if (start < 0)
         start = 0;
@@ -2082,13 +2083,13 @@
 }
 
 static PySequenceMethods cmyk_as_sequence = {
-    (inquiry)cmyk_length,
+    cmyk_length,
     (binaryfunc)0,
-    (intargfunc)0,
-    (intargfunc)cmyk_getitem,
-    (intintargfunc)cmyk_slice,
-    (intobjargproc)cmyk_setitem,
-    (intintobjargproc)0,
+    0,
+    cmyk_getitem,
+    cmyk_slice,
+    cmyk_setitem,
+    0,
     (objobjproc)0,
 };
 
@@ -2104,7 +2105,7 @@
             return NULL;
         return cmyk_getitem(self, i);
     } else if (PySlice_Check(item)) {
-        int start, stop, step, slicelength, cur, i;
+        Py_ssize_t start, stop, step, slicelength, cur, i;
         PyObject *ret;
 
         if (PySlice_GetIndicesEx((PySliceObject*)item, 5,
@@ -2153,7 +2154,7 @@
 }
 
 static PyMappingMethods cmyk_as_mapping = {
-    (inquiry)cmyk_length,
+    cmyk_length,
     (binaryfunc)cmyk_subscript,
     (objobjargproc)0
 };

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp-display.c
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp-display.c	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp-display.c	Thu Jul  3 11:43:23 2008
@@ -46,7 +46,7 @@
 {
     PyGimpDisplay *self;
 
-    if (ID == -1) {
+    if (!gimp_display_is_valid(ID)) {
         Py_INCREF(Py_None);
         return Py_None;
     }

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp-drawable.c
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp-drawable.c	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp-drawable.c	Thu Jul  3 11:43:23 2008
@@ -1202,21 +1202,16 @@
 {
     PyObject *self;
 
-    if (drawable == NULL && ID == -1) {
+    if (drawable != NULL)
+    ID = drawable->drawable_id;
+
+    if (!gimp_drawable_is_valid(ID)) {
 	Py_INCREF(Py_None);
 	return Py_None;
     }
 
-    if (drawable != NULL)
-	ID = drawable->drawable_id;
-
     /* create the appropriate object type */
-    
-    /* avoids calling gimp_drawable_is_layer with an invalid id
-     * pygimp_channel_new handles it cleanly 
-     */
-    if (gimp_drawable_is_valid(ID) && 
-        gimp_drawable_is_layer(ID))
+    if (gimp_drawable_is_layer(ID))
 	self = pygimp_layer_new(ID);
     else
 	self = pygimp_channel_new(ID);
@@ -1224,6 +1219,7 @@
     if (self == NULL)
 	return NULL;
 
+    if (PyObject_TypeCheck(self, &PyGimpDrawable_Type))
     ((PyGimpDrawable *)self)->drawable = drawable;
 
     return self;
@@ -1692,7 +1688,7 @@
     gchar *name;
 
     name = gimp_drawable_get_name(self->ID);
-    s = PyString_FromFormat("<gimp.Layer '%s'>", name);
+    s = PyString_FromFormat("<gimp.Layer '%s'>", name ? name : "(null)");
     g_free(name);
 
     return s;
@@ -1778,7 +1774,7 @@
 {
     PyGimpLayer *self;
 
-    if (ID == -1) {
+    if (!gimp_drawable_is_valid(ID) || !gimp_drawable_is_layer(ID)) {
 	Py_INCREF(Py_None);
 	return Py_None;
     }
@@ -1971,7 +1967,7 @@
     gchar *name;
 
     name = gimp_drawable_get_name(self->ID);
-    s = PyString_FromFormat("<gimp.Channel '%s'>", name);
+    s = PyString_FromFormat("<gimp.Channel '%s'>", name ? name : "(null)");
     g_free(name);
 
     return s;
@@ -2066,7 +2062,7 @@
 {
     PyGimpChannel *self;
 
-    if (ID == -1) {
+    if (!gimp_drawable_is_valid(ID) || !gimp_drawable_is_channel(ID)) {
 	Py_INCREF(Py_None);
 	return Py_None;
     }

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp-image.c
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp-image.c	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp-image.c	Thu Jul  3 11:43:23 2008
@@ -1225,7 +1225,7 @@
 {
     PyGimpImage *self;
 
-    if (ID == -1) {
+    if (!gimp_image_is_valid(ID)) {
 	Py_INCREF(Py_None);
 	return Py_None;
     }

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp-pdb.c
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp-pdb.c	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp-pdb.c	Thu Jul  3 11:43:23 2008
@@ -787,7 +787,7 @@
 #endif
 
     if (kwargs) {
-        int len, pos;
+        Py_ssize_t len, pos;
         PyObject *key, *val;
 
         len = PyDict_Size(kwargs);

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp-tile.c
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp-tile.c	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp-tile.c	Thu Jul  3 11:43:23 2008
@@ -142,10 +142,10 @@
     return s;
 }
 
-static int
-tile_length(PyGimpTile *self)
+static Py_ssize_t 
+tile_length(PyObject *self)
 {
-    return self->tile->ewidth * self->tile->eheight;
+    return ((PyGimpTile*)self)->tile->ewidth * ((PyGimpTile*)self)->tile->eheight;
 }
 
 static PyObject *
@@ -247,7 +247,7 @@
 }
 
 static PyMappingMethods tile_as_mapping = {
-    (inquiry)tile_length, /*length*/
+    tile_length, /*length*/
     (binaryfunc)tile_subscript, /*subscript*/
     (objobjargproc)tile_ass_sub, /*ass_sub*/
 };
@@ -354,8 +354,8 @@
 
 /* Code to access pr objects as mappings */
 
-static int
-pr_length(PyGimpPixelRgn *self)
+static Py_ssize_t 
+pr_length(PyObject *self)
 {
     PyErr_SetString(pygimp_error, "Can't get size of pixel region");
     return -1;
@@ -367,7 +367,7 @@
     GimpPixelRgn *pr = &(self->pr);
     int bpp = pr->bpp;
     PyObject *x, *y;
-    int x1, y1, x2, y2, xs, ys;
+    Py_ssize_t x1, y1, x2, y2, xs, ys;
 
     if (!PyTuple_Check(key) || PyTuple_Size(key) != 2) {
 	PyErr_SetString(PyExc_TypeError, "subscript must be a 2-tuple");
@@ -476,7 +476,7 @@
     int bpp = pr->bpp;
     PyObject *x, *y;
     guchar *buf;
-    int len, x1, x2, xs, y1, y2, ys;
+    Py_ssize_t len, x1, x2, xs, y1, y2, ys;
 	
     if (w == NULL) {
 	PyErr_SetString(PyExc_TypeError, "can't delete subscripts");
@@ -588,7 +588,7 @@
 }
 
 static PyMappingMethods pr_as_mapping = {
-    (inquiry)pr_length,		/*mp_length*/
+    pr_length,		/*mp_length*/
     (binaryfunc)pr_subscript,		/*mp_subscript*/
     (objobjargproc)pr_ass_sub,	/*mp_ass_subscript*/
 };

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp-vectors.c
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp-vectors.c	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp-vectors.c	Thu Jul  3 11:43:23 2008
@@ -973,7 +973,7 @@
 {
     PyGimpVectors *self;
 
-    if (ID == -1) {
+    if (!gimp_vectors_is_valid(ID)) {
         Py_INCREF(Py_None);
         return Py_None;
     }

Modified: branches/gimp-2-4/plug-ins/pygimp/pygimp.h
==============================================================================
--- branches/gimp-2-4/plug-ins/pygimp/pygimp.h	(original)
+++ branches/gimp-2-4/plug-ins/pygimp/pygimp.h	Thu Jul  3 11:43:23 2008
@@ -27,6 +27,12 @@
 #define _INSIDE_PYGIMP_
 #include "pygimp-api.h"
 
+#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
+typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+#endif
+
 G_BEGIN_DECLS
 
 extern PyObject *pygimp_error;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]