[PATCH 1/3 v3] Cygwin: tzcode resync: basics

Corinna Vinschen corinna-cygwin@cygwin.com
Mon May 25 12:06:34 GMT 2020


Hi Mark,

On May 22 02:32, Mark Geisert wrote:
> Modifies winsup/cygwin/Makefile.in to build localtime.o from items in
> new winsup/cygwin/tzcode subdirectory.  Compiler option "-fpermissive"
> is used to accept warnings about missing casts on the return values of
> malloc() calls.  This patch also removes existing localtime.cc and
> tz_posixrules.h from winsup/cygwin as they are superseded by the
> subsequent patches in this set.
> [...]
> @@ -246,6 +246,15 @@ MATH_OFILES:= \
>  	tgammal.o \
>  	truncl.o
>  
> +TZCODE_OFILES:=localtime.o
> +
> +localtime.o: $(srcdir)/tzcode/localtime.cc $(srcdir)/tzcode/localtime.c.patch
> +	(cd $(srcdir)/tzcode && \
> +		patch -u -o localtime.c.patched localtime.c localtime.c.patch)
> +	$(CXX) ${CXXFLAGS} ${localtime_CFLAGS} \
> +		-I$(target_builddir)/winsup/cygwin \
> +		-I$(srcdir) -I$(srcdir)/tzcode -c -o $@ $<
> +

This doesn't work well for me.  That rule is the top rule in Makefile.in
now, so just calling `make' doesn't build the DLL anymore, only
localtime.o.  The rule should get moved way down Makefile.in.

What still bugs me is that we get these -fpermissive warnings (albeit
non-fatal) and the fact that we don't get a dependencies file.  On
second thought, there's no good reason to keep localtime.cc a C++ file.
Converting this file to a plain C wrapper drops the C++-specific warning
and thus allows to revert the localtime.o build rule to use ${COMMON_CFLAGS}.

So I took the liberty to tweak your patch a bit.  I created a followup
patchset, which I'd like you to take a look at.

I attached the followup patches to this mail.  Please scrutinize it and
don't hesitate to discuss the changes.  For a start:

- I do not exactly like the name "localtime_wrapper.c" but I don't
  have a better idea.

- muto's are C++-only, so I changed rwlock_wrlock/rwlock_unlock to use
  Windows SRWLocks.  I think this is a good thing and I'm inclined
  to drop the muto datatype entirely in favor of using SRWLocks since
  they are cleaner and langauge-agnostic.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
>From 2ce569ec924b75894492f1a103f42900610fe00f Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <corinna@vinschen.de>
Date: Mon, 25 May 2020 13:45:17 +0200
Subject: [PATCH 1/4] Cygwin: move localtime.o build rule to end of file

otherwise a simple `make' in the cygwin dir won't build
the DLL anymore.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 winsup/cygwin/Makefile.in | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 2ac8bcbd89ff..2e8c274a36b3 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -248,13 +248,6 @@ MATH_OFILES:= \
 
 TZCODE_OFILES:=localtime.o
 
-localtime.o: $(srcdir)/tzcode/localtime.cc $(srcdir)/tzcode/localtime.c.patch
-	(cd $(srcdir)/tzcode && \
-		patch -u -o localtime.c.patched localtime.c localtime.c.patch)
-	$(CXX) ${CXXFLAGS} ${localtime_CFLAGS} \
-		-I$(target_builddir)/winsup/cygwin \
-		-I$(srcdir) -I$(srcdir)/tzcode -c -o $@ $<
-
 DLL_OFILES:= \
 	advapi32.o \
 	aio.o \
@@ -741,6 +734,13 @@ dcrt0.o sigproc.o: child_info_magic.h
 
 shared.o: shared_info_magic.h
 
+localtime.o: $(srcdir)/tzcode/localtime.cc $(srcdir)/tzcode/localtime.c.patch
+	(cd $(srcdir)/tzcode && \
+		patch -u -o localtime.c.patched localtime.c localtime.c.patch)
+	$(CXX) ${CXXFLAGS} ${localtime_CFLAGS} \
+		-I$(target_builddir)/winsup/cygwin \
+		-I$(srcdir) -I$(srcdir)/tzcode -c -o $@ $<
+
 $(srcdir)/devices.cc: gendevices devices.in devices.h
 	${wordlist 1,2,$^} $@
 
