Commit graph

238 commits

Author SHA1 Message Date
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
a0e3825de6 Fix replace handling corner case
With flags DOH_REPLACE_ID_BEGIN, DOH_REPLACE_ID_END and
DOH_REPLACE_NUMBER_END the code looked for a match for the token
string using strstr() and then checked the extra condition - if the
extra condition didn't apply it then advanced by the length of the token
before searching again.

However that can miss matches if the strstr() matches can overlap
one another, so only advance one position, which is conservative
but can't miss matches.

For example this would not match before:

Replace("123123", "1231", r, DOH_REPLACE_NUMBER_END);

This issue seems to be entirely latent in the current SWIG codebase
due to the nature of the token strings passed when using these flags.

See #2235
2022-03-19 08:55:39 +13:00
Olly Betts
9efcc785ae Re-enable symbol poisoning in a CI job
It seems too brittle to enable by default as we'd have to avoid
including any system headers after doh.h, which is hard to enforce,
but just having it enabled for one CI job should avoid uses of the
poisoned symbols from being accidentally introduced.

See #2223
2022-03-15 11:14:23 +13:00
William S Fulton
77853770bd Disable use of gcc poison pragmas
Needs a rethink to avoid use of poisoned macros in system headers.
I see this on Ubuntu 16.04:

gcc -DHAVE_CONFIG_H   -I../Source/Include -I../Source/CParse
-I../Source/Include -I../Source/DOH -I../Source/CParse
-I../Source/Doxygen -I../Source/Preprocessor -I../Source/Swig
-I../Source/Modules   -g -O2 -Wall -W -pedantic -MT DOH/base.o -MD -MP
-MF $depbase.Tpo -c -o DOH/base.o DOH/base.c &&\
mv -f $depbase.Tpo $depbase.Po
In file included from /usr/include/string.h:630:0,
                 from DOH/dohint.h:21,
                 from DOH/base.c:15:
/usr/include/x86_64-linux-gnu/bits/string2.h:1282:19: error: attempt to
use poisoned "calloc"
        ? (char *) calloc ((size_t) 1, (size_t) 1)        \
                   ^
/usr/include/x86_64-linux-gnu/bits/string2.h:1284:32: error: attempt to
use poisoned "malloc"
      char *__retval = (char *) malloc (__len);       \
                                ^
/usr/include/x86_64-linux-gnu/bits/string2.h:1302:19: error: attempt to
use poisoned "calloc"
        ? (char *) calloc ((size_t) 1, (size_t) 1)        \
                   ^
/usr/include/x86_64-linux-gnu/bits/string2.h:1308:26: error: attempt to
use poisoned "malloc"
      __retval = (char *) malloc (__len);        \
                          ^
2022-03-12 23:04:24 +00:00
Olly Betts
747a51f095 Try to prevent direct use of exit(), malloc(), etc
Use `#pragma GCC poison` (supported since GCC 3, maybe earlier) when
compiling with GCC to help prevent direct uses being introduced for
functions which DOH provides a wrapper for.
2022-03-06 15:36:42 +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
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
e38847f7e1 Fail cleanly on allocation failures
Previously code in the SWIG tool didn't handle allocation failures
well.  Most places didn't check for NULL return from
malloc()/realloc()/calloc() at all, typically resulting in undefined
behaviour, and some places used assert() to check for a NULL return
(which is a misuse of assert() and such checks disappear if built with
NDEBUG defined leaving us back with undefined behaviour).

All C allocations are now done via wrapper functions (Malloc(),
Realloc() and Calloc()) which emit and error and exit with non-zero
status on failure, so a non-NULL return can be relied upon.

Fixes #1901.
2022-03-04 11:47:49 +13:00
Olly Betts
4c7febfb80 Make DOH Char macro more robust
For example, `Char(foo)[0]` now works to get the first character
of DOH String `foo`.

