diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac index 588f999..8235c88 100644 --- a/libgfortran/configure.ac +++ b/libgfortran/configure.ac @@ -236,7 +236,12 @@ AC_SUBST(extra_ldflags_libgfortran) LIBGFOR_WORKING_GFORTRAN AC_SYS_LARGEFILE + +# Types AC_TYPE_OFF_T +AC_TYPE_INTPTR_T +AC_TYPE_UINTPTR_T +AC_CHECK_TYPES([ptrdiff_t]) # check header files AC_STDC_HEADERS @@ -264,10 +269,6 @@ AC_CHECK_FUNCS(clock_gettime strftime) # Check for glibc backtrace functions AC_CHECK_FUNCS(backtrace backtrace_symbols) -# Check for types -AC_CHECK_TYPES([intptr_t]) -AC_CHECK_TYPES([uintptr_t]) - # Check libc for getgid, getpid, getuid AC_CHECK_LIB([c],[getgid],[AC_DEFINE([HAVE_GETGID],[1],[libc includes getgid])]) AC_CHECK_LIB([c],[getpid],[AC_DEFINE([HAVE_GETPID],[1],[libc includes getpid])]) diff --git a/libgfortran/intrinsics/cshift0.c b/libgfortran/intrinsics/cshift0.c index 651cd6e..00a50d5 100644 --- a/libgfortran/intrinsics/cshift0.c +++ b/libgfortran/intrinsics/cshift0.c @@ -30,7 +30,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see static void cshift0 (gfc_array_char * ret, const gfc_array_char * array, - ssize_t shift, int which, index_type size) + ptrdiff_t shift, int which, index_type size) { /* r.* indicates the return array. */ index_type rstride[GFC_MAX_DIMENSIONS]; @@ -328,7 +328,7 @@ cshift0 (gfc_array_char * ret, const gfc_array_char * array, rptr = ret->data; sptr = array->data; - shift = len == 0 ? 0 : shift % (ssize_t)len; + shift = len == 0 ? 0 : shift % (ptrdiff_t)len; if (shift < 0) shift += len; diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h index b48582d..37353d7 100644 --- a/libgfortran/io/io.h +++ b/libgfortran/io/io.h @@ -53,22 +53,21 @@ struct gfc_unit; #define is_char4_unit(dtp) ((dtp)->u.p.unit_is_internal && (dtp)->common.unit) /* The array_loop_spec contains the variables for the loops over index ranges - that are encountered. Since the variables can be negative, ssize_t - is used. */ + that are encountered. */ typedef struct array_loop_spec { /* Index counter for this dimension. */ - ssize_t idx; + index_type idx; /* Start for the index counter. */ - ssize_t start; + index_type start; /* End for the index counter. */ - ssize_t end; + index_type end; /* Step for the index counter. */ - ssize_t step; + index_type step; } array_loop_spec; diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index 6e1cb69..39783bf 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -2172,7 +2172,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, } /* Now read the index. */ - if (convert_integer (dtp, sizeof(ssize_t), neg)) + if (convert_integer (dtp, sizeof(index_type), neg)) { if (is_char) sprintf (parse_err_msg, "Bad integer substring qualifier"); @@ -2187,11 +2187,11 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, if (!null_flag) { if (indx == 0) - memcpy (&ls[dim].start, dtp->u.p.value, sizeof(ssize_t)); + memcpy (&ls[dim].start, dtp->u.p.value, sizeof(index_type)); if (indx == 1) - memcpy (&ls[dim].end, dtp->u.p.value, sizeof(ssize_t)); + memcpy (&ls[dim].end, dtp->u.p.value, sizeof(index_type)); if (indx == 2) - memcpy (&ls[dim].step, dtp->u.p.value, sizeof(ssize_t)); + memcpy (&ls[dim].step, dtp->u.p.value, sizeof(index_type)); } /* Singlet or doublet indices. */ @@ -2199,7 +2199,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, { if (indx == 0) { - memcpy (&ls[dim].start, dtp->u.p.value, sizeof(ssize_t)); + memcpy (&ls[dim].start, dtp->u.p.value, sizeof(index_type)); /* If -std=f95/2003 or an array section is specified, do not allow excess data to be processed. */ @@ -2229,10 +2229,10 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, } /* Check the values of the triplet indices. */ - if ((ls[dim].start > (ssize_t) GFC_DIMENSION_UBOUND(ad[dim])) - || (ls[dim].start < (ssize_t) GFC_DIMENSION_LBOUND(ad[dim])) - || (ls[dim].end > (ssize_t) GFC_DIMENSION_UBOUND(ad[dim])) - || (ls[dim].end < (ssize_t) GFC_DIMENSION_LBOUND(ad[dim]))) + if ((ls[dim].start > GFC_DIMENSION_UBOUND(ad[dim])) + || (ls[dim].start < GFC_DIMENSION_LBOUND(ad[dim])) + || (ls[dim].end > GFC_DIMENSION_UBOUND(ad[dim])) + || (ls[dim].end < GFC_DIMENSION_LBOUND(ad[dim]))) { if (is_char) sprintf (parse_err_msg, "Substring out of range"); diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index 987c3cd..4733d51 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -1932,7 +1932,7 @@ obj_loop: { obj->ls[dim_i].idx += nml_carry ; nml_carry = 0; - if (obj->ls[dim_i].idx > (ssize_t) GFC_DESCRIPTOR_UBOUND(obj,dim_i)) + if (obj->ls[dim_i].idx > GFC_DESCRIPTOR_UBOUND(obj,dim_i)) { obj->ls[dim_i].idx = GFC_DESCRIPTOR_LBOUND(obj,dim_i); nml_carry = 1; diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index c9d3f37..7d9aca1 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -106,38 +106,11 @@ typedef off_t gfc_offset; #endif -/* We use intptr_t and uintptr_t, which may not be always defined in - system headers. */ - -#ifndef HAVE_INTPTR_T -#if __SIZEOF_POINTER__ == __SIZEOF_LONG__ -#define intptr_t long -#elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__ -#define intptr_t long long -#elif __SIZEOF_POINTER__ == __SIZEOF_INT__ -#define intptr_t int -#elif __SIZEOF_POINTER__ == __SIZEOF_SHORT__ -#define intptr_t short -#else -#error "Pointer type with unexpected size" -#endif +/* Make sure we have ptrdiff_t. */ +#ifndef HAVE_PTRDIFF_T +typedef intptr_t ptrdiff_t; #endif -#ifndef HAVE_UINTPTR_T -#if __SIZEOF_POINTER__ == __SIZEOF_LONG__ -#define uintptr_t unsigned long -#elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__ -#define uintptr_t unsigned long long -#elif __SIZEOF_POINTER__ == __SIZEOF_INT__ -#define uintptr_t unsigned int -#elif __SIZEOF_POINTER__ == __SIZEOF_SHORT__ -#define uintptr_t unsigned short -#else -#error "Pointer type with unexpected size" -#endif -#endif - - /* On mingw, work around the buggy Windows snprintf() by using the one mingw provides, __mingw_snprintf(). We also provide a prototype for __mingw_snprintf(), because the mingw headers currently don't have one. */ @@ -269,7 +242,7 @@ typedef GFC_INTEGER_4 GFC_IO_INT; /* The following two definitions must be consistent with the types used by the compiler. */ /* The type used of array indices, amongst other things. */ -typedef ssize_t index_type; +typedef ptrdiff_t index_type; /* The type used for the lengths of character variables. */ typedef GFC_INTEGER_4 gfc_charlen_type; @@ -1323,52 +1296,52 @@ internal_proto(count_0); /* Internal auxiliary functions for cshift */ -void cshift0_i1 (gfc_array_i1 *, const gfc_array_i1 *, ssize_t, int); +void cshift0_i1 (gfc_array_i1 *, const gfc_array_i1 *, ptrdiff_t, int); internal_proto(cshift0_i1); -void cshift0_i2 (gfc_array_i2 *, const gfc_array_i2 *, ssize_t, int); +void cshift0_i2 (gfc_array_i2 *, const gfc_array_i2 *, ptrdiff_t, int); internal_proto(cshift0_i2); -void cshift0_i4 (gfc_array_i4 *, const gfc_array_i4 *, ssize_t, int); +void cshift0_i4 (gfc_array_i4 *, const gfc_array_i4 *, ptrdiff_t, int); internal_proto(cshift0_i4); -void cshift0_i8 (gfc_array_i8 *, const gfc_array_i8 *, ssize_t, int); +void cshift0_i8 (gfc_array_i8 *, const gfc_array_i8 *, ptrdiff_t, int); internal_proto(cshift0_i8); #ifdef HAVE_GFC_INTEGER_16 -void cshift0_i16 (gfc_array_i16 *, const gfc_array_i16 *, ssize_t, int); +void cshift0_i16 (gfc_array_i16 *, const gfc_array_i16 *, ptrdiff_t, int); internal_proto(cshift0_i16); #endif -void cshift0_r4 (gfc_array_r4 *, const gfc_array_r4 *, ssize_t, int); +void cshift0_r4 (gfc_array_r4 *, const gfc_array_r4 *, ptrdiff_t, int); internal_proto(cshift0_r4); -void cshift0_r8 (gfc_array_r8 *, const gfc_array_r8 *, ssize_t, int); +void cshift0_r8 (gfc_array_r8 *, const gfc_array_r8 *, ptrdiff_t, int); internal_proto(cshift0_r8); #ifdef HAVE_GFC_REAL_10 -void cshift0_r10 (gfc_array_r10 *, const gfc_array_r10 *, ssize_t, int); +void cshift0_r10 (gfc_array_r10 *, const gfc_array_r10 *, ptrdiff_t, int); internal_proto(cshift0_r10); #endif #ifdef HAVE_GFC_REAL_16 -void cshift0_r16 (gfc_array_r16 *, const gfc_array_r16 *, ssize_t, int); +void cshift0_r16 (gfc_array_r16 *, const gfc_array_r16 *, ptrdiff_t, int); internal_proto(cshift0_r16); #endif -void cshift0_c4 (gfc_array_c4 *, const gfc_array_c4 *, ssize_t, int); +void cshift0_c4 (gfc_array_c4 *, const gfc_array_c4 *, ptrdiff_t, int); internal_proto(cshift0_c4); -void cshift0_c8 (gfc_array_c8 *, const gfc_array_c8 *, ssize_t, int); +void cshift0_c8 (gfc_array_c8 *, const gfc_array_c8 *, ptrdiff_t, int); internal_proto(cshift0_c8); #ifdef HAVE_GFC_COMPLEX_10 -void cshift0_c10 (gfc_array_c10 *, const gfc_array_c10 *, ssize_t, int); +void cshift0_c10 (gfc_array_c10 *, const gfc_array_c10 *, ptrdiff_t, int); internal_proto(cshift0_c10); #endif #ifdef HAVE_GFC_COMPLEX_16 -void cshift0_c16 (gfc_array_c16 *, const gfc_array_c16 *, ssize_t, int); +void cshift0_c16 (gfc_array_c16 *, const gfc_array_c16 *, ptrdiff_t, int); internal_proto(cshift0_c16); #endif diff --git a/libgfortran/m4/cshift0.m4 b/libgfortran/m4/cshift0.m4 index 0c5e015..5c0d22e 100644 --- a/libgfortran/m4/cshift0.m4 +++ b/libgfortran/m4/cshift0.m4 @@ -33,7 +33,7 @@ include(iparm.m4)dnl `#if defined (HAVE_'rtype_name`) void -cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, ssize_t shift, +cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, ptrdiff_t shift, int which) { /* r.* indicates the return array. */ @@ -98,7 +98,7 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, ssize_t shift, rptr = ret->data; sptr = array->data; - shift = len == 0 ? 0 : shift % (ssize_t)len; + shift = len == 0 ? 0 : shift % (ptrdiff_t)len; if (shift < 0) shift += len;