-- 
2.25.4

-------------- next part --------------
>From 57625ac256299c1472f371f6d39b23c59f55d72e Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <corinna@vinschen.de>
Date: Mon, 25 May 2020 13:46:24 +0200
Subject: [PATCH 2/4] Cygwin: rename localtime.cc to localtime_wrapper.c

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 winsup/cygwin/Makefile.in                                  | 2 +-
 winsup/cygwin/tzcode/{localtime.cc => localtime_wrapper.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename winsup/cygwin/tzcode/{localtime.cc => localtime_wrapper.c} (100%)

diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 2e8c274a36b3..1e1342ab7849 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -734,7 +734,7 @@ dcrt0.o sigproc.o: child_info_magic.h
 
 shared.o: shared_info_magic.h
 
-localtime.o: $(srcdir)/tzcode/localtime.cc $(srcdir)/tzcode/localtime.c.patch
+localtime.o: $(srcdir)/tzcode/localtime_wrapper.c $(srcdir)/tzcode/localtime.c.patch
 	(cd $(srcdir)/tzcode && \
 		patch -u -o localtime.c.patched localtime.c localtime.c.patch)
 	$(CXX) ${CXXFLAGS} ${localtime_CFLAGS} \
diff --git a/winsup/cygwin/tzcode/localtime.cc b/winsup/cygwin/tzcode/localtime_wrapper.c
similarity index 100%
rename from winsup/cygwin/tzcode/localtime.cc
rename to winsup/cygwin/tzcode/localtime_wrapper.c
-- 
2.25.4

-------------- next part --------------
>From b4fdc99de23da851791b9976a8ae4e6e7a9a04f5 Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <corinna@vinschen.de>
Date: Mon, 25 May 2020 13:50:36 +0200
Subject: [PATCH 3/4] Cygwin: convert localtime_wrapper.c to plain C source

That also requires a small tweak to localtime.c.patch, otherwise
GCC complains about the position of the 'trydefrules' label.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 winsup/cygwin/Makefile.in                |  4 ++--
 winsup/cygwin/tzcode/localtime.c.patch   |  8 +++++---
 winsup/cygwin/tzcode/localtime_wrapper.c | 24 +++++++++---------------
 3 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 1e1342ab7849..1801b1a114eb 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -561,7 +561,7 @@ TARGET_LIBS:=$(LIB_NAME) $(CYGWIN_START) $(GMON_START) $(LIBGMON_A) $(SUBLIBS) $
 
 ifneq "${filter -O%,$(CFLAGS)}" ""
 dtable_CFLAGS:=-fcheck-new
-localtime_CFLAGS:=-fwrapv -fpermissive
+localtime_CFLAGS:=-fwrapv
 malloc_CFLAGS:=-O3
 sync_CFLAGS:=-O3
 ifeq ($(target_cpu),i686)
@@ -737,7 +737,7 @@ shared.o: shared_info_magic.h
 localtime.o: $(srcdir)/tzcode/localtime_wrapper.c $(srcdir)/tzcode/localtime.c.patch
 	(cd $(srcdir)/tzcode && \
 		patch -u -o localtime.c.patched localtime.c localtime.c.patch)
-	$(CXX) ${CXXFLAGS} ${localtime_CFLAGS} \
+	$(CC) ${COMMON_CFLAGS} ${localtime_CFLAGS} \
 		-I$(target_builddir)/winsup/cygwin \
 		-I$(srcdir) -I$(srcdir)/tzcode -c -o $@ $<
 
diff --git a/winsup/cygwin/tzcode/localtime.c.patch b/winsup/cygwin/tzcode/localtime.c.patch
index e19a2cd0254f..0587b5ea7626 100644
--- a/winsup/cygwin/tzcode/localtime.c.patch
+++ b/winsup/cygwin/tzcode/localtime.c.patch
@@ -32,13 +32,15 @@
  	nread = read(fid, up->buf, sizeof up->buf);
  	if (nread < (ssize_t)tzheadsize) {
  		int err = nread < 0 ? errno : EINVAL;
-@@ -501,6 +501,15 @@
+@@ -501,6 +501,17 @@
  	}
  	if (close(fid) < 0)
  		return errno;
 +	if (0) {
++		const char *base;
 +trydefrules:
-+		const char *base = strrchr(name, '/');
++
++		base = strrchr(name, '/');
 +		base = base ? base + 1 : name;
 +		if (strcmp(base, TZDEFRULES))
 +		    return errno;
@@ -48,7 +50,7 @@
  	for (stored = 4; stored <= 8; stored *= 2) {
  		int_fast32_t ttisstdcnt = detzcode(up->tzhead.tzh_ttisstdcnt);
  		int_fast32_t ttisutcnt = detzcode(up->tzhead.tzh_ttisutcnt);
-@@ -1417,6 +1426,8 @@
+@@ -1417,6 +1428,8 @@
  tzsetlcl(char const *name)
  {
  	struct state *sp = __lclptr;
diff --git a/winsup/cygwin/tzcode/localtime_wrapper.c b/winsup/cygwin/tzcode/localtime_wrapper.c
index c903bf3b9d6d..fce3e36cbbef 100644
--- a/winsup/cygwin/tzcode/localtime_wrapper.c
+++ b/winsup/cygwin/tzcode/localtime_wrapper.c
@@ -7,15 +7,16 @@ Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 details. */
 
 #include "../winsup.h"
-#include "../sync.h"
+#include "../perprocess.h"
 #include "../include/cygwin/version.h"
 #include "tz_posixrules.h"
+#include <stdlib.h>
 
-static NO_COPY muto tzset_guard;
+static SRWLOCK tzset_guard;
 
-// Convert these NetBSD rwlock ops into Cygwin muto ops
-#define rwlock_wrlock(X) tzset_guard.init("tzset_guard")->acquire()
-#define rwlock_unlock(X) tzset_guard.release()
+// Convert these NetBSD rwlock ops into SRWLocks
+#define rwlock_wrlock(X) AcquireSRWLockExclusive(&tzset_guard)
+#define rwlock_unlock(X) ReleaseSRWLockExclusive(&tzset_guard)
 
 // Set these NetBSD-related option #defines appropriately for Cygwin
 //#define STD_INSPIRED	// early-include private.h below does this
@@ -109,9 +110,6 @@ tzgetwintzi (char *wildabbr, char *outbuf)
 }
 
 // Get ready to wrap NetBSD's localtime.c
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 // Pull these in early to catch any small issues before the real test
 #include "private.h"
@@ -126,19 +124,15 @@ extern "C" {
 */
 #include "localtime.c.patched"
 
-#ifdef __cplusplus
-}
-#endif
-
 // Don't forget these Cygwin-specific additions from this point to EOF
 EXPORT_ALIAS (tzset_unlocked, _tzset_unlocked)
 
-extern "C" long
+long
 __cygwin_gettzoffset (const struct tm *tmp)
 {
 #ifdef TM_GMTOFF
     if (CYGWIN_VERSION_CHECK_FOR_EXTRA_TM_MEMBERS)
-    	return tmp->TM_GMTOFF;
+	return tmp->TM_GMTOFF;
 #endif /* defined TM_GMTOFF */
     __tzinfo_type *tz = __gettzinfo ();
     /* The sign of this is exactly opposite the envvar TZ.  We
@@ -148,7 +142,7 @@ __cygwin_gettzoffset (const struct tm *tmp)
     return offset;
 }
 
-extern "C" const char *
+const char *
 __cygwin_gettzname (const struct tm *tmp)
 {
 #ifdef TM_ZONE
-- 
2.25.4

-------------- next part --------------
>From 48c341531c6e1117405d1f163bdf9cc02117d45c Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <corinna@vinschen.de>
Date: Mon, 25 May 2020 13:51:35 +0200
Subject: [PATCH 4/4] .gitignore: add *.patched to support Cygwin's new
 localtime build rules

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 13a554aa0986..578d9d8fdc01 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 *.diff
 *.patch
+*.patched
 *.orig
 *.rej
 
-- 
2.25.4



More information about the Cygwin-patches mailing list