-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
src: allow blobs in addition to FILE*s in embedder snapshot API
#46491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
FILE*s in embedder snapshot API
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,11 +65,28 @@ int RunNodeInstance(MultiIsolatePlatform* platform, | |
| std::find(args.begin(), args.end(), "--embedder-snapshot-create"); | ||
| auto snapshot_arg_it = | ||
| std::find(args.begin(), args.end(), "--embedder-snapshot-blob"); | ||
| auto snapshot_as_file_it = | ||
| std::find(args.begin(), args.end(), "--embedder-snapshot-as-file"); | ||
| if (snapshot_arg_it < args.end() - 1 && | ||
| snapshot_build_mode_it == args.end()) { | ||
| FILE* fp = fopen((snapshot_arg_it + 1)->c_str(), "r"); | ||
| const char* filename = (snapshot_arg_it + 1)->c_str(); | ||
| FILE* fp = fopen(filename, "r"); | ||
| assert(fp != nullptr); | ||
| snapshot = node::EmbedderSnapshotData::FromFile(fp); | ||
| if (snapshot_as_file_it != args.end()) { | ||
| snapshot = node::EmbedderSnapshotData::FromFile(fp); | ||
| } else { | ||
| uv_fs_t req; | ||
| int statret = uv_fs_stat(nullptr, &req, filename, nullptr); | ||
| assert(statret == 0); | ||
| size_t filesize = req.statbuf.st_size; | ||
| uv_fs_req_cleanup(&req); | ||
|
|
||
| std::vector<char> vec(filesize); | ||
| size_t read = fread(vec.data(), filesize, 1, fp); | ||
| assert(read == 1); | ||
| snapshot = node::EmbedderSnapshotData::FromBlob(vec); | ||
| } | ||
| assert(snapshot); | ||
| fclose(fp); | ||
| } | ||
|
|
||
|
|
@@ -125,7 +142,13 @@ int RunNodeInstance(MultiIsolatePlatform* platform, | |
|
|
||
| FILE* fp = fopen((snapshot_arg_it + 1)->c_str(), "w"); | ||
| assert(fp != nullptr); | ||
| snapshot->ToFile(fp); | ||
| if (snapshot_as_file_it != args.end()) { | ||
| snapshot->ToFile(fp); | ||
| } else { | ||
| const std::vector<char> vec = snapshot->ToBlob(); | ||
| size_t written = fwrite(vec.data(), vec.size(), 1, fp); | ||
| assert(written == 1); | ||
| } | ||
| fclose(fp); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be entirely wrong about this, but my understanding of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry, I didn't realize I was referring to a test file. I think it's also true for non-test occurrences such as the same call to Maybe add
I didn't look at what exactly
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense to me. I’ll follow up with a PR to do that.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR: #46531 |
||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.