c++ patch

Marc Glisse marc.glisse at normalesup.org
Thu May 11 17:26:23 CEST 2006


I attach a patch that I am using. It in particular helps me on solaris, 
where I use:

Some cxx tests (t-binary t-ops t-prec t-ternary t-unary) still fail to 
compile, but I believe it is because of bugs in the compiler (whereas what 
I patched looks like bugs in the code).

A bit more details:
there are a number of missing std:: for c++ use. Since gmp-impl.h is not 
installed, it can just use the easy "using namespace std;". For gmp.h, I 
did something cleaner (It is better for standard conformance, but I am not 
sure it may not hurt some broken c++ compiler).
The typedef in gmpxx.h is because a C linkage function and a C++ linkage 
function need not look the same I think.

I will check again after the next patch to sun's c++ compiler (the one 
released today was a disappointment).

Marc Glisse
-------------- next part --------------
--- gmp-4.2.1/gmpxx.h	2006-04-08 21:15:38.000000000 +0200
+++ gmp-4.2.1.new/gmpxx.h	2006-05-11 16:15:27.978711000 +0200
@@ -1379,13 +1379,14 @@
 /* this is much the same as gmp_allocated_string in gmp-impl.h
    since gmp-impl.h is not publicly available, I redefine it here
    I use a different name to avoid possible clashes */
+extern "C" typedef void (*_gmp_freefunc_type) (void *, size_t);
 struct __gmp_alloc_cstring
   char *str;
   __gmp_alloc_cstring(char *s) { str = s; }
-    void (*freefunc) (void *, size_t);
+    _gmp_freefunc_type freefunc;
     mp_get_memory_functions (NULL, NULL, &freefunc);
     (*freefunc) (str, std::strlen(str)+1);
--- gmp-4.2.1/gmp-h.in	2006-04-11 20:10:15.000000000 +0200
+++ gmp-4.2.1.new/gmp-h.in	2006-05-11 15:57:12.128198000 +0200
@@ -49,8 +49,10 @@
 #define __need_size_t  /* tell gcc stddef.h we only want size_t */
 #if defined (__cplusplus)
+#define GMP_CSTD std::
 #include <cstddef>     /* for size_t */
+#define GMP_CSTD
 #include <stddef.h>    /* for size_t */
 #undef __need_size_t
@@ -512,18 +514,17 @@
 #if defined (__cplusplus)
 extern "C" {
-using std::FILE;
 #define mp_set_memory_functions __gmp_set_memory_functions
-__GMP_DECLSPEC void mp_set_memory_functions __GMP_PROTO ((void *(*) (size_t),
-				      void *(*) (void *, size_t, size_t),
-				      void (*) (void *, size_t))) __GMP_NOTHROW;
+__GMP_DECLSPEC void mp_set_memory_functions __GMP_PROTO ((void *(*) (GMP_CSTD size_t),
+				      void *(*) (void *, GMP_CSTD size_t, GMP_CSTD size_t),
+				      void (*) (void *, GMP_CSTD size_t))) __GMP_NOTHROW;
 #define mp_get_memory_functions __gmp_get_memory_functions
-__GMP_DECLSPEC void mp_get_memory_functions __GMP_PROTO ((void *(**) (size_t),
-                                      void *(**) (void *, size_t, size_t),
-                                      void (**) (void *, size_t))) __GMP_NOTHROW;
+__GMP_DECLSPEC void mp_get_memory_functions __GMP_PROTO ((void *(**) (GMP_CSTD size_t),
+                                      void *(**) (void *, GMP_CSTD size_t, GMP_CSTD size_t),
+                                      void (**) (void *, GMP_CSTD size_t))) __GMP_NOTHROW;
 #define mp_bits_per_limb __gmp_bits_per_limb
 __GMP_DECLSPEC extern __gmp_const int mp_bits_per_limb;
@@ -581,7 +582,7 @@
 #define gmp_fprintf __gmp_fprintf
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC int gmp_fprintf __GMP_PROTO ((FILE *, __gmp_const char *, ...));
+__GMP_DECLSPEC int gmp_fprintf __GMP_PROTO ((GMP_CSTD FILE *, __gmp_const char *, ...));
 #define gmp_obstack_printf __gmp_obstack_printf
@@ -591,41 +592,41 @@
 #define gmp_obstack_vprintf __gmp_obstack_vprintf
 #if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_obstack_vprintf __GMP_PROTO ((struct obstack *, __gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_obstack_vprintf __GMP_PROTO ((struct obstack *, __gmp_const char *, GMP_CSTD va_list));
 #define gmp_printf __gmp_printf
 __GMP_DECLSPEC int gmp_printf __GMP_PROTO ((__gmp_const char *, ...));
 #define gmp_snprintf __gmp_snprintf
-__GMP_DECLSPEC int gmp_snprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, ...));
+__GMP_DECLSPEC int gmp_snprintf __GMP_PROTO ((char *, GMP_CSTD size_t, __gmp_const char *, ...));
 #define gmp_sprintf __gmp_sprintf
 __GMP_DECLSPEC int gmp_sprintf __GMP_PROTO ((char *, __gmp_const char *, ...));
 #define gmp_vasprintf __gmp_vasprintf
 #if defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vasprintf __GMP_PROTO ((char **, __gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vasprintf __GMP_PROTO ((char **, __gmp_const char *, GMP_CSTD va_list));
 #define gmp_vfprintf __gmp_vfprintf
 #if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vfprintf __GMP_PROTO ((FILE *, __gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vfprintf __GMP_PROTO ((GMP_CSTD FILE *, __gmp_const char *, GMP_CSTD va_list));
 #define gmp_vprintf __gmp_vprintf
 #if defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vprintf __GMP_PROTO ((__gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vprintf __GMP_PROTO ((__gmp_const char *, GMP_CSTD va_list));
 #define gmp_vsnprintf __gmp_vsnprintf
 #if defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vsnprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vsnprintf __GMP_PROTO ((char *, GMP_CSTD size_t, __gmp_const char *, GMP_CSTD va_list));
 #define gmp_vsprintf __gmp_vsprintf
 #if defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vsprintf __GMP_PROTO ((char *, __gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vsprintf __GMP_PROTO ((char *, __gmp_const char *, GMP_CSTD va_list));
