Ticket #1843: 0001-Make-config-gen-platform-generic-sysmem.c-more-gener.patch
File 0001-Make-config-gen-platform-generic-sysmem.c-more-gener.patch, 7.6 KB (added by doughera, 11 years ago) |
---|
-
MANIFEST
From 7ab24b3fbcdfadc315bbab87d8840e6d78f23bf5 Mon Sep 17 00:00:00 2001 From: Andy Dougherty <doughera@fractal.phys.lafayette.edu> Date: Fri, 3 Dec 2010 12:11:10 -0500 Subject: [PATCH] Make config/gen/platform/generic/sysmem.c more generic. Include the two most likely methods (sysconf and sysctl) in the generic file, based on various #ifdef probes. This way, new systems are more likely to work without first needing their own sysmem.c file. If neither sysconf() nor sysctl() seems to work, assume a default of 512 MB. One could certainly argue for putting an error message here instead. --- MANIFEST | 2 - config/auto/headers.pm | 2 +- config/gen/platform/freebsd/sysmem.c | 69 ---------------------------------- config/gen/platform/generic/sysmem.c | 56 ++++++++++++++++++++++++++- config/gen/platform/netbsd/sysmem.c | 69 ---------------------------------- 5 files changed, 54 insertions(+), 144 deletions(-) delete mode 100644 config/gen/platform/freebsd/sysmem.c delete mode 100644 config/gen/platform/netbsd/sysmem.c diff --git a/MANIFEST b/MANIFEST index eec496a..bb111e8 100644
a b 240 240 config/gen/platform/darwin/begin.c [] 241 241 config/gen/platform/darwin/hires_timer.c [] 242 242 config/gen/platform/darwin/sysmem.c [] 243 config/gen/platform/freebsd/sysmem.c []244 243 config/gen/platform/generic/dl.c [] 245 244 config/gen/platform/generic/dl.h [] 246 245 config/gen/platform/generic/env.c [] … … 264 263 config/gen/platform/netbsd/math.c [] 265 264 config/gen/platform/netbsd/misc.c [] 266 265 config/gen/platform/netbsd/misc.h [] 267 config/gen/platform/netbsd/sysmem.c []268 266 config/gen/platform/openbsd/math.c [] 269 267 config/gen/platform/openbsd/memexec.c [] 270 268 config/gen/platform/openbsd/misc.h [] -
config/auto/headers.pm
diff --git a/config/auto/headers.pm b/config/auto/headers.pm index f52b3be..8f2338d 100644
a b 97 97 # the header. 98 98 my @extra_headers = qw(malloc.h fcntl.h setjmp.h pthread.h signal.h 99 99 sys/types.h sys/socket.h netinet/in.h arpa/inet.h 100 sys/stat.h sysexit.h limits.h );100 sys/stat.h sysexit.h limits.h sys/sysctl.h); 101 101 102 102 # more extra_headers needed on mingw/msys; *BSD fails if they are present 103 103 if ( $conf->data->get('OSNAME_provisional') eq "msys" ) { -
(a) a/config/gen/platform/freebsd/sysmem.c vs. (b) /dev/null
diff --git a/config/gen/platform/freebsd/sysmem.c b/config/gen/platform/freebsd/sysmem.c deleted file mode 100644 index 4d21d74..0000000
a b 1 /*2 * Copyright (C) 2010, Parrot Foundation.3 */4 5 /*6 7 =head1 NAME8 9 config/gen/platform/freebsd/sysmem.c10 11 =head1 DESCRIPTION12 13 Get system memory information.14 15 =head2 Functions16 17 =over 418 19 =cut20 21 */22 #include <sys/sysctl.h>23 #include <stdio.h>24 25 /*26 27 =item C<size_t Parrot_sysmem_amount(PARROT_INTERP)>28 29 Get information about available physical memory.30 31 =cut32 33 */34 35 size_t36 Parrot_sysmem_amount(PARROT_INTERP)37 {38 int err = 0;39 size_t memsize = 0;40 char *err_msg;41 unsigned long length = sizeof (memsize);42 43 int selection[2] = { CTL_HW, HW_PHYSMEM };44 45 err = sysctl(selection, 2, &memsize, &length, NULL, 0);46 47 if (err) {48 err_msg = strerror(err);49 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR,50 "sysctl failed: %s", err_msg);51 }52 53 return memsize;54 }55 56 /*57 58 =back59 60 =cut61 62 */63 64 /*65 * Local variables:66 * c-file-style: "parrot"67 * End:68 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :69 */ -
config/gen/platform/generic/sysmem.c
diff --git a/config/gen/platform/generic/sysmem.c b/config/gen/platform/generic/sysmem.c index d2f2c82..5293b97 100644
a b 20 20 21 21 */ 22 22 23 #include <stdio.h> 23 24 #include <unistd.h> 24 25 #include "parrot/sysmem.h" 25 26 26 #if def _SC_PAGESIZE /* some SVR4 systems omit an underscore */27 # define _SC_PAGE_SIZE _SC_PAGESIZE27 #if defined(PARROT_HAS_HEADER_SYSSYSCTL) 28 # include <sys/sysctl.h> 28 29 #endif 29 30 30 31 /* … … 37 38 38 39 */ 39 40 41 /* 42 * The POSIX name is _SC_PAGESIZE, but apparently some systems 43 * require _SC_PAGE_SIZE instead. (Specific citations would 44 * be useful.) 45 */ 46 #if !defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE) 47 # define _SC_PAGESIZE _SC_PAGE_SIZE 48 #endif 49 40 50 size_t 41 51 Parrot_sysmem_amount(PARROT_INTERP) 42 52 { 43 return sysconf(_SC_AVPHYS_PAGES) * sysconf(_SC_PAGE_SIZE); 53 size_t memsize = 0; 54 55 #if defined(_SC_PAGESIZE) && defined(_SC_AVPHYS_PAGES) 56 /* Method 1: sysconf(). 57 * Works on Linux and Solaris, and probably other SVR4-related systems. 58 * This should really check for #ifdef HAS_SYSCONF, but Configure 59 * doesn't probe for that yet. 60 */ 61 memsize = sysconf(_SC_AVPHYS_PAGES) * sysconf(_SC_PAGESIZE); 62 63 #elif defined(PARROT_HAS_HEADER_SYSSYSCTL) && defined(CTL_HW) && defined(HW_PHYSMEM) 64 65 /* Method 2: sysctl(). Works on BSD-derived systems. Darwin is 66 * slightly different, and has its own implementation. 67 * Configure really should test for HAS_SYSCTL, but, for now, test for 68 * the header sys/sysctl.h and the appropriate constants. 69 */ 70 71 int err = 0; 72 char *err_msg; 73 unsigned long length = sizeof (memsize); 74 75 int selection[2] = { CTL_HW, HW_PHYSMEM }; 76 77 err = sysctl(selection, 2, &memsize, &length, NULL, 0); 78 79 if (err) { 80 err_msg = strerror(err); 81 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR, 82 "sysctl failed: %s", err_msg); 83 } 84 85 #else 86 /* Method 3: Random guess. Simply guess 512 MB. This way, parrot 87 * will at least build. Arguably, one could also just put an error 88 * here and instruct the user to fix it manually. 89 */ 90 memsize = 512 * 1024 * 1024; 91 #endif 92 93 return memsize; 44 94 } 45 95 46 96 /* -
(a) a/config/gen/platform/netbsd/sysmem.c vs. (b) /dev/null
diff --git a/config/gen/platform/netbsd/sysmem.c b/config/gen/platform/netbsd/sysmem.c deleted file mode 100644 index 37594d7..0000000
a b 1 /*2 * Copyright (C) 2010, Parrot Foundation.3 */4 5 /*6 7 =head1 NAME8 9 config/gen/platform/netbsd/sysmem.c10 11 =head1 DESCRIPTION12 13 Get system memory information.14 15 =head2 Functions16 17 =over 418 19 =cut20 21 */22 #include <sys/sysctl.h>23 #include <stdio.h>24 25 /*26 27 =item C<size_t Parrot_sysmem_amount(PARROT_INTERP)>28 29 Get information about available physical memory.30 31 =cut32 33 */34 35 size_t36 Parrot_sysmem_amount(PARROT_INTERP)37 {38 int err = 0;39 size_t memsize = 0;40 char *err_msg;41 unsigned long length = sizeof (memsize);42 43 int selection[2] = { CTL_HW, HW_PHYSMEM };44 45 err = sysctl(selection, 2, &memsize, &length, NULL, 0);46 47 if (err) {48 err_msg = strerror(err);49 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR,50 "sysctl failed: %s", err_msg);51 }52 53 return memsize;54 }55 56 /*57 58 =back59 60 =cut61 62 */63 64 /*65 * Local variables:66 * c-file-style: "parrot"67 * End:68 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :69 */