From f87b4e5d7d2722dd4d730fd73f2b1091796edeb4 Mon Sep 17 00:00:00 2001 From: "Bradley C. Kuszmaul" Date: Tue, 18 Dec 2007 16:34:48 +0000 Subject: [PATCH] Make db_create work a little more under c++. Addresses #197. git-svn-id: file:///svn/tokudb@1196 c7de825b-a66e-492c-adef-691d508d4ae1 --- cxx/Makefile | 5 +++++ cxx/db.cpp | 6 ++++-- cxx/db_cxx.h | 2 ++ cxx/tests/Makefile | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cxx/Makefile b/cxx/Makefile index 843ce102c6b..fba14e46798 100644 --- a/cxx/Makefile +++ b/cxx/Makefile @@ -1,5 +1,10 @@ CPPFLAGS = -I../include +CXXFLAGS = -Wall -g CC = c++ LDFLAGS = -lz +SRCS = $(wildcard *.cpp) +OBJS = $(patsubst %.cpp, %.o, $(SRCS)) +default: $(OBJS) +$(OBJS): db_cxx.h test1: test1.o dbt.o db.o dbenv.o ../lib/libdb.a diff --git a/cxx/db.cpp b/cxx/db.cpp index 8fef40d0f64..71037bca987 100644 --- a/cxx/db.cpp +++ b/cxx/db.cpp @@ -3,9 +3,11 @@ #include #include "db_cxx.h" -Db::Db(DbEnv *env, u_int32_t flags) { +Db::Db(DbEnv *env, u_int32_t flags) + : the_Env(env) +{ the_db = 0; - the_Env = env; + if (the_Env == 0) { is_private_env = 1; } diff --git a/cxx/db_cxx.h b/cxx/db_cxx.h index 2d99ebd258c..ac9169e766c 100644 --- a/cxx/db_cxx.h +++ b/cxx/db_cxx.h @@ -69,6 +69,7 @@ class DbEnv { DbEnv(u_int32_t flags); DB_ENV *get_DB_ENV(void) { + if (this==0) return 0; return the_env; } @@ -86,6 +87,7 @@ class DbTxn { public: DB_TXN *get_DB_TXN() { + if (this==0) return 0; return the_txn; } private: diff --git a/cxx/tests/Makefile b/cxx/tests/Makefile index f8ed28923e5..3e71b448d09 100644 --- a/cxx/tests/Makefile +++ b/cxx/tests/Makefile @@ -1,13 +1,15 @@ SRCS = $(wildcard *.cpp) TARGETS = $(patsubst %.cpp,%,$(SRCS)) -DBCXX = ../dbt.o ../db.o ../dbenv.o ../dbt.o +DBCXX = ../dbt.o ../db.o ../dbenv.o CPPFLAGS = -I../ -I../../include CXXFLAGS = -Wall -g LDFLAGS = -L../lib -ldb $(TARGETS): $(DBCXX) +$(DBCXX): + cd ..;make all: $(TARGETS) clean: