Dynamic import of statically linked .so results in Reference error

オープン
#423 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
c
領域
compilers

調査の方向性

Reproduce the two scenarios using foo.c, app.js, qjsc, and the generated app.c, then compare the initialization code produced for static and dynamic imports. Start by tracing qjsc's -M handling and verify that the dynamic import path can initialize foo.so; done means the dynamic import no longer raises ReferenceError without manually editing app.c.

索引モデルが issue の本文から書いたものです。

説明

Setup: foo.c is c module named foo.

Scenario 1: foo.c is statically linked with app.mjs to create ./app:

qjsc  -e -M foo.so,foo -m -o app.c app.js
gcc -I/opt/homebrew/Cellar/quickjs/2025-04-26/include/quickjs -c app.c -o app.o
gcc -I/opt/homebrew/Cellar/quickjs/2025-04-26/include/quickjs -c foo.c -o foo.o
gcc -L/opt/homebrew/Cellar/quickjs/2025-04-26/lib/quickjs -lquickjs - -o app app.o foo.o

app.js does: import { add } from './foo.so;
This works as expected

Scenario 2: app.js does: const { add } = await import( './foo.so' )
there is a reference error.

This is because the required initialization code:

{
    extern JSModuleDef *js_init_module_foo(JSContext *ctx, const char *name);
    js_init_module_foo(ctx, "foo.so");
 }

gets added to app.c in scenario 1 but not scenario 2.

If the init code is manaully added to app.c in scenario 2 it works fine. It seems like qjsc -M provides enough information to create the init code in either case.

主要言語
C
スター
11.1k
フォーク
1.2k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bellard/quickjs のほかの issue

bellard/quickjs の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。