Commit graph

4,354 commits

Author SHA1 Message Date
William S Fulton
dafe2d6949 Add director typemaps for pointer const ref types 2017-10-24 23:47:40 +01:00
William S Fulton
ae044c1c2f Generation of director method declarations fixes
- Fixes generation of director method declarations containing C++11 ref-qualifiers.
- Fixes generation of director method declarations returning more complex types such
  as const ref pointers.
- Rewrite Swig_method_call to use more up to date code in the core.
2017-10-23 18:55:14 +01:00
William S Fulton
3f8b8fe734 Enhancements for directorin typemaps
The directorin typemaps will now generate a temporary variable
(specified after the type), such as:
%typemap(directorin) MyType (MyType *temp) { ... use temp ... }

The shared_ptr director typemaps have been fixed for use in functions
that take more than one parameter.
2017-10-16 19:28:27 +01:00
William S Fulton
fcd7ecd9e2 R memory handling standardisation
Replace R_SWIG_EXTERNAL and R_SWIG_OWNER with the standard equivalent
macros. I can't see where these were actually used, but in case they are,
equivalent backwards compatibility can be obtained using:

  #define R_SWIG_EXTERNAL 0
  #define R_SWIG_OWNER SWIG_POINTER_OWN

SWIG_MakePtr does not seem to be used within the R SWIG code base so I
havn't added the above as backwards compatibility macros.
There seems to be no memory management in R. I've made this change
to fit in with the rest of SWIG though in preparation for an upcoming
commit to use the same shared_ptr macros as is used elsewhere.
2017-10-13 07:34:38 +01:00
Joseph C Wang
be05daa39a change r to allow logical enums. add change to CHANGES.current 2017-10-10 17:50:58 +08:00
Joseph Wang
8c9b06c9c0 Merge pull request #1118 from ojwb/r-enum-improvements
[R] Improve handling of enums
2017-10-10 04:45:34 +08:00
Olly Betts
0c56d0cb72 [PHP] Fix incorrect wrapper code generation
Fix code generated when there's a combination of overloading, parameters
with a default value and %newobject.  Fixes
https://sourceforge.net/p/swig/bugs/1350/
2017-10-09 10:40:27 +13:00
Olly Betts
59ebe27a95 Merge pull request #1111 from ojwb/empty-arglist-macros
Fix handling of macro with empty argument list
2017-10-08 15:34:37 +13:00
Olly Betts
0863eca5e7 Fix constants involved parenthesised char literals
Fixes https://sourceforge.net/p/swig/bugs/1168/
2017-10-08 13:43:02 +13:00
Olly Betts
f85d87a64c Fix bug with macro invocation with empty first arg
The first argument was being dropped in this case.
2017-10-08 09:02:28 +13:00
Olly Betts
866840f791 Fix handling of macro with empty argument list 2017-10-08 09:02:28 +13:00
Olly Betts
4236b1ec9e [R] Improve handling of enums
Partial fix for https://github.com/swig/swig/issues/1116 but this needs
more work.
2017-10-07 10:36:07 +13:00
William S Fulton
4a7976a5d8 Fix platorm inconsistency in Python default argument handling.
32 bit and 64 bit compiled versions of SWIG generated different Python files
when default arguments were outside the range of 32 bit signed integers.
The default arguments specified in Python are now only those that are in the
range of a 32 bit signed integer, otherwise the default is obtained from C/C++ code.

Closes #1108
2017-10-06 21:57:04 +01:00
William S Fulton
afd986c577 Python - set errno for default args handling
errno needs setting otherwise a failed strol may result in subsequent
unnecessary code generation to use *args instead of actual default
argument values. Related to issue #1108.
2017-10-04 06:50:47 +01:00
William S Fulton
8834047dcd Enhance -debug-csymbols and -debug-symbols to show siblings 2017-10-02 19:07:24 +01:00
Joseph C Wang
f0acfcfb4b Merge branch 'r_fixes_2' of https://github.com/fschlimb/swig 2017-10-01 09:48:37 +08:00
William S Fulton
e27a606335 Allow an instantiated template to have the same name as the C++ template name
For example, this is now possible:
  template<typename T> struct X { ... };
  %template(X) X<int>;
Closes #1100.
2017-09-29 23:28:04 +01:00
William S Fulton
d37e41fed8 Cosmetic variable name change in parser 2017-09-29 21:16:19 +01:00
William S Fulton
ed4b84f4d3 Fix overloading of shared_ptr method overloading
Add 'equivalent' attribute to typecheck typemap.
Closes #1098.
2017-09-23 15:19:34 +01:00
William S Fulton
9e79d3566b Workaround spurious gcc warning [-Woverlength]
warning: string length ‘2241’ is greater than the length ‘509’ ISO C90 compilers are required to support [-Woverlength-strings]
2017-09-20 14:04:16 +01:00
William S Fulton
20521eae68 Merge branch 'interface-using-declaration'
* interface-using-declaration:
  Fix seg fault with %interface and using declarations
