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 if HAVE_EXECINFO
UTIL_FILES += backtrace_execinfo.cpp UTIL_FILES += backtrace_execinfo.cpp
else
UTIL_FILES += backtrace_null.cpp
endif endif
CLEANFILES = json.cpp version.cpp ip.cpp CLEANFILES = json.cpp version.cpp ip.cpp
EXTRA_DIST = json.cpp.rl version.cpp.rl ip.cpp.rl 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], [AS_HELP_STRING([--enable-debugging],
[enables developer debugging support])], [enables developer debugging support])],
[ case "${enableval}" in [ case "${enableval}" in
yes) cv_debugging=yes ;; yes) ac_cv_debugging=yes ;;
no) cv_debugging=no ;; no) ac_cv_debugging=no ;;
*) AC_MSG_ERROR([bad value for --enable-debugging=[yes|no]]) ;; *) AC_MSG_ERROR([bad value for --enable-debugging=[yes|no]]) ;;
esac ], esac ],
[cv_debugging=no]) [ac_cv_debugging=no])
## ##
## Warnings ## Warnings
@ -83,21 +83,35 @@ AC_C_INLINE
## Architecture features ## Architecture features
AC_C_BIGENDIAN AC_C_BIGENDIAN
##
## Useful headers or platform features
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
## ##
## platform features ## platform features
COMMON_CFLAGS="$COMMON_CFLAGS -D_GNU_SOURCE"
AC_FUNC_MMAP 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"]) AM_CONDITIONAL([HAVE_EXECINFO], [test x$ac_cv_header_execinfo_h = "xyes"])
## ##
## Debug features ## 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" COMMON_CFLAGS="$COMMON_CFLAGS -O0 -D_GLIBCXX_DEBUG"
else else
COMMON_CFLAGS="$COMMON_CFLAGS -O2 -flto" AS_CXX_COMPILER_FLAG([-flto], [ac_cv_flto=yes])
COMMON_LDFLAGS="-flto"
if test "x$ac_cv_flto" = "xyes"; then
COMMON_CFLAGS="$COMMON_CFLAGS -flto"
COMMON_LDFLAGS="-flto"
fi
COMMON_CFLAGS="$COMMON_CFLAGS -O2"
fi fi
## ##

View File

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

10
io.cpp
View File

@ -6,7 +6,6 @@
#include <cstdio> #include <cstdio>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@ -15,8 +14,8 @@ using namespace std;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
uint8_t * uint8_t *
slurp (boost::filesystem::path& path) { slurp (const boost::filesystem::path& path) {
fd_ref fd(open (path.c_str(), O_RDONLY | O_CLOEXEC)); fd_ref fd(open (path.string ().c_str (), O_RDONLY)); // | O_CLOEXEC));
// Calculate the total file size // Calculate the total file size
off_t size = lseek (fd, 0, SEEK_END); off_t size = lseek (fd, 0, SEEK_END);
@ -68,6 +67,9 @@ fd_ref::operator int (void) const
{ return fd; } { return fd; }
#if defined(HAVE_MMAP)
#include <sys/mman.h>
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
mapped_file::mapped_file (const char *_path): mapped_file::mapped_file (const char *_path):
m_fd (open (_path, O_RDONLY)) m_fd (open (_path, O_RDONLY))
@ -119,6 +121,6 @@ mapped_file::data (void) const {
return m_data; 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 /// Reads an entire file into memory. Caller frees the result. Guarantees a
/// null trailing byte. /// null trailing byte.
uint8_t * uint8_t *
slurp (boost::filesystem::path&) mustuse; slurp (const boost::filesystem::path&) mustuse;
/// A simple RAII wrapper for file descriptors /// A simple RAII wrapper for file descriptors
struct fd_ref { 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. /// Wraps a mechanism to map a file into memory. Read only.
class mapped_file { class mapped_file {
protected: protected:
@ -74,6 +75,7 @@ class mapped_file {
const uint8_t* data (void) const; const uint8_t* data (void) const;
size_t size (void) const; size_t size (void) const;
}; };
#endif
#endif #endif

View File

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

View File

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

22
test/.gitignore vendored
View File

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

View File

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