Previously this gave a confusing error because it expanded to
`(char *) Data(foo)[0]` and the `[0]` binds more tightly
than the `(char *)`.
2021-12-13 09:33:26 +13:00
Michel Zou
ee8d47cec4 Fix few unused variable warnings 2021-03-07 11:20:31 +00:00
Olly Betts
975f8fcfdb Avoid undefined behaviour in DOH Replace() function
If the source and replacement strings were the same length, the code
was performing undefined pointer arithmetic involving a NULL pointer.
I'm not aware of any observable effects of this in practice, but it's
potentially problematic.  It's detected by ubsan, for example when
running `make check-python-test-suite`:

DOH/string.c:839:4: runtime error: applying non-zero offset to non-null pointer 0x602000001558 produced null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior DOH/string.c:839:4 in
2020-09-04 10:44:49 +12:00
Zackery Spytz
3b0db10aa4 Increase DOH_POOL_SIZE
Increase DOH_POOL_SIZE to 2^22.

Addresses GH-1775.
2020-04-18 09:57:20 -06:00
William S Fulton
18b2dcd222 C# 'out' or 'ref' removal improvements in director typemaps.
- Add support to DOH Replace for not replacing inside C comments
- Fix removing 'out' or 'ref' when these are present in C comments
  in cstype typemaps.

Closes #1628
2019-11-26 19:39:28 +00:00
William S Fulton
b36ae64185 Remove all generated files on error.
Previously generated files were not removed,
potentially breaking Makefiles using file dependencies, especially when
-Werror (warnings as errors) was used.
2019-07-31 00:08:49 +01:00
William S Fulton
98f29f8ad9 Remove deprecated DohClose in DOH 2019-07-31 00:08:49 +01:00
William S Fulton
e7d626d1b4 Remove use of 'register' in C source
No noticable performance change using gcc x86-64 in Java and Python
test-suites.
2018-05-04 20:02:13 +01:00
William S Fulton
edcdaaec16 Warning fixes for 64bit visual c++ on Windows 2015-07-03 20:59:24 +01:00
William S Fulton
220acc3fc8 Fixes for clang -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error
Fixes 'Illegal instruction' when SWIG executes and compiled with above
compiler options

Fixes #263
2014-11-08 10:59:59 +00:00
Karl Wette
6612997b63 Fix bug in DohNewStringWithSize(): guarantee string is nul-terminated 2014-06-01 15:33:26 +02:00
William S Fulton
b86a171e43 DOH readme correction 2014-04-08 19:19:43 +01:00
Olly Betts
4959957c18 Update documentation for deprecation and removal of Close() 2014-04-06 06:00:49 +12:00
Vadim Zeitlin
a1fe8a6501 Fix gcc strict aliasing warnings with function pointers too.
The commit 40bf877 fixed warnings about converting between function and object
pointers but introduced warnings about breaking strict-aliasing rules which
appear with -Wstrict-aliasing which is implicitly enabled by -O2.

Avoid these warnings as well by using an intermediate union for conversion
instead of casts trickery.
2014-02-01 15:00:15 +01:00
Vadim Zeitlin
40bf877499 Work around gcc warning about function pointers conversions.
Work around harmless (at least under POSIX systems where function pointers are
guaranteed to have the same representation as object pointers) but annoying
warnings given by gcc when converting between function and object pointers, e.g.

Source/DOH/fio.c: In function 'DohEncoding':
Source/DOH/fio.c:51: warning: ISO C forbids conversion of function pointer to object pointer type
Source/DOH/fio.c: In function 'encode':
Source/DOH/fio.c:75: warning: ISO C forbids conversion of object pointer to function pointer type
Source/DOH/base.c: In function 'DohCall':
Source/DOH/base.c:952: warning: ISO C forbids conversion of object pointer to function pointer type

