Commit Graph

181 Commits

Author SHA1 Message Date
William S Fulton 22a8088a98 Fix -Wunused-variable warning in Lua and Octave wrappers
Add bool output parameter to Swig_overload_dispatch to say when it has
generated code that will use the typecheck typemap code to help Lua and
Octave to not emit unused argv[] arrays.

Alas, resorted to warning suppression for deficient cpp11_initializer_list
typecheck typemap in cpp11_std_initializer_list testcase.
2025-06-23 21:39:49 +01:00
William S Fulton 86498e46c6 Remove -xmllang option used with -xml
which had no effect on the output.
2024-10-15 08:59:51 +01:00
William S Fulton 09001ee302 Add $isvoid special variable expansion for directors
Complete the removal of Ruby's output_helper macro and replacement
with SWIG_AppendOutput for director typemaps.
Requires $isvoid special variable support in director code.
2024-10-06 15:00:37 +01:00
Olly Betts 7a8c9fdfa8 Straighten out handling of char and string constants
Fixes #904
Fixes #1907
Fixes #2579
Fixes #2990
2024-08-17 16:12:45 +12:00
William S Fulton 2c70a912a6 Add $isvoid special variable
The $isvoid special variable expands to 1 if the
wrapped function has a void return, otherwise expands to 0.

In the implementation, use a consistent variable name, returntype,
for a node's "type" attribute.

Issue #2907
2024-06-15 23:13:12 +01:00
Olly Betts 0c7459e6b6 [ocaml] Strip out SWIG copies of ocaml macros
These were only needed because of the "value" macro hack.
2024-02-23 11:16:47 +13:00
Olly Betts b2eaefdde9 [ocaml] Strip out the value macro typedef hack
It's far from ideal that ocaml's C API uses a common term like "value"
as a typedef as it can clash with uses of "value" as an identifier in
the C/C++ API being wrapped, but that's not a problem that SWIG created
or really is able to solve.

Previously SWIG would try to rename "value" inside ocaml's headers
by defining it as a macro before including them and then undefining it
afterwards.  However this doesn't work for uses of "value" in macros
defined in the ocaml headers for use in code using the ocaml C API.
This lead to SWIG trying to have tweaked copies to replace all such
macros, which have inevitably diverged from those defined by ocaml;
also SWIG lacks replacements for more recently introduced macros.
2024-02-23 11:16:01 +13:00
Olly Betts c9ec14efad [Ocaml] Remove deprecated -suffix command line option
This option has emitted a deprecation warning since SWIG 3.0.4 - if you
want to specify a different filename extension for generated C++ files
use -cppext instead, which works for all SWIG target language backends.
2023-12-04 15:50:43 +13:00
William S Fulton c0b36721a3 Replace Language::is_assignable with Language::is_immutable
Avoids confusion with newly created Allocate::is_assignable.
Language::is_immutable is just a wrapper around the
"feature:immutable" flag since previous commit.

is_mutable rename wip
2023-09-07 07:01:37 +01:00
William S Fulton abd299c6f4 Guile, Ocaml, Perl - add missing use of is_assignment() for variable wrappers
Don't attempt to generate a setter when wrapping
variables which have a private assignment operator as assignment is not
possible. This now matches the behaviour of all the other target languages.
2023-09-03 17:55:36 +01:00
William S Fulton 84542f6b59 Replace Language::directorsEnabled() with Swig_directors_enabled()
For use outside of the target languages for forthcoming commits
which move adding default constructors/destructors from Language
to Allocate.
2023-07-12 18:44:42 +01:00
Olly Betts 736c052d7d Remove long deprecated features
These features were all deprecated in 1.3.26 (October 9, 2005)
or before (many long before), so all more than 17 years and 3 new major
versions ago which seems more than enough time for users to have stopped
using them, especially as most emit a deprecation warning if used.
2023-06-15 15:05:15 +12:00
William S Fulton c5e02bf327 Ocaml name mangling fix
Fixes testcase template_expr which was resulting in OCaml syntax errors.
2022-11-29 08:04:37 +00:00
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