{"record":{"id":"8b07895f2fc5bc13","repo":"wasmerio/wasmer","slug":"wasmer-env-set-memory-is-not-supported","errorCode":null,"errorMessage":"wasmer_env_set_memory() is not supported","messagePattern":"wasmer_env_set_memory\\(\\) is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/c-api/src/wasm_c_api/wasi/mod.rs","lineNumber":245,"sourceCode":"}\n\n/// Delete a [`wasi_env_t`].\n#[unsafe(no_mangle)]\npub extern \"C\" fn wasi_env_delete(state: Option<Box<wasi_env_t>>) {\n    if let Some(mut env) = state {\n        let mut store = unsafe { env.store.store_mut() };\n        env.inner.on_exit(&mut store, None);\n    }\n}\n\n/// Set the memory on a [`wasi_env_t`].\n// NOTE: Only here to not break the C API.\n// This was previously supported, but is no longer possible due to WASIX changes.\n// Customizing memories should be done through the builder or the runtime.\n#[unsafe(no_mangle)]\n#[deprecated(since = \"4.0.0\")]\npub unsafe extern \"C\" fn wasi_env_set_memory(_env: &mut wasi_env_t, _memory: &wasm_memory_t) {\n    panic!(\"wasmer_env_set_memory() is not supported\");\n}\n\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn wasi_env_read_stdout(\n    env: &mut wasi_env_t,\n    buffer: *mut c_char,\n    buffer_len: usize,\n) -> isize {\n    let inner_buffer = unsafe { slice::from_raw_parts_mut(buffer as *mut _, buffer_len) };\n    let store = unsafe { env.store.store() };\n\n    let stdout = {\n        let data = env.inner.data(&store);\n        data.stdout()\n    };\n\n    if let Ok(mut stdout) = stdout {\n        if let Some(stdout) = stdout.as_mut() {","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/c-api/src/wasm_c_api/wasi/mod.rs#L227-L263","documentation":"wasi_env_set_memory is a deprecated stub kept only for C API source compatibility. Setting the WASI environment's memory directly is no longer possible because WASIX changes made memory management owned elsewhere. Any call unconditionally panics; memory customization must now go through the builder or runtime APIs.","triggerScenarios":"Calling wasi_env_set_memory(env, memory) — the function body is an unconditional panic. There is no path that succeeds.","commonSituations":"Code written against Wasmer 3.x that customized WASI memory by replacement, recompiled against 4.0+; legacy C API samples or vendored bindings still calling the deprecated symbol; ignoring the since-4.0.0 deprecation warning until runtime.","solutions":["Remove the wasi_env_set_memory call entirely; use wasi_env_new / builder APIs to configure memory.","Configure memory via the WASI environment builder or runtime (e.g. set memory sizes at build time) instead of replacing it after creation.","Treat the deprecation attribute as a build-time signal and fix callers before upgrading to 4.x.","If you need a specific memory, attach it through the store/runtime plumbing rather than the WASI env."],"exampleFix":"// before\nwasi_env_set_memory(env, memory); // panics since 4.0\n// after\nwasi_config_t *config = wasi_config_new();\nwasi_env_t *env = wasi_env_new(store, config); // configure via builder/runtime","handlingStrategy":"try-catch","validationCode":"// C: refuse to call the deprecated stub\n#ifdef WASMER_VERSION_MAJOR\n# if WASMER_VERSION_MAJOR >= 4\n#  error \"wasi_env_set_memory was removed in Wasmer 4.x; use the builder API\"\n# endif\n#endif","typeGuard":null,"tryCatchPattern":"// Catch around migration shims during upgrade\nstd::panic::catch_unwind(|| unsafe { wasi_env_set_memory(env, memory) })\n    .expect_err(\"wasi_env_set_memory is not supported; migrate to builder API\");","preventionTips":["Fix all deprecation warnings before upgrading across major versions.","Configure WASI memory only through builder/runtime APIs.","Grep codebases for wasi_env_set_memory during 3.x -> 4.x migrations."],"tags":["rust","panic","c-api","wasi","deprecated","breaking-change"],"backgroundTag":"deprecated-api-removed","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}