Changeset 35554


Ignore:
Timestamp:
2021-10-12T14:55:23+13:00 (3 years ago)
Author:
davidb
Message:

While it was discovered that JAVAGDBM had some macros defined to help with type-casting between pointers and "int/long/jlong" where the pointer is handled 'numerically' as a memory location, it was found during testing under Windows 64-bit that the actual #ifdef that picks out the macro to use wasn't 'firing' correctly as SIZEOF_VOID_P and SIZEOF_LONG were not defined AT ALLsvn status The code change here takes a conservative line: it tests to see if these values are defined, and if not, resorts to a sequence of further #ifdef tests using values that gcc and VisualStudio set based on the 'size of' model for int, long, and pointers, to correcty determine what values they should be

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/packages/javagdbm/jni/gdbmjava.c

    r26674 r35554  
    4141#define GDBM_FILE gdbm_file_info *
    4242extern char* gdbm_version;
     43extern char *gdbm_strerror(gdbm_error);
    4344#else
    4445#include <gdbm.h>
     
    9091jbyteArray datumToArray(JNIEnv *env, datum *fromDatum);
    9192
     93/*
     94   The macros defined below for DBF_TO_JLONG(x) and JLONG_TO_DBF(x)
     95   expect SIZEOF_VOID_P and SIZEOF_LONG to be defined.
     96
     97   It's possible for autoconf to determine these, but:
     98   (a) This currently doesn't appear to be bound into JAVAGDBM
     99       compilation sequence (config.h would need to be #included)
     100   (b) Even if this was done for Unix system, there would still
     101       need to be a way to do this for Windows: both 32-bit and
     102       64-bit as the values would be differnt
     103
     104   In the event SIZEOF_VOID_P and SIZEON_LONG are not already set,
     105   the solution taken here is to test for various #ifdef values
     106   known to be set by Unix/Windows *compilers* that indicate
     107   the type sizes they use for int, long, pointer, and
     108   from that information explicitly set the values used in
     109   the macro definition tests below.
     110
     111   For more details on what these sizes are, two useful references are:
     112
     113     https://en.cppreference.com/w/cpp/language/types
     114     https://unix.org/version2/whatsnew/lp64_wp.html
     115*/
     116
     117#ifndef SIZEOF_VOID_P
     118#  if defined ( _MSC_VER ) /* i.e., Microsoft Visual Studio, not a Mingw based GCC */
     119#    if defined( _WIN64 )
     120#      define SIZEOF_VOID_P 8
     121
     122#    elif defined( _WIN32 )
     123#      define SIZEOF_VOID_P 4
     124
     125#    else
     126#      error Windows OS neither 32-bit nor 64-bit.  SIZEOF_VOID_P not specified
     127#    endif
     128
     129#  else /* Presumably Unix */
     130#    if defined( __ILP32 )     /* i.e., int, long and pointer are all 32-bits */
     131#      define SIZEOF_VOID_P 4
     132
     133#    elif defined( __LP64 )    /* i.e., long, and pointer are both 64-bits */
     134#      define SIZEOF_VOID_P 8
     135
     136#    else
     137#      error Compiler's 'sizeof' model not matched as either IILP32 or LP64.  SIZEOF_VOID_P not specified
     138#    endif
     139#  endif
     140#endif
     141
     142
     143
     144#ifndef SIZEOF_LONG
     145#  if defined ( _MSC_VER ) /* i.e., Microsoft Visual Studio, not a Mingw based GCC */
     146#    if defined( _WIN64 )
     147#      define SIZEOF_LONG 4 /* but note that SIZEOF_VOID_P above is 8 ! */
     148
     149#    elif defined( _WIN32 )
     150#      define SIZEOF_LONG 4
     151
     152#    else
     153#      error Windows OS neither 32-bit nor 64-bit.  SIZEOF_LONG not specified
     154#    endif
     155
     156#  else /* Presumably Unix */
     157#    if defined( __ILP32 )
     158#      define SIZEOF_LONG 4
     159
     160#    elif defined( __LP64 )
     161#      define SIZEOF_LONG 8
     162
     163#    else
     164#      error Compiler's 'sizeof' model not matched as either IILP32 or LP64.  SIZEOF_LONG not specified
     165#    endif
     166#  endif
     167#endif
     168
     169
     170
    92171/* Convert between a jlong and a void ptr using a well-defined cast.
    93172 * (Casting between a pointer and an integer of different sizes spooks
    94173 * both gcc and mbp. */
     174
    95175#if (SIZEOF_VOID_P == SIZEOF_LONG)
    96176#  define DBF_TO_JLONG(x) ((jlong)((long) x))
Note: See TracChangeset for help on using the changeset viewer.