Commit graph

168 commits

Author SHA1 Message Date
William S Fulton
46f7501d94 Cleanup SWIG_VERSION definition
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.

Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this

Closes #1050
2022-10-13 19:47:43 +01:00
William S Fulton
0239ba5536 OCaml director return fix
Fixes director_unwrap_result testcase when returning Element *const *&
2022-10-10 18:55:37 +01:00
Olly Betts
631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
William S Fulton
76f5670fa4 Fix OCaml %rename for enum items 2022-10-05 22:42:17 +01: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
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
Olly Betts
735732d721 Eliminate calls to abort()
Call Exit(EXIT_FAILURE) instead so that output files get removed.
2022-03-06 14:21:06 +13:00
Olly Betts
55377bdc08 Add DOH Exit() and SetExitHandler()
Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.

This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.

This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).

Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms.  Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.

Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
2022-03-06 12:33:54 +13:00
Olly Betts
9d7c962ee8 Clean up uses of Replace()
We were passing flags of DOH_REPLACE_ANY|DOH_REPLACE_FIRST in three
places, which doesn't make sense as those are mutually exclusive
concepts.  In the current implementation DOH_REPLACE_FIRST wins in
this situation, so replace with that and clarify the docs.
2022-02-06 09:59:30 +13:00
Olly Betts
9ddc9dceb7 Remove support for $source and $target
These were officially deprecated in 2001, and attempts to use them have
resulted in a warning (including a pointer to what to update them to)
for most if not all of that time.

Fixes #1984
2021-04-30 10:20:14 +12:00
Zackery Spytz
02862fb278 [OCaml] Fix compilation errors with OCaml 4.09.0
caml_named_value() was modified to return a const value* in OCaml
4.09.0.

Closes #1686.
2019-12-29 22:41:43 -07:00
William S Fulton
b58995c89e $arg and $input were incorrectly substituted in the argout typemap
when two or more arguments were present.

Closes #1559
2019-06-28 08:09:47 +01:00
Zackery Spytz
2f48bec666 Merge remote-tracking branch 'upstream/master' into OCaml-INPUT-OUTPUT-INOUT-primitives 2019-05-08 14:05:02 -06:00
Zackery Spytz
17d0610d00 [OCaml] Fix possible memory leaks in generated dispatch functions
All paths now free argv.
2019-02-23 04:05:03 -07:00
Zackery Spytz
b74b2189e6 [OCaml] Rename ocaml.swg to ocamlrun.swg
Rename ocamldec.swg to ocamlrundec.swg.
2019-02-18 22:35:55 -07:00
Zackery Spytz
071803f000 [OCaml] Fix segfaults when too few arguments are passed to a function
Prevent segfaults when too few arguments are passed to a function.

Length checks are not needed for the wrappers of overloaded
functions -- the generated dispatch function already checks.

Add default_args_runme.ml.

Fix minor errors in some runtime tests.  Extra args were being passed
in some cases.
2019-02-15 01:17:15 -07:00
William S Fulton
9ab873f432 Merge branch 'ZackerySpytz-OCaml-classDirectorMethod-CAMLreturn'
* ZackerySpytz-OCaml-classDirectorMethod-CAMLreturn:
  [OCaml] Fix possible GC issues in generated director code

 Conflicts:
	Examples/test-suite/ocaml/director_unroll_runme.ml
2019-02-09 22:54:43 +00:00
William S Fulton
d7bb500315 Merge branch 'ZackerySpytz-OCaml-director-ctors'
* ZackerySpytz-OCaml-director-ctors:
  [OCaml] Fix a bug in the ctors of director classes
2019-02-09 22:28:10 +00:00
William S Fulton
d595a7a9ed Merge branch 'ZackerySpytz-OCaml-cache-caml_named_value'
* ZackerySpytz-OCaml-cache-caml_named_value:
  [OCaml] Cache the result of caml_named_value() in some cases
2019-02-09 22:14:10 +00:00
Zackery Spytz
28a846705f [OCaml] Fix possible GC issues in generated director code
Make `classDirectorMethod()` generate `CAMLreturn_type()` or
`CAMLreturn0` when there are local variables of type `value`.
2019-02-07 22:08:10 -07:00
Zackery Spytz
828ce477c8 [OCaml] Fix a bug in the ctors of director classes
If a class was given the director feature, it was not possible
to use ctors with multiple parameters.

