C++ bindgen: function with two `own<resource>` args returns an error handle

Offen
#1,684 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
cpp, wasm
Bereich
compilers, devtools

Rechercherichtung

Beginnen Sie damit, den Fehler mit den Provider-Quellen in src/provider-Cpp/, den Consumer-Quellen in src/consumer-C/ und der bereitgestellten composed.wasm zu reproduzieren. Untersuchen Sie anschließend den C++-Bindgen-Pfad für Resource-Methoden, die Strings zurückgeben. Die Behebung ist abgeschlossen, wenn die zusammengesetzte Komponente statt "" "temres26" ausgibt und weiterhin die aufgeführten jco- und wasmtime-Läufe besteht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary: C++ provider component lifts a non-empty string return value as an empty string.

A wit-bindgen-cpp bug where a C++ provider component returns an empty string in place of the actual string value (e.g. "temres26"), observed consistently across all consumer languages.

Environment

component version
OS macOS 15.7 (Darwin 24.6.0), x86_64
jco 1.16.1 (source checkout, tag jco-v1.16.1)
Node.js v22.22.2
wac wac-cli 0.8.1
wasi-sdk 27.0 (wasm32-wasip2-clang/clang++)

Steps to reproduce

The full chain is: compile the guest sources into a provider component and a consumer component, compose them with wac, then run the composed component. Prebuilt copies of every artifact are included (components/provider.wasm, components/consumer.wasm, composed.wasm), so you can also skip straight to step 5.

Github repo:https://github.com/xiaozzzZZzzz240/G051-Cplusplus-string-return-from-a-resource-method-comes-back-empty

  1. Clone this repository:

    git clone <THIS_REPO_URL>
    cd <THIS_REPO_DIR>
    
  2. Compile the provider component from the C++ sources in src/provider-Cpp/ (toolchain versions in the table above; the WIT package is in wit/):

    wasm32-wasip2-clang++ -std=c++23 -fno-exceptions -o components/provider.wasm -mexec-model=reactor src/provider-Cpp/world69-uvfx7r7j_generated.cpp src/provider-Cpp/world69_uvfx7r7j.cpp src/provider-Cpp/world69_uvfx7r7j_component_type.o
    
  3. Compile the consumer component from the C sources in src/consumer-C/:

    wasm32-wasip2-clang -o components/consumer.wasm -mexec-model=reactor src/consumer-C/world69b-myhp0jr6_generated.c src/consumer-C/world69b_myhp0jr6.c src/consumer-C/world69b_myhp0jr6_component_type.o
    
  4. Compose the two components into one runnable component with wac 0.8.1:

    wac plug components/consumer.wasm --plug components/provider.wasm -o composed.wasm
    
  5. Run the composed component with jco:

    npm install -g @bytecodealliance/[email protected]
    jco run composed.wasm
    

Expected result

The composed component should print exactly the following, then exit 0:

"resinst0"
"resinst0"
"foo"
true
true
"temres132"
resource("temres26")
([resource("temres28")], "foo")
true
resource("temres160")
resource("temres161")
true
"temres26"
"temres32"
7
"p"

Actual result

Under jco the same composed.wasm exits with rc=0. stdout:

"resinst0"
"resinst0"
"foo"
true
true
"temres132"
resource("temres26")
([resource("temres28")], "foo")
true
resource("temres160")
resource("temres161")
true
""
"temres32"
7
"p"

stderr:

(empty)

wasmtime on the exact same file: rc=1

"resinst0"
"resinst0"
"foo"
true
true
"temres132"
resource("temres26")
([resource("temres28")], "foo")
true
resource("temres160")
resource("temres161")
true

--- stderr ---
Error: failed to run main module `/Users/myuser/WASM/myProject/Wasm_component_testing/mycode/execute/reportrepo/G051-wit-bindgen-cpp-returns-empty-string-instead-of-original-value/composed.wasm`

Caused by:
    0: failed to invoke `run` function
    1: error while executing at wasm backtrace:
           0:    0x5fe - <unknown>!<wasm function 17>
           1:  0xa18f9 - wit-component:shim!indirect-mydefined:package3hl16smu1p/itf-n3bcdaqpyw-f-ywm7quh
           2:  0x64eca - consumer.wasm!mydefined_package3hl16smu1p_itf_n3bcdaqpyw_f_ywm7quh
           3:  0x642eb - consumer.wasm!exports_wasi_cli_run_run
           4:  0x64fd1 - consumer.wasm!__wasm_export_exports_wasi_cli_run_run
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    2: unknown handle index 521124
Vorherrschende Sprache
Rust
Sterne
1.5k
Forks
306
Ø Merge
1 T. 4 Std.
Gemergte PRs (30 T.)
21

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Keine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus bytecodealliance/wit-bindgen

Alle Issues in bytecodealliance/wit-bindgen

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.