Skip to content

Commit

Permalink
Merge branch 'swig:master' into feature/new_objc
Browse files Browse the repository at this point in the history
  • Loading branch information
CancerQ authored Feb 1, 2024
2 parents 76d3165 + 2823c70 commit 3d4b5e7
Show file tree
Hide file tree
Showing 35 changed files with 362 additions and 206 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
show-progress: false
submodules: recursive

- name: Install CCache
Expand Down
20 changes: 20 additions & 0 deletions CHANGES.current
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.2.1 (in progress)
===========================

2024-01-31: olly
Fix assertion failure and segfault trying to use %constant to
deduce the type of a "float _Complex" constant.

2024-01-31: jim-easterbrook
#2771 [Python] builtin fixes to handle NULL values passed to slots using
functype: ssizeobjargproc and ternaryfunc.

2024-01-31: olly
[java] #2766 Fix segfault trying to wrap a constant whose type is unknown
to SWIG with "%javaconst(1);" enabled.

2024-01-31: wsfulton
#2768 Fix seg fault handling upcasting when using %shared_ptr on some
templates.

2024-01-31: olly
#2783 Fix incorrectly deduced type for function call. Regression
introduced in 4.2.0.

2024-01-27: wsfulton
[Python] Fix compilation error when wrapping two or more classes that
have the same friend operator overload when the classes are in a namespace.
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ endif()
configure_file (${SWIG_ROOT}/Tools/cmake/swigconfig.h.in
${CMAKE_CURRENT_BINARY_DIR}/Source/Include/swigconfig.h)

find_package (BISON REQUIRED)
find_package (BISON 3.5 REQUIRED)


# Compiler flags
Expand Down
2 changes: 1 addition & 1 deletion Doc/Devel/internals.html
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ <h2>3. Types and Typemaps</h2>
<li><tt>SwigType_str(SwigType *t, char *name)</tt>.<br>
This function produces the exact string
representation of the datatype <tt>t</tt>. <tt>name</tt> is an optional parameter that
specifies a declaration name. This is used when dealing with more complicated datatypes
specifies a declaration name and can be <tt>NULL</tt>. This is used when dealing with more complicated datatypes
such as arrays and pointers to functions where the output might look something like
"<tt>int (*name)(int, double)</tt>".

Expand Down
4 changes: 2 additions & 2 deletions Doc/Manual/SWIGPlus.html
Original file line number Diff line number Diff line change
Expand Up @@ -4503,8 +4503,8 @@ <H2><a name="SWIGPlus_namespaces">6.19 Namespaces</a></H2>

<div class="shell">
<pre>
example.i:26. Error. 'foo' is multiply defined in the generated target language module.
example.i:23. Previous declaration of 'foo'
example.i:26: Error: 'foo' is multiply defined in the generated target language module.
example.i:23: Error: Previous declaration of 'foo'
</pre>
</div>

Expand Down
7 changes: 6 additions & 1 deletion Examples/test-suite/ccomplextest.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%{
#include <complex.h>

#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199001L
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __STDC_NO_COMPLEX__
#define HAS_C99_COMPLEX_FOR_TESTING 1
#else
/* c99 complex not supported - super hack tests to just test plain floating point numbers */
Expand All @@ -26,6 +26,11 @@
#endif
%}

%inline %{
static float _Complex CPLX_CONSTANT_ = 0;
%}
%constant CPLX_CONSTANT = CPLX_CONSTANT_;

