The typecheck typemaps succeed for non pointers (SWIGTYPE, SWIGTYPE&,
SWIGTYPE&&) when the equivalent to C NULL is passed from the target
language. This commit implements a fix for Python to not accept a Python
None for non-pointer types.
Issue #1202
The -cppcast option is still turned on by default. The -nocppcast option
to turn off the use of c++ casts (const_cast, static_cast etc) has been
removed. However, defining SWIG_NO_CPLUSPLUS_CAST will still generate C casts
instead of C++ casts for C++ wrappers.
This a revert of commit fc79264a48:
"Revert "Remove -cppcast and -nocppcast command line options""
The Scilab and Javascript casting problems are now fixed, so -cppcast
is now switched on as default.
The function pointer typemaps were not being used when the function
pointer is const, like ADD_BY_VALUE_C in the funcptr_cpp.i testcase:
%constant int (* const ADD_BY_VALUE_C)(const int &, int) = addByValue;
Problem affecting Javascript and observable when running test-suite with -cppcast.
The -cppcast option is still turned on by default. The -nocppcast option
to turn off the use of c++ casts (const_cast, static_cast etc) has been
removed. However, defining SWIG_NO_CPLUSPLUS_CAST will still generate C casts
instead of C++ casts for C++ wrappers.
Use std::move on this pointer as the default approach to supporting
rvalue ref-qualifiers if a user really wants to wrap.
std::move requires <memory> headers so add swigfragments.swg for all
languages to use common fragments. Just header file fragments for now.
- .travis.yml:
- ppa:kwwette/octaves has Octave version 4.2, also run C++11 tests
- configure.ac:
- prefer Octave program "octave-cli" to "octave"
- extract any -std=* flags from CXX, add to OCTAVE_CXXFLAGS
- Lib/typemaps/fragments.swg:
- SWIG_isfinite_func(): extern "C++" is required as this fragment can
end up inside an extern "C" { } block
- Lib/octave:
- add std_wstring.i (copied from std_string.i) for C++11 tests
- Lib/octave/octrun.swg:
- move Octave version-checking macros to octruntime.swg
- Octave single()/double() functions now call .as_single()/.as_double()
methods; redirect calls to __float__() method as per .scalar_value()
- << and >> operators are no longer supported by Octave
- Lib/octave/octruntime.swg:
- move Octave version-checking macros here for conditional #includes
- #include interpreter.h instead of #toplev.h
- #include call-stack.h (now needed for octave_call_stack)
- unwind_protect is now in octave:: namespace
- error_state and warning_state are deprecated; use try/catch to catch
errors in feval() instead
- always set octave_exit = ::_Exit, to try to prevent segfault on exit
- Lib/octave/octopers.swg:
- << and >> operators are no longer supported by Octave
- Lib/octave/exception.i:
- Add macro SWIG_RETHROW_OCTAVE_EXCEPTIONS which rethrows any
exceptions raised by Octave >= 4.2
- Examples/test-suite/exception_order.i:
- Use macro SWIG_RETHROW_OCTAVE_EXCEPTIONS to rethrow exceptions
raised by error() function in Octave >= 4.2
- Update Doc/Manual/Octave.html and CHANGES.current
The vector of pointers (just fixed) were not working correctly because the
descriptors returned from swig::type_info() were sometimes returning
zero. Zero should only be used for void * as the subsequent call to
SWIG_ConvertPtr will blindly cast the pointer without checking
descriptor.
std::vector<void *> does not work and will require further changes:
specializing traits_info<void *> to return 0 and traits_asptr<void *>.
I tried this and traits_asptr<void> also needs to be added in which
seems odd and requires further investigation...
Lib/python/pystdcommon.swg:
template <> struct traits_info<void *> {
static swig_type_info *type_info() {
static swig_type_info *info = 0;
}
};
Lib/std/std_common.i:
template <>
struct traits_asptr<void *> {
static int asptr(PyObject *obj, void ***val) {
void **p;
swig_type_info *descriptor = 0;
int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
// this is needed, but am not sure this is expected
template <>
struct traits_asptr<void> {
static int asptr(PyObject *obj, void **val) {
void **p;
swig_type_info *descriptor = 0;
int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
New fragment to check if long long is available using LLONG_MAX
AsVal and From functions for ptrdiff_t and size_t now use long long if available and sizeof(ptrdiff_t) > sizeof(long)
Generated code does not include <string>, which is referenced in templates.
Clang may be incorrectly or aggresively instantiating some template.
E.g.,
import_stl_b_wrap.cxx:3199:51: error: implicit instantiation of undefined template 'std::__1::basic_string<char, std::__1::char_traits<char>
It was previously possible to assign "hello" to a variable backed by char[5]
storage in C, and the array contained the correct character data but without
the trailing NUL, which was unexpected in C.
This is not allowed any more, only "helo" can fit into a char[5] now and
anything else fails the type check, just as it already happened for the longer
strings before.
Closes#122
Use the usual C rule for NUL-terminated strings instead of discarding all the
trailing NUL characters.
This was unexpected (as buffers in C code are not necessarily always padded
with NULs to their full length) and also inconsistent among languages as this
was only done for those of them using typemaps/strings.swg but not for C# or
Java, for example, which terminated the string at the first NUL even before
this change.
Notice that this patch couldn't use strlen() or wcslen() with possibly not
NUL-terminated strings, so we had to add [our own equivalents of] strnlen()
and wcsnlen() and use them instead. This required adding yet another parameter
to string typemap macros, so update the example using them accordingly too.
* nested:
Deprecation of the 'nestedworkaround' feature
Ensure -c++out is not used with -c++
Add missing header to new source file
Nested C class setters restored in c++out mode for Octave
Classprefix fixed after private nested classes some comments and spaces added
Fix template partial specialization detection
Minor tweaks in Swig_feature_set
Swig_offset_string moved to misc.c
nested private classes are discarded while parsing nested relate functions are moved to nested.cxx and renamed accordingly
out-of-scope template definitions fixed nested_private test disabled again
fixed out-of-scope nested class definitions, added a test enabled nested C structs assignment (still disabled for Octave), added Java runtime test fixed nested_private test case for Java & C#
Testcase of private nested class usage causing segfault
C nested struct passed by value example
Add in Travis testing for nested branch
Add C++ nested class example
Minor code improvements
Cosmetics/code beautification of nested class support
Nested classes support
Suitable casts are required so that assignment of instances of nested classes
work as the nested class is duplicated in the global namespace, eg:
struct Outer {
struct Nested {
int bar;
} bar_instance;
};
Outer.bar_instance can now be assigned to.
This fix makes the handling of type 'float' and 'double' the same. The implementation requires the
C99 isfinite() macro, or otherwise some platform dependent equivalents, to be available.
* New test case tests that %attribute macros correctly supports passing
template with multiple parameters as class name or attribute type name
* Some further changes were made to %attribute macros - now
AttributeType is protected with %arg as well. This allows you
to have attributes of type e.g. std::pair<int,int> etc
Update CHANGES file for %attribute template fixes
Closes#48