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, 4 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  
    240240config/gen/platform/darwin/begin.c                          [] 
    241241config/gen/platform/darwin/hires_timer.c                    [] 
    242242config/gen/platform/darwin/sysmem.c                         [] 
    243 config/gen/platform/freebsd/sysmem.c                        [] 
    244243config/gen/platform/generic/dl.c                            [] 
    245244config/gen/platform/generic/dl.h                            [] 
    246245config/gen/platform/generic/env.c                           [] 
     
    264263config/gen/platform/netbsd/math.c                           [] 
    265264config/gen/platform/netbsd/misc.c                           [] 
    266265config/gen/platform/netbsd/misc.h                           [] 
    267 config/gen/platform/netbsd/sysmem.c                         [] 
    268266config/gen/platform/openbsd/math.c                          [] 
    269267config/gen/platform/openbsd/memexec.c                       [] 
    270268config/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  
    9797    # the header. 
    9898    my @extra_headers = qw(malloc.h fcntl.h setjmp.h pthread.h signal.h 
    9999        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); 
    101101 
    102102    # more extra_headers needed on mingw/msys; *BSD fails if they are present 
    103103    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 NAME 
    8  
    9 config/gen/platform/freebsd/sysmem.c 
    10  
    11 =head1 DESCRIPTION 
    12  
    13 Get system memory information. 
    14  
    15 =head2 Functions 
    16  
    17 =over 4 
    18  
    19 =cut 
    20  
    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 =cut 
    32  
    33 */ 
    34  
    35 size_t 
    36 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 =back 
    59  
    60 =cut 
    61  
    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  
    2020 
    2121*/ 
    2222 
     23#include <stdio.h> 
    2324#include <unistd.h> 
    2425#include "parrot/sysmem.h" 
    2526 
    26 #ifdef _SC_PAGESIZE         /* some SVR4 systems omit an underscore */ 
    27 define  _SC_PAGE_SIZE _SC_PAGESIZE 
     27#if defined(PARROT_HAS_HEADER_SYSSYSCTL) 
     28include <sys/sysctl.h> 
    2829#endif 
    2930 
    3031/* 
     
    3738 
    3839*/ 
    3940 
     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 
    4050size_t 
    4151Parrot_sysmem_amount(PARROT_INTERP) 
    4252{ 
    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; 
    4494} 
    4595 
    4696/* 
  • (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 NAME 
    8  
    9 config/gen/platform/netbsd/sysmem.c 
    10  
    11 =head1 DESCRIPTION 
    12  
    13 Get system memory information. 
    14  
    15 =head2 Functions 
    16  
    17 =over 4 
    18  
    19 =cut 
    20  
    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 =cut 
    32  
    33 */ 
    34  
    35 size_t 
    36 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 =back 
    59  
    60 =cut 
    61  
    62 */ 
    63  
    64 /* 
    65  * Local variables: 
    66  *   c-file-style: "parrot" 
    67  * End: 
    68  * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : 
    69  */