2017-09-18 18:09:30 +01:00
William S Fulton
9e2a12416c Fix type promotion wrapping some non-trivial constant expressions
This was previously an integral type instead of a floating point type:
2017-09-18 07:06:27 +01:00
William S Fulton
90ba174fce Fix generated code for constant expressions containing wchar_t L literals.
Such as:
  # define __WCHAR_MAX    (0x7fffffff + L'\0')

Reported on swig-user mailing list.
2017-09-17 19:02:55 +01:00
William S Fulton
2fee7c96cc Remove C casts in PyTypeObject for Python builtin type declarations
Choose compile time failures over runtime errors.
This change highlighted a problem in the constructor wrappers for tp_init
where the kwargs parameter was missing in the generated wrapper function.
Leave casts in for 0 initialization.
2017-09-12 18:10:57 +01:00
William S Fulton
8a168795d3 Cosmetic formatting fixes in generated code for exception handlers 2017-09-12 08:47:10 +01:00
William S Fulton
6077b808f7 Remove code duplication of Swig_overload_rank
Allegrocl and R versions were also out of date
2017-09-11 23:18:55 +01:00
William S Fulton
4d2d8dd80e Merge branch 'cpp11-ref-qualifiers'
* cpp11-ref-qualifiers:
  Warnings in testcases fix
  Add support for %typemap and member function pointers with qualifiers
  Fix wrapping of some member function pointer parameters
  Add support for member function pointers with ref-qualifiers
  Add error for constructors, destructors, static methods declared with qualifiers
  Add support for conversion operators with ref-qualifiers
  Alternate function syntax parsing improvement
  Re-organise parser grammar for initializer rules
  Re-organise parser grammar for declarator and initializer rules
  Add docs for C++11 ref-qualifiers
  Add unignore for rvalue ref-qualifiers
  Improve ref-qualifier implementation
  Fix support for member const function pointer variables
  Use normal SWIG encodings for ref-qualifiers
  C++11 ref-qualifier support added
2017-09-11 19:33:27 +01:00
William S Fulton
c4e280024f Add support for %typemap and member function pointers with qualifiers 2017-09-09 23:46:14 +01:00
William S Fulton
45c161dfce Fix wrapping of some member function pointer parameters
Generated code did not compile if both cv-qualifiers and rvalue
ref-qualifiers were present in the member function pointer.
2017-09-07 06:58:01 +01:00
William S Fulton
eb68e4375d Add support for member function pointers with ref-qualifiers 2017-09-05 18:44:00 +01:00
Frank Schlimbach
1df744e0c3 smart-pointer classes deriving from parent smart-pointers
white-space cleanup
2017-08-31 05:28:48 -05:00
Frank Schlimbach
e6a1a7dbd1 constructors now returning smart pointers (if class declared as such) 2017-08-31 05:24:29 -05:00
Frank Schlimbach
d4989aa7fc fixing smart-pointer and NAMESPACE support 2017-08-31 05:24:03 -05:00
Frank Schlimbach
61c24e9cd1 - allowing R package names with containing dosts ('.')
- allowing mulitple get accessors in R
2017-08-31 04:04:58 -05:00
William S Fulton
7e4717320b Add error for constructors, destructors, static methods declared with qualifiers
SWIG parses a superset of valid C++ declarations. These ill-formed declarations
were previously successfully parsed but now result an error message.
2017-08-30 18:17:05 +01:00
William S Fulton
950edc1c00 Add support for conversion operators with ref-qualifiers 2017-08-30 18:17:05 +01:00
William S Fulton
0e50ef30b1 Alternate function syntax parsing improvement
This was incorrectly accepting qualifiers and exception specifications
in the wrong place.
2017-08-30 18:17:04 +01:00
William S Fulton
8227c02267 Re-organise parser grammar for initializer rules
Simply split initializer into const_cpp and initializer
2017-08-30 18:17:04 +01:00
William S Fulton
c9d425604c Re-organise parser grammar for declarator and initializer rules
Step 1 to make these closer to the definitions used in the standard.
The initializer rule should not include qualifiers and exception specification.

- split cpp_const into add qualifiers_exception_specification and empty rules
- simplify initializer to use new qualifiers_exception_specification rule
2017-08-30 18:17:04 +01:00
William S Fulton
8a40327aa8 Add unignore for rvalue ref-qualifiers
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.
2017-08-30 18:17:04 +01:00
William S Fulton
1cf599bccb Improve ref-qualifier implementation
Internally, handle function ref-qualifiers in the function decl type string.
Needed for a whole host of things to work like %feature and %rename.
Add %feature %rename and %ignore testing for ref-qualifiers.
2017-08-30 18:17:04 +01:00
William S Fulton
eeab152901 Fix support for member const function pointer variables
Was not generating code that compiled when the variable was not
a simple member pointer, for example,
a const reference member pointer:
  short (Funcs::* const& cc7)(bool) const = cc1;
