* Makeconfig: Define CXXFLAGS. Split out warnings from +gccwarn which

are not understood by the C++ compiler.
	* Makerules: Add rules to build C++ code for test cases.
	* include/stdlib.h: Protect for inclusion in C++ code.
	* include/time.h: Likewise.

	* test-skeleton.c (timeout_handler): Rewrite ts initialization for
	C++ compatibility.
This commit is contained in:
Ulrich Drepper 2005-12-23 01:55:26 +00:00
parent 331926097f
commit 7735afa212
8 changed files with 159 additions and 7 deletions

View File

@ -1,3 +1,11 @@
2005-12-22 Ulrich Drepper <drepper@redhat.com>
* Makeconfig: Define CXXFLAGS. Split out warnings from +gccwarn which
are not understood by the C++ compiler.
* Makerules: Add rules to build C++ code for test cases.
* include/stdlib.h: Protect for inclusion in C++ code.
* include/time.h: Likewise.
2005-12-22 Roland McGrath <roland@redhat.com>
* Makerules [gen-as-const-headers] (tests): Add one test per .sym
@ -8,6 +16,9 @@
2005-12-22 Ulrich Drepper <drepper@redhat.com>
* test-skeleton.c (timeout_handler): Rewrite ts initialization for
C++ compatibility.
* sysdeps/x86_64/__longjmp.S: Also protect SP and BP.
* sysdeps/x86_64/setjmp.S: Likewise.

View File

