[GiNaC-devel] [SCM] GiNaC -- a C++ library for symbolic computations branch, ginac_1-5, updated. release_1-4-0-198-g8bf0597

Alexei Sheplyakov varg at metalica.kh.ua
Fri Jul 31 13:57:13 CEST 2009


Dear Jens,

On Fri, Jul 31, 2009 at 12:50:26PM +0200, Jens Vollinga wrote:

> commit eaf81b3115697a8e883848ace0ceb919cf443b2c
> Author: Jens Vollinga <jensv at balin.nikhef.nl>
> Date:   Fri Jul 31 11:14:01 2009 +0200
> 
>     Fixed cast that caused compile error on 64bit machines.

diff --git a/ginac/parser/parser.cpp b/ginac/parser/parser.cpp
index a46017d..d91b7e8 100644
--- a/ginac/parser/parser.cpp
+++ b/ginac/parser/parser.cpp
@@ -66,8 +66,16 @@ ex parser::parse_identifier_expr()
                Parse_error_("no function \"" << name << "\" with " <<
                             args.size() << " arguments");
        }
-       ex ret = GiNaC::function(reinterpret_cast<unsigned>(reader->second), args);
-       return ret;
+       // dirty hack to distinguish between serial numbers of functions and real
+       // pointers.
+       ex ret;
+       try {
+               ret = GiNaC::function(reinterpret_cast<unsigned>(reader->second), args);
+       }
+       catch ( std::runtime_error ) {
+               ret = reader->second(args);
+       }
+    return ret;
 }

I'm afraid this code is a bit dangerous.

Suppose reader->second corresponds to the serial of some (GiNaC::)function
(and not a pointer to a C++ function). ret = GiNaC::function(...) calls
eval(), and it might throw an exception. We catch the exception and
dereference ->second => oops...

Best regards,
	Alexei



More information about the GiNaC-devel mailing list