This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[gfortran,patch] Complete libgfortran namespace separation and version number


:ADDPATCH fortran:

Attached patch does the following three things:
 - add an undocumented -fallow-leading-underscore option to gfortran,
for internal use only, until the ISO_C_BINDING patch is commited, that
allows symbol names to begin with an underscore (note: it does
explicitely ICE if one of these variables has implicit type)
 - use this to prefix all libgfortran symbols names with _gfortran_
(this was not the case before, especially for specifics), achieving
complete namespace separation for the library
 - bump the libgfortran version number to 4.3.0

Bootstrapped & regtested on i686-linux. OK for mainline?

FX

Attachment: namespace_cleanup.ChangeLog
Description: Binary data

Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c	(revision 120530)
+++ gcc/fortran/symbol.c	(working copy)
@@ -202,6 +202,12 @@
   char letter;
 
   letter = sym->name[0];
+
+  if (gfc_option.flag_allow_leading_underscore && letter == '_')
+    gfc_internal_error ("Option -fallow_leading_underscore is for use only by "
+			"gfortran developpers, and should not be used for "
+			"implicitely typed variables");
+
   if (letter < 'a' || letter > 'z')
     gfc_internal_error ("gfc_get_default_type(): Bad symbol");
 
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 120530)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -1656,6 +1656,7 @@
   int flag_f2c;
   int flag_automatic;
   int flag_backslash;
+  int flag_allow_leading_underscore;
   int flag_external_blas;
   int blas_matmul_limit;
   int flag_cray_pointer;
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 120530)
+++ gcc/fortran/lang.opt	(working copy)
@@ -77,6 +77,10 @@
 Fortran RejectNegative
 All intrinsics procedures are available regardless of selected standard
 
+fallow-leading-underscore
+Fortran Undocumented
+; For internal use only: allow the first character of symbol names to be an underscore
+
 fautomatic
 Fortran
 Do not treat local variables and COMMON blocks as if they were named in SAVE statements
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 120530)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1059,7 +1059,7 @@
   gfc_expr e;
   gfc_intrinsic_sym *isym;
   gfc_expr argexpr;
-  char s[GFC_MAX_SYMBOL_LEN + 13]; /* "f2c_specific" and '\0'.  */
+  char s[GFC_MAX_SYMBOL_LEN + 23]; /* "_gfortran_f2c_specific" and '\0'.  */
   tree name;
   tree mangled_name;
 
@@ -1107,10 +1107,10 @@
 	{
 	  /* Specific which needs a different implementation if f2c
 	     calling conventions are used.  */
-	  sprintf (s, "f2c_specific%s", e.value.function.name);
+	  sprintf (s, "_gfortran_f2c_specific%s", e.value.function.name);
 	}
       else
-	sprintf (s, "specific%s", e.value.function.name);
+	sprintf (s, "_gfortran_specific%s", e.value.function.name);
 
       name = get_identifier (s);
       mangled_name = name;
@@ -2081,13 +2081,15 @@
 				     gfc_charlen_type_node, pchar_type_node);
 
   gfor_fndecl_si_kind =
