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

[Fwd: Re: Bug in g2c.h for calling Fortran vom C++ (not C)]


Mark,

This is a regression w.r.t. 2.95.x. I'm getting bug reports about it, so it seems to be relevant, now.

Could this go in when the 3.2.1 is released (so that it will show up in 3.2.2.) ?

Thanks in advance,

--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
--- Begin Message ---
Toon Moene wrote:

> Peter Englmaier wrote:

> > I used C++ to call FORTRAN and it worked fine until I upgraded to
> > Redhat 7.2 from Redhat 6.2. As explained in the g77 manual, I used the
> > g2c.h header to call the fortran subroutines from C and C++:
> >
> > #ifdef __cplusplus
> > extern "C" {
> > #endif
> >
> > #include <g2c.h>
> > void f77open_dmp(int *,int *,char *,float *, ftnlen);
> >
> > #ifdef __cplusplus
> > }
> > #endif
> >
> > This worked fine with older Versions of both C and C++, but with the
> > new version gcc 2.96 (included in Redhat 7.2) as well as gcc 3.0.1 (also
> > included in Redhat 7.2) it stopped working with C++. Apparently, some
> > internal variables are no longer pre-defined, namely:
> > __g77_integer, __g77_uinteger, __g77_longint, __g77_ulongint.
> > As a workaround I now define those types myself and it compiles OK.
> >
> > Please let me know, if this is (i) a gcc bug which will is/will be
> > fixed with more recent versions), or (ii) a bug from Redhat. In the
> > later case I will report the bug to Redhat as well.

> Well, let's call it an oversight.  __g77_integer and friends became
> internalised into the C compiler shortly before Red Hat forked its 2.96
> release.
> 
> I approved that internalisation without realising that it would break
> compiling interfaces with C++ (you are the first one to complain about
> it, actually).
> 
> The solution is to move these internal declarations from c-decl.c to
> c-common.c.  I'll try to come up with a patch for that (the C-like
> frontends are not my area of expertise).  It's uncertain whether it will
> be in time for the 3.1 release (which is imminent).

I tested the following patch on the trunk; it solves the problem (make
bootstrap, make check, make install for all languages on
i686-pc-linux-gnu - no regressions).

Could someone approve this for mainline ?

Mark, would this be OK for the 3.1 branch ?  It is a regression with
respect to 2.95.

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
2002-04-10  Toon Moene  <toon@moene.indiv.nluug.nl>

	* c-decl.c (c_init_decl_processing): Move generation of
	decls for g77_integer_type_node and friends from here ...
	* c-common.c (c_common_nodes_and_builtins): ... to here.

*** c-decl.c.orig	Sat Apr  6 20:23:05 2002
--- c-decl.c	Tue Apr  9 22:26:17 2002
*************** c_init_decl_processing ()
*** 2932,2984 ****
  			   tree_cons (NULL_TREE, ptr_type_node, endlink));
  
-   /* Types which are common to the fortran compiler and libf2c.  When
-      changing these, you also need to be concerned with f/com.h.  */
- 
-   if (TYPE_PRECISION (float_type_node)
-       == TYPE_PRECISION (long_integer_type_node))
-     {
-       g77_integer_type_node = long_integer_type_node;
-       g77_uinteger_type_node = long_unsigned_type_node;
-     }
-   else if (TYPE_PRECISION (float_type_node)
- 	   == TYPE_PRECISION (integer_type_node))
-     {
-       g77_integer_type_node = integer_type_node;
-       g77_uinteger_type_node = unsigned_type_node;
-     }
-   else
-     g77_integer_type_node = g77_uinteger_type_node = NULL_TREE;
- 
-   if (g77_integer_type_node != NULL_TREE)
-     {
-       pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_integer"),
- 			    g77_integer_type_node));
-       pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_uinteger"),
- 			    g77_uinteger_type_node));
-     }
- 
-   if (TYPE_PRECISION (float_type_node) * 2
-       == TYPE_PRECISION (long_integer_type_node))
-     {
-       g77_longint_type_node = long_integer_type_node;
-       g77_ulongint_type_node = long_unsigned_type_node;
-     }
-   else if (TYPE_PRECISION (float_type_node) * 2
- 	   == TYPE_PRECISION (long_long_integer_type_node))
-     {
-       g77_longint_type_node = long_long_integer_type_node;
-       g77_ulongint_type_node = long_long_unsigned_type_node;
-     }
-   else
-     g77_longint_type_node = g77_ulongint_type_node = NULL_TREE;
- 
-   if (g77_longint_type_node != NULL_TREE)
-     {
-       pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_longint"),
- 			    g77_longint_type_node));
-       pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_ulongint"),
- 			    g77_ulongint_type_node));
-     }
- 
    pedantic_lvalues = pedantic;
  
--- 2932,2935 ----
*** c-common.c.orig	Sat Apr  6 20:23:05 2002
--- c-common.c	Tue Apr  9 22:22:06 2002
*************** c_common_nodes_and_builtins ()
*** 2653,2656 ****
--- 2653,2709 ----
  		 complex_long_double_type_node));
  
+   /* Types which are common to the fortran compiler and libf2c.  When
+      changing these, you also need to be concerned with f/com.h.  */
+ 
+   if (TYPE_PRECISION (float_type_node)
+       == TYPE_PRECISION (long_integer_type_node))
+     {
+       g77_integer_type_node = long_integer_type_node;
+       g77_uinteger_type_node = long_unsigned_type_node;
+     }
+   else if (TYPE_PRECISION (float_type_node)
+ 	   == TYPE_PRECISION (integer_type_node))
+     {
+       g77_integer_type_node = integer_type_node;
+       g77_uinteger_type_node = unsigned_type_node;
+     }
+   else
+     g77_integer_type_node = g77_uinteger_type_node = NULL_TREE;
+ 
+   if (g77_integer_type_node != NULL_TREE)
+     {
+       (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
+ 						get_identifier ("__g77_integer"),
+ 						g77_integer_type_node));
+       (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
+ 						get_identifier ("__g77_uinteger"),
+ 						g77_uinteger_type_node));
+     }
+ 
+   if (TYPE_PRECISION (float_type_node) * 2
+       == TYPE_PRECISION (long_integer_type_node))
+     {
+       g77_longint_type_node = long_integer_type_node;
+       g77_ulongint_type_node = long_unsigned_type_node;
+     }
+   else if (TYPE_PRECISION (float_type_node) * 2
+ 	   == TYPE_PRECISION (long_long_integer_type_node))
+     {
+       g77_longint_type_node = long_long_integer_type_node;
+       g77_ulongint_type_node = long_long_unsigned_type_node;
+     }
+   else
+     g77_longint_type_node = g77_ulongint_type_node = NULL_TREE;
+ 
+   if (g77_longint_type_node != NULL_TREE)
+     {
+       (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
+ 						get_identifier ("__g77_longint"),
+ 						g77_longint_type_node));
+       (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
+ 						get_identifier ("__g77_ulongint"),
+ 						g77_ulongint_type_node));
+     }
+ 
    record_builtin_type (RID_VOID, NULL, void_type_node);
  
--- End Message ---

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