Commit graph

146 commits

Author SHA1 Message Date
Vadim Zeitlin
61e13eb42b Get rid of useless IS_SET_TO_ONE macro
Just use the standard GetFlag() instead.
2019-08-04 14:59:48 +02:00
Vadim Zeitlin
d1f8d46528 Fix some very wrongly indented lines and "else" style
Consistently put "else" on the same line as closing "}" from the
matching "if", if any.

No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
92c922c841 Remove trailing whitespace
No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
0599b77377 Remove useless overridden extendDirective()
There is no need to override it just to call the base class version.

Also remove the outdated comment, as %extend is supported currently
(albeit with some bugs remaining).

No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
7bef0b704d Remove unnecessary "virtual" keywords
Don't mark functions not intended to be overridden (nor overriding those
in the base class) as "virtual", this is useless and confusing.

No real changes.
2019-08-04 14:57:08 +02:00
Vadim Zeitlin
83e9d50763 Remove unused C::int_string field
This was simply never used at all.
2019-08-04 14:43:02 +02:00
Vadim Zeitlin
290f49a2c1 Remove unused C::tl_namespace member
This was never set to anything, so just drop it.
2019-08-04 14:41:29 +02:00
Vadim Zeitlin
d9b3453763 Add missing SWIGIMPORT to function declarations
This went unnoticed under Linux, but would have resulted in link errors
for all functions under MSW.
2019-08-04 14:33:34 +02:00
Vadim Zeitlin
b4d08c1787 Get rid of special ctor/dtor handling in C module
By delegating to the base class instead we not only save quite a few
lines of code, but gain support for ctors/dtors defined using %extend,
which didn't work before, allowing to reenable some of the previously
failing tests.
2019-08-04 02:22:16 +02:00
Vadim Zeitlin
bbac8ca521 Don't reimplement base class version of globalfunctionHandler()
This is useless and the C-specific version didn't handle template
methods added with %extend correctly, so removing this code also fixes
some (but not all yet) failures in extend_template_method.cpptest unit
test.
2019-08-03 14:40:09 +02:00
Vadim Zeitlin
b0d99a1cc3 Don't emit functions added by %extend into C structs
This is never going to work and just results in generating uncompilable
code.

In principle, we could either generate wrappers for these functions
while still handling the struct as a plain C struct, or switch to
generating class-like wrappers for it if it's %extended with any
functions, but for now just ignore them as this is the simplest thing to
do.

Incidentally, this makes the default_args_c test pass again now, after
the last merge with master pulled in such %extend directives into it.
2019-08-03 02:37:18 +02:00
Vadim Zeitlin
9204e57cc1 Fix $typemap() expansion for "ctype" typemap
This didn't work correctly before because we need to override the base class
replaceSpecialVariables() method to expand $resolved_type, which appears
during the expansion, using the type supplied as $typemap() argument instead
of doing it later using it the type to which the typemap containing the macro
is attached.

This is a prerequisite for implementing smart pointers support.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
2f4eb2d412 Replace output_target parameter with global current_output
This will allow implementing replaceSpecialVariables(): as it is called from
inside the typemap lookup code, we can't pass any parameters to it directly,
but we can use a class language-global member variable to it indirectly.

No real changes yet.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
dcda566ce6 Remove unnecessary memory allocation from substituteResolvedType()
Don't allocate memory just to leak it, SwigType_typedef_resolve_all() already
returns a copy we can use.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
bf71891197 Just get rid of an unnecessary variable
Simplify the code by avoiding a superfluous extra variable.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
0353317a21 Remove substituteResolvedType() return value as it is unused
It doesn't matter if this function did anything or not as its output parameter
is always used anyhow by the caller.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
ad5de803b5 Avoid unnecessary allocation in get_wrapper_func_return_type()
Don't call NewString() just to overwrite it with another pointer (and leak the
one allocated by NewString()).
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
11426ac1cd Drop code dealing with tmap:ctype:out which is never used
This typemap attribute is not used with C (so far), there is no point in
checking for it in the code.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
6e0e728a14 Refactor node copying in C::classHandler()
Don't create a new node just to delete it if we don't need it, but rather only
create it if we do need it.

Also copy as much as can be copied in copy_node() helper, it was confusing to
copy part of the attributes in it and part in the caller. And one of them
("c:inherited_from") was even copied twice, it was first created in the
function and then unconditionally overwritten by the caller -- don't do this
any more.

