illume avatar illume committed 9f910ed

Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!

Comments (0)

Files changed (13)

     raw_input = input
 
 # Exported functions
+__all__ = ['raw_input_', 'print_', 'is_msys']
+
+# 2.x/3.x compatibility stuff
+try:
+    raw_input
+except NameError:
+    raw_input = input
+
+# Exported functions
 def raw_input_(prompt=None):
     """Prompt for user input in an MSYS console friendly way"""
     if prompt is None:
 static void
 pygame_parachute (int sig)
 {
+#ifdef HAVE_SIGNAL_H
     char* signaltype;
     
     signal (sig, SIG_DFL);
 
     _quit ();
     Py_FatalError (signaltype);
+#endif    
 }
 
+
 static int fatal_signals[] =
 {
     SIGSEGV,
 static void
 install_parachute (void)
 {
+#ifdef HAVE_SIGNAL_H
     int i;
     void (*ohandler)(int);
 
     /* Set a handler for any fatal signal not already handled */
     for (i = 0; fatal_signals[i]; ++i)
     {
-        ohandler = signal (fatal_signals[i], pygame_parachute);
+        ohandler = (void(*)(int))signal (fatal_signals[i], pygame_parachute);
         if (ohandler != SIG_DFL)
             signal (fatal_signals[i], ohandler);
     }
-#ifdef SIGALRM
+    
+#if defined(SIGALRM) && defined(HAVE_SIGACTION) 
     {/* Set SIGALRM to be ignored -- necessary on Solaris */
         struct sigaction action, oaction;
         /* Set SIG_IGN action */
             sigaction (SIGALRM, &oaction, NULL);
     }
 #endif
+#endif    
     return;
 }
 
 static void
 uninstall_parachute (void)
 {
+#ifdef HAVE_SIGNAL_H
     int i;
     void (*ohandler)(int);
 
     /* Remove a handler for any fatal signal handled */
     for (i = 0; fatal_signals[i]; ++i)
     {
-        ohandler = signal (fatal_signals[i], SIG_DFL);
+        ohandler = (void(*)(int))signal (fatal_signals[i], SIG_DFL);
         if (ohandler != pygame_parachute)
             signal (fatal_signals[i], ohandler);
     }
+#endif    
 }
 
 /* bind functions to python */
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("base", _base_methods, DOC_PYGAME);
+    module = Py_InitModule3 (MIDOREFIX "base", _base_methods, DOC_PYGAME);
 #endif
     if (module == NULL) {
         MODINIT_ERROR;
         }
         Py_DECREF (rval);
         Py_AtExit (atexit_quit);
+#ifdef HAVE_SIGNAL_H    
         install_parachute ();
+#endif
+
+
 #ifdef MS_WIN32
         SDL_RegisterApp ("pygame", 0, GetModuleHandle (NULL));
 #endif
     };
 #endif
 
+
     /* imported needed apis; Do this first so if there is an error
        the module is not loaded.
     */
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("cdrom", _cdrom_methods, DOC_PYGAMECDROM);
+    module = Py_InitModule3 (MODPREFIX "cdrom", 
+                             _cdrom_methods, 
+                             DOC_PYGAMECDROM);
 #endif
     if (module == NULL) {
         MODINIT_ERROR;
     }
     ecode = PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
     Py_DECREF (apiobj);
