[libc++/abi] Clean up uses of <iostream> in the test suite
We used <iostream> in several places where we don't actually need the
full power of <iostream>, and where using basic `std::printf` is enough.
This is better, since `std::printf` can be supported on systems that don't
have a notion of locales, while <iostream> can't.
GitOrigin-RevId: cc69d211d0d65d7bf0335fecbc323f784ac3afcc
diff --git a/src/fallback_malloc.cpp b/src/fallback_malloc.cpp
index fdae407..8c0fd6c 100644
--- a/src/fallback_malloc.cpp
+++ b/src/fallback_malloc.cpp
@@ -144,29 +144,26 @@
mutexor mtx(&heap_mutex);
#ifdef DEBUG_FALLBACK_MALLOC
- std::cout << "Freeing item at " << offset_from_node(cp) << " of size "
- << cp->len << std::endl;
+ std::printf("Freeing item at %d of size %d\n", offset_from_node(cp), cp->len);
#endif
for (p = freelist, prev = 0; p && p != list_end;
prev = p, p = node_from_offset(p->next_node)) {
#ifdef DEBUG_FALLBACK_MALLOC
- std::cout << " p, cp, after (p), after(cp) " << offset_from_node(p) << ' '
- << offset_from_node(cp) << ' ' << offset_from_node(after(p))
- << ' ' << offset_from_node(after(cp)) << std::endl;
+ std::printf(" p=%d, cp=%d, after(p)=%d, after(cp)=%d\n",
+ offset_from_node(p), offset_from_node(cp),
+ offset_from_node(after(p)), offset_from_node(after(cp)));
#endif
if (after(p) == cp) {
#ifdef DEBUG_FALLBACK_MALLOC
- std::cout << " Appending onto chunk at " << offset_from_node(p)
- << std::endl;
+ std::printf(" Appending onto chunk at %d\n", offset_from_node(p));
#endif
p->len = static_cast<heap_size>(
p->len + cp->len); // make the free heap_node larger
return;
} else if (after(cp) == p) { // there's a free heap_node right after
#ifdef DEBUG_FALLBACK_MALLOC
- std::cout << " Appending free chunk at " << offset_from_node(p)
- << std::endl;
+ std::printf(" Appending free chunk at %d\n", offset_from_node(p));
#endif
cp->len = static_cast<heap_size>(cp->len + p->len);
if (prev == 0) {
@@ -179,8 +176,7 @@
}
// Nothing to merge with, add it to the start of the free list
#ifdef DEBUG_FALLBACK_MALLOC
- std::cout << " Making new free list entry " << offset_from_node(cp)
- << std::endl;
+ std::printf(" Making new free list entry %d\n", offset_from_node(cp));
#endif
cp->next_node = offset_from_node(freelist);
freelist = cp;
@@ -195,11 +191,11 @@
for (p = freelist, prev = 0; p && p != list_end;
prev = p, p = node_from_offset(p->next_node)) {
- std::cout << (prev == 0 ? "" : " ") << "Offset: " << offset_from_node(p)
- << "\tsize: " << p->len << " Next: " << p->next_node << std::endl;
+ std::printf("%sOffset: %d\tsize: %d Next: %d\n",
+ (prev == 0 ? "" : " "), offset_from_node(p), p->len, p->next_node);
total_free += p->len;
}
- std::cout << "Total Free space: " << total_free << std::endl;
+ std::printf("Total Free space: %d\n", total_free);
return total_free;
}
#endif
diff --git a/test/catch_multi_level_pointer.pass.cpp b/test/catch_multi_level_pointer.pass.cpp
index 5aa0915..895e611 100644
--- a/test/catch_multi_level_pointer.pass.cpp
+++ b/test/catch_multi_level_pointer.pass.cpp
@@ -9,17 +9,17 @@
// UNSUPPORTED: no-exceptions
#include <cassert>
+#include <cstdio>
#include <cstdlib>
-#include <iostream>
// Roll our own assertion macro to get better error messages out of the tests.
// In particular on systems that don't use __PRETTY_FUNCTION__ in assertions.
#define my_assert(pred, msg) do_assert(pred, msg, __LINE__, __PRETTY_FUNCTION__)
void do_assert(bool assert_passed, const char* msg, int line, const char* func) {
- if (assert_passed) return;
- std::cerr << __FILE__ << ":" << line << " " << func
- << ": Assertion Failed `" << msg << "'\n\n";
+ if (assert_passed)
+ return;
+ std::printf("%s:%d %s: Assertion Failed '%s'\n\n", __FILE__, line, func, msg);
std::abort();
}
diff --git a/test/cxa_bad_typeid.pass.cpp b/test/cxa_bad_typeid.pass.cpp
index fc491d7..a1afe52 100644
--- a/test/cxa_bad_typeid.pass.cpp
+++ b/test/cxa_bad_typeid.pass.cpp
@@ -14,7 +14,6 @@
#include <exception>
#include <typeinfo>
#include <string>
-#include <iostream>
#include "test_macros.h"
@@ -28,7 +27,7 @@
return typeid(*p).name();
}
-void my_terminate() { std::cout << "A" << std::endl; exit(0); }
+void my_terminate() { exit(0); }
int main ()
{
diff --git a/test/support/timer.h b/test/support/timer.h
index 98a5dc0..7109627 100644
--- a/test/support/timer.h
+++ b/test/support/timer.h
@@ -13,7 +13,7 @@
#ifndef LIBCXXABI_NO_TIMER
#include <chrono>
-#include <iostream>
+#include <cstdio>
class timer
{
@@ -31,7 +31,7 @@
using std::chrono::duration_cast;
TimePoint end = Clock::now();
MicroSeconds us = duration_cast<MicroSeconds>(end - m_start);
- std::cout << us.count() << " microseconds\n";
+ std::printf("%d microseconds\n", us.count());
}
private:
diff --git a/test/test_aux_runtime.pass.cpp b/test/test_aux_runtime.pass.cpp
index 585fd7d..c79e0f5 100644
--- a/test/test_aux_runtime.pass.cpp
+++ b/test/test_aux_runtime.pass.cpp
@@ -9,7 +9,6 @@
// UNSUPPORTED: no-exceptions
#include <typeinfo>
-#include <iostream>
// Test taken from 5.2.8.2
// When typeid is applied to a glvalue expression whose type is a polymorphic
@@ -30,7 +29,7 @@
try {bool b = typeid(*bp) == typeid (A); ((void)b); }
catch ( const std::bad_typeid &) { return true; }
return false;
- }
+}
// The value of a failed cast to pointer type is the null pointer value of
@@ -46,20 +45,18 @@
try { D &dr = dynamic_cast<D&> (*bp); ((void)dr); }
catch ( const std::bad_cast & ) { return true; }
return false;
- }
+}
int main ( ) {
int ret_val = 0;
if ( !bad_typeid_test ()) {
- std::cerr << "TypeID test failed!" << std::endl;
ret_val = 1;
}
if ( !bad_cast_test ()) {
- std::cerr << "Bad cast test failed!" << std::endl;
- ret_val = 1;
+ ret_val = 2;
}
return ret_val;
- }
+}
diff --git a/test/test_aux_runtime_op_array_new.pass.cpp b/test/test_aux_runtime_op_array_new.pass.cpp
index cc73c3c..943ebe8 100644
--- a/test/test_aux_runtime_op_array_new.pass.cpp
+++ b/test/test_aux_runtime_op_array_new.pass.cpp
@@ -8,8 +8,8 @@
// UNSUPPORTED: no-exceptions
-#include <iostream>
#include <cxxabi.h>
+#include <new>
// If the expression passed to operator new[] would result in an overflow, the
// allocation function is not called, and a std::bad_array_new_length exception
@@ -31,7 +31,6 @@
int ret_val = 0;
if ( !bad_array_new_length_test ()) {
- std::cerr << "Bad array new length test failed!" << std::endl;
ret_val = 1;
}
diff --git a/test/test_demangle.pass.cpp b/test/test_demangle.pass.cpp
index f72b2ea..cbbccb1 100644
--- a/test/test_demangle.pass.cpp
+++ b/test/test_demangle.pass.cpp
@@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//
#include "support/timer.h"
-#include <iostream>
-#include <string>
+#include <cassert>
+#include <cstdio>
#include <cstdlib>
#include <cxxabi.h>
-#include <cassert>
+#include <string>
// Is long double fp80? (Only x87 extended double has 64-bit mantissa)
#define LDBL_FP80 (__LDBL_MANT_DIG__ == 64)
@@ -29901,17 +29901,16 @@
char* demang = __cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
if (demang == 0 || std::strcmp(demang, cases[i][1]) != 0)
{
- std::cout << "ERROR demangling " << cases[i][0] << '\n'
- << "expected: " << cases[i][1] << std::endl;
+ std::printf("ERROR demangling %s\nexpected: %s\n", cases[i][0], cases[i][1]);
if (demang)
{
- std::cout << " reality: " << demang << '\n' << std::endl;
+ std::printf(" reality: %s\n", demang);
buf = demang;
failed = true;
}
else
{
- std::cout << "Got instead: NULL, " << status << '\n';
+ std::printf("Got instead: NULL, %d\n", status);
failed = true;
}
}
@@ -29934,7 +29933,8 @@
char* demang = __cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
if (status != -2)
{
- std::cout << invalid_cases[i] << " should be invalid but is not\n" << " got status = " << status << '\n';
+ std::printf("%s should be invalid but is not\n", invalid_cases[i]);
+ std::printf("Got status %d\n", status);
assert(status == -2);
}
else
@@ -29964,8 +29964,8 @@
char* demang = __cxxabiv1::__cxa_demangle(xfail_cases[i], buf, &len, &status);
if (status != -2)
{
- std::cout << xfail_cases[i] << " was documented as xfail but passed\n"
- << "got status = " << status << '\n';
+ std::printf("%s was documented as xfail but passed\n", xfail_cases[i]);
+ std::printf("Got status = %d\n", status);
assert(status == -2);
}
else
@@ -29987,8 +29987,8 @@
char* demang = __cxxabiv1::__cxa_demangle(fpCase->mangled, buf, &len, &status);
if (demang == 0)
{
- std::cout << fpCase->mangled << " -> " << fpCase->expecting[0] << '\n';
- std::cout << "Got instead: NULL, " << status << '\n';
+ std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
+ std::printf("Got instead: NULL, %d\n", status);
assert(false);
continue;
}
@@ -29996,8 +29996,8 @@
std::string *e_end = fpCase->expecting + NEF;
if (std::find(e_beg, e_end, demang) == e_end)
{
- std::cout << fpCase->mangled << " -> " << fpCase->expecting[0] << '\n';
- std::cout << "Got instead: " << demang << '\n';
+ std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
+ std::printf("Got instead: %s\n", demang);
assert(false);
continue;
}
@@ -30008,7 +30008,7 @@
int main(int, char**)
{
- std::cout << "Testing " << N << " symbols." << std::endl;
+ std::printf("Testing %d symbols.\n", N);
{
timer t;
test();
diff --git a/test/test_exception_storage.pass.cpp b/test/test_exception_storage.pass.cpp
index 305a970..5c29c45 100644
--- a/test/test_exception_storage.pass.cpp
+++ b/test/test_exception_storage.pass.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include <cstdlib>
#include <algorithm>
-#include <iostream>
+#include <cstdio>
+#include <cstdlib>
#include <__threading_support>
#include <unistd.h>
@@ -19,19 +19,19 @@
void *thread_code (void *parm) {
size_t *result = (size_t *) parm;
globals_t *glob1, *glob2;
-
+
glob1 = __cxxabiv1::__cxa_get_globals ();
if ( NULL == glob1 )
- std::cerr << "Got null result from __cxa_get_globals" << std::endl;
+ std::printf("Got null result from __cxa_get_globals\n");
glob2 = __cxxabiv1::__cxa_get_globals_fast ();
if ( glob1 != glob2 )
- std::cerr << "Got different globals!" << std::endl;
-
+ std::printf("Got different globals!\n");
+
*result = (size_t) glob1;
sleep ( 1 );
return parm;
- }
+}
#ifndef _LIBCXXABI_HAS_NO_THREADS
#define NUMTHREADS 10
@@ -49,18 +49,20 @@
for ( int i = 0; i < NUMTHREADS; ++i )
std::__libcpp_thread_join ( &threads [ i ] );
- for ( int i = 0; i < NUMTHREADS; ++i )
+ for ( int i = 0; i < NUMTHREADS; ++i ) {
if ( 0 == thread_globals [ i ] ) {
- std::cerr << "Thread #" << i << " had a zero global" << std::endl;
+ std::printf("Thread #%d had a zero global\n", i);
retVal = 1;
- }
-
+ }
+ }
+
std::sort ( thread_globals, thread_globals + NUMTHREADS );
- for ( int i = 1; i < NUMTHREADS; ++i )
+ for ( int i = 1; i < NUMTHREADS; ++i ) {
if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) {
- std::cerr << "Duplicate thread globals (" << i-1 << " and " << i << ")" << std::endl;
+ std::printf("Duplicate thread globals (%d and %d)\n", i-1, i);
retVal = 2;
- }
+ }
+ }
#else // _LIBCXXABI_HAS_NO_THREADS
size_t thread_globals;
// Check that __cxa_get_globals() is not NULL.
diff --git a/test/test_fallback_malloc.pass.cpp b/test/test_fallback_malloc.pass.cpp
index 3b3fd9b..8b98659 100644
--- a/test/test_fallback_malloc.pass.cpp
+++ b/test/test_fallback_malloc.pass.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include <iostream>
+#include <cstdio>
#include <deque>
#include <__threading_support>
@@ -20,169 +20,169 @@
container alloc_series ( size_t sz ) {
container ptrs;
void *p;
-
+
while ( NULL != ( p = fallback_malloc ( sz )))
ptrs.push_back ( p );
return ptrs;
- }
+}
container alloc_series ( size_t sz, float growth ) {
container ptrs;
void *p;
-
+
while ( NULL != ( p = fallback_malloc ( sz ))) {
ptrs.push_back ( p );
sz *= growth;
- }
+ }
return ptrs;
- }
+}
container alloc_series ( const size_t *first, size_t len ) {
container ptrs;
const size_t *last = first + len;
void * p;
-
+
for ( const size_t *iter = first; iter != last; ++iter ) {
if ( NULL == (p = fallback_malloc ( *iter )))
break;
ptrs.push_back ( p );
- }
+ }
return ptrs;
- }
+}
void *pop ( container &c, bool from_end ) {
void *ptr;
if ( from_end ) {
ptr = c.back ();
c.pop_back ();
- }
+ }
else {
ptr = c.front ();
c.pop_front ();
- }
- return ptr;
}
+ return ptr;
+}
void exhaustion_test1 () {
container ptrs;
-
+
init_heap ();
- std::cout << "Constant exhaustion tests" << std::endl;
-
+ std::printf("Constant exhaustion tests\n");
+
// Delete in allocation order
ptrs = alloc_series ( 32 );
- std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
+ std::printf("Allocated %lu 32 byte chunks\n", ptrs.size());
print_free_list ();
for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
fallback_free ( *iter );
print_free_list ();
- std::cout << "----" << std::endl;
+ std::printf("----\n");
// Delete in reverse order
ptrs = alloc_series ( 32 );
- std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
+ std::printf("Allocated %lu 32 byte chunks\n", ptrs.size());
for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
fallback_free ( *iter );
print_free_list ();
- std::cout << "----" << std::endl;
+ std::printf("----\n");
// Alternate deletions
ptrs = alloc_series ( 32 );
- std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
+ std::printf("Allocated %lu 32 byte chunks\n", ptrs.size());
while ( ptrs.size () > 0 )
fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
print_free_list ();
- }
-
+}
+
void exhaustion_test2 () {
container ptrs;
init_heap ();
-
- std::cout << "Growing exhaustion tests" << std::endl;
+
+ std::printf("Growing exhaustion tests\n");
// Delete in allocation order
ptrs = alloc_series ( 32, 1.5 );
- std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl;
+
+ std::printf("Allocated %lu { 32, 48, 72, 108, 162 ... } byte chunks\n", ptrs.size());
print_free_list ();
for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
fallback_free ( *iter );
print_free_list ();
- std::cout << "----" << std::endl;
-
+ std::printf("----\n");
+
// Delete in reverse order
print_free_list ();
ptrs = alloc_series ( 32, 1.5 );
- std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl;
+ std::printf("Allocated %lu { 32, 48, 72, 108, 162 ... } byte chunks\n", ptrs.size());
for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
fallback_free ( *iter );
print_free_list ();
- std::cout << "----" << std::endl;
+ std::printf("----\n");
// Alternate deletions
ptrs = alloc_series ( 32, 1.5 );
- std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl;
+ std::printf("Allocated %lu { 32, 48, 72, 108, 162 ... } byte chunks\n", ptrs.size());
while ( ptrs.size () > 0 )
fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
- print_free_list ();
-
- }
+ print_free_list ();
+
+}
void exhaustion_test3 () {
const size_t allocs [] = { 124, 60, 252, 60, 4 };
container ptrs;
init_heap ();
-
- std::cout << "Complete exhaustion tests" << std::endl;
+
+ std::printf("Complete exhaustion tests\n");
// Delete in allocation order
ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
- std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
+ std::printf("Allocated %lu chunks\n", ptrs.size());
print_free_list ();
for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
fallback_free ( *iter );
print_free_list ();
- std::cout << "----" << std::endl;
-
+ std::printf("----\n");
+
// Delete in reverse order
print_free_list ();
ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
- std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
+ std::printf("Allocated %lu chunks\n", ptrs.size());
for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
fallback_free ( *iter );
print_free_list ();
- std::cout << "----" << std::endl;
+ std::printf("----\n");
// Alternate deletions
ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
- std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
+ std::printf("Allocated %lu chunks\n", ptrs.size());
while ( ptrs.size () > 0 )
fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
- print_free_list ();
-
- }
+ print_free_list ();
-
+}
+
+
int main () {
print_free_list ();
char *p = (char *) fallback_malloc ( 1024 ); // too big!
- std::cout << "fallback_malloc ( 1024 ) --> " << (unsigned long ) p << std::endl;
+ std::printf("fallback_malloc ( 1024 ) --> %lu\n", (unsigned long ) p);
print_free_list ();
-
+
p = (char *) fallback_malloc ( 32 );
- std::cout << "fallback_malloc ( 32 ) --> " << (unsigned long) (p - heap) << std::endl;
+ std::printf("fallback_malloc ( 32 ) --> %lu\n", (unsigned long) (p - heap));
if ( !is_fallback_ptr ( p ))
- std::cout << "### p is not a fallback pointer!!" << std::endl;
-
+ std::printf("### p is not a fallback pointer!!\n");
+
print_free_list ();
fallback_free ( p );
print_free_list ();
-
- std::cout << std::endl;
- exhaustion_test1 (); std::cout << std::endl;
- exhaustion_test2 (); std::cout << std::endl;
- exhaustion_test3 (); std::cout << std::endl;
+
+ exhaustion_test1();
+ exhaustion_test2();
+ exhaustion_test3();
return 0;
- }
+}
diff --git a/test/test_vector1.pass.cpp b/test/test_vector1.pass.cpp
index 10b77b0..86230c7 100644
--- a/test/test_vector1.pass.cpp
+++ b/test/test_vector1.pass.cpp
@@ -8,36 +8,36 @@
#include "cxxabi.h"
-#include <iostream>
-#include <cstdlib>
#include <cassert>
+#include <cstdio>
+#include <cstdlib>
#include "test_macros.h"
// Wrapper routines
void *my_alloc2 ( size_t sz ) {
void *p = std::malloc ( sz );
-// std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p );
+// std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p );
return p;
- }
-
+}
+
void my_dealloc2 ( void *p ) {
-// std::printf ( "Freeing %lx\n", (unsigned long) p );
- std::free ( p );
- }
+// std::printf ( "Freeing %lx\n", (unsigned long) p );
+ std::free ( p );
+}
void my_dealloc3 ( void *p, size_t ) {
-// std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz );
- std::free ( p );
- }
+// std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz );
+ std::free ( p );
+}
void my_construct ( void * ) {
// std::printf ( "Constructing %lx\n", (unsigned long) p );
- }
+}
void my_destruct ( void * ) {
// std::printf ( "Destructing %lx\n", (unsigned long) p );
- }
+}
int gCounter;
void count_construct ( void * ) { ++gCounter; }
@@ -72,7 +72,7 @@
void *storage;
vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct )) {}
~vec_on_stack () CAN_THROW {__cxxabiv1::__cxa_vec_delete ( storage, 40, 8, throw_destruct ); }
- };
+};
// Test calls with empty constructors and destructors
int test_empty ( ) {
@@ -86,7 +86,7 @@
__cxxabiv1::__cxa_vec_delete ( one, 40, 0, NULL );
__cxxabiv1::__cxa_vec_delete2( two, 40, 0, NULL, my_dealloc2 );
__cxxabiv1::__cxa_vec_delete3( three, 40, 0, NULL, my_dealloc3 );
-
+
// Try with no padding
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, my_construct, my_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc2 );
@@ -96,7 +96,7 @@
__cxxabiv1::__cxa_vec_delete2( two, 40, 0, my_destruct, my_dealloc2 );
__cxxabiv1::__cxa_vec_delete3( three, 40, 0, my_destruct, my_dealloc3 );
-// Padding and no con/destructors
+// Padding and no con/destructors
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, NULL, NULL );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc2 );
three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc3 );
@@ -105,7 +105,7 @@
__cxxabiv1::__cxa_vec_delete2( two, 40, 8, NULL, my_dealloc2 );
__cxxabiv1::__cxa_vec_delete3( three, 40, 8, NULL, my_dealloc3 );
-// Padding with con/destructors
+// Padding with con/destructors
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, my_construct, my_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc2 );
three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc3 );
@@ -115,7 +115,7 @@
__cxxabiv1::__cxa_vec_delete3( three, 40, 8, my_destruct, my_dealloc3 );
return 0;
- }
+}
// Make sure the constructors and destructors are matched
int test_counted ( ) {
@@ -123,24 +123,24 @@
void *one, *two, *three;
// Try with no padding
- gCounter = 0;
+ gCounter = 0;
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, count_construct, count_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc2 );
three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc3 );
-
+
__cxxabiv1::__cxa_vec_delete ( one, 40, 0, count_destruct );
__cxxabiv1::__cxa_vec_delete2( two, 40, 0, count_destruct, my_dealloc2 );
__cxxabiv1::__cxa_vec_delete3( three, 40, 0, count_destruct, my_dealloc3 );
-
-// Since there was no padding, the # of elements in the array are not stored
+
+// Since there was no padding, the # of elements in the array are not stored
// and the destructors are not called.
if ( gCounter != 30 ) {
- std::cerr << "Mismatched Constructor/Destructor calls (1)" << std::endl;
- std::cerr << " Expected 30, got " << gCounter << std::endl;
+ std::printf("Mismatched Constructor/Destructor calls (1)\n");
+ std::printf(" Expected 30, got %d\n", gCounter);
retVal = 1;
- }
-
- gCounter = 0;
+ }
+
+ gCounter = 0;
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, count_construct, count_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc2 );
three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc3 );
@@ -150,14 +150,14 @@
__cxxabiv1::__cxa_vec_delete3( three, 40, 8, count_destruct, my_dealloc3 );
if ( gCounter != 0 ) {
- std::cerr << "Mismatched Constructor/Destructor calls (2)" << std::endl;
- std::cerr << " Expected 0, got " << gCounter << std::endl;
+ std::printf("Mismatched Constructor/Destructor calls (2)\n");
+ std::printf(" Expected 0, got %d\n", gCounter);
retVal = 1;
- }
+ }
return retVal;
- }
-
+}
+
#ifndef TEST_HAS_NO_EXCEPTIONS
// Make sure the constructors and destructors are matched
int test_exception_in_constructor ( ) {
@@ -173,24 +173,23 @@
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, throw_construct, throw_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc2 );
three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc3 );
- }
+ }
catch ( int i ) {}
-
+
__cxxabiv1::__cxa_vec_delete ( one, 40, 0, throw_destruct );
__cxxabiv1::__cxa_vec_delete2( two, 40, 0, throw_destruct, my_dealloc2 );
__cxxabiv1::__cxa_vec_delete3( three, 40, 0, throw_destruct, my_dealloc3 );
-
-// Since there was no padding, the # of elements in the array are not stored
+
+// Since there was no padding, the # of elements in the array are not stored
// and the destructors are not called.
// Since we threw after 15 calls to the constructor, we should see 5 calls to
// the destructor from the partially constructed array.
if ( gConstructorCounter - gDestructorCounter != 10 ) {
- std::cerr << "Mismatched Constructor/Destructor calls (1C)" << std::endl;
- std::cerr << gConstructorCounter << " constructors, but " <<
- gDestructorCounter << " destructors" << std::endl;
+ std::printf("Mismatched Constructor/Destructor calls (1C)\n");
+ std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter);
retVal = 1;
- }
-
+ }
+
gConstructorCounter = gDestructorCounter = 0;
gConstructorThrowTarget = 15;
gDestructorThrowTarget = -1;
@@ -199,22 +198,21 @@
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 );
three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc3 );
- }
+ }
catch ( int i ) {}
-
+
__cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct );
__cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 );
__cxxabiv1::__cxa_vec_delete3( three, 40, 8, throw_destruct, my_dealloc3 );
if ( gConstructorCounter != gDestructorCounter ) {
- std::cerr << "Mismatched Constructor/Destructor calls (2C)" << std::endl;
- std::cerr << gConstructorCounter << " constructors, but " <<
- gDestructorCounter << " destructors" << std::endl;
+ std::printf("Mismatched Constructor/Destructor calls (2C)\n");
+ std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter);
retVal = 1;
- }
+ }
return retVal;
- }
+}
#endif
#ifndef TEST_HAS_NO_EXCEPTIONS
@@ -232,25 +230,24 @@
one = two = NULL;
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 );
- }
+ }
catch ( int i ) {}
-
+
try {
__cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct );
__cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 );
assert(false);
- }
+ }
catch ( int i ) {}
-
+
// We should have thrown in the middle of cleaning up "two", which means that
// there should be 20 calls to the destructor and the try block should exit
// before the assertion.
if ( gConstructorCounter != 20 || gDestructorCounter != 20 ) {
- std::cerr << "Unexpected Constructor/Destructor calls (1D)" << std::endl;
- std::cerr << "Expected (20, 20), but got (" << gConstructorCounter << ", " <<
- gDestructorCounter << ")" << std::endl;
+ std::printf("Unexpected Constructor/Destructor calls (1D)\n");
+ std::printf("Expected (20, 20), but got (%d, %d)\n", gConstructorCounter, gDestructorCounter);
retVal = 1;
- }
+ }
// Try throwing from a destructor - should be fine.
gConstructorCounter = gDestructorCounter = 0;
@@ -258,19 +255,18 @@
gDestructorThrowTarget = 5;
try { vec_on_stack v; }
catch ( int i ) {}
-
+
if ( gConstructorCounter != gDestructorCounter ) {
- std::cerr << "Mismatched Constructor/Destructor calls (2D)" << std::endl;
- std::cerr << gConstructorCounter << " constructors, but " <<
- gDestructorCounter << " destructors" << std::endl;
+ std::printf("Mismatched Constructor/Destructor calls (2D)\n");
+ std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter);
retVal = 1;
- }
+ }
return retVal;
- }
+}
#endif
-int main () {
+int main(int, char**) {
int retVal = 0;
retVal += test_empty ();
retVal += test_counted ();
@@ -279,4 +275,4 @@
retVal += test_exception_in_destructor ();
#endif
return retVal;
- }
+}
diff --git a/test/test_vector2.pass.cpp b/test/test_vector2.pass.cpp
index 21b5e86..dd09d2a 100644
--- a/test/test_vector2.pass.cpp
+++ b/test/test_vector2.pass.cpp
@@ -10,8 +10,9 @@
#include "cxxabi.h"
-#include <iostream>
+#include <cassert>
#include <cstdlib>
+#include <exception>
void my_terminate () { exit ( 0 ); }
@@ -20,25 +21,25 @@
void *p = std::malloc ( sz );
// std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p );
return p;
- }
+}
void my_dealloc2 ( void *p ) {
// std::printf ( "Freeing %lx\n", (unsigned long) p );
std::free ( p );
- }
+}
void my_dealloc3 ( void *p, size_t ) {
// std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz );
std::free ( p );
- }
+}
void my_construct ( void *) {
// std::printf ( "Constructing %lx\n", (unsigned long) p );
- }
+}
void my_destruct ( void *) {
// std::printf ( "Destructing %lx\n", (unsigned long) p );
- }
+}
int gCounter;
void count_construct ( void * ) { ++gCounter; }
@@ -56,7 +57,7 @@
void *storage;
vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct )) {}
~vec_on_stack () { __cxxabiv1::__cxa_vec_delete ( storage, 40, 8, throw_destruct ); }
- };
+};
// Make sure the constructors and destructors are matched
@@ -69,16 +70,17 @@
try {
vec_on_stack v;
throw 3;
- }
- catch ( int i ) {}
+ } catch ( int i ) {
- std::cerr << "should never get here" << std::endl;
}
+ assert(false && "should never get here");
+}
+
int main () {
std::set_terminate ( my_terminate );
test_exception_in_destructor ();
return 1; // we failed if we get here
- }
+}