annotate src/base.c @ 3182:0c07af110477 docs-changes

Ignore Sphinx-generated files
author Thomas Kluyver <takowl@gmail.com>
date Wed, 09 Jan 2013 22:35:43 +0000
parents 42e2bde1a12c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
1 /*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2 pygame - Python Game Library
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
3 Copyright (C) 2000-2001 Pete Shinners
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
4
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
5 This library is free software; you can redistribute it and/or
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
6 modify it under the terms of the GNU Library General Public
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
7 License as published by the Free Software Foundation; either
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
8 version 2 of the License, or (at your option) any later version.
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
9
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
10 This library is distributed in the hope that it will be useful,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
13 Library General Public License for more details.
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
14
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
15 You should have received a copy of the GNU Library General Public
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
16 License along with this library; if not, write to the Free
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
18
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
19 Pete Shinners
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
20 pete@shinners.org
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
21 */
346
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
22 #define NO_PYGAME_C_API
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
23 #define PYGAMEAPI_BASE_INTERNAL
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
24 #include "pygame.h"
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
25 #include "pgcompat.h"
1937
0d661c00c1aa Merged FreeType branch into trunk.
tanoku
parents: 1900
diff changeset
26 #include "doc/pygame_doc.h"
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
27 #include <signal.h>
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
28
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
29
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
30 /* This file controls all the initialization of
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
31 * the module and the various SDL subsystems
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
32 */
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
33
120
19072dafa19d initial mac support
pygame
parents: 107
diff changeset
34 /*platform specific init stuff*/
19072dafa19d initial mac support
pygame
parents: 107
diff changeset
35
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
36 #ifdef MS_WIN32 /*python gives us MS_WIN32*/
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
37 #define WIN32_LEAN_AND_MEAN
83
249cb2af007a really shutdown SDL
pygame
parents: 68
diff changeset
38 #define VC_EXTRALEAN
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
39 #include<windows.h>
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
40 extern int SDL_RegisterApp (char*, Uint32, void*);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
41 #endif
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
42
120
19072dafa19d initial mac support
pygame
parents: 107
diff changeset
43 #if defined(macintosh)
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
44 #if(!defined(__MWERKS__) && !TARGET_API_MAC_CARBON)
120
19072dafa19d initial mac support
pygame
parents: 107
diff changeset
45 QDGlobals qd;
19072dafa19d initial mac support
pygame
parents: 107
diff changeset
46 #endif
19072dafa19d initial mac support
pygame
parents: 107
diff changeset
47 #endif
19072dafa19d initial mac support
pygame
parents: 107
diff changeset
48
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
49 /* Only one instance of the state per process. */
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
50 static PyObject* quitfunctions = NULL;
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
51 static int sdl_was_init = 0;
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
52
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
53 static void install_parachute (void);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
54 static void uninstall_parachute (void);
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
55 static void _quit (void);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
56 static void atexit_quit (void);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
57 static int PyGame_Video_AutoInit (void);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
58 static void PyGame_Video_AutoQuit (void);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
59
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
60 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
61 CheckSDLVersions (void) /*compare compiled to linked*/
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
62 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
63 SDL_version compiled;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
64 const SDL_version* linked;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
65 SDL_VERSION (&compiled);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
66 linked = SDL_Linked_Version ();
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
67
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
68 /*only check the major and minor version numbers.
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
69 we will relax any differences in 'patch' version.*/
491
eb228fb45c48 int sized rects
pygame
parents: 487
diff changeset
70
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
71 if (compiled.major != linked->major || compiled.minor != linked->minor)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
72 {
1894
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
73 PyErr_Format(PyExc_RuntimeError, "SDL compiled with version %d.%d.%d, linked to %d.%d.%d",
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
74 compiled.major, compiled.minor, compiled.patch,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
75 linked->major, linked->minor, linked->patch);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
76 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
77 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
78 return 1;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
79 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
80
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
81 void
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
82 PyGame_RegisterQuit (void(*func)(void))
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
83 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
84 PyObject* obj;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
85 if (!quitfunctions)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
86 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
87 quitfunctions = PyList_New (0);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
88 if (!quitfunctions)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
89 return;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
90 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
91 if (func)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
92 {
2120
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
93 obj = PyCapsule_New (func, "quit", NULL);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
94 PyList_Append (quitfunctions, obj);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
95 Py_DECREF (obj);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
96 }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
97 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
98
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
99 static PyObject*
1894
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
100 register_quit (PyObject* self, PyObject* value)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
101 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
102 if (!quitfunctions)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
103 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
104 quitfunctions = PyList_New (0);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
105 if (!quitfunctions)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
106 return NULL;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
107 }
1894
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
108 PyList_Append (quitfunctions, value);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
109
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
110 Py_RETURN_NONE;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
111 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
112
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
113 static PyObject*
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
114 init (PyObject* self)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
115 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
116 PyObject *allmodules, *moduleslist, *dict, *func, *result, *mod;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
117 int loop, num;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
118 int success=0, fail=0;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
119
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
120 if (!CheckSDLVersions ())
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
121 return NULL;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
122
246
6875c7724e88 reworked initialization for easier embedding
pygame
parents: 240
diff changeset
123
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
124 /*nice to initialize timer, so startup time will reflec init() time*/
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
125 sdl_was_init = SDL_Init (
587
f94b4aaeb26b experimental fastevents wrapper
bob
parents: 572
diff changeset
126 #if defined(WITH_THREAD) && !defined(MS_WIN32) && defined(SDL_INIT_EVENTTHREAD)
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
127 SDL_INIT_EVENTTHREAD |
587
f94b4aaeb26b experimental fastevents wrapper
bob
parents: 572
diff changeset
128 #endif
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
129 SDL_INIT_TIMER |
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
130 SDL_INIT_NOPARACHUTE) == 0;
566
a87965752666 add pygame.base.get_version function
bob
parents: 550
diff changeset
131
a87965752666 add pygame.base.get_version function
bob
parents: 550
diff changeset
132
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
133 /* initialize all pygame modules */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
134 allmodules = PyImport_GetModuleDict ();
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
135 moduleslist = PyDict_Values (allmodules);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
136 if (!allmodules || !moduleslist)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
137 return Py_BuildValue ("(ii)", 0, 0);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
138
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
139 if (PyGame_Video_AutoInit ())
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
140 ++success;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
141 else
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
142 ++fail;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
143
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
144 num = PyList_Size (moduleslist);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
145 for (loop = 0; loop < num; ++loop)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
146 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
147 mod = PyList_GET_ITEM (moduleslist, loop);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
148 if (!mod || !PyModule_Check (mod))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
149 continue;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
150 dict = PyModule_GetDict (mod);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
151 func = PyDict_GetItemString (dict, "__PYGAMEinit__");
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
152 if(func && PyCallable_Check (func))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
153 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
154 result = PyObject_CallObject (func, NULL);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
155 if (result && PyObject_IsTrue (result))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
156 ++success;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
157 else
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
158 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
159 PyErr_Clear ();
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
160 ++fail;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
161 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
162 Py_XDECREF (result);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
163 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
164 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
165 Py_DECREF (moduleslist);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
166
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
167 return Py_BuildValue ("(ii)", success, fail);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
168 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
169
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
170 static void
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
171 atexit_quit (void)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
172 {
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
173 PyGame_Video_AutoQuit ();
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
174
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
175 /* Maybe it is safe to call SDL_quit more than once after an SDL_Init,
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
176 but this is undocumented. So play it safe and only call after a
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
177 successful SDL_Init.
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
178 */
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
179 if (sdl_was_init) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
180 sdl_was_init = 0;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
181 SDL_Quit ();
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
182 }
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
183 }
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
184
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
185 static PyObject*
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
186 get_sdl_version (PyObject* self)
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
187 {
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
188 const SDL_version *v;
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
189
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
190 v = SDL_Linked_Version ();
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
191 return Py_BuildValue ("iii", v->major, v->minor, v->patch);
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
192 }
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
193
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
194 static PyObject*
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
195 get_sdl_byteorder (PyObject *self)
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
196 {
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
197 return PyLong_FromLong (SDL_BYTEORDER);
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
198 }
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
199
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
200 static PyObject*
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
201 quit (PyObject* self)
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
202 {
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
203 _quit ();
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
204 Py_RETURN_NONE;
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
205 }
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
206
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
207 static void
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
208 _quit (void)
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
209 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
210 PyObject* quit;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
211 PyObject* privatefuncs;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
212 int num;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
213
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
214 if (!quitfunctions) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
215 return;
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
216 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
217
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
218 privatefuncs = quitfunctions;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
219 quitfunctions = NULL;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
220
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
221 uninstall_parachute ();
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
222 num = PyList_Size (privatefuncs);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
223
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
224 while (num--) /*quit in reverse order*/
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
225 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
226 quit = PyList_GET_ITEM (privatefuncs, num);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
227 if (PyCallable_Check (quit))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
228 PyObject_CallObject (quit, NULL);
2120
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
229 else if (PyCapsule_CheckExact (quit))
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
230 {
2120
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
231 void* ptr = PyCapsule_GetPointer (quit, "quit");
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
232 (*(void(*)(void)) ptr) ();
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
233 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
234 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
235 Py_DECREF (privatefuncs);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
236
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
237 atexit_quit ();
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
238 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
239
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
240 /* internal C API utility functions */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
241 static int
835
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
242 IntFromObj (PyObject* obj, int* val) {
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
243 int tmp_val;
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
244 tmp_val = PyInt_AsLong (obj);
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
245 if (tmp_val == -1 && PyErr_Occurred ())
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
246 {
835
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
247 PyErr_Clear ();
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
248 return 0;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
249 }
835
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
250 *val = tmp_val;
a331cb9c3f85 Replaced IntFromObj function with something smaller.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
251 return 1;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
252 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
253
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
254 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
255 IntFromObjIndex (PyObject* obj, int _index, int* val)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
256 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
257 int result = 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
258 PyObject* item;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
259 item = PySequence_GetItem (obj, _index);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
260 if (item)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
261 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
262 result = IntFromObj (item, val);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
263 Py_DECREF (item);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
264 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
265 return result;
442
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
266 }
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
267
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
268 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
269 TwoIntsFromObj (PyObject* obj, int* val1, int* val2)
442
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
270 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
271 if (PyTuple_Check (obj) && PyTuple_Size (obj) == 1)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
272 return TwoIntsFromObj (PyTuple_GET_ITEM (obj, 0), val1, val2);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
273
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
274 if (!PySequence_Check (obj) || PySequence_Length (obj) != 2)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
275 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
276
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
277 if (!IntFromObjIndex (obj, 0, val1) || !IntFromObjIndex (obj, 1, val2))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
278 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
279
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
280 return 1;
442
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
281 }
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
282
1894
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
283 static int
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
284 FloatFromObj (PyObject* obj, float* val)
442
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
285 {
1894
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
286 float f= (float)PyFloat_AsDouble (obj);
442
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
287
1894
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
288 if (f==-1 && PyErr_Occurred()) {
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
289 PyErr_Clear ();
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
290 return 0;
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
291 }
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
292
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
293 *val = f;
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
294 return 1;
442
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
295 }
ad9e57cfa846 antialiased lines
pygame
parents: 441
diff changeset
296
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
297 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
298 FloatFromObjIndex (PyObject* obj, int _index, float* val)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
299 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
300 int result = 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
301 PyObject* item;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
302 item = PySequence_GetItem (obj, _index);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
303 if (item)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
304 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
305 result = FloatFromObj (item, val);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
306 Py_DECREF (item);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
307 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
308 return result;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
309 }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
310
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
311 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
312 TwoFloatsFromObj (PyObject* obj, float* val1, float* val2)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
313 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
314 if (PyTuple_Check (obj) && PyTuple_Size (obj) == 1)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
315 return TwoFloatsFromObj (PyTuple_GET_ITEM (obj, 0), val1, val2);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
316
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
317 if (!PySequence_Check (obj) || PySequence_Length (obj) != 2)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
318 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
319
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
320 if (!FloatFromObjIndex (obj, 0, val1) || !FloatFromObjIndex (obj, 1, val2))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
321 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
322
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
323 return 1;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
324 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
325
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
326 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
327 UintFromObj (PyObject* obj, Uint32* val)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
328 {
1900
46cf8eef39cc 64bit issues with Surface.get_masks and UintFromObj. thanks Lorenz Quack!
Rene Dudfield <renesd@gmail.com>
parents: 1894
diff changeset
329 PyObject* longobj;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
330
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
331 if (PyNumber_Check (obj))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
332 {
1900
46cf8eef39cc 64bit issues with Surface.get_masks and UintFromObj. thanks Lorenz Quack!
Rene Dudfield <renesd@gmail.com>
parents: 1894
diff changeset
333 if (!(longobj = PyNumber_Long (obj)))
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
334 return 0;
1900
46cf8eef39cc 64bit issues with Surface.get_masks and UintFromObj. thanks Lorenz Quack!
Rene Dudfield <renesd@gmail.com>
parents: 1894
diff changeset
335 *val = (Uint32) PyLong_AsUnsignedLong (longobj);
46cf8eef39cc 64bit issues with Surface.get_masks and UintFromObj. thanks Lorenz Quack!
Rene Dudfield <renesd@gmail.com>
parents: 1894
diff changeset
336 Py_DECREF (longobj);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
337 return 1;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
338 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
339 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
340 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
341
1900
46cf8eef39cc 64bit issues with Surface.get_masks and UintFromObj. thanks Lorenz Quack!
Rene Dudfield <renesd@gmail.com>
parents: 1894
diff changeset
342 static int
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
343 UintFromObjIndex (PyObject* obj, int _index, Uint32* val)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
344 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
345 int result = 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
346 PyObject* item;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
347 item = PySequence_GetItem (obj, _index);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
348 if (item)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
349 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
350 result = UintFromObj (item, val);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
351 Py_DECREF (item);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
352 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
353 return result;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
354 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
355
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
356 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
357 RGBAFromObj (PyObject* obj, Uint8* RGBA)
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents: 15
diff changeset
358 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
359 int length;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
360 Uint32 val;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
361 if (PyTuple_Check (obj) && PyTuple_Size (obj) == 1)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
362 return RGBAFromObj (PyTuple_GET_ITEM (obj, 0), RGBA);
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents: 15
diff changeset
363
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
364 if (!PySequence_Check (obj))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
365 return 0;
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents: 15
diff changeset
366
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
367 length = PySequence_Length (obj);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
368 if (length < 3 || length > 4)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
369 return 0;
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents: 15
diff changeset
370
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
371 if (!UintFromObjIndex (obj, 0, &val) || val > 255)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
372 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
373 RGBA[0] = (Uint8) val;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
374 if (!UintFromObjIndex (obj, 1, &val) || val > 255)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
375 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
376 RGBA[1] = (Uint8) val;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
377 if (!UintFromObjIndex (obj, 2, &val) || val > 255)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
378 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
379 RGBA[2] = (Uint8) val;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
380 if (length == 4)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
381 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
382 if (!UintFromObjIndex (obj, 3, &val) || val > 255)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
383 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
384 RGBA[3] = (Uint8) val;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
385 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
386 else RGBA[3] = (Uint8) 255;
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents: 15
diff changeset
387
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
388 return 1;
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents: 15
diff changeset
389 }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
390
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
391 static PyObject*
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
392 get_error (PyObject* self)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
393 {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
394 return Text_FromUTF8 (SDL_GetError ());
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
395 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
396
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
397 static PyObject*
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
398 set_error (PyObject *s, PyObject *args)
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
399 {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
400 char *errstring = NULL;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
401
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
402 if (!PyArg_ParseTuple (args, "s", &errstring))
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
403 return NULL;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
404
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
405 SDL_SetError(errstring);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
406
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
407 Py_RETURN_NONE;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
408 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
409
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
410
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
411
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
412
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
413 /*video init needs to be here, because of it's
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
414 *important init order priority
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
415 */
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
416 static void
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
417 PyGame_Video_AutoQuit (void)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
418 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
419 if (SDL_WasInit (SDL_INIT_VIDEO))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
420 SDL_QuitSubSystem (SDL_INIT_VIDEO);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
421 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
422
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
423 static int
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
424 PyGame_Video_AutoInit (void)
290
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
425 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
426 if (!SDL_WasInit (SDL_INIT_VIDEO))
290
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
427 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
428 int status;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
429 #if defined(__APPLE__) && defined(darwin)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
430 PyObject *module;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
431 PyObject *rval;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
432 module = PyImport_ImportModule ("pygame.macosx");
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
433 if (!module)
1453
401c014117ad Removing PyObjC dependency
brian
parents: 868
diff changeset
434 {
401c014117ad Removing PyObjC dependency
brian
parents: 868
diff changeset
435 printf("ERROR: pygame.macosx import FAILED\n");
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
436 return -1;
1453
401c014117ad Removing PyObjC dependency
brian
parents: 868
diff changeset
437 }
491
eb228fb45c48 int sized rects
pygame
parents: 487
diff changeset
438
1453
401c014117ad Removing PyObjC dependency
brian
parents: 868
diff changeset
439 rval = PyObject_CallMethod (module, "Video_AutoInit", "");
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
440 Py_DECREF (module);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
441 if (!rval)
1453
401c014117ad Removing PyObjC dependency
brian
parents: 868
diff changeset
442 {
401c014117ad Removing PyObjC dependency
brian
parents: 868
diff changeset
443 printf("ERROR: pygame.macosx.Video_AutoInit() call FAILED\n");
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
444 return -1;
1453
401c014117ad Removing PyObjC dependency
brian
parents: 868
diff changeset
445 }
491
eb228fb45c48 int sized rects
pygame
parents: 487
diff changeset
446
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
447 status = PyObject_IsTrue (rval);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
448 Py_DECREF (rval);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
449 if (status != 1)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
450 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
451 #endif
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
452 status = SDL_InitSubSystem (SDL_INIT_VIDEO);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
453 if (status)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
454 return 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
455 SDL_EnableUNICODE (1);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
456 /*we special case the video quit to last now*/
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
457 /*PyGame_RegisterQuit(PyGame_Video_AutoQuit);*/
290
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
458 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
459 return 1;
290
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
460 }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
461
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
462 /*error signal handlers (replacing SDL parachute)*/
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
463 static void
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
464 pygame_parachute (int sig)
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
465 {
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
466 #ifdef HAVE_SIGNAL_H
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
467 char* signaltype;
528
df11f5a31fce arc fixes
pygame
parents: 517
diff changeset
468
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
469 signal (sig, SIG_DFL);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
470 switch (sig)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
471 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
472 case SIGSEGV:
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
473 signaltype = "(pygame parachute) Segmentation Fault";
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
474 break;
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
475 #ifdef SIGBUS
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
476 #if SIGBUS != SIGSEGV
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
477 case SIGBUS:
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
478 signaltype = "(pygame parachute) Bus Error";
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
479 break;
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
480 #endif
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
481 #endif
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
482 #ifdef SIGFPE
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
483 case SIGFPE:
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
484 signaltype = "(pygame parachute) Floating Point Exception";
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
485 break;
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
486 #endif
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
487 #ifdef SIGQUIT
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
488 case SIGQUIT:
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
489 signaltype = "(pygame parachute) Keyboard Abort";
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
490 break;
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
491 #endif
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
492 default:
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
493 signaltype = "(pygame parachute) Unknown Signal";
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
494 break;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
495 }
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
496
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
497 _quit ();
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
498 Py_FatalError (signaltype);
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
499 #endif
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
500 }
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
501
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
502
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
503 static int fatal_signals[] =
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
504 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
505 SIGSEGV,
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
506 #ifdef SIGBUS
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
507 SIGBUS,
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
508 #endif
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
509 #ifdef SIGFPE
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
510 SIGFPE,
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
511 #endif
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
512 #ifdef SIGQUIT
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
513 SIGQUIT,
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
514 #endif
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
515 0 /*end of list*/
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
516 };
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
517
346
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
518 static int parachute_installed = 0;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
519 static void
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
520 install_parachute (void)
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
521 {
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
522 #ifdef HAVE_SIGNAL_H
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
523 int i;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
524 void (*ohandler)(int);
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
525
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
526 if (parachute_installed)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
527 return;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
528 parachute_installed = 1;
346
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
529
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
530 /* Set a handler for any fatal signal not already handled */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
531 for (i = 0; fatal_signals[i]; ++i)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
532 {
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
533 ohandler = (void(*)(int))signal (fatal_signals[i], pygame_parachute);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
534 if (ohandler != SIG_DFL)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
535 signal (fatal_signals[i], ohandler);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
536 }
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
537
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
538 #if defined(SIGALRM) && defined(HAVE_SIGACTION)
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
539 {/* Set SIGALRM to be ignored -- necessary on Solaris */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
540 struct sigaction action, oaction;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
541 /* Set SIG_IGN action */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
542 memset (&action, 0, (sizeof action));
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
543 action.sa_handler = SIG_IGN;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
544 sigaction (SIGALRM, &action, &oaction);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
545 /* Reset original action if it was already being handled */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
546 if (oaction.sa_handler != SIG_DFL)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
547 sigaction (SIGALRM, &oaction, NULL);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
548 }
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
549 #endif
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
550 #endif
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
551 return;
67
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
552 }
24e2f4883473 parachute switched from sdl
pygame
parents: 57
diff changeset
553
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
554 static void
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
555 uninstall_parachute (void)
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
556 {
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
557 #ifdef HAVE_SIGNAL_H
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
558 int i;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
559 void (*ohandler)(int);
346
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
560
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
561 if (!parachute_installed)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
562 return;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
563 parachute_installed = 0;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
564
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
565 /* Remove a handler for any fatal signal handled */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
566 for (i = 0; fatal_signals[i]; ++i)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
567 {
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
568 ohandler = (void(*)(int))signal (fatal_signals[i], SIG_DFL);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
569 if (ohandler != pygame_parachute)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
570 signal (fatal_signals[i], ohandler);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
571 }
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
572 #endif
221
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
573 }
af725c6545be more debugging fixes, yay
pygame
parents: 220
diff changeset
574
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
575 /* bind functions to python */
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
576
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
577 static PyObject*
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
578 do_segfault (PyObject* self)
290
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
579 {
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
580 //force crash
291
49763cfeaa44 pygame parachute tracebacks
pygame
parents: 290
diff changeset
581 *((int*)1) = 45;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
582 memcpy ((char*)2, (char*)3, 10);
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 627
diff changeset
583 Py_RETURN_NONE;
290
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
584 }
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
585
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
586 static PyMethodDef _base_methods[] =
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
587 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
588 { "init", (PyCFunction) init, METH_NOARGS, DOC_PYGAMEINIT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
589 { "quit", (PyCFunction) quit, METH_NOARGS, DOC_PYGAMEQUIT },
1894
29f30466a1d0 From Campbell Barton.FloatFromObj speedup. register_quit cleanup.
Rene Dudfield <renesd@gmail.com>
parents: 1602
diff changeset
590 { "register_quit", register_quit, METH_O, DOC_PYGAMEREGISTERQUIT },
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
591 { "get_error", (PyCFunction) get_error, METH_NOARGS, DOC_PYGAMEGETERROR },
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
592 { "set_error", (PyCFunction) set_error, METH_VARARGS, DOC_PYGAMESETERROR },
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
593 { "get_sdl_version", (PyCFunction) get_sdl_version, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
594 DOC_PYGAMEGETSDLVERSION },
868
5c55c84986c1 Added pygame.get_sdl_byteorder() to get the SDL byte order. Added pixelarray and mask html docs. Fixed buffer length in surface.get_buffer().
marcus
parents: 835
diff changeset
595 { "get_sdl_byteorder", (PyCFunction) get_sdl_byteorder, METH_NOARGS,
5c55c84986c1 Added pygame.get_sdl_byteorder() to get the SDL byte order. Added pixelarray and mask html docs. Fixed buffer length in surface.get_buffer().
marcus
parents: 835
diff changeset
596 DOC_PYGAMEGETSDLBYTEORDER },
290
672090421d37 pygame parachute tracebacks
pygame
parents: 246
diff changeset
597
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
598 { "segfault", (PyCFunction) do_segfault, METH_NOARGS, "crash" },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
599 { NULL, NULL, 0, NULL }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
600 };
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
601
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
602 MODINIT_DEFINE(base)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
603 {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
604 static int is_loaded = 0;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
605 PyObject *module, *dict, *apiobj;
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
606 PyObject *atexit, *atexit_register = NULL, *quit, *rval;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
607 PyObject *PyExc_SDLError;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
608 int ecode;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
609 static void* c_api[PYGAMEAPI_BASE_NUMSLOTS];
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
610
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
611 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
612 static struct PyModuleDef _module = {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
613 PyModuleDef_HEAD_INIT,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
614 "base",
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
615 "",
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
616 -1,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
617 _base_methods,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
618 NULL, NULL, NULL, NULL
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
619 };
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
620 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
621
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
622 if (!is_loaded) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
623 /* import need modules. Do this first so if there is an error
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
624 the module is not loaded.
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
625 */
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
626 atexit = PyImport_ImportModule ("atexit");
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
627 if (!atexit) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
628 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
629 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
630 atexit_register = PyObject_GetAttrString (atexit, "register");
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
631 Py_DECREF (atexit);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
632 if (!atexit_register) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
633 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
634 }
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
635 }
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
636
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
637 /* create the module */
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
638 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
639 module = PyModule_Create (&_module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
640 #else
1602
94e248442be3 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1581
diff changeset
641 module = Py_InitModule3 (MODPREFIX "base", _base_methods, DOC_PYGAME);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
642 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
643 if (module == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
644 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
645 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
646 dict = PyModule_GetDict (module);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
647
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
648 /* create the exceptions */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
649 PyExc_SDLError = PyErr_NewException ("pygame.error", PyExc_RuntimeError,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
650 NULL);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
651 if (PyExc_SDLError == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
652 Py_XDECREF (atexit_register);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
653 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
654 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
655 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
656 ecode = PyDict_SetItemString (dict, "error", PyExc_SDLError);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
657 Py_DECREF (PyExc_SDLError);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
658 if (ecode) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
659 Py_XDECREF (atexit_register);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
660 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
661 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
662 }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
663
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
664 /* export the c api */
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
665 c_api[0] = PyExc_SDLError;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
666 c_api[1] = PyGame_RegisterQuit;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
667 c_api[2] = IntFromObj;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
668 c_api[3] = IntFromObjIndex;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
669 c_api[4] = TwoIntsFromObj;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
670 c_api[5] = FloatFromObj;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
671 c_api[6] = FloatFromObjIndex;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
672 c_api[7] = TwoFloatsFromObj;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
673 c_api[8] = UintFromObj;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
674 c_api[9] = UintFromObjIndex;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
675 c_api[10] = PyGame_Video_AutoQuit;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
676 c_api[11] = PyGame_Video_AutoInit;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
677 c_api[12] = RGBAFromObj;
2120
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
678 apiobj = encapsulate_api (c_api, "base");
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
679 if (apiobj == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
680 Py_XDECREF (atexit_register);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
681 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
682 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
683 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
684 ecode = PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
685 Py_DECREF (apiobj);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
686 if (ecode) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
687 Py_XDECREF (atexit_register);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
688 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
689 MODINIT_ERROR;
1500
8f8e6461fa20 fixes bugzilla bug 20: Segmentation fault with register_quit
Lenard Lindstrom <len-l@telus.net>
parents: 1453
diff changeset
690 }
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
691
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
692 if (!is_loaded) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
693 /*some intialization*/
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
694 quit = PyObject_GetAttrString (module, "quit");
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
695 if (quit == NULL) { /* assertion */
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
696 Py_DECREF (atexit_register);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
697 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
698 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
699 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
700 rval = PyObject_CallFunctionObjArgs (atexit_register, quit, NULL);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
701 Py_DECREF (atexit_register);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
702 Py_DECREF (quit);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
703 if (rval == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
704 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
705 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
706 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
707 Py_DECREF (rval);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
708 Py_AtExit (atexit_quit);
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
709 #ifdef HAVE_SIGNAL_H
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
710 install_parachute ();
1581
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
711 #endif
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
712
9f910eda60c5 Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents: 1553
diff changeset
713
346
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
714 #ifdef MS_WIN32
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
715 SDL_RegisterApp ("pygame", 0, GetModuleHandle (NULL));
346
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
716 #endif
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
717 #if defined(macintosh)
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
718 #if(!defined(__MWERKS__) && !TARGET_API_MAC_CARBON)
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
719 SDL_InitQuickDraw (&qd);
346
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
720 #endif
5337d682bd10 init cleanup
pygame
parents: 302
diff changeset
721 #endif
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
722 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
723 is_loaded = 1;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1500
diff changeset
724 MODINIT_RETURN (module);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
725 }