-    gfc_build_library_function_decl (get_identifier ("selected_int_kind"),
+    gfc_build_library_function_decl (get_identifier
+					(PREFIX("selected_int_kind")),
                                      gfc_int4_type_node,
                                      1,
                                      pvoid_type_node);
 
   gfor_fndecl_sr_kind =
-    gfc_build_library_function_decl (get_identifier ("selected_real_kind"),
+    gfc_build_library_function_decl (get_identifier 
+					(PREFIX("selected_real_kind")),
                                      gfc_int4_type_node,
                                      2, pvoid_type_node,
                                      pvoid_type_node);
Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c	(revision 120530)
+++ gcc/fortran/match.c	(working copy)
@@ -394,7 +394,7 @@
   gfc_gobble_whitespace ();
 
   c = gfc_next_char ();
-  if (!ISALPHA (c))
+  if (!(ISALPHA (c) || (c == '_' && gfc_option.flag_allow_leading_underscore)))
     {
       gfc_current_locus = old_loc;
       return MATCH_NO;
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 120530)
+++ gcc/fortran/options.c	(working copy)
@@ -83,6 +83,7 @@
   gfc_option.flag_preprocessed = 0;
   gfc_option.flag_automatic = 1;
   gfc_option.flag_backslash = 1;
+  gfc_option.flag_allow_leading_underscore = 0;
   gfc_option.flag_external_blas = 0;
   gfc_option.blas_matmul_limit = 30;
   gfc_option.flag_cray_pointer = 0;
@@ -442,6 +443,10 @@
       gfc_option.flag_automatic = value;
       break;
 
+    case OPT_fallow_leading_underscore:
+      gfc_option.flag_allow_leading_underscore = value;
+      break;
+      
     case OPT_fbackslash:
       gfc_option.flag_backslash = value;
       break;
Index: libgfortran/m4/misc_specifics.m4
===================================================================
--- libgfortran/m4/misc_specifics.m4	(revision 120530)
+++ libgfortran/m4/misc_specifics.m4	(working copy)
@@ -22,10 +22,10 @@
 dnl   NINT specifics
 foreach(`ikind', `(4, 8, 16)', `foreach(`rkind', `(4, 8, 10, 16)', `
 `#if defined (HAVE_GFC_REAL_'rkind`) && defined (HAVE_GFC_INTEGER_'ikind`)'
-elemental function specific__nint_`'ikind`_'rkind (parm)
+elemental function _gfortran_specific__nint_`'ikind`_'rkind (parm)
    real (kind=rkind) , intent (in) :: parm
-   integer (kind=ikind) :: specific__nint_`'ikind`_'rkind
-   specific__nint_`'ikind`_'rkind = nint (parm)
+   integer (kind=ikind) :: _gfortran_specific__nint_`'ikind`_'rkind
+   _gfortran_specific__nint_`'ikind`_'rkind = nint (parm)
 end function
 #endif
 ')')
@@ -33,10 +33,10 @@
 dnl   CHAR specifics
 foreach(`ckind', `(1)', `foreach(`ikind', `(4, 8, 16)', `
 `#if defined (HAVE_GFC_INTEGER_'ikind`)'
-elemental function specific__char_`'ckind`_i'ikind (parm)
+elemental function _gfortran_specific__char_`'ckind`_i'ikind (parm)
    integer (kind=ikind) , intent (in) :: parm
-   character (kind=ckind,len=1) :: specific__char_`'ckind`_i'ikind
-   specific__char_`'ckind`_i'ikind` = char (parm, kind='ckind`)'
+   character (kind=ckind,len=1) :: _gfortran_specific__char_`'ckind`_i'ikind
+   _gfortran_specific__char_`'ckind`_i'ikind` = char (parm, kind='ckind`)'
 end function
 #endif
 ')')
@@ -44,10 +44,10 @@
 dnl   LEN specifics
 foreach(`ckind', `(1)', `foreach(`ikind', `(4, 8, 16)', `
 `#if defined (HAVE_GFC_INTEGER_'ikind`)'
-elemental function specific__len_`'ckind`_i'ikind (parm)
+elemental function _gfortran_specific__len_`'ckind`_i'ikind (parm)
    character (kind=ckind,len=*) , intent (in) :: parm
-   integer (kind=ikind) :: specific__len_`'ckind`_i'ikind
-   specific__len_`'ckind`_i'ikind` = len (parm)'
+   integer (kind=ikind) :: _gfortran_specific__len_`'ckind`_i'ikind
+   _gfortran_specific__len_`'ckind`_i'ikind` = len (parm)'
 end function
 #endif
 ')')
@@ -55,10 +55,10 @@
 dnl   INDEX specifics
 foreach(`ckind', `(1)', `foreach(`ikind', `(4, 8, 16)', `
 `#if defined (HAVE_GFC_INTEGER_'ikind`)'
-elemental function specific__index_`'ckind`_i'ikind (parm1, parm2)
+elemental function _gfortran_specific__index_`'ckind`_i'ikind (parm1, parm2)
    character (kind=ckind,len=*) , intent (in) :: parm1, parm2
-   integer (kind=ikind) :: specific__index_`'ckind`_i'ikind
-   specific__index_`'ckind`_i'ikind` = index (parm1, parm2)'
+   integer (kind=ikind) :: _gfortran_specific__index_`'ckind`_i'ikind
+   _gfortran_specific__index_`'ckind`_i'ikind` = index (parm1, parm2)'
 end function
 #endif
 ')')
