Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
35bead7b
Commit
35bead7b
authored
Feb 25, 2018
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use writable mmap() to write generated code. Fixes #635
parent
44f5f568
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
38 deletions
+4
-38
capnpc-c++.c++
c++/src/capnp/compiler/capnpc-c++.c++
+4
-38
No files found.
c++/src/capnp/compiler/capnpc-c++.c++
View file @
35bead7b
...
...
@@ -3012,48 +3012,14 @@ private:
// - In a power outage scenario, the user would obviously restart the build from scratch
// anyway.
//
// We do, however, use mmap(), allowing us to write directly to page cache, avoiding a copy,
// and even allowing us to avoid dirtying the file pages if they're not modified, which will
// commonly be the case with incremental builds.
//
// Yes, I overengineered this a bit... but it was fun.
// At one point, in a fit of over-engineering, we used writable mmap() here. That turned out
// to be a bad idea: writable mmap() is not implemented on some filesystems, especially shared
// folders in VirtualBox. Oh well.
auto
path
=
kj
::
Path
::
parse
(
filename
);
auto
file
=
fs
->
getCurrent
().
openFile
(
path
,
kj
::
WriteMode
::
CREATE
|
kj
::
WriteMode
::
MODIFY
|
kj
::
WriteMode
::
CREATE_PARENT
);
file
->
truncate
(
text
.
size
());
auto
mapping
=
file
->
mmapWritable
(
0
,
text
.
size
());
auto
bytes
=
mapping
->
get
();
byte
*
target
=
bytes
.
begin
();
byte
*
firstModified
=
nullptr
;
text
.
visit
([
&
](
kj
::
ArrayPtr
<
const
char
>
text
)
{
if
(
firstModified
==
nullptr
)
{
if
(
memcmp
(
target
,
text
.
begin
(),
text
.
size
())
==
0
)
{
target
+=
text
.
size
();
return
;
}
firstModified
=
target
;
}
memcpy
(
target
,
text
.
begin
(),
text
.
size
());
target
+=
text
.
size
();
});
KJ_ASSERT
(
target
==
bytes
.
end
());
if
(
firstModified
==
nullptr
)
{
// The file is completely unchanged. But we should probably update the modification time
// anyway so that build systems don't get confused.
//
// TODO(cleanup): Add touch() to kj::FsNode.
#if _WIN32
FILETIME
time
;
GetSystemTimeAsFileTime
(
&
time
);
KJ_WIN32
(
SetFileTime
(
KJ_ASSERT_NONNULL
(
file
->
getWin32Handle
()),
NULL
,
&
time
,
&
time
));
#else
KJ_SYSCALL
(
futimes
(
KJ_ASSERT_NONNULL
(
file
->
getFd
()),
nullptr
));
#endif
}
else
{
mapping
->
changed
(
kj
::
arrayPtr
(
firstModified
,
bytes
.
end
()));
}
file
->
writeAll
(
text
.
flatten
());
}
kj
::
MainBuilder
::
Validity
run
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment