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

Re: [pygame] "import pygame" crashes with svn build



Oops, forgot to attach the patch.

Lenard

Lenard Lindstrom wrote:

Hi Lorenz,

Yes, it is supposed to be summer where I am too, and actually was hot for awhile, but not now. Anyway, to make sure I am clear on this, Rev. 1658 crashes when the transform module is imported, but earlier revisions work. I assume this means pygame.transform.smoothscale also works. So I am guessing it is the call to the SDL function SDL_HasSSE that is causing the problem. The attached patch to transform.c, Rev 2447 (release candidate 2) removes the SDL_HasSSE call for 64bit intels. Would you give it a try? If it works I will commit it to SVN. It is not ideal, but at least smoothscale will still use MMX.

Lenard

Lorenz Quack wrote:
Hey Lenard,

sorry for the long delays but I'm quite busy these days plus the good weather... not many PC hours left.

Lenard Lindstrom wrote:
Hi Lorenz,

Could you try dropping in SVN rev 1912 of transform.c instead. This predates the Python 3 updates. This is kind of reaching, but it will narrow down the search.

I tried this out and poked some more at it and it doesn't seem to be py3k related but rather MMX/SSE.
The transform.c rev 1657 works and 1658 breaks.
Also if I comment out "#define SCALE_MMX_SUPPORT" in any version it works.