Add director_default_runme.ml (it is based on
director_default_runme.java).
2019-02-05 13:35:43 -07:00
Zackery Spytz
bdc038b578 [OCaml] Cache the result of caml_named_value() in some cases
The result of caml_named_value() can be cached for (slightly)
improved performance.

This is mentioned in the OCaml reference manual.
https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec453

In addition, fix incorrect use of CAMLreturn() in
caml_ptr_val_internal().
2019-02-03 17:37:46 -07:00
Zackery Spytz
08029e6642 [OCaml] Add support for the docstring option in the module directive
If given, the OCaml module will place the docstring at the very
beginning of the generated mli file, where it can be read by the
OCamldoc tool.

The implementation is based on the equivalent features in the Python
and Ruby modules.
2019-01-31 15:32:38 -07:00
William S Fulton
528f33e9e5 Merge branch 'ZackerySpytz-OCaml-eliminate-wno-write-strings'
* ZackerySpytz-OCaml-eliminate-wno-write-strings:
  [OCaml] Remove support for OCaml versions < 3.12.0
  [OCaml] Fix toplevel creation for ocamlmktop versions >= 4.04.0
  [OCaml] Eliminate use of -Wno-write-strings
2019-01-31 07:29:09 +00:00
William S Fulton
526b2cf0ae Merge branch 'ZackerySpytz-OCaml-director-classes-throw'
* ZackerySpytz-OCaml-director-classes-throw:
  [OCaml] Fix handling of exception specifications for director classes
2019-01-31 07:21:50 +00:00
William S Fulton
c6d2c7703e Merge branch 'ZackerySpytz-OCaml-overloaded-duplicates'
* ZackerySpytz-OCaml-overloaded-duplicates:
  [OCaml] Don't generate duplicate declarations for overloaded functions
2019-01-31 07:18:22 +00:00
Zackery Spytz
35663b1622 [OCaml] Fix handling of exception specifications for director classes
The OCaml module was generating invalid code for director classes
which contain methods with exception specifications. The fix is based
on some of the code in python.cxx's classDirectorMethod().

This commit fixes compilation failures for a number of director unit
tests.

Add director_exception_catches_runme.ml,
director_exception_nothrow_runme.ml, and director_ignore_runme.ml.
2019-01-26 05:58:38 -07:00
Zackery Spytz
f1a29ef6ec [OCaml] Don't generate duplicate declarations for overloaded functions
The OCaml module was generating duplicate declarations in the ml
and mli files for overloaded functions.  For every wrapper function
created for an overloaded function, it would generate a duplicate of
the dispatch function in the ml and mli files.

In addition, add the SWIG banner to generated ml and mli files.
2019-01-25 08:45:59 -07:00
Zackery Spytz
4ca7cd7b27 [OCaml] Eliminate use of -Wno-write-strings
Don't convert string literals to char * in the strings_test example.

In constantWrapper(), use SwigType_str() instead of SwigType_lstr()
in order to keep const qualifiers.
2019-01-24 05:32:35 -07:00
Zackery Spytz
4074f788b3 [OCaml] Fix %allowexception
OCaml's variableWrapper() wasn't calling emit_action_code() for
in/out typemaps, which meant that %allowexception was being ignored.

In addition, remove all comments in the typemaps in Lib/ocaml. In the
case of the allowexcept test, one of the typemap comments caused
compilation to fail because it became nested within another comment
in an %exception block.

Re-enable the allowexcept test.
Add allowexcept_runme.ml.
2019-01-22 07:51:45 -07:00
William S Fulton
65cab79071 Merge branch 'ZackerySpytz-OCaml-dead-code-overloaded-funcs'
* ZackerySpytz-OCaml-dead-code-overloaded-funcs:
  [OCaml] Fix dead code generation in overloaded function wrappers