+
+
     if (ecode == -1) {
         DECREF_MOD (module);
         MODINIT_ERROR;
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("display", _display_methods, DOC_PYGAMEDISPLAY);
+    module = Py_InitModule3 (MODPREFIX "display", 
+                             _display_methods, 
+                             DOC_PYGAMEDISPLAY);
 #endif
     if (module == NULL) {
         MODINIT_ERROR;
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("event", _event_methods, DOC_PYGAMEEVENT);
+    module = Py_InitModule3 (MODPREFIX "event", _event_methods, DOC_PYGAMEEVENT);
 #endif
     dict = PyModule_GetDict (module);
 
     PyObject *module, *eventmodule, *dict;
     int ecode;
 
+
 #if PY3
     static struct PyModuleDef _module = {
         PyModuleDef_HEAD_INIT,
     */
     import_pygame_base ();
     if (PyErr_Occurred ()) {
-	MODINIT_ERROR;
+	return;
     }
     import_pygame_event ();
     if (PyErr_Occurred ()) {
-	MODINIT_ERROR;
+	return;
     }
 
     /* create the module */
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("fastevent", _fastevent_methods,
+    module = Py_InitModule3 ( MODPREFIX "fastevent", fastevent_builtins,
                              doc_fastevent_MODULE);
 #endif
     if (module == NULL) {
     dict = PyModule_GetDict (module);
 
     /* add the event module functions if available */
-    eventmodule = PyImport_ImportModule ("pygame.event");
+    eventmodule = PyImport_ImportModule (IMPPREFIX "event");
     if (eventmodule)
     {
         char *NAMES[] = {"Event", "event_name", NULL};
 #define PyFont_Check(x) ((x)->ob_type == &PyFont_Type)
 
 static int font_initialized = 0;
+#ifndef __SYMBIAN32__
+static const char const *font_defaultname = "freesansbold.ttf";
+static const char const *pkgdatamodule_name = "pygame.pkgdata";
+static const char const *resourcefunc_name = "getResource";
+#else
+/// Symbian GCCE does not like the second const
 static const char *font_defaultname = "freesansbold.ttf";
-
 static const char *pkgdatamodule_name = "pygame.pkgdata";
 static const char *resourcefunc_name = "getResource";
+#endif
+
 
 static PyObject*
 font_resource (const char *filename)
     }
 #else
     if (PyFile_Check (result))
-    {
-        PyObject *tmp = PyFile_Name (result);
+    {		
+        PyObject *tmp = PyFile_Name (result);        
         Py_INCREF (tmp);
         Py_DECREF (result);
         result = tmp;
     int fontsize;
     TTF_Font* font = NULL;
     PyObject* fileobj;
-	
+    
     self->font = NULL;
     if (!PyArg_ParseTuple (args, "Oi", &fileobj, &fontsize))
         return -1;
         if (!fileobj)
         {
             char error[1024];
-            snprintf (error, 1024, "default font not found '%s'",
+            PyOS_snprintf (error, 1024, "default font not found '%s'",
                       font_defaultname);
             RAISE (PyExc_RuntimeError, error);
             goto error;
         if (fontsize <= 1)
             fontsize = 1;
     }
-
+     
     if (PyUnicode_Check (fileobj)) {
         PyObject* tmp = PyUnicode_AsASCIIString (fileobj);
 
 
     if (Bytes_Check (fileobj))
     {
-        FILE* test;
+        FILE* test;        
         char* filename = Bytes_AsString (fileobj);
-
+       		
         if (!filename) {
             goto error;
         }
-
+                
         /*check if it is a valid file, else SDL_ttf segfaults*/
         test = fopen (filename, "rb");
         if(!test)
             Py_BEGIN_ALLOW_THREADS;
             font = TTF_OpenFont(filename, fontsize);
             Py_END_ALLOW_THREADS;
-        }
+        }	
     }
     if (!font)
     {
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("font", _font_methods, DOC_PYGAMEFONT);
+    module = Py_InitModule3 (MODPREFIX "font", 
+                             _font_methods, 
+                             DOC_PYGAMEFONT);
 #endif
     if (module == NULL) {
         MODINIT_ERROR;
 #define PyFont_New (*(PyObject*(*)(TTF_Font*))PyFONT_C_API[1])
 /*slot 2 taken by FONT_INIT_CHECK*/
 #define import_pygame_font() { \
-	PyObject *module = PyImport_ImportModule("pygame.font"); \
+	PyObject *module = PyImport_ImportModule(MODPREFIX "font"); \
 	if (module != NULL) { \
 		PyObject *dict = PyModule_GetDict(module); \
 		PyObject *c_api = PyDict_GetItemString(dict, PYGAMEAPI_LOCAL_ENTRY); \
             {
                 /* If it is .png .jpg .jpeg use the extended module. */
                 /* try to get extended formats */
-                imgext = PyImport_ImportModule ("pygame.imageext");
+                imgext = PyImport_ImportModule (IMPPREFIX "imageext");
                 if (imgext)
                 {
                     PyObject *extdict = PyModule_GetDict (imgext);
 }
 
 /*******************************************************/
-/* tga code by Mattias Engdegrd, in the public domain */
+/* tga code by Mattias Engdegard, in the public domain */
 /*******************************************************/
 struct TGAheader
 {
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("image", _image_methods, DOC_PYGAMEIMAGE);
+    module = Py_InitModule3 (MODPREFIX "image", _image_methods, DOC_PYGAMEIMAGE);
 #endif
     if (module == NULL) {
         MODINIT_ERROR;
 
 
     /* try to get extended formats */
-    extmodule = PyImport_ImportModule ("pygame.imageext");
+    extmodule = PyImport_ImportModule (IMPPREFIX "imageext");
     if (extmodule)
     {
         PyObject *extdict = PyModule_GetDict (extmodule);
  *  the extended load and save functions, which are autmatically used
  *  by the normal pygame.image module if it is available.
  */
+// This is temporal until PNG support is done for Symbian
+#ifdef __SYMBIAN32__
+#include <stdio.h>
+#else
 #include <png.h>
+#endif
 #include <jpeglib.h>
 /* Keep a stray macro from conflicting with python.h */
 #if defined(HAVE_PROTOTYPES)
 #if PY3
     PyObject *oname, *odecoded = NULL;
 #endif
+#if PY3
+    PyObject *oname, *odecoded = NULL;
+#endif
     char* name = NULL;
     SDL_Surface* surf;
     SDL_RWops *rw;
     cinfo.in_color_space = JCS_RGB;
     /* cinfo.optimize_coding = FALSE;
      */
-
-
-
+    /* cinfo.optimize_coding = FALSE;
+     */
+  
     jpeg_set_defaults (&cinfo);
     jpeg_set_quality (&cinfo, quality, TRUE);
 
 
 
         ss_surface = SDL_CreateRGBSurface (SDL_SWSURFACE,
-                                           ss_w, ss_h, pixel_bits,
+                                       ss_w, ss_h, pixel_bits,
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
                                        0xff0000, 0xff00, 0xff, 0x000000ff
 #else
         SDL_FreeSurface (ss_surface);
         ss_surface = NULL;
     }
-
     return r;
 }
 
 #endif /* end if JPEGLIB_H */
 
-/* NOTE XX HACK TODO FIXME: this opengltosdl is also in image.c
+/* NOTE XX HACK TODO FIXME: this opengltosdl is also in image.c  
    need to share it between both.
 */
 
 
     GL_glReadPixels_Func p_glReadPixels= NULL;
 
-    p_glReadPixels = (GL_glReadPixels_Func) SDL_GL_GetProcAddress ("glReadPixels"); 
+    p_glReadPixels = (GL_glReadPixels_Func) SDL_GL_GetProcAddress("glReadPixels"); 
 
     surf = SDL_GetVideoSurface ();
 
         return NULL;
     }
 
-    pixels = (unsigned char*) malloc (surf->w * surf->h * 3);
+    pixels = (unsigned char*) malloc(surf->w * surf->h * 3);
 
     if(!pixels) {
         RAISE (PyExc_MemoryError, "Cannot allocate enough memory for pixels.");
     }
 
     /* GL_RGB, GL_UNSIGNED_BYTE */
-    p_glReadPixels (0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels);
+    p_glReadPixels(0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels);
 
     if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {
         rmask=0x000000FF;
     surf = SDL_CreateRGBSurface (SDL_SWSURFACE, surf->w, surf->h, 24,
                                  rmask, gmask, bmask, 0);
     if (!surf) {
-        free (pixels);
+        free(pixels);
         RAISE (PyExc_SDLError, SDL_GetError ());
         return NULL;
     }
     }
 
 
-    free (pixels);
+    free(pixels);
     return surf;
 }
 
 	MODINIT_ERROR;
     }
     import_pygame_rwobject ();
+
+
     if (PyErr_Occurred ()) {
         MODINIT_ERROR;
     }
 #if PY3
     module = PyModule_Create (&_module);
 #else
-    module = Py_InitModule3 ("imageext", _imageext_methods, _imageext_doc);
+    module = Py_InitModule3(MODPREFIX "imageext", 
+                            _imageext_methods, 
+                            _imageext_doc);
 #endif
     MODINIT_RETURN (module);
 }
 #define PyMask_Check(x) ((x)->ob_type == &PyMask_Type)
 
 #define import_pygame_mask() {                                                                 \
-	PyObject *module = PyImport_ImportModule("pygame.mask");                               \
+	PyObject *module = PyImport_ImportModule(IMPPREFIX "mask");                               \
 	if (module != NULL) {                                                                  \
 		PyObject *dict  = PyModule_GetDict(module);                                    \
 		PyObject *c_api = PyDict_GetItemString(dict, PYGAMEAPI_LOCAL_ENTRY);           \
 #define PyMixer_AutoInit (*(PyObject*(*)(PyObject*, PyObject*))PyMIXER_C_API[5])
 #define PyMixer_AutoQuit (*(void(*)(void))PyMIXER_C_API[6])
 #define import_pygame_mixer() { \
-	PyObject *_module = PyImport_ImportModule("pygame.mixer"); \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "mixer"); \
 	if (_module != NULL) { \
 		PyObject *_dict = PyModule_GetDict(_module); \
 		PyObject *_c_api = PyDict_GetItemString(_dict, PYGAMEAPI_LOCAL_ENTRY); \
 #undef HAVE_SNPRINTF        /* remove GCC redefine warning */
 #endif
 
+// This must be before all else
+#if defined(__SYMBIAN32__) && defined( OPENC )
+#include <sys/types.h>
+
+#if defined(__WINS__)
+void* _alloca(size_t size);
+#  define alloca _alloca
+#endif
+
+#endif
+
 #include <Python.h>
 
+// No signal()
+#if defined(__SYMBIAN32__) && defined(HAVE_SIGNAL_H)
+#undef HAVE_SIGNAL_H
+#endif
+
 #if defined(HAVE_SNPRINTF)
 #undef HAVE_SNPRINTF
 #endif
 #endif
 #endif
 
+
+/// Prefix when initializing module
+#define MODPREFIX ""
+/// Prefix when importing module
+#define IMPPREFIX "pygame."
+
+#ifdef __SYMBIAN32__
+#undef MODPREFIX
+#undef IMPPREFIX
+// On Symbian there is no pygame package. The extensions are built-in or in sys\bin.
+#define MODPREFIX "pygame_"
+#define IMPPREFIX "pygame_"
+#endif
+
 #include <SDL.h>
 
 /* macros used throughout the source */
     (*(int(*)(PyObject*, Uint8*))PyGAME_C_API[PYGAMEAPI_BASE_FIRSTSLOT + 12])
 
 #define import_pygame_base() {                                          \
-	PyObject *_module = PyImport_ImportModule("pygame.base");        \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "base");        \
 	if (_module != NULL) {                                           \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
      PyGAME_C_API[PYGAMEAPI_RECT_FIRSTSLOT + 3])
 
 #define import_pygame_rect() {                                          \
-	PyObject *_module = PyImport_ImportModule("pygame.rect");        \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "rect");        \
 	if (_module != NULL) {                                         \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
     (*(PyObject*(*)(int))PyGAME_C_API[PYGAMEAPI_CDROM_FIRSTSLOT + 1])
 
 #define import_pygame_cd() {                                      \
-	PyObject *_module = PyImport_ImportModule("pygame.cdrom"); \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "cdrom"); \
 	if (_module != NULL) {                                     \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
     (*(PyObject*(*)(int))PyGAME_C_API[PYGAMEAPI_JOYSTICK_FIRSTSLOT + 1])
 
 #define import_pygame_joystick() {                                      \
-	PyObject *_module = PyImport_ImportModule("pygame.joystick");    \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "joystick");    \
 	if (_module != NULL) {                                           \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
     (*(PyObject*(*)(SDL_VideoInfo*))                    \
      PyGAME_C_API[PYGAMEAPI_DISPLAY_FIRSTSLOT + 1])
 #define import_pygame_display() {                                   \
-	PyObject *_module = PyImport_ImportModule("pygame.display"); \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "display"); \
 	if (_module != NULL) {                                       \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
      PyGAME_C_API[PYGAMEAPI_SURFACE_FIRSTSLOT + 2])
 
 #define import_pygame_surface() do {                                   \
-	PyObject *_module = PyImport_ImportModule("pygame.surface"); \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "surface"); \
 	if (_module != NULL) {                                       \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
                 for(i = 0; i < PYGAMEAPI_SURFACE_NUMSLOTS; ++i)         \
                     PyGAME_C_API[i + PYGAMEAPI_SURFACE_FIRSTSLOT] =     \
                         localptr[i];                                    \
-            }                                                           \
-            Py_DECREF(_module);                                          \
-        }                                                               \
-	else                                                            \
-	{                                                               \
-	    break;                                                      \
-	}                                                               \
-	_module = PyImport_ImportModule("pygame.surflock");              \
-	if (_module != NULL) {                                           \
+				}                                                           \
+				Py_DECREF(_module);                                          \
+			}                                                               \
+			else                                                            \
+			{                                                               \
+				break;                                                      \
+			}                                                               \
+			_module = PyImport_ImportModule(IMPPREFIX "surflock");          \
+			if (_module != NULL) {                                           \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
                                                    PYGAMEAPI_LOCAL_ENTRY); \
     (*(int (*)(PyEventObject*, SDL_Event*))             \
      PyGAME_C_API[PYGAMEAPI_EVENT_FIRSTSLOT + 3])
 #define import_pygame_event() {                                   \
-	PyObject *_module = PyImport_ImportModule("pygame.event"); \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "event"); \
 	if (_module != NULL) {                                     \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
 #define RWopsCheckPythonThreaded                                        \
     (*(int(*)(SDL_RWops*))PyGAME_C_API[PYGAMEAPI_RWOBJECT_FIRSTSLOT + 3])
 #define import_pygame_rwobject() {                                   \
-	PyObject *_module = PyImport_ImportModule("pygame.rwobject"); \
+	PyObject *_module = PyImport_ImportModule(IMPPREFIX "rwobject"); \
 	if (_module != NULL) {                                        \
             PyObject *_dict = PyModule_GetDict(_module);                  \
             PyObject *_c_api = PyDict_GetItemString(_dict,                \
     PyGAME_C_API[PYGAMEAPI_BUFFERPROXY_FIRSTSLOT + 1])
 #define import_pygame_bufferproxy()                                      \
     {                                                                    \
-	PyObject *_module = PyImport_ImportModule ("pygame.bufferproxy");\
+	PyObject *_module = PyImport_ImportModule (IMPPREFIX "bufferproxy");\
 	if (_module != NULL)                                             \
         {                                                                \
             PyObject *_dict = PyModule_GetDict (_module);                \
     (*(PyObject*(*)) PyGAME_C_API[PYGAMEAPI_PIXELARRAY_FIRSTSLOT + 1])
 #define import_pygame_pixelarray()                                       \
     {                                                                    \
-	PyObject *_module = PyImport_ImportModule ("pygame.pixelarray"); \
+	PyObject *_module = PyImport_ImportModule (IMPPREFIX "pixelarray"); \
 	if (_module != NULL)                                             \
         {                                                                \
             PyObject *_dict = PyModule_GetDict (_module);                \
     (*(int(*)(PyObject*, Uint8*)) PyGAME_C_API[PYGAMEAPI_COLOR_FIRSTSLOT + 2])
 #define import_pygame_color()                                           \
     {                                                                   \
-	PyObject *_module = PyImport_ImportModule ("pygame.color");     \
+	PyObject *_module = PyImport_ImportModule (IMPPREFIX "color");     \
 	if (_module != NULL)                                            \
         {                                                               \
             PyObject *_dict = PyModule_GetDict (_module);               \
 #endif
 
 /*last platform compiler stuff*/
-#if defined(macintosh) && defined(__MWERKS__)
+#if defined(macintosh) && defined(__MWERKS__) || defined(__SYMBIAN32__)
 #define PYGAME_EXPORT __declspec(export)
 #else
 #define PYGAME_EXPORT
 #endif
 
+#ifdef __SYMBIAN32__ && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2
+
+// These are missing from Python 2.2
+#ifndef Py_RETURN_NONE
+
+#define Py_RETURN_NONE     return Py_INCREF(Py_None), Py_None
+#define Py_RETURN_TRUE     return Py_INCREF(Py_True), Py_True
+#define Py_RETURN_FALSE    return Py_INCREF(Py_False), Py_False
+
+#ifndef intrptr_t
+#define intptr_t int
+
+// No PySlice_GetIndicesEx on Py 2.2        
+#define PySlice_GetIndicesEx(a,b,c,d,e,f) PySlice_GetIndices(a,b,c,d,e)
+
+#define PyBool_FromLong(x) 	Py_BuildValue("b", x)
+#endif
+
+// _symport_free and malloc are not exported in python.dll
+// See http://discussion.forum.nokia.com/forum/showthread.php?t=57874
+#undef PyObject_NEW
+#define PyObject_NEW PyObject_New
+#undef PyMem_MALLOC
+#define PyMem_MALLOC PyMem_Malloc
+#undef PyObject_DEL
+#define PyObject_DEL PyObject_Del
+
+#endif // intptr_t
+
+#endif // __SYMBIAN32__ Python 2.2.2
+
 #endif /* PYGAME_H */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.