|
From: Carlo W. <li...@us...> - 2002-01-08 18:14:50
|
CVSROOT : /cvsroot/libcw
Module : src
Commit time: 2002-00-08 18:14:49 UTC
Modified files:
libcwd/INSTALL libcwd/debugmalloc.cc
libcwd/include/libcw/private_TSD.h
libcwd/include/libcw/private_threading.h
libcwd/testsuite/.cvsignore libcwd/testsuite/Makefile.in
Added files:
libcwd/testsuite/libcwd.threads/keys.cc
libcwd/testsuite/libcwd.threads/keys.re
libcwd/testsuite/libcwd.threads/test.exp
Log message:
Fix for gcc 2.95.x. pthread_setspecific calls calloc() which
was initializing libcwd (and the WARNING channel) with a temporal TSD.
The symbols are still read with the temporal TSD, but that doesn't
seem to harm.
---------------------- diff included ----------------------
Index: src/libcwd/INSTALL
diff -u src/libcwd/INSTALL:1.22 src/libcwd/INSTALL:1.23
--- src/libcwd/INSTALL:1.22 Sat Dec 29 20:17:46 2001
+++ src/libcwd/INSTALL Tue Jan 8 10:14:37 2002
@@ -86,7 +86,7 @@
iii) GNU make
iv) GNU m4
v) GNU which version 2.x
-vi) autoconf version 2.13 (2.52 seems to have problems)
+vi) autoconf version 2.13 or 2.52 or higher
vii) automake version 1.4pl1 or higher
viii) libtool version 1.4 or higher
Index: src/libcwd/debugmalloc.cc
diff -u src/libcwd/debugmalloc.cc:1.68 src/libcwd/debugmalloc.cc:1.69
--- src/libcwd/debugmalloc.cc:1.68 Fri Jan 4 20:22:24 2002
+++ src/libcwd/debugmalloc.cc Tue Jan 8 10:14:37 2002
@@ -1,4 +1,4 @@
-// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.68 2002/01/05 04:22:24 libcw Exp $
+// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.69 2002/01/08 18:14:37 libcw Exp $
//
// Copyright (C) 2000 - 2001, by
//
@@ -1491,10 +1491,16 @@
WST_initialization_state = -1;
_private_::set_alloc_checking_on(LIBCWD_TSD);
}
+ if (1
+#ifdef LIBCWD_THREAD_SAFE
+ // Don't initialize libcwd while having only a 'temporal' __libcwd_tsd!
+ && ::libcw::debug::_private_::thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::initialized()
+#endif
#ifdef __GLIBCPP__
- // "ios_base" is always initialized for libstdc++ version 2.
- if (!_private_::WST_ios_base_initialized && !_private_::inside_ios_base_Init_Init())
+ // "ios_base" is always initialized for libstdc++ version 2.
+ && !_private_::WST_ios_base_initialized && !_private_::inside_ios_base_Init_Init()
#endif // __GLIBCPP__
+ )
{
WST_initialization_state = 1; // ST_initialize_globals() calls malloc again of course.
#ifdef DEBUGDEBUGMALLOC
Index: src/libcwd/include/libcw/private_TSD.h
diff -u src/libcwd/include/libcw/private_TSD.h:1.2 src/libcwd/include/libcw/private_TSD.h:1.3
--- src/libcwd/include/libcw/private_TSD.h:1.2 Sat Dec 29 20:17:50 2001
+++ src/libcwd/include/libcw/private_TSD.h Tue Jan 8 10:14:38 2002
@@ -1,4 +1,4 @@
-// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_TSD.h,v 1.2 2001/12/30 04:17:50 libcw Exp $
+// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_TSD.h,v 1.3 2002/01/08 18:14:38 libcw Exp $
//
// Copyright (C) 2001, by
//
@@ -50,6 +50,7 @@
// When _REENTRANT is not defined then `__libcwd_tsd' is simply a global object in namespace _private_:
extern TSD_st __libcwd_tsd;
#endif
+extern int WST_initializing_TSD;
} // namespace _private_
} // namespace debug
Index: src/libcwd/include/libcw/private_threading.h
diff -u src/libcwd/include/libcw/private_threading.h:1.3 src/libcwd/include/libcw/private_threading.h:1.4
--- src/libcwd/include/libcw/private_threading.h:1.3 Fri Jan 4 20:22:25 2002
+++ src/libcwd/include/libcw/private_threading.h Tue Jan 8 10:14:38 2002
@@ -1,4 +1,4 @@
-// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.3 2002/01/05 04:22:25 libcw Exp $
+// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.4 2002/01/08 18:14:38 libcw Exp $
//
// Copyright (C) 2001, by
//
@@ -411,6 +411,7 @@
static pthread_key_t S_key;
static TSD* S_temporary_instance;
static bool S_initializing;
+ static bool S_WNS_initialized;
static void S_alloc_key(void) throw();
static TSD* S_initialize(void) throw();
static void S_destroy(void* tsd_ptr) throw();
@@ -422,6 +423,7 @@
instance = S_initialize();
return *instance;
}
+ static bool initialized(void) { return S_WNS_initialized; }
};
template<class TSD>
@@ -437,6 +439,9 @@
bool thread_specific_data_tct<TSD>::S_initializing;
template<class TSD>
+ bool thread_specific_data_tct<TSD>::S_WNS_initialized;
+
+template<class TSD>
void thread_specific_data_tct<TSD>::S_destroy(void* tsd_ptr) throw()
{
TSD* instance = reinterpret_cast<TSD*>(tsd_ptr);
@@ -475,6 +480,7 @@
set_alloc_checking_on(LIBCWD_TSD);
pthread_setspecific(S_key, instance);
S_initializing = false;
+ S_WNS_initialized = true;
mutex_tct<tsd_initialization_instance>::unlock();
return instance;
}
Index: src/libcwd/testsuite/.cvsignore
diff -u src/libcwd/testsuite/.cvsignore:1.4 src/libcwd/testsuite/.cvsignore:1.5
--- src/libcwd/testsuite/.cvsignore:1.4 Fri Aug 3 21:25:50 2001
+++ src/libcwd/testsuite/.cvsignore Tue Jan 8 10:14:38 2002
@@ -6,4 +6,6 @@
nodebug_*_static
tst_*_shared
tst_*_static
+threads_*_shared
+threads_*_static
module.so
Index: src/libcwd/testsuite/Makefile.in
diff -u src/libcwd/testsuite/Makefile.in:1.25 src/libcwd/testsuite/Makefile.in:1.26
--- src/libcwd/testsuite/Makefile.in:1.25 Sat Dec 29 20:17:50 2001
+++ src/libcwd/testsuite/Makefile.in Tue Jan 8 10:14:38 2002
@@ -1,5 +1,6 @@
NODEBUGCHECK = nodebug
TSTCHECK = alloctag basic bfd cf continued dc demangler dlopen do flush leak lockable_auto_ptr magic marker strdup test_delete type_info
+THREADSCHECK = keys
srcdir = @srcdir@
top_builddir = ..
@@ -24,22 +25,26 @@
INCLUDES = -Ilibcwd.tst -I$(top_builddir)/include -I$(srcdir)/../include
PACKAGE = @PACKAGE@
VERSION = @VERSION@
-DISTFILES = Makefile.in module.cc config lib libcwd.tst libcwd.nodebug
+DISTFILES = Makefile.in module.cc config lib libcwd.tst libcwd.nodebug libcwd.threads
ifeq ($(enable_shared), yes)
SHAREDTSTTARGETS := $(patsubst %,tst_%_shared,$(TSTCHECK))
SHAREDNODEBUGTARGETS := $(patsubst %,nodebug_%_shared,$(NODEBUGCHECK))
+SHAREDTHREADSTARGETS := $(patsubst %,threads_%_shared,$(THREADSCHECK))
else
SHAREDTSTTARGETS :=
SHAREDNODEBUGTARGETS :=
+SHAREDTHREADSTARGETS :=
endif
ifeq ($(enable_static), yes)
STATICTSTTARGETS := $(patsubst %,tst_%_static,$(TSTCHECK))
STATICNODEBUGTARGETS := $(patsubst %,nodebug_%_static,$(NODEBUGCHECK))
+STATICTHREADSTARGETS := $(patsubst %,threads_%_static,$(THREADSCHECK))
else
STATICTSTTARGETS :=
STATICNODEBUGTARGETS :=
+STATICTHREADSTARGETS :=
endif
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
@@ -86,6 +91,9 @@
nodebug_%.o: libcwd.nodebug/%.cc Makefile $(top_builddir)/include/libcw/*.h
$(CXXCOMPILE) -c $< -o $@
+threads_%.o: libcwd.threads/%.cc Makefile $(top_builddir)/include/libcw/*.h
+ $(CXXCOMPILE) -c $< -o $@
+
ifeq ($(enable_shared), yes)
%_shared: %.o $(top_builddir)/.libs/libcwd.so.*
$(CXXLINK) $< -o $@ $(SHAREDLIBS)
@@ -96,11 +104,13 @@
$(CXXLINK) $< -o $@ $(STATICLIBS)
endif
-shared: $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS)
-static: $(STATICTSTTARGETS) $(STATICNODEBUGTARGETS)
+shared: $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS) $(SHAREDTHREADSTARGETS)
+static: $(STATICTSTTARGETS) $(STATICNODEBUGTARGETS) $(STATICTHREADSTARGETS)
run: shared static module.so
- @for i in $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS) $(STATICTSTTARGETS) $(STATICNODEBUGTARGETS); do echo -n "$$i: "; if ./$$i 2>/dev/null >/dev/null; then echo "OK"; else echo "ERROR"; fi ; done
+ @for i in $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS) $(SHAREDTHREADSTARGETS) \
+ $(STATICTSTTARGETS) $(STATICNODEBUGTARGETS) $(STATICTHREADSTARGETS); do \
+ echo -n "$$i: "; if ./$$i 2>/dev/null >/dev/null; then echo "OK"; else echo "ERROR"; fi ; done
# Clean rules
mostlyclean:
Index: src/libcwd/testsuite/libcwd.threads/keys.cc
diff -u /dev/null src/libcwd/testsuite/libcwd.threads/keys.cc:1.1
--- /dev/null Tue Jan 8 10:14:49 2002
+++ src/libcwd/testsuite/libcwd.threads/keys.cc Tue Jan 8 10:14:39 2002
@@ -0,0 +1,29 @@
+#include "sys.h"
+#include <libcw/debug.h>
+
+void S_destroy(void* tsd_ptr) throw()
+{
+ delete (int*)tsd_ptr;
+}
+
+int main(void)
+{
+ Debug( check_configuration() );
+ Debug( libcw_do.on() );
+ Debug( dc::notice.on() );
+
+ // This tests if the warning channel is turned on.
+ Dout( dc::warning, "Ok");
+
+ pthread_key_t S_key;
+ pthread_key_create(&S_key, S_destroy);
+ int* p = new int;
+ *p = 123454321;
+ pthread_setspecific(S_key, p);
+ int* q = (int*)pthread_getspecific(S_key);
+ std::cout << "q = " << q << "; *q = " << *q << '\n';
+ int* q2 = (int*)pthread_getspecific(S_key);
+ assert( q == q2 );
+
+ exit(0);
+}
Index: src/libcwd/testsuite/libcwd.threads/keys.re
diff -u /dev/null src/libcwd/testsuite/libcwd.threads/keys.re:1.1
--- /dev/null Tue Jan 8 10:14:49 2002
+++ src/libcwd/testsuite/libcwd.threads/keys.re Tue Jan 8 10:14:39 2002
@@ -0,0 +1,7 @@
+// input lines 3
+// output till ^WARNING
+((WARNING : core size is limited.*
+)*BFD : Loading debug info from.*
+)*
+WARNING : Ok
+q = 0x[0-9a-f]*; \*q = 123454321
Index: src/libcwd/testsuite/libcwd.threads/test.exp
diff -u /dev/null src/libcwd/testsuite/libcwd.threads/test.exp:1.1
--- /dev/null Tue Jan 8 10:14:49 2002
+++ src/libcwd/testsuite/libcwd.threads/test.exp Tue Jan 8 10:14:39 2002
@@ -0,0 +1,34 @@
+global srcdir subdir
+global SHAREDLIBS STATICLIBS
+
+catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles
+# set srcfiles $srcdir/$subdir/keys.cc
+verbose "srcfiles are $srcfiles"
+
+set prefix ""
+foreach x $srcfiles {
+ regsub "\\.cc$" $x "" prefix
+ set bname [file tail $prefix]
+ set args ""
+ if [file exists ${prefix}.arg] {
+ set id [open "${prefix}.arg" r];
+ set args [read -nonewline $id];
+ close $id;
+ }
+ set resfile "${prefix}.re"
+ set options "regexp_match"
+
+ if [file exists ${prefix}.inp] {
+ set inpfile ${prefix}.inp
+ } else {
+ set inpfile ""
+ }
+ verbose "inpfile is $inpfile"
+
+ if { $SHAREDLIBS != "" } {
+ test_libcwd $options "${prefix}.cc" "" $inpfile $resfile $args
+ }
+ if { $STATICLIBS != "" } {
+ test_libcwd "static $options" "${prefix}.cc" "" $inpfile $resfile $args
+ }
+}
----------------------- End of diff -----------------------
|