Commit graph

5,357 commits

Author SHA1 Message Date
William S Fulton
15b2ec53e3 Runtime tables deterministic ordering (4)
Output C/C++ type strings (| separated) in swig_type_info tables in
fixed order. The types are output in alphabetically sorted order,
with an exception. The final type is a fully resolved type, but
does not necessarily include default template parameters.
This type is the one used by SWIG_TypePrettyName which is commonly
used to display a type when the wrong type is passed in as a
parameter.

Previously the order was not very deterministic due to the use of
internal hash tables which do not have an ordering guarantee.
2022-09-29 19:40:47 +01:00
William S Fulton
5fdb591a62 Runtime tables deterministic ordering (3)
Output conversion functions used in the type tables in sorted order.
Sorted order in this case is the type being converted from.
So _p_BarTo_p_Foo comes before _p_ZarTo_p_Foo.

Previously the order was roughly in the order that the types were
parsed, but not necessarily due to the use of internal hash tables
which do not have an ordering guarantee.
2022-09-29 19:30:20 +01:00
William S Fulton
04af102578 Runtime tables deterministic ordering (2)
Output conversion functions used in the type tables in sorted order.
Sorted order in this case is the type being converted to.
So _p_BarTo_p_Foo comes before _p_BarTo_p_Zoo.

Previously the order was roughly in the order that the types were
parsed, but not necessarily due to the use of internal hash tables
which do not have an ordering guarantee.
2022-09-29 19:30:20 +01:00
William S Fulton
acbe8ed49c Runtime tables deterministic ordering (1)
Many parts of the runtime tables are alphabetically sorted before
for the generated code. This patch sorts the elements within the
swig_cast_info lists. Order now is first the elements without a
converter then the elements with a converter.
For example:

new:
static swig_cast_info _swigc__p_Foo[] = {
  {&_swigt__p_Foo, 0, 0, 0},
  {&_swigt__p_Bar, _p_BarTo_p_Foo, 0, 0},
  {&_swigt__p_Spam, _p_SpamTo_p_Foo, 0, 0},
  {0, 0, 0, 0}};

old:
static swig_cast_info _swigc__p_Foo[] = {
  {&_swigt__p_Bar, _p_BarTo_p_Foo, 0, 0},
  {&_swigt__p_Foo, 0, 0, 0},
  {&_swigt__p_Spam, _p_SpamTo_p_Foo, 0, 0},
  {0, 0, 0, 0}};

Previously the order was roughly in the order that the types were
parsed, but not necessarily due to the use of internal hash tables
which do not have an ordering guarantee.
2022-09-29 19:30:20 +01:00
Olly Betts
9a4dea06c8 [php] Add php:allowdynamicproperties feature
This follows PHP 8.2 deprecating dynamic features.

The new feature also provides a clean way to fix the remaining PHP
test case failure under PHP 8.2.
2022-09-29 18:16:51 +13:00
Olly Betts
cb9c96011a [php] Suppress -Wdeclaration-after-statement in php.h
In PHP 8.2 zend_operators.h contains inline code which triggers this
warning and our testsuite uses with option and -Werror.

I don't see a good way to only do this within our testsuite, but
disabling it globally like this shouldn't be problematic.
2022-09-29 11:06:56 +13:00
Olly Betts
246dd2d787 [php] Workaround PHP 8.2 header problem
We need to include php.h before stdio.h (and probably before most
other libc headers).
2022-09-28 19:01:01 +13:00
Olly Betts
55c95d475c [php] Adapt swig_ptr_cast_object for PHP 8.2
The required return type has changed from int to an enum, which
gives a compiler warning when we assign a function pointer.
2022-09-28 18:59:31 +13:00
Frank Schlimbach
fa00622614 Fixes for classes with the same name in different namespaces
Includes the majority of patch #1484.
Excludes changes in typepass.cxx for specializations which have no effect
on the duplicate_class_name_in_ns testcase, nor the rest of the test-suite.
2022-09-21 22:38:22 +01:00
William S Fulton
ee9e436971 Fix -Wmisleading-indentation in Octave wrappers 2022-09-20 22:31:50 +01:00
Vadim Zeitlin
b9fa8c23bb Make method wrappers suffix optional and disabled by default
Unfortunately the changes of 26bf86322 (Use SWIG-specific for
non-overloaded synthesized functions too, 2021-11-09) did break some
existing code bases using SWIG as they hardcoded the old wrapper
function names.

So turn this off by default and add a global variable allowing to enable
this, which can be done for a specific language only. This is ugly but,
unfortunately, there is no way to use the Language object from the C
function Swig_MethodToFunction(), so the only alternative would be to
add another parameter to it, but it already has 6 of them, so it
wouldn't really be that much better.

See #2366, #2368, #2370.
2022-09-19 12:40:03 +12:00
William S Fulton
910fd1e3cf [D] Fix occasional undefined behaviour with inheritance hierarchies
Particularly when using virtual inheritance as the pointers weren't
correctly upcast from derived class to base class when stored in the
base's proxy class.