2017-08-30 18:16:59 +01:00
William S Fulton
fbada9959c Fix types when calling PyTuple_New
Replace int with Py_ssize_t to fix warnings on Windows when using -O
and/or -builtin.
2017-08-27 14:18:00 +01:00
William S Fulton
665b09ffc9 Fix seg fault with %interface and using declarations 2017-08-21 18:34:51 +01:00
William S Fulton
685ee6cdc4 Use normal SWIG encodings for ref-qualifiers 2017-08-19 09:38:19 +01:00
William S Fulton
9e19fe7868 C++11 ref-qualifier support added
Fixes #1059

Methods with rvalue ref-qualifiers are ignored by default as it is not
possible to have an rvalue temporary from the target language (which is
needed to call the rvalue ref-qualified method).
A warning 405 is shown mentioning the ignored rvalue ref-qualifier method
which can be seen with the -Wextra option.

  cpp_refqualifier.i:15: Warning 405: Method with rvalue ref-qualifier ignored h() const &&.

Usually rvalue and lvalue ref-qualifier overloaded methods are written - the
lvalue method will then be wrapped.
2017-08-19 01:02:34 +01:00
William S Fulton
32a454cfef Merge branch 'templates-scope-enforcement'
* templates-scope-enforcement:
  Test a few %template errors
  Add using declarations to templates into typedef table.
  Fix type lookup in the presence of using directives and using declarations
  More docs on %template
  Testcase fix for nameclash in php
  %template scope enforcement and class definition fixes
  Template documentation tweaks
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Documentation corrections to use targetlang formatting
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Namespace documentation minor corrections
  Improve description of template_parameters_resolve
  Minor code optimisation in template_parameters_resolve
  Fix scope lookup for template parameters containing unary scope operators
  Typemap change for templates
2017-08-16 21:44:51 +01:00
William S Fulton
96e99416d7 Add using declarations to templates into typedef table.
Fixes #1051. Using declarations to templates were missing in SWIG's internal typedef tables.
This led to a few problems, such as, templates that did not instantiate and generated
C++ code that did not compile as SWIG did not know what scope the template was
in. This happened mostly when a using declaration was used on a template type in a
completely unrelated namespace.
2017-08-16 00:24:25 +01:00
William S Fulton
bf98c5304f Fix type lookup in the presence of using directives and using declarations
Fix some cases of type lookup failure via a combination of both using directives and
using declarations resulting in C++ code that did not compile as the generated type was
not fully qualified for use in the global namespace. Example below:

    namespace Space5 {
      namespace SubSpace5 {
        namespace SubSubSpace5 {
          struct F {};
        }
      }
      using namespace SubSpace5;
      using SubSubSpace5::F;
      void func(SubSubSpace5::F f);
    }
2017-08-16 00:24:25 +01:00
William S Fulton
959e627208 %template scope enforcement and class definition fixes
The scoping rules around %template have been specified and enforced.
The %template directive for a class template is the equivalent to an
explicit instantiation of a C++ class template. The scope for a valid
%template instantiation is now the same as the scope required for a
valid explicit instantiation of a C++ template. A definition of the
template for the explicit instantiation must be in scope where the
instantiation is declared and must not be enclosed within a different
namespace.

For example, a few %template and explicit instantiations of std::vector
are shown below:

  // valid
  namespace std {
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // valid
  using namespace std;
  %template(vin) vector<int>;
  template class vector<int>;

  // valid
  using std::vector;
  %template(vin) vector<int>;
  template class vector<int>;

  // ill-formed
  namespace unrelated {
    using std::vector;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    using namespace std;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    namespace std {
      %template(vin) vector<int>;
      template class vector<int>;
    }
  }

  // ill-formed
  namespace unrelated {
    %template(vin) std::vector<int>;
    template class std::vector<int>;
  }

When the scope is incorrect, an error now occurs such as:

cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and
was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.

Previously SWIG accepted the ill-formed examples above but this led to
numerous subtle template scope problems especially in the presence of
using declarations and using directives as well as with %feature and %typemap.

Actually, a valid instantiation is one which conforms to the C++03
standard as C++11 made a change to disallow using declarations and
using directives to find a template.

  // valid C++03, ill-formed C++11
  using std::vector;
  template class vector<int>;

Similar fixes for defining classes using forward class references have
also been put in place. For example:

namespace Space1 {
  struct A;
}
namespace Space2 {
  struct Space1::A {
    void x();
  }
}

will now error out with:

cpp_class_definition.i:5: Error: 'Space1::A' resolves to 'Space1::A' and
was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
2017-08-16 00:24:25 +01:00