No real changes.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
2ce15d3e6a Don't leak a Node in C::classHandler()
Delete the copied node if we end up not using it.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
65d9cad1ca Don't force inheritance of ignored methods
If a symbol is ignored in the base class, it shouldn't appear in the derived
class neither.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
8eba14c6e0 Resolve typedefs in parameter types after applying ctype typemap
Typedefs were not resolved for non-object types in spite of
SwigType_typedef_resolve_all() call as it didn't affect "c_parm_type".

Actually it is not even clear if resolving typedefs is a good idea as using
them probably makes the generated code more clear, but at least in the case of
nested typedefs we do need to do it as "Class::Type" can't appear in C code.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
8fa28e0ce9 Don't lose the correct sym:name when inheriting base class methods
For some reason, the copy of the function made in the derived class used the
"name" attribute instead of "sym:name", which means that any %renames attached
to it were lost and didn't affect the derived class version.

Fix this and also a problem uncovered by doing it in the operator_overload
unit test as the assignment operator shouldn't be inherited at all, the
compiler-generated operator is used instead if the derived class doesn't
define its own one.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
0c936d9089 Simplify and inline functionWrapperAddCPPResult()
This function seemed to be doing a few unnecessary things, e.g. it resolved
the typedefs which doesn't seem to be necessary and the test for member
pointer seems to be useless too.

Just add a local "cppresult" directly in the caller instead of using a
separate function to do all this.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
d3412499bb Use the original function name in C code wrappers
Using "sym:name" in the wrapping code is wrong, it is different from "name" if
the function has been renamed and we need to call the original C function, not
whichever name it is exported under.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
10d25c7327 Drop longjmp-based exception handling approach
Using longjmp was incompatible with using C++ objects in the code using the
wrappers, and using this C API from C++ to avoid ABI incompatibilities between
different C++ compilers is one of the main reasons for using this module.

Also, this required using a separate SwigObj instead of just using the real
object pointer which inevitably resulted in memory leaks whenever a non owned
object was returned from anywhere, e.g. from a member accessor or any method
returning pointer or reference.

Abandon the attempts to recreate C++ exceptions in C and just use a very
simple approach allowing to pass an error message out of band after any
function call in a global variable. An alternative could be to add a special
"out" error parameter to each and every function, but this risked being too
verbose, especially for the functions which don't really throw, and the calls
to SWIG_PendingException_get() won't need to be made explicitly when using a
C++ wrapper around the generated C API in the future.

This simplifies both the module and the generated code, in particular we don't
need any runtime code at all any more and there is no need for an extra level
of indirection for every object.

It also makes a couple more tests pass.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
bda731cd8f Change naming convention for wrapped ctors and dtor
Use Foo_{new,delete}() instead of {new,delete}_Foo() to ensure that all
methods of the class Foo start with the corresponding prefix.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
b24665fa6a Add names of the functions being wrapped to symbol table
At the very least this results in clear error messages when running SWIG if
the symbol is encountered twice instead of errors given only when compiling
the generated code later.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
7f4549a0f3 Ensure that we define bool before using it for variables
It would have been better to hook into the fragment machinery, but for now do
it directly to make sure the generated code compiles.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
5fd1f28477 Do not export static global variables at all
They shouldn't be exported and can't be when using shared libraries.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
97fc60ef51 Get rid of c:objstruct attribute
The only remaining use of this attribute is to test for whether we're wrapping
a ctor and it is simpler and more clear to just check the node type directly
in this case.

This attribute was pretty confusing as it was used for parameters and entire
declarations, so removing it makes things more clear and simpler.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
0480694a7a Remove the now unused functionWrapperCPPSpecificMarkFirstParam()
There is no need to set c:objstruct for the first parameter of the methods now
that we take care of it for disambiguating between overloads explicitly and
this function doesn't seem to be useful for anything else, simply drop it.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
8e30abf7ab Don't use "this" method parameter for disambiguating overloads
When building the unique suffix for each member of the overloaded functions
set, don't use the first "this" parameter of the object methods in it as it's
the same for all of them and so is completely useless for disambiguation
purposes and just results in unnecessarily long and ugly names.

