[Assorted-commits] SF.net SVN: assorted:[1231] cpp-commons/trunk
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-02-25 07:45:31
|
Revision: 1231 http://assorted.svn.sourceforge.net/assorted/?rev=1231&view=rev Author: yangzhang Date: 2009-02-25 07:45:26 +0000 (Wed, 25 Feb 2009) Log Message: ----------- lots of general cleanup - fixed warnings on remaining files - added swap for arrays, size_t - in st_reader, using (the faster) memcpy instead of (the slower) copy, after some experiments - using new check functions in load_file() - added algo.h, with just swap() - fixed missing includes - fixed include guards - added tools for generating build tests, checking include guard names, listing sources - added test Makefile with lots of warnings - moved files around so that third-party sources are not in commons/ - updated the README Modified Paths: -------------- cpp-commons/trunk/README cpp-commons/trunk/src/commons/array.h cpp-commons/trunk/src/commons/cpuid.h cpp-commons/trunk/src/commons/delegates.h cpp-commons/trunk/src/commons/exceptions.h cpp-commons/trunk/src/commons/files.h cpp-commons/trunk/src/commons/pthread/barrier.h cpp-commons/trunk/src/commons/rand.h cpp-commons/trunk/src/commons/region.h cpp-commons/trunk/src/commons/st/st.h cpp-commons/trunk/src/commons/strings.h cpp-commons/trunk/src/commons/threads.h cpp-commons/trunk/src/commons/x86asm.h Added Paths: ----------- cpp-commons/trunk/src/boost/ cpp-commons/trunk/src/boost/unique_ptr.hpp cpp-commons/trunk/src/commons/algo.h cpp-commons/trunk/src/test/Makefile cpp-commons/trunk/src/yonat/ cpp-commons/trunk/tools/check.bash Removed Paths: ------------- cpp-commons/trunk/src/commons/unique_ptr.hpp cpp-commons/trunk/src/commons/yonat/ cpp-commons/trunk/src/test/all.cc Modified: cpp-commons/trunk/README =================================================================== --- cpp-commons/trunk/README 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/README 2009-02-25 07:45:26 UTC (rev 1231) @@ -14,7 +14,6 @@ - RAII utilities, such as for closing file descriptors and `finally` objects - smart arrays: sized arrays, "managed" (moveable, conditionally scope-destroyed) arrays -- Howard Hinnant's C++03-emulated TR1 `unique_ptr.hpp` - `pool`: fixed-size object pools - bit manipulation - bundles of header includes @@ -40,6 +39,20 @@ - micro-utilities: noncopyable, expander annotations - x86 architecture-specific tools +Third-party code: + +- Howard Hinnant's [C++03-emulated TR1 `unique_ptr.hpp`] +- [Yonat's STL extensions] + - pointainer: auto-cleaning STL container of pointers. Many times this is a + better alternative than using smart pointers (no overhead, no + multi-threading problems). + - pointerator: iterator to T* that behaves like iterator to T. Useful for + iterating pointainers and containers of smart pointers. + - stringizer: turns an object into a std::string. + +[C++03-emulated TR1 `unique_ptr.hpp`]: http://home.roadrunner.com/~hinnant/unique_ptr03.html +[Yonat's STL extensions]: http://ootips.org/yonat/4dev/ + Setup ----- Copied: cpp-commons/trunk/src/boost/unique_ptr.hpp (from rev 1219, cpp-commons/trunk/src/commons/unique_ptr.hpp) =================================================================== --- cpp-commons/trunk/src/boost/unique_ptr.hpp (rev 0) +++ cpp-commons/trunk/src/boost/unique_ptr.hpp 2009-02-25 07:45:26 UTC (rev 1231) @@ -0,0 +1,535 @@ +/////////////////////////////////////////////////////////////////////////////// +// unique_ptr.hpp header file +// +// Copyright 2009 Howard Hinnant, Ion Gaztañaga. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// See http://www.boost.org/libs/foreach for documentation + +// This is a C++03 emulation of std::unique_ptr placed in namespace boost. +// Reference http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf +// for the latest unique_ptr specification, and +// reference http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html +// for any pending issues against this specification. + +#ifndef UNIQUE_PTR_HPP +#define UNIQUE_PTR_HPP + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits.hpp> +#include <boost/static_assert.hpp> +#include <boost/mpl/if.hpp> + +namespace boost +{ + +namespace detail_unique_ptr +{ + +typedef char one; +struct two {one _[2];}; + +// An is_convertible<From, To> that considers From an rvalue (consistent with C++0X). +// This is a simplified version neglecting the types function, array, void and abstract types +// I had to make a special case out of is_convertible<T,T> to make move-only +// types happy. + +namespace is_conv_imp +{ +template <class T> one test1(const T&); +template <class T> two test1(...); +template <class T> one test2(T); +template <class T> two test2(...); +template <class T> T source(); +} + +template <class T1, class T2> +struct is_convertible +{ + static const bool value = sizeof(is_conv_imp::test1<T2>(is_conv_imp::source<T1>())) == 1; +}; + +template <class T> +struct is_convertible<T, T> +{ + static const bool value = sizeof(is_conv_imp::test2<T>(is_conv_imp::source<T>())) == 1; +}; + +template <class T> +class rv +{ + T& r_; + +public: + explicit rv(T& r) : r_(r) {} + T* operator->() {return &r_;} + T& operator*() {return r_;} +}; + +template <class T> +struct identity +{ + typedef T type; +}; + +} // detail_unique_ptr + +template <class T> +inline +typename enable_if_c +< + !detail_unique_ptr::is_convertible<T, detail_unique_ptr::rv<T> >::value, + T& +>::type +move(T& t) +{ + return t; +} + +template <class T> +inline +typename enable_if_c +< + !detail_unique_ptr::is_convertible<T, detail_unique_ptr::rv<T> >::value, + const T& +>::type +move(const T& t) +{ + return t; +} + +template <class T> +inline +typename enable_if_c +< + detail_unique_ptr::is_convertible<T, detail_unique_ptr::rv<T> >::value, + T +>::type +move(T& t) +{ + return T(detail_unique_ptr::rv<T>(t)); +} + +template <class T> +inline +typename enable_if_c +< + is_reference<T>::value, + T +>::type +forward(typename detail_unique_ptr::identity<T>::type t) +{ + return t; +} + +template <class T> +inline +typename enable_if_c +< + !is_reference<T>::value, + T +>::type +forward(typename detail_unique_ptr::identity<T>::type& t) +{ + return move(t); +} + +template <class T> +inline +typename enable_if_c +< + !is_reference<T>::value, + T +>::type +forward(const typename detail_unique_ptr::identity<T>::type& t) +{ + return move(const_cast<T&>(t)); +} + +namespace detail_unique_ptr { + +// A move-aware but stripped-down compressed_pair which only optimizes storage for T2 +template <class T1, class T2, bool = is_empty<T2>::value> +class unique_ptr_storage +{ + T1 t1_; + T2 t2_; + + typedef typename add_reference<T2>::type T2_reference; + typedef typename add_reference<const T2>::type T2_const_reference; + + unique_ptr_storage(const unique_ptr_storage&); + unique_ptr_storage& operator=(const unique_ptr_storage&); +public: + operator rv<unique_ptr_storage>() {return rv<unique_ptr_storage>(*this);} + + unique_ptr_storage() : t1_(), t2_() {} + + explicit unique_ptr_storage(T1 t1) + : t1_(move(t1)), t2_() {} + + unique_ptr_storage(T1 t1, T2 t2) + : t1_(move(t1)), t2_(forward<T2>(t2)) {} + + T1& first() {return t1_;} + const T1& first() const {return t1_;} + + T2_reference second() {return t2_;} + T2_const_reference second() const {return t2_;} +}; + +template <class T1, class T2> +class unique_ptr_storage<T1, T2, true> + : private T2 +{ + T1 t1_; + typedef T2 t2_; + + unique_ptr_storage(const unique_ptr_storage&); + unique_ptr_storage& operator=(const unique_ptr_storage&); +public: + operator rv<unique_ptr_storage>() {return rv<unique_ptr_storage>(*this);} + + unique_ptr_storage() : t1_() {} + + explicit unique_ptr_storage(T1 t1) + : t1_(move(t1)) {} + + unique_ptr_storage(T1 t1, T2 t2) + : t2_(move(t2)), t1_(move(t1)) {} + + T1& first() {return t1_;} + const T1& first() const {return t1_;} + + T2& second() {return *this;} + const T2& second() const {return *this;} +}; + +template <class T1, class T2, bool b> +inline +void +swap(unique_ptr_storage<T1, T2, b>& x, unique_ptr_storage<T1, T2, b>& y) +{ + using std::swap; + swap(x.first(), y.first()); + swap(x.second(), y.second()); +} + +} // detail_unique_ptr + +template <class T> +struct default_delete +{ + default_delete() {} + template <class U> + default_delete(const default_delete<U>&, + typename enable_if_c<detail_unique_ptr::is_convertible<U*, T*>::value>::type* = 0) + {} + + void operator()(T* ptr) const + { + BOOST_STATIC_ASSERT(sizeof(T) > 0); + delete ptr; + } +}; + +template <class T> +struct default_delete<T[]> +{ + void operator()(T* ptr) const + { + BOOST_STATIC_ASSERT(sizeof(T) > 0); + delete [] ptr; + } + +private: + + template <class U> void operator()(U*) const; +}; + +namespace detail_unique_ptr +{ + +namespace pointer_type_imp +{ + +template <class U> static two test(...); +template <class U> static one test(typename U::pointer* = 0); + +} // pointer_type_imp + +template <class T> +struct has_pointer_type +{ + static const bool value = sizeof(pointer_type_imp::test<T>(0)) == 1; +}; + +namespace pointer_type_imp +{ + +template <class T, class D, bool = has_pointer_type<D>::value> +struct pointer_type +{ + typedef typename D::pointer type; +}; + +template <class T, class D> +struct pointer_type<T, D, false> +{ + typedef T* type; +}; + +} // pointer_type_imp + +template <class T, class D> +struct pointer_type +{ + typedef typename pointer_type_imp::pointer_type<T, + typename boost::remove_reference<D>::type>::type type; +}; + +} // detail_unique_ptr + +template <class T, class D = default_delete<T> > +class unique_ptr +{ +public: + typedef T element_type; + typedef D deleter_type; + typedef typename detail_unique_ptr::pointer_type<element_type, deleter_type>::type pointer; + +private: + detail_unique_ptr::unique_ptr_storage<pointer, deleter_type> ptr_; + + typedef typename add_reference<deleter_type>::type deleter_reference; + typedef typename add_reference<const deleter_type>::type deleter_const_reference; + + struct nat {int for_bool_;}; + + unique_ptr(unique_ptr&); + unique_ptr& operator=(unique_ptr&); + +public: + operator detail_unique_ptr::rv<unique_ptr>() {return detail_unique_ptr::rv<unique_ptr>(*this);} + unique_ptr(detail_unique_ptr::rv<unique_ptr> r) : ptr_(r->release(), forward<deleter_type>(r->get_deleter())) {} + unique_ptr& operator=(detail_unique_ptr::rv<unique_ptr> r) + { + reset(r->release()); + ptr_.second() = move(r->get_deleter()); + return *this; + } + + unique_ptr() + { + BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); + BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); + } + + explicit unique_ptr(pointer p) + : ptr_(p) + { + BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); + BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); + } + + unique_ptr(pointer p, typename mpl::if_<is_reference<D>, + volatile typename remove_reference<D>::type&, D>::type d) + : ptr_(move(p), forward<D>(const_cast<typename add_reference<D>::type>(d))) {} + + template <class U, class E> + unique_ptr(unique_ptr<U, E> u, + typename enable_if_c + < + !boost::is_array<U>::value && + detail_unique_ptr::is_convertible<typename unique_ptr<U>::pointer, pointer>::value && + detail_unique_ptr::is_convertible<E, deleter_type>::value && + ( + !is_reference<deleter_type>::value || + is_same<deleter_type, E>::value + ) + >::type* = 0) + : ptr_(u.release(), forward<D>(forward<E>(u.get_deleter()))) {} + + ~unique_ptr() {reset();} + + unique_ptr& operator=(int nat::*) + { + reset(); + return *this; + } + + template <class U, class E> + unique_ptr& + operator=(unique_ptr<U, E> u) + { + reset(u.release()); + ptr_.second() = move(u.get_deleter()); + return *this; + } + + typename add_reference<T>::type operator*() const {return *get();} + pointer operator->() const {return get();} + pointer get() const {return ptr_.first();} + deleter_reference get_deleter() {return ptr_.second();} + deleter_const_reference get_deleter() const {return ptr_.second();} + operator int nat::*() const {return get() ? &nat::for_bool_ : 0;} + + void reset(pointer p = pointer()) + { + pointer t = get(); + if (t != pointer()) + get_deleter()(t); + ptr_.first() = p; + } + + pointer release() + { + pointer tmp = get(); + ptr_.first() = pointer(); + return tmp; + } + + void swap(unique_ptr& u) {detail_unique_ptr::swap(ptr_, u.ptr_);} +}; + +template <class T, class D> +class unique_ptr<T[], D> +{ +public: + typedef T element_type; + typedef D deleter_type; + typedef typename detail_unique_ptr::pointer_type<element_type, deleter_type>::type pointer; + +private: + detail_unique_ptr::unique_ptr_storage<pointer, deleter_type> ptr_; + + typedef typename add_reference<deleter_type>::type deleter_reference; + typedef typename add_reference<const deleter_type>::type deleter_const_reference; + + struct nat {int for_bool_;}; + + unique_ptr(unique_ptr&); + unique_ptr& operator=(unique_ptr&); + +public: + operator detail_unique_ptr::rv<unique_ptr>() {return detail_unique_ptr::rv<unique_ptr>(*this);} + unique_ptr(detail_unique_ptr::rv<unique_ptr> r) : ptr_(r->release(), forward<deleter_type>(r->get_deleter())) {} + unique_ptr& operator=(detail_unique_ptr::rv<unique_ptr> r) + { + reset(r->release()); + ptr_.second() = move(r->get_deleter()); + return *this; + } + + unique_ptr() + { + BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); + BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); + } + + explicit unique_ptr(pointer p) + : ptr_(p) + { + BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); + BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); + } + + unique_ptr(pointer p, typename mpl::if_<is_reference<D>, + volatile typename remove_reference<D>::type&, D>::type d) + : ptr_(move(p), forward<D>(const_cast<typename add_reference<D>::type>(d))) {} + + ~unique_ptr() {reset();} + + T& operator[](size_t i) const {return get()[i];} + pointer get() const {return ptr_.first();} + deleter_reference get_deleter() {return ptr_.second();} + deleter_const_reference get_deleter() const {return ptr_.second();} + operator int nat::*() const {return get() ? &nat::for_bool_ : 0;} + + void reset(pointer p = pointer()) + { + pointer t = get(); + if (t != pointer()) + get_deleter()(t); + ptr_.first() = p; + } + + pointer release() + { + pointer tmp = get(); + ptr_.first() = pointer(); + return tmp; + } + + void swap(unique_ptr& u) {detail_unique_ptr::swap(ptr_, u.ptr_);} +private: + template <class U> + explicit unique_ptr(U, + typename enable_if_c<detail_unique_ptr::is_convertible<U, pointer>::value>::type* = 0); + + template <class U> + unique_ptr(U, typename mpl::if_<is_reference<D>, + volatile typename remove_reference<D>::type&, D>::type, + typename enable_if_c<detail_unique_ptr::is_convertible<U, pointer>::value>::type* = 0); +}; + +template<class T, class D> +inline +void +swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) +{ + x.swap(y); +} + +template<class T1, class D1, class T2, class D2> +inline +bool +operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) +{ + return x.get() == y.get(); +} + +template<class T1, class D1, class T2, class D2> +inline +bool +operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) +{ + return !(x == y); +} + +template<class T1, class D1, class T2, class D2> +inline +bool +operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) +{ + return x.get() < y.get(); +} + +template<class T1, class D1, class T2, class D2> +inline +bool +operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) +{ + return !(y < x); +} + +template<class T1, class D1, class T2, class D2> +inline +bool +operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) +{ + return y < x; +} + +template<class T1, class D1, class T2, class D2> +inline +bool +operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) +{ + return !(x < y); +} + +} // boost + +#endif // UNIQUE_PTR_HPP Added: cpp-commons/trunk/src/commons/algo.h =================================================================== --- cpp-commons/trunk/src/commons/algo.h (rev 0) +++ cpp-commons/trunk/src/commons/algo.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -0,0 +1,16 @@ +#ifndef COMMONS_ALGO_H +#define COMMONS_ALGO_H + +#include <sys/types.h> + +namespace commons { + + void swap(size_t &x, size_t &y) { + x = x ^ y; + y = x ^ y; + x = x ^ y; + } + +} + +#endif Modified: cpp-commons/trunk/src/commons/array.h =================================================================== --- cpp-commons/trunk/src/commons/array.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/array.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -1,15 +1,19 @@ #ifndef COMMONS_ARRAY_H #define COMMONS_ARRAY_H +#include <boost/unique_ptr.hpp> +#include <commons/algo.h> #include <commons/check.h> #include <commons/nullptr.h> -#include <commons/unique_ptr.hpp> #include <commons/utility.h> namespace commons { using namespace boost; + template<typename T> class array; + template<typename T> void swap(array<T> &a, array<T> &b); + /** * A thin wrapper around arrays. Like a fixed-size vector. Unlike array * since the size can be dynamically determined. @@ -17,6 +21,7 @@ template<typename T> class array { EXPAND(unique_ptr<T[]>) + friend void swap<>(array<T> &a, array<T> &b); public: explicit array(size_t n) : p_(checkpass(new T[n])), n_(n) {} size_t size() const { return n_; } @@ -30,6 +35,17 @@ }; /** + * Swap two arrays. + */ + template<typename T> + void + swap(array<T> &a, array<T> &b) + { + swap(a.p_, b.p_); + swap(a.n_, b.n_); + } + + /** * Conditionally-scoped, move-able, release-able, un-sized array. */ template<typename T> Modified: cpp-commons/trunk/src/commons/cpuid.h =================================================================== --- cpp-commons/trunk/src/commons/cpuid.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/cpuid.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -31,7 +31,7 @@ { unsigned int a, b, c, d; cpuid(1, a, b, c, d); - return (unsigned short) (high(b) * 8); + return static_cast<unsigned short>(high(b) * 8); } /** Modified: cpp-commons/trunk/src/commons/delegates.h =================================================================== --- cpp-commons/trunk/src/commons/delegates.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/delegates.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -1,5 +1,5 @@ -#ifndef COMMONS_BOOST_DELEGATES_H -#define COMMONS_BOOST_DELEGATES_H +#ifndef COMMONS_DELEGATES_H +#define COMMONS_DELEGATES_H #include <boost/function.hpp> #include <boost/scoped_ptr.hpp> Modified: cpp-commons/trunk/src/commons/exceptions.h =================================================================== --- cpp-commons/trunk/src/commons/exceptions.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/exceptions.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -2,6 +2,7 @@ #define COMMONS_EXCEPTIONS_H #include <exception> +#include <string> namespace commons { Modified: cpp-commons/trunk/src/commons/files.h =================================================================== --- cpp-commons/trunk/src/commons/files.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/files.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -19,7 +19,7 @@ using namespace std; - class file_not_found_exception : exception { + class file_not_found_exception : std::exception { public: file_not_found_exception(const string & name) : name(name) {} virtual ~file_not_found_exception() throw() {} @@ -50,40 +50,35 @@ * buffer (size of the file). * TODO this probably isn't very safe, since we're demoting an off_t to a * size_t. Is there a healthier approach? - * TODO move to C99 commons */ char * - load_file(const char *path, size_t & len, unsigned int ncpus) { + load_file(const char *path, size_t & len, unsigned int ncpus) + { struct stat sb; - int fd; + int fd = checkpass(open(path, 0)); - fd = open(path, 0); - check(fd >= 0); - - check(fstat(fd, &sb) == 0); + check0x(fstat(fd, &sb)); check(sb.st_size <= 0xffffffff); // TODO Why don't we need (static) cast here? Isn't this a lossy cast? len = sb.st_size; - char *buf = new char[len + 1]; - check(buf); + char *buf = checkpass(new char[len + 1]); + checkeqnneg(pread(fd, buf, len, 0), static_cast<ssize_t>(len)); - ssize_t status = pread(fd, buf, len, 0); - size_t nread = static_cast<size_t>(status); - check(status != -1 && nread == len); - // TODO Use threads to pull data to the correct initial locations? - // size_t chunk_len = len / ncpus; - // for (unsigned int i = 0; i < ncpus; i++) { - // int off = i *chunk_len; - // ssize_t status = pread(fd, buf + off, chunk_len, off); - // // We read the whole chunk or hit the end. - // size_t nread = static_cast<size_t>(status); - // check(status != -1 && (nread == chunk_len || off + nread == len)); - // } + if (false) { + size_t chunk_len = len / ncpus; + for (unsigned int i = 0; i < ncpus; i++) { + size_t off = i * chunk_len; + size_t nread = static_cast<size_t> + (checknnegerr(pread(fd, buf + off, chunk_len, off))); + // We read the whole chunk or hit the end. + check(nread == chunk_len || off + nread == len); + } + } - check(close(fd) == 0); + check0x(close(fd)); buf[len] = '\0'; // don't let strcmp() run off the end return buf; Modified: cpp-commons/trunk/src/commons/pthread/barrier.h =================================================================== --- cpp-commons/trunk/src/commons/pthread/barrier.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/pthread/barrier.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -21,7 +21,8 @@ }; int -pthread_barrier_init(pthread_barrier_t* b, pthread_barrierattr_t* a, unsigned count) +pthread_barrier_init(pthread_barrier_t* b, pthread_barrierattr_t*, + unsigned count) { check0(pthread_mutex_init(&b->lock, NULL)); check0(pthread_cond_init (&b->cond, NULL)); Modified: cpp-commons/trunk/src/commons/rand.h =================================================================== --- cpp-commons/trunk/src/commons/rand.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/rand.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -1,5 +1,5 @@ -#ifndef COMMONS_RAND_H_ -#define COMMONS_RAND_H_ +#ifndef COMMONS_RAND_H +#define COMMONS_RAND_H #include <cassert> #include <cstdlib> // random, RAND_MAX Modified: cpp-commons/trunk/src/commons/region.h =================================================================== --- cpp-commons/trunk/src/commons/region.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/region.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -173,14 +173,16 @@ */ pointer allocate(size_type num, const void* = 0) { - return (pointer) region->alloc_mem(num * sizeof(T)); + return reinterpret_cast<pointer>(region->alloc_mem(num * sizeof(T))); } /** * Initialize elements of allocated storage p with value `value` using * placement new. */ - void construct(pointer p, const T& value) { new((void*)p)T(value); } + void construct(pointer p, const T& value) { + new (static_cast<void*>(p)) T(value); + } /** * Destroy elements of initialized storage p by calling their destructor. Modified: cpp-commons/trunk/src/commons/st/st.h =================================================================== --- cpp-commons/trunk/src/commons/st/st.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/st/st.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -401,6 +401,11 @@ size_t rem() { return buf_.end() - end_; } /** + * The entire read buffer. + */ + array<char> &buf() { return buf_; } + + /** * Discard the requested number of bytes. */ void skip(size_t req, st_utime_t to = ST_UTIME_NO_TIMEOUT) { @@ -440,7 +445,7 @@ // Handle large arrays specially. if (req > buf_.size()) { managed_array<char> p(checkpass(new char[req]), true); - copy(start_, end_, p.get()); + memcpy(p.get(), start_, unread()); checkeqnneg(st_read_fully(fd_, p + unread(), req - unread(), to), static_cast<ssize_t>(req - unread())); start_ = end_ = buf_.get(); return p; @@ -448,7 +453,7 @@ // Shift things down if necessary. if (req > static_cast<size_t>(buf_.end() - end_)) { - copy(start_, end_, buf_.get()); + memmove(buf_.get(), start_, unread()); size_t diff = start_ - buf_.get(); start_ -= diff; end_ -= diff; @@ -486,7 +491,7 @@ // Shift things down if necessary. if (req > static_cast<size_t>(buf_.end() - end_)) { - copy(start_, end_, buf_.get()); + memmove(buf_.get(), start_, unread()); size_t diff = start_ - buf_.get(); start_ -= diff; end_ -= diff; Modified: cpp-commons/trunk/src/commons/strings.h =================================================================== --- cpp-commons/trunk/src/commons/strings.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/strings.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -49,19 +49,21 @@ /** * Look for a substring, but without null-termination conventions. + * + * TODO: remove or fix */ inline char * - unsafe_strstr(char *p, const char *q, const char *lim) + unsafe_strstr(char *p, const char *, const char *lim) { if (lim == 0) { while (true) { - for (; !(*p == '\0' && *(p+1) == '\0'); p++); + for (; !(*p == '\0' && *(p+1) == '\0'); p++) {} return p; } } else { check(p < lim); while (true) { - for (; !(*p == '\0' && *(p+1) == '\0') && p < lim; p++); + for (; !(*p == '\0' && *(p+1) == '\0') && p < lim; p++) {} if (p == lim) return NULL; return p; } @@ -74,7 +76,7 @@ inline const char* unsafe_strstr(const char *p, const char *q, const char *lim) { - return unsafe_strstr((char*) p, q, lim); + return unsafe_strstr(const_cast<char*>(p), q, lim); } /** @@ -87,9 +89,9 @@ scan(const void* buf, size_t len) { char sum = 0; - const char* start = (const char*) buf; + const char* start = reinterpret_cast<const char*>(buf); for (const char* p = start; p < start + len; p++) { - sum += *p; + sum = static_cast<char>(sum | *p); } return sum; } @@ -105,7 +107,7 @@ { const size_t sz = 1024; char tmp[sz]; - const char* p = (const char*) buf; + const char* p = reinterpret_cast<const char*>(buf); const char* end = p + len; for (; p + sz < end; p += 1024) { memcpy(tmp, p, sz); Modified: cpp-commons/trunk/src/commons/threads.h =================================================================== --- cpp-commons/trunk/src/commons/threads.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/threads.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -2,6 +2,7 @@ #define COMMONS_THREADS_H #include <pthread.h> +#include <sched.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> @@ -18,13 +19,19 @@ using namespace boost; /** + * Work-around to make CPU_SET etc. -Wold-style-cast-safe. + */ +#undef __CPUMASK +#define __CPUMASK(cpu) (static_cast<__cpu_mask>(1) << ((cpu) % __NCPUBITS)) + + /** * Get the current thread ID. Glibc does not provide a wrapper for this * system call. */ inline pid_t gettid() { - return (pid_t) syscall(SYS_gettid); + return static_cast<pid_t>(syscall(SYS_gettid)); } /** @@ -60,7 +67,8 @@ spawn(const boost::function<void()>& f) { pthread_t t; - return pthread_create(&t, NULL, &run_function0_null, (void*) new boost::function<void()>(f)) == 0 ? t : 0; + return pthread_create(&t, NULL, &run_function0_null, + new boost::function<void()>(f)) == 0 ? t : 0; } } Deleted: cpp-commons/trunk/src/commons/unique_ptr.hpp =================================================================== --- cpp-commons/trunk/src/commons/unique_ptr.hpp 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/unique_ptr.hpp 2009-02-25 07:45:26 UTC (rev 1231) @@ -1,535 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// unique_ptr.hpp header file -// -// Copyright 2009 Howard Hinnant, Ion Gaztañaga. -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// See http://www.boost.org/libs/foreach for documentation - -// This is a C++03 emulation of std::unique_ptr placed in namespace boost. -// Reference http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf -// for the latest unique_ptr specification, and -// reference http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html -// for any pending issues against this specification. - -#ifndef UNIQUE_PTR_HPP -#define UNIQUE_PTR_HPP - -#include <boost/utility/enable_if.hpp> -#include <boost/type_traits.hpp> -#include <boost/static_assert.hpp> -#include <boost/mpl/if.hpp> - -namespace boost -{ - -namespace detail_unique_ptr -{ - -typedef char one; -struct two {one _[2];}; - -// An is_convertible<From, To> that considers From an rvalue (consistent with C++0X). -// This is a simplified version neglecting the types function, array, void and abstract types -// I had to make a special case out of is_convertible<T,T> to make move-only -// types happy. - -namespace is_conv_imp -{ -template <class T> one test1(const T&); -template <class T> two test1(...); -template <class T> one test2(T); -template <class T> two test2(...); -template <class T> T source(); -} - -template <class T1, class T2> -struct is_convertible -{ - static const bool value = sizeof(is_conv_imp::test1<T2>(is_conv_imp::source<T1>())) == 1; -}; - -template <class T> -struct is_convertible<T, T> -{ - static const bool value = sizeof(is_conv_imp::test2<T>(is_conv_imp::source<T>())) == 1; -}; - -template <class T> -class rv -{ - T& r_; - -public: - explicit rv(T& r) : r_(r) {} - T* operator->() {return &r_;} - T& operator*() {return r_;} -}; - -template <class T> -struct identity -{ - typedef T type; -}; - -} // detail_unique_ptr - -template <class T> -inline -typename enable_if_c -< - !detail_unique_ptr::is_convertible<T, detail_unique_ptr::rv<T> >::value, - T& ->::type -move(T& t) -{ - return t; -} - -template <class T> -inline -typename enable_if_c -< - !detail_unique_ptr::is_convertible<T, detail_unique_ptr::rv<T> >::value, - const T& ->::type -move(const T& t) -{ - return t; -} - -template <class T> -inline -typename enable_if_c -< - detail_unique_ptr::is_convertible<T, detail_unique_ptr::rv<T> >::value, - T ->::type -move(T& t) -{ - return T(detail_unique_ptr::rv<T>(t)); -} - -template <class T> -inline -typename enable_if_c -< - is_reference<T>::value, - T ->::type -forward(typename detail_unique_ptr::identity<T>::type t) -{ - return t; -} - -template <class T> -inline -typename enable_if_c -< - !is_reference<T>::value, - T ->::type -forward(typename detail_unique_ptr::identity<T>::type& t) -{ - return move(t); -} - -template <class T> -inline -typename enable_if_c -< - !is_reference<T>::value, - T ->::type -forward(const typename detail_unique_ptr::identity<T>::type& t) -{ - return move(const_cast<T&>(t)); -} - -namespace detail_unique_ptr { - -// A move-aware but stripped-down compressed_pair which only optimizes storage for T2 -template <class T1, class T2, bool = is_empty<T2>::value> -class unique_ptr_storage -{ - T1 t1_; - T2 t2_; - - typedef typename add_reference<T2>::type T2_reference; - typedef typename add_reference<const T2>::type T2_const_reference; - - unique_ptr_storage(const unique_ptr_storage&); - unique_ptr_storage& operator=(const unique_ptr_storage&); -public: - operator rv<unique_ptr_storage>() {return rv<unique_ptr_storage>(*this);} - - unique_ptr_storage() : t1_(), t2_() {} - - explicit unique_ptr_storage(T1 t1) - : t1_(move(t1)), t2_() {} - - unique_ptr_storage(T1 t1, T2 t2) - : t1_(move(t1)), t2_(forward<T2>(t2)) {} - - T1& first() {return t1_;} - const T1& first() const {return t1_;} - - T2_reference second() {return t2_;} - T2_const_reference second() const {return t2_;} -}; - -template <class T1, class T2> -class unique_ptr_storage<T1, T2, true> - : private T2 -{ - T1 t1_; - typedef T2 t2_; - - unique_ptr_storage(const unique_ptr_storage&); - unique_ptr_storage& operator=(const unique_ptr_storage&); -public: - operator rv<unique_ptr_storage>() {return rv<unique_ptr_storage>(*this);} - - unique_ptr_storage() : t1_() {} - - explicit unique_ptr_storage(T1 t1) - : t1_(move(t1)) {} - - unique_ptr_storage(T1 t1, T2 t2) - : t2_(move(t2)), t1_(move(t1)) {} - - T1& first() {return t1_;} - const T1& first() const {return t1_;} - - T2& second() {return *this;} - const T2& second() const {return *this;} -}; - -template <class T1, class T2, bool b> -inline -void -swap(unique_ptr_storage<T1, T2, b>& x, unique_ptr_storage<T1, T2, b>& y) -{ - using std::swap; - swap(x.first(), y.first()); - swap(x.second(), y.second()); -} - -} // detail_unique_ptr - -template <class T> -struct default_delete -{ - default_delete() {} - template <class U> - default_delete(const default_delete<U>&, - typename enable_if_c<detail_unique_ptr::is_convertible<U*, T*>::value>::type* = 0) - {} - - void operator()(T* ptr) const - { - BOOST_STATIC_ASSERT(sizeof(T) > 0); - delete ptr; - } -}; - -template <class T> -struct default_delete<T[]> -{ - void operator()(T* ptr) const - { - BOOST_STATIC_ASSERT(sizeof(T) > 0); - delete [] ptr; - } - -private: - - template <class U> void operator()(U*) const; -}; - -namespace detail_unique_ptr -{ - -namespace pointer_type_imp -{ - -template <class U> static two test(...); -template <class U> static one test(typename U::pointer* = 0); - -} // pointer_type_imp - -template <class T> -struct has_pointer_type -{ - static const bool value = sizeof(pointer_type_imp::test<T>(0)) == 1; -}; - -namespace pointer_type_imp -{ - -template <class T, class D, bool = has_pointer_type<D>::value> -struct pointer_type -{ - typedef typename D::pointer type; -}; - -template <class T, class D> -struct pointer_type<T, D, false> -{ - typedef T* type; -}; - -} // pointer_type_imp - -template <class T, class D> -struct pointer_type -{ - typedef typename pointer_type_imp::pointer_type<T, - typename boost::remove_reference<D>::type>::type type; -}; - -} // detail_unique_ptr - -template <class T, class D = default_delete<T> > -class unique_ptr -{ -public: - typedef T element_type; - typedef D deleter_type; - typedef typename detail_unique_ptr::pointer_type<element_type, deleter_type>::type pointer; - -private: - detail_unique_ptr::unique_ptr_storage<pointer, deleter_type> ptr_; - - typedef typename add_reference<deleter_type>::type deleter_reference; - typedef typename add_reference<const deleter_type>::type deleter_const_reference; - - struct nat {int for_bool_;}; - - unique_ptr(unique_ptr&); - unique_ptr& operator=(unique_ptr&); - -public: - operator detail_unique_ptr::rv<unique_ptr>() {return detail_unique_ptr::rv<unique_ptr>(*this);} - unique_ptr(detail_unique_ptr::rv<unique_ptr> r) : ptr_(r->release(), forward<deleter_type>(r->get_deleter())) {} - unique_ptr& operator=(detail_unique_ptr::rv<unique_ptr> r) - { - reset(r->release()); - ptr_.second() = move(r->get_deleter()); - return *this; - } - - unique_ptr() - { - BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); - BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); - } - - explicit unique_ptr(pointer p) - : ptr_(p) - { - BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); - BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); - } - - unique_ptr(pointer p, typename mpl::if_<is_reference<D>, - volatile typename remove_reference<D>::type&, D>::type d) - : ptr_(move(p), forward<D>(const_cast<typename add_reference<D>::type>(d))) {} - - template <class U, class E> - unique_ptr(unique_ptr<U, E> u, - typename enable_if_c - < - !boost::is_array<U>::value && - detail_unique_ptr::is_convertible<typename unique_ptr<U>::pointer, pointer>::value && - detail_unique_ptr::is_convertible<E, deleter_type>::value && - ( - !is_reference<deleter_type>::value || - is_same<deleter_type, E>::value - ) - >::type* = 0) - : ptr_(u.release(), forward<D>(forward<E>(u.get_deleter()))) {} - - ~unique_ptr() {reset();} - - unique_ptr& operator=(int nat::*) - { - reset(); - return *this; - } - - template <class U, class E> - unique_ptr& - operator=(unique_ptr<U, E> u) - { - reset(u.release()); - ptr_.second() = move(u.get_deleter()); - return *this; - } - - typename add_reference<T>::type operator*() const {return *get();} - pointer operator->() const {return get();} - pointer get() const {return ptr_.first();} - deleter_reference get_deleter() {return ptr_.second();} - deleter_const_reference get_deleter() const {return ptr_.second();} - operator int nat::*() const {return get() ? &nat::for_bool_ : 0;} - - void reset(pointer p = pointer()) - { - pointer t = get(); - if (t != pointer()) - get_deleter()(t); - ptr_.first() = p; - } - - pointer release() - { - pointer tmp = get(); - ptr_.first() = pointer(); - return tmp; - } - - void swap(unique_ptr& u) {detail_unique_ptr::swap(ptr_, u.ptr_);} -}; - -template <class T, class D> -class unique_ptr<T[], D> -{ -public: - typedef T element_type; - typedef D deleter_type; - typedef typename detail_unique_ptr::pointer_type<element_type, deleter_type>::type pointer; - -private: - detail_unique_ptr::unique_ptr_storage<pointer, deleter_type> ptr_; - - typedef typename add_reference<deleter_type>::type deleter_reference; - typedef typename add_reference<const deleter_type>::type deleter_const_reference; - - struct nat {int for_bool_;}; - - unique_ptr(unique_ptr&); - unique_ptr& operator=(unique_ptr&); - -public: - operator detail_unique_ptr::rv<unique_ptr>() {return detail_unique_ptr::rv<unique_ptr>(*this);} - unique_ptr(detail_unique_ptr::rv<unique_ptr> r) : ptr_(r->release(), forward<deleter_type>(r->get_deleter())) {} - unique_ptr& operator=(detail_unique_ptr::rv<unique_ptr> r) - { - reset(r->release()); - ptr_.second() = move(r->get_deleter()); - return *this; - } - - unique_ptr() - { - BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); - BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); - } - - explicit unique_ptr(pointer p) - : ptr_(p) - { - BOOST_STATIC_ASSERT(!is_reference<deleter_type>::value); - BOOST_STATIC_ASSERT(!is_pointer<deleter_type>::value); - } - - unique_ptr(pointer p, typename mpl::if_<is_reference<D>, - volatile typename remove_reference<D>::type&, D>::type d) - : ptr_(move(p), forward<D>(const_cast<typename add_reference<D>::type>(d))) {} - - ~unique_ptr() {reset();} - - T& operator[](size_t i) const {return get()[i];} - pointer get() const {return ptr_.first();} - deleter_reference get_deleter() {return ptr_.second();} - deleter_const_reference get_deleter() const {return ptr_.second();} - operator int nat::*() const {return get() ? &nat::for_bool_ : 0;} - - void reset(pointer p = pointer()) - { - pointer t = get(); - if (t != pointer()) - get_deleter()(t); - ptr_.first() = p; - } - - pointer release() - { - pointer tmp = get(); - ptr_.first() = pointer(); - return tmp; - } - - void swap(unique_ptr& u) {detail_unique_ptr::swap(ptr_, u.ptr_);} -private: - template <class U> - explicit unique_ptr(U, - typename enable_if_c<detail_unique_ptr::is_convertible<U, pointer>::value>::type* = 0); - - template <class U> - unique_ptr(U, typename mpl::if_<is_reference<D>, - volatile typename remove_reference<D>::type&, D>::type, - typename enable_if_c<detail_unique_ptr::is_convertible<U, pointer>::value>::type* = 0); -}; - -template<class T, class D> -inline -void -swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) -{ - x.swap(y); -} - -template<class T1, class D1, class T2, class D2> -inline -bool -operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) -{ - return x.get() == y.get(); -} - -template<class T1, class D1, class T2, class D2> -inline -bool -operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) -{ - return !(x == y); -} - -template<class T1, class D1, class T2, class D2> -inline -bool -operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) -{ - return x.get() < y.get(); -} - -template<class T1, class D1, class T2, class D2> -inline -bool -operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) -{ - return !(y < x); -} - -template<class T1, class D1, class T2, class D2> -inline -bool -operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) -{ - return y < x; -} - -template<class T1, class D1, class T2, class D2> -inline -bool -operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y) -{ - return !(x < y); -} - -} // boost - -#endif // UNIQUE_PTR_HPP Modified: cpp-commons/trunk/src/commons/x86asm.h =================================================================== --- cpp-commons/trunk/src/commons/x86asm.h 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/commons/x86asm.h 2009-02-25 07:45:26 UTC (rev 1231) @@ -11,7 +11,7 @@ inline unsigned char high(unsigned int r) { - return ((r >> 8) & 0xffU); + return static_cast<unsigned char>((r >> 8) & 0xffU); } /** @@ -21,7 +21,7 @@ inline unsigned char low(unsigned int r) { - return (r & 0xffU); + return static_cast<unsigned char>(r & 0xffU); } } Added: cpp-commons/trunk/src/test/Makefile =================================================================== --- cpp-commons/trunk/src/test/Makefile (rev 0) +++ cpp-commons/trunk/src/test/Makefile 2009-02-25 07:45:26 UTC (rev 1231) @@ -0,0 +1,35 @@ +CXXFLAGS = \ + -Wall \ + -Werror \ + -Wextra \ + -Wstrict-null-sentinel \ + -Wold-style-cast \ + -Woverloaded-virtual \ + -Wsign-promo \ + -Wformat=2 \ + -Winit-self \ + -Wswitch-enum \ + -Wunused \ + -Wfloat-equal \ + -Wundef \ + -Wunsafe-loop-optimizations \ + -Wpointer-arith \ + -Wcast-qual \ + -Wcast-align \ + -Wwrite-strings \ + -Wconversion \ + -Wlogical-op \ + -Wno-aggregate-return \ + -Wno-missing-declarations \ + -Wno-missing-field-initializers \ + -Wmissing-format-attribute \ + -Wpacked \ + -Wredundant-decls \ + -Winvalid-pch \ + -Wlong-long \ + -Wvolatile-register-var \ + -std=gnu++0x \ + +all: $(patsubst %.cc,%.o,$(wildcard *.cc)) + +.PHONY: all Deleted: cpp-commons/trunk/src/test/all.cc =================================================================== --- cpp-commons/trunk/src/test/all.cc 2009-02-24 20:03:15 UTC (rev 1230) +++ cpp-commons/trunk/src/test/all.cc 2009-02-25 07:45:26 UTC (rev 1231) @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Yang Zhang * - * gmail:yaaang * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License as * - * published by the Free Software Foundation; either version 2 of the * - * License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <commons/boost/threads.h> -#include <commons/check.h> -#include <commons/cpuid.h> -#include <commons/files.h> -#include <commons/hash.h> -#include <commons/strings.h> -#include <commons/time.h> -#include <commons/threads.h> -#include <commons/x86asm.h> - Property changes on: cpp-commons/trunk/src/yonat ___________________________________________________________________ Added: svn:mergeinfo + Added: cpp-commons/trunk/tools/check.bash =================================================================== --- cpp-commons/trunk/tools/check.bash (rev 0) +++ cpp-commons/trunk/tools/check.bash 2009-02-25 07:45:26 UTC (rev 1231) @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +. common.bash || exit 1 + +cd "$(dirname $0)/../src/" + +srcs() { + find boost/ commons/ yonat/ -name '*.h' -o -name '*.hpp' +} + +my-srcs() { + find commons/ -name '*.h' +} + +clobber-if-diff() { + if [[ -f "$1" ]] ; then + cat > "$1.tmp" + if diff "$1" "$1.tmp" > /dev/null + then rm "$1.tmp" + else mv "$1.tmp" "$1" + fi + else + cat > "$1" + fi +} + +build-tests() { + my-srcs | sed 's/^/#include </; s/$/>/' > test/all.cc + for i in $(my-srcs) + do echo "#include <$i>" | clobber-if-diff test/$(basename ${i%.h}).cc + done + make -C test/ +} + +check-include-guards() { + python -c " +from __future__ import with_statement +import re, sys +def check(x, y): + if not x == y: + raise Exception('failed: %s != %s' % (x,y)) +for path in sys.argv[1:]: + expected = '#ifndef ' + re.sub(r'[/\\.]', '_', path).upper() + with file(path) as f: + for line in f: + if line.strip() == expected: + break + else: + raise Exception('line not found: ' + expected) +" $(my-srcs) +} + +eval "$@" Property changes on: cpp-commons/trunk/tools/check.bash ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |