Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Aug 25, 2023
1 parent c2be37a commit ca4e002
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 49 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Expand Up @@ -52,7 +52,6 @@ ARG ASSERTIONS=0
ARG OPTIMIZE=-O2
# ARG PRE_JS=
ARG INITIAL_MEMORY=256mb
COPY ./source /src/source
COPY --from=libxml /src/libxml2/build/ /src/usr
COPY --from=sqlite /src/sqlite/sqlite3.o /src/usr/lib/
COPY --from=sqlite /src/sqlite/sqlite3.h /src/usr/include/sqlite3/
Expand Down Expand Up @@ -93,6 +92,7 @@ RUN ./buildconf --force \
RUN emmake make -j8
# PHP7 outputs a libphp7 whereas php8 a libphp
RUN bash -c '[[ -f .libs/libphp7.la ]] && mv .libs/libphp7.la .libs/libphp.la && mv .libs/libphp7.a .libs/libphp.a && mv .libs/libphp7.lai .libs/libphp.lai || exit 0'
COPY ./source /src/source
RUN emcc $OPTIMIZE \
-I . \
-I Zend \
Expand All @@ -105,7 +105,7 @@ RUN emcc $OPTIMIZE \
RUN mkdir /build && emcc $OPTIMIZE \
-o /build/php-$WASM_ENVIRONMENT.mjs \
--llvm-lto 2 \
-s EXPORTED_FUNCTIONS='["_pib_init", "_pib_destroy", "_pib_run", "_pib_exec", "_pib_refresh", "_php_embed_init", "_php_embed_shutdown", "_php_embed_shutdown", "_zend_eval_string"]' \
-s EXPORTED_FUNCTIONS='["_phpw", "_phpw_flush", "_phpw_exec", "_phpw_run", "_php_embed_init", "_php_embed_shutdown", "_zend_eval_string"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS"]' \
-s ENVIRONMENT=$WASM_ENVIRONMENT \
-s FORCE_FILESYSTEM=1 \
Expand All @@ -116,7 +116,6 @@ RUN mkdir /build && emcc $OPTIMIZE \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s MODULARIZE=1 \
-s INVOKE_RUN=0 \
# --pre-js=$PRE_JS \
-s LZ4=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=createPhpModule \
Expand Down
78 changes: 32 additions & 46 deletions source/pib_eval.c
Expand Up @@ -8,14 +8,7 @@

int main() { return 0; }

int EMSCRIPTEN_KEEPALIVE pib_init()
{
putenv("USE_ZEND_ALLOC=0");

return php_embed_init(0, NULL);
}

void pib_finally()
void phpw_flush()
{
fflush(stdout);
fprintf(stdout, "\n");
Expand All @@ -24,8 +17,9 @@ void pib_finally()
fprintf(stderr, "\n");
}

char *EMSCRIPTEN_KEEPALIVE pib_exec(char *code)
char *EMSCRIPTEN_KEEPALIVE phpw_exec(char *code)
{
php_embed_init(0, NULL);
char *retVal = NULL;

zend_try
Expand All @@ -37,59 +31,51 @@ char *EMSCRIPTEN_KEEPALIVE pib_exec(char *code)
convert_to_string(&retZv);

retVal = Z_STRVAL(retZv);
}
zend_catch
{
}
} zend_catch {
} zend_end_try();

zend_end_try();

pib_finally();
phpw_flush();
php_embed_shutdown();

return retVal;
}

int EMSCRIPTEN_KEEPALIVE pib_run(char *code)
void EMSCRIPTEN_KEEPALIVE phpw_run(char *code)
{
int retVal = 255; // Unknown error.

php_embed_init(0, NULL);
zend_try
{
retVal = zend_eval_string(code, NULL, "php-wasm run script");

zend_eval_string(code, NULL, "php-wasm run script");
if(EG(exception))
{
zend_exception_error(EG(exception), E_ERROR);
retVal = 2;
}
}
zend_catch
{
retVal = 1; // Code died.
}

zend_end_try();

pib_finally();

return retVal;
// retVal = 2;
// }
} zend_catch {
/* int exit_status = EG(exit_status); */
} zend_end_try();

phpw_flush();
php_embed_shutdown();
}

char *pib_tokenize(char *code)
void phpw(char *file)
{
// tokenize_parse(zval zend_string)
php_embed_init(0, NULL);

return "";
}
zend_first_try {
zend_file_handle file_handle;
zend_stream_init_filename(&file_handle, file);

void EMSCRIPTEN_KEEPALIVE pib_destroy()
{
return php_embed_shutdown();
}

int EMSCRIPTEN_KEEPALIVE pib_refresh()
{
pib_destroy();
if (php_execute_script(&file_handle) == FAILURE) {
php_printf("Failed to execute PHP script.\n");
}
zend_destroy_file_handle(&file_handle);
} zend_catch {
/* int exit_status = EG(exit_status); */
} zend_end_try();

return pib_init();
phpw_flush();
php_embed_shutdown();
}

0 comments on commit ca4e002

Please sign in to comment.