Re: [patch] fix strfuncs-related breakage of cygserver

2008-02-06 Thread Corinna Vinschen
On Feb  6 23:10, Corinna Vinschen wrote:
 Hi Brian,
 
 On Feb  4 13:10, Corinna Vinschen wrote:
  On Feb  3 19:37, Brian Dessent wrote:
   Attached are two patches, one for cygwin/ and one in cygserver/.
  
  Thanks, applied.
 
 On second thought it occured to me that there's no good reason that
 cygserver shouldn't use standard C functions instead of the internal
 __small_printf stuff, given that it is linked against Cygwin anyway.
 
 So what I did was to remove every trace of dependency to Cygwin sources,
 except for the version information.
 
 I'd be grateful if you could have a sanitizing look.  Maybe I missed
 something.

Of course I forgot something.
I forgot to replace special small_printf format specifiers with standard
printf specifiers.  I hope that's fixed now.


Corinna

-- 
Corinna Vinschen  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader  cygwin AT cygwin DOT com
Red Hat


Re: [patch] fix strfuncs-related breakage of cygserver

2008-02-04 Thread Corinna Vinschen
On Feb  3 19:37, Brian Dessent wrote:
 
 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/.

Thanks, applied.


Corinna

-- 
Corinna Vinschen  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader  cygwin AT cygwin DOT com
Red Hat


[patch] fix strfuncs-related breakage of cygserver

2008-02-03 Thread Brian Dessent

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/.

Brian2008-02-03  Brian Dessent  [EMAIL PROTECTED]

* 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 -  1.4
+++ smallprint.cc   4 Feb 2008 03:18:45 -
@@ -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 -  1.4
+++ strfuncs.cc 4 Feb 2008 03:18:45 -
@@ -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  [EMAIL PROTECTED]

* 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 -   1.16
+++ Makefile.in 4 Feb 2008 03:22:32 -
@@ -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