diff --git a/CHANGES.current b/CHANGES.current index 824781e03ec..da84352fa36 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,26 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.3.0 (in progress) =========================== +2024-09-14: wsfulton + C++ reference errors when passing in a 'NULL' change of behaviour. + Most languages now use "NullReferenceError" in the error message + where they previously used "ValueError". Also exception changes: + + Guile: "swig-null-reference-error" instead of "swig-value-error" + MzScheme: "swig-null-reference-error" instead of "swig-value-error" + PHP: zend_ce_type_error instead of zend_ce_value_error + Python: Consistently raises TypeError instead of a mix of ValueError + and TypeError. + Ruby: Consistently raises NullReferenceError instead of a mix of + ArgumentError and NullReferenceErrorError. + + The consistent raising of a TypeError instead of ValueError for Python + ensures that incorrectly passing 'None' into a C++ reference argument + will correctly convert the error into a NotImplemented error for + the rich comparisons implementations per PEP 207. Fixes #2987 + + *** POTENTIAL INCOMPATIBILITY *** + 2024-09-12: olly Remove remains of %nestedworkaround and the nestedworkaround feature it uses, which were deprecated over 10 years ago in SWIG diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index b39b393557a..d40681587ff 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -456,16 +456,17 @@

26.9 Exception Handling

-      MAP(SWIG_MemoryError,     "swig-memory-error");
-      MAP(SWIG_IOError,         "swig-io-error");
-      MAP(SWIG_RuntimeError,    "swig-runtime-error");
-      MAP(SWIG_IndexError,      "swig-index-error");
-      MAP(SWIG_TypeError,       "swig-type-error");
-      MAP(SWIG_DivisionByZero,  "swig-division-by-zero");
-      MAP(SWIG_OverflowError,   "swig-overflow-error");
-      MAP(SWIG_SyntaxError,     "swig-syntax-error");
-      MAP(SWIG_ValueError,      "swig-value-error");
-      MAP(SWIG_SystemError,     "swig-system-error");
+      MAP(SWIG_MemoryError,	    "swig-memory-error");
+      MAP(SWIG_IOError,		    "swig-io-error");
+      MAP(SWIG_RuntimeError,	    "swig-runtime-error");
+      MAP(SWIG_IndexError,	    "swig-index-error");
+      MAP(SWIG_TypeError,	    "swig-type-error");
+      MAP(SWIG_DivisionByZero,	    "swig-division-by-zero");
+      MAP(SWIG_OverflowError,	    "swig-overflow-error");
+      MAP(SWIG_SyntaxError,	    "swig-syntax-error");
+      MAP(SWIG_ValueError,	    "swig-value-error");
+      MAP(SWIG_SystemError,	    "swig-system-error");
+      MAP(SWIG_NullReferenceError,  "swig-null-reference-error");
 
diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index a62d5b799b8..884eca84f5e 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -2399,6 +2399,7 @@

12.5.1 exception.i

