Commit graph

5,438 commits

Author SHA1 Message Date
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
Olly Betts
2de2efb0bb Fix PHP parameter type declarations compatibility
Ensure PHP parameter type declarations are compatible with those for
the same method in any classes we inherit from.

See #2151
2022-06-10 11:12:54 +12:00
Olly Betts
d43d62cd7a Revert "Fix PHP parameter type declarations compatibility"
I missed that this change breaks cpp_static, which seems to be to do
with handling the combined getter and setter we emit for static
member variables.  Reverting while I figure out how to handle that.

This reverts commit a277748870.
2022-06-09 17:55:09 +12:00
Olly Betts
a277748870 Fix PHP parameter type declarations compatibility
Ensure PHP parameter type declarations are compatible with those for
the same method in any classes we inherit from.

See #2151
2022-06-09 17:36:11 +12:00
Olly Betts
a8994d4186 Rename zend_types to be clearer
It's actually tracking pointer types which aren't wrapped as classes.
2022-06-09 12:49:30 +12:00
Olly Betts
d7ed1a8b97 [php] Eliminate sprintf to temp buffer to create ZVAL
Use zend_strpprintf() which handles this more cleanly without risk of
buffer overflow and without a fixed length limit.
2022-06-09 09:06:12 +12:00
Olly Betts
97a109ecc9 WIP: Refactor pararent class tracking 2022-06-08 17:41:00 +12:00
Seth R Johnson
6254de05ef Avoid emitting locals duiring keyword typemap lookup 2022-06-04 14:19:15 +01:00
Seth R Johnson
5afc813842 Fix whitespace and memory leak 2022-06-04 13:55:24 +01:00
William S Fulton
da40946aaa Merge branch 'typemap-colon'
* typemap-colon:
  Incoporate review suggestions
  Allow referencing of typemap keywords inside of "$typemap("
2022-06-01 07:57:01 +01:00
William S Fulton
34c219b5f7 Merge branch 'imfunc'
* imfunc:
  Add special variable imfuncname expansion for C# and D
  Test and document imfuncname special variable expansion
  Update docs.
  Also expose  in proxyClassFunctionHandler
  Expose  to javaout typemaps.

Conflicts:
	CHANGES.current
2022-05-30 19:45:28 +01:00
William S Fulton
954f29b032 Add special variable imfuncname expansion for C# and D
Same functionality as Java
2022-05-30 19:43:04 +01:00
William S Fulton
b4cc35ddbc Merge branch 'csharp-strenghten-overload-check'
* csharp-strenghten-overload-check:
  Fix expanded director_basic test.
  Improve correctness of SwigDerivedClassHasMethod() by making sure only methods that have `override` are used connected by director.
2022-05-26 08:23:18 +01:00
William S Fulton
6939d91e4c Header file tidyup
Fix Visual C++ warning in scilab.cxx:
  warning C4996: 'strtok': This function or variable may be unsafe.
2022-05-07 11:56:06 +01:00
William S Fulton
69dba70319 Visual C++ warning fix 2022-05-07 11:56:06 +01:00
William S Fulton
07a9eece10
Merge pull request #2264 from KrisThielemans/tp_vectorcall_offset_Slot
[Python] Replace tp_print with tp_vectorcall_offset slot from Python 3.8
2022-05-06 20:04:11 +01:00
William S Fulton
ed42422d1c Add support for wchar_t * and std::wstring Unicode strings on Linux
Initial contributions for Linux provided in issue #1233, modified to work
on both Windows and Linux. Dual support is possible by detecting
the sizeof wchar_t which is different on each of these systems.
2022-05-02 21:08:19 +01:00
Kris Thielemans
f5934b099b [Python] Replace tp_print with tp_vectorcall_offset slot for Python 3.8
The tp_print slot is no longer supported and replaced with tp_vectorcall_offset.
The (printfunc) cast that we used caused problems on PyPy.

Fixes #2262
2022-04-21 12:28:54 +01:00
Corey Minyard
fb4c69b4b0 [Go] Add missing newlines for goin typemaps
In some cases the \n was missing from goin directives in some places.
Without this change, you will get

}	swig_r = (int)(C....

in the output in some cases, and that won't compile in Go, it will
error with:

  ../gensio/gensio.go:1508:3: expected ';', found swig_r

It only did this on director callbacks with godirectorin, and only if
the virtual function wasn't assigned to zero.  So the following will
fail:

    class callbacks {
    public:
        virtual bool call1(int v, const char * const *strarray);
        virtual ~callbacks() = default;
    };

but the following won't:

    class callbacks {
    public:
        virtual bool call1(int v, const char * const *strarray) = 0;
        virtual ~callbacks() = default;
    };

Add "\n" to the proper places to fix this.
2022-04-16 16:10:32 -05:00
luz paz
c8bec18554 Fix various typos
Found via `codespell -q 3 -L ans,anumber,ba,bae,chello,clos,cmo,coo,dout,fo,funktion,goin,inout,methid,nd,nin,nnumber,object,objekt,od,ois,packag,parm,parms,pres,statics,strack,struc,tempdate,te,thru,uint,upto,writen`
2022-04-11 07:59:36 +12:00
Olly Betts
1aeaa2a644 Recognise and ignore Doxygen group commands @{ and @}
Fixes #1750
2022-04-07 12:05:54 +12:00
Olly Betts
779d5cf57a Remove bogus parser grammar rule for unary &&
This appears to have been accidentally added in
d8cc75946b as part of the changes to
support C++11 rvalue references, presumably to match the existing
correct rule for unary &.

There is a non-standard GCC extension for taking the address of a label
using unary &&:

https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

However this extension only works in an expression in a function body,
and SWIG doesn't parse the contents of function bodies so this grammar
rule isn't even providing any useful support for this extension.
2022-04-07 12:01:40 +12:00