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
da17193a
Commit
da17193a
authored
Aug 23, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure compiler can accept source files over pipes by falling back to reading into a buffer.
parent
21a508bb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
12 deletions
+46
-12
module-loader.c++
c++/src/capnp/compiler/module-loader.c++
+23
-6
schema-parser.c++
c++/src/capnp/schema-parser.c++
+23
-6
No files found.
c++/src/capnp/compiler/module-loader.c++
View file @
da17193a
...
...
@@ -80,13 +80,30 @@ kj::Array<const char> mmapForRead(kj::StringPtr filename) {
struct
stat
stats
;
KJ_SYSCALL
(
fstat
(
fd
,
&
stats
));
const
void
*
mapping
=
mmap
(
NULL
,
stats
.
st_size
,
PROT_READ
,
MAP_SHARED
,
fd
,
0
);
if
(
mapping
==
MAP_FAILED
)
{
KJ_FAIL_SYSCALL
(
"mmap"
,
errno
,
filename
);
}
if
(
S_ISREG
(
stats
.
st_mode
))
{
// Regular file. Just mmap() it.
const
void
*
mapping
=
mmap
(
NULL
,
stats
.
st_size
,
PROT_READ
,
MAP_SHARED
,
fd
,
0
);
if
(
mapping
==
MAP_FAILED
)
{
KJ_FAIL_SYSCALL
(
"mmap"
,
errno
,
filename
);
}
return
kj
::
Array
<
const
char
>
(
reinterpret_cast
<
const
char
*>
(
mapping
),
stats
.
st_size
,
mmapDisposer
);
return
kj
::
Array
<
const
char
>
(
reinterpret_cast
<
const
char
*>
(
mapping
),
stats
.
st_size
,
mmapDisposer
);
}
else
{
// This could be a stream of some sort, like a pipe. Fall back to read().
// TODO(cleanup): This does a lot of copies. Not sure I care.
kj
::
Vector
<
char
>
data
(
8192
);
char
buffer
[
4096
];
for
(;;)
{
ssize_t
n
;
KJ_SYSCALL
(
n
=
read
(
fd
,
buffer
,
sizeof
(
buffer
)));
if
(
n
==
0
)
break
;
data
.
addAll
(
buffer
,
buffer
+
n
);
}
return
data
.
releaseAsArray
();
}
}
static
char
*
canonicalizePath
(
char
*
path
)
{
...
...
c++/src/capnp/schema-parser.c++
View file @
da17193a
...
...
@@ -350,13 +350,30 @@ kj::Array<const char> SchemaFile::DiskFileReader::read(kj::StringPtr path) const
struct
stat
stats
;
KJ_SYSCALL
(
fstat
(
fd
,
&
stats
));
const
void
*
mapping
=
mmap
(
NULL
,
stats
.
st_size
,
PROT_READ
,
MAP_SHARED
,
fd
,
0
);
if
(
mapping
==
MAP_FAILED
)
{
KJ_FAIL_SYSCALL
(
"mmap"
,
errno
,
path
);
}
if
(
S_ISREG
(
stats
.
st_mode
))
{
// Regular file. Just mmap() it.
const
void
*
mapping
=
mmap
(
NULL
,
stats
.
st_size
,
PROT_READ
,
MAP_SHARED
,
fd
,
0
);
if
(
mapping
==
MAP_FAILED
)
{
KJ_FAIL_SYSCALL
(
"mmap"
,
errno
,
path
);
}
return
kj
::
Array
<
const
char
>
(
reinterpret_cast
<
const
char
*>
(
mapping
),
stats
.
st_size
,
mmapDisposer
);
}
else
{
// This could be a stream of some sort, like a pipe. Fall back to read().
// TODO(cleanup): This does a lot of copies. Not sure I care.
kj
::
Vector
<
char
>
data
(
8192
);
char
buffer
[
4096
];
for
(;;)
{
ssize_t
n
;
KJ_SYSCALL
(
n
=
::
read
(
fd
,
buffer
,
sizeof
(
buffer
)));
if
(
n
==
0
)
break
;
data
.
addAll
(
buffer
,
buffer
+
n
);
}
return
kj
::
Array
<
const
char
>
(
reinterpret_cast
<
const
char
*>
(
mapping
),
stats
.
st_size
,
mmapDisposer
);
return
data
.
releaseAsArray
();
}
}
// -------------------------------------------------------------------
...
...
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