From a93cc4dc166bfad1b6f46d2375910513b96d3bb8 Mon Sep 17 00:00:00 2001 From: Stefan Roiser <Stefan.Roiser@cern.ch> Date: Fri, 20 Jan 2006 17:21:18 +0000 Subject: [PATCH] From Pere: - Fixing a bug from the CINTEnumBuilder patch - functions returning objects 'by value' and throwing exceptions at the same time. The CINT structure was not properly cleaned and CINT was freeing objects that did not exist git-svn-id: http://root.cern.ch/svn/root/trunk@13877 27541ba8-7e3a-0410-8455-c3a389f83636 --- cintex/src/CINTEnumBuilder.cxx | 6 +++--- cintex/src/CINTFunctional.cxx | 21 ++++++++++++++------- cintex/test/dict/CintexTest.h | 9 +++++---- cintex/test/dict/selection.xml | 3 ++- cintex/test/test_PyCintex_basics.py | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/cintex/src/CINTEnumBuilder.cxx b/cintex/src/CINTEnumBuilder.cxx index be06f4dedb5..db773a19d95 100644 --- a/cintex/src/CINTEnumBuilder.cxx +++ b/cintex/src/CINTEnumBuilder.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTEnumBuilder.cxx,v 1.5 2005/12/12 09:12:27 roiser Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTEnumBuilder.cxx,v 1.6 2006/01/18 08:00:26 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -65,8 +65,8 @@ namespace ROOT { namespace Cintex { } for ( size_t i = 0; i < e.DataMemberSize(); i++ ) { stringstream s; - s << e.DataMemberAt(i).Name(); - if ( isCPPMacroEnum ) s << "=" << (const char*)e.DataMemberAt(i).Offset(); + s << e.DataMemberAt(i).Name() << "="; + if ( isCPPMacroEnum ) s << (const char*)e.DataMemberAt(i).Offset(); else s << (int)e.DataMemberAt(i).Offset(); string item = s.str(); diff --git a/cintex/src/CINTFunctional.cxx b/cintex/src/CINTFunctional.cxx index 9ec62262a5d..a0f699ebfea 100644 --- a/cintex/src/CINTFunctional.cxx +++ b/cintex/src/CINTFunctional.cxx @@ -1,4 +1,4 @@ -// @(#)root/cintex:$Name: $:$Id: CINTFunctional.cxx,v 1.9 2005/12/15 10:13:18 brun Exp $ +// @(#)root/cintex:$Name: $:$Id: CINTFunctional.cxx,v 1.10 2006/01/16 17:13:06 roiser Exp $ // Author: Pere Mato 2005 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved. @@ -189,9 +189,11 @@ int Method_stub_with_context(StubContext* context, string errtxt(e.what()); errtxt += " (C++ exception)"; G__genericerror(errtxt.c_str()); + context->ProcessResult(result, 0); } catch (...) { G__genericerror("Unknown C++ exception"); + context->ProcessResult(result, 0); } return(1); } @@ -206,12 +208,13 @@ int Constructor_stub_with_context(StubContext* context, if ( !context->fInitialized ) context->Initialize(); context->ProcessParam(libp); + void* obj; + // Catch here everything since going through the adaptor in the data section // does not transmit the exception try { long nary = G__getaryconstruct(); size_t size = context->fClass.SizeOf(); - void* obj; if ( nary ) { if( context->fNewdelfuncs ) { obj = context->fNewdelfuncs->NewArray(nary); @@ -227,20 +230,24 @@ int Constructor_stub_with_context(StubContext* context, obj = ::operator new( size ); (*context->fStub)(obj, context->fParam, 0); } - - result->obj.i = (long)obj; - result->ref = (long)obj; - result->type = 'u'; - result->tagnum = context->fClass_tag; } catch ( std::exception& e ) { string errtxt(e.what()); errtxt += " (C++ exception)"; G__genericerror(errtxt.c_str()); + ::operator delete (obj); + obj = 0; } catch (...) { G__genericerror("Unknown C++ exception"); + ::operator delete (obj); + obj = 0; } + + result->obj.i = (long)obj; + result->ref = (long)obj; + result->type = 'u'; + result->tagnum = context->fClass_tag; return(1); } diff --git a/cintex/test/dict/CintexTest.h b/cintex/test/dict/CintexTest.h index c5927ffd3fb..832a8e06a1f 100644 --- a/cintex/test/dict/CintexTest.h +++ b/cintex/test/dict/CintexTest.h @@ -583,10 +583,10 @@ public: virtual int get() { return 0; } }; -class PP : public Pbase { +class PPbase : public Pbase { public: - PP(int i) : m_i(i) {} - virtual ~PP() {} + PPbase(int i) : m_i(i) {} + virtual ~PPbase() {} virtual int get() { return m_i; } private: int m_i; @@ -646,7 +646,8 @@ class ExceptionGenerator { public: ExceptionGenerator( bool b ) { if (b) throw std::logic_error("My Exception in constructor"); } ~ExceptionGenerator() {} - void doThrow( bool b ) {if (b) throw std::logic_error("My Exception in method"); } + A::B::C::MyClass doThrow( bool b ) {if (b) throw std::logic_error("My Exception in method"); return A::B::C::MyClass(); } + A::B::C::MyClass doThrowUnknown( bool b ) {if (b) throw std::string("hello"); return A::B::C::MyClass();} }; #include <list> diff --git a/cintex/test/dict/selection.xml b/cintex/test/dict/selection.xml index 93057a47fe9..4d6e2d1616a 100644 --- a/cintex/test/dict/selection.xml +++ b/cintex/test/dict/selection.xml @@ -28,8 +28,9 @@ <class name="SimpleProperty<std::string,Verifier<std::string> >"/> <class name="Pbase"/> - <class name="PP"/> + <class name="PPbase"/> <class name="std::vector<const Pbase*>"/> + <class name="std::vector<int>"/> <class name="Obj"/> <class name="ExceptionGenerator"/> diff --git a/cintex/test/test_PyCintex_basics.py b/cintex/test/test_PyCintex_basics.py index d37101ca1d9..b7e22737257 100644 --- a/cintex/test/test_PyCintex_basics.py +++ b/cintex/test/test_PyCintex_basics.py @@ -366,7 +366,7 @@ class BasicsTestCase(unittest.TestCase): def test22VectorPointers(self) : v = self.gbl.std.vector('const Pbase*')() self.failUnless(v) - coll = [ self.gbl.P(i) for i in range(10) ] + coll = [ self.gbl.PPbase(i) for i in range(10) ] for p in coll : v.push_back(p) self.failUnlessEqual(len(v),10) p = v.at(1) -- GitLab