2019-01-19 23:03:07 +00:00
Zackery Spytz
b3f903722b [OCaml] Improve the error message for incorrect overloaded function calls
List the possible prototypes in the error message. The code was taken
from python.cxx's dispatchFunction().
2019-01-16 23:08:12 -07:00
Zackery Spytz
fa1a0a378c [OCaml] Fix dead code generation in overloaded function wrappers
The OCaml module was generating dead code in the wrappers for
overloaded functions. Only the generated dispatch function needs to
allocate an array for the passed arguments.

In addition, add overload_extend, overload_rename and overload_subtype
runtime tests.
2019-01-16 20:00:40 -07:00
William S Fulton
32a8cd8f2f Merge branch 'ZackerySpytz-OCaml-constant-char-wrapping'
* ZackerySpytz-OCaml-constant-char-wrapping:
  [OCaml] Fix the wrapping of static const member chars
2019-01-16 21:46:57 +00:00
Zackery Spytz
c61c221057 [OCaml] Fix the wrapping of static const member chars
OCaml's constantWrapper() was adding unneeded quotes when wrapping
static const member chars.

Add runtime tests for char_constant, chartest, and
static_const_member.
2019-01-15 16:37:26 -07:00
Zackery Spytz
05589508a6 [OCaml] Add the caml_ prefix to some OCaml functions
In OCaml 3.08.0, many functions in the OCaml C API were renamed to
include a caml_ prefix. Their previous names were retained as macros
in caml/compatibility.h and were (apparently) deprecated.

Rename occurrences of alloc_string, alloc_tuple, callback, callback2,
callback3, copy_double, copy_int64, copy_string, failwith, and modify
in the OCaml module.

The OCaml module requires OCaml >= 3.08.3, so this change is safe
for all supported OCaml versions.
2019-01-14 20:45:13 -07:00
William S Fulton
b64d685d5f Merge branch 'ZackerySpytz-OCaml-fix-member-var-access'
* ZackerySpytz-OCaml-fix-member-var-access:
  OCaml's classHandler() requires name, not sym:name.
  [OCaml] Fix member var getters and setters
2019-01-11 18:42:19 +00:00
Zackery Spytz
4ca6fdc551 OCaml's classHandler() requires name, not sym:name.
In classHandler(), assign sym:name to the classname global so that it
can be used in membervariableHandler().

Add a small runme test for li_std_vector.
Use swigp4 when compiling the runme tests.
2019-01-08 20:10:07 -07:00
Zackery Spytz
4a912668fc [OCaml] Fix member var getters and setters
Add `membervariableHandler()` to the `OCAML` class in ocaml.cxx (it is
partly based on the code in python.cxx and octave.cxx).

In Lib/ocaml/class.swg, wrapped classes/structs were not being added
to `class_master_list`. This is fixed by adding a call to
`register_class_byname`.

Add a unit test in the form of struct_value_runme.ml.
2019-01-06 09:40:25 -07:00
Zackery Spytz
fe85dd22d8 [OCaml] Don't generate unused _v variables 2019-01-05 11:17:06 -07:00
Olly Betts
d721b4d639 Fix comment typo "aruments" 2018-05-29 09:00:18 +12: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
ebd37155a8 Fix potential use of uninitialized variables in directors 2017-05-13 22:40:59 +01:00
William S Fulton
08688d7d9d Add support for "ret" typemap where missing and improve documentation on it. 2016-09-29 08:07:26 +01:00
William S Fulton
1d62790928 Fix assertion for some languages when wrapping a C++11 enum class that is private in a class.
Also don't wrap private enums for a few languages that attempted to do so.

Closes #594.
2016-03-31 20:27:36 +01:00
Petre Eftime
0a07cd4c30 Prevent redefinition warnings when compiling with SWIG<module> defined
Signed-off-by: Petre Eftime <petre.p.eftime@intel.com>
2015-12-22 14:33:21 +02:00
William S Fulton
edcdaaec16 Warning fixes for 64bit visual c++ on Windows 2015-07-03 20:59:24 +01:00
Olly Betts
01d0ee86e0 Fix C&P references to Python in comments 2015-03-27 12:40:42 +13:00
Olly Betts
7ba0652677 Create director_common.swg for language-indep code
Move -DSWIG_DIRECTOR_STATIC handling there, so this is now supported for
all languages with director support, not just Python and PHP.
2015-03-12 19:51:11 +13:00