@ -552,10 +552,11 @@ endif
# Extra flags to pass to GCC.
ifeq ($(all-warnings),yes)
+gccwarn := -Wall -Wwrite-strings -Winline -Wstrict-prototypes -Wcast-qual -Wbad-function-cast -Wmissing-noreturn -Wmissing-prototypes -Wmissing-declarations -Wcomment -Wcomments -Wtrigraphs -Wsign-compare -Wfloat-equal -Wmultichar
+gccwarn := -Wall -Wwrite-strings -Winline -Wcast-qual -Wbad-function-cast -Wmissing-noreturn -Wmissing-prototypes -Wmissing-declarations -Wcomment -Wcomments -Wtrigraphs -Wsign-compare -Wfloat-equal -Wmultichar
else
+gccwarn := -Wall -Wwrite-strings -Winline -Wstrict-prototypes
+gccwarn := -Wall -Wwrite-strings -Winline
endif
+gccwarn-c = -Wstrict-prototypes
# We do not depend on the address of constants in different files to be
# actually different, so allow the compiler to merge them all.
@ -647,8 +648,11 @@ CPPFLAGS = $($(subdir)-CPPFLAGS) $(+includes) $(defines) \
$(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
$(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))
override CFLAGS = -std=gnu99 \
$(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
$(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
$(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
$(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
$(CFLAGS-$(@F))
override CXXFLAGS = $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
$(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
# If everything is compiled with -fPIC (implicitly) we must tell this by
# defining the PIC symbol.

View File

@ -306,6 +306,12 @@ endef
object-suffixes-left := $(all-object-suffixes)
include $(o-iterator)
define o-iterator-doit
$(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
endef
object-suffixes-left := $(all-object-suffixes)
include $(o-iterator)
# Omit the objpfx rules when building in the source tree, because
# objpfx is empty and so these rules just override the ones above.
ifdef objpfx
@ -381,9 +387,11 @@ compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
# GCC can grok options after the file name, and it looks nicer that way.
compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
$(ASFLAGS) $(ASFLAGS-$(suffix $@))
COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
@ -1180,9 +1188,9 @@ xcheck: xtests
all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
ifneq (,$(all-nonlib))
cpp-srcs-left = $(all-nonlib:=.c)
cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
lib := nonlib
include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
endif
# The include magic above causes those files to use this variable for flags.

View File

@ -10,6 +10,8 @@
/* Now define the internal interfaces. */
#ifndef __Need_M_And_C
__BEGIN_DECLS
extern __typeof (strtol_l) __strtol_l;
extern __typeof (strtoul_l) __strtoul_l;
extern __typeof (strtoll_l) __strtoll_l;
@ -197,6 +199,8 @@ __strtoull_l (__const char * __restrict __nptr, char **__restrict __endptr,
extern void * __default_morecore (ptrdiff_t);
libc_hidden_proto (__default_morecore)
__END_DECLS
#undef __Need_M_And_C
#endif /* include/stdlib.h */

View File

@ -5,6 +5,8 @@
# include <time/time.h>
# include <xlocale.h>
__BEGIN_DECLS
extern __typeof (strftime_l) __strftime_l;
libc_hidden_proto (__strftime_l)
extern __typeof (strptime_l) __strptime_l;
@ -89,6 +91,8 @@ extern int __getclktck (void);
/* strptime support. */
/* Status of lookup: do we use the locale data or the raw data? */
#ifndef __cplusplus
// C++ cannot deal with using 'not'.
enum ptime_locale_status { not, loc, raw };
extern char * __strptime_internal (const char *rp, const char *fmt,
@ -96,6 +100,7 @@ extern char * __strptime_internal (const char *rp, const char *fmt,
enum ptime_locale_status *decided,
int era_cnt, __locale_t locparam)
internal_function;
#endif
extern double __difftime (time_t time1, time_t time0);
@ -105,5 +110,8 @@ extern double __difftime (time_t time1, time_t time0);
#ifndef _ISOMAC
# define CLOCK_IDFIELD_SIZE 3
#endif
__END_DECLS
#endif
#endif

View File

@ -3,6 +3,8 @@
[BZ #1913]
* sysdeps/unix/sysv/linux/i386/i486/sem_wait.S (__new_sem_wait):
Fix unwind info. Remove useless branch prediction prefix.
* tst-cancel24.cc: New file.
* Makefile: Add rules to build and run tst-cancel24.
2005-12-21 Roland McGrath <roland@redhat.com>

View File

@ -220,7 +220,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 \
tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \
tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \
tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \
tst-cancel21 tst-cancel22 tst-cancel23 \
tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 \
tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \
tst-flock1 tst-flock2 \
tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \
@ -479,6 +479,8 @@ $(objpfx)tst-clock2: $(common-objpfx)rt/librt.a
$(objpfx)tst-rwlock14: $(common-objpfx)rt/librt.a
endif
LDFLAGS-tst-cancel24 = -lstdc++
extra-B-pthread.so = -B$(common-objpfx)nptl/
$(objpfx)libpthread.so: $(addprefix $(objpfx),$(crti-objs) $(crtn-objs))
$(objpfx)libpthread.so: +preinit += $(addprefix $(objpfx),$(crti-objs))

113
nptl/tst-cancel24.cc Normal file
View File

@ -0,0 +1,113 @@
#include <cstdlib>
#include <cstdio>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
static volatile bool destr_called;
static volatile bool except_caught;
static pthread_barrier_t b;
struct monitor
{
// gcc is broken and would generate a warning without this dummy
// constructor.
monitor () { }
~monitor() { destr_called = true; }
};
static void *
tf (void *arg)
{
sem_t *s = static_cast<sem_t *> (arg);
try
{
monitor m;
pthread_barrier_wait (&b);
while (1)
sem_wait (s);
}
catch (...)
{
except_caught = true;
throw;
}
return NULL;
}
static int
do_test ()
{
if (pthread_barrier_init (&b, NULL, 2) != 0)
{
puts ("barrier_init failed");
return 1;
}
sem_t s;
if (sem_init (&s, 0, 0) != 0)
{
puts ("sem_init failed");
return 1;
}
pthread_t th;
if (pthread_create (&th, NULL, tf, &s) != 0)
{
puts ("pthread_create failed");
return 1;
}
pthread_barrier_wait (&b);
/* There is unfortunately no better method to try to assure the
child thread reached the sem_wait call and is actually waiting
than to sleep here. */
sleep (1);
if (pthread_cancel (th) != 0)
{
puts ("cancel failed");
return 1;
}
void *res;
if (pthread_join (th, &res) != 0)
{
puts ("join failed");
return 1;
}
if (res != PTHREAD_CANCELED)
{
puts ("thread was not canceled");
return 1;
}
if (! except_caught)
{
puts ("exception not caught");
return 1;
}
if (! destr_called)
{
puts ("destructor not called");
return 1;
}
return 0;
}
#define TEST_FUNCTION do_test ()
#define TIMEOUT 3
#include "../test-skeleton.c"