SWIG_SyntaxError SWIG_ValueError SWIG_SystemError +SWIG_NullReferenceError diff --git a/Examples/test-suite/lua/li_constraints_runme.lua b/Examples/test-suite/lua/li_constraints_runme.lua index c7577c2acc4..51e5d6e7ed3 100644 --- a/Examples/test-suite/lua/li_constraints_runme.lua +++ b/Examples/test-suite/lua/li_constraints_runme.lua @@ -6,7 +6,7 @@ function check_func(except, f, val, name) actual, err = pcall(f, val); assert(actual == except, 'function perform exception wrongly'); if name == nil then - r = 'SWIG_ValueError:Received a NULL pointer.'; + r = 'SWIG_NullReferenceError:Received a NULL pointer.'; else r = 'SWIG_ValueError:Expected a ' .. name .. ' value.'; end diff --git a/Examples/test-suite/octave/li_constraints_runme.m b/Examples/test-suite/octave/li_constraints_runme.m index eaea571a06f..be1236cca55 100644 --- a/Examples/test-suite/octave/li_constraints_runme.m +++ b/Examples/test-suite/octave/li_constraints_runme.m @@ -52,7 +52,7 @@ function check_double(except, f, val, name) # Empty matrix translate to null pointer li_constraints.test_nonnull([]); catch - have_exception = strcmp("Received a NULL pointer. (SWIG_ValueError)", lasterr) == 1; + have_exception = strcmp("Received a NULL pointer. (SWIG_NullReferenceError)", lasterr) == 1; end if (!have_exception) error("test_nonnull should perform exception with 'null' value"); diff --git a/Examples/test-suite/perl5/cpp17_string_view_runme.pl b/Examples/test-suite/perl5/cpp17_string_view_runme.pl index bc91637c425..16d0de8a3a2 100644 --- a/Examples/test-suite/perl5/cpp17_string_view_runme.pl +++ b/Examples/test-suite/perl5/cpp17_string_view_runme.pl @@ -24,7 +24,7 @@ # Verify type-checking for %typemap(in) const std::string_view & {} eval { cpp17_string_view::test_const_reference(undef) }; -like($@, qr/\bValueError\b/, "Test 4"); +like($@, qr/\bNullReferenceError\b/, "Test 4"); # # Input and output typemaps for pointers and non-const references to diff --git a/Examples/test-suite/perl5/li_constraints_runme.pl b/Examples/test-suite/perl5/li_constraints_runme.pl index b1fd143e207..894d756126c 100644 --- a/Examples/test-suite/perl5/li_constraints_runme.pl +++ b/Examples/test-suite/perl5/li_constraints_runme.pl @@ -49,7 +49,7 @@ sub check_double { my $ret = eval { li_constraints::test_nonnull(undef); 1; }; my $err = $@; is($ret, undef, "li_constraints::test_nonnull throw exception with null"); -ok($err =~ "^ValueError Received a NULL pointer.", "li_constraints::test_nonnull throw proper exception"); +ok($err =~ "^NullReferenceError Received a NULL pointer.", "li_constraints::test_nonnull throw proper exception"); my $ptr = li_constraints::get_nonnull(); # There should be no exception, we can use Perl lambda function $ret = (sub { li_constraints::test_nonnull($ptr); 1; })->(); diff --git a/Examples/test-suite/perl5/li_std_string_runme.pl b/Examples/test-suite/perl5/li_std_string_runme.pl index 0eb0b1476f9..8260925b885 100644 --- a/Examples/test-suite/perl5/li_std_string_runme.pl +++ b/Examples/test-suite/perl5/li_std_string_runme.pl @@ -24,7 +24,7 @@ # Verify type-checking for %typemap(in) const std::string & {} eval { li_std_string::test_const_reference(undef) }; -like($@, qr/\bValueError\b/, "Test 4"); +like($@, qr/\bNullReferenceError\b/, "Test 4"); # # Input and output typemaps for pointers and non-const references to diff --git a/Examples/test-suite/php/li_constraints_runme.php b/Examples/test-suite/php/li_constraints_runme.php index 35d523b9f99..d991b8a4091 100644 --- a/Examples/test-suite/php/li_constraints_runme.php +++ b/Examples/test-suite/php/li_constraints_runme.php @@ -56,7 +56,7 @@ function check_double(bool $except, $fn, string $f, $val) { $have_exception = false; try { test_nonnull(null); -} catch(ValueError $e) { +} catch(TypeError $e) { $msg = $e->getMessage(); $have_exception = strcmp($msg, "Received a NULL pointer.") === 0; } diff --git a/Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py b/Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py index 43e586f9a36..9562aa00122 100644 --- a/Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py +++ b/Examples/test-suite/python/cpp11_rvalue_reference_move_runme.py @@ -43,7 +43,7 @@ exception_thrown = False try: MovableCopyable.movein(None) -except ValueError as e: +except TypeError as e: if "invalid null reference" not in str(e): raise RuntimeError("incorrect exception message:" + str(e)) exception_thrown = True diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index bde79fd61e6..44d3b65a2af 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -156,7 +156,7 @@ def runtest(self): try: li_boost_shared_ptr.valuetest(k) raise RuntimeError("Failed to catch null pointer") - except ValueError: + except TypeError: pass if (li_boost_shared_ptr.pointertest(k) != None): @@ -165,7 +165,7 @@ def runtest(self): try: li_boost_shared_ptr.reftest(k) raise RuntimeError("Failed to catch null pointer") - except ValueError: + except TypeError: pass # test null pointers emitted from C++ @@ -476,7 +476,7 @@ def runtest(self): try: m.MemberValue = None raise RuntimeError("Failed to catch null pointer") - except ValueError: + except TypeError: pass # ////////////////////////////////// Global variables ///////////////// @@ -514,7 +514,7 @@ def runtest(self): try: li_boost_shared_ptr.cvar.GlobalValue = None raise RuntimeError("Failed to catch null pointer") - except ValueError: + except TypeError: pass # plain pointer @@ -548,7 +548,7 @@ def runtest(self): try: li_boost_shared_ptr.cvar.GlobalReference = None raise RuntimeError("Failed to catch null pointer") - except ValueError: + except TypeError: pass # ////////////////////////////////// Templates //////////////////////// diff --git a/Examples/test-suite/python/li_constraints_runme.py b/Examples/test-suite/python/li_constraints_runme.py index 72ba22d9a6a..2b04512b922 100644 --- a/Examples/test-suite/python/li_constraints_runme.py +++ b/Examples/test-suite/python/li_constraints_runme.py @@ -46,7 +46,7 @@ def check_double(et, fn, f, val): have_exception = False try: li_constraints.test_nonnull(None) -except ValueError as e: +except TypeError as e: have_exception = "Received a NULL pointer." == "%s"%(e) if not have_exception: raise Exception("test_nonnull should perform exception with 'null' value") diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py index ca8dc31848a..0c8eed7cb0d 100644 --- a/Examples/test-suite/python/li_std_wstring_runme.py +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -27,13 +27,13 @@ def check_equal(a, b): try: li_std_wstring.test_reference(None) raise RuntimeError("NULL check failed") -except ValueError as e: +except TypeError as e: if "invalid null reference" not in str(e): raise RuntimeError("Missing text {}".format(e)) try: li_std_wstring.test_const_reference(None) raise RuntimeError("NULL check failed") -except ValueError as e: +except TypeError as e: if "invalid null reference" not in str(e): raise RuntimeError("Missing text {}".format(e)) diff --git a/Examples/test-suite/ruby/cpp11_rvalue_reference_move_runme.rb b/Examples/test-suite/ruby/cpp11_rvalue_reference_move_runme.rb index 0a423d6c463..8407ec2e779 100644 --- a/Examples/test-suite/ruby/cpp11_rvalue_reference_move_runme.rb +++ b/Examples/test-suite/ruby/cpp11_rvalue_reference_move_runme.rb @@ -74,7 +74,7 @@ exception_thrown = false begin Cpp11_rvalue_reference_move::MovableCopyable.movein(nil) -rescue ArgumentError => e +rescue NullReferenceError => e if (!e.to_s.include? "invalid null reference") raise RuntimeError, "incorrect exception message: #{e.to_s}" end diff --git a/Examples/test-suite/ruby/li_boost_shared_ptr_runme.rb b/Examples/test-suite/ruby/li_boost_shared_ptr_runme.rb index cc5c0cab062..86793972a08 100644 --- a/Examples/test-suite/ruby/li_boost_shared_ptr_runme.rb +++ b/Examples/test-suite/ruby/li_boost_shared_ptr_runme.rb @@ -184,7 +184,7 @@ def runtest begin Li_boost_shared_ptr::valuetest(k) raise RuntimeError, "Failed to catch null pointer" - rescue ArgumentError + rescue NullReferenceError end if (Li_boost_shared_ptr::pointertest(k) != nil) @@ -194,7 +194,7 @@ def runtest begin Li_boost_shared_ptr::reftest(k) raise RuntimeError, "Failed to catch null pointer" - rescue ArgumentError + rescue NullReferenceError end # $owner @@ -508,7 +508,7 @@ def runtest begin m.MemberValue = nil raise RuntimeError, "Failed to catch null pointer" - rescue ArgumentError + rescue NullReferenceError end # ////////////////////////////////// Global variables ///////////////// @@ -547,7 +547,7 @@ def runtest begin Li_boost_shared_ptr.GlobalValue = nil raise RuntimeError, "Failed to catch null pointer" - rescue ArgumentError + rescue NullReferenceError end # plain pointer @@ -582,7 +582,7 @@ def runtest begin Li_boost_shared_ptr.GlobalReference = nil raise RuntimeError, "Failed to catch null pointer" - rescue ArgumentError + rescue NullReferenceError end # ////////////////////////////////// Templates //////////////////////// diff --git a/Examples/test-suite/ruby/li_constraints_runme.rb b/Examples/test-suite/ruby/li_constraints_runme.rb index a4dcd685ac7..bd5bb91009c 100644 --- a/Examples/test-suite/ruby/li_constraints_runme.rb +++ b/Examples/test-suite/ruby/li_constraints_runme.rb @@ -54,7 +54,7 @@ def check_double(except, fn, f, val) begin test_nonnull(nil) rescue => e - have_exception = e.class == ArgumentError && e.message == "Received a NULL pointer." + have_exception = e.class == NullReferenceError && e.message == "Received a NULL pointer." end if not have_exception raise RuntimeError, "test_nonnull should perform exception with 'null' value" diff --git a/Examples/test-suite/ruby/li_std_wstring_runme.rb b/Examples/test-suite/ruby/li_std_wstring_runme.rb index 170f80ebfaf..bb8474b808b 100644 --- a/Examples/test-suite/ruby/li_std_wstring_runme.rb +++ b/Examples/test-suite/ruby/li_std_wstring_runme.rb @@ -24,13 +24,13 @@ begin Li_std_wstring.test_reference(nil) raise RuntimeError, "NULL check failed" -rescue ArgumentError => e +rescue NullReferenceError => e swig_assert_simple(e.message.include? "invalid null reference") end begin Li_std_wstring.test_const_reference(nil) raise RuntimeError, "NULL check failed" -rescue ArgumentError => e +rescue NullReferenceError => e swig_assert_simple(e.message.include? "invalid null reference") end diff --git a/Examples/test-suite/tcl/li_constraints_runme.tcl b/Examples/test-suite/tcl/li_constraints_runme.tcl index ca7a182e39a..4ba98613aca 100644 --- a/Examples/test-suite/tcl/li_constraints_runme.tcl +++ b/Examples/test-suite/tcl/li_constraints_runme.tcl @@ -44,7 +44,7 @@ check_double 0 nonzero "nonzero" -10 set actual [ catch { test_nonnull NULL } err_msg ] if { ($actual != 1) || - ([ string equal $err_msg "ValueError Received a NULL pointer." ] != 1) } { + ([ string equal $err_msg "NullReferenceError Received a NULL pointer." ] != 1) } { error "Test 'test_nonnull' with null value fail" } set nonnull [ get_nonnull ] diff --git a/Lib/constraints.i b/Lib/constraints.i index 77e9778d126..20c4c15ce8b 100644 --- a/Lib/constraints.i +++ b/Lib/constraints.i @@ -175,7 +175,7 @@ Pointer NONNULL { if (!$1) { - SWIG_exception(SWIG_ValueError,"Received a NULL pointer."); + SWIG_exception(SWIG_NullReferenceError,"Received a NULL pointer."); } } diff --git a/Lib/d/boost_shared_ptr.i b/Lib/d/boost_shared_ptr.i index 6d85c5aef74..34c950ec68c 100644 --- a/Lib/d/boost_shared_ptr.i +++ b/Lib/d/boost_shared_ptr.i @@ -18,7 +18,7 @@ %typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{ argp = ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0; if (!argp) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "Attempt to dereference null $1_type"); return $null; } $1 = *argp; %} @@ -30,7 +30,7 @@ %typemap(directorout) CONST TYPE %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "Attempt to dereference null $1_type"); return $null; } SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input; @@ -56,7 +56,7 @@ %typemap(in, canthrow=1) CONST TYPE & %{ $1 = ($1_ltype)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0); if (!$1) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type reference is null"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "$1_type reference is null"); return $null; } %} %typemap(out, fragment="SWIG_null_deleter") CONST TYPE & diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg index 40393c9887f..20b9fe5d35d 100644 --- a/Lib/d/dhead.swg +++ b/Lib/d/dhead.swg @@ -24,7 +24,8 @@ typedef enum { SWIG_DIllegalArgumentException, SWIG_DIllegalElementException, SWIG_DIOException, - SWIG_DNoSuchElementException + SWIG_DNoSuchElementException, + SWIG_DNullReferenceException } SWIG_DExceptionCodes; typedef void (* SWIG_DExceptionCallback_t)(const char *); @@ -39,7 +40,8 @@ static SWIG_DException_t SWIG_d_exceptions[] = { { SWIG_DIllegalArgumentException, NULL }, { SWIG_DIllegalElementException, NULL }, { SWIG_DIOException, NULL }, - { SWIG_DNoSuchElementException, NULL } + { SWIG_DNoSuchElementException, NULL }, + { SWIG_DNullReferenceException, NULL } }; static void SWIGUNUSED SWIG_DSetPendingException(SWIG_DExceptionCodes code, const char *msg) { @@ -58,12 +60,14 @@ SWIGEXPORT void SWIGRegisterExceptionCallbacks_$module( SWIG_DExceptionCallback_t illegalArgumentCallback, SWIG_DExceptionCallback_t illegalElementCallback, SWIG_DExceptionCallback_t ioCallback, - SWIG_DExceptionCallback_t noSuchElementCallback) { + SWIG_DExceptionCallback_t noSuchElementCallback, + SWIG_DExceptionCallback_t nullReferenceCallback) { SWIG_d_exceptions[SWIG_DException].callback = exceptionCallback; SWIG_d_exceptions[SWIG_DIllegalArgumentException].callback = illegalArgumentCallback; SWIG_d_exceptions[SWIG_DIllegalElementException].callback = illegalElementCallback; SWIG_d_exceptions[SWIG_DIOException].callback = ioCallback; SWIG_d_exceptions[SWIG_DNoSuchElementException].callback = noSuchElementCallback; + SWIG_d_exceptions[SWIG_DNullReferenceException].callback = nullReferenceCallback; } %} @@ -80,6 +84,7 @@ private class SwigExceptionHelper { &setException, &setException, &setException, + &setException, &setException ); } diff --git a/Lib/d/dswigtype.swg b/Lib/d/dswigtype.swg index 4aad8833451..67f02f4e70a 100644 --- a/Lib/d/dswigtype.swg +++ b/Lib/d/dswigtype.swg @@ -45,7 +45,7 @@ %typemap(in, canthrow=1) SWIGTYPE ($&1_type argp) %{ argp = ($&1_ltype)$input; if (!argp) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "Attempt to dereference null $1_type"); return $null; } $1 = *argp; %} @@ -65,7 +65,7 @@ "$input = (void *)new $1_ltype(SWIG_STD_MOVE($1));" %typemap(directorout) SWIGTYPE %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "Unexpected null return for type $1_type"); return $null; } $result = *($&1_ltype)$input; %} @@ -122,7 +122,7 @@ %typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input; if (!$1) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "$1_type is null"); return $null; } %} %typemap(out) SWIGTYPE & "$result = (void *)$1;" @@ -131,7 +131,7 @@ "$input = ($1_ltype) &$1;" %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE & %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "Unexpected null return for type $1_type"); return $null; } $result = ($1_ltype)$input; %} @@ -159,7 +159,7 @@ %typemap(in, canthrow=1, fragment="") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input; if (!$1) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "$1_type is null"); return $null; } rvrdeleter.reset($1); %} @@ -169,7 +169,7 @@ "$input = ($1_ltype) &$1;" %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE && %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "Unexpected null return for type $1_type"); return $null; } $result = ($1_ltype)$input; %} diff --git a/Lib/d/std_string.i b/Lib/d/std_string.i index fbee0578c7a..629f77c5c92 100644 --- a/Lib/d/std_string.i +++ b/Lib/d/std_string.i @@ -27,13 +27,13 @@ class string; %typemap(in, canthrow=1) string, const string & %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "null string"); return $null; } $1.assign($input); %} %typemap(in, canthrow=1) const string & %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "null string"); return $null; } $*1_ltype $1_str($input); @@ -52,14 +52,14 @@ class string; %typemap(directorout, canthrow=1) string %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "null string"); return $null; } $result.assign($input); %} %typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string & %{ if (!$input) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "null string"); return $null; } /* possible thread/reentrant code problem */ diff --git a/Lib/d/swigmove.i b/Lib/d/swigmove.i index e2eb834064a..2bb890179da 100644 --- a/Lib/d/swigmove.i +++ b/Lib/d/swigmove.i @@ -8,7 +8,7 @@ %typemap(in, canthrow=1) SWIGTYPE MOVE ($&1_type argp) %{ argp = ($&1_ltype)$input; if (!argp) { - SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type"); + SWIG_DSetPendingException(SWIG_DNullReferenceException, "Attempt to dereference null $1_type"); return $null; } SwigValueWrapper< $1_ltype >::reset($1, argp); %} diff --git a/Lib/d/wrapperloader.swg b/Lib/d/wrapperloader.swg index f0f1d1b4696..d12e5cb87fa 100644 --- a/Lib/d/wrapperloader.swg +++ b/Lib/d/wrapperloader.swg @@ -292,7 +292,8 @@ extern(C) void function( SwigExceptionCallback illegalArgumentCallback, SwigExceptionCallback illegalElementCallback, SwigExceptionCallback ioCallback, - SwigExceptionCallback noSuchElementCallback) swigRegisterExceptionCallbacks$module; + SwigExceptionCallback noSuchElementCallback, + SwigExceptionCallback nullReferenceCallback) swigRegisterExceptionCallbacks$module; extern(C) void function(SwigStringCallback callback) swigRegisterStringCallback$module; %} diff --git a/Lib/exception.i b/Lib/exception.i index 1c00fb3a1c0..c3629bbfaba 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -20,6 +20,7 @@ code == SWIG_DivisionByZero ? zend_ce_division_by_zero_error : \ code == SWIG_SyntaxError ? zend_ce_parse_error : \ code == SWIG_OverflowError ? zend_ce_arithmetic_error : \ + code == SWIG_NullReferenceError ? zend_ce_type_error : \ NULL, msg, code); SWIG_fail; } while (0) %} #endif @@ -36,16 +37,17 @@ ERROR(scmerr); \ break switch (code) { - MAP(SWIG_MemoryError, "swig-memory-error"); - MAP(SWIG_IOError, "swig-io-error"); - MAP(SWIG_RuntimeError, "swig-runtime-error"); - MAP(SWIG_IndexError, "swig-index-error"); - MAP(SWIG_TypeError, "swig-type-error"); - MAP(SWIG_DivisionByZero, "swig-division-by-zero"); - MAP(SWIG_OverflowError, "swig-overflow-error"); - MAP(SWIG_SyntaxError, "swig-syntax-error"); - MAP(SWIG_ValueError, "swig-value-error"); - MAP(SWIG_SystemError, "swig-system-error"); + MAP(SWIG_MemoryError, "swig-memory-error"); + MAP(SWIG_IOError, "swig-io-error"); + MAP(SWIG_RuntimeError, "swig-runtime-error"); + MAP(SWIG_IndexError, "swig-index-error"); + MAP(SWIG_TypeError, "swig-type-error"); + MAP(SWIG_DivisionByZero, "swig-division-by-zero"); + MAP(SWIG_OverflowError, "swig-overflow-error"); + MAP(SWIG_SyntaxError, "swig-syntax-error"); + MAP(SWIG_ValueError, "swig-value-error"); + MAP(SWIG_SystemError, "swig-system-error"); + MAP(SWIG_NullReferenceError, "swig-null-reference-error"); default: ERROR("swig-error"); } @@ -68,16 +70,17 @@ SWIGINTERN void SWIG_exception_ (int code, const char *msg) { ERROR(errname); \ break switch (code) { - MAP(SWIG_MemoryError, "swig-memory-error"); - MAP(SWIG_IOError, "swig-io-error"); - MAP(SWIG_RuntimeError, "swig-runtime-error"); - MAP(SWIG_IndexError, "swig-index-error"); - MAP(SWIG_TypeError, "swig-type-error"); - MAP(SWIG_DivisionByZero, "swig-division-by-zero"); - MAP(SWIG_OverflowError, "swig-overflow-error"); - MAP(SWIG_SyntaxError, "swig-syntax-error"); - MAP(SWIG_ValueError, "swig-value-error"); - MAP(SWIG_SystemError, "swig-system-error"); + MAP(SWIG_MemoryError, "swig-memory-error"); + MAP(SWIG_IOError, "swig-io-error"); + MAP(SWIG_RuntimeError, "swig-runtime-error"); + MAP(SWIG_IndexError, "swig-index-error"); + MAP(SWIG_TypeError, "swig-type-error"); + MAP(SWIG_DivisionByZero, "swig-division-by-zero"); + MAP(SWIG_OverflowError, "swig-overflow-error"); + MAP(SWIG_SyntaxError, "swig-syntax-error"); + MAP(SWIG_ValueError, "swig-value-error"); + MAP(SWIG_SystemError, "swig-system-error"); + MAP(SWIG_NullReferenceError, "swig-null-reference-error"); default: ERROR("swig-error"); } @@ -116,6 +119,9 @@ SWIGINTERN void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) { case SWIG_TypeError: exception_code = SWIG_JavaIllegalArgumentException; break; + case SWIG_NullReferenceError: + exception_code = SWIG_JavaNullPointerException; + break; case SWIG_UnknownError: default: exception_code = SWIG_JavaUnknownError; @@ -160,6 +166,9 @@ SWIGINTERN void SWIG_OCamlException(int code, const char *msg) { case SWIG_ValueError: exception_code = SWIG_OCamlIllegalArgumentException; break; + case SWIG_NullReferenceError: + exception_code = SWIG_OCamlNullReferenceException; + break; case SWIG_UnknownError: default: exception_code = SWIG_OCamlUnknownError; @@ -197,6 +206,9 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) { case SWIG_OverflowError: exception_code = SWIG_CSharpOverflowException; break; + case SWIG_NullReferenceError: + exception_code = SWIG_CSharpNullReferenceException; + break; case SWIG_RuntimeError: case SWIG_TypeError: case SWIG_SyntaxError: @@ -238,6 +250,9 @@ SWIGINTERN void SWIG_DThrowException(int code, const char *msg) { case SWIG_ValueError: exception_code = SWIG_DIllegalArgumentException; break; + case SWIG_NullReferenceError: + exception_code = SWIG_DNullReferenceException; + break; case SWIG_DivisionByZero: case SWIG_MemoryError: case SWIG_OverflowError: diff --git a/Lib/javascript/napi/javascriptrun.swg b/Lib/javascript/napi/javascriptrun.swg index 48783967118..7e956f966cf 100644 --- a/Lib/javascript/napi/javascriptrun.swg +++ b/Lib/javascript/napi/javascriptrun.swg @@ -49,6 +49,7 @@ SWIGINTERN void SWIG_NAPI_Raise(Napi::Env env, int type, const char *msg) { throw Napi::RangeError::New(env, msg); case SWIG_ValueError: case SWIG_TypeError: + case SWIG_NullReferenceError: throw Napi::TypeError::New(env, msg); } } @@ -90,6 +91,7 @@ SWIGINTERN void SWIG_NAPI_Raise(Napi::Env env, int type, const char *msg) { return; case SWIG_ValueError: case SWIG_TypeError: + case SWIG_NullReferenceError: Napi::TypeError::New(env, msg).ThrowAsJavaScriptException(); return; } diff --git a/Lib/ocaml/ocamlrundec.swg b/Lib/ocaml/ocamlrundec.swg index 4d20f34b261..76a1d61097c 100644 --- a/Lib/ocaml/ocamlrundec.swg +++ b/Lib/ocaml/ocamlrundec.swg @@ -45,6 +45,7 @@ typedef enum { SWIG_OCamlIndexOutOfBoundsException, SWIG_OCamlRuntimeException, SWIG_OCamlSystemException, + SWIG_OCamlNullReferenceException, SWIG_OCamlUnknownError } SWIG_OCamlExceptionCodes; @@ -54,6 +55,7 @@ SWIGINTERN void SWIG_OCamlThrowException(SWIG_OCamlExceptionCodes code, const ch switch (code) { case SWIG_OCamlIllegalArgumentException: + case SWIG_OCamlNullReferenceException: caml_invalid_argument(msg); break; case SWIG_OCamlSystemException: diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 5865c921b3e..228023c3570 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -43,6 +43,8 @@ SWIGRUNTIME octave_value SWIG_ErrorType(int code) { return "SWIG_SystemError"; case SWIG_AttributeError: return "SWIG_AttributeError"; + case SWIG_NullReferenceError: + return "SWIG_NullReferenceError"; } return "SWIG unknown error"; } diff --git a/Lib/perl5/perlerrors.swg b/Lib/perl5/perlerrors.swg index 57296c6793c..0e563b62df1 100644 --- a/Lib/perl5/perlerrors.swg +++ b/Lib/perl5/perlerrors.swg @@ -27,6 +27,8 @@ SWIG_Perl_ErrorType(int code) { return "SystemError"; case SWIG_AttributeError: return "AttributeError"; + case SWIG_NullReferenceError: + return "NullReferenceError"; default: return "RuntimeError"; } diff --git a/Lib/python/pyerrors.swg b/Lib/python/pyerrors.swg index 129327fad0a..e7fe688d193 100644 --- a/Lib/python/pyerrors.swg +++ b/Lib/python/pyerrors.swg @@ -39,6 +39,9 @@ SWIG_Python_ErrorType(int code) { case SWIG_AttributeError: type = PyExc_AttributeError; break; + case SWIG_NullReferenceError: + type = PyExc_TypeError; + break; default: type = PyExc_RuntimeError; } diff --git a/Lib/scilab/scirun.swg b/Lib/scilab/scirun.swg index 481aac7ac01..a7b737a6d61 100644 --- a/Lib/scilab/scirun.swg +++ b/Lib/scilab/scirun.swg @@ -131,6 +131,8 @@ SWIG_Scilab_ErrorType(int code) { return "SystemError"; case SWIG_AttributeError: return "AttributeError"; + case SWIG_NullReferenceError: + return "NullReferenceError"; default: return "RuntimeError"; } diff --git a/Lib/tcl/tclerrors.swg b/Lib/tcl/tclerrors.swg index 73d73f8cf81..120bb3ea05b 100644 --- a/Lib/tcl/tclerrors.swg +++ b/Lib/tcl/tclerrors.swg @@ -39,6 +39,9 @@ SWIG_Tcl_ErrorType(int code) { case SWIG_AttributeError: type = "AttributeError"; break; + case SWIG_NullReferenceError: + type = "NullReferenceError"; + break; default: type = "RuntimeError"; } diff --git a/Lib/typemaps/swigtypemaps.swg b/Lib/typemaps/swigtypemaps.swg index 733e5acd0fc..3c3014f8490 100644 --- a/Lib/typemaps/swigtypemaps.swg +++ b/Lib/typemaps/swigtypemaps.swg @@ -137,14 +137,14 @@ #define %error_block(Block...) %block(Block) #define %default_code(code) SWIG_ArgError(code) #define %argument_fail(code, type, name, argn) SWIG_exception_fail(%default_code(code), %argfail_fmt(type, name, argn)) -#define %argument_nullref(type, name, argn) SWIG_exception_fail(SWIG_ValueError, %argnullref_fmt(type, name, argn)) +#define %argument_nullref(type, name, argn) SWIG_exception_fail(SWIG_NullReferenceError, %argnullref_fmt(type, name, argn)) #define %variable_fail(code, type, name) SWIG_exception_fail(%default_code(code), %varfail_fmt(type, name)) -#define %variable_nullref(type, name) SWIG_exception_fail(SWIG_ValueError, %varnullref_fmt(type, name)) +#define %variable_nullref(type, name) SWIG_exception_fail(SWIG_NullReferenceError, %varnullref_fmt(type, name)) #define %releasenotowned_fail(code, type, name, argn) SWIG_exception_fail(%default_code(code), %releasenotownedfail_fmt(type, name, argn)) #if defined(SWIG_DIRECTOR_TYPEMAPS) #define %dirout_fail(code, type) SWIG_DirOutFail(%default_code(code), %outfail_fmt(type)) -#define %dirout_nullref(type) SWIG_DirOutFail(SWIG_ValueError, %outnullref_fmt(type)) +#define %dirout_nullref(type) SWIG_DirOutFail(SWIG_NullReferenceError, %outnullref_fmt(type)) #endif /* -----------------------------------------------------------------------------