Skip to content

Commit 19fbdc8

Browse files
committed
Fixing sapi name pointer bug
1 parent 19d16b5 commit 19fbdc8

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

source/PhpBase.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export class PhpBase extends EventTarget
123123

124124
inputString(byteString)
125125
{
126-
console.trace(byteString);
127126
this.input(this.encoder.encode(byteString));
128127
}
129128

source/pib/pib.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ char *_sapi_name = NULL;
4242
*/
4343
int EMSCRIPTEN_KEEPALIVE __attribute__((noinline)) pib_init(char *__sapi_name)
4444
{
45-
_sapi_name = __sapi_name;
45+
if(!_sapi_name)
46+
{
47+
_sapi_name = malloc(strlen(__sapi_name) + 1);
48+
strcpy(_sapi_name, __sapi_name);
49+
}
50+
4651
putenv("USE_ZEND_ALLOC=0");
4752

48-
// fprintf(stderr, "SAPI: %s...\n\n", _sapi_name);
4953
if(0 == strcmp(_sapi_name, "embed"))
5054
{
5155
return php_embed_init(0, NULL);

test/basic.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test('Can maintain memory between executions', async () => {
9090
});
9191

9292
test('Can refresh memory between executions', async () => {
93-
const php = new PhpNode();
93+
const php = new PhpNode({});
9494

9595
let stdOut = '', stdErr = '';
9696

@@ -101,10 +101,11 @@ test('Can refresh memory between executions', async () => {
101101
await php.run(`<?php $i = 100;`);
102102
await php.run(`<?php $i++;`);
103103
await php.refresh();
104-
await php.run(`<?php ini_set('display_errors', 1); @error_reporting(E_ALL | E_STRICT); echo $i . PHP_EOL;`);
104+
await php.run(`<?php ini_set('display_errors', 1); @error_reporting(E_ALL | E_STRICT); var_dump($i) . PHP_EOL;`);
105105

106-
assert.equal(stdOut, `\nWarning: Undefined variable $i in php-wasm run script on line 1\n\n`);
106+
assert.equal(stdOut, `\nWarning: Undefined variable $i in php-wasm run script on line 1\nNULL\n`);
107107
assert.equal(stdErr, '');
108+
108109
});
109110

110111
test('Can read files from the local FS through PHP functions', async () => {

0 commit comments

Comments
 (0)