%inline
{
int has_c99_complex(void) {
Expand Down
92 changes: 92 additions & 0 deletions Examples/test-suite/cpp11_shared_ptr_crtp_upcast.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
%module cpp11_shared_ptr_crtp_upcast

// Cutdown testcase for assert reported in https://github.com/swig/swig/issues/2768
// Note that this test has CRTP and %template instantiations for DiscretisedDensity template parameters not fully resolved

%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_RUBY_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) stir::DiscretisedDensity<3,float>;

%include <std_shared_ptr.i>

%{
#include <memory>
namespace stir {}
using namespace stir;
%}

%inline %{
namespace stir {
// Note: CRTP
template <typename Derived, typename Base, typename Parent = Base>
class RegisteredParsingObject : public Parent {
};
}
%}

%shared_ptr(stir::Array<3,float>)
%inline %{
namespace stir {
template <int num_dimensions, typename elemT>
class Array {
};
}
%}
%template(FloatArray3D) stir::Array<3,float>;

%shared_ptr(stir::ExamData);
%inline %{
namespace stir {
class ExamData {
};
}
%}

%shared_ptr(stir::DiscretisedDensity<3,float>)
%inline %{
namespace stir {
template<int num_dimensions, typename elemT>
class DiscretisedDensity : public ExamData, public Array<num_dimensions,elemT> {
};
}
%}

%shared_ptr(stir::DataProcessor<stir::DiscretisedDensity<3,float> >)
%shared_ptr(stir::RegisteredParsingObject<
stir::ChainedDataProcessor<stir::DiscretisedDensity<3,float> >,
stir::DataProcessor<DiscretisedDensity<3,float> >,
stir::DataProcessor<DiscretisedDensity<3,float> > >)
%shared_ptr(stir::ChainedDataProcessor<stir::DiscretisedDensity<3,float> >)

%inline %{
namespace stir {
template <typename DataT>
class DataProcessor {
};

template <typename DataT>
class ChainedDataProcessor : public RegisteredParsingObject< ChainedDataProcessor<DataT>, DataProcessor<DataT>, DataProcessor<DataT> > {
};
}
%}

// SWIG will qualify Discretised in the %template() declaration even though Discretised
// is not in scope with the 'using namespace stir' below commented out.
//using namespace stir;
%template(Float3DDiscretisedDensity) stir::DiscretisedDensity<3,float>;
%template(DataProcessor3DFloat) stir::DataProcessor<stir::DiscretisedDensity<3,float> >;
%template(RPChainedDataProcessor3DFloat) stir::RegisteredParsingObject<
stir::ChainedDataProcessor<stir::DiscretisedDensity<3,float> >,
stir::DataProcessor<DiscretisedDensity<3,float> >,
stir::DataProcessor<DiscretisedDensity<3,float> > >;
%template(ChainedDataProcessor3DFloat) stir::ChainedDataProcessor<stir::DiscretisedDensity<3,float> >;

%inline %{
void useobject(stir::RegisteredParsingObject<
stir::ChainedDataProcessor<stir::DiscretisedDensity<3,float> >,
stir::DataProcessor<DiscretisedDensity<3,float> >,
stir::DataProcessor<DiscretisedDensity<3,float> > >) {
}
%}
1 change: 1 addition & 0 deletions Examples/test-suite/csharp/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CPP_TEST_CASES = \

CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_crtp_upcast \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_template_upcast \
Expand Down
1 change: 1 addition & 0 deletions Examples/test-suite/d/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CPP_TEST_CASES = \

CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_crtp_upcast \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
Expand Down
14 changes: 14 additions & 0 deletions Examples/test-suite/errors/cpp_smartptr_feature.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%module xxx

%feature("smartptr", noblock=1) AA { std::shared_ptr< AA > }
%feature("smartptr", noblock=1) DD { std::shared_ptr< }


struct AA {};
struct BB : AA {};
struct CC : AA {};
struct DD : AA {};

%feature("smartptr", noblock=1) YY { std::shared_ptr< YY > }
struct XX {};
struct YY : XX {};
5 changes: 5 additions & 0 deletions Examples/test-suite/errors/cpp_smartptr_feature.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cpp_smartptr_feature.i:8: Warning 520: Derived class 'BB' of 'AA' is not similarly marked as a smart pointer.
cpp_smartptr_feature.i:9: Warning 520: Derived class 'CC' of 'AA' is not similarly marked as a smart pointer.
cpp_smartptr_feature.i:10: Error: Invalid type (std::shared_ptr<) in 'smartptr' feature for class DD.
cpp_smartptr_feature.i:10: Warning 520: Derived class 'DD' of 'AA' is not similarly marked as a smart pointer.
cpp_smartptr_feature.i:14: Warning 520: Base class 'XX' of 'YY' is not similarly marked as a smart pointer.
1 change: 1 addition & 0 deletions Examples/test-suite/java/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ CPP_TEST_CASES = \

CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_crtp_upcast \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_template_upcast \
Expand Down
1 change: 1 addition & 0 deletions Examples/test-suite/octave/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CPP_TEST_CASES += \

CPP11_TEST_CASES += \
cpp11_shared_ptr_const \
cpp11_shared_ptr_crtp_upcast \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
Expand Down
2 changes: 1 addition & 1 deletion Examples/test-suite/php/overload_simple_runme.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require "tests.php";

check::functions(array('foo','blah','fbool','fint','fdouble','num','fid','as_ull','as_ll','malloc_void','free_void','int_object'));
check::functions(array('foo','blah','fbool','fint','fdouble','num','fid','as_l','as_ll','as_ul','as_ull','malloc_void','free_void','int_object','sizeof_long'));
check::classes(array('Foo','Bar','overload_simple','Spam','ClassA'));
// No new vars
check::globals(array());
Expand Down
1 change: 1 addition & 0 deletions Examples/test-suite/python/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ CPP_TEST_CASES += \
CPP11_TEST_CASES = \
cpp11_hash_tables \
cpp11_shared_ptr_const \
cpp11_shared_ptr_crtp_upcast \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_template_upcast \
Expand Down
23 changes: 23 additions & 0 deletions Examples/test-suite/python/python_builtin_runme.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,26 @@
z = pow(x, y, z)
if z.Value() != 7:
raise RuntimeError("pow(x, y, z) wrong")

# Test 8 https://github.com/swig/swig/pull/2771 __setitem__ for deleting item, uses C NULL
def check_gsi(gsi, idx, value, args_count, kw_count):
if gsi.idx != idx:
raise RuntimeError("idx wrong {}".format(idx))
if gsi.value != value:
raise RuntimeError("value wrong {}".format(value))
if gsi.args_count != args_count:
raise RuntimeError("args_count wrong {}".format(args_count))
if gsi.kw_count != kw_count:
raise RuntimeError("kw_count wrong {}".format(kw_count))
gsi.reset()

if is_python_builtin():
gsi = GetSetItem()
gsi[0] = 111
check_gsi(gsi, 0, 111, -100, -100)
del gsi[0]
check_gsi(gsi, 0, -11, -100, -100)
gsi(222, fred = 333, jack = 444)
check_gsi(gsi, -100, -100, 1, 2)
gsi(333)
check_gsi(gsi, -100, -100, 1, -11)
32 changes: 32 additions & 0 deletions Examples/test-suite/python_builtin.i
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,35 @@ public:
}
};
%}

