Merge branch 'master' of ssh://192.168.1.7/home/danny/libgim

This commit is contained in:
Danny Robson 2011-07-07 19:27:05 +10:00
commit 79e0d2de9d
10 changed files with 82 additions and 44 deletions

View File

@ -51,9 +51,10 @@ UTIL_FILES = \
if HAVE_EXECINFO
UTIL_FILES += backtrace_execinfo.cpp
else
UTIL_FILES += backtrace_null.cpp
endif
CLEANFILES = json.cpp version.cpp ip.cpp
EXTRA_DIST = json.cpp.rl version.cpp.rl ip.cpp.rl

17
backtrace_null.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "backtrace.hpp"
#include <iostream>
using namespace std;
debug::backtrace::backtrace (void):
m_frames (DEFAULT_DEPTH)
{ ; }
ostream&
operator <<(ostream &os, const debug::backtrace &rhs) {
os << "null backtrace";
return os;
}

View File

@ -22,11 +22,11 @@ AC_ARG_ENABLE([debugging],
[AS_HELP_STRING([--enable-debugging],
[enables developer debugging support])],
[ case "${enableval}" in
yes) cv_debugging=yes ;;
no) cv_debugging=no ;;
yes) ac_cv_debugging=yes ;;
no) ac_cv_debugging=no ;;
*) AC_MSG_ERROR([bad value for --enable-debugging=[yes|no]]) ;;
esac ],
[cv_debugging=no])
[ac_cv_debugging=no])
##
## Warnings
@ -83,21 +83,35 @@ AC_C_INLINE
## Architecture features
AC_C_BIGENDIAN
##
## Useful headers or platform features
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
##
## platform features
COMMON_CFLAGS="$COMMON_CFLAGS -D_GNU_SOURCE"
AC_FUNC_MMAP
AC_CHECK_HEADER([execinfo.h], [break], [AC_MSG_ERROR([Missing backtrace support])])
AC_CHECK_HEADER([execinfo.h], [break])
AM_CONDITIONAL([HAVE_EXECINFO], [test x$ac_cv_header_execinfo_h = "xyes"])
##
## Debug features
if test "x$cv_debugging" = "xyes"; then
if test "x$ac_cv_debugging" = "xyes"; then
COMMON_CFLAGS="$COMMON_CFLAGS -O0 -D_GLIBCXX_DEBUG"
else
COMMON_CFLAGS="$COMMON_CFLAGS -O2 -flto"
COMMON_LDFLAGS="-flto"
AS_CXX_COMPILER_FLAG([-flto], [ac_cv_flto=yes])
if test "x$ac_cv_flto" = "xyes"; then
COMMON_CFLAGS="$COMMON_CFLAGS -flto"
COMMON_LDFLAGS="-flto"
fi
COMMON_CFLAGS="$COMMON_CFLAGS -O2"
fi
##

View File

@ -42,7 +42,7 @@ panic (void)
void
breakpoint (void) {
if (getenv ("DEBUG")) {
#if defined (__x86_64)
#if defined (__x86_64) || defined (__i386)
__asm__ ("int $3;");
#else
raise (SIGINT);

10
io.cpp
View File

@ -6,7 +6,6 @@
#include <cstdio>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
@ -15,8 +14,8 @@ using namespace std;
//----------------------------------------------------------------------------
uint8_t *
slurp (boost::filesystem::path& path) {
fd_ref fd(open (path.c_str(), O_RDONLY | O_CLOEXEC));
slurp (const boost::filesystem::path& path) {
fd_ref fd(open (path.string ().c_str (), O_RDONLY)); // | O_CLOEXEC));
// Calculate the total file size
off_t size = lseek (fd, 0, SEEK_END);
@ -68,6 +67,9 @@ fd_ref::operator int (void) const
{ return fd; }
#if defined(HAVE_MMAP)
#include <sys/mman.h>
//----------------------------------------------------------------------------
mapped_file::mapped_file (const char *_path):
m_fd (open (_path, O_RDONLY))
@ -119,6 +121,6 @@ mapped_file::data (void) const {
return m_data;
}
#endif

4
io.hpp
View File

@ -38,7 +38,7 @@ enum access_t {
/// Reads an entire file into memory. Caller frees the result. Guarantees a
/// null trailing byte.
uint8_t *
slurp (boost::filesystem::path&) mustuse;
slurp (const boost::filesystem::path&) mustuse;
/// A simple RAII wrapper for file descriptors
struct fd_ref {
@ -52,6 +52,7 @@ struct fd_ref {
};
#if defined(HAVE_MMAP)
/// Wraps a mechanism to map a file into memory. Read only.
class mapped_file {
protected:
@ -74,6 +75,7 @@ class mapped_file {
const uint8_t* data (void) const;
size_t size (void) const;
};
#endif
#endif

View File

@ -29,7 +29,6 @@
#include <algorithm>
#include <sstream>
#include <sys/mman.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -236,13 +235,14 @@ struct parse_context {
namespace json {
json::node *
parse (const boost::filesystem::path &path) {
mapped_file file(path);
return parse ((const char *)file.data (),
(const char *)file.data () + file.size ());
}
parse (const boost::filesystem::path &path)
{ return parse ((const char *)slurp (path)); }
json::node *
parse (const std::string &path)
{ return parse (path.c_str (), path.c_str () + path.size ()); }
node *
parse (const char *start,
const char *stop) {

View File

@ -40,6 +40,7 @@ namespace json {
extern node* parse (const boost::filesystem::path &path);
extern node* parse (const char *start, const char *stop);
extern node* parse (const char *start);
extern node* parse (const std::string&);
/// Abstract base for all JSON values
class node {

22
test/.gitignore vendored
View File

@ -1,11 +1,11 @@
/backtrace
/float
/hton
/ip
/json-check
/maths
/matrix
/pool
/range
/signal
/version
/backtrace*
/float*
/hton*
/ip*
/json-check*
/maths*
/matrix*
/pool*
/range*
/signal*
/version*

View File

@ -1,12 +1,13 @@
#include "../backtrace.hpp"
#include <iostream>
using namespace std;
int
main (int, char **) {
cout << debug::backtrace() << endl;
return EXIT_SUCCESS;
}
#include "../backtrace.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;
int
main (int, char **) {
cout << debug::backtrace() << endl;
return EXIT_SUCCESS;
}