Hi,
Attached is a patch against the 0.6.5 release that fixes a number of core
dumps when attributes of a GdkStyle or GdkWindow object are accessed. It
adds checks for NULL pointers and returns None in those cases. It also
restricts the available attributes on a pixmap GdkWindow to depth, height,
type, & width -- accessing these attributes triggers errors at the Xlib
level.
I can update these patches to be either against 0.6.6 or the CVS sources
if that would help them get applied to future pygtk versions.
Thanks,
John
------------------------------------------------------------------------
Archaeopteryx Software, Inc. Wing IDE for Python
www.archaeopteryx.com Take Flight!
--- /home/jpe/down/pygtk-0.6.5/gtkmodule.c Mon Mar 13 04:04:14 2000
+++ gtkmodule.c Tue Sep 26 17:42:30 2000
@@ -637,10 +643,18 @@
return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->text_gc);
if (!strcmp(attr, "base_gc"))
return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->base_gc);
- if (!strcmp(attr, "black_gc"))
- return PyGdkGC_New(style->black_gc);
- if (!strcmp(attr, "white_gc"))
- return PyGdkGC_New(style->white_gc);
+ if (!strcmp(attr, "black_gc")) {
+ if (style->black_gc)
+ return PyGdkGC_New(style->black_gc);
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ if (!strcmp(attr, "white_gc")){
+ if (style->white_gc)
+ return PyGdkGC_New(style->white_gc);
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
if (!strcmp(attr, "bg_pixmap"))
return PyGtkStyleHelper_New(style, STYLE_PIXMAP_ARRAY, style->bg_pixmap);
if (!strcmp(attr, "colormap")) {
@@ -1674,76 +1696,102 @@
gint x, y;
GdkModifierType p_mask;
- if (!strcmp(key, "__members__"))
- return Py_BuildValue("[sssssssssssss]", "children", "colormap", "depth",
- "height", "parent", "pointer", "pointer_state",
- "toplevel", "type", "width", "x", "xid", "y");
- if (!strcmp(key, "width")) {
- gdk_window_get_size(win, &x, NULL);
- return PyInt_FromLong(x);
- }
- if (!strcmp(key, "height")) {
- gdk_window_get_size(win, NULL, &y);
- return PyInt_FromLong(y);
- }
- if (!strcmp(key, "x")) {
- gdk_window_get_position(win, &x, NULL);
- return PyInt_FromLong(x);
- }
- if (!strcmp(key, "y")) {
- gdk_window_get_position(win, NULL, &y);
- return PyInt_FromLong(y);
- }
- if (!strcmp(key, "colormap"))
- return PyGdkColormap_New(gdk_window_get_colormap(win));
- if (!strcmp(key, "pointer")) {
- gdk_window_get_pointer(win, &x, &y, NULL);
- return Py_BuildValue("(ii)", x, y);
- }
- if (!strcmp(key, "pointer_state")) {
- gdk_window_get_pointer(win, NULL, NULL, &p_mask);
- return PyInt_FromLong(p_mask);
+ if (gdk_window_get_type(win) == GDK_WINDOW_PIXMAP) {
+ if (!strcmp(key, "__members__"))
+ return Py_BuildValue("[ssss]", "depth", "height", "type", "width");
+ if (!strcmp(key, "width")) {
+ gdk_window_get_size(win, &x, NULL);
+ return PyInt_FromLong(x);
+ }
+ if (!strcmp(key, "height")) {
+ gdk_window_get_size(win, NULL, &y);
+ return PyInt_FromLong(y);
+ }
+ if (!strcmp(key, "type"))
+ return PyInt_FromLong(gdk_window_get_type(win));
+ if (!strcmp(key, "depth")) {
+ gdk_window_get_geometry(win, NULL, NULL, NULL, NULL, &x);
+ return PyInt_FromLong(x);
+ }
}
- if (!strcmp(key, "parent")) {
+ else {
+ if (!strcmp(key, "__members__"))
+ return Py_BuildValue("[sssssssssssss]", "children", "colormap", "depth",
+ "height", "parent", "pointer", "pointer_state",
+ "toplevel", "type", "width", "x", "xid", "y");
+ if (!strcmp(key, "width")) {
+ gdk_window_get_size(win, &x, NULL);
+ return PyInt_FromLong(x);
+ }
+ if (!strcmp(key, "height")) {
+ gdk_window_get_size(win, NULL, &y);
+ return PyInt_FromLong(y);
+ }
+ if (!strcmp(key, "x")) {
+ gdk_window_get_position(win, &x, NULL);
+ return PyInt_FromLong(x);
+ }
+ if (!strcmp(key, "y")) {
+ gdk_window_get_position(win, NULL, &y);
+ return PyInt_FromLong(y);
+ }
+ if (!strcmp(key, "colormap")) {
+ if (gdk_window_get_type(win) == GDK_WINDOW_PIXMAP) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyGdkColormap_New(gdk_window_get_colormap(win));
+ }
+ if (!strcmp(key, "pointer")) {
+ gdk_window_get_pointer(win, &x, &y, NULL);
+ return Py_BuildValue("(ii)", x, y);
+ }
+ if (!strcmp(key, "pointer_state")) {
+ gdk_window_get_pointer(win, NULL, NULL, &p_mask);
+ return PyInt_FromLong(p_mask);
+ }
+ if (!strcmp(key, "parent")) {
GdkWindow *par = gdk_window_get_parent(win);
if (par)
- return PyGdkWindow_New(par);
+ return PyGdkWindow_New(par);
Py_INCREF(Py_None);
return Py_None;
- }
- if (!strcmp(key, "toplevel"))
- return PyGdkWindow_New(gdk_window_get_toplevel(win));
- if (!strcmp(key, "children")) {
- GList *children, *tmp;
- PyObject *ret;
- children = gdk_window_get_children(win);
- if ((ret = PyList_New(0)) == NULL)
- return NULL;
- for (tmp = children; tmp != NULL; tmp = tmp->next) {
- PyObject *win = PyGdkWindow_New(tmp->data);
- if (win == NULL) {
- Py_DECREF(ret);
- return NULL;
+ }
+ if (!strcmp(key, "toplevel"))
+ return PyGdkWindow_New(gdk_window_get_toplevel(win));
+ if (!strcmp(key, "children")) {
+ GList *children, *tmp;
+ PyObject *ret;
+
+ if ((ret = PyList_New(0)) == NULL)
+ return NULL;
+ children = gdk_window_get_children(win);
+ for (tmp = children; tmp != NULL; tmp = tmp->next) {
+ PyObject *win = PyGdkWindow_New(tmp->data);
+ if (win == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyList_Append(ret, win);
+ Py_DECREF(win);
}
- PyList_Append(ret, win);
- Py_DECREF(win);
+ g_list_free(children);
+ return ret;
+ }
+ if (!strcmp(key, "type"))
+ return PyInt_FromLong(gdk_window_get_type(win));
+ if (!strcmp(key, "depth")) {
+ gdk_window_get_geometry(win, NULL, NULL, NULL, NULL, &x);
+ return PyInt_FromLong(x);
}
- g_list_free(children);
- return ret;
- }
- if (!strcmp(key, "type"))
- return PyInt_FromLong(gdk_window_get_type(win));
- if (!strcmp(key, "depth")) {
- gdk_window_get_geometry(win, NULL, NULL, NULL, NULL, &x);
- return PyInt_FromLong(x);
- }
#ifdef WITH_XSTUFF
- if (!strcmp(key, "xid"))
+ if (!strcmp(key, "xid"))
return PyInt_FromLong(GDK_WINDOW_XWINDOW(win));
#endif
+ }
- return Py_FindMethod(PyGdkWindow_methods, (PyObject *)self, key);
-}
+ return Py_FindMethod(PyGdkWindow_methods, (PyObject *)self, key);
+ }