Re: [eigen] patch to throw std::bad_alloc |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] patch to throw std::bad_alloc
- From: "Benoit Jacob" <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 16 Dec 2008 17:00:42 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=SRYYPlwjDACke4xwbTaETUkmqOoRgE44CHHvx+WgjMc=; b=BgwECuXlGM2fgJDnxFPYHvrmAtc/wjoxEB4WafZHPlfIWnC6KHX9A+Fbk6H5q17aIu MvjWQPSOIARHn6iUTnM6cEBdHTb8aRymgruuPD9PInR7vbpc/vIKYVSWt4ZAPQdpz80w JGkL4MibUfkHLax16Sjb5zVrKUJ6zIcCuMDNw=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=dQJx0MIenNRtrXQQ4t6kbYpVs9+mn/Q2uUFOicLRb1hQnjBt3Qb6arurjbow/oAP/l jmj8VHPcbS9rHnzsbBSwqUpZ+Tc2ZaSsb7NgutL0u1oj6aWy5sLf9b2tM/+xS76LdZo8 TLDsz+QIRLW9K/Fzbi2L8cfp5ULkg3mO+l0TI=
Hi,
Thanks a lot for your patch. Having never worked with assertions I
actually didn't know how this should be done.
I committed your patch with some modifications, so if you svn up you
could try it and see if you like it.
Notice that on the linux platform, Eigen will also try to use dynamic
stack allocation in ei_stack_alloc() in Memory.h, which has undefined
behavior in case of stack overflow. Which I guess you would frown upon
;) so if you want to disable that, just define
EIGEN_STACK_ALLOCATION_LIMIT to 0.
If you define EIGEN_STACK_ALLOCATION_LIMIT to 0 and have exceptions
enabled it's guaranteed that any kind of bad allocation will throw a
bad_alloc.
Now the comments...
>+#include <new>
I moved that to the Eigen/Core header. The place were you put it is
actually included inside namespace Eigen!
Also we only include that if exceptions are enabled. I introduced
EIGEN_EXCEPTIONS.
> inline T* ei_aligned_malloc(size_t size)
> {
Here I made some modifications: fix the warning "unused variable
failed" when exceptions are disabled, avoid an if(), etc.
>+ throw std::bad_alloc;
This failed to compile, I had to add parentheses. OK? (i don't have
any experience)
Thanks again,
Benoit
2008/12/16 Kenneth Riddile <kfriddile@xxxxxxxxx>:
> After discussion in IRC, I have written and attached a patch to Memory.h to
> throw std::bad_alloc when ei_aligned_malloc() fails to allocate memory. If
> exceptions are disabled, ei_aligned_malloc() should behave exactly as it did
> before. I haven't actually been able to compile this code due to problems
> with my machine here at work, so I would appreciate someone testing it for
> me. Also, if there are any unit tests that test the behavior of
> ei_aligned_malloc(), they may need to be altered since its behavior is now
> different if compiled with exceptions on. I don't know how Eigen structures
> its unit tests, but I know most test suites I've used have some way to
> verify that a particular exception was or was not thrown.
>
> -Kenny Riddile
---