Index: libgfortran/m4/specific2.m4
===================================================================
--- libgfortran/m4/specific2.m4	(revision 120530)
+++ libgfortran/m4/specific2.m4	(working copy)
@@ -6,7 +6,7 @@
 define(get_typename, `get_typename2(ifelse($1,i,integer,ifelse($1,r,real,ifelse($1,l,logical,ifelse($1,c,complex,unknown)))),`$2')')dnl
 define(atype_name, get_typename(atype_letter,atype_kind))dnl
 define(name, regexp(regexp(file, `[^/]*$', `\&'), `^_\([^_]*\)_', `\1'))dnl
-define(function_name,`specific__'name`_'atype_code)dnl
+define(function_name,`_gfortran_specific__'name`_'atype_code)dnl
 
 define(Q,ifelse(atype_kind,4,F,ifelse(atype_kind,8,`',ifelse(atype_kind,10,L,ifelse(atype_kind,16,L,`_'atype_kind)))))dnl
 
Index: libgfortran/m4/specific.m4
===================================================================
--- libgfortran/m4/specific.m4	(revision 120530)
+++ libgfortran/m4/specific.m4	(working copy)
@@ -7,7 +7,7 @@
 define(atype_name, get_typename(atype_letter,atype_kind))dnl
 define(name, regexp(regexp(file, `[^/]*$', `\&'), `^_\([^_]*\)_', `\1'))dnl
 define(rtype_name,get_typename(ifelse(name,abs,ifelse(atype_letter,c,r,atype_letter),ifelse(name,aimag,ifelse(atype_letter,c,r,atype_letter),atype_letter)),atype_kind))dnl
-define(function_name,ifelse(name,conjg,`specific__conjg_'atype_kind,`specific__'name`_'atype_code))dnl
+define(function_name,ifelse(name,conjg,`_gfortran_specific__conjg_'atype_kind,`_gfortran_specific__'name`_'atype_code))dnl
 
 define(type,ifelse(atype_letter,l,LOGICAL,ifelse(atype_letter,i,INTEGER,ifelse(atype_letter,r,REAL,ifelse(atype_letter,c,COMPLEX,UNKNOW)))))dnl
 define(Q,ifelse(atype_kind,4,F,ifelse(atype_kind,8,`',ifelse(atype_kind,10,L,ifelse(atype_kind,16,L,`_'atype_kind)))))dnl
Index: libgfortran/intrinsics/selected_int_kind.f90
===================================================================
--- libgfortran/intrinsics/selected_int_kind.f90	(revision 120530)
+++ libgfortran/intrinsics/selected_int_kind.f90	(working copy)
@@ -19,10 +19,10 @@
 !Boston, MA 02110-1301, USA.
 !
 
-function selected_int_kind (r)
+function _gfortran_selected_int_kind (r)
   implicit none
   integer, intent (in) :: r
-  integer :: selected_int_kind
+  integer :: _gfortran_selected_int_kind
   integer :: i
   ! Integer kind_range table
   type :: int_info
@@ -34,10 +34,10 @@
 
   do i = 1, c
     if (r <= int_infos (i) % range) then
-      selected_int_kind = int_infos (i) % kind
+      _gfortran_selected_int_kind = int_infos (i) % kind
       return
     end if
   end do
-  selected_int_kind = -1
+  _gfortran_selected_int_kind = -1
   return
 end function
Index: libgfortran/intrinsics/selected_real_kind.f90
===================================================================
--- libgfortran/intrinsics/selected_real_kind.f90	(revision 120530)
+++ libgfortran/intrinsics/selected_real_kind.f90	(working copy)
@@ -19,10 +19,10 @@
 !Boston, MA 02110-1301, USA.
 !
 
-function selected_real_kind (p, r)
+function _gfortran_selected_real_kind (p, r)
   implicit none
   integer, optional, intent (in) :: p, r
-  integer :: selected_real_kind
+  integer :: _gfortran_selected_real_kind
   integer :: i, p2, r2
   logical :: found_p, found_r
   ! Real kind_precision_range table
@@ -34,7 +34,7 @@
 
   include "selected_real_kind.inc"
 
-  selected_real_kind = 0
+  _gfortran_selected_real_kind = 0
   p2 = 0
   r2 = 0
   found_p = .false.
@@ -49,13 +49,13 @@
     if (p2 <= real_infos (i) % precision) found_p = .true.
     if (r2 <= real_infos (i) % range) found_r = .true.
     if (found_p .and. found_r) then
-      selected_real_kind = real_infos (i) % kind
+      _gfortran_selected_real_kind = real_infos (i) % kind
       return
     end if
   end do
 
-  if (.not. (found_p)) selected_real_kind = selected_real_kind - 1
-  if (.not. (found_r)) selected_real_kind = selected_real_kind - 2
+  if (.not. (found_p)) _gfortran_selected_real_kind = _gfortran_selected_real_kind - 1
+  if (.not. (found_r)) _gfortran_selected_real_kind = _gfortran_selected_real_kind - 2
 
   return
 end function
Index: libgfortran/intrinsics/f2c_specifics.F90
===================================================================
--- libgfortran/intrinsics/f2c_specifics.F90	(revision 120530)
+++ libgfortran/intrinsics/f2c_specifics.F90	(working copy)
@@ -41,7 +41,7 @@
 
 ! one argument functions
 #define REAL_HEAD(NAME) \
-elemental function f2c_specific__/**/NAME/**/_r4 (parm) result(res);
+elemental function _gfortran_f2c_specific__/**/NAME/**/_r4 (parm) result(res);
 
 #define REAL_BODY(NAME) \
   REAL, intent (in) :: parm; \
@@ -50,7 +50,7 @@
 end function
 
 #define COMPLEX_HEAD(NAME) \
-subroutine f2c_specific__/**/NAME/**/_c4 (res, parm);
+subroutine _gfortran_f2c_specific__/**/NAME/**/_c4 (res, parm);
 
 #define COMPLEX_BODY(NAME) \
   COMPLEX, intent (in) :: parm; \
@@ -59,7 +59,7 @@
 end subroutine
 
 #define DCOMPLEX_HEAD(NAME) \
-subroutine f2c_specific__/**/NAME/**/_c8 (res, parm);
+subroutine _gfortran_f2c_specific__/**/NAME/**/_c8 (res, parm);
 
 #define DCOMPLEX_BODY(NAME) \
   DOUBLE COMPLEX, intent (in) :: parm; \
@@ -71,7 +71,7 @@
 REAL_BODY(abs)
 
 ! abs is special in that the result is real
-elemental function f2c_specific__abs_c4 (parm) result (res)
+elemental function _gfortran_f2c_specific__abs_c4 (parm) result (res)
   COMPLEX, intent(in) :: parm
   DOUBLE PRECISION :: res
   res = abs(parm)
@@ -79,16 +79,16 @@
 
 
 ! aimag is special in that the result is real
-elemental function f2c_specific__aimag_c4 (parm)
+elemental function _gfortran_f2c_specific__aimag_c4 (parm)
   complex(kind=4), intent(in) :: parm
-  double precision :: f2c_specific__aimag_c4
-  f2c_specific__aimag_c4 = aimag(parm)
+  double precision :: _gfortran_f2c_specific__aimag_c4
+  _gfortran_f2c_specific__aimag_c4 = aimag(parm)
 end function
 
-elemental function f2c_specific__aimag_c8 (parm)
+elemental function _gfortran_f2c_specific__aimag_c8 (parm)
   complex(kind=8), intent(in) :: parm
-  double precision :: f2c_specific__aimag_c8
-  f2c_specific__aimag_c8 = aimag(parm)
+  double precision :: _gfortran_f2c_specific__aimag_c8
+  _gfortran_f2c_specific__aimag_c8 = aimag(parm)
 end function
 
 
@@ -168,7 +168,7 @@
 
 ! two argument functions
 #define REAL2_HEAD(NAME) \
-elemental function f2c_specific__/**/NAME/**/_r4 (p1, p2) result(res);
+elemental function _gfortran_f2c_specific__/**/NAME/**/_r4 (p1, p2) result(res);
 
 #define REAL2_BODY(NAME) \
   REAL, intent (in) :: p1, p2; \
@@ -189,12 +189,12 @@
 REAL2_BODY(mod)
 
 ! conjg is special-cased because it is not suffixed _c4 but _4
-subroutine f2c_specific__conjg_4 (res, parm)
+subroutine _gfortran_f2c_specific__conjg_4 (res, parm)
   COMPLEX, intent (in) :: parm
   COMPLEX, intent (out) :: res
   res = conjg (parm)
 end subroutine
-subroutine f2c_specific__conjg_8 (res, parm)
+subroutine _gfortran_f2c_specific__conjg_8 (res, parm)
   DOUBLE COMPLEX, intent (in) :: parm
   DOUBLE COMPLEX, intent (out) :: res
   res = conjg (parm)
Index: libgfortran/intrinsics/dprod_r8.f90
===================================================================
--- libgfortran/intrinsics/dprod_r8.f90	(revision 120530)
+++ libgfortran/intrinsics/dprod_r8.f90	(working copy)
@@ -19,9 +19,9 @@
 !Boston, MA 02110-1301, USA.
 
 
-elemental function specific__dprod_r8 (p1, p2)
+elemental function _gfortran_specific__dprod_r8 (p1, p2)
    real (kind=4), intent (in) :: p1, p2
-   real (kind=8) :: specific__dprod_r8
+   real (kind=8) :: _gfortran_specific__dprod_r8
 
-   specific__dprod_r8 = dprod (p1, p2)
+   _gfortran_specific__dprod_r8 = dprod (p1, p2)
 end function
Index: libgfortran/libtool-version
===================================================================
--- libgfortran/libtool-version	(revision 120530)
+++ libgfortran/libtool-version	(working copy)
@@ -3,4 +3,4 @@
 # This is a separate file so that version updates don't involve re-running
 # automake.
 # CURRENT:REVISION:AGE
-2:0:0
+3:0:0
Index: libgfortran/Makefile.am
===================================================================
--- libgfortran/Makefile.am	(revision 120530)
+++ libgfortran/Makefile.am	(working copy)
@@ -601,6 +601,10 @@
 # Logical matmul doesn't vectorize.
 $(patsubst %.c,%.lo,$(notdir $(i_matmull_c))): AM_CFLAGS += -funroll-loops
 
+# Add the -fallow-leading-underscore option when needed
+$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore
+selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore
+
 BUILT_SOURCES=$(gfor_built_src) $(gfor_built_specific_src) \
     $(gfor_built_specific2_src) $(gfor_misc_specifics)
 libgfortran_la_SOURCES = $(gfor_src) $(gfor_built_src) $(gfor_io_src) \

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