This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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 Implement __gnat_set_close_on_exec on Windows


This patch implements __gnat_set_close_on_exec for Windows, as suggested
by a comment in that function, in the process fixing the following
bootstrap failure on i686-pc-mingw32.

stage1/xgcc.exe -Bstage1/
-B/aaronwl/cs/env/mingw-head/20040323/i686-pc-mingw32/bin/ -c   -g -O2
-DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes
-Wmissing-prototypes    -Werror -Wno-format -fno-common
-DHAVE_CONFIG_H    -I. -Iada
-I/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc
-I/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/ada
-I/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/../include -I./../intl
-I/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/../libcpp/include
-I/aaronwl/cs/math/gmp/gmp-4.1.4/include
-I/aaronwl/cs/math/mpfr/mpfr-2.1.0/include
/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/ada/adaint.c -o ada/adaint.o
cc1.exe: warnings being treated as errors
/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/ada/adaint.c: In function
'__gnat_portable_spawn':
/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/ada/adaint.c:1582:
warning: passing argument 3 of 'spawnvp' from incompatible pointer type
/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/ada/adaint.c: In function
'__gnat_set_close_on_exec':
/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/ada/adaint.c:2604:
warning: unused parameter 'fd'
/aaronwl/cs/compilers/gcc/src/cvs/head/gcc/gcc/ada/adaint.c:2604:
warning: unused parameter 'close_on_exec_p'
make[3]: *** [ada/adaint.o] Error 1


OK to commit?
2005-03-23  Aaron W. LaFramboise  <aaronavay62@aaronwl.com>

	* adaint.c (__gnat_portable_spawn): Adjust cast.
	(__gnat_set_close_on_exec) [_WIN32]: Implement.

Index: gcc/ada/adaint.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/adaint.c,v
retrieving revision 1.43
diff -c -3 -p -r1.43 adaint.c
*** gcc/ada/adaint.c	18 Mar 2005 11:46:57 -0000	1.43
--- gcc/ada/adaint.c	24 Mar 2005 01:59:46 -0000
*************** __gnat_portable_spawn (char *args[])
*** 1579,1585 ****
    strcat (args[0], args_0);
    strcat (args[0], "\"");
  
!   status = spawnvp (P_WAIT, args_0, (char* const*)args);
  
    /* restore previous value */
    free (args[0]);
--- 1579,1585 ----
    strcat (args[0], args_0);
    strcat (args[0], "\"");
  
!   status = spawnvp (P_WAIT, args_0, (const char* const*)args);
  
    /* restore previous value */
    free (args[0]);
*************** __gnat_set_close_on_exec (int fd, int cl
*** 2612,2622 ****
    else
      flags &= ~FD_CLOEXEC;
    return fcntl (fd, F_SETFD, flags | FD_CLOEXEC);
  #else
    return -1;
!   /* For the Windows case, we should use SetHandleInformation to remove
!      the HANDLE_INHERIT property from fd. This is not implemented yet,
!      but for our purposes (support of GNAT.Expect) this does not matter,
!      as by default handles are *not* inherited. */
  #endif
  }
--- 2612,2630 ----
    else
      flags &= ~FD_CLOEXEC;
    return fcntl (fd, F_SETFD, flags | FD_CLOEXEC);
+ 
+ #elif defined(_WIN32)
+   HANDLE h = (HANDLE) _get_osfhandle (fd);
+   if (h == (HANDLE) -1)
+     return -1;
+   if (close_on_exec_p)
+     return ! SetHandleInformation (h, HANDLE_FLAG_INHERIT, 0);
+   return ! SetHandleInformation (h, HANDLE_FLAG_INHERIT, 
+     HANDLE_FLAG_INHERIT);
+ 
  #else
+   /* Unimplemented. */
    return -1;
! 
  #endif
  }

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