Commit 5a5580a8 authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

Fix tests for XShm.h.

Sat Jun 23 18:02:46 2001  Owen Taylor  <otaylor@redhat.com>

        * configure.in: Fix tests for XShm.h.

        * gdk/x11/gdkimage-x11.c: Cleanup error handling in
        gdk_image_new() by use of goto, properly use g_object_unref().
parent 92e87e40
Sat Jun 23 18:02:46 2001 Owen Taylor <otaylor@redhat.com>
* configure.in: Fix tests for XShm.h.
* gdk/x11/gdkimage-x11.c: Cleanup error handling in
gdk_image_new() by use of goto, properly use g_object_unref().
Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org> Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org>
* gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image) * gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image)
......
Sat Jun 23 18:02:46 2001 Owen Taylor <otaylor@redhat.com>
* configure.in: Fix tests for XShm.h.
* gdk/x11/gdkimage-x11.c: Cleanup error handling in
gdk_image_new() by use of goto, properly use g_object_unref().
Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org> Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org>
* gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image) * gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image)
......
Sat Jun 23 18:02:46 2001 Owen Taylor <otaylor@redhat.com>
* configure.in: Fix tests for XShm.h.
* gdk/x11/gdkimage-x11.c: Cleanup error handling in
gdk_image_new() by use of goto, properly use g_object_unref().
Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org> Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org>
* gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image) * gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image)
......
Sat Jun 23 18:02:46 2001 Owen Taylor <otaylor@redhat.com>
* configure.in: Fix tests for XShm.h.
* gdk/x11/gdkimage-x11.c: Cleanup error handling in
gdk_image_new() by use of goto, properly use g_object_unref().
Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org> Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org>
* gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image) * gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image)
......
Sat Jun 23 18:02:46 2001 Owen Taylor <otaylor@redhat.com>
* configure.in: Fix tests for XShm.h.
* gdk/x11/gdkimage-x11.c: Cleanup error handling in
gdk_image_new() by use of goto, properly use g_object_unref().
Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org> Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org>
* gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image) * gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image)
......
Sat Jun 23 18:02:46 2001 Owen Taylor <otaylor@redhat.com>
* configure.in: Fix tests for XShm.h.
* gdk/x11/gdkimage-x11.c: Cleanup error handling in
gdk_image_new() by use of goto, properly use g_object_unref().
Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org> Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org>
* gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image) * gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image)
......
Sat Jun 23 18:02:46 2001 Owen Taylor <otaylor@redhat.com>
* configure.in: Fix tests for XShm.h.
* gdk/x11/gdkimage-x11.c: Cleanup error handling in
gdk_image_new() by use of goto, properly use g_object_unref().
Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org> Sat Jun 23 22:03:20 2001 Tim Janik <timj@gtk.org>
* gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image) * gdk/x11/gdkimage-x11.c (gdk_image_init): disabled g_free (image)
......
...@@ -775,18 +775,27 @@ if test "x$gdktarget" = "xx11"; then ...@@ -775,18 +775,27 @@ if test "x$gdktarget" = "xx11"; then
AC_CHECK_HEADER(sys/shm.h, AC_DEFINE(HAVE_SHM_H), no_sys_shm=yes) AC_CHECK_HEADER(sys/shm.h, AC_DEFINE(HAVE_SHM_H), no_sys_shm=yes)
# Check for the X shared memory extension header file # Check for the X shared memory extension header file
have_xshm=no
AC_MSG_CHECKING(X11/extensions/XShm.h) AC_MSG_CHECKING(X11/extensions/XShm.h)
if test "x$no_xext_lib" = "xyes"; then if test "x$no_xext_lib" = "xyes"; then
AC_MSG_RESULT(no) :
no_xshm=yes
else else
if test -f "$x_includes/X11/extensions/XShm.h"; then gtk_save_CFLAGS="$CFLAGS"
AC_MSG_RESULT(yes) CFLAGS="$CFLAGS $x_cflags"
AC_DEFINE(HAVE_XSHM_H) AC_TRY_COMPILE([
else #include <stdlib.h>
AC_MSG_RESULT(no) #include <sys/types.h>
no_xshm=yes #include <sys/ipc.h>
fi #include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XShm.h>
], [XShmSegmentInfo *x_shm_info;], have_xshm=yes)
CFLAGS="$gtk_save_CFLAGS"
fi
AC_MSG_RESULT($have_xshm)
if test $have_xshm = yes ; then
AC_DEFINE(HAVE_XSHM_H)
fi fi
fi fi
......
...@@ -62,8 +62,6 @@ static void gdk_image_finalize (GObject *object); ...@@ -62,8 +62,6 @@ static void gdk_image_finalize (GObject *object);
#define PRIVATE_DATA(image) ((GdkImagePrivateX11 *) GDK_IMAGE (image)->windowing_data) #define PRIVATE_DATA(image) ((GdkImagePrivateX11 *) GDK_IMAGE (image)->windowing_data)
#define LEAK_IMAGE(image) /* FIXME!! this should be g_object_unref */
GType GType
gdk_image_get_type (void) gdk_image_get_type (void)
{ {
...@@ -243,16 +241,17 @@ gdk_image_new (GdkImageType type, ...@@ -243,16 +241,17 @@ gdk_image_new (GdkImageType type,
{ {
private->x_shm_info = g_new (XShmSegmentInfo, 1); private->x_shm_info = g_new (XShmSegmentInfo, 1);
x_shm_info = private->x_shm_info; x_shm_info = private->x_shm_info;
x_shm_info->shmid = -1;
x_shm_info->shmaddr = (char*) -1;
private->ximage = XShmCreateImage (private->xdisplay, xvisual, visual->depth, private->ximage = XShmCreateImage (private->xdisplay, xvisual, visual->depth,
ZPixmap, NULL, x_shm_info, width, height); ZPixmap, NULL, x_shm_info, width, height);
if (private->ximage == NULL) if (private->ximage == NULL)
{ {
g_warning ("XShmCreateImage failed"); g_warning ("XShmCreateImage failed");
gdk_use_xshm = FALSE;
LEAK_IMAGE (image);
gdk_use_xshm = False; goto error;
return NULL;
} }
x_shm_info->shmid = shmget (IPC_PRIVATE, x_shm_info->shmid = shmget (IPC_PRIVATE,
...@@ -269,14 +268,10 @@ gdk_image_new (GdkImageType type, ...@@ -269,14 +268,10 @@ gdk_image_new (GdkImageType type,
if (errno != EINVAL) if (errno != EINVAL)
{ {
g_warning ("shmget failed: error %d (%s)", errno, g_strerror (errno)); g_warning ("shmget failed: error %d (%s)", errno, g_strerror (errno));
gdk_use_xshm = False; gdk_use_xshm = FALSE;
} }
XDestroyImage (private->ximage); goto error;
g_free (private->x_shm_info);
LEAK_IMAGE (image);
return NULL;
} }
x_shm_info->readOnly = False; x_shm_info->readOnly = False;
...@@ -286,20 +281,12 @@ gdk_image_new (GdkImageType type, ...@@ -286,20 +281,12 @@ gdk_image_new (GdkImageType type,
if (x_shm_info->shmaddr == (char*) -1) if (x_shm_info->shmaddr == (char*) -1)
{ {
g_warning ("shmat failed: error %d (%s)", errno, g_strerror (errno)); g_warning ("shmat failed: error %d (%s)", errno, g_strerror (errno));
XDestroyImage (private->ximage);
shmctl (x_shm_info->shmid, IPC_RMID, 0);
g_free (private->x_shm_info);
LEAK_IMAGE (image);
/* Failure in shmat is almost certainly permanent. Most likely error is /* Failure in shmat is almost certainly permanent. Most likely error is
* EMFILE, which would mean that we've exceeded the per-process * EMFILE, which would mean that we've exceeded the per-process
* Shm segment limit. * Shm segment limit.
*/ */
gdk_use_xshm = False; gdk_use_xshm = FALSE;
goto error;
return NULL;
} }
gdk_error_trap_push (); gdk_error_trap_push ();
...@@ -310,16 +297,8 @@ gdk_image_new (GdkImageType type, ...@@ -310,16 +297,8 @@ gdk_image_new (GdkImageType type,
if (gdk_error_trap_pop ()) if (gdk_error_trap_pop ())
{ {
/* this is the common failure case so omit warning */ /* this is the common failure case so omit warning */
XDestroyImage (private->ximage); gdk_use_xshm = FALSE;
shmdt (x_shm_info->shmaddr); goto error;
shmctl (x_shm_info->shmid, IPC_RMID, 0);
g_free (private->x_shm_info);
LEAK_IMAGE (image);
gdk_use_xshm = False;
return NULL;
} }
/* We mark the segment as destroyed so that when /* We mark the segment as destroyed so that when
...@@ -334,15 +313,10 @@ gdk_image_new (GdkImageType type, ...@@ -334,15 +313,10 @@ gdk_image_new (GdkImageType type,
image_list = g_list_prepend (image_list, image); image_list = g_list_prepend (image_list, image);
} }
else else
{ #else /* !USE_SHM */
LEAK_IMAGE (image); goto error;
return NULL;
}
break;
#else /* USE_SHM */
LEAK_IMAGE (image);
return NULL;
#endif /* USE_SHM */ #endif /* USE_SHM */
break;
case GDK_IMAGE_NORMAL: case GDK_IMAGE_NORMAL:
private->ximage = XCreateImage (private->xdisplay, xvisual, visual->depth, private->ximage = XCreateImage (private->xdisplay, xvisual, visual->depth,
ZPixmap, 0, 0, width, height, 32, 0); ZPixmap, 0, 0, width, height, 32, 0);
...@@ -352,6 +326,8 @@ gdk_image_new (GdkImageType type, ...@@ -352,6 +326,8 @@ gdk_image_new (GdkImageType type,
*/ */
private->ximage->data = malloc (private->ximage->bytes_per_line * private->ximage->data = malloc (private->ximage->bytes_per_line *
private->ximage->height); private->ximage->height);
if (!private->ximage->data)
goto error;
break; break;
case GDK_IMAGE_FASTEST: case GDK_IMAGE_FASTEST:
...@@ -369,6 +345,30 @@ gdk_image_new (GdkImageType type, ...@@ -369,6 +345,30 @@ gdk_image_new (GdkImageType type,
} }
return image; return image;
error:
if (private->ximage)
{
XDestroyImage (private->ximage);
private->ximage = NULL;
}
#ifdef USE_SHM
if (private->x_shm_info)
{
x_shm_info = private->x_shm_info;
if (x_shm_info->shmaddr != (char *)-1)
shmdt (x_shm_info->shmaddr);
if (x_shm_info->shmid != -1)
shmctl (x_shm_info->shmid, IPC_RMID, 0);
g_free (x_shm_info);
private->x_shm_info = NULL;
}
#endif /* USE_SHM */
g_object_unref (image);
return NULL;
} }
GdkImage* GdkImage*
...@@ -478,34 +478,37 @@ gdk_x11_image_destroy (GdkImage *image) ...@@ -478,34 +478,37 @@ gdk_x11_image_destroy (GdkImage *image)
* time from _finalize() * time from _finalize()
*/ */
return; return;
switch (image->type)
{
case GDK_IMAGE_NORMAL:
XDestroyImage (private->ximage);
break;
case GDK_IMAGE_SHARED: if (private->ximage) /* Deal with failure of creation */
{
switch (image->type)
{
case GDK_IMAGE_NORMAL:
XDestroyImage (private->ximage);
break;
case GDK_IMAGE_SHARED:
#ifdef USE_SHM #ifdef USE_SHM
gdk_flush(); gdk_flush();
XShmDetach (private->xdisplay, private->x_shm_info); XShmDetach (private->xdisplay, private->x_shm_info);
XDestroyImage (private->ximage); XDestroyImage (private->ximage);
x_shm_info = private->x_shm_info; x_shm_info = private->x_shm_info;
shmdt (x_shm_info->shmaddr); shmdt (x_shm_info->shmaddr);
g_free (private->x_shm_info); g_free (private->x_shm_info);
private->x_shm_info = NULL; private->x_shm_info = NULL;
image_list = g_list_remove (image_list, image); image_list = g_list_remove (image_list, image);
#else /* USE_SHM */ #else /* USE_SHM */
g_error ("trying to destroy shared memory image when gdk was compiled without shared memory support"); g_error ("trying to destroy shared memory image when gdk was compiled without shared memory support");
#endif /* USE_SHM */ #endif /* USE_SHM */
break; break;
case GDK_IMAGE_FASTEST: case GDK_IMAGE_FASTEST:
g_assert_not_reached (); g_assert_not_reached ();
}
} }
g_free (private); g_free (private);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment