Commit Graph

175 Commits

Author SHA1 Message Date
William S Fulton bbdec1f77b Beautify using swig specific .clang-format
Cosmetic whitespace only change

Closes #3312

This commit is the result of running the following bash commands:

1. Remove tabs at start of source files

files=$(find Source -name "*.cxx" -o -name "*.h" -o -name "*.c")
for file in $files ; do
    printf "Processing $file\n"
    expand --initial $file > $file.tmp
    cp $file.tmp $file
done

2. Remove trailing whitespace in source

files=$(find Source -name "*.cxx" -o -name "*.h" -o -name "*.c")
for file in $files ; do
    printf "Processing $file\n"
    sed -i s/[[:space:]]*$// $file
done

3. Convert remaining tabs to spaces

files=$(find Source -name "*.cxx" -o -name "*.h" -o -name "*.c")
for file in $files ; do
        printf "Processing $file\n"
        expand $file > $file.tmp
        mv -f $file.tmp $file
done

4. Finally use clang-format with the newly added .clang-format file

files=$(find Source -name "*.cxx" -o -name "*.h" -o -name "*.c")
for file in $files ; do
    printf "Processing $file\n"
    clang-format -i $file
done
2026-03-04 21:53:30 +00:00
Olly Betts 30030583da Improve handling of zero bytes in input files
This is certainly a corner case, but GCC and clang both accept zero
bytes at least in comments, and SWIG's current handling is to ignore
the zero byte and all following characters up to and including the next
newline, so for example if a // comment contains a zero byte SWIG would
quietly ignore the next line.

Closes #3010
2024-09-03 10:14:01 +12:00
Olly Betts 4231b9d60d Allow unmatched ' and " in #error and #warning
Fixes #657
2024-08-12 16:55:44 +12:00
Olly Betts 99df7a085d Minor optimisation to macro replacement
Replace() tells us if it did anything so we can avoid calling
strstr() first.
2024-05-21 10:52:14 +12:00
Olly Betts a7eca8b415 Support __VA_OPT__
Fixes #1574
2024-03-28 12:46:58 +13:00
Olly Betts d1303767e9 Fix preprocessor comment parsing bug
Fix preprocessor to handle C-style comment ending **/ in macro argument.
2024-03-28 10:59:32 +13:00
Olly Betts f5daf83d47 Make a load of internal functions static
None of these are prototyped, used outside of the file they are
declared in, or documented aside from comments above the function.
2024-03-28 08:53:22 +13:00
Olly Betts e2aefbfe38 Avoid temporary string object 2024-03-28 08:53:22 +13:00
Olly Betts bc651a3926 Fix elision of comma before ##__VARARGS__
We document this as supported but it seems to have not worked since
before 2009.

Fixes #2848
2024-03-25 15:10:11 +13: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
Olly Betts b94c33bd86 Fix bug in previous commit
We need to set state=1 before we jump to state 1 or else we are
still in state 30 if the code path in state 1 doesn't set state,
unlike a normal entry into state 1.  This was causing a parse
error in Lib/python/pybuffer.i.
2023-06-07 19:00:15 +12:00
Olly Betts 81bc7700d9 Fix preprocessor scanning bug
Fix preprocessor handling of a slash immediately followed by
a single quote, which wasn't getting recognised as starting a
character literal.

Fixes #2630
2023-06-07 16:52:57 +12:00
Olly Betts de1327fb15 Allow defining __cplusplus on the command line
The default value for __cplusplus is now 199711L rather than defining
it to have the value __cplusplus.

Fixes #2591
2023-05-18 12:45:31 +12:00
Olly Betts 8a9628e2b9 Use strchr/Strchr for single character searches
This can be more efficient than using strstr/Strstr with a single
character search string.

GCC is able to optimise strstr() with a single character literal
search string to strchr(), but clang doesn't, and likely no compiler
can for Strstr() (unless some sort of inter-object optimisation such
as LTO is used) since the literal string is in a different source file
to the strstr() call.
2023-05-15 16:19:17 +12:00
Olly Betts de4e3b454e Fix #ifdef and #ifndef to work inside a %define
Previously they were silently ignored in this context (but #if defined
already worked here if you need a workaround which works for older
versions).

Fixes #2183
2023-04-21 07:40:25 +12:00
Olly Betts 043bdf5677 Copy over missing parts of macro expansion code
We need to insert newlines for a multi-line macro invocation, and
we shouldn't leak memory.
2023-04-19 14:52:40 +12:00
Momtchil Momtchev d39cee1ce1 suppress a warning 2023-04-14 10:25:45 +02:00
Momtchil Momtchev 24756d1bf9 fix code readability issues 2023-04-14 09:55:29 +02:00
Momtchil Momtchev 80f23effa4 alternative, much cleaner, approach 2023-04-11 20:35:20 +02:00
William S Fulton 46f2778412 Consolidate name mangling functions
Swig_string_mangle      => Swig_name_mangle_string
Swig_name_mangle        => Swig_name_mangle_string
Swig_string_mangle_type => Swig_name_mangle_type
2022-11-12 09:18:19 +00:00
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13: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 b2c58115d7 Fix previous commit
Revert changes inadvertently included, and fix `=` to `==`.
2022-03-20 19:44:23 +13:00
Olly Betts 029ddab8b5 [ci] Try to fix failing appveyor python builds 2022-03-20 18:42:50 +13:00
Olly Betts f8a766295c Handle `)` in command line interface filename
SWIG now handles an interface filename specified on the command line
which contains a closing parenthesis `)`, and more generally with
attributes to `%include` and `%import` which are quoted and contain
parentheses.

Fixes #1006
2022-03-08 18:15:18 +13: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 74d12d8c4c Don't report "Warning 202: Error: ..."
An invalid preprocessor expression is reported as a pair of
warnings with the second giving a more detailed message from the
expression evaluator.  Previously SWIG prefixed the second message
with "Error:" - that was confusing as it's actually only a warning
by default so we've now dropped this prefix.

Before:

x.i:1: Warning 202: Could not evaluate expression '1.2'
x.i:1: Warning 202: Error: 'Floating point constant in preprocessor expression'

Now:

x.i:1: Warning 202: Could not evaluate expression '1.2'
x.i:1: Warning 202: Floating point constant in preprocessor expression

See #1465
2022-02-24 08:40:27 +13:00
William S Fulton 661cd54526 Fix -Wchar-subscripts warning
warning: array subscript has type ‘char’ [-Wchar-subscripts]
2021-04-26 22:32:52 +01:00
William S Fulton 1f46d9b7b9 Fix regression parsing gcc preprocessor linemarkers
These are preprocessor statement in the form:

 # linenum filename flags

Closes #1475
2019-02-19 21:32:04 +00:00
Luca Longinotti 30719feaf9 Fix handling of // comments inside macro arguments
/* */ are already handled correctly.

This completes the fix from commit
624ec3e1b7 related to swig/swig#974.
2018-03-07 14:49:08 +13:00
William S Fulton 72964a1faf Don't accept some invalid preprocessor code
Whitespace or non-numeric characters are required after a preprocessor
directive that requires an expression.
2018-01-16 08:07:37 +00:00
William S Fulton ab5559f51c Fix out of bounds memory problems in handling simple macro arguments
Fixes handling macro in swigmacros.swg:
  #define %arg(Arg...)        Arg

AddressSanitizer error running Python test-suite.
2018-01-14 13:25:57 +00:00
Olly Betts f85d87a64c Fix bug with macro invocation with empty first arg
The first argument was being dropped in this case.
2017-10-08 09:02:28 +13:00
Olly Betts 866840f791 Fix handling of macro with empty argument list 2017-10-08 09:02:28 +13:00
Philip Herron 624ec3e1b7 Fix bug with comments inline in macros
- commit fixes #974
2017-04-27 15:35:13 +01:00
Olly Betts 7a3cfdb013 Fix GCC 7 warnings
From -Wimplicit-fallthrough which is now enabled by -W.
2016-12-21 13:05:20 +13:00
Olly Betts d26a505dad Ignore unknown preprocessor directives which are inside an inactive
conditional (github issue #394, reported by Dan Wilcox).
Regression introduced in 3.0.3.
2015-04-30 13:40:42 +12:00
Olly Betts be4065531e Add suggestion to check block delimiter
The fix for #217 means that blocks of target code delimited by { } with
'#' comments in now give errors (previously these lines were quietly
discarded).

The fix is generally to use %{ %} delimiters instead, so suggest this
might be the issue in the error message to help users hitting this issue
with wrappers which were apparently working before.
2015-01-14 16:08:08 +13:00
Olly Betts ce90ff6a77 When reporting an error for a construct which hasn't been terminated
when the end of the file is reached, report it at the start line rather
than "EOF" as then tools like editors and IDEs will take you to a
generally more useful place for fixing the problem.
2015-01-08 13:19:17 +13:00
William S Fulton 93d58cd3ed Fix use of preprocessor null directive
This was broken recently in commit 255c929c56
for issue #217
2014-12-20 17:05:13 +00:00
Olly Betts 255c929c56 Issue an error for unknown SWIG preprocessor directives, rather
than quietly ignoring them.  Reported by jrhelsey in issue#217.
2014-09-01 00:26:15 -03:00
William S Fulton 7841a0d097 Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00
William S Fulton dac89e16d4 const char * correctness fixes (in C code)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13939 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-26 20:30:37 +00:00
William S Fulton b596ddbbc1 Correct type change from char * to String introduced in rev 13904
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13937 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-26 20:28:09 +00:00
William S Fulton d918bddfc0 Fix segfaults when using filename paths greater than 1024 characters in length - use String * and heap instead of fixed size static char array buffers.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13904 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-18 00:45:18 +00:00
William S Fulton 475c6c6ce0 Suppress some unchecked return value warnings for Coverity
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13902 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-18 00:44:19 +00:00
William S Fulton 3d6b068b8c Add some assertions around use of Tell
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13896 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-16 19:38:48 +00:00
William S Fulton e87e94572e Fix unused variables found by Coverity checker
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13892 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-16 19:33:43 +00:00
William S Fulton 425b460a09 Fix %include inside %define macros - patch from Karl Wette
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12924 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-03-15 20:32:14 +00:00
William S Fulton f5feb6cc24 Fix regression introduced in swig-2.0.2 where filenames with spaces were not found when used with %include and %import
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12546 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-03-17 07:33:05 +00:00