changeset 616:4ce3ef053a25

Remove every case where an exception could be silently eaten by a cdef function.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Mar 2015 23:21:15 +0100
parents d1f0bb0b7a17
children a6af3ff86612
files pytouhou/lib/sdl.pxd pytouhou/lib/sdl.pyx pytouhou/ui/music.pyx pytouhou/ui/sdl/sprite.pyx pytouhou/utils/random.pyx
diffstat 5 files changed, 25 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/lib/sdl.pxd	Sat Mar 28 21:40:51 2015 +0100
+++ b/pytouhou/lib/sdl.pxd	Sat Mar 28 23:21:15 2015 +0100
@@ -60,17 +60,17 @@
     cdef SDL_GLContext context
     cdef SDL_Renderer *renderer
 
-    cdef void gl_create_context(self) except *
+    cdef bint gl_create_context(self) except True
     cdef void present(self) nogil
     cdef void set_window_size(self, int width, int height) nogil
 
     # The following functions are there for the pure SDL backend.
-    cdef void create_renderer(self, Uint32 flags)
-    cdef void render_clear(self)
-    cdef void render_copy(self, Texture texture, Rect srcrect, Rect dstrect)
-    cdef void render_copy_ex(self, Texture texture, Rect srcrect, Rect dstrect, double angle, bint flip)
-    cdef void render_set_clip_rect(self, Rect rect)
-    cdef void render_set_viewport(self, Rect rect)
+    cdef bint create_renderer(self, Uint32 flags) except True
+    cdef bint render_clear(self) except True
+    cdef bint render_copy(self, Texture texture, Rect srcrect, Rect dstrect) except True
+    cdef bint render_copy_ex(self, Texture texture, Rect srcrect, Rect dstrect, double angle, bint flip) except True
+    cdef bint render_set_clip_rect(self, Rect rect) except True
+    cdef bint render_set_viewport(self, Rect rect) except True
     cdef Texture create_texture_from_surface(self, Surface surface)
 
 
@@ -134,4 +134,4 @@
 cdef Chunk load_chunk(file_)
 cdef Uint32 get_ticks() nogil
 cdef void delay(Uint32 ms) nogil
-cpdef int show_simple_message_box(unicode message)
+cpdef bint show_simple_message_box(unicode message) except True
--- a/pytouhou/lib/sdl.pyx	Sat Mar 28 21:40:51 2015 +0100
+++ b/pytouhou/lib/sdl.pyx	Sat Mar 28 23:21:15 2015 +0100
@@ -109,7 +109,7 @@
         if self.window != NULL:
             SDL_DestroyWindow(self.window)
 
-    cdef void gl_create_context(self) except *:
+    cdef bint gl_create_context(self) except True:
         self.context = SDL_GL_CreateContext(self.window)
         if self.context == NULL:
             raise SDLError()
@@ -124,32 +124,32 @@
         SDL_SetWindowSize(self.window, width, height)
 
     # The following functions are there for the pure SDL backend.
-    cdef void create_renderer(self, Uint32 flags):
+    cdef bint create_renderer(self, Uint32 flags) except True:
         self.renderer = SDL_CreateRenderer(self.window, -1, flags)
         if self.renderer == NULL:
             raise SDLError()
 
-    cdef void render_clear(self):
+    cdef bint render_clear(self) except True:
         ret = SDL_RenderClear(self.renderer)
         if ret == -1:
             raise SDLError()
 
-    cdef void render_copy(self, Texture texture, Rect srcrect, Rect dstrect):
+    cdef bint render_copy(self, Texture texture, Rect srcrect, Rect dstrect) except True:
         ret = SDL_RenderCopy(self.renderer, texture.texture, &srcrect.rect, &dstrect.rect)
         if ret == -1:
             raise SDLError()
 
-    cdef void render_copy_ex(self, Texture texture, Rect srcrect, Rect dstrect, double angle, bint flip):
+    cdef bint render_copy_ex(self, Texture texture, Rect srcrect, Rect dstrect, double angle, bint flip) except True:
         ret = SDL_RenderCopyEx(self.renderer, texture.texture, &srcrect.rect, &dstrect.rect, angle, NULL, flip)
         if ret == -1:
             raise SDLError()
 
-    cdef void render_set_clip_rect(self, Rect rect):
+    cdef bint render_set_clip_rect(self, Rect rect) except True:
         ret = SDL_RenderSetClipRect(self.renderer, &rect.rect)
         if ret == -1:
             raise SDLError()
 
-    cdef void render_set_viewport(self, Rect rect):
+    cdef bint render_set_viewport(self, Rect rect) except True:
         ret = SDL_RenderSetViewport(self.renderer, &rect.rect)
         if ret == -1:
             raise SDLError()
@@ -372,6 +372,8 @@
     SDL_Delay(ms)
 
 
-cpdef int show_simple_message_box(unicode message):
+cpdef bint show_simple_message_box(unicode message) except True:
     text = message.encode('UTF-8')
-    return SDL_ShowSimpleMessageBox(1, 'PyTouhou', text, NULL)
+    ret = SDL_ShowSimpleMessageBox(1, 'PyTouhou', text, NULL)
+    if ret == -1:
+        raise SDLError()
--- a/pytouhou/ui/music.pyx	Sat Mar 28 21:40:51 2015 +0100
+++ b/pytouhou/ui/music.pyx	Sat Mar 28 23:21:15 2015 +0100
@@ -76,7 +76,7 @@
         self.volume = volume
         self.next_channel = 0
 
-    cdef int get_channel(self, name):
+    cdef int get_channel(self, name) except -1:
         if name not in self.channels:
             self.channels[name] = self.next_channel
             self.next_channel += 1
--- a/pytouhou/ui/sdl/sprite.pyx	Sat Mar 28 21:40:51 2015 +0100
+++ b/pytouhou/ui/sdl/sprite.pyx	Sat Mar 28 23:21:15 2015 +0100
@@ -12,7 +12,7 @@
 ## GNU General Public License for more details.
 ##
 
-
+cimport cython
 from libc.stdlib cimport malloc
 from libc.math cimport M_PI as pi
 
@@ -23,6 +23,7 @@
     return <RenderingData*>sprite._rendering_data
 
 
+@cython.cdivision(True)
 cdef void render_sprite(Sprite sprite) nogil:
     if sprite._rendering_data == NULL:
         sprite._rendering_data = malloc(sizeof(RenderingData))
--- a/pytouhou/utils/random.pyx	Sat Mar 28 21:40:51 2015 +0100
+++ b/pytouhou/utils/random.pyx	Sat Mar 28 23:21:15 2015 +0100
@@ -25,9 +25,11 @@
 
 #TODO: maybe some post-processing is missing
 
-
+cimport cython
 from time import time
 
+
+@cython.final
 cdef class Random:
     def __init__(self, long seed=-1):
         if seed < 0: