7
7
8
8
// Emscripten tests
9
9
10
- #include <stdio.h>
11
- #include <stdlib.h>
12
10
#include <assert.h>
11
+ #include <emscripten.h>
12
+ #include <stdlib.h>
13
13
14
14
int main (int ac , char * * av )
15
15
{
@@ -20,67 +20,30 @@ int main(int ac, char **av)
20
20
char * allocations [NUM ];
21
21
for (int i = 0 ; i < NUM /2 ; i ++ ) {
22
22
allocations [i ] = (char * )malloc ((11 * i )%1024 + x );
23
- //printf("zz alloc: %d\n", (int)allocations[i]);
24
23
assert (allocations [i ]);
25
24
if (i > 10 && i %4 == 1 && allocations [i - 10 ]) {
26
- //printf("zz free: %d\n", (int)allocations[i-10]);
27
25
free (allocations [i - 10 ]);
28
26
allocations [i - 10 ] = NULL ;
29
27
}
30
28
}
31
29
for (int i = NUM /2 ; i < NUM ; i ++ ) {
32
30
allocations [i ] = (char * )malloc (1024 * (i + 1 ));
33
- //printf("zz alloc: %d\n", (int)allocations[i]);
34
31
assert (allocations [i ]);
35
32
if (i > 10 && i %4 != 1 && allocations [i - 10 ]) {
36
- //printf("zz free: %d\n", (int)allocations[i-10]);
37
33
free (allocations [i - 10 ]);
38
34
allocations [i - 10 ] = NULL ;
39
35
}
40
36
}
41
37
char * first = allocations [0 ];
42
38
for (int i = 0 ; i < NUM ; i ++ ) {
43
39
if (allocations [i ]) {
44
- //printf("zz free: %d\n", (int)allocations[i]);
45
40
free (allocations [i ]);
46
41
}
47
42
}
48
43
char * last = (char * )malloc (512 ); // should be identical, as we free'd it all
49
- //printf("zz last: %d\n", (int)last);
50
44
char * newer = (char * )malloc (512 ); // should be different
51
- //printf("zz newer: %d\n", (int)newer);
52
- #ifndef __APPLE__
53
45
c1 += first == last ;
54
46
c2 += first == newer ;
55
- #else // On OSX, it's been detected that memory is not necessarily allocated linearly, so skip this check and simulate success.
56
- ++ c1 ;
57
- #endif
58
47
}
59
- printf ( "*%d,%d*\n" , c1 , c2 );
48
+ emscripten_log ( EM_LOG_CONSOLE , "*%d,%d*\n" , c1 , c2 );
60
49
}
61
-
62
- /* Some debugging tools: Make JS and native code work exactly the same */
63
- /*
64
- time_t time ( time_t * timer )
65
- {
66
- if (timer) *timer = 1;
67
- return 1;
68
- }
69
-
70
- long sysconf(int name)
71
- {
72
- printf("sysconf: %d (30 is page size)\n", name);
73
- return 4096;
74
- }
75
-
76
- void *sbrk(intptr_t increment)
77
- {
78
- static char spaace[1024*1024*1];
79
- static intptr_t where = 0;
80
- printf("sbrk! spaace=%d (%d,%d)\n", (int)&spaace[0], where, increment); // copy the value printed at runtime here in native code into your js
81
- void *ret = &spaace[where];
82
- where += increment;
83
- return ret;
84
- }
85
- */
86
-
0 commit comments