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
21a508bb
Commit
21a508bb
authored
Aug 23, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add valgrind pass to test script. Fix valgrind errors.
parent
f66ca5e8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
10 deletions
+72
-10
array.c++
c++/src/kj/array.c++
+14
-8
exception-test.c++
c++/src/kj/exception-test.c++
+34
-0
exception.h
c++/src/kj/exception.h
+10
-0
io.c++
c++/src/kj/io.c++
+2
-2
super-test.sh
super-test.sh
+12
-0
No files found.
c++/src/kj/array.c++
View file @
21a508bb
...
...
@@ -22,6 +22,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "array.h"
#include "exception.h"
namespace
kj
{
...
...
@@ -62,38 +63,43 @@ void NullArrayDisposer::disposeImpl(
namespace
_
{
// private
struct
AutoDeleter
{
void
*
ptr
;
inline
void
*
release
()
{
void
*
result
=
ptr
;
ptr
=
nullptr
;
return
result
;
}
inline
AutoDeleter
(
void
*
ptr
)
:
ptr
(
ptr
)
{}
inline
~
AutoDeleter
()
{
operator
delete
(
ptr
);
}
};
void
*
HeapArrayDisposer
::
allocateImpl
(
size_t
elementSize
,
size_t
elementCount
,
size_t
capacity
,
void
(
*
constructElement
)(
void
*
),
void
(
*
destroyElement
)(
void
*
))
{
void
*
result
=
operator
new
(
elementSize
*
capacity
);
AutoDeleter
result
(
operator
new
(
elementSize
*
capacity
)
);
if
(
constructElement
==
nullptr
)
{
// Nothing to do.
}
else
if
(
destroyElement
==
nullptr
)
{
byte
*
pos
=
reinterpret_cast
<
byte
*>
(
result
);
byte
*
pos
=
reinterpret_cast
<
byte
*>
(
result
.
ptr
);
while
(
elementCount
>
0
)
{
constructElement
(
pos
);
pos
+=
elementSize
;
--
elementCount
;
}
}
else
{
ExceptionSafeArrayUtil
guard
(
result
,
elementSize
,
0
,
destroyElement
);
ExceptionSafeArrayUtil
guard
(
result
.
ptr
,
elementSize
,
0
,
destroyElement
);
guard
.
construct
(
elementCount
,
constructElement
);
guard
.
release
();
}
return
result
;
return
result
.
release
()
;
}
void
HeapArrayDisposer
::
disposeImpl
(
void
*
firstElement
,
size_t
elementSize
,
size_t
elementCount
,
size_t
capacity
,
void
(
*
destroyElement
)(
void
*
))
const
{
// Note that capacity is ignored since operator delete() doesn't care about it.
AutoDeleter
deleter
(
firstElement
);
if
(
destroyElement
==
nullptr
)
{
operator
delete
(
firstElement
);
}
else
{
KJ_DEFER
(
operator
delete
(
firstElement
));
if
(
destroyElement
!=
nullptr
)
{
ExceptionSafeArrayUtil
guard
(
firstElement
,
elementSize
,
elementCount
,
destroyElement
);
guard
.
destroyAll
();
}
...
...
c++/src/kj/exception-test.c++
View file @
21a508bb
...
...
@@ -95,6 +95,40 @@ TEST(Exception, ExceptionCallbackMustBeOnStack) {
#endif
}
#if !KJ_NO_EXCEPTIONS
TEST
(
Exception
,
ScopeSuccessFail
)
{
bool
success
=
false
;
bool
failure
=
false
;
{
KJ_ON_SCOPE_SUCCESS
(
success
=
true
);
KJ_ON_SCOPE_FAILURE
(
failure
=
true
);
EXPECT_FALSE
(
success
);
EXPECT_FALSE
(
failure
);
}
EXPECT_TRUE
(
success
);
EXPECT_FALSE
(
failure
);
success
=
false
;
failure
=
false
;
try
{
KJ_ON_SCOPE_SUCCESS
(
success
=
true
);
KJ_ON_SCOPE_FAILURE
(
failure
=
true
);
EXPECT_FALSE
(
success
);
EXPECT_FALSE
(
failure
);
throw
1
;
}
catch
(
int
)
{}
EXPECT_FALSE
(
success
);
EXPECT_TRUE
(
failure
);
}
#endif
}
// namespace
}
// namespace _ (private)
}
// namespace kj
c++/src/kj/exception.h
View file @
21a508bb
...
...
@@ -262,6 +262,16 @@ void UnwindDetector::catchExceptionsIfUnwinding(Func&& func) const {
}
}
#define KJ_ON_SCOPE_SUCCESS(code) \
::kj::UnwindDetector KJ_UNIQUE_NAME(_kjUnwindDetector); \
KJ_DEFER(if (!KJ_UNIQUE_NAME(_kjUnwindDetector).isUnwinding()) { code; })
// Runs `code` if the current scope is exited normally (not due to an exception).
#define KJ_ON_SCOPE_FAILURE(code) \
::kj::UnwindDetector KJ_UNIQUE_NAME(_kjUnwindDetector); \
KJ_DEFER(if (KJ_UNIQUE_NAME(_kjUnwindDetector).isUnwinding()) { code; })
// Runs `code` if the current scope is exited due to an exception.
}
// namespace kj
#endif // KJ_EXCEPTION_H_
c++/src/kj/io.c++
View file @
21a508bb
...
...
@@ -295,11 +295,11 @@ void FdOutputStream::write(ArrayPtr<const ArrayPtr<const byte>> pieces) {
}
while
(
current
<
iov
.
end
())
{
ssize_t
n
;
ssize_t
n
=
0
;
KJ_SYSCALL
(
n
=
::
writev
(
fd
,
current
,
iov
.
end
()
-
current
),
fd
);
KJ_ASSERT
(
n
>
0
,
"writev() returned zero."
);
while
(
static_cast
<
size_t
>
(
n
)
>=
current
->
iov_len
)
{
while
(
n
>
0
&&
static_cast
<
size_t
>
(
n
)
>=
current
->
iov_len
)
{
n
-=
current
->
iov_len
;
++
current
;
}
...
...
super-test.sh
View file @
21a508bb
...
...
@@ -289,6 +289,18 @@ doit make distclean
doit ./configure
--disable-shared
CXXFLAGS
=
"
$CXXFLAGS
-fno-rtti -fno-exceptions"
doit make
-j6
check
if
which valgrind
>
/dev/null
;
then
echo
"========================================================================="
echo
"Testing with valgrind"
echo
"========================================================================="
doit ./configure
--disable-shared
CXXFLAGS
=
"-g"
doit make
-j6
doit make
-j6
capnp-test
doin valgrind
--leak-check
=
full
--track-fds
=
yes
--error-exitcode
=
1 capnp-test
doit make distclean
fi
doit make maintainer-clean
rm
-rf
"
$STAGING
"
...
...
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