From 85394c5613f1f52407020abab650fda6b9da91ad Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 23 Apr 2025 04:03:19 +0900 Subject: feat(blog/content): update post /posts/2023-10-02/compile-php-runtime-to-wasm/ --- .../compile-php-runtime-to-wasm/index.html | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'vhosts/blog/public/posts/2023-10-02/compile-php-runtime-to-wasm') diff --git a/vhosts/blog/public/posts/2023-10-02/compile-php-runtime-to-wasm/index.html b/vhosts/blog/public/posts/2023-10-02/compile-php-runtime-to-wasm/index.html index 61ed2092..933253a3 100644 --- a/vhosts/blog/public/posts/2023-10-02/compile-php-runtime-to-wasm/index.html +++ b/vhosts/blog/public/posts/2023-10-02/compile-php-runtime-to-wasm/index.html @@ -58,6 +58,9 @@
  • : 公開
  • +
  • + : fflush() の前に改行の出力が必要だった理由と正しい実装について追記 +
  • @@ -160,6 +163,39 @@

    次に、コードを評価したあとに呼んでいる標準出力と標準エラー出力に対する改行の出力について。 出力バッファから出力させるためだけなら改行を出力させなくとも fflush() だけで事足りると考えたのだが、ないと動かなかったので追加した。 これにより、PHP コードの出力の後ろに余分な改行が追加されてしまう。 改行を出力せずともバッファを消費させる手段をご存知のかたはご教示願いたい。

    +
    +
    + NOTE +
    +
    +

    + 2025-04-23 追記: +

    +

    + fflush() の前に改行の出力が必要だった理由が判明したので追記する。 これは、index.mjs で標準出力・標準エラー出力へ出力する方法を指定せず、デフォルトの実装に任せているため。 Emscripten のデフォルト実装では、改行コードを出力するまで出力内容がバッファリングされ、fflush() が機能しない。 +

    +

    + デフォルトの出力方法は index.mjs の中で PHPWasm() を呼ぶとき、stdoutstderr というオプションを渡せば変更できる。 +

    +
    +
    const { ccall } = await PHPWasm({
    +  stdout: (c) => {
    +    if (c === null) {
    +      // flush the standard output.
    +    } else {
    +      // output c to the standard output.
    +    }
    +  },
    +});
    +
    +

    + cnull か 1バイト符号つき整数を取り、null が flush 要求を意味する。 +

    +

    + 記事末尾のリポジトリはすでにこの変更を適用済み。stdoutstderr の完全なサンプルはそちらを参照のこと。 +

    +
    +

    WebAssembly にコンパイルする

    -- cgit v1.2.3-70-g09d2