Use an extra level of pointer indirection to avoid them.
2014-01-10 14:38:54 +01:00
Olly Betts
d3252bbf7f Fix comment typo 2013-07-02 13:22:35 +12:00
William S Fulton
7841a0d097 Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00
Olly Betts
f9566ad2df Fix assorted typos.
From https://sourceforge.net/p/swig/patches/332/ and some others too.
2013-01-08 18:47:40 +13:00
William S Fulton
6679f5dcd0 Rework warning fixes in rev 13512 as it introduces dead code flagged by sun studio
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13969 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-12-15 14:55:54 +00:00
William S Fulton
89052f3b0a Fix Strcmp - it didn't have consistent null pointer handling - revert to what it used to be - a lightweight wrapper around strcmp which means functions once again must not pass in null to it.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13943 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-12-02 13:36:13 +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
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
5a1e82a2f4 Remove DohClose (Close) and replace with calls to DohDelete (Delete) to fix some minor memory leaks in most uses of NewFile.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13885 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-14 22:16:07 +00:00
William S Fulton
45a259d274 Correct accidental turning on of DOH_DEBUG_MEMORY_POOLS
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13525 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-05 22:18:39 +00:00
William S Fulton
766128065f Error checking for stale DOH object use - also with documentation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13521 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-05 16:16:23 +00:00
William S Fulton
cdfa81e572 Add some error checking for stale DOH object use
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13520 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-05 15:53:56 +00:00
Oliver Buchtala
db0f2d7a8e Fix pedantic warnings in fio.c methods.
From: Oliver Buchtala <oliver.buchtala@googlemail.com>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13512 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-05 08:38:16 +00:00
William S Fulton
7b58300cbd Fix display of pointers on 64 bit systems, only 32 bit values were being shown.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13340 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-07-21 22:52:30 +00:00
William S Fulton
8bf1347354 Warning fixes using clang
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13024 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-04-29 21:51:18 +00:00
Joseph Wang
f67509e154 revert objinfo fix. If objinfo is null then we have
a malformed DOH and things should crash


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12946 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-03-23 15:23:47 +00:00
Joseph Wang
266ab63924 check for null pointer in inString to prevent segfaults
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12929 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-03-18 04:05:19 +00:00
William S Fulton
6d922f2ddd Fix #3433541 %typemap(in, numinputs=0) with 10+ arguments.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12849 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-11-28 19:35:44 +00:00
William S Fulton
a63d456f8a Remove redundant code highlighted by warnings in gcc-4.6
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12536 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-03-14 07:22:08 +00:00
William S Fulton
9a0f7ed06c Some more constness added to DOH and code comment consistency changes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12356 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-23 20:30:41 +00:00
William S Fulton
c8c3e13065 function prototype in comment fix
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12337 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-08 19:35:52 +00:00
William S Fulton
d1e6643161 Expand the family of debug print functions for displaying DOH types. Provide gdb support for calling these. Document improved debugging experience.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12221 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-09-15 20:17:11 +00:00
Vadim Zeitlin
ac5ddb0315 Make argument of DohWrite() const.
Writing a buffer to a DOH object doesn't modify so it should be const.

This allows the code using const pointers to pass them to DohWrite() without
neither the casts nor gcc warnings.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12167 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-07-22 16:59:29 +00:00
William S Fulton
d399c1a04c DohDelete and DohCopy assertions called if not a DOH object
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11897 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-03-04 21:45:26 +00:00
William S Fulton
cb64f65bae SWIG license change - Source moves to GPLv3
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11876 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-02-27 23:53:33 +00:00
Haoyu Bai
47b4825168 Merged revisions 11085-11086,11088-11089 via svnmerge from
https://swig.svn.sourceforge.net/svnroot/swig/branches/swig-2.0

........
  r11085 | bhy | 2009-01-25 00:21:55 +0800 (Sun, 25 Jan 2009) | 2 lines
  
  Fix const-correctness.
........
  r11086 | bhy | 2009-01-25 02:08:50 +0800 (Sun, 25 Jan 2009) | 2 lines
  
  Correct some function definition in header files, which implementation changed in previous commit caused mismatch.
........
  r11088 | bhy | 2009-01-25 02:38:32 +0800 (Sun, 25 Jan 2009) | 1 line
  
  minor fix and now SWIG is alive again
........
  r11089 | bhy | 2009-01-25 06:07:07 +0800 (Sun, 25 Jan 2009) | 1 line
  
  Correct some bug introduced in previous commits. Now SWIG is pretty good with C++ compiler.
........


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11097 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-01-30 10:27:37 +00:00