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:
frsyuki 2009-02-15 09:09:58 +00:00
parent a7936ba05b
commit 3165973811
9 changed files with 80 additions and 43 deletions

View File

@ -2,10 +2,15 @@ AC_INIT(pack.c)
AM_INIT_AUTOMAKE(msgpackc, 0.1.0)
AC_CONFIG_HEADER(config.h)
AC_SUBST(CFLAGS)
if test "" = "$CFLAGS"; then
CFLAGS="-g -O4"
fi
AC_PROG_CC
AC_PROG_LIBTOOL
CFLAGS="-O4 $CFLAGS -Wall -I.."
CFLAGS="-O4 -Wall $CFLAGS -I.."
AC_OUTPUT([Makefile])

View File

@ -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
View 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 $@

View File

@ -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();
}

View File

@ -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);

View File

@ -72,17 +72,21 @@
msgpack_pack_inline_func(int)(msgpack_pack_user x, int d)
{
if(d < -32) {
if(d < -32768) { // signed 32
if(d < -32768) {
// signed 32
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
msgpack_pack_append_buffer(x, buf, 5);
} else if(d < -128) { // signed 16
} else if(d < -128) {
// signed 16
const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
msgpack_pack_append_buffer(x, buf, 3);
} else { // signed 8
} else {
// signed 8
const unsigned char buf[2] = {0xd0, (uint8_t)d};
msgpack_pack_append_buffer(x, buf, 2);
}
} else if(d < 128) { // fixnum
} else if(d < 128) {
// fixnum
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
} else {
if(d < 256) {
@ -104,21 +108,25 @@ msgpack_pack_inline_func(int)(msgpack_pack_user x, int d)
// wrapper
msgpack_pack_inline_func(unsigned_int)(msgpack_pack_user x, unsigned int d)
{
if(d < 128) {
// fixnum
msgpack_pack_append_buffer(x, (unsigned char*)&d, 1);
} else if(d < 256) {
// unsigned 8
const unsigned char buf[2] = {0xcc, (uint8_t)d};
msgpack_pack_append_buffer(x, buf, 2);
} else if(d < 65536) {
// unsigned 16
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
msgpack_pack_append_buffer(x, buf, 3);
if(d < 256) {
if(d < 128) {
// fixnum
msgpack_pack_append_buffer(x, (unsigned char*)&d, 1);
} else {
// unsigned 8
const unsigned char buf[2] = {0xcc, (uint8_t)d};
msgpack_pack_append_buffer(x, buf, 2);
}
} else {
// unsigned 32
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
msgpack_pack_append_buffer(x, buf, 5);
if(d < 65536) {
// unsigned 16
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
msgpack_pack_append_buffer(x, buf, 3);
} else {
// unsigned 32
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
msgpack_pack_append_buffer(x, buf, 5);
}
}
}

View File

@ -1,4 +1,4 @@
require 'mkmf'
$CFLAGS << " -I.. -Wall -O9"
$CFLAGS << " -I.. -Wall -O4"
create_makefile('msgpack')

View File

@ -21,6 +21,8 @@ check 256
check 65535
check 65536
check -1
check -32
check -33
check -128
check -129
check -32768

View File

@ -176,13 +176,13 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
int ret;
if(from >= dlen) {
rb_raise(eUnpackError, "Requested start is after data buffer end.");
rb_raise(eUnpackError, "offset is bigger than data buffer size.");
}
ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
if(ret < 0) {
rb_raise(eUnpackError, "Parse error.");
rb_raise(eUnpackError, "parse error.");
} else if(ret > 0) {
mp->user.finished = 1;
return ULONG2NUM(from);
@ -242,12 +242,12 @@ static VALUE MessagePack_unpack_impl(VALUE args)
ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
if(ret < 0) {
rb_raise(eUnpackError, "Parse error.");
rb_raise(eUnpackError, "parse error.");
} else if(ret == 0) {
rb_raise(eUnpackError, "Insufficient bytes.");
rb_raise(eUnpackError, "insufficient bytes.");
} else {
if(from < dlen) {
rb_raise(eUnpackError, "Extra bytes.");
rb_raise(eUnpackError, "extra bytes.");
}
return msgpack_unpacker_data(mp);
}