From: Monty Taylor Date: March 22 2007 8:40am Subject: Re: SWIG_exception vs. SWIG_exception_fail List-Archive: http://lists.mysql.com/ndb-connectors/16 Message-Id: <460240FA.6040006@mysql.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020602050305090702010102" --------------020602050305090702010102 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit As far as I can tell, this is a bug in SWIG. SWIG_exception_fail does not, in fact, exist in Java. But it seems that the real problem is that the goto fail; was removed from the Perl SWIG_exception. I made a patch to make SWIG_exception work like we want it to for perl... but then I got to thinking. Maybe this is correct _for_perl_. The goal isn't specifically just to throw and catch exceptions. The original C++ doesn't use exceptions. I think in Python and Java there should be exceptions because that is the normal way you do things there. But in Perl, that would involve wrapping the block in an exec{}; right? And I think most people won't want to do that. So maybe we shouldn't throw exceptions in perl... what do you think? Anyway - I'm attaching the revision bundle if we do decide this is what we want to do. Oh, I also just made a fix to the Makefile.am and Makefile.PL to pass along LDFLAGS - I'll push that in just a sec. Monty Monty Taylor wrote: > Bother. I think there might be some inconsistency within SWIG. I believe > we started off using SWIG_exception_fail and that it didn't work right > under Java or something. I'll look deeper and see if I can remember what > the issue was. > > Monty > > Mika Raento wrote: >> Hello >> >> I think we need to use SWIG_exception_fail instead of SWIG_exception. >> >> In python they are actually defined as the same thing, but in perl >> SWIG_exception_fail does a 'goto fail;' and the croak() is done under >> fail. A plain SWIG_exception continues in the success path and doesn't >> throw an exception (it just creates the exception information but >> doesn't throw it). >> >> With SWIG_exception, >> $connection = new ndb::Ndb_cluster_connection(); >> if ($connection->connect(5,3,1)) { >> >> print "Connect to cluster management server failed.\n"; >> exit -1; >> } >> >> actually prints >> Connect to cluster management server failed. >> >> Whereas with SWIG_exception_fail, the script dies with >> RuntimeError Connect to management server failed >> >> Which is the behaviour I assume we are looking for. >> >> I'll provide a patch in a bit. >> >> Mika >> > > -- Monty Taylor Senior Consultant MySQL Inc., www.mysql.com Get More with MySQL! www.mysql.com/consulting --------------020602050305090702010102 Content-Type: text/plain; name="macro_redef.bundle" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="macro_redef.bundle" # Bazaar revision bundle v0.9 # # message: # Didn't really need reference to perl5/exception.i # # committer: Monty Taylor # date: Thu 2007-03-22 01:38:04.503999949 -0700 === modified file configure.in // last-changed:monty@stripped ... 1-7g179xnd34et1727 --- configure.in +++ configure.in @@ -21,6 +21,8 @@ JNI_INCLUDES="$JNI_INCLUDES -I$JNI_INCLUDE_DIR" done +# TODO: check for Python.h +# Check for setuptools AM_PATH_PYTHON() WITH_PERL() === modified file perl/ndb.i --- perl/ndb.i +++ perl/ndb.i @@ -1,6 +1,9 @@ %module ndb %include "globals.i" +%{ +#define SWIG_exception(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) +%} %include "Ndb_cluster_connection.i" %include "../swig/Ndb.i" %include "NdbTransaction.i" === modified directory // last-changed:monty@stripped ... gq42tl9k71y # revision id: monty@stripped # sha1: 187a19bf275fcd0e7ceb0772efbac1171fc1c96e # inventory sha1: ad6dae29202c61b36928fc8ae7cde8ce01935c94 # parent ids: # monty@stripped # base id: monty@stripped # properties: # branch-nick: except # message: # Redefine SWIG_exception to be the same as SWIG_exception_fail # # committer: Monty Taylor # date: Thu 2007-03-22 01:37:01.661999941 -0700 === modified file configure.in // encoding:base64 LS0tIGNvbmZpZ3VyZS5pbgorKysgY29uZmlndXJlLmluCkBAIC0yMSw2ICsyMSw4IEBACiAgIEpO SV9JTkNMVURFUz0iJEpOSV9JTkNMVURFUyAtSSRKTklfSU5DTFVERV9ESVIiCiBkb25lCiAKKyMg VE9ETzogY2hlY2sgZm9yIFB5dGhvbi5oCisjIENoZWNrIGZvciBzZXR1cHRvb2xzCiBBTV9QQVRI X1BZVEhPTigpCiAKIFdJVEhfUEVSTCgpCgo= === modified file perl/ndb.i // encoding:base64 LS0tIHBlcmwvbmRiLmkKKysrIHBlcmwvbmRiLmkKQEAgLTEsNiArMSwxMCBAQAogJW1vZHVsZSBu ZGIKIAogJWluY2x1ZGUgImdsb2JhbHMuaSIKKyVpbmNsdWRlICJwZXJsNS9leGNlcHRpb24uaSIK KyV7CisjZGVmaW5lIFNXSUdfZXhjZXB0aW9uKGNvZGUsIG1zZykgZG8geyBTV0lHX0Vycm9yKGNv ZGUsIG1zZyk7IFNXSUdfZmFpbDsgfSB3aGlsZSgwKQorJX0KICVpbmNsdWRlICJOZGJfY2x1c3Rl cl9jb25uZWN0aW9uLmkiCiAlaW5jbHVkZSAiLi4vc3dpZy9OZGIuaSIKICVpbmNsdWRlICJOZGJU cmFuc2FjdGlvbi5pIgoK === modified directory // last-changed:monty@stripped ... xnd34et1727 # revision id: monty@stripped # sha1: d84b0a9a49f28b68455592ede25b09351dbe39fe # inventory sha1: 2cbc1dff85963636eb81f0fa0d29845b83a133f2 # parent ids: # monty@stripped # properties: # branch-nick: except --------------020602050305090702010102--