[ffigen] Fix potential null access for _tmpDir when creating temporary directories#3029
[ffigen] Fix potential null access for _tmpDir when creating temporary directories#3029Gurleen-kansray wants to merge 6 commits intodart-lang:mainfrom
Conversation
|
PR description is inaccurate. The code was already null safe, you're just changing the name of the temp directory. Setting that aside, I'd prefer if this change only affected the tests. Maybe change it from a getter to a function with an optional prefix param, and pass a path with a space in the tests. But now that I'm looking at this code, I notice an issue with it (not related to your change, but it'd be nice if you could fix this at the same time). I recently tried to eliminate all the global variables from FFIgen, but it seems I missed one. Moving |
|
Thanks for the feedback @liamappelbe ..you’re right, my PR description was inaccurate. The code was already null-safe, and the change effectively only altered the temp directory name. I want to make sure I’m aligning with the intended direction before attempting a larger refactor. |
There's already a |
|
Hi @liamappelbe, I updated _matchFileWithExpected to require a Context so it can use tmpDir from the context, avoiding conflicts in concurrent FFIgen runs. This affects all tests calling it. Should I go ahead and update the tests to pass Context, or keep backward compatibility for now? |
There's no need to maintain backwards compatibility in tests. Definitely update the tests. |
PR HealthLicense Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with |
0e95334 to
d3b1463
Compare
| // Initialize compiler options | ||
| compilerOpts = config.headers.compilerOptions ?? defaultCompilerOpts(logger); | ||
|
|
||
| objCBuiltInFunctions = ObjCBuiltInFunctions( |
There was a problem hiding this comment.
What's with all these unrelated diffs? You've removed some important stuff.
pkgs/ffigen/lib/src/strings.dart
Outdated
There was a problem hiding this comment.
You've still got this global variable. The point was to move this into the context.
|
Thanks, that makes sense. You’re right ......I added The unrelated diffs weren’t intentional; I’ll revert those and keep the change focused. I also see the remaining global I’ll update the PR accordingly. |
|
Following the earlier review, I’ve updated _matchFileWithExpected to use context.tmpDir and removed the remaining global _tmpDir. Please let me know if any further adjustments are needed. |
This PR fixes a potential null access issue for _tmpDir when creating a temporary directory. The assignment now safely uses the null-aware operator to ensure _tmpDir is initialized properly:
_tmpDir ??= Directory.systemTemp.createTempSync('temp dir ');
Verified with scope_test.dart, which directly tests this functionality.
The change is localized, so it should not affect unrelated functionality. This ensures safer initialization of _tmpDir and prevents potential runtime null errors.
[x] I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Closes #3026