Fixes commented out test code in cpp11_std_unique_ptr_runme
and li_std_auto_ptr_runme D tests.
2022-08-05 22:30:23 +01:00
William S Fulton
15a9ce36f8 ISO C comments fix 2022-08-04 07:51:20 +01:00
William S Fulton
1d56bc6b85 Add initialisers for additional members in PyHeapTypeObject
(builtin mode) for Python-3.11 - _ht_tpname, _spec_cache.
2022-08-01 08:24:52 +01:00
William S Fulton
3fa8e1f38f Visual C++ warning fix
conversion from '__int64' to 'long', possible loss of data
2022-07-31 01:02:08 +01:00
Olly Betts
dce4254377 [php] Fix handling of friend functions
We were incorrectly considering them as methods of the class they
are a friend of for the purposes of calculate PHP type declarations.
2022-07-29 16:37:22 +12:00
Olly Betts
8cc3d04a35 [perl] Note in -help that -proxy is on by default 2022-07-28 10:23:54 +12:00
Olly Betts
100d4d5350 Only recognise spaceship operator for C++
I don't think any valid C program can contain `<=>` in a tokenisable
context, but it's more helpful to fail with a syntax error at SWIG
parse time and not potentially generate C code trying to use `<=>` in
an expression which then fails at compile time.
2022-07-27 13:46:53 +12:00
Olly Betts
54ddefe410 Revert "Modify fix for << in array size"
This reverts commit 0ff9a0959a.

The modified fix breaks Java and C#, where C constant expressions
get used in the generated target language code in some cases.

Revert this fix for now.
2022-07-27 13:45:08 +12:00
Olly Betts
0ff9a0959a Modify fix for << in array size
The previous fix broke testcase arrays for Go.
2022-07-27 12:25:27 +12:00
Olly Betts
2227dc9e53 Fix handling of array whose size contains <<
Fixes https://sourceforge.net/p/swig/bugs/983/
2022-07-27 10:29:33 +12:00
Olly Betts
e31de2aebb Tidy up indentation 2022-07-27 09:30:30 +12:00
Zackery Spytz
61928bd882 Add support for C++20 "templated" lambdas
Such as `auto lambda = []<typename T>(std::vector<T> t){};`
2022-07-27 09:15:32 +12:00
Olly Betts
02b4bd8eca Fix spaceship operator bugs, document, add tests
Remove some erroneously added brackets_increment() calls.

Reject <=> in preprocessor expressions with a clear error message (it
seems it isn't supported here - clang and gcc don't at least).

The type returned by `<=>` is not `bool`.  We pretend it's
`int` for now, which should work for how it's likely to be used
in constant expressions.

Fixes #1622
2022-07-27 09:12:40 +12:00
Zackery Spytz
cb887ed2d4 Add support for the <=> operator (C++20) 2022-07-27 09:12:40 +12:00
Olly Betts
36310c04e5 Add comments to clarify how #define gets wrapped
It took me a while to fully get my head around this, and I'd like to
help out future developers.
2022-07-27 09:10:51 +12:00
Olly Betts
8c5c14b9ad Merge branch 'cpp-testing'
Closes #2329
2022-07-27 07:55:24 +12:00
Olly Betts
1bfe88eeda Support binary integer literals in the preprocessor 2022-07-26 15:28:51 +12:00
Olly Betts
de5ce08a7d Fix operator precedence in preprocessor expressions 2022-07-26 14:18:38 +12:00
William S Fulton
7592722e39 Order of interfaces generated for %interface macros
Ensure the order of interfaces generated in proxy interfaces for the
%interface family of macros is the same as that parsed from the bases in C++.
2022-07-20 19:50:53 +01:00
Olly Betts
6b4d5fe3f0 Remove remaining code to support macos9
This OS has been unsupported for over 20 years.  We stopped providing
macswig builds more than 20 years ago too:

https://sourceforge.net/projects/swig/files/macswig/

The required SIOUX library doesn't seem to be available anywhere
now either.

Closes #2323
2022-07-19 11:22:37 +12:00
Olly Betts
892557e799 Improve #include guard macros
Avoid using reserved identifiers such as `_DOHINT_H` (fixes #1989),
fix cases where the name doesn't match the filename, and make the naming
more consistent and less likely to collide with include guards in other
headers.
2022-07-19 09:35:46 +12:00
Olly Betts
64fa88c0eb [php] Omit incompatible return type declaraction
Under %feature("php:type", "compat") we don't generate return type
declaration for virtual methods if directors are enabled for that class.
However if a base class of the class has a method of the same name which
isn't directed this was still getting a return type declaration which
caused PHP to give an error when it tried to load the module.

Now we detect this situation and suppress the base class method's
return type declaration too.

Re-enable testcase director_redefined which now works again (it was
failing under PHP8 due to this issue).

See #2151
2022-07-13 16:01:59 +12:00
Olly Betts
cfc3888cba [php] Emit arginfo after all the code
Another step in preparation for a fix for the incompatible overridden
method problem discussed in #2151.
2022-07-13 15:21:12 +12:00
William S Fulton
ea193a98f3 Merge two commits from movable-types-inputs
Performance optimisation for parameters passed by value that are C++11 movable.
  Test copy constructor and assignment operator calls for movable types

Conflicts:
	CHANGES.current
2022-07-12 09:48:17 +01:00
Olly Betts
216c7f72cf Revert "Adjust the DOH string hash function"
Changing the hash function breaks some testcases.

It seems there's a latent bug here (I suspect something somewhere in
SWIG depends on the hash iteration order), but I didn't see where and
we can't really have CI continuing to fail.