// Test 8 https://github.com/swig/swig/pull/2771 __setitem__ for deleting item, uses C NULL
%feature("python:slot", "sq_item", functype="ssizeargfunc") GetSetItem::__getitem__;
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") GetSetItem::__setitem__;
%feature("python:slot", "tp_call", functype="ternaryfunc") GetSetItem::__call__;
%typemap(default) PyObject* value {$1 = NULL;}

%inline %{
class GetSetItem {
public:
int idx, value, args_count, kw_count;
GetSetItem() : idx(), value(), args_count(), kw_count() { reset(); }
int __getitem__(int idx) {
this->idx = idx;
return 123;
}
void __setitem__(int idx, PyObject* value) {
this->idx = idx;
this->value = value ? (int)PyInt_AsLong(value) : -11;
}
void __call__(PyObject* args, PyObject* kw) {
this->args_count = args ? (int)PyTuple_Size(args) : -11;
this->kw_count = kw ? (int)PyDict_Size(kw) : -11;
}
void reset() {
idx = -100;
value = -100;
args_count = -100;
kw_count = -100;
}
};
%}
1 change: 1 addition & 0 deletions Examples/test-suite/ruby/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CPP_TEST_CASES = \
CPP11_TEST_CASES = \
cpp11_hash_tables \
cpp11_shared_ptr_const \
cpp11_shared_ptr_crtp_upcast \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
Expand Down
12 changes: 8 additions & 4 deletions Lib/python/builtin.swg
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ SwigPyBuiltin_ternaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py
assert(tuple);
Py_INCREF(b);
PyTuple_SET_ITEM(tuple, 0, b);
Py_INCREF(c);
PyTuple_SET_ITEM(tuple, 1, c);
if (c) {
Py_INCREF(c);
PyTuple_SET_ITEM(tuple, 1, c);
}
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
Expand Down Expand Up @@ -656,8 +658,10 @@ SwigPyBuiltin_ssizeobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a
tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
Py_INCREF(c);
PyTuple_SET_ITEM(tuple, 1, c);
if (c) {
Py_INCREF(c);
PyTuple_SET_ITEM(tuple, 1, c);
}
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_XDECREF(resultobj);
Expand Down
28 changes: 23 additions & 5 deletions Source/CParse/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,14 @@ Hash *Swig_cparse_features(void) {
return features_hash;
}

/* Fully qualify any template parameters */
/* -----------------------------------------------------------------------------
* feature_identifier_fix()
*
* If a template, return template with all template parameters fully resolved.
*
* This is a copy and modification of typemap_identifier_fix.
* ----------------------------------------------------------------------------- */

static String *feature_identifier_fix(String *s) {
String *tp = SwigType_istemplate_templateprefix(s);
if (tp) {
Expand Down Expand Up @@ -3162,10 +3169,13 @@ c_decl : storage_class type declarator cpp_const initializer c_decl_tail {
if ($5.val && $5.type) {
/* store initializer type as it might be different to the declared type */
SwigType *valuetype = NewSwigType($5.type);
if (Len(valuetype) > 0)
Setattr($$,"valuetype",valuetype);
else
Delete(valuetype);
if (Len(valuetype) > 0) {
Setattr($$, "valuetype", valuetype);
} else {
/* If we can't determine the initializer type use the declared type. */
Setattr($$, "valuetype", $2);
}
Delete(valuetype);
}
if (!$6) {
if (Len(scanner_ccode)) {
Expand Down Expand Up @@ -6882,7 +6892,15 @@ exprcompound : expr PLUS expr {
}
$$.val = NewStringf("%s%s",qty,scanner_ccode);
Clear(scanner_ccode);
// Try to deduce the type - this could be a C++ "constructor
// cast" such as `double(4)` or a function call such as
// `some_func()`. In the latter case we get T_USER, but that
// is wrong so we map it to T_UNKNOWN until we can actually
// deduce the return type of a function call (which is
// complicated because the return type can vary between
// overloaded forms).
$$.type = SwigType_type(qty);
if ($$.type == T_USER) $$.type = T_UNKNOWN;
Delete(qty);
}
;
Expand Down
Loading

0 comments on commit 3d4b5e7

Please sign in to comment.