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]

Re: Patch: *bsd & darwin support in libiberty/physmem.c


geoffk at geoffk dot org said:
> Aargh!  That version works, but right after I sent it I saw I'd done
> the error-checking wrong.

> This is better. 

Nearly, but it still contains a GCCism.  IIRC you can't initialize an 
automatic array during a declartion in ISO C90.

Here's a further slight revision which works OK on NetBSD/arm.  I've also 
included a missing Makefile dependency on config.h and libiberty.h

R.


Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/Makefile.in,v
retrieving revision 1.87
diff -p -r1.87 Makefile.in
*** Makefile.in	21 Feb 2003 00:27:04 -0000	1.87
--- Makefile.in	22 Feb 2003 12:39:19 -0000
*************** pex-msdos.o: config.h pex-common.h $(INC
*** 466,471 ****
--- 466,472 ----
  pex-os2.o: config.h pex-common.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
  pex-unix.o: config.h pex-common.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
  pex-win32.o: config.h pex-common.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
+ physmem.o: config.h $(INCDIR)/libiberty.h
  putenv.o: config.h $(INCDIR)/ansidecl.h
  random.o: $(INCDIR)/ansidecl.h
  regex.o: config.h $(INCDIR)/xregex.h $(INCDIR)/xregex2.h
Index: config.in
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/config.in,v
retrieving revision 1.25
diff -p -r1.25 config.in
*** config.in	21 Feb 2003 20:33:49 -0000	1.25
--- config.in	22 Feb 2003 12:39:19 -0000
***************
*** 183,188 ****
--- 183,191 ----
  /* Define if you have the sysconf function.  */
  #undef HAVE_SYSCONF
  
+ /* Define if you have the sysctl function.  */
+ #undef HAVE_SYSCTL
+ 
  /* Define if you have the sysmp function.  */
  #undef HAVE_SYSMP
  
***************
*** 248,253 ****
--- 251,259 ----
  
  /* Define if you have the <sys/stat.h> header file.  */
  #undef HAVE_SYS_STAT_H
+ 
+ /* Define if you have the <sys/sysctl.h> header file.  */
+ #undef HAVE_SYS_SYSCTL_H
  
  /* Define if you have the <sys/sysinfo.h> header file.  */
  #undef HAVE_SYS_SYSINFO_H
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/configure.in,v
retrieving revision 1.61
diff -p -r1.61 configure.in
*** configure.in	21 Feb 2003 20:33:50 -0000	1.61
--- configure.in	22 Feb 2003 12:39:19 -0000
*************** AC_SUBST_FILE(host_makefile_frag)
*** 142,148 ****
  # It's OK to check for header files.  Although the compiler may not be
  # able to link anything, it had better be able to at least compile
  # something.
! AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h)
  AC_HEADER_SYS_WAIT
  AC_HEADER_TIME
  
--- 142,148 ----
  # It's OK to check for header files.  Although the compiler may not be
  # able to link anything, it had better be able to at least compile
  # something.
! AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h)
  AC_HEADER_SYS_WAIT
  AC_HEADER_TIME
  
*************** vars="sys_errlist sys_nerr sys_siglist"
*** 208,214 ****
  
  checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
  checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp"
! checkfuncs="$checkfuncs getsysinfo table"
  
  # These are neither executed nor required, but they help keep
  # autoheader happy without adding a bunch of text to acconfig.h.
--- 208,214 ----
  
  checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
  checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp"
! checkfuncs="$checkfuncs getsysinfo table sysctl"
  
  # These are neither executed nor required, but they help keep
  # autoheader happy without adding a bunch of text to acconfig.h.
*************** if test "x" = "y"; then
*** 220,226 ****
    AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
    AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
    AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
!   AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table)
    AC_CHECK_FUNCS(realpath canonicalize_file_name)
    AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
    AC_DEFINE(HAVE_SYS_NERR,    1, [Define if you have the sys_nerr variable.])
--- 220,226 ----
    AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
    AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
    AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
!   AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl)
    AC_CHECK_FUNCS(realpath canonicalize_file_name)
    AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
    AC_DEFINE(HAVE_SYS_NERR,    1, [Define if you have the sys_nerr variable.])
Index: physmem.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/physmem.c,v
retrieving revision 1.5
diff -p -r1.5 physmem.c
*** physmem.c	21 Feb 2003 20:33:50 -0000	1.5
--- physmem.c	22 Feb 2003 12:39:19 -0000
***************
*** 42,47 ****
--- 42,57 ----
  #  include <sys/table.h>
  #endif
  
+ #include <sys/types.h>
+ 
+ #if HAVE_SYS_PARAM_H
+ #include <sys/param.h>
+ #endif
+ 
+ #if HAVE_SYS_SYSCTL_H
+ #include <sys/sysctl.h>
+ #endif
+ 
  #include "libiberty.h"
  
  /* Return the total amount of physical memory.  */
*************** physmem_total ()
*** 98,103 ****
--- 108,125 ----
    }
  #endif
  
+ #if HAVE_SYSCTL && defined HW_PHYSMEM
+   { /* This works on *bsd and darwin.  */
+     unsigned int physmem;
+     size_t len = sizeof(physmem);
+     static int mib[2] = {CTL_HW, HW_PHYSMEM};
+ 
+     if (sysctl(mib, ARRAY_SIZE(mib), &physmem, &len, NULL, 0) == 0
+ 	&& len == sizeof (physmem))
+       return (double)physmem;
+   }
+ #endif
+ 
    /* Return 0 if we can't determine the value.  */
    return 0;
  }
*************** physmem_available ()
*** 155,160 ****
--- 177,194 ----
  	if (0 <= pages && 0 <= pagesize)
  	  return pages * pagesize;
        }
+   }
+ #endif
+ 
+ #if HAVE_SYSCTL && defined HW_USERMEM
+   { /* This works on *bsd and darwin.  */
+     unsigned int usermem;
+     size_t len = sizeof(usermem);
+     static int mib[2] = {CTL_HW, HW_PAGESIZE};
+ 
+     if (sysctl(mib, ARRAY_SIZE(mib), &usermem, &len, NULL, 0) == 0
+ 	&& len == sizeof (usermem))
+       return (double)usermem;
    }
  #endif
  

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