8
8
9
9
int main () { return 0 ; }
10
10
11
- int EMSCRIPTEN_KEEPALIVE pib_init ()
12
- {
13
- putenv ("USE_ZEND_ALLOC=0" );
14
-
15
- return php_embed_init (0 , NULL );
16
- }
17
-
18
- void pib_finally ()
11
+ void phpw_flush ()
19
12
{
20
13
fflush (stdout );
21
14
fprintf (stdout , "\n" );
@@ -24,8 +17,9 @@ void pib_finally()
24
17
fprintf (stderr , "\n" );
25
18
}
26
19
27
- char * EMSCRIPTEN_KEEPALIVE pib_exec (char * code )
20
+ char * EMSCRIPTEN_KEEPALIVE phpw_exec (char * code )
28
21
{
22
+ php_embed_init (0 , NULL );
29
23
char * retVal = NULL ;
30
24
31
25
zend_try
@@ -37,59 +31,51 @@ char *EMSCRIPTEN_KEEPALIVE pib_exec(char *code)
37
31
convert_to_string (& retZv );
38
32
39
33
retVal = Z_STRVAL (retZv );
40
- }
41
- zend_catch
42
- {
43
- }
34
+ } zend_catch {
35
+ } zend_end_try ();
44
36
45
- zend_end_try ();
46
-
47
- pib_finally ();
37
+ phpw_flush ();
38
+ php_embed_shutdown ();
48
39
49
40
return retVal ;
50
41
}
51
42
52
- int EMSCRIPTEN_KEEPALIVE pib_run (char * code )
43
+ void EMSCRIPTEN_KEEPALIVE phpw_run (char * code )
53
44
{
54
- int retVal = 255 ; // Unknown error.
55
-
45
+ php_embed_init (0 , NULL );
56
46
zend_try
57
47
{
58
- retVal = zend_eval_string (code , NULL , "php-wasm run script" );
59
-
48
+ zend_eval_string (code , NULL , "php-wasm run script" );
60
49
if (EG (exception ))
61
50
{
62
51
zend_exception_error (EG (exception ), E_ERROR );
63
- retVal = 2 ;
64
52
}
65
- }
66
- zend_catch
67
- {
68
- retVal = 1 ; // Code died.
69
- }
70
-
71
- zend_end_try ();
72
-
73
- pib_finally ();
74
-
75
- return retVal ;
53
+ // retVal = 2;
54
+ // }
55
+ } zend_catch {
56
+ /* int exit_status = EG(exit_status); */
57
+ } zend_end_try ();
58
+
59
+ phpw_flush ();
60
+ php_embed_shutdown ();
76
61
}
77
62
78
- char * pib_tokenize (char * code )
63
+ void phpw (char * file )
79
64
{
80
- // tokenize_parse(zval zend_string)
65
+ php_embed_init ( 0 , NULL );
81
66
82
- return "" ;
83
- }
67
+ zend_first_try {
68
+ zend_file_handle file_handle ;
69
+ zend_stream_init_filename (& file_handle , file );
84
70
85
- void EMSCRIPTEN_KEEPALIVE pib_destroy ()
86
- {
87
- return php_embed_shutdown ();
88
- }
89
-
90
- int EMSCRIPTEN_KEEPALIVE pib_refresh ()
91
- {
92
- pib_destroy ();
71
+ if (php_execute_script (& file_handle ) == FAILURE ) {
72
+ php_printf ("Failed to execute PHP script.\n" );
73
+ }
74
+ zend_destroy_file_handle (& file_handle );
75
+ } zend_catch {
76
+ /* int exit_status = EG(exit_status); */
77
+ } zend_end_try ();
93
78
94
- return pib_init ();
79
+ phpw_flush ();
80
+ php_embed_shutdown ();
95
81
}
0 commit comments