MySQL Lists are EOL. Please join:

List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:March 22 2007 8:40am
Subject:Re: SWIG_exception vs. SWIG_exception_fail
View as plain text  
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 and Makefile.PL to pass
along LDFLAGS - I'll push that in just a sec.


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.,
Get More with MySQL!

# Bazaar revision bundle v0.9
# message:
#   Didn't really need reference to perl5/exception.i
# committer: Monty Taylor <monty@stripped>
# date: Thu 2007-03-22 01:38:04.503999949 -0700

=== modified file // last-changed:monty@stripped
... 1-7g179xnd34et1727
@@ -21,6 +21,8 @@
+# TODO: check for Python.h
+# Check for setuptools

=== 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 <monty@stripped>
# date: Thu 2007-03-22 01:37:01.661999941 -0700

=== modified file // encoding:base64

=== modified file perl/ndb.i // encoding:base64

=== modified directory  // last-changed:monty@stripped
... xnd34et1727
# revision id: monty@stripped
# sha1: d84b0a9a49f28b68455592ede25b09351dbe39fe
# inventory sha1: 2cbc1dff85963636eb81f0fa0d29845b83a133f2
# parent ids:
#   monty@stripped
# properties:
#   branch-nick: except

SWIG_exception vs. SWIG_exception_failMika Raento21 Mar
  • Re: SWIG_exception vs. SWIG_exception_failMonty Taylor21 Mar
    • Re: SWIG_exception vs. SWIG_exception_failMonty Taylor22 Mar
      • exceptions and perlMika Raento22 Mar
        • Re: exceptions and perlMonty Taylor22 Mar