See #2303.

This reverts commit 5a96a39aa4.
2022-07-12 12:51:48 +12:00
Olly Betts
7cf91c12dc php: Move ME and FE generation back out of PHPTypes
It's more natural to leave it where it was, and will work better
when we delay the arginfo generation.
2022-07-11 17:38:34 +12:00
Olly Betts
6503200684 php: Encapsulate arginfo generation
Encapsulate the code to generate arginfo in the PHPTypes class.
By itself this should result in no functional changes, but it's
a step towards being able to delay arginfo generation which I
think is necessary to address the incompatible overridden
method problem discussed in #2151.
2022-07-11 17:23:20 +12:00
Olly Betts
cf9422b4d9 [php] Stop setting unused php:proxy attribute
This is no longer used since we changed how classes are wrapped.
2022-07-11 15:32:43 +12:00
William S Fulton
e777b054d5 Performance optimisation for parameters passed by value that are C++11 movable.
The C++ wrappers create a temporary variable for a parameter to be passed to a
function. This is initially default constructed and then copy assigned from the
instance being passed in from the target language. This is unchanged, however,
when the temporary variable is passed to wrapped function, it is now done using
std::move. If the type is move constructible, the move constructor will be used
instead of the copy constructor.

Note that the implementation calls std::move for all user-defined types
(non-primitive types passed by value), this excludes anything passed by pointer,
reference and arrays. It does also include any type that has not been
defined/parsed by SWIG, that is, unknown types. std::move is called via the
SWIG_STD_MOVE macro which only calls std::move for C++11 and later code.
2022-07-08 17:41:15 +01:00
Olly Betts
22a4355f34 [xml] Move to "Experimental" target language status
The XML target language support is not in good shape and is likely to be
removed unless somebody steps up to bring it up to the expected standard
(it fails to even meet the criteria for "Experimental" currently).

Closes #2213
2022-07-08 16:34:19 +12:00
Olly Betts
04abbcf4ae Turn an unmatched ]] back into two ]
Needed to handle e.g. `a[a[0]]`.  SWIG's parser doesn't seem to handle
that currently though.  See #2286.
2022-07-08 15:50:51 +12:00
Julien Marrec
d3759a9b36 Avoid parse errors for C++ attributes
Just ignore anything in between [[ and ]] in the scanner, which is better
that failing with a parse error.

Fixes #1158
Fixes #2286
2022-07-08 15:27:02 +12:00
Olly Betts
5a96a39aa4 Adjust the DOH string hash function
The one we're currently using only considers the last five characters
plus the least significant bit of the last-but-sixth character, which
unsurprisingly generates a lot of many-way collisions.

This change seems to give about a 4% reduction in wallclock time for
processing li_std_list_wrap.i from the testsuite for Python.  The
hash collision rate for this example drops from 39% to 0!

Closes #2303
2022-07-07 11:50:00 +12:00
Ian Lance Taylor
87cbf8c341 [Go] #2245 Handle NULL pointers for string* conversions.
Rearrange generation of director methods and rename
receiver argument from p to swig_p.

Fixes #2245
2022-07-05 17:00:48 -07:00
Olly Betts
f5e2d044df Remove set but not used variables
Highlighted by clang-15 warnings such as:

warning: variable 'index' set but not used [-Wunused-but-set-variable]
2022-06-30 12:52:37 +12:00
Olly Betts
6c4010e442 Resolve -Wstrict-prototypes warnings with clang-15
warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
2022-06-30 12:52:00 +12:00
Olly Betts
9cdf46e8c8 [php] Adjust #required params for subclass methods
If the same method name is implemented in a parent class then the
subclass can't have more required parameters than that or else we
get a compatibility error when the module is loaded.

The testsuite wasn't catching this problem because it was no longer
trying to load the modules for testcases without _runme.php, because
the mechanism to do that relied on there being a generated .php
wrapper, which we no longer have by default.  Fix that to provide a
regression test for this fix.

See #2151
2022-06-14 16:00:46 +12:00
Olly Betts
c95df57976 [php] Fix missing parameter type declarations
In some cases of overloaded functions the parameter type information was
missing for some or all parameters.

See #2151
2022-06-12 09:22:27 +12:00
Olly Betts
2df27036b7 [php] Skip directorout typemap if PHP exception pending
Otherwise can end up with a second PHP exception if the directorout
typemap doesn't accept PHP Null.  `SWIG_fail` in this case results
in us returning to PHP which then propagates the pending exception.

This commit fixes a failure in smoketest.php in Xapian's PHP bindings,
but I've not managed to come up with a reproducer which works for
SWIG's testsuite.
2022-06-10 16:01:05 +12:00