mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
lang/c/msgpack: fix compile optimization flag
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@70 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
parent
a7936ba05b
commit
3165973811
9 changed files with 80 additions and 43 deletions
|
|
@ -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])
|
||||
|
||||
|
|
|
|||
9
cpp/test.mk
Normal file
9
cpp/test.mk
Normal file
|
|
@ -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 $@
|
||||
|
||||
26
cpp/zone.cpp
26
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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
16
cpp/zone.hpp
16
cpp/zone.hpp
|
|
@ -40,11 +40,18 @@ public:
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue