Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,7 @@ scratch*.{js,ts,tsx,cjs,mjs}

*.bun-build

scripts/lldb-inline
scripts/lldb-inline

# We regenerate these in all the build scripts
cmake/sources/*.txt
22 changes: 0 additions & 22 deletions cmake/sources/BakeRuntimeSources.txt

This file was deleted.

7 changes: 0 additions & 7 deletions cmake/sources/BindgenSources.txt

This file was deleted.

12 changes: 0 additions & 12 deletions cmake/sources/BunErrorSources.txt

This file was deleted.

15 changes: 0 additions & 15 deletions cmake/sources/CSources.txt

This file was deleted.

21 changes: 0 additions & 21 deletions cmake/sources/JavaScriptCodegenSources.txt

This file was deleted.

172 changes: 0 additions & 172 deletions cmake/sources/JavaScriptSources.txt

This file was deleted.

24 changes: 0 additions & 24 deletions cmake/sources/NodeFallbacksSources.txt

This file was deleted.

25 changes: 0 additions & 25 deletions cmake/sources/ZigGeneratedClassesSources.txt

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"watch-windows": "bun run zig build check-windows --watch -fincremental --prominent-compile-errors --global-cache-dir build/debug/zig-check-cache --zig-lib-dir vendor/zig/lib",
"bd:v": "(bun run --silent build:debug &> /tmp/bun.debug.build.log || (cat /tmp/bun.debug.build.log && rm -rf /tmp/bun.debug.build.log && exit 1)) && rm -f /tmp/bun.debug.build.log && ./build/debug/bun-debug",
"bd": "BUN_DEBUG_QUIET_LOGS=1 bun --silent bd:v",
"build:debug": "export COMSPEC=\"C:\\Windows\\System32\\cmd.exe\" && bun scripts/glob-sources.mjs > /dev/null && bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug --log-level=NOTICE",
"build:debug": "export COMSPEC=\"C:\\Windows\\System32\\cmd.exe\" && bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug --log-level=NOTICE",
"build:debug:asan": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -B build/debug-asan --log-level=NOTICE",
"build:release": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Release -B build/release",
"build:ci": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCI=true -B build/release-ci --verbose --fresh",
Expand Down
6 changes: 4 additions & 2 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { spawn as nodeSpawn } from "node:child_process";
import { chmodSync, cpSync, existsSync, mkdirSync, readFileSync } from "node:fs";
import { basename, join, relative, resolve } from "node:path";
Expand All @@ -14,6 +12,10 @@ import {
startGroup,
} from "./utils.mjs";

if (globalThis.Bun) {
await import("./glob-sources.mjs");
}

// https://cmake.org/cmake/help/latest/manual/cmake.1.html#generate-a-project-buildsystem
const generateFlags = [
["-S", "string", "path to source directory"],
Expand Down
26 changes: 24 additions & 2 deletions src/bun.js/bindings/libuv/generate_uv_posix_stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,32 @@ async function generate(symbol_name: string): Promise<[stub: string, symbol_name
assert(decl.includes("UV_EXTERN"), "Must include UV_EXTERN: \n" + decl);

const types = extractParameterTypes(decl);
types.decls = types.decls.map(d => d + ";");

// For stub generation, we need semicolons but no initialization
const stub_types = { ...types };
stub_types.decls = stub_types.decls.map(d => d + ";");
if (stub_types.args.length === 1 && stub_types.args[0] === "void") {
stub_types.decls = [];
stub_types.args = [];
}

// For test plugin generation, we need initialization
if (types.args.length === 1 && types.args[0] === "void") {
types.decls = [];
types.args = [];
} else {
types.decls = types.decls.map(d => {
if (d.includes("argv") || d.includes("argc")) {
return d.trim() + ";";
}

// Initialize function pointers and multi-pointers to NULL, everything else to {0}
if (d.includes("**") || d.includes("(*") || d.includes("_cb ")) {
return d + " = NULL;";
}

return d + " = {0};";
});
}
Comment on lines +231 to 244

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Initialize pointers with NULL (including single pointers); avoid {0} for pointer types.

Current check only NULL-inits multi-pointers/function ptrs, leaving single pointers initialized with {0}, which can trigger braced-scalar-init warnings and is brittle. Treat any pointer declarator as needing NULL.

Apply this diff:

-      types.decls = types.decls.map(d => {
-        if (d.includes("argv") || d.includes("argc")) {
-          return d.trim() + ";";
-        }
-
-        // Initialize function pointers and multi-pointers to NULL, everything else to {0}
-        if (d.includes("**") || d.includes("(*") || d.includes("_cb ")) {
-          return d + " = NULL;";
-        }
-
-        return d + " = {0};";
-      });
+      types.decls = types.decls.map(d => {
+        if (/\b(argv|argc)\b/.test(d)) return d.trim() + ";";
+        // Any pointer (incl. function pointers) -> NULL; everything else -> zero-init
+        if (d.includes("*")) return d + " = NULL;";
+        return d + " = {0};";
+      });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else {
types.decls = types.decls.map(d => {
if (d.includes("argv") || d.includes("argc")) {
return d.trim() + ";";
}
// Initialize function pointers and multi-pointers to NULL, everything else to {0}
if (d.includes("**") || d.includes("(*") || d.includes("_cb ")) {
return d + " = NULL;";
}
return d + " = {0};";
});
}
} else {
types.decls = types.decls.map(d => {
if (/\b(argv|argc)\b/.test(d)) return d.trim() + ";";
// Any pointer (incl. function pointers) -> NULL; everything else -> zero-init
if (d.includes("*")) return d + " = NULL;";
return d + " = {0};";
});
}
🤖 Prompt for AI Agents
In src/bun.js/bindings/libuv/generate_uv_posix_stubs.ts around lines 231 to 244,
the code currently only initializes multi-pointers and function pointers to NULL
but leaves single pointer declarations initialized with "{0}", which can trigger
braced-scalar-init warnings; update the logic to treat any pointer declarator
(e.g., any declara tor text containing "*" ) as needing " = NULL;" so that
single pointers, multi-pointers, and function pointers are all initialized to
NULL, while non-pointer types keep " = {0};" and keep the existing argc/argv
special-case unchanged.


const decl_without_semicolon = decl.replaceAll(";", "").trim();
Expand Down Expand Up @@ -362,7 +384,7 @@ napi_value Init(napi_env env, napi_value exports) {
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
`;

const plugin_path_ = join(import.meta.dir, "../", "../", "test", "napi", "uv-stub-stuff", "plugin.c");
const plugin_path_ = join(import.meta.dir, "../", "../", "../", "../", "test", "napi", "uv-stub-stuff", "plugin.c");
await Bun.write(plugin_path_, test_plugin_contents);

if (Bun.which("clang-format")) {
Expand Down
1 change: 1 addition & 0 deletions test/internal/ban-words.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { file, Glob } from "bun";
import { readdirSync } from "fs";
import path from "path";
import "../../scripts/glob-sources.mjs";

// prettier-ignore
const words: Record<string, { reason: string; regex?: boolean }> = {
Expand Down
Loading