Use "_const" suffix for the methods differing by their const-ness only, this
is necessary now that we don't use "_pFoo" or "_pcFoo" in their names.

This makes it superfluous to check for c:objstruct in
functionWrapperAppendOverloaded() (and checking for it there was not enough
neither, as the changes in the test suite show, sometimes the "this" parameter
type still found its way into the generated wrappers).
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
e068aa8cc9 Simplify ctors/dtor handling by reusing base class code
Just use our custom object creation/destruction code, but let the base class
do everything else.

This uncovered complete lack of support for ctors/dtors defined using %extend,
but this is not new and will have to remain broken for now.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
2e3b427b7e Get rid of unnecessary and confusing c:stype attribute
We can just use "type" directly, there is no need for any C-specific stype.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
2c65b4db5b Remove obsolete RCS ID line
No real changes.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
02c52331cd Return scoped_dohptr from get_wrapper_func_proto()
This ensures that the pointer is not leaked.

Unfortunately it requires adding a dangerous, std::auto_ptr<>-like destructive
copy ctor to scoped_dohptr<>, but there is no better solution without C++11.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
e2738ad524 Refactor: add parentheses in get_wrapper_func_proto() itself
Return the prototype strings already surrounded by parentheses instead of
having to add them in the caller.

No real changes.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
c971919e2f Merge almost identical code generating wrapper function arguments
Reuse get_wrapper_func_proto() for the wrapper function definitions too, this
cuts down on the amount of duplicated code and also ensures that declarations
and definitions match.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
00ef2c4c7d Remove unused functionWrapperCPPSpecificProxyWrapperCallGet()
This is identical to the main part of functionWrapperCPPSpecificWrapper() now
and it is not used anywhere.
2016-04-21 18:58:33 +02:00
Vadim Zeitlin
8cae88dd39 Get rid of separate cmodtype typemap
Use the same ctype for wrapper declarations and definitions and just expand
$resolved_type differently in the two cases.

This simplifies the typemaps and ensures that the declarations and definitions
use the same types, at least for all non-object parameters.
2016-04-21 18:58:32 +02:00
Vadim Zeitlin
806f79de14 No real changes, just rename "proxy_header" to "cheader"
Continue getting rid of "proxy" terminology, there is no proxy when using C
module, so it's confusing to use this term.
2016-04-21 15:18:22 +02:00
Vadim Zeitlin
e2bb89ccb3 Replace unknown enums with int in the wrappers
An enum can be declared outside of the code wrapped by SWIG, just use int
instead of it then.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
41d46460b8 Add helper scoped_dohptr class
This is useful for avoiding having to explicitly write Delete() calls for DOH
objects.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
113ce5ae7d Add a blank line to the generated code
This is purely cosmetic: add an extra blank line after the __cplusplus ifdef
end.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
4b5e5d0cc8 Allow to use the original name of the global functions
It is impossible to have two functions with the same name inside the same
program, but it is possible to provide a #define to allow the user code to use
the original function name for the wrapper function, so do it for convenience.

Remove the old changes adding explicit "_wrap_" prefix to the examples and the
tests and remove the few more now passing tests from the list of failing tests.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
36fdd4e78f Wrap unknown type as opaque pointers
Don't give errors for the unknown types, instead wrap them using the mangled
name of the type.

This is the expected (even if not particularly useful) SWIG behaviour and
allows many more tests to pass.
2016-04-21 01:37:42 +02:00
Vadim Zeitlin
d9feedc37a Remove unnecessary SwigType_typedef_resolve_all() call
No real changes, just don't bother calling SwigType_typedef_resolve_all()
before calling classLookup() because the latter already does it anyhow.
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
2ec9d9da6e Don't try to export variables in namespace scope directly
The generated code, which used C++ scope operator "::" in a C header, didn't
compile and couldn't work anyhow.

Just use the accessor functions for not really global variables.
2016-04-21 01:37:41 +02:00
Vadim Zeitlin
e39265ba13 Handle primitive types when expanding "resolved_type" in typemaps
Although the default typemaps only use "resolved_type" for non-simple types,
the generic SWIGTYPE typemap can also be applied explicitly to other types as
"apply_strings" and "char_binary" unit tests do.

In this case just use the original type unchanged if we can, this is enough to
make these tests pass.
2016-04-21 01:37:41 +02:00