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
6d346575
Commit
6d346575
authored
Jun 03, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CHECK -> ASSERT
parent
20272ec5
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
99 additions
and
99 deletions
+99
-99
arena.c++
c++/src/capnproto/arena.c++
+2
-2
capnpc-capnp.c++
c++/src/capnproto/compiler/capnpc-capnp.c++
+2
-2
dynamic.c++
c++/src/capnproto/dynamic.c++
+25
-25
encoding-test.c++
c++/src/capnproto/encoding-test.c++
+1
-1
layout.c++
c++/src/capnproto/layout.c++
+13
-13
message.c++
c++/src/capnproto/message.c++
+3
-3
schema-loader.c++
c++/src/capnproto/schema-loader.c++
+3
-3
serialize-packed-test.c++
c++/src/capnproto/serialize-packed-test.c++
+2
-2
serialize-packed.c++
c++/src/capnproto/serialize-packed.c++
+8
-8
serialize-snappy-test.c++
c++/src/capnproto/serialize-snappy-test.c++
+2
-2
serialize-snappy.c++
c++/src/capnproto/serialize-snappy.c++
+3
-3
serialize-test.c++
c++/src/capnproto/serialize-test.c++
+1
-1
serialize.c++
c++/src/capnproto/serialize.c++
+1
-1
stringify.c++
c++/src/capnproto/stringify.c++
+1
-1
array-test.c++
c++/src/kj/array-test.c++
+3
-3
io.c++
c++/src/kj/io.c++
+2
-2
logging-test.c++
c++/src/kj/logging-test.c++
+9
-9
logging.h
c++/src/kj/logging.h
+14
-14
string.c++
c++/src/kj/string.c++
+4
-4
No files found.
c++/src/capnproto/arena.c++
View file @
6d346575
...
...
@@ -168,7 +168,7 @@ kj::ArrayPtr<const kj::ArrayPtr<const word>> BuilderArena::getSegmentsForOutput(
return
kj
::
arrayPtr
(
&
segment0ForOutput
,
1
);
}
}
else
{
D
CHECK
(
moreSegments
->
forOutput
.
size
()
==
moreSegments
->
builders
.
size
()
+
1
,
D
ASSERT
(
moreSegments
->
forOutput
.
size
()
==
moreSegments
->
builders
.
size
()
+
1
,
"moreSegments->forOutput wasn't resized correctly when the last builder was added."
,
moreSegments
->
forOutput
.
size
(),
moreSegments
->
builders
.
size
());
...
...
@@ -201,7 +201,7 @@ SegmentReader* BuilderArena::tryGetSegment(SegmentId id) {
}
void
BuilderArena
::
reportReadLimitReached
()
{
FAIL_RECOVERABLE_
CHECK
(
FAIL_RECOVERABLE_
ASSERT
(
"Read limit reached for BuilderArena, but it should have been unlimited."
)
{}
}
...
...
c++/src/capnproto/compiler/capnpc-capnp.c++
View file @
6d346575
...
...
@@ -128,8 +128,8 @@ void TextBlob::allocate(size_t textSize, size_t branchCount,
}
void
TextBlob
::
fill
(
char
*
textPos
,
Branch
*
branchesPos
)
{
CHECK
(
textPos
==
text
.
end
(),
textPos
-
text
.
end
());
CHECK
(
branchesPos
==
branches
.
end
(),
branchesPos
-
branches
.
end
());
ASSERT
(
textPos
==
text
.
end
(),
textPos
-
text
.
end
());
ASSERT
(
branchesPos
==
branches
.
end
(),
branchesPos
-
branches
.
end
());
}
template
<
typename
First
,
typename
...
Rest
>
...
...
c++/src/capnproto/dynamic.c++
View file @
6d346575
...
...
@@ -83,7 +83,7 @@ internal::FieldSize elementSizeFor(schema::Type::Body::Which elementType) {
case
schema
:
:
Type
::
Body
::
ENUM_TYPE
:
return
internal
::
FieldSize
::
TWO_BYTES
;
case
schema
:
:
Type
::
Body
::
STRUCT_TYPE
:
return
internal
::
FieldSize
::
INLINE_COMPOSITE
;
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
return
internal
::
FieldSize
::
POINTER
;
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
FAIL_
CHECK
(
"List(Object) not supported."
);
break
;
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
FAIL_
ASSERT
(
"List(Object) not supported."
);
break
;
}
// Unknown type. Treat it as zero-size.
...
...
@@ -255,7 +255,7 @@ Data::Builder DynamicUnion::Builder::initObjectAsData(Text::Reader name, uint si
StructSchema
::
Member
DynamicUnion
::
Builder
::
checkIsObject
()
{
KJ_IF_MAYBE
(
w
,
which
())
{
CHECK
(
w
->
getProto
().
getBody
().
which
()
==
schema
::
StructNode
::
Member
::
Body
::
FIELD_MEMBER
,
ASSERT
(
w
->
getProto
().
getBody
().
which
()
==
schema
::
StructNode
::
Member
::
Body
::
FIELD_MEMBER
,
"Unsupported union member type."
);
REQUIRE
(
w
->
getProto
().
getBody
().
getFieldMember
().
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected Object."
);
...
...
@@ -456,7 +456,7 @@ DynamicStruct::Builder DynamicStruct::Builder::getObject(
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
DynamicStruct
::
Builder
();
}
DynamicList
::
Builder
DynamicStruct
::
Builder
::
getObject
(
...
...
@@ -475,7 +475,7 @@ DynamicList::Builder DynamicStruct::Builder::getObject(
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
DynamicList
::
Builder
();
}
Text
::
Builder
DynamicStruct
::
Builder
::
getObjectAsText
(
StructSchema
::
Member
member
)
{
...
...
@@ -493,7 +493,7 @@ Text::Builder DynamicStruct::Builder::getObjectAsText(StructSchema::Member membe
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
Text
::
Builder
();
}
Data
::
Builder
DynamicStruct
::
Builder
::
getObjectAsData
(
StructSchema
::
Member
member
)
{
...
...
@@ -511,7 +511,7 @@ Data::Builder DynamicStruct::Builder::getObjectAsData(StructSchema::Member membe
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
Data
::
Builder
();
}
...
...
@@ -531,7 +531,7 @@ DynamicStruct::Builder DynamicStruct::Builder::initObject(
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
DynamicStruct
::
Builder
();
}
DynamicList
::
Builder
DynamicStruct
::
Builder
::
initObject
(
...
...
@@ -550,7 +550,7 @@ DynamicList::Builder DynamicStruct::Builder::initObject(
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
DynamicList
::
Builder
();
}
Text
::
Builder
DynamicStruct
::
Builder
::
initObjectAsText
(
StructSchema
::
Member
member
,
uint
size
)
{
...
...
@@ -568,7 +568,7 @@ Text::Builder DynamicStruct::Builder::initObjectAsText(StructSchema::Member memb
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
Text
::
Builder
();
}
Data
::
Builder
DynamicStruct
::
Builder
::
initObjectAsData
(
StructSchema
::
Member
member
,
uint
size
)
{
...
...
@@ -586,7 +586,7 @@ Data::Builder DynamicStruct::Builder::initObjectAsData(StructSchema::Member memb
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
Data
::
Builder
();
}
...
...
@@ -723,7 +723,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
}
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
FAIL_
CHECK
(
"Interfaces not yet implemented."
);
FAIL_
ASSERT
(
"Interfaces not yet implemented."
);
break
;
}
...
...
@@ -731,7 +731,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
nullptr
;
}
...
...
@@ -826,7 +826,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
}
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
FAIL_
CHECK
(
"Interfaces not yet implemented."
);
FAIL_
ASSERT
(
"Interfaces not yet implemented."
);
break
;
}
...
...
@@ -834,7 +834,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
return
nullptr
;
}
DynamicStruct
::
Builder
DynamicStruct
::
Builder
::
getObjectImpl
(
...
...
@@ -963,7 +963,7 @@ void DynamicStruct::Builder::setImpl(
}
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
FAIL_
CHECK
(
"Interfaces not yet implemented."
);
FAIL_
ASSERT
(
"Interfaces not yet implemented."
);
return
;
}
...
...
@@ -972,7 +972,7 @@ void DynamicStruct::Builder::setImpl(
}
}
FAIL_
CHECK
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
FAIL_
ASSERT
(
"switch() missing case."
,
(
uint
)
member
.
getProto
().
getBody
().
which
());
}
DynamicValue
::
Builder
DynamicStruct
::
Builder
::
initImpl
(
...
...
@@ -1109,7 +1109,7 @@ DynamicValue::Reader DynamicList::Reader::operator[](uint index) const {
reader
.
getObjectElement
(
index
*
ELEMENTS
)));
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
FAIL_RECOVERABLE_
CHECK
(
"Interfaces not implemented."
)
{}
FAIL_RECOVERABLE_
ASSERT
(
"Interfaces not implemented."
)
{}
return
nullptr
;
}
...
...
@@ -1167,11 +1167,11 @@ DynamicValue::Builder DynamicList::Builder::operator[](uint index) const {
schema
.
getEnumElementType
(),
builder
.
getDataElement
<
uint16_t
>
(
index
*
ELEMENTS
)));
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
FAIL_
CHECK
(
"List(Object) not supported."
);
FAIL_
ASSERT
(
"List(Object) not supported."
);
return
nullptr
;
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
FAIL_RECOVERABLE_
CHECK
(
"Interfaces not implemented."
)
{}
FAIL_RECOVERABLE_
ASSERT
(
"Interfaces not implemented."
)
{}
return
nullptr
;
}
...
...
@@ -1219,7 +1219,7 @@ void DynamicList::Builder::set(uint index, DynamicValue::Reader value) {
// Not supported for the same reason List<struct> doesn't support it -- the space for the
// element is already allocated, and if it's smaller than the input value the copy would
// have to be lossy.
FAIL_RECOVERABLE_
CHECK
(
"DynamicList of structs does not support set()."
);
FAIL_RECOVERABLE_
ASSERT
(
"DynamicList of structs does not support set()."
);
return
;
case
schema
:
:
Type
::
Body
::
ENUM_TYPE
:
{
...
...
@@ -1240,11 +1240,11 @@ void DynamicList::Builder::set(uint index, DynamicValue::Reader value) {
}
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
FAIL_RECOVERABLE_
CHECK
(
"List(Object) not supported."
);
FAIL_RECOVERABLE_
ASSERT
(
"List(Object) not supported."
);
return
;
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
FAIL_RECOVERABLE_
CHECK
(
"Interfaces not implemented."
)
{}
FAIL_RECOVERABLE_
ASSERT
(
"Interfaces not implemented."
)
{}
return
;
}
...
...
@@ -1296,7 +1296,7 @@ DynamicValue::Builder DynamicList::Builder::init(uint index, uint size) {
}
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
{
FAIL_
CHECK
(
"List(Object) not supported."
);
FAIL_
ASSERT
(
"List(Object) not supported."
);
return
nullptr
;
}
}
...
...
@@ -1332,10 +1332,10 @@ DynamicValue::Reader DynamicValue::Builder::asReader() {
case
ENUM
:
return
Reader
(
enumValue
);
case
STRUCT
:
return
Reader
(
structValue
.
asReader
());
case
UNION
:
return
Reader
(
unionValue
.
asReader
());
case
INTERFACE
:
FAIL_
CHECK
(
"Interfaces not implemented."
);
return
Reader
();
case
INTERFACE
:
FAIL_
ASSERT
(
"Interfaces not implemented."
);
return
Reader
();
case
OBJECT
:
return
Reader
(
objectValue
);
}
FAIL_
CHECK
(
"Missing switch case."
);
FAIL_
ASSERT
(
"Missing switch case."
);
return
Reader
();
}
...
...
c++/src/capnproto/encoding-test.c++
View file @
6d346575
...
...
@@ -279,7 +279,7 @@ UnionState initUnion(Func&& initializer) {
initializer
(
builder
.
getRoot
<
StructType
>
());
kj
::
ArrayPtr
<
const
word
>
segment
=
builder
.
getSegmentsForOutput
()[
0
];
CHECK
(
segment
.
size
()
>
2
,
segment
.
size
());
ASSERT
(
segment
.
size
()
>
2
,
segment
.
size
());
// Find the offset of the first set bit after the union discriminants.
int
offset
=
0
;
...
...
c++/src/capnproto/layout.c++
View file @
6d346575
...
...
@@ -338,7 +338,7 @@ struct WireHelpers {
break
;
}
case
WirePointer
:
:
RESERVED_3
:
FAIL_RECOVERABLE_
CHECK
(
"Don't know how to handle RESERVED_3."
)
{}
FAIL_RECOVERABLE_
ASSERT
(
"Don't know how to handle RESERVED_3."
)
{}
break
;
}
}
...
...
@@ -380,7 +380,7 @@ struct WireHelpers {
case
FieldSize
:
:
INLINE_COMPOSITE
:
{
WirePointer
*
elementTag
=
reinterpret_cast
<
WirePointer
*>
(
ptr
);
CHECK
(
elementTag
->
kind
()
==
WirePointer
::
STRUCT
,
ASSERT
(
elementTag
->
kind
()
==
WirePointer
::
STRUCT
,
"Don't know how to handle non-STRUCT inline composite."
);
WordCount
dataSize
=
elementTag
->
structRef
.
dataSize
.
get
();
WirePointerCount
pointerCount
=
elementTag
->
structRef
.
ptrCount
.
get
();
...
...
@@ -404,10 +404,10 @@ struct WireHelpers {
break
;
}
case
WirePointer
:
:
FAR
:
FAIL_RECOVERABLE_
CHECK
(
"Unexpected FAR pointer."
)
{}
FAIL_RECOVERABLE_
ASSERT
(
"Unexpected FAR pointer."
)
{}
break
;
case
WirePointer
:
:
RESERVED_3
:
FAIL_RECOVERABLE_
CHECK
(
"Don't know how to handle RESERVED_3."
)
{}
FAIL_RECOVERABLE_
ASSERT
(
"Don't know how to handle RESERVED_3."
)
{}
break
;
}
}
...
...
@@ -538,7 +538,7 @@ struct WireHelpers {
break
;
}
case
WirePointer
:
:
FAR
:
FAIL_RECOVERABLE_
CHECK
(
"Unexpected FAR pointer."
)
{
FAIL_RECOVERABLE_
ASSERT
(
"Unexpected FAR pointer."
)
{
break
;
}
break
;
...
...
@@ -640,7 +640,7 @@ struct WireHelpers {
const
word
*
srcElement
=
srcPtr
+
POINTER_SIZE_IN_WORDS
;
word
*
dstElement
=
dstPtr
+
POINTER_SIZE_IN_WORDS
;
CHECK
(
srcTag
->
kind
()
==
WirePointer
::
STRUCT
,
ASSERT
(
srcTag
->
kind
()
==
WirePointer
::
STRUCT
,
"INLINE_COMPOSITE of lists is not yet supported."
);
uint
n
=
srcTag
->
inlineCompositeListElementCount
()
/
ELEMENTS
;
...
...
@@ -689,7 +689,7 @@ struct WireHelpers {
// Darn, need a double-far.
SegmentBuilder
*
farSegment
=
srcSegment
->
getArena
()
->
getSegmentWithAvailable
(
2
*
WORDS
);
landingPad
=
reinterpret_cast
<
WirePointer
*>
(
farSegment
->
allocate
(
2
*
WORDS
));
D
CHECK
(
landingPad
!=
nullptr
,
D
ASSERT
(
landingPad
!=
nullptr
,
"getSegmentWithAvailable() returned segment without space available."
);
landingPad
[
0
].
setFar
(
false
,
srcSegment
->
getOffsetTo
(
src
->
target
()));
...
...
@@ -915,7 +915,7 @@ struct WireHelpers {
break
;
case
FieldSize
:
:
INLINE_COMPOSITE
:
FAIL_
CHECK
(
"Can't get here."
);
FAIL_
ASSERT
(
"Can't get here."
);
break
;
}
...
...
@@ -1148,11 +1148,11 @@ struct WireHelpers {
}
else
{
// If oldSize were POINTER or EIGHT_BYTES then the preferred size must be
// INLINE_COMPOSITE because any other compatible size would not require an upgrade.
CHECK
(
oldSize
<
FieldSize
::
EIGHT_BYTES
);
ASSERT
(
oldSize
<
FieldSize
::
EIGHT_BYTES
);
// If the preferred size were BIT then oldSize must be VOID, but we handled that case
// above.
CHECK
(
elementSize
.
preferredListEncoding
>=
FieldSize
::
BIT
);
ASSERT
(
elementSize
.
preferredListEncoding
>=
FieldSize
::
BIT
);
// OK, so the expected list elements are all data and between 1 byte and 1 word each,
// and the old element are data between 1 bit and 4 bytes. We're upgrading from one
...
...
@@ -1364,7 +1364,7 @@ struct WireHelpers {
case
32
:
elementSize
=
FieldSize
::
FOUR_BYTES
;
break
;
case
64
:
elementSize
=
FieldSize
::
EIGHT_BYTES
;
break
;
default
:
FAIL_
CHECK
(
"invalid list step size"
,
value
.
step
*
ELEMENTS
/
BITS
);
FAIL_
ASSERT
(
"invalid list step size"
,
value
.
step
*
ELEMENTS
/
BITS
);
break
;
}
...
...
@@ -2142,7 +2142,7 @@ StructReader ListReader::getStructElement(ElementCount index) const {
reinterpret_cast
<
const
WirePointer
*>
(
structData
+
structDataSize
/
BITS_PER_BYTE
);
// This check should pass if there are no bugs in the list pointer validation code.
D
CHECK
(
structPointerCount
==
0
*
POINTERS
||
D
ASSERT
(
structPointerCount
==
0
*
POINTERS
||
(
uintptr_t
)
structPointers
%
sizeof
(
WirePointer
)
==
0
,
"Pointer segment of struct list element not aligned."
);
...
...
@@ -2153,7 +2153,7 @@ StructReader ListReader::getStructElement(ElementCount index) const {
}
static
const
WirePointer
*
checkAlignment
(
const
void
*
ptr
)
{
D
CHECK
((
uintptr_t
)
ptr
%
sizeof
(
WirePointer
)
==
0
,
D
ASSERT
((
uintptr_t
)
ptr
%
sizeof
(
WirePointer
)
==
0
,
"Pointer segment of struct list element not aligned."
);
return
reinterpret_cast
<
const
WirePointer
*>
(
ptr
);
}
...
...
c++/src/capnproto/message.c++
View file @
6d346575
...
...
@@ -80,10 +80,10 @@ internal::SegmentBuilder* MessageBuilder::getRootSegment() {
WordCount
ptrSize
=
1
*
POINTERS
*
WORDS_PER_POINTER
;
internal
::
SegmentBuilder
*
segment
=
arena
()
->
getSegmentWithAvailable
(
ptrSize
);
CHECK
(
segment
->
getSegmentId
()
==
internal
::
SegmentId
(
0
),
ASSERT
(
segment
->
getSegmentId
()
==
internal
::
SegmentId
(
0
),
"First allocated word of new arena was not in segment ID 0."
);
word
*
location
=
segment
->
allocate
(
ptrSize
);
CHECK
(
location
==
segment
->
getPtrUnchecked
(
0
*
WORDS
),
ASSERT
(
location
==
segment
->
getPtrUnchecked
(
0
*
WORDS
),
"First allocated word of new arena was not the first word in its segment."
);
return
segment
;
}
...
...
@@ -161,7 +161,7 @@ MallocMessageBuilder::~MallocMessageBuilder() {
// Must zero first segment.
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
=
getSegmentsForOutput
();
if
(
segments
.
size
()
>
0
)
{
CHECK
(
segments
[
0
].
begin
()
==
firstSegment
,
ASSERT
(
segments
[
0
].
begin
()
==
firstSegment
,
"First segment in getSegmentsForOutput() is not the first segment allocated?"
);
memset
(
firstSegment
,
0
,
segments
[
0
].
size
()
*
sizeof
(
word
));
}
...
...
c++/src/capnproto/schema-loader.c++
View file @
6d346575
...
...
@@ -119,7 +119,7 @@ public:
for
(
auto
&
dep
:
dependencies
)
{
result
[
pos
++
]
=
dep
.
second
;
}
D
CHECK
(
pos
==
*
count
);
D
ASSERT
(
pos
==
*
count
);
return
result
;
}
...
...
@@ -131,7 +131,7 @@ public:
for
(
auto
&
member
:
members
)
{
result
[
pos
++
]
=
internal
::
RawSchema
::
MemberInfo
(
member
.
first
.
first
,
member
.
second
);
}
D
CHECK
(
pos
==
*
count
);
D
ASSERT
(
pos
==
*
count
);
return
result
;
}
...
...
@@ -934,7 +934,7 @@ private:
schema
::
Value
::
Reader
replacement
)
{
// Note that we test default compatibility only after testing type compatibility, and default
// values have already been validated as matching their types, so this should pass.
RECOVERABLE_
CHECK
(
value
.
getBody
().
which
()
==
replacement
.
getBody
().
which
())
{
RECOVERABLE_
ASSERT
(
value
.
getBody
().
which
()
==
replacement
.
getBody
().
which
())
{
compatibility
=
INCOMPATIBLE
;
return
;
}
...
...
c++/src/capnproto/serialize-packed-test.c++
View file @
6d346575
...
...
@@ -62,7 +62,7 @@ public:
}
size_t
read
(
void
*
buffer
,
size_t
minBytes
,
size_t
maxBytes
)
override
{
CHECK
(
maxBytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
ASSERT
(
maxBytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
size_t
amount
=
std
::
min
(
maxBytes
,
std
::
max
(
minBytes
,
preferredReadSize
));
memcpy
(
buffer
,
data
.
data
()
+
readPos
,
amount
);
readPos
+=
amount
;
...
...
@@ -70,7 +70,7 @@ public:
}
void
skip
(
size_t
bytes
)
override
{
CHECK
(
bytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
ASSERT
(
bytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
readPos
+=
bytes
;
}
...
...
c++/src/capnproto/serialize-packed.c++
View file @
6d346575
...
...
@@ -66,7 +66,7 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
for
(;;)
{
uint8_t
tag
;
D
CHECK
((
out
-
reinterpret_cast
<
uint8_t
*>
(
dst
))
%
sizeof
(
word
)
==
0
,
D
ASSERT
((
out
-
reinterpret_cast
<
uint8_t
*>
(
dst
))
%
sizeof
(
word
)
==
0
,
"Output pointer should always be aligned here."
);
if
(
BUFFER_REMAINING
<
10
)
{
...
...
@@ -122,7 +122,7 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
}
if
(
tag
==
0
)
{
D
CHECK
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
D
ASSERT
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
uint
runLength
=
*
in
++
*
sizeof
(
word
);
...
...
@@ -134,7 +134,7 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
out
+=
runLength
;
}
else
if
(
tag
==
0xffu
)
{
D
CHECK
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
D
ASSERT
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
uint
runLength
=
*
in
++
*
sizeof
(
word
);
...
...
@@ -177,8 +177,8 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
}
}
FAIL_
CHECK
(
"Can't get here."
);
return
0
;
// GCC knows FAIL_
CHECK
doesn't return, but Eclipse CDT still warns...
FAIL_
ASSERT
(
"Can't get here."
);
return
0
;
// GCC knows FAIL_
ASSERT
doesn't return, but Eclipse CDT still warns...
#undef REFRESH_BUFFER
}
...
...
@@ -248,7 +248,7 @@ void PackedInputStream::skip(size_t bytes) {
}
if
(
tag
==
0
)
{
D
CHECK
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
D
ASSERT
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
uint
runLength
=
*
in
++
*
sizeof
(
word
);
...
...
@@ -260,7 +260,7 @@ void PackedInputStream::skip(size_t bytes) {
bytes
-=
runLength
;
}
else
if
(
tag
==
0xffu
)
{
D
CHECK
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
D
ASSERT
(
BUFFER_REMAINING
>
0
,
"Should always have non-empty buffer here."
);
uint
runLength
=
*
in
++
*
sizeof
(
word
);
...
...
@@ -298,7 +298,7 @@ void PackedInputStream::skip(size_t bytes) {
}
}
FAIL_
CHECK
(
"Can't get here."
);
FAIL_
ASSERT
(
"Can't get here."
);
}
// -------------------------------------------------------------------
...
...
c++/src/capnproto/serialize-snappy-test.c++
View file @
6d346575
...
...
@@ -96,7 +96,7 @@ public:
}
size_t
read
(
void
*
buffer
,
size_t
minBytes
,
size_t
maxBytes
)
override
{
CHECK
(
maxBytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
ASSERT
(
maxBytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
size_t
amount
=
std
::
min
(
maxBytes
,
std
::
max
(
minBytes
,
preferredReadSize
));
memcpy
(
buffer
,
data
.
data
()
+
readPos
,
amount
);
readPos
+=
amount
;
...
...
@@ -104,7 +104,7 @@ public:
}
void
skip
(
size_t
bytes
)
override
{
CHECK
(
bytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
ASSERT
(
bytes
<=
data
.
size
()
-
readPos
,
"Overran end of stream."
);
readPos
+=
bytes
;
}
...
...
c++/src/capnproto/serialize-snappy.c++
View file @
6d346575
...
...
@@ -40,7 +40,7 @@ public:
// implements snappy::Source ---------------------------------------
size_t
Available
()
const
override
{
FAIL_
CHECK
(
"Snappy doesn't actually call this."
);
FAIL_
ASSERT
(
"Snappy doesn't actually call this."
);
return
0
;
}
...
...
@@ -121,7 +121,7 @@ void SnappyInputStream::refill() {
SnappyOutputStream
::
SnappyOutputStream
(
OutputStream
&
inner
,
kj
::
ArrayPtr
<
byte
>
buffer
,
kj
::
ArrayPtr
<
byte
>
compressedBuffer
)
:
inner
(
inner
)
{
D
CHECK
(
SNAPPY_COMPRESSED_BUFFER_SIZE
>=
snappy
::
MaxCompressedLength
(
snappy
::
kBlockSize
),
D
ASSERT
(
SNAPPY_COMPRESSED_BUFFER_SIZE
>=
snappy
::
MaxCompressedLength
(
snappy
::
kBlockSize
),
"snappy::MaxCompressedLength() changed?"
);
if
(
buffer
.
size
()
<
SNAPPY_BUFFER_SIZE
)
{
...
...
@@ -159,7 +159,7 @@ void SnappyOutputStream::flush() {
snappy
::
UncheckedByteArraySink
sink
(
reinterpret_cast
<
char
*>
(
compressedBuffer
.
begin
()));
size_t
n
=
snappy
::
Compress
(
&
source
,
&
sink
);
CHECK
(
n
<=
compressedBuffer
.
size
(),
ASSERT
(
n
<=
compressedBuffer
.
size
(),
"Critical security bug: Snappy compression overran its output buffer."
);
inner
.
write
(
compressedBuffer
.
begin
(),
n
);
...
...
c++/src/capnproto/serialize-test.c++
View file @
6d346575
...
...
@@ -104,7 +104,7 @@ public:
~
TestInputStream
()
{}
size_t
read
(
void
*
buffer
,
size_t
minBytes
,
size_t
maxBytes
)
override
{
CHECK
(
maxBytes
<=
size_t
(
end
-
pos
),
"Overran end of stream."
);
ASSERT
(
maxBytes
<=
size_t
(
end
-
pos
),
"Overran end of stream."
);
size_t
amount
=
lazy
?
minBytes
:
maxBytes
;
memcpy
(
buffer
,
pos
,
amount
);
pos
+=
amount
;
...
...
c++/src/capnproto/serialize.c++
View file @
6d346575
...
...
@@ -122,7 +122,7 @@ kj::Array<word> messageToFlatArray(kj::ArrayPtr<const kj::ArrayPtr<const word>>
dst
+=
segment
.
size
();
}
D
CHECK
(
dst
==
result
.
end
(),
"Buffer overrun/underrun bug in code above."
);
D
ASSERT
(
dst
==
result
.
end
(),
"Buffer overrun/underrun bug in code above."
);
return
kj
::
mv
(
result
);
}
...
...
c++/src/capnproto/stringify.c++
View file @
6d346575
...
...
@@ -162,7 +162,7 @@ static void print(std::ostream& os, DynamicValue::Reader value,
break
;
}
case
DynamicValue
:
:
INTERFACE
:
FAIL_RECOVERABLE_
CHECK
(
"Don't know how to print interfaces."
)
{}
FAIL_RECOVERABLE_
ASSERT
(
"Don't know how to print interfaces."
)
{}
break
;
case
DynamicValue
:
:
OBJECT
:
os
<<
"(opaque object)"
;
...
...
c++/src/kj/array-test.c++
View file @
6d346575
...
...
@@ -33,11 +33,11 @@ namespace {
struct
TestObject
{
TestObject
()
{
index
=
count
;
CHECK
(
index
!=
throwAt
);
ASSERT
(
index
!=
throwAt
);
++
count
;
}
TestObject
(
const
TestObject
&
other
)
{
CHECK
(
other
.
index
!=
throwAt
);
ASSERT
(
other
.
index
!=
throwAt
);
index
=
-
1
;
copiedCount
++
;
}
...
...
@@ -47,7 +47,7 @@ struct TestObject {
}
else
{
--
count
;
EXPECT_EQ
(
index
,
count
);
CHECK
(
count
!=
throwAt
);
ASSERT
(
count
!=
throwAt
);
}
}
...
...
c++/src/kj/io.c++
View file @
6d346575
...
...
@@ -257,7 +257,7 @@ void FdOutputStream::write(const void* buffer, size_t size) {
while
(
size
>
0
)
{
ssize_t
n
=
SYSCALL
(
::
write
(
fd
,
pos
,
size
),
fd
);
CHECK
(
n
>
0
,
"write() returned zero."
);
ASSERT
(
n
>
0
,
"write() returned zero."
);
pos
+=
n
;
size
-=
n
;
}
...
...
@@ -281,7 +281,7 @@ void FdOutputStream::write(ArrayPtr<const ArrayPtr<const byte>> pieces) {
while
(
current
<
iov
.
end
())
{
ssize_t
n
=
SYSCALL
(
::
writev
(
fd
,
current
,
iov
.
end
()
-
current
),
fd
);
CHECK
(
n
>
0
,
"writev() returned zero."
);
ASSERT
(
n
>
0
,
"writev() returned zero."
);
while
(
static_cast
<
size_t
>
(
n
)
>=
current
->
iov_len
)
{
n
-=
current
->
iov_len
;
...
...
c++/src/kj/logging-test.c++
View file @
6d346575
...
...
@@ -101,24 +101,24 @@ TEST(Logging, Log) {
mockCallback
.
text
);
mockCallback
.
text
.
clear
();
CHECK
(
1
==
1
);
EXPECT_THROW
(
CHECK
(
1
==
2
),
MockException
);
line
=
__LINE__
;
ASSERT
(
1
==
1
);
EXPECT_THROW
(
ASSERT
(
1
==
2
),
MockException
);
line
=
__LINE__
;
EXPECT_EQ
(
"fatal exception: "
+
fileLine
(
__FILE__
,
line
)
+
": bug in code: expected "
"1 == 2
\n
"
,
mockCallback
.
text
);
mockCallback
.
text
.
clear
();
RECOVERABLE_
CHECK
(
1
==
1
)
{
RECOVERABLE_
ASSERT
(
1
==
1
)
{
ADD_FAILURE
()
<<
"Shouldn't call recovery code when check passes."
;
};
bool
recovered
=
false
;
RECOVERABLE_
CHECK
(
1
==
2
,
"1 is not 2"
)
{
recovered
=
true
;
}
line
=
__LINE__
;
RECOVERABLE_
ASSERT
(
1
==
2
,
"1 is not 2"
)
{
recovered
=
true
;
}
line
=
__LINE__
;
EXPECT_EQ
(
"recoverable exception: "
+
fileLine
(
__FILE__
,
line
)
+
": bug in code: expected "
"1 == 2; 1 is not 2
\n
"
,
mockCallback
.
text
);
EXPECT_TRUE
(
recovered
);
mockCallback
.
text
.
clear
();
EXPECT_THROW
(
CHECK
(
1
==
2
,
i
,
"hi"
,
str
),
MockException
);
line
=
__LINE__
;
EXPECT_THROW
(
ASSERT
(
1
==
2
,
i
,
"hi"
,
str
),
MockException
);
line
=
__LINE__
;
EXPECT_EQ
(
"fatal exception: "
+
fileLine
(
__FILE__
,
line
)
+
": bug in code: expected "
"1 == 2; i = 123; hi; str = foo
\n
"
,
mockCallback
.
text
);
mockCallback
.
text
.
clear
();
...
...
@@ -128,7 +128,7 @@ TEST(Logging, Log) {
"1 == 2; i = 123; hi; str = foo
\n
"
,
mockCallback
.
text
);
mockCallback
.
text
.
clear
();
EXPECT_THROW
(
CHECK
(
false
,
"foo"
),
MockException
);
line
=
__LINE__
;
EXPECT_THROW
(
ASSERT
(
false
,
"foo"
),
MockException
);
line
=
__LINE__
;
EXPECT_EQ
(
"fatal exception: "
+
fileLine
(
__FILE__
,
line
)
+
": bug in code: foo
\n
"
,
mockCallback
.
text
);
mockCallback
.
text
.
clear
();
...
...
@@ -164,7 +164,7 @@ TEST(Logging, Context) {
{
CONTEXT
(
"foo"
);
int
cline
=
__LINE__
;
EXPECT_THROW
(
FAIL_
CHECK
(
"bar"
),
MockException
);
int
line
=
__LINE__
;
EXPECT_THROW
(
FAIL_
ASSERT
(
"bar"
),
MockException
);
int
line
=
__LINE__
;
EXPECT_EQ
(
"fatal exception: "
+
fileLine
(
__FILE__
,
cline
)
+
": context: foo
\n
"
+
fileLine
(
__FILE__
,
line
)
+
": bug in code: bar
\n
"
,
...
...
@@ -175,7 +175,7 @@ TEST(Logging, Context) {
int
i
=
123
;
const
char
*
str
=
"qux"
;
CONTEXT
(
"baz"
,
i
,
"corge"
,
str
);
int
cline2
=
__LINE__
;
EXPECT_THROW
(
FAIL_
CHECK
(
"bar"
),
MockException
);
line
=
__LINE__
;
EXPECT_THROW
(
FAIL_
ASSERT
(
"bar"
),
MockException
);
line
=
__LINE__
;
EXPECT_EQ
(
"fatal exception: "
+
fileLine
(
__FILE__
,
cline
)
+
": context: foo
\n
"
+
fileLine
(
__FILE__
,
cline2
)
+
": context: baz; i = 123; corge; str = qux
\n
"
...
...
@@ -186,7 +186,7 @@ TEST(Logging, Context) {
{
CONTEXT
(
"grault"
);
int
cline2
=
__LINE__
;
EXPECT_THROW
(
FAIL_
CHECK
(
"bar"
),
MockException
);
line
=
__LINE__
;
EXPECT_THROW
(
FAIL_
ASSERT
(
"bar"
),
MockException
);
line
=
__LINE__
;
EXPECT_EQ
(
"fatal exception: "
+
fileLine
(
__FILE__
,
cline
)
+
": context: foo
\n
"
+
fileLine
(
__FILE__
,
cline2
)
+
": context: grault
\n
"
...
...
c++/src/kj/logging.h
View file @
6d346575
...
...
@@ -24,7 +24,7 @@
// This file declares convenient macros for debug logging and error handling. The macros make
// it excessively easy to extract useful context information from code. Example:
//
//
CHECK
(a == b, a, b, "a and b must be the same.");
//
ASSERT
(a == b, a, b, "a and b must be the same.");
//
// On failure, this will throw an exception whose description looks like:
//
...
...
@@ -39,19 +39,19 @@
// `FATAL`. If the severity is not higher than the global logging threshold, nothing will be
// written and in fact the log message won't even be evaluated.
//
// * `
CHECK
(condition, ...)`: Throws an exception if `condition` is false, or aborts if exceptions
// * `
ASSERT
(condition, ...)`: Throws an exception if `condition` is false, or aborts if exceptions
// are disabled. This macro should be used to check for bugs in the surrounding code and its
// dependencies, but NOT to check for invalid input.
//
// * `REQUIRE(condition, ...)`: Like `
CHECK
` but used to check preconditions -- e.g. to validate
// * `REQUIRE(condition, ...)`: Like `
ASSERT
` but used to check preconditions -- e.g. to validate
// parameters passed from a caller. A failure indicates that the caller is buggy.
//
// * `RECOVERABLE_
CHECK(condition, ...) { ... }`: Like `CHECK
` except that if exceptions are
// * `RECOVERABLE_
ASSERT(condition, ...) { ... }`: Like `ASSERT
` except that if exceptions are
// disabled, instead of aborting, the following code block will be executed. This block should
// do whatever it can to fill in dummy values so that the code can continue executing, even if
// this means the eventual output will be garbage.
//
// * `RECOVERABLE_REQUIRE(condition, ...) { ... }`: Like `RECOVERABLE_
CHECK
` and `REQUIRE`.
// * `RECOVERABLE_REQUIRE(condition, ...) { ... }`: Like `RECOVERABLE_
ASSERT
` and `REQUIRE`.
//
// * `VALIDATE_INPUT(condition, ...) { ... }`: Like `RECOVERABLE_PRECOND` but used to validate
// input that may have come from the user or some other untrusted source. Recoverability is
...
...
@@ -64,7 +64,7 @@
//
// int fd = SYSCALL(open(filename, O_RDONLY), filename);
//
// * `RECOVERABLE_SYSCALL(code, ...) { ... }`: Like `RECOVERABLE_
CHECK
` and `SYSCALL`. Note that
// * `RECOVERABLE_SYSCALL(code, ...) { ... }`: Like `RECOVERABLE_
ASSERT
` and `SYSCALL`. Note that
// unfortunately this macro cannot return a value since it implements control flow, but you can
// assign to a variable *inside* the parameter instead:
//
...
...
@@ -226,14 +226,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
::kj::Exception::Nature::nature, #cond, #__VA_ARGS__, ##__VA_ARGS__), false) {} \
else
#define
CHECK
(...) FAULT(LOCAL_BUG, __VA_ARGS__)
#define RECOVERABLE_
CHECK
(...) RECOVERABLE_FAULT(LOCAL_BUG, __VA_ARGS__)
#define
ASSERT
(...) FAULT(LOCAL_BUG, __VA_ARGS__)
#define RECOVERABLE_
ASSERT
(...) RECOVERABLE_FAULT(LOCAL_BUG, __VA_ARGS__)
#define REQUIRE(...) FAULT(PRECONDITION, __VA_ARGS__)
#define RECOVERABLE_REQUIRE(...) RECOVERABLE_FAULT(PRECONDITION, __VA_ARGS__)
#define VALIDATE_INPUT(...) RECOVERABLE_FAULT(INPUT, __VA_ARGS__)
#define FAIL_
CHECK(...) CHECK
(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_
CHECK(...) RECOVERABLE_CHECK
(false, ##__VA_ARGS__)
#define FAIL_
ASSERT(...) ASSERT
(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_
ASSERT(...) RECOVERABLE_ASSERT
(false, ##__VA_ARGS__)
#define FAIL_REQUIRE(...) REQUIRE(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_REQUIRE(...) RECOVERABLE_REQUIRE(false, ##__VA_ARGS__)
#define FAIL_VALIDATE_INPUT(...) VALIDATE_INPUT(false, ##__VA_ARGS__)
...
...
@@ -272,14 +272,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
#ifdef NDEBUG
#define DLOG(...) do {} while (false)
#define D
CHECK
(...) do {} while (false)
#define RECOVERABLE_D
CHECK
(...) do {} while (false)
#define D
ASSERT
(...) do {} while (false)
#define RECOVERABLE_D
ASSERT
(...) do {} while (false)
#define DREQUIRE(...) do {} while (false)
#define RECOVERABLE_DREQUIRE(...) do {} while (false)
#else
#define DLOG LOG
#define D
CHECK CHECK
#define RECOVERABLE_D
CHECK RECOVERABLE_CHECK
#define D
ASSERT ASSERT
#define RECOVERABLE_D
ASSERT RECOVERABLE_ASSERT
#define DREQUIRE REQUIRE
#define RECOVERABLE_DREQUIRE RECOVERABLE_REQUIRE
#endif
...
...
c++/src/kj/string.c++
View file @
6d346575
...
...
@@ -232,7 +232,7 @@ char* DoubleToBuffer(double value, char* buffer) {
// The snprintf should never overflow because the buffer is significantly
// larger than the precision we asked for.
D
CHECK
(
snprintf_result
>
0
&&
snprintf_result
<
kDoubleToBufferSize
);
D
ASSERT
(
snprintf_result
>
0
&&
snprintf_result
<
kDoubleToBufferSize
);
// We need to make parsed_value volatile in order to force the compiler to
// write it out to the stack. Otherwise, it may keep the value in a
...
...
@@ -246,7 +246,7 @@ char* DoubleToBuffer(double value, char* buffer) {
snprintf
(
buffer
,
kDoubleToBufferSize
,
"%.*g"
,
DBL_DIG
+
2
,
value
);
// Should never overflow; see above.
D
CHECK
(
snprintf_result
>
0
&&
snprintf_result
<
kDoubleToBufferSize
);
D
ASSERT
(
snprintf_result
>
0
&&
snprintf_result
<
kDoubleToBufferSize
);
}
DelocalizeRadix
(
buffer
);
...
...
@@ -288,7 +288,7 @@ char* FloatToBuffer(float value, char* buffer) {
// The snprintf should never overflow because the buffer is significantly
// larger than the precision we asked for.
D
CHECK
(
snprintf_result
>
0
&&
snprintf_result
<
kFloatToBufferSize
);
D
ASSERT
(
snprintf_result
>
0
&&
snprintf_result
<
kFloatToBufferSize
);
float
parsed_value
;
if
(
!
safe_strtof
(
buffer
,
&
parsed_value
)
||
parsed_value
!=
value
)
{
...
...
@@ -296,7 +296,7 @@ char* FloatToBuffer(float value, char* buffer) {
snprintf
(
buffer
,
kFloatToBufferSize
,
"%.*g"
,
FLT_DIG
+
2
,
value
);
// Should never overflow; see above.
D
CHECK
(
snprintf_result
>
0
&&
snprintf_result
<
kFloatToBufferSize
);
D
ASSERT
(
snprintf_result
>
0
&&
snprintf_result
<
kFloatToBufferSize
);
}
DelocalizeRadix
(
buffer
);
...
...
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