@@ -633,7 +634,7 @@
 #define gmp_fscanf __gmp_fscanf
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC int gmp_fscanf __GMP_PROTO ((FILE *, __gmp_const char *, ...));
+__GMP_DECLSPEC int gmp_fscanf __GMP_PROTO ((GMP_CSTD FILE *, __gmp_const char *, ...));
 #define gmp_scanf __gmp_scanf
@@ -644,17 +645,17 @@
 #define gmp_vfscanf __gmp_vfscanf
 #if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vfscanf __GMP_PROTO ((FILE *, __gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vfscanf __GMP_PROTO ((GMP_CSTD FILE *, __gmp_const char *, GMP_CSTD va_list));
 #define gmp_vscanf __gmp_vscanf
 #if defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vscanf __GMP_PROTO ((__gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vscanf __GMP_PROTO ((__gmp_const char *, GMP_CSTD va_list));
 #define gmp_vsscanf __gmp_vsscanf
 #if defined (_GMP_H_HAVE_VA_LIST)
-__GMP_DECLSPEC int gmp_vsscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, va_list));
+__GMP_DECLSPEC int gmp_vsscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, GMP_CSTD va_list));
@@ -781,7 +782,7 @@
 __GMP_DECLSPEC void mpz_dump __GMP_PROTO ((mpz_srcptr));
 #define mpz_export __gmpz_export
-__GMP_DECLSPEC void *mpz_export __GMP_PROTO ((void *, size_t *, int, size_t, int, size_t, mpz_srcptr));
+__GMP_DECLSPEC void *mpz_export __GMP_PROTO ((void *, GMP_CSTD size_t *, int, GMP_CSTD size_t, int, GMP_CSTD size_t, mpz_srcptr));
 #define mpz_fac_ui __gmpz_fac_ui
 __GMP_DECLSPEC void mpz_fac_ui __GMP_PROTO ((mpz_ptr, unsigned long int));
@@ -878,7 +879,7 @@
 __GMP_DECLSPEC unsigned long int mpz_hamdist __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
 #define mpz_import __gmpz_import
-__GMP_DECLSPEC void mpz_import __GMP_PROTO ((mpz_ptr, size_t, int, size_t, int, size_t, __gmp_const void *));
+__GMP_DECLSPEC void mpz_import __GMP_PROTO ((mpz_ptr, GMP_CSTD size_t, int, GMP_CSTD size_t, int, GMP_CSTD size_t, __gmp_const void *));
 #define mpz_init __gmpz_init
 __GMP_DECLSPEC void mpz_init __GMP_PROTO ((mpz_ptr));
@@ -903,12 +904,12 @@
 #define mpz_inp_raw __gmpz_inp_raw
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpz_inp_raw __GMP_PROTO ((mpz_ptr, FILE *));
+__GMP_DECLSPEC GMP_CSTD size_t mpz_inp_raw __GMP_PROTO ((mpz_ptr, GMP_CSTD FILE *));
 #define mpz_inp_str __gmpz_inp_str
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpz_inp_str __GMP_PROTO ((mpz_ptr, FILE *, int));
+__GMP_DECLSPEC GMP_CSTD size_t mpz_inp_str __GMP_PROTO ((mpz_ptr, GMP_CSTD FILE *, int));
 #define mpz_invert __gmpz_invert
@@ -978,12 +979,12 @@
 #define mpz_out_raw __gmpz_out_raw
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpz_out_raw __GMP_PROTO ((FILE *, mpz_srcptr));
+__GMP_DECLSPEC GMP_CSTD size_t mpz_out_raw __GMP_PROTO ((GMP_CSTD FILE *, mpz_srcptr));
 #define mpz_out_str __gmpz_out_str
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpz_out_str __GMP_PROTO ((FILE *, int, mpz_srcptr));
+__GMP_DECLSPEC GMP_CSTD size_t mpz_out_str __GMP_PROTO ((GMP_CSTD FILE *, int, mpz_srcptr));
 #define mpz_perfect_power_p __gmpz_perfect_power_p