I don't get this. I keep thinking that something must be wrong with _my_ system otherwise someone else
must have encountered this as well.
The only thing I could possibly think of is that I installed the sdl-gfx package without the "mmx" USE-flag
(I'm running Gentoo) because it is not available on amd64 architecture.

By the way. I also tried commenting out all the asm stuff in scale_mmx64.c but it would still crash. So maybe it is something that is going on in transform.c but related to MMX/SSE

If you have any other ideas let me know.

yours
//Lorenz



Thanks,

Lenard

Lorenz Quack wrote:

Hi again,


you figured this out yet?


not 100% but at least now I get it to compile by following your advice:
Easiest way to work around it...
  Comment out import transform lines in the file:
      site-packages/pygame/__init__.py

[...]

Perhaps try commenting out the sse/mmx parts?


that seems to be the problem. If I comment out

#       include "scale_mmx64.c"

in "scale_mmx.c" it compiles. if I import pygame the interpreter naturally complains about undefined symbols but as long as I don't use the transform module it seems to work this way as well. of course this is not a solution.

For debugging purposes I tried to remove all SSE/MMX code and simply implement
empty dummy functions like this:

void filter_shrink_X_MMX(Uint8 *srcpix, Uint8 *dstpix, int height, int srcpitch,
                         int dstpitch, int srcwidth, int dstwidth) {}

that also crashed. I find this very confusing and frustrating. So I settle with
the work around for now.


thanks again for the help and if I can help with some debug information or if you
have any ideas let me know.

yours
//Lorenz




Index: src/transform.c
===================================================================
--- src/transform.c	(revision 2447)
+++ src/transform.c	(working copy)
@@ -35,6 +35,8 @@
 typedef void (* SMOOTHSCALE_FILTER_P)(Uint8 *, Uint8 *, int, int, int, int, int);
 struct _module_state {
     const char *filter_type;
+    int has_sse;
+    int has_mmx;
     SMOOTHSCALE_FILTER_P filter_shrink_X;
     SMOOTHSCALE_FILTER_P filter_shrink_Y;
     SMOOTHSCALE_FILTER_P filter_expand_X;
@@ -60,7 +62,9 @@
 static void filter_expand_Y_ONLYC(Uint8 *, Uint8 *, int, int, int, int, int);
 
 static struct _module_state _state = {
-    "GENERIC", 
+    "GENERIC",
+    0,
+    0,
     filter_shrink_X_ONLYC,
     filter_shrink_Y_ONLYC,
     filter_expand_X_ONLYC,
@@ -1186,6 +1190,12 @@
 static void
 smoothscale_init (struct _module_state *st)
 {
+    st->has_mmx = SDL_HasMMX ();
+#if !defined(__x86_64__)
+    st->has_sse = SDL_HasSSE ();
+#else
+    st->has_sse = 0;
+#endif
     if (st->filter_shrink_X == 0)
     {
 	if (SDL_HasSSE ())
@@ -1452,60 +1462,60 @@
     if (!PyArg_ParseTupleAndKeywords (args, kwds, "s:set_smoothscale_backend",
                                       keywords, &type))
     {
-	return NULL;
+        return NULL;
     }
 
 #if defined(SCALE_MMX_SUPPORT)
     if (strcmp (type, "GENERIC") == 0)
     {
-	st->filter_type = "GENERIC";
-	st->filter_shrink_X = filter_shrink_X_ONLYC;
-	st->filter_shrink_Y = filter_shrink_Y_ONLYC;
-	st->filter_expand_X = filter_expand_X_ONLYC;
-	st->filter_expand_Y = filter_expand_Y_ONLYC;
+        st->filter_type = "GENERIC";
+        st->filter_shrink_X = filter_shrink_X_ONLYC;
+        st->filter_shrink_Y = filter_shrink_Y_ONLYC;
+        st->filter_expand_X = filter_expand_X_ONLYC;
+        st->filter_expand_Y = filter_expand_Y_ONLYC;
     }
     else if (strcmp (type, "MMX") == 0)
     {
-	if (!SDL_HasMMX ())
-	{
-	    return RAISE (PyExc_ValueError,
+        if (!st->has_mmx)
+        {
+            return RAISE (PyExc_ValueError,
                           "MMX not supported on this machine");
-	}
-	st->filter_type = "MMX";
-	st->filter_shrink_X = filter_shrink_X_MMX;
-	st->filter_shrink_Y = filter_shrink_Y_MMX;
-	st->filter_expand_X = filter_expand_X_MMX;
-	st->filter_expand_Y = filter_expand_Y_MMX;
+        }
+        st->filter_type = "MMX";
+        st->filter_shrink_X = filter_shrink_X_MMX;
+        st->filter_shrink_Y = filter_shrink_Y_MMX;
+        st->filter_expand_X = filter_expand_X_MMX;
+        st->filter_expand_Y = filter_expand_Y_MMX;
     }
     else if (strcmp (type, "SSE") == 0)
     {
-	if (!SDL_HasSSE ())
-	{
-	    return RAISE (PyExc_ValueError,
+        if (!st->has_sse)
+        {
+            return RAISE (PyExc_ValueError,
                           "SSE not supported on this machine");
-	}
-	st->filter_type = "SSE";
-	st->filter_shrink_X = filter_shrink_X_SSE;
-	st->filter_shrink_Y = filter_shrink_Y_SSE;
-	st->filter_expand_X = filter_expand_X_SSE;
-	st->filter_expand_Y = filter_expand_Y_SSE;
+        }
+        st->filter_type = "SSE";
+        st->filter_shrink_X = filter_shrink_X_SSE;
+        st->filter_shrink_Y = filter_shrink_Y_SSE;
+        st->filter_expand_X = filter_expand_X_SSE;
+        st->filter_expand_Y = filter_expand_Y_SSE;
     }
     else
     {
-	return PyErr_Format (PyExc_ValueError,
+        return PyErr_Format (PyExc_ValueError,
                              "Unknown backend type %s", type);
     }
     Py_RETURN_NONE;
 #else /* Not an x86 processor */
     if (strcmp (type, "GENERIC") != 0)
     {
-	if (strcmp (st->filter_type, "MMX") == 0 ||
-	    strcmp (st->filter_type, "SSE") == 0    )
-	{
-	    return PyErr_Format (PyExc_ValueError,
+        if (strcmp (st->filter_type, "MMX") == 0 ||
+            strcmp (st->filter_type, "SSE") == 0    )
+        {
+            return PyErr_Format (PyExc_ValueError,
                                  "%s not supported on this machine", type);
-	}
-	return PyErr_Format (PyExc_ValueError,
+        }
+        return PyErr_Format (PyExc_ValueError,
                              "Unknown backend type %s", type);
     }
     Py_RETURN_NONE;