diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/configure.in | 7 | ||||
-rw-r--r-- | cpp/test.mk | 9 | ||||
-rw-r--r-- | cpp/zone.cpp | 26 | ||||
-rw-r--r-- | cpp/zone.hpp | 16 |
4 files changed, 40 insertions, 18 deletions
diff --git a/cpp/configure.in b/cpp/configure.in index 5126be4..a60a489 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -2,13 +2,18 @@ AC_INIT(object.cpp) AM_INIT_AUTOMAKE(msgpack, 0.1.0) AC_CONFIG_HEADER(config.h) +AC_SUBST(CXXFLAGS) +if test "" = "$CXXFLAGS"; then + CXXFLAGS="-g -O4" +fi + AC_PROG_CXX AC_PROG_LIBTOOL AC_CHECK_PROG(ERB, erb, erb, [$PATH]) AC_CHECK_LIB(stdc++, main) -CXXFLAGS="-O4 $CXXFLAGS -Wall -I.." +CXXFLAGS="-O4 -Wall $CXXFLAGS -I.." AC_OUTPUT([Makefile]) diff --git a/cpp/test.mk b/cpp/test.mk new file mode 100644 index 0000000..f1beac5 --- /dev/null +++ b/cpp/test.mk @@ -0,0 +1,9 @@ + +CXXFLAGS += -Wall -g -I. -I.. -O4 +LDFLAGS += + +all: test + +test: test.o unpack.o zone.o object.o pack.hpp unpack.hpp zone.hpp object.hpp + $(CXX) test.o unpack.o zone.o object.o $(CXXFLAGS) $(LDFLAGS) -o $@ + diff --git a/cpp/zone.cpp b/cpp/zone.cpp index 490bc25..527cc9c 100644 --- a/cpp/zone.cpp +++ b/cpp/zone.cpp @@ -20,10 +20,6 @@ namespace msgpack { -zone::zone() { } - -zone::~zone() { clear(); } - void zone::clear() { for(std::vector<char*>::iterator it(m_ptrs.begin()), it_end(m_ptrs.end()); @@ -33,22 +29,18 @@ void zone::clear() m_ptrs.clear(); } -char* zone::realloc(char* ptr, size_t count) +char* zone::realloc_real(char* ptr, size_t count) { - if(ptr == NULL) { - return zone::malloc(count); - } else { - for(std::vector<char*>::reverse_iterator it(m_ptrs.rbegin()), it_end(m_ptrs.rend()); - it != it_end; ++it) { - if(*it == ptr) { - char* tmp = (char*)::realloc(ptr, count); - if(!tmp) { throw std::bad_alloc(); } - *it = tmp; - return tmp; - } + for(std::vector<char*>::reverse_iterator it(m_ptrs.rbegin()), it_end(m_ptrs.rend()); + it != it_end; ++it) { + if(*it == ptr) { + char* tmp = (char*)::realloc(ptr, count); + if(!tmp) { throw std::bad_alloc(); } + *it = tmp; + return tmp; } - throw std::bad_alloc(); } + throw std::bad_alloc(); } diff --git a/cpp/zone.hpp b/cpp/zone.hpp index f8c9cba..e7e73e1 100644 --- a/cpp/zone.hpp +++ b/cpp/zone.hpp @@ -41,10 +41,17 @@ private: std::vector<char*> m_ptrs; private: + char* realloc_real(char* ptr, size_t count); + +private: zone(const zone&); }; +inline zone::zone() { } + +inline zone::~zone() { clear(); } + inline char* zone::malloc(size_t count) { char* ptr = (char*)::malloc(count); @@ -58,6 +65,15 @@ inline char* zone::malloc(size_t count) return ptr; } +inline char* zone::realloc(char* ptr, size_t count) +{ + if(ptr == NULL) { + return zone::malloc(count); + } else { + return realloc_real(ptr, count); + } +} + inline object* zone::malloc_container(size_t count) { return (object*)zone::malloc(sizeof(object)*count); |