@@ -1066,11 +1067,11 @@
 #define mpz_size __gmpz_size
 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size)
-__GMP_DECLSPEC size_t mpz_size __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
 #define mpz_sizeinbase __gmpz_sizeinbase
-__GMP_DECLSPEC size_t mpz_sizeinbase __GMP_PROTO ((mpz_srcptr, int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
+__GMP_DECLSPEC GMP_CSTD size_t mpz_sizeinbase __GMP_PROTO ((mpz_srcptr, int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
 #define mpz_sqrt __gmpz_sqrt
 __GMP_DECLSPEC void mpz_sqrt __GMP_PROTO ((mpz_ptr, mpz_srcptr));
@@ -1191,7 +1192,7 @@
 #define mpq_inp_str __gmpq_inp_str
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpq_inp_str __GMP_PROTO ((mpq_ptr, FILE *, int));
+__GMP_DECLSPEC GMP_CSTD size_t mpq_inp_str __GMP_PROTO ((mpq_ptr, GMP_CSTD FILE *, int));
 #define mpq_inv __gmpq_inv
@@ -1210,7 +1211,7 @@
 #define mpq_out_str __gmpq_out_str
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpq_out_str __GMP_PROTO ((FILE *, int, mpq_srcptr));
+__GMP_DECLSPEC GMP_CSTD size_t mpq_out_str __GMP_PROTO ((GMP_CSTD FILE *, int, mpq_srcptr));
 #define mpq_set __gmpq_set
@@ -1327,7 +1328,7 @@
 __GMP_DECLSPEC long mpf_get_si __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
 #define mpf_get_str __gmpf_get_str
-__GMP_DECLSPEC char *mpf_get_str __GMP_PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr));
+__GMP_DECLSPEC char *mpf_get_str __GMP_PROTO ((char *, mp_exp_t *, int, GMP_CSTD size_t, mpf_srcptr));
 #define mpf_get_ui __gmpf_get_ui
 __GMP_DECLSPEC unsigned long mpf_get_ui __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
@@ -1355,7 +1356,7 @@
 #define mpf_inp_str __gmpf_inp_str
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpf_inp_str __GMP_PROTO ((mpf_ptr, FILE *, int));
+__GMP_DECLSPEC GMP_CSTD size_t mpf_inp_str __GMP_PROTO ((mpf_ptr, GMP_CSTD FILE *, int));
 #define mpf_integer_p __gmpf_integer_p
@@ -1375,7 +1376,7 @@
 #define mpf_out_str __gmpf_out_str
 #ifdef _GMP_H_HAVE_FILE
-__GMP_DECLSPEC size_t mpf_out_str __GMP_PROTO ((FILE *, int, size_t, mpf_srcptr));
+__GMP_DECLSPEC GMP_CSTD size_t mpf_out_str __GMP_PROTO ((GMP_CSTD FILE *, int, GMP_CSTD size_t, mpf_srcptr));
 #define mpf_pow_ui __gmpf_pow_ui
@@ -1418,7 +1419,7 @@
 __GMP_DECLSPEC void mpf_set_z __GMP_PROTO ((mpf_ptr, mpz_srcptr));
 #define mpf_size __gmpf_size
-__GMP_DECLSPEC size_t mpf_size __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
 #define mpf_sqrt __gmpf_sqrt
 __GMP_DECLSPEC void mpf_sqrt __GMP_PROTO ((mpf_ptr, mpf_srcptr));
@@ -1553,7 +1554,7 @@
 __GMP_DECLSPEC unsigned long int mpn_scan1 __GMP_PROTO ((mp_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE;
 #define mpn_set_str __MPN(set_str)
-__GMP_DECLSPEC mp_size_t mpn_set_str __GMP_PROTO ((mp_ptr, __gmp_const unsigned char *, size_t, int));
+__GMP_DECLSPEC mp_size_t mpn_set_str __GMP_PROTO ((mp_ptr, __gmp_const unsigned char *, GMP_CSTD size_t, int));
 #define mpn_sqrtrem __MPN(sqrtrem)
 __GMP_DECLSPEC mp_size_t mpn_sqrtrem __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
@@ -1753,7 +1754,7 @@
 #if ! defined (__GMP_FORCE_mpz_size)
+GMP_CSTD size_t
 mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW
   return __GMP_ABS (__gmp_z->_mp_size);
--- gmp-4.2.1/gmp-impl.h	2006-04-08 21:32:18.000000000 +0200
+++ gmp-4.2.1.new/gmp-impl.h	2006-05-11 15:47:49.897143000 +0200
@@ -119,6 +119,7 @@
 #ifdef __cplusplus
 #include <cstring>  /* for strlen */
 #include <string>   /* for std::string */
+using namespace std;

More information about the gmp-bugs mailing list