aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-05 16:12:43 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-05 16:12:43 -0700
commitbf673b03ca52e3613b78ddf412cb99be71a4d816 (patch)
tree26efcfe7c703bd51b58733e269f79de25ef34a09
parent558ac1930bf2fb014e8906408a5821c61729382a (diff)
add test for sdl allocation, and warn when using stub malloc/free
-rw-r--r--src/library.js9
-rwxr-xr-xtests/runner.py3
-rw-r--r--tests/sdl_alloctext.c36
3 files changed, 47 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index e984b1eb..cfe83c6e 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3751,10 +3751,17 @@ LibraryManager.library = {
* implementation (replaced by dlmalloc normally) so
* not an issue.
*/
+#if ASSERTIONS
+ Runtime.warnOnce('using stub malloc (reference it from C to have the real one included)');
+#endif
var ptr = Runtime.dynamicAlloc(bytes + 8);
return (ptr+8) & 0xFFFFFFF8;
},
- free: function(){},
+ free: function() {
+#if ASSERTIONS
+ Runtime.warnOnce('using stub free (reference it from C to have the real one included)');
+#endif
+},
calloc__deps: ['malloc'],
calloc: function(n, s) {
diff --git a/tests/runner.py b/tests/runner.py
index 7005718c..0d8878c3 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -12117,6 +12117,9 @@ elif 'browser' in str(sys.argv):
self.btest('sdl_canvas_palette_2.c', reference='sdl_canvas_palette_g.png', args=['--pre-js', 'pre.js', '--pre-js', 'args-g.js'])
self.btest('sdl_canvas_palette_2.c', reference='sdl_canvas_palette_b.png', args=['--pre-js', 'pre.js', '--pre-js', 'args-b.js'])
+ def test_sdl_alloctext(self):
+ self.btest('sdl_alloctext.c', expected='1', args=['-O2', '-s', 'TOTAL_MEMORY=' + str(1024*1024*8)])
+
def test_glbegin_points(self):
shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png'))
self.btest('glbegin_points.c', reference='glbegin_points.png', args=['--preload-file', 'screenshot.png'])
diff --git a/tests/sdl_alloctext.c b/tests/sdl_alloctext.c
new file mode 100644
index 00000000..0ee75f07
--- /dev/null
+++ b/tests/sdl_alloctext.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL.h>
+#include <SDL_ttf.h>
+
+int main(int argc, char **argv)
+{
+ int result = 0;
+
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
+
+ TTF_Font *font = TTF_OpenFont("myfont.ttf", 40);
+
+ if (argc == 12) font = (TTF_Font*)malloc(1024);
+ if (argc % 3) free(font);
+
+ int i = 0;
+ while (i < 200)
+ {
+ printf("%i\n", i);
+ i++;
+
+ SDL_Color color = { 0xff, 0x99, 0x00, 0xff };
+ SDL_Surface *text = TTF_RenderText_Solid(font, "hello world", color);
+ SDL_BlitSurface (text, NULL, screen, NULL);
+
+ SDL_FreeSurface(text);
+ }
+
+#if __EMSCRIPTEN__
+ result = 1;
+ REPORT_RESULT();
+#endif
+}
+