[GiNaC-devel] remove_dirac_ONE() and documentation patches
Alexey Sheplyakov
asheplyakov at yandex.ru
Sun May 19 17:31:06 CEST 2019
Hi,
> Thus I re-write remove_dirac_ONE() without exceptions. The signature
> of the method has to change, but a user may not notice this in the
> first approximation.
There a few fatal differences (which are indeed not so easy to spot):
- A user code might be relying on remove_dirac_ONE() to throw an exception when something goes wrong.
The patch breaks such a code without a slightest warning from the compiler.
- Before the patch this:
remove_dirac_ONE(e, 0, 0);
used to compile and work just fine. With the patch it also compiles (without a slightest warning),
and segfaults at the run time (for the last 0 is `bool *success` now).0
> * @param e Expression to be processed
> - * @param rl Value of representation label
> - * @param options Defines some internal use */
> -ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, unsigned options = 0);
> + * @param rl Value of representation label, all dirac_ONE with this or greater value will be processed
> + * @param success It is changed to false if there is at least one clifford_unit() in the expression
> + * @param options Defines some internal value for recursive calls, shall be ommited in user code */
> +ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, bool *success = new bool, unsigned options = 0);
Also there's a memory leak (since nobody is going to release that `new bool`).
Therefore I think the patch is wrong and should not be applied.
Possible solutions:
1)
a) Make a new (overload of) remove_dirac_ONE function:
ex remove_dirac_ONE(const ex& e, bool& success, unsigned char rl = 0, unsigned options = 0);
which reports errors without exceptions
b) Don't change the behavior of the existing `ex remove_dirac_ONE(const ex& e, unsigned char rl =0, unsigned options = 0);
2) Leave current `remove_dirac_ONE` as is. It's not broken, there's nothing to fix.
> The exceptions in remove_dirac_ONE() terminated a Qt Windows application
And fix that application instead (perhaps I could help if the sources and instructions how to reproduce the problem are available)
Best regards,
Alexey
More information about the GiNaC-devel
mailing list