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
20272ec5
Commit
20272ec5
authored
Jun 01, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PRECOND -> REQUIRE
parent
5b65179c
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
166 additions
and
169 deletions
+166
-169
capnproto-common.h
c++/src/capnproto/benchmark/capnproto-common.h
+1
-1
blob.h
c++/src/capnproto/blob.h
+5
-5
capnpc-capnp.c++
c++/src/capnproto/compiler/capnpc-capnp.c++
+9
-9
dynamic.c++
c++/src/capnproto/dynamic.c++
+67
-67
layout.c++
c++/src/capnproto/layout.c++
+14
-14
message.c++
c++/src/capnproto/message.c++
+4
-4
schema-loader.c++
c++/src/capnproto/schema-loader.c++
+4
-4
schema.c++
c++/src/capnproto/schema.c++
+18
-18
serialize-packed.c++
c++/src/capnproto/serialize-packed.c++
+3
-3
serialize.c++
c++/src/capnproto/serialize.c++
+2
-2
array.h
c++/src/kj/array.h
+6
-6
common.c++
c++/src/kj/common.c++
+1
-1
common.h
c++/src/kj/common.h
+10
-13
exception.c++
c++/src/kj/exception.c++
+1
-1
io.c++
c++/src/kj/io.c++
+1
-1
logging-test.c++
c++/src/kj/logging-test.c++
+1
-1
logging.h
c++/src/kj/logging.h
+10
-10
string.h
c++/src/kj/string.h
+1
-1
c++-header.mustache
compiler/src/c++-header.mustache
+8
-8
No files found.
c++/src/capnproto/benchmark/capnproto-common.h
View file @
20272ec5
...
...
@@ -181,7 +181,7 @@ struct UseScratch {
word
*
words
;
ScratchSpace
()
{
PRECOND
(
scratchCounter
<
6
,
"Too many scratch spaces needed at once."
);
REQUIRE
(
scratchCounter
<
6
,
"Too many scratch spaces needed at once."
);
words
=
scratchSpace
+
scratchCounter
++
*
SCRATCH_SIZE
;
}
~
ScratchSpace
()
{
...
...
c++/src/capnproto/blob.h
View file @
20272ec5
...
...
@@ -76,7 +76,7 @@ public:
inline
const
char
operator
[](
uint
index
)
const
{
return
bytes
[
index
];
}
inline
Reader
slice
(
uint
start
,
uint
end
)
const
{
KJ_I
NLINE_DPRECOND
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds slice."
);
KJ_I
REQUIRE
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds slice."
);
return
Reader
(
bytes
+
start
,
end
-
start
);
}
...
...
@@ -121,13 +121,13 @@ public:
inline
Reader
(
const
char
*
text
)
:
Data
::
Reader
(
text
,
strlen
(
text
))
{}
inline
Reader
(
char
*
text
)
:
Data
::
Reader
(
text
,
strlen
(
text
))
{}
inline
Reader
(
const
char
*
text
,
uint
size
)
:
Data
::
Reader
(
text
,
size
)
{
KJ_I
NLINE_DPRECOND
(
text
[
size
]
==
'\0'
,
"Text must be NUL-terminated."
);
KJ_I
REQUIRE
(
text
[
size
]
==
'\0'
,
"Text must be NUL-terminated."
);
}
template
<
typename
T
>
inline
Reader
(
const
T
&
other
)
:
Data
::
Reader
(
other
.
c_str
(),
other
.
size
())
{
// Primarily intended for converting from std::string.
KJ_I
NLINE_DPRECOND
(
data
()[
size
()]
==
'\0'
,
"Text must be NUL-terminated."
);
KJ_I
REQUIRE
(
data
()[
size
()]
==
'\0'
,
"Text must be NUL-terminated."
);
}
inline
const
char
*
c_str
()
const
{
return
data
();
}
...
...
@@ -164,7 +164,7 @@ public:
inline
char
&
operator
[](
uint
index
)
const
{
return
bytes
[
index
];
}
inline
Builder
slice
(
uint
start
,
uint
end
)
const
{
KJ_I
NLINE_DPRECOND
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds slice."
);
KJ_I
REQUIRE
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds slice."
);
return
Builder
(
bytes
+
start
,
end
-
start
);
}
...
...
@@ -183,7 +183,7 @@ public:
template
<
typename
T
>
inline
void
copyFrom
(
const
T
&
other
)
const
{
KJ_I
NLINE_DPRECOND
(
size
()
==
other
.
size
(),
"Sizes must match to copy."
);
KJ_I
REQUIRE
(
size
()
==
other
.
size
(),
"Sizes must match to copy."
);
memcpy
(
bytes
,
other
.
data
(),
other
.
size
());
}
inline
void
copyFrom
(
const
void
*
other
)
const
{
...
...
c++/src/capnproto/compiler/capnpc-capnp.c++
View file @
20272ec5
...
...
@@ -217,7 +217,7 @@ Text::Reader getUnqualifiedName(Schema schema) {
return
nested
.
getName
();
}
}
FAIL_
PRECOND
(
"A schema Node's supposed scope did not contain the node as a NestedNode."
);
FAIL_
REQUIRE
(
"A schema Node's supposed scope did not contain the node as a NestedNode."
);
return
"(?)"
;
}
...
...
@@ -365,22 +365,22 @@ TextBlob genValue(schema::Type::Reader type, schema::Value::Reader value, Schema
case
schema
:
:
Value
::
Body
::
TEXT_VALUE
:
return
text
(
DynamicValue
::
Reader
(
body
.
getTextValue
()));
case
schema
:
:
Value
::
Body
::
DATA_VALUE
:
return
text
(
DynamicValue
::
Reader
(
body
.
getDataValue
()));
case
schema
:
:
Value
::
Body
::
LIST_VALUE
:
{
PRECOND
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
LIST_TYPE
,
"type/value mismatch"
);
REQUIRE
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
LIST_TYPE
,
"type/value mismatch"
);
auto
value
=
body
.
getListValue
<
DynamicList
>
(
ListSchema
::
of
(
type
.
getBody
().
getListType
(),
scope
));
return
text
(
value
);
}
case
schema
:
:
Value
::
Body
::
ENUM_VALUE
:
{
PRECOND
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
ENUM_TYPE
,
"type/value mismatch"
);
REQUIRE
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
ENUM_TYPE
,
"type/value mismatch"
);
auto
enumNode
=
scope
.
getDependency
(
type
.
getBody
().
getEnumType
()).
asEnum
().
getProto
();
auto
enumType
=
enumNode
.
getBody
().
getEnumNode
();
auto
enumerants
=
enumType
.
getEnumerants
();
PRECOND
(
body
.
getEnumValue
()
<
enumerants
.
size
(),
REQUIRE
(
body
.
getEnumValue
()
<
enumerants
.
size
(),
"Enum value out-of-range."
,
body
.
getEnumValue
(),
enumNode
.
getDisplayName
());
return
text
(
enumerants
[
body
.
getEnumValue
()].
getName
());
}
case
schema
:
:
Value
::
Body
::
STRUCT_VALUE
:
{
PRECOND
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
STRUCT_TYPE
,
"type/value mismatch"
);
REQUIRE
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
STRUCT_TYPE
,
"type/value mismatch"
);
auto
value
=
body
.
getStructValue
<
DynamicStruct
>
(
scope
.
getDependency
(
type
.
getBody
().
getStructType
()).
asStruct
());
return
text
(
value
);
...
...
@@ -400,7 +400,7 @@ TextBlob genAnnotation(schema::Annotation::Reader annotation,
const
char
*
prefix
=
" "
,
const
char
*
suffix
=
""
)
{
auto
decl
=
schemaLoader
.
get
(
annotation
.
getId
());
auto
body
=
decl
.
getProto
().
getBody
();
PRECOND
(
body
.
which
()
==
schema
::
Node
::
Body
::
ANNOTATION_NODE
);
REQUIRE
(
body
.
which
()
==
schema
::
Node
::
Body
::
ANNOTATION_NODE
);
auto
annDecl
=
body
.
getAnnotationNode
();
return
text
(
prefix
,
"$"
,
nodeName
(
decl
,
scope
),
"("
,
...
...
@@ -468,12 +468,12 @@ TextBlob genDecl(Schema schema, Text::Reader name, uint64_t scopeId, Indent inde
auto
proto
=
schema
.
getProto
();
if
(
proto
.
getScopeId
()
!=
scopeId
)
{
// This appears to be an alias for something declared elsewhere.
FAIL_
PRECOND
(
"Aliases not implemented."
);
FAIL_
REQUIRE
(
"Aliases not implemented."
);
}
switch
(
proto
.
getBody
().
which
())
{
case
schema
:
:
Node
::
Body
::
FILE_NODE
:
FAIL_
PRECOND
(
"Encountered nested file node."
);
FAIL_
REQUIRE
(
"Encountered nested file node."
);
break
;
case
schema
:
:
Node
::
Body
::
STRUCT_NODE
:
{
auto
body
=
proto
.
getBody
().
getStructNode
();
...
...
@@ -578,7 +578,7 @@ TextBlob genNestedDecls(Schema schema, Indent indent) {
TextBlob
genFile
(
Schema
file
)
{
auto
proto
=
file
.
getProto
();
auto
body
=
proto
.
getBody
();
PRECOND
(
body
.
which
()
==
schema
::
Node
::
Body
::
FILE_NODE
,
"Expected a file node."
,
REQUIRE
(
body
.
which
()
==
schema
::
Node
::
Body
::
FILE_NODE
,
"Expected a file node."
,
(
uint
)
body
.
which
());
return
text
(
...
...
c++/src/capnproto/dynamic.c++
View file @
20272ec5
...
...
@@ -112,7 +112,7 @@ kj::Maybe<EnumSchema::Enumerant> DynamicEnum::getEnumerant() {
}
uint16_t
DynamicEnum
::
asImpl
(
uint64_t
requestedTypeId
)
{
RECOVERABLE_
PRECOND
(
requestedTypeId
==
schema
.
getProto
().
getId
(),
RECOVERABLE_
REQUIRE
(
requestedTypeId
==
schema
.
getProto
().
getId
(),
"Type mismatch in DynamicEnum.as()."
)
{
// use it anyway
}
...
...
@@ -125,7 +125,7 @@ DynamicStruct::Reader DynamicObject::as(StructSchema schema) {
if
(
reader
.
kind
==
internal
::
ObjectKind
::
NULL_POINTER
)
{
return
DynamicStruct
::
Reader
(
schema
,
internal
::
StructReader
());
}
RECOVERABLE_
PRECOND
(
reader
.
kind
==
internal
::
ObjectKind
::
STRUCT
,
"Object is not a struct."
)
{
RECOVERABLE_
REQUIRE
(
reader
.
kind
==
internal
::
ObjectKind
::
STRUCT
,
"Object is not a struct."
)
{
// Return default struct.
return
DynamicStruct
::
Reader
(
schema
,
internal
::
StructReader
());
}
...
...
@@ -136,7 +136,7 @@ DynamicList::Reader DynamicObject::as(ListSchema schema) {
if
(
reader
.
kind
==
internal
::
ObjectKind
::
NULL_POINTER
)
{
return
DynamicList
::
Reader
(
schema
,
internal
::
ListReader
());
}
RECOVERABLE_
PRECOND
(
reader
.
kind
==
internal
::
ObjectKind
::
LIST
,
"Object is not a list."
)
{
RECOVERABLE_
REQUIRE
(
reader
.
kind
==
internal
::
ObjectKind
::
LIST
,
"Object is not a list."
)
{
// Return empty list.
return
DynamicList
::
Reader
(
schema
,
internal
::
ListReader
());
}
...
...
@@ -257,27 +257,27 @@ StructSchema::Member DynamicUnion::Builder::checkIsObject() {
KJ_IF_MAYBE
(
w
,
which
())
{
CHECK
(
w
->
getProto
().
getBody
().
which
()
==
schema
::
StructNode
::
Member
::
Body
::
FIELD_MEMBER
,
"Unsupported union member type."
);
PRECOND
(
w
->
getProto
().
getBody
().
getFieldMember
().
getType
().
getBody
().
which
()
==
REQUIRE
(
w
->
getProto
().
getBody
().
getFieldMember
().
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected Object."
);
return
*
w
;
}
else
{
FAIL_
PRECOND
(
"Can't get() unknown union value."
);
FAIL_
REQUIRE
(
"Can't get() unknown union value."
);
}
}
void
DynamicUnion
::
Builder
::
setDiscriminant
(
StructSchema
::
Member
member
)
{
KJ_IF_MAYBE
(
containingUnion
,
member
.
getContainingUnion
())
{
PRECOND
(
*
containingUnion
==
schema
,
"`member` is not a member of this union."
);
REQUIRE
(
*
containingUnion
==
schema
,
"`member` is not a member of this union."
);
builder
.
setDataField
<
uint16_t
>
(
schema
.
getProto
().
getBody
().
getUnionMember
().
getDiscriminantOffset
()
*
ELEMENTS
,
member
.
getIndex
());
}
else
{
FAIL_
PRECOND
(
"`member` is not a member of this union."
);
FAIL_
REQUIRE
(
"`member` is not a member of this union."
);
}
}
void
DynamicUnion
::
Builder
::
setObjectDiscriminant
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getProto
().
getBody
().
getFieldMember
().
getType
().
getBody
().
which
()
==
REQUIRE
(
member
.
getProto
().
getBody
().
getFieldMember
().
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected Object."
);
setDiscriminant
(
member
);
}
...
...
@@ -285,16 +285,16 @@ void DynamicUnion::Builder::setObjectDiscriminant(StructSchema::Member member) {
// =======================================================================================
DynamicValue
::
Reader
DynamicStruct
::
Reader
::
get
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
return
getImpl
(
reader
,
member
);
}
DynamicValue
::
Builder
DynamicStruct
::
Builder
::
get
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
return
getImpl
(
builder
,
member
);
}
bool
DynamicStruct
::
Reader
::
has
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
auto
body
=
member
.
getProto
().
getBody
();
switch
(
body
.
which
())
{
...
...
@@ -360,7 +360,7 @@ bool DynamicStruct::Reader::has(StructSchema::Member member) {
return
false
;
}
bool
DynamicStruct
::
Builder
::
has
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
auto
body
=
member
.
getProto
().
getBody
();
switch
(
body
.
which
())
{
...
...
@@ -427,30 +427,30 @@ bool DynamicStruct::Builder::has(StructSchema::Member member) {
}
void
DynamicStruct
::
Builder
::
set
(
StructSchema
::
Member
member
,
DynamicValue
::
Reader
value
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
return
setImpl
(
builder
,
member
,
value
);
}
DynamicValue
::
Builder
DynamicStruct
::
Builder
::
init
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
return
initImpl
(
builder
,
member
);
}
DynamicValue
::
Builder
DynamicStruct
::
Builder
::
init
(
StructSchema
::
Member
member
,
uint
size
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
return
initImpl
(
builder
,
member
,
size
);
}
DynamicStruct
::
Builder
DynamicStruct
::
Builder
::
getObject
(
StructSchema
::
Member
member
,
StructSchema
type
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
break
;
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
getObjectImpl
(
builder
,
member
,
type
);
}
...
...
@@ -461,15 +461,15 @@ DynamicStruct::Builder DynamicStruct::Builder::getObject(
}
DynamicList
::
Builder
DynamicStruct
::
Builder
::
getObject
(
StructSchema
::
Member
member
,
ListSchema
type
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
break
;
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
getObjectImpl
(
builder
,
member
,
type
);
}
...
...
@@ -479,15 +479,15 @@ DynamicList::Builder DynamicStruct::Builder::getObject(
return
DynamicList
::
Builder
();
}
Text
::
Builder
DynamicStruct
::
Builder
::
getObjectAsText
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
return
Text
::
Builder
();
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
getObjectAsDataImpl
(
builder
,
member
);
}
...
...
@@ -497,15 +497,15 @@ Text::Builder DynamicStruct::Builder::getObjectAsText(StructSchema::Member membe
return
Text
::
Builder
();
}
Data
::
Builder
DynamicStruct
::
Builder
::
getObjectAsData
(
StructSchema
::
Member
member
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
return
Data
::
Builder
();
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
getObjectAsDataImpl
(
builder
,
member
);
}
...
...
@@ -517,15 +517,15 @@ Data::Builder DynamicStruct::Builder::getObjectAsData(StructSchema::Member membe
DynamicStruct
::
Builder
DynamicStruct
::
Builder
::
initObject
(
StructSchema
::
Member
member
,
StructSchema
type
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
return
DynamicStruct
::
Builder
();
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
initFieldImpl
(
builder
,
member
,
type
);
}
...
...
@@ -536,15 +536,15 @@ DynamicStruct::Builder DynamicStruct::Builder::initObject(
}
DynamicList
::
Builder
DynamicStruct
::
Builder
::
initObject
(
StructSchema
::
Member
member
,
ListSchema
type
,
uint
size
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
return
DynamicList
::
Builder
();
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
initFieldImpl
(
builder
,
member
,
type
,
size
);
}
...
...
@@ -554,15 +554,15 @@ DynamicList::Builder DynamicStruct::Builder::initObject(
return
DynamicList
::
Builder
();
}
Text
::
Builder
DynamicStruct
::
Builder
::
initObjectAsText
(
StructSchema
::
Member
member
,
uint
size
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
return
Text
::
Builder
();
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
initFieldAsDataImpl
(
builder
,
member
,
size
);
}
...
...
@@ -572,15 +572,15 @@ Text::Builder DynamicStruct::Builder::initObjectAsText(StructSchema::Member memb
return
Text
::
Builder
();
}
Data
::
Builder
DynamicStruct
::
Builder
::
initObjectAsData
(
StructSchema
::
Member
member
,
uint
size
)
{
PRECOND
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
REQUIRE
(
member
.
getContainingStruct
()
==
schema
,
"`member` is not a member of this struct."
);
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
"Expected an Object."
);
FAIL_
REQUIRE
(
"Expected an Object."
);
return
Data
::
Builder
();
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
field
=
member
.
getProto
().
getBody
().
getFieldMember
();
PRECOND
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
REQUIRE
(
field
.
getType
().
getBody
().
which
()
==
schema
::
Type
::
Body
::
OBJECT_TYPE
,
"Expected an Object."
);
return
initFieldAsDataImpl
(
builder
,
member
,
size
);
}
...
...
@@ -880,7 +880,7 @@ void DynamicStruct::Builder::setImpl(
getImpl
(
builder
,
member
).
as
<
DynamicUnion
>
().
set
(
member
,
src
.
get
());
return
;
}
else
{
FAIL_RECOVERABLE_
PRECOND
(
FAIL_RECOVERABLE_
REQUIRE
(
"Trying to copy a union value, but the union's discriminant is not recognized. It "
"was probably constructed using a newer version of the schema."
)
{
// Just don't copy anything.
...
...
@@ -928,7 +928,7 @@ void DynamicStruct::Builder::setImpl(
rawValue
=
enumSchema
.
getEnumerantByName
(
value
.
as
<
Text
>
()).
getOrdinal
();
}
else
{
DynamicEnum
enumValue
=
value
.
as
<
DynamicEnum
>
();
RECOVERABLE_
PRECOND
(
enumValue
.
getSchema
()
==
enumSchema
,
RECOVERABLE_
REQUIRE
(
enumValue
.
getSchema
()
==
enumSchema
,
"Type mismatch when using DynamicList::Builder::set()."
)
{
return
;
}
...
...
@@ -967,7 +967,7 @@ void DynamicStruct::Builder::setImpl(
return
;
}
FAIL_RECOVERABLE_
PRECOND
(
"can't set field of unknown type"
,
(
uint
)
type
.
which
());
FAIL_RECOVERABLE_
REQUIRE
(
"can't set field of unknown type"
,
(
uint
)
type
.
which
());
return
;
}
}
...
...
@@ -979,7 +979,7 @@ DynamicValue::Builder DynamicStruct::Builder::initImpl(
internal
::
StructBuilder
builder
,
StructSchema
::
Member
member
,
uint
size
)
{
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
FAIL_
REQUIRE
(
"Can't init() a union. get() it first and then init() one of its members."
);
break
;
...
...
@@ -994,7 +994,7 @@ DynamicValue::Builder DynamicStruct::Builder::initImpl(
case
schema
:
:
Type
::
Body
::
DATA_TYPE
:
return
initFieldAsDataImpl
(
builder
,
member
,
size
);
default
:
FAIL_
PRECOND
(
FAIL_
REQUIRE
(
"init() with size is only valid for list, text, or data fields."
,
(
uint
)
type
.
which
());
break
;
}
...
...
@@ -1010,13 +1010,13 @@ DynamicValue::Builder DynamicStruct::Builder::initImpl(
internal
::
StructBuilder
builder
,
StructSchema
::
Member
member
)
{
switch
(
member
.
getProto
().
getBody
().
which
())
{
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
FAIL_
PRECOND
(
FAIL_
REQUIRE
(
"Can't init() a union. get() it first and then init() one of its members."
);
break
;
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
auto
type
=
member
.
getProto
().
getBody
().
getFieldMember
().
getType
().
getBody
();
PRECOND
(
type
.
which
()
==
schema
::
Type
::
Body
::
STRUCT_TYPE
,
REQUIRE
(
type
.
which
()
==
schema
::
Type
::
Body
::
STRUCT_TYPE
,
"init() without a size is only valid for struct fields."
);
return
initFieldImpl
(
builder
,
member
,
member
.
getContainingStruct
().
getDependency
(
type
.
getStructType
()).
asStruct
());
...
...
@@ -1063,7 +1063,7 @@ Data::Builder DynamicStruct::Builder::initFieldAsDataImpl(
// =======================================================================================
DynamicValue
::
Reader
DynamicList
::
Reader
::
operator
[](
uint
index
)
const
{
PRECOND
(
index
<
size
(),
"List index out-of-bounds."
);
REQUIRE
(
index
<
size
(),
"List index out-of-bounds."
);
switch
(
schema
.
whichElementType
())
{
#define HANDLE_TYPE(name, discrim, typeName) \
...
...
@@ -1117,7 +1117,7 @@ DynamicValue::Reader DynamicList::Reader::operator[](uint index) const {
}
DynamicValue
::
Builder
DynamicList
::
Builder
::
operator
[](
uint
index
)
const
{
PRECOND
(
index
<
size
(),
"List index out-of-bounds."
);
REQUIRE
(
index
<
size
(),
"List index out-of-bounds."
);
switch
(
schema
.
whichElementType
())
{
#define HANDLE_TYPE(name, discrim, typeName) \
...
...
@@ -1179,7 +1179,7 @@ DynamicValue::Builder DynamicList::Builder::operator[](uint index) const {
}
void
DynamicList
::
Builder
::
set
(
uint
index
,
DynamicValue
::
Reader
value
)
{
RECOVERABLE_
PRECOND
(
index
<
size
(),
"List index out-of-bounds."
)
{
RECOVERABLE_
REQUIRE
(
index
<
size
(),
"List index out-of-bounds."
)
{
return
;
}
...
...
@@ -1229,7 +1229,7 @@ void DynamicList::Builder::set(uint index, DynamicValue::Reader value) {
rawValue
=
schema
.
getEnumElementType
().
getEnumerantByName
(
value
.
as
<
Text
>
()).
getOrdinal
();
}
else
{
DynamicEnum
enumValue
=
value
.
as
<
DynamicEnum
>
();
RECOVERABLE_
PRECOND
(
schema
.
getEnumElementType
()
==
enumValue
.
getSchema
(),
RECOVERABLE_
REQUIRE
(
schema
.
getEnumElementType
()
==
enumValue
.
getSchema
(),
"Type mismatch when using DynamicList::Builder::set()."
)
{
return
;
}
...
...
@@ -1248,11 +1248,11 @@ void DynamicList::Builder::set(uint index, DynamicValue::Reader value) {
return
;
}
FAIL_RECOVERABLE_
PRECOND
(
"can't set element of unknown type"
,
(
uint
)
schema
.
whichElementType
());
FAIL_RECOVERABLE_
REQUIRE
(
"can't set element of unknown type"
,
(
uint
)
schema
.
whichElementType
());
}
DynamicValue
::
Builder
DynamicList
::
Builder
::
init
(
uint
index
,
uint
size
)
{
PRECOND
(
index
<
this
->
size
(),
"List index out-of-bounds."
);
REQUIRE
(
index
<
this
->
size
(),
"List index out-of-bounds."
);
switch
(
schema
.
whichElementType
())
{
case
schema
:
:
Type
::
Body
::
VOID_TYPE
:
...
...
@@ -1270,7 +1270,7 @@ DynamicValue::Builder DynamicList::Builder::init(uint index, uint size) {
case
schema
:
:
Type
::
Body
::
ENUM_TYPE
:
case
schema
:
:
Type
::
Body
::
STRUCT_TYPE
:
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
FAIL_
PRECOND
(
"Expected a list or blob."
);
FAIL_
REQUIRE
(
"Expected a list or blob."
);
return
nullptr
;
case
schema
:
:
Type
::
Body
::
TEXT_TYPE
:
...
...
@@ -1305,7 +1305,7 @@ DynamicValue::Builder DynamicList::Builder::init(uint index, uint size) {
}
void
DynamicList
::
Builder
::
copyFrom
(
std
::
initializer_list
<
DynamicValue
::
Reader
>
value
)
{
PRECOND
(
value
.
size
()
==
size
(),
"DynamicList::copyFrom() argument had different size."
);
REQUIRE
(
value
.
size
()
==
size
(),
"DynamicList::copyFrom() argument had different size."
);
uint
i
=
0
;
for
(
auto
element
:
value
)
{
set
(
i
++
,
element
);
...
...
@@ -1343,7 +1343,7 @@ namespace {
template
<
typename
T
>
T
signedToUnsigned
(
long
long
value
)
{
RECOVERABLE_
PRECOND
(
value
>=
0
&&
T
(
value
)
==
value
,
RECOVERABLE_
REQUIRE
(
value
>=
0
&&
T
(
value
)
==
value
,
"Value out-of-range for requested type."
,
value
)
{
// Use it anyway.
}
...
...
@@ -1352,7 +1352,7 @@ T signedToUnsigned(long long value) {
template
<>
uint64_t
signedToUnsigned
<
uint64_t
>
(
long
long
value
)
{
RECOVERABLE_
PRECOND
(
value
>=
0
,
"Value out-of-range for requested type."
,
value
)
{
RECOVERABLE_
REQUIRE
(
value
>=
0
,
"Value out-of-range for requested type."
,
value
)
{
// Use it anyway.
}
return
value
;
...
...
@@ -1360,7 +1360,7 @@ uint64_t signedToUnsigned<uint64_t>(long long value) {
template
<
typename
T
>
T
unsignedToSigned
(
unsigned
long
long
value
)
{
RECOVERABLE_
PRECOND
(
T
(
value
)
>=
0
&&
(
unsigned
long
long
)
T
(
value
)
==
value
,
RECOVERABLE_
REQUIRE
(
T
(
value
)
>=
0
&&
(
unsigned
long
long
)
T
(
value
)
==
value
,
"Value out-of-range for requested type."
,
value
)
{
// Use it anyway.
}
...
...
@@ -1369,7 +1369,7 @@ T unsignedToSigned(unsigned long long value) {
template
<>
int64_t
unsignedToSigned
<
int64_t
>
(
unsigned
long
long
value
)
{
RECOVERABLE_
PRECOND
(
int64_t
(
value
)
>=
0
,
"Value out-of-range for requested type."
,
value
)
{
RECOVERABLE_
REQUIRE
(
int64_t
(
value
)
>=
0
,
"Value out-of-range for requested type."
,
value
)
{
// Use it anyway.
}
return
value
;
...
...
@@ -1377,7 +1377,7 @@ int64_t unsignedToSigned<int64_t>(unsigned long long value) {
template
<
typename
T
,
typename
U
>
T
checkRoundTrip
(
U
value
)
{
RECOVERABLE_
PRECOND
(
T
(
value
)
==
value
,
"Value out-of-range for requested type."
,
value
)
{
RECOVERABLE_
REQUIRE
(
T
(
value
)
==
value
,
"Value out-of-range for requested type."
,
value
)
{
// Use it anyway.
}
return
value
;
...
...
@@ -1395,7 +1395,7 @@ typeName DynamicValue::Reader::AsImpl<typeName>::apply(Reader reader) { \
case FLOAT: \
return ifFloat<typeName>(reader.floatValue); \
default: \
FAIL_RECOVERABLE_
PRECOND
("Type mismatch when using DynamicValue::Reader::as().") { \
FAIL_RECOVERABLE_
REQUIRE
("Type mismatch when using DynamicValue::Reader::as().") { \
/* use zero */
\
} \
return 0; \
...
...
@@ -1410,7 +1410,7 @@ typeName DynamicValue::Builder::AsImpl<typeName>::apply(Builder builder) { \
case FLOAT: \
return ifFloat<typeName>(builder.floatValue); \
default: \
FAIL_RECOVERABLE_
PRECOND
("Type mismatch when using DynamicValue::Builder::as().") { \
FAIL_RECOVERABLE_
REQUIRE
("Type mismatch when using DynamicValue::Builder::as().") { \
/* use zero */
\
} \
return 0; \
...
...
@@ -1432,12 +1432,12 @@ HANDLE_NUMERIC_TYPE(double, kj::upcast, kj::upcast, kj::upcast)
#define HANDLE_TYPE(name, discrim, typeName) \
ReaderFor<typeName> DynamicValue::Reader::AsImpl<typeName>::apply(Reader reader) { \
PRECOND
(reader.type == discrim, \
REQUIRE
(reader.type == discrim, \
"Type mismatch when using DynamicValue::Reader::as()."); \
return reader.name##Value; \
} \
BuilderFor<typeName> DynamicValue::Builder::AsImpl<typeName>::apply(Builder builder) { \
PRECOND
(builder.type == discrim, \
REQUIRE
(builder.type == discrim, \
"Type mismatch when using DynamicValue::Builder::as()."); \
return builder.name##Value; \
}
...
...
@@ -1459,7 +1459,7 @@ Data::Reader DynamicValue::Reader::AsImpl<Data>::apply(Reader reader) {
// Implicitly convert from text.
return
reader
.
textValue
;
}
RECOVERABLE_
PRECOND
(
reader
.
type
==
DATA
,
RECOVERABLE_
REQUIRE
(
reader
.
type
==
DATA
,
"Type mismatch when using DynamicValue::Reader::as()."
)
{
return
Data
::
Reader
();
}
...
...
@@ -1470,7 +1470,7 @@ Data::Builder DynamicValue::Builder::AsImpl<Data>::apply(Builder builder) {
// Implicitly convert from text.
return
builder
.
textValue
;
}
RECOVERABLE_
PRECOND
(
builder
.
type
==
DATA
,
RECOVERABLE_
REQUIRE
(
builder
.
type
==
DATA
,
"Type mismatch when using DynamicValue::Builder::as()."
)
{
return
Data
::
Builder
();
}
...
...
@@ -1479,14 +1479,14 @@ Data::Builder DynamicValue::Builder::AsImpl<Data>::apply(Builder builder) {
// As in the header, HANDLE_TYPE(void, VOID, Void) crashes GCC 4.7.
Void
DynamicValue
::
Reader
::
AsImpl
<
Void
>::
apply
(
Reader
reader
)
{
RECOVERABLE_
PRECOND
(
reader
.
type
==
VOID
,
RECOVERABLE_
REQUIRE
(
reader
.
type
==
VOID
,
"Type mismatch when using DynamicValue::Reader::as()."
)
{
return
Void
();
}
return
reader
.
voidValue
;
}
Void
DynamicValue
::
Builder
::
AsImpl
<
Void
>::
apply
(
Builder
builder
)
{
RECOVERABLE_
PRECOND
(
builder
.
type
==
VOID
,
RECOVERABLE_
REQUIRE
(
builder
.
type
==
VOID
,
"Type mismatch when using DynamicValue::Builder::as()."
)
{
return
Void
();
}
...
...
c++/src/capnproto/layout.c++
View file @
20272ec5
...
...
@@ -102,12 +102,12 @@ struct WirePointer {
}
KJ_ALWAYS_INLINE
(
WordCount
farPositionInSegment
()
const
)
{
D
PRECOND
(
kind
()
==
FAR
,
D
REQUIRE
(
kind
()
==
FAR
,
"positionInSegment() should only be called on FAR pointers."
);
return
(
offsetAndKind
.
get
()
>>
3
)
*
WORDS
;
}
KJ_ALWAYS_INLINE
(
bool
isDoubleFar
()
const
)
{
D
PRECOND
(
kind
()
==
FAR
,
D
REQUIRE
(
kind
()
==
FAR
,
"isDoubleFar() should only be called on FAR pointers."
);
return
(
offsetAndKind
.
get
()
>>
2
)
&
1
;
}
...
...
@@ -155,12 +155,12 @@ struct WirePointer {
}
KJ_ALWAYS_INLINE
(
void
set
(
FieldSize
es
,
ElementCount
ec
))
{
D
PRECOND
(
ec
<
(
1
<<
29
)
*
ELEMENTS
,
"Lists are limited to 2**29 elements."
);
D
REQUIRE
(
ec
<
(
1
<<
29
)
*
ELEMENTS
,
"Lists are limited to 2**29 elements."
);
elementSizeAndCount
.
set
(((
ec
/
ELEMENTS
)
<<
3
)
|
static_cast
<
int
>
(
es
));
}
KJ_ALWAYS_INLINE
(
void
setInlineComposite
(
WordCount
wc
))
{
D
PRECOND
(
wc
<
(
1
<<
29
)
*
WORDS
,
"Inline composite lists are limited to 2**29 words."
);
D
REQUIRE
(
wc
<
(
1
<<
29
)
*
WORDS
,
"Inline composite lists are limited to 2**29 words."
);
elementSizeAndCount
.
set
(((
wc
/
WORDS
)
<<
3
)
|
static_cast
<
int
>
(
FieldSize
::
INLINE_COMPOSITE
));
}
...
...
@@ -656,7 +656,7 @@ struct WireHelpers {
break
;
}
default
:
FAIL_
PRECOND
(
"Copy source message contained unexpected kind."
);
FAIL_
REQUIRE
(
"Copy source message contained unexpected kind."
);
break
;
}
...
...
@@ -796,7 +796,7 @@ struct WireHelpers {
static
KJ_ALWAYS_INLINE
(
ListBuilder
initListPointer
(
WirePointer
*
ref
,
SegmentBuilder
*
segment
,
ElementCount
elementCount
,
FieldSize
elementSize
))
{
D
PRECOND
(
elementSize
!=
FieldSize
::
INLINE_COMPOSITE
,
D
REQUIRE
(
elementSize
!=
FieldSize
::
INLINE_COMPOSITE
,
"Should have called initStructListPointer() instead."
);
BitCount
dataSize
=
dataBitsPerElement
(
elementSize
)
*
ELEMENTS
;
...
...
@@ -848,7 +848,7 @@ struct WireHelpers {
static
KJ_ALWAYS_INLINE
(
ListBuilder
getWritableListPointer
(
WirePointer
*
origRef
,
SegmentBuilder
*
origSegment
,
FieldSize
elementSize
,
const
word
*
defaultValue
))
{
D
PRECOND
(
elementSize
!=
FieldSize
::
INLINE_COMPOSITE
,
D
REQUIRE
(
elementSize
!=
FieldSize
::
INLINE_COMPOSITE
,
"Use getStructList{Element,Field}() for structs."
);
if
(
origRef
->
isNull
())
{
...
...
@@ -886,7 +886,7 @@ struct WireHelpers {
// Read the tag to get the actual element count.
WirePointer
*
tag
=
reinterpret_cast
<
WirePointer
*>
(
ptr
);
PRECOND
(
tag
->
kind
()
==
WirePointer
::
STRUCT
,
REQUIRE
(
tag
->
kind
()
==
WirePointer
::
STRUCT
,
"INLINE_COMPOSITE list with non-STRUCT elements not supported."
);
ptr
+=
POINTER_SIZE_IN_WORDS
;
...
...
@@ -1226,9 +1226,9 @@ struct WireHelpers {
}
else
{
word
*
ptr
=
followFars
(
ref
,
segment
);
PRECOND
(
ref
->
kind
()
==
WirePointer
::
LIST
,
REQUIRE
(
ref
->
kind
()
==
WirePointer
::
LIST
,
"Called getText{Field,Element}() but existing pointer is not a list."
);
PRECOND
(
ref
->
listRef
.
elementSize
()
==
FieldSize
::
BYTE
,
REQUIRE
(
ref
->
listRef
.
elementSize
()
==
FieldSize
::
BYTE
,
"Called getText{Field,Element}() but existing list pointer is not byte-sized."
);
// Subtract 1 from the size for the NUL terminator.
...
...
@@ -1263,9 +1263,9 @@ struct WireHelpers {
}
else
{
word
*
ptr
=
followFars
(
ref
,
segment
);
PRECOND
(
ref
->
kind
()
==
WirePointer
::
LIST
,
REQUIRE
(
ref
->
kind
()
==
WirePointer
::
LIST
,
"Called getData{Field,Element}() but existing pointer is not a list."
);
PRECOND
(
ref
->
listRef
.
elementSize
()
==
FieldSize
::
BYTE
,
REQUIRE
(
ref
->
listRef
.
elementSize
()
==
FieldSize
::
BYTE
,
"Called getData{Field,Element}() but existing list pointer is not byte-sized."
);
return
Data
::
Builder
(
reinterpret_cast
<
char
*>
(
ptr
),
ref
->
listRef
.
elementCount
()
/
ELEMENTS
);
...
...
@@ -1291,7 +1291,7 @@ struct WireHelpers {
if
(
ref
->
listRef
.
elementSize
()
==
FieldSize
::
INLINE_COMPOSITE
)
{
// Read the tag to get the actual element count.
WirePointer
*
tag
=
reinterpret_cast
<
WirePointer
*>
(
ptr
);
PRECOND
(
tag
->
kind
()
==
WirePointer
::
STRUCT
,
REQUIRE
(
tag
->
kind
()
==
WirePointer
::
STRUCT
,
"INLINE_COMPOSITE list with non-STRUCT elements not supported."
);
// First list element is at tag + 1 pointer.
...
...
@@ -1951,7 +1951,7 @@ ObjectReader StructReader::getObjectField(
}
const
word
*
StructReader
::
getUncheckedPointer
(
WirePointerCount
ptrIndex
)
const
{
PRECOND
(
segment
==
nullptr
,
"getUncheckedPointer() only allowed on unchecked messages."
);
REQUIRE
(
segment
==
nullptr
,
"getUncheckedPointer() only allowed on unchecked messages."
);
return
reinterpret_cast
<
const
word
*>
(
pointers
+
ptrIndex
);
}
...
...
c++/src/capnproto/message.c++
View file @
20272ec5
...
...
@@ -146,10 +146,10 @@ MallocMessageBuilder::MallocMessageBuilder(
kj
::
ArrayPtr
<
word
>
firstSegment
,
AllocationStrategy
allocationStrategy
)
:
nextSize
(
firstSegment
.
size
()),
allocationStrategy
(
allocationStrategy
),
ownFirstSegment
(
false
),
returnedFirstSegment
(
false
),
firstSegment
(
firstSegment
.
begin
())
{
PRECOND
(
firstSegment
.
size
()
>
0
,
"First segment size must be non-zero."
);
REQUIRE
(
firstSegment
.
size
()
>
0
,
"First segment size must be non-zero."
);
// Checking just the first word should catch most cases of failing to zero the segment.
PRECOND
(
*
reinterpret_cast
<
uint64_t
*>
(
firstSegment
.
begin
())
==
0
,
REQUIRE
(
*
reinterpret_cast
<
uint64_t
*>
(
firstSegment
.
begin
())
==
0
,
"First segment must be zeroed."
);
}
...
...
@@ -218,12 +218,12 @@ FlatMessageBuilder::FlatMessageBuilder(kj::ArrayPtr<word> array): array(array),
FlatMessageBuilder
::~
FlatMessageBuilder
()
{}
void
FlatMessageBuilder
::
requireFilled
()
{
PRECOND
(
getSegmentsForOutput
()[
0
].
end
()
==
array
.
end
(),
REQUIRE
(
getSegmentsForOutput
()[
0
].
end
()
==
array
.
end
(),
"FlatMessageBuilder's buffer was too large."
);
}
kj
::
ArrayPtr
<
word
>
FlatMessageBuilder
::
allocateSegment
(
uint
minimumSize
)
{
PRECOND
(
!
allocated
,
"FlatMessageBuilder's buffer was not large enough."
);
REQUIRE
(
!
allocated
,
"FlatMessageBuilder's buffer was not large enough."
);
allocated
=
true
;
return
array
;
}
...
...
c++/src/capnproto/schema-loader.c++
View file @
20272ec5
...
...
@@ -447,7 +447,7 @@ public:
CONTEXT
(
"checking compatibility with previously-loaded node of the same id"
,
existingNode
.
getDisplayName
());
D
PRECOND
(
existingNode
.
getId
()
==
replacement
.
getId
());
D
REQUIRE
(
existingNode
.
getId
()
==
replacement
.
getId
());
nodeName
=
existingNode
.
getDisplayName
();
compatibility
=
EQUIVALENT
;
...
...
@@ -1026,7 +1026,7 @@ internal::RawSchema* SchemaLoader::Impl::loadNative(const internal::RawSchema* n
if
(
slot
==
nullptr
)
{
slot
=
allocate
<
internal
::
RawSchema
>
();
}
else
if
(
slot
->
canCastTo
!=
nullptr
)
{
PRECOND
(
slot
->
canCastTo
==
nativeSchema
,
REQUIRE
(
slot
->
canCastTo
==
nativeSchema
,
"two different compiled-in type have the same type ID"
,
reader
.
getId
(),
reader
.
getDisplayName
(),
readMessageUnchecked
<
schema
::
Node
>
(
slot
->
canCastTo
->
encodedNode
).
getDisplayName
());
...
...
@@ -1079,7 +1079,7 @@ internal::RawSchema* SchemaLoader::Impl::loadEmpty(
case
schema
:
:
Node
::
Body
::
FILE_NODE
:
case
schema
:
:
Node
::
Body
::
CONST_NODE
:
case
schema
:
:
Node
::
Body
::
ANNOTATION_NODE
:
FAIL_
PRECOND
(
"Not a type."
);
FAIL_
REQUIRE
(
"Not a type."
);
break
;
}
...
...
@@ -1111,7 +1111,7 @@ SchemaLoader::~SchemaLoader() {}
Schema
SchemaLoader
::
get
(
uint64_t
id
)
const
{
internal
::
RawSchema
*
raw
=
impl
->
tryGet
(
id
);
PRECOND
(
raw
!=
nullptr
,
"no schema node loaded for id"
,
id
);
REQUIRE
(
raw
!=
nullptr
,
"no schema node loaded for id"
,
id
);
return
Schema
(
raw
);
}
...
...
c++/src/capnproto/schema.c++
View file @
20272ec5
...
...
@@ -51,33 +51,33 @@ Schema Schema::getDependency(uint64_t id) const {
}
}
FAIL_
PRECOND
(
"Requested ID not found in dependency table."
,
id
);
FAIL_
REQUIRE
(
"Requested ID not found in dependency table."
,
id
);
return
Schema
();
}
StructSchema
Schema
::
asStruct
()
const
{
PRECOND
(
getProto
().
getBody
().
which
()
==
schema
::
Node
::
Body
::
STRUCT_NODE
,
REQUIRE
(
getProto
().
getBody
().
which
()
==
schema
::
Node
::
Body
::
STRUCT_NODE
,
"Tried to use non-struct schema as a struct."
,
getProto
().
getDisplayName
());
return
StructSchema
(
raw
);
}
EnumSchema
Schema
::
asEnum
()
const
{
PRECOND
(
getProto
().
getBody
().
which
()
==
schema
::
Node
::
Body
::
ENUM_NODE
,
REQUIRE
(
getProto
().
getBody
().
which
()
==
schema
::
Node
::
Body
::
ENUM_NODE
,
"Tried to use non-enum schema as an enum."
,
getProto
().
getDisplayName
());
return
EnumSchema
(
raw
);
}
InterfaceSchema
Schema
::
asInterface
()
const
{
PRECOND
(
getProto
().
getBody
().
which
()
==
schema
::
Node
::
Body
::
INTERFACE_NODE
,
REQUIRE
(
getProto
().
getBody
().
which
()
==
schema
::
Node
::
Body
::
INTERFACE_NODE
,
"Tried to use non-interface schema as an interface."
,
getProto
().
getDisplayName
());
return
InterfaceSchema
(
raw
);
}
void
Schema
::
requireUsableAs
(
const
internal
::
RawSchema
*
expected
)
{
PRECOND
(
raw
==
expected
||
REQUIRE
(
raw
==
expected
||
(
raw
!=
nullptr
&&
expected
!=
nullptr
&&
raw
->
canCastTo
==
expected
),
"This schema is not compatible with the requested native type."
);
}
...
...
@@ -132,7 +132,7 @@ StructSchema::Member StructSchema::getMemberByName(Text::Reader name) const {
KJ_IF_MAYBE
(
member
,
findMemberByName
(
name
))
{
return
*
member
;
}
else
{
FAIL_
PRECOND
(
"struct has no such member"
,
name
);
FAIL_
REQUIRE
(
"struct has no such member"
,
name
);
}
}
...
...
@@ -142,7 +142,7 @@ kj::Maybe<StructSchema::Union> StructSchema::Member::getContainingUnion() const
}
StructSchema
::
Union
StructSchema
::
Member
::
asUnion
()
const
{
PRECOND
(
proto
.
getBody
().
which
()
==
schema
::
StructNode
::
Member
::
Body
::
UNION_MEMBER
,
REQUIRE
(
proto
.
getBody
().
which
()
==
schema
::
StructNode
::
Member
::
Body
::
UNION_MEMBER
,
"Tried to use non-union struct member as a union."
,
parent
.
getProto
().
getDisplayName
(),
proto
.
getName
());
return
Union
(
*
this
);
...
...
@@ -160,7 +160,7 @@ StructSchema::Member StructSchema::Union::getMemberByName(Text::Reader name) con
KJ_IF_MAYBE
(
member
,
findMemberByName
(
name
))
{
return
*
member
;
}
else
{
FAIL_
PRECOND
(
"union has no such member"
,
name
);
FAIL_
REQUIRE
(
"union has no such member"
,
name
);
}
}
...
...
@@ -178,7 +178,7 @@ EnumSchema::Enumerant EnumSchema::getEnumerantByName(Text::Reader name) const {
KJ_IF_MAYBE
(
enumerant
,
findEnumerantByName
(
name
))
{
return
*
enumerant
;
}
else
{
FAIL_
PRECOND
(
"enum has no such enumerant"
,
name
);
FAIL_
REQUIRE
(
"enum has no such enumerant"
,
name
);
}
}
...
...
@@ -196,7 +196,7 @@ InterfaceSchema::Method InterfaceSchema::getMethodByName(Text::Reader name) cons
KJ_IF_MAYBE
(
method
,
findMethodByName
(
name
))
{
return
*
method
;
}
else
{
FAIL_
PRECOND
(
"interface has no such method"
,
name
);
FAIL_
REQUIRE
(
"interface has no such method"
,
name
);
}
}
...
...
@@ -224,11 +224,11 @@ ListSchema ListSchema::of(schema::Type::Body::Which primitiveType) {
case
schema
:
:
Type
::
Body
::
ENUM_TYPE
:
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
case
schema
:
:
Type
::
Body
::
LIST_TYPE
:
FAIL_
PRECOND
(
"Must use one of the other ListSchema::of() overloads for complex types."
);
FAIL_
REQUIRE
(
"Must use one of the other ListSchema::of() overloads for complex types."
);
break
;
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
FAIL_
PRECOND
(
"List(Object) not supported."
);
FAIL_
REQUIRE
(
"List(Object) not supported."
);
break
;
}
...
...
@@ -267,7 +267,7 @@ ListSchema ListSchema::of(schema::Type::Reader elementType, Schema context) {
return
of
(
of
(
body
.
getListType
(),
context
));
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
FAIL_
PRECOND
(
"List(Object) not supported."
);
FAIL_
REQUIRE
(
"List(Object) not supported."
);
return
ListSchema
();
}
...
...
@@ -276,31 +276,31 @@ ListSchema ListSchema::of(schema::Type::Reader elementType, Schema context) {
}
StructSchema
ListSchema
::
getStructElementType
()
const
{
PRECOND
(
nestingDepth
==
0
&&
elementType
==
schema
::
Type
::
Body
::
STRUCT_TYPE
,
REQUIRE
(
nestingDepth
==
0
&&
elementType
==
schema
::
Type
::
Body
::
STRUCT_TYPE
,
"ListSchema::getStructElementType(): The elements are not structs."
);
return
elementSchema
.
asStruct
();
}
EnumSchema
ListSchema
::
getEnumElementType
()
const
{
PRECOND
(
nestingDepth
==
0
&&
elementType
==
schema
::
Type
::
Body
::
ENUM_TYPE
,
REQUIRE
(
nestingDepth
==
0
&&
elementType
==
schema
::
Type
::
Body
::
ENUM_TYPE
,
"ListSchema::getEnumElementType(): The elements are not enums."
);
return
elementSchema
.
asEnum
();
}
InterfaceSchema
ListSchema
::
getInterfaceElementType
()
const
{
PRECOND
(
nestingDepth
==
0
&&
elementType
==
schema
::
Type
::
Body
::
INTERFACE_TYPE
,
REQUIRE
(
nestingDepth
==
0
&&
elementType
==
schema
::
Type
::
Body
::
INTERFACE_TYPE
,
"ListSchema::getInterfaceElementType(): The elements are not interfaces."
);
return
elementSchema
.
asInterface
();
}
ListSchema
ListSchema
::
getListElementType
()
const
{
PRECOND
(
nestingDepth
>
0
,
REQUIRE
(
nestingDepth
>
0
,
"ListSchema::getListElementType(): The elements are not lists."
);
return
ListSchema
(
elementType
,
nestingDepth
-
1
,
elementSchema
);
}
void
ListSchema
::
requireUsableAs
(
ListSchema
expected
)
{
PRECOND
(
elementType
==
expected
.
elementType
&&
nestingDepth
==
expected
.
nestingDepth
,
REQUIRE
(
elementType
==
expected
.
elementType
&&
nestingDepth
==
expected
.
nestingDepth
,
"This schema is not compatible with the requested native type."
);
elementSchema
.
requireUsableAs
(
expected
.
elementSchema
.
raw
);
}
...
...
c++/src/capnproto/serialize-packed.c++
View file @
20272ec5
...
...
@@ -39,8 +39,8 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
return
0
;
}
D
PRECOND
(
minBytes
%
sizeof
(
word
)
==
0
,
"PackedInputStream reads must be word-aligned."
);
D
PRECOND
(
maxBytes
%
sizeof
(
word
)
==
0
,
"PackedInputStream reads must be word-aligned."
);
D
REQUIRE
(
minBytes
%
sizeof
(
word
)
==
0
,
"PackedInputStream reads must be word-aligned."
);
D
REQUIRE
(
maxBytes
%
sizeof
(
word
)
==
0
,
"PackedInputStream reads must be word-aligned."
);
uint8_t
*
__restrict__
out
=
reinterpret_cast
<
uint8_t
*>
(
dst
);
uint8_t
*
const
outEnd
=
reinterpret_cast
<
uint8_t
*>
(
dst
)
+
maxBytes
;
...
...
@@ -190,7 +190,7 @@ void PackedInputStream::skip(size_t bytes) {
return
;
}
D
PRECOND
(
bytes
%
sizeof
(
word
)
==
0
,
"PackedInputStream reads must be word-aligned."
);
D
REQUIRE
(
bytes
%
sizeof
(
word
)
==
0
,
"PackedInputStream reads must be word-aligned."
);
kj
::
ArrayPtr
<
const
byte
>
buffer
=
inner
.
getReadBuffer
();
const
uint8_t
*
__restrict__
in
=
reinterpret_cast
<
const
uint8_t
*>
(
buffer
.
begin
());
...
...
c++/src/capnproto/serialize.c++
View file @
20272ec5
...
...
@@ -88,7 +88,7 @@ kj::ArrayPtr<const word> FlatArrayMessageReader::getSegment(uint id) {
}
kj
::
Array
<
word
>
messageToFlatArray
(
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
)
{
PRECOND
(
segments
.
size
()
>
0
,
"Tried to serialize uninitialized message."
);
REQUIRE
(
segments
.
size
()
>
0
,
"Tried to serialize uninitialized message."
);
size_t
totalSize
=
segments
.
size
()
/
2
+
1
;
...
...
@@ -237,7 +237,7 @@ kj::ArrayPtr<const word> InputStreamMessageReader::getSegment(uint id) {
// -------------------------------------------------------------------
void
writeMessage
(
kj
::
OutputStream
&
output
,
kj
::
ArrayPtr
<
const
kj
::
ArrayPtr
<
const
word
>>
segments
)
{
PRECOND
(
segments
.
size
()
>
0
,
"Tried to serialize uninitialized message."
);
REQUIRE
(
segments
.
size
()
>
0
,
"Tried to serialize uninitialized message."
);
internal
::
WireValue
<
uint32_t
>
table
[(
segments
.
size
()
+
2
)
&
~
size_t
(
1
)];
...
...
c++/src/kj/array.h
View file @
20272ec5
...
...
@@ -94,7 +94,7 @@ public:
inline
size_t
size
()
const
{
return
size_
;
}
inline
T
&
operator
[](
size_t
index
)
const
{
KJ_I
NLINE_DPRECOND
(
index
<
size_
,
"Out-of-bounds Array access."
);
KJ_I
REQUIRE
(
index
<
size_
,
"Out-of-bounds Array access."
);
return
ptr
[
index
];
}
...
...
@@ -108,11 +108,11 @@ public:
inline
T
&
back
()
{
return
*
(
ptr
+
size_
-
1
);
}
inline
ArrayPtr
<
T
>
slice
(
size_t
start
,
size_t
end
)
{
KJ_I
NLINE_DPRECOND
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds Array::slice()."
);
KJ_I
REQUIRE
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds Array::slice()."
);
return
ArrayPtr
<
T
>
(
ptr
+
start
,
end
-
start
);
}
inline
ArrayPtr
<
const
T
>
slice
(
size_t
start
,
size_t
end
)
const
{
KJ_I
NLINE_DPRECOND
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds Array::slice()."
);
KJ_I
REQUIRE
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds Array::slice()."
);
return
ArrayPtr
<
const
T
>
(
ptr
+
start
,
end
-
start
);
}
...
...
@@ -235,7 +235,7 @@ public:
inline
size_t
size
()
const
{
return
pos
-
ptr
;
}
inline
size_t
capacity
()
const
{
return
endPtr
-
ptr
;
}
inline
T
&
operator
[](
size_t
index
)
const
{
KJ_I
NLINE_DPRECOND
(
index
<
pos
-
ptr
,
"Out-of-bounds Array access."
);
KJ_I
REQUIRE
(
index
<
pos
-
ptr
,
"Out-of-bounds Array access."
);
return
ptr
[
index
];
}
...
...
@@ -266,7 +266,7 @@ public:
template
<
typename
...
Params
>
void
add
(
Params
&&
...
params
)
{
KJ_I
NLINE_DPRECOND
(
pos
<
endPtr
,
"Added too many elements to ArrayBuilder."
);
KJ_I
REQUIRE
(
pos
<
endPtr
,
"Added too many elements to ArrayBuilder."
);
ctor
(
*
pos
,
kj
::
fwd
<
Params
>
(
params
)...);
++
pos
;
}
...
...
@@ -286,7 +286,7 @@ public:
// arbitrary disposers with ArrayBuilder in the future, and anyway this check might catch bugs.
// Probably we should just create a new Vector-like data structure if we want to allow building
// of arrays without knowing the final size in advance.
KJ_I
NLINE_DPRECOND
(
pos
==
endPtr
,
"ArrayBuilder::finish() called prematurely."
);
KJ_I
REQUIRE
(
pos
==
endPtr
,
"ArrayBuilder::finish() called prematurely."
);
Array
<
T
>
result
(
reinterpret_cast
<
T
*>
(
ptr
),
pos
-
ptr
,
internal
::
HeapArrayDisposer
::
instance
);
ptr
=
nullptr
;
pos
=
nullptr
;
...
...
c++/src/kj/common.c++
View file @
20272ec5
...
...
@@ -27,7 +27,7 @@
namespace
kj
{
namespace
internal
{
void
inline
Precondition
Failure
(
const
char
*
file
,
int
line
,
const
char
*
expectation
,
void
inline
Require
Failure
(
const
char
*
file
,
int
line
,
const
char
*
expectation
,
const
char
*
macroArgs
,
const
char
*
message
)
{
if
(
message
==
nullptr
)
{
Log
::
fatalFault
(
file
,
line
,
Exception
::
Nature
::
PRECONDITION
,
expectation
,
macroArgs
);
...
...
c++/src/kj/common.h
View file @
20272ec5
...
...
@@ -113,24 +113,22 @@ typedef unsigned char byte;
namespace
internal
{
void
inline
Precondition
Failure
(
void
inline
Require
Failure
(
const
char
*
file
,
int
line
,
const
char
*
expectation
,
const
char
*
macroArgs
,
const
char
*
message
=
nullptr
)
KJ_NORETURN
;
}
// namespace internal
#define KJ_INLINE_PRECOND(condition, ...) \
if (KJ_EXPECT_TRUE(condition)); else ::kj::internal::inlinePreconditionFailure( \
#ifdef NDEBUG
#define KJ_IREQUIRE(condition, ...)
#else
#define KJ_IREQUIRE(condition, ...) \
if (KJ_EXPECT_TRUE(condition)); else ::kj::internal::inlineRequireFailure( \
__FILE__, __LINE__, #condition, #__VA_ARGS__, ##__VA_ARGS__)
// Version of
PRECOND
() which is safe to use in headers that are #included by users. Used to check
// Version of
REQUIRE
() which is safe to use in headers that are #included by users. Used to check
// preconditions inside inline methods. KJ_INLINE_DPRECOND is particularly useful in that
// it will be enabled depending on whether the application is compiled in debug mode rather than
// whether libkj is.
#ifdef NDEBUG
#define KJ_INLINE_DPRECOND(...)
#else
#define KJ_INLINE_DPRECOND KJ_INLINE_PRECOND
#endif
// #define KJ_STACK_ARRAY(type, name, size, minStack, maxStack)
...
...
@@ -501,7 +499,7 @@ public:
inline
size_t
size
()
const
{
return
size_
;
}
inline
T
&
operator
[](
size_t
index
)
const
{
KJ_I
NLINE_DPRECOND
(
index
<
size_
,
"Out-of-bounds ArrayPtr access."
);
KJ_I
REQUIRE
(
index
<
size_
,
"Out-of-bounds ArrayPtr access."
);
return
ptr
[
index
];
}
...
...
@@ -511,7 +509,7 @@ public:
inline
T
&
back
()
const
{
return
*
(
ptr
+
size_
-
1
);
}
inline
ArrayPtr
slice
(
size_t
start
,
size_t
end
)
const
{
KJ_I
NLINE_DPRECOND
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds ArrayPtr::slice()."
);
KJ_I
REQUIRE
(
start
<=
end
&&
end
<=
size_
,
"Out-of-bounds ArrayPtr::slice()."
);
return
ArrayPtr
(
ptr
+
start
,
end
-
start
);
}
...
...
@@ -578,8 +576,7 @@ To downcast(From* from) {
}
#if !KJ_NO_RTTI
KJ_INLINE_DPRECOND
(
from
==
nullptr
||
dynamic_cast
<
To
>
(
from
)
!=
nullptr
,
KJ_IREQUIRE
(
from
==
nullptr
||
dynamic_cast
<
To
>
(
from
)
!=
nullptr
,
"Value cannot be downcast() to requested type."
);
#endif
...
...
c++/src/kj/exception.c++
View file @
20272ec5
...
...
@@ -174,7 +174,7 @@ void ExceptionCallback::logMessage(StringPtr text) {
}
void
ExceptionCallback
::
useProcessWide
()
{
RECOVERABLE_
PRECOND
(
globalCallback
==
nullptr
,
RECOVERABLE_
REQUIRE
(
globalCallback
==
nullptr
,
"Can't register multiple global ExceptionCallbacks at once."
)
{
return
;
}
...
...
c++/src/kj/io.c++
View file @
20272ec5
...
...
@@ -217,7 +217,7 @@ void ArrayOutputStream::write(const void* src, size_t size) {
// Oh goody, the caller wrote directly into our buffer.
fillPos
+=
size
;
}
else
{
PRECOND
(
size
<=
(
size_t
)(
array
.
end
()
-
fillPos
),
REQUIRE
(
size
<=
(
size_t
)(
array
.
end
()
-
fillPos
),
"ArrayOutputStream's backing array was not large enough for the data written."
);
memcpy
(
fillPos
,
src
,
size
);
fillPos
+=
size
;
...
...
c++/src/kj/logging-test.c++
View file @
20272ec5
...
...
@@ -123,7 +123,7 @@ TEST(Logging, Log) {
"1 == 2; i = 123; hi; str = foo
\n
"
,
mockCallback
.
text
);
mockCallback
.
text
.
clear
();
EXPECT_THROW
(
PRECOND
(
1
==
2
,
i
,
"hi"
,
str
),
MockException
);
line
=
__LINE__
;
EXPECT_THROW
(
REQUIRE
(
1
==
2
,
i
,
"hi"
,
str
),
MockException
);
line
=
__LINE__
;
EXPECT_EQ
(
"fatal exception: "
+
fileLine
(
__FILE__
,
line
)
+
": precondition not met: expected "
"1 == 2; i = 123; hi; str = foo
\n
"
,
mockCallback
.
text
);
mockCallback
.
text
.
clear
();
...
...
c++/src/kj/logging.h
View file @
20272ec5
...
...
@@ -43,7 +43,7 @@
// 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.
//
// * `
PRECOND(condition, ...)`: Like `CHECK` but used to check preconditions -- i.e
. to validate
// * `
REQUIRE(condition, ...)`: Like `CHECK` 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
...
...
@@ -51,7 +51,7 @@
// 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_
PRECOND(condition, ...) { ... }`: Like `RECOVERABLE_CHECK` and `PRECOND
`.
// * `RECOVERABLE_
REQUIRE(condition, ...) { ... }`: Like `RECOVERABLE_CHECK` 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
...
...
@@ -228,14 +228,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
#define CHECK(...) FAULT(LOCAL_BUG, __VA_ARGS__)
#define RECOVERABLE_CHECK(...) RECOVERABLE_FAULT(LOCAL_BUG, __VA_ARGS__)
#define
PRECOND
(...) FAULT(PRECONDITION, __VA_ARGS__)
#define RECOVERABLE_
PRECOND
(...) RECOVERABLE_FAULT(PRECONDITION, __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_
PRECOND(...) PRECOND
(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_
PRECOND(...) RECOVERABLE_PRECOND
(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__)
#define SYSCALL(call, ...) \
...
...
@@ -274,14 +274,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
#define DLOG(...) do {} while (false)
#define DCHECK(...) do {} while (false)
#define RECOVERABLE_DCHECK(...) do {} while (false)
#define D
PRECOND
(...) do {} while (false)
#define RECOVERABLE_D
PRECOND
(...) do {} while (false)
#define D
REQUIRE
(...) do {} while (false)
#define RECOVERABLE_D
REQUIRE
(...) do {} while (false)
#else
#define DLOG LOG
#define DCHECK CHECK
#define RECOVERABLE_DCHECK RECOVERABLE_CHECK
#define D
PRECOND PRECOND
#define RECOVERABLE_D
PRECOND RECOVERABLE_PRECOND
#define D
REQUIRE REQUIRE
#define RECOVERABLE_D
REQUIRE RECOVERABLE_REQUIRE
#endif
template
<
typename
...
Params
>
...
...
c++/src/kj/string.h
View file @
20272ec5
...
...
@@ -365,7 +365,7 @@ inline const char* String::end() const { return content == nullptr ? nullptr : c
inline
String
::
String
(
char
*
value
,
size_t
size
,
const
ArrayDisposer
&
disposer
)
:
content
(
value
,
size
+
1
,
disposer
)
{
KJ_I
NLINE_DPRECOND
(
value
[
size
]
==
'\0'
,
"String must be NUL-terminated."
);
KJ_I
REQUIRE
(
value
[
size
]
==
'\0'
,
"String must be NUL-terminated."
);
}
inline
String
heapString
(
const
char
*
value
)
{
...
...
compiler/src/c++-header.mustache
View file @
20272ec5
...
...
@@ -309,7 +309,7 @@ inline {{unionFullName}}::Which {{unionFullName}}::Builder::which() {
{{#
fieldIsPrimitive
}}
inline
{{
fieldType
}}
{{
typeFullName
}}
::Reader::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return _reader.getDataField
<
{{
fieldType
}}
>
(
...
...
@@ -318,7 +318,7 @@ inline {{fieldType}} {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
inline
{{
fieldType
}}
{{
typeFullName
}}
::Builder::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return _builder.getDataField
<
{{
fieldType
}}
>
(
...
...
@@ -346,7 +346,7 @@ inline bool {{typeFullName}}::Builder::has{{fieldTitleCase}}() {
{{^
fieldIsGenericObject
}}
inline
{{
fieldType
}}
::Reader
{{
typeFullName
}}
::Reader::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<
{{
fieldType
}}
>
::get(
...
...
@@ -356,7 +356,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
inline
{{
fieldType
}}
::Builder
{{
typeFullName
}}
::Builder::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<
{{
fieldType
}}
>
::get(
...
...
@@ -413,7 +413,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
template
<typename
T
>
inline typename T::Reader
{{
typeFullName
}}
::Reader::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<T>
::get(
...
...
@@ -423,7 +423,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
template
<typename
T
>
inline typename T::Builder
{{
typeFullName
}}
::Builder::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<T>
::get(
...
...
@@ -433,7 +433,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
template
<typename
T
,
typename
Param
>
inline typename T::Reader
{{
typeFullName
}}
::Reader::get
{{
fieldTitleCase
}}
(Param
&&
param) {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<T>
::getDynamic(
...
...
@@ -443,7 +443,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&
template
<typename
T
,
typename
Param
>
inline typename T::Builder
{{
typeFullName
}}
::Builder::get
{{
fieldTitleCase
}}
(Param
&&
param) {
{{#
fieldUnion
}}
KJ_I
NLINE_DPRECOND
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
KJ_I
REQUIRE
(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<T>
::getDynamic(
...
...
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