This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] fix strfuncs-related breakage of cygserver


The recent addition of the sys_{wcstombs,mbstowcs}_alloc() functions to
strfuncs.cc causes cygserver to no longer build.  The problem is simply
that we can't call ccalloc() from within cygserver, but cygserver needs
__small_vsprintf() which in turn calls sys_wcstombs_alloc(), which in
turn wants to call ccalloc().  To get around this, I just
conditionalized the foo_alloc() functions to always use plain calloc()
when inside cygserver, and changed cygserver's Makefile to rebuild
strfuncs.cc again instead of sharing the .o from the DLL.

There is also a small additional buglet in that the call to
sys_wcstombs_alloc() in __small_vsprintf() was passing PATH_MAX as the
heap type, and that is not a valid cygheap_types.  I changed it to
HEAP_NOTHEAP as that is the only value that makes sense here since this
pointer is subsequently free()'d and not cfree()'d.

Attached are two patches, one for cygwin/ and one in cygserver/.

Brian
2008-02-03  Brian Dessent  <brian@dessent.net>

	* smallprint.cc (__small_vsprintf): Use HEAP_NOTHEAP for type.
	* strfuncs.cc (sys_wcstombs_alloc): Guard use of ccalloc
	to !__OUTSIDE_CYGWIN__ for use in cygserver.
	(sys_mbstowcs_alloc): Ditto.


Index: smallprint.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/smallprint.cc,v
retrieving revision 1.4
diff -u -p -r1.4 smallprint.cc
--- smallprint.cc	31 Jan 2008 20:26:01 -0000	1.4
+++ smallprint.cc	4 Feb 2008 03:18:45 -0000
@@ -197,7 +197,7 @@ __small_vsprintf (char *dst, const char 
 		  {
 		    char *tmp;
 
-		    if (!sys_wcstombs_alloc (&tmp, PATH_MAX, us->Buffer,
+		    if (!sys_wcstombs_alloc (&tmp, HEAP_NOTHEAP, us->Buffer,
 					     us->Length / sizeof (WCHAR)))
 		      {
 			s = "invalid UNICODE_STRING";
Index: strfuncs.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/strfuncs.cc,v
retrieving revision 1.4
diff -u -p -r1.4 strfuncs.cc
--- strfuncs.cc	31 Jan 2008 20:26:01 -0000	1.4
+++ strfuncs.cc	4 Feb 2008 03:18:45 -0000
@@ -60,7 +60,11 @@ sys_wcstombs (char *tgt, int tlen, const
    value is the number of bytes written to the buffer, as usual.
    The "type" argument determines where the resulting buffer is stored.
    It's either one of the cygheap_types values, or it's "HEAP_NOTHEAP".
-   In the latter case the allocation uses simple calloc. */
+   In the latter case the allocation uses simple calloc.
+   
+   Note that this code is shared by cygserver (which requires it via
+   __small_vsprintf) and so when built there plain calloc is the 
+   only choice.  */
 int __stdcall
 sys_wcstombs_alloc (char **tgt_p, int type, const PWCHAR src, int slen)
 {
@@ -71,10 +75,14 @@ sys_wcstombs_alloc (char **tgt_p, int ty
     {
       size_t tlen = (slen == -1 ? ret : ret + 1);
 
+#ifndef __OUTSIDE_CYGWIN__
       if (type == HEAP_NOTHEAP)
+#endif
         *tgt_p = (char *) calloc (tlen, sizeof (char));
+#ifndef __OUTSIDE_CYGWIN__
       else
       	*tgt_p = (char *) ccalloc ((cygheap_types) type, tlen, sizeof (char));
+#endif
       if (!*tgt_p)
         return 0;
       ret = sys_wcstombs (*tgt_p, tlen, src, slen);
@@ -98,10 +106,14 @@ sys_mbstowcs_alloc (PWCHAR *tgt_p, int t
   ret = MultiByteToWideChar (get_cp (), 0, src, -1, NULL, 0);
   if (ret)
     {
+#ifndef __OUTSIDE_CYGWIN__
       if (type == HEAP_NOTHEAP)
+#endif
         *tgt_p = (PWCHAR) calloc (ret, sizeof (WCHAR));
+#ifndef __OUTSIDE_CYGWIN__
       else
       	*tgt_p = (PWCHAR) ccalloc ((cygheap_types) type, ret, sizeof (WCHAR));
+#endif
       if (!*tgt_p)
         return 0;
       ret = sys_mbstowcs (*tgt_p, src, ret);
2008-02-03  Brian Dessent  <brian@dessent.net>

	* Makefile.in: Don't link strfuncs.o from the Cygwin build dir.
	Build it again with __OUTSIDE_CYGWIN__ defined.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/winsup/cygserver/Makefile.in,v
retrieving revision 1.16
diff -u -p -r1.16 Makefile.in
--- Makefile.in	2 Aug 2007 14:23:22 -0000	1.16
+++ Makefile.in	4 Feb 2008 03:22:32 -0000
@@ -43,7 +43,7 @@ OBJS:=	cygserver.o client.o process.o ms
 	sysv_msg.o sysv_sem.o sysv_shm.o
 LIBOBJS:=${patsubst %.o,lib%.o,$(OBJS)}
 
-CYGWIN_OBJS:=$(cygwin_build)/smallprint.o $(cygwin_build)/strfuncs.o $(cygwin_build)/version.o
+CYGWIN_OBJS:=$(cygwin_build)/smallprint.o $(cygwin_build)/version.o
 
 CYGWIN_LIB:=$(cygwin_build)/libcygwin.a
 
@@ -67,7 +67,7 @@ libclean:
 
 fullclean: clean libclean
 
-cygserver.exe: $(CYGWIN_LIB) $(OBJS) $(CYGWIN_OBJS)
+cygserver.exe: $(CYGWIN_LIB) $(OBJS) $(CYGWIN_OBJS) strfuncs.o
 	$(CXX) -o $@ ${wordlist 2,999,$^} -L$(cygwin_build) -lntdll
 
 $(cygwin_build)/%.o: $(cygwin_source)/%.cc
@@ -81,6 +81,9 @@ Makefile: Makefile.in configure
 lib%.o: %.cc
 	${filter-out -D__OUTSIDE_CYGWIN__, $(COMPILE_CXX)} -I$(updir)/cygwin -o $(@D)/${basename $(@F)}$o $<
 
+strfuncs.o: $(cygwin_source)/strfuncs.cc
+	$(COMPILE_CXX) -I$(updir)/cygwin -o $(@D)/$(*F)$o $<
+
 libcygserver.a: $(LIBOBJS)
 	$(AR) crus $@ $?
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]