Commit graph

90 commits

Author SHA1 Message Date
William S Fulton
32b963ef1c Re-organise Python method creation and docstring functions declarations
Fix ‘PyMethodDef* SWIG_PythonGetProxyDoc(const char*)’ declared ‘static’ but
never defined [-Wunused-function]

Closes #1448 (again)
2019-02-19 22:54:08 +00:00
William S Fulton
43438b66ab Re-organise some generate Python code for method creation and docstring support
Fix ‘PyMethodDef* SWIG_PythonGetProxyDoc(const char*)’ declared ‘static’ but
never defined [-Wunused-function]

Closes #1448
2019-02-10 22:55:16 +00:00
William S Fulton
b8fc71b5f8 Remove functions associated with tp_print that are now redundant
Removes SwigPyPacked_print and swig_varlink_print
2018-12-11 08:08:14 +00:00
Andrew Rogers
f8bf286a6e #1368: AV in tp_print caused by mismatched Python/extension CRT usage 2018-12-11 07:54:57 +00:00
William S Fulton
0147fb2e64 Workaround for incorrect output formatting 2018-12-06 07:44:34 +00:00
William S Fulton
009415e43b Cosmetic changes in SWIG_globals
Make local variable name standards compliant
2018-12-04 22:15:52 +00:00
Andrew Rogers
0fecd1538f Cleanup accessing/decref of globals, to avoid code bloat in init function. 2018-11-27 23:30:51 +00:00
Andrew Rogers
3c090307a4 Fix ISOC build errors. 2018-11-25 04:23:18 +00:00
Andrew Rogers
493d96a732 Fix unused variable warning. 2018-11-24 20:07:44 +00:00
Andrew Rogers
65edf2258f #1360: Leak of SWIG var link object 2018-11-23 16:02:46 +00:00
William S Fulton
a1f40568d6 Remove non-const char * usage where the Python API now supports it
Python fixed many APIs to use const char * instead of char * at around
Python 2.4. As we support 2.7 and later, we can now remove the non-const
string usage.
Types changed:
  PyArg_ParseTuple
  PyArg_ParseTupleAndKeywords
  PyArg_UnpackTuple
  PyDict_SetItemString
  PyMethodDef
  PyModuleDef
  SWIG_Python_UnpackTuple
  SWIG_Python_str_FromChar
  SWIG_addvarlink
  swig_const_info
2018-10-22 08:19:50 +01:00
William S Fulton
b2aa01f492 Python options simplification: Remove -buildnone, -nobuildnone
A custom implementation for Py_None was implemented in SWIG_Py_None().
This was used by default on Windows only. It isn't clear why this
was done just for Windows. Now Py_None is the real Py_None on all
operating systems.
2018-10-22 08:19:50 +01:00
Julien Schueller
c0c2d90497
[Python] Fix -Wstringop-overflow warning
fixes #1332
2018-10-01 09:31:42 +02:00
William S Fulton
d56d7a7253 Initialize Python function-local statics (singletons)
Singletons are created during Python module initialization in order to avoid
deadlocks with subsequent multi-threaded usage.
Fixes #1275 #1279
2018-07-17 19:56:12 +01:00
William S Fulton
8e6799d783 Revert "Merge branch 'petrmitrichev-remove-function-local-statics'"
This reverts commit b8ed7759d5, reversing
changes made to 6f2399e86d.
2018-07-17 08:46:53 +01:00
William S Fulton
4b4e0180f4 Python initialization code tidy up
I've moved the initialization of statics a little earlier on - a little
safer as it is hard to follow exactly when some of these were being
used, such as SWIG_Py_None which sometimes replaces Py_None.
2018-06-30 19:28:03 +01:00
Petr Mitrichev
d956081fd3 Avoid function-local statics that call Python code to avoid deadlocks with GIL 2018-06-28 14:27:52 +02:00
Olly Betts
7f98830110 [Python] Fix new GCC8 warnings in generated code
Avoid casts between incompatible function types where possible (when
keyword args are in use, it is not possible to avoid such warnings as
they are inherent in the design of Python's C API in that particular
case).  Fixes #1259.
2018-06-11 15:51:53 +12:00
Olly Betts
a82c1b943b Drop support for Python 3.0 to 3.3
See #701.
2018-06-08 11:08:31 +12:00
Olly Betts
7c034ead32 Remove special handling for Python < 2.6
See #701.
2018-06-08 09:34:48 +12:00
William S Fulton
b0e29fbdf3 Add missing checks for failures in calls to PyUnicode_AsUTF8String.
Previously a seg fault could occur when passing invalid UTF8 strings (low
surrogates), eg passing u"\udcff" to the C layer (Python 3).
2017-12-04 20:14:04 +00:00
Mark Dufour
9825fcbab5 [Coverity] fix issue reported for SWIG_Python_FixMethods
Fix Coverity issue reported for SWIG_Python_FixMethods:

"buffer_size: Calling strncpy with a source string whose length
(10 chars) is greater than or equal to the size argument (10)
will fail to null-terminate buff."

The issue is only reported for the "swig_ptr: " line, but for
consistency we replace both occurrences of strncpy with memcpy.
2017-02-15 15:58:26 +13:00
William S Fulton
e5fd1c979b Cosmetic change to using SwigPyObject 2016-10-14 07:30:44 +01:00
William S Fulton
96fae38be2 Fix Python pickling and metaclass for builtin wrappers
The metaclass (SwigPyObjectType) for SWIG objects was not defined in
a way that let importlib successfully import the Python wrappers.
The pickle module failed because it couldn't determine what module the
SWIG wrapped objects are in.

I've changed the definition of SwigPyObjectType using more normal
builtin type definitions. There are still some open questions:
- None of the builtin types, like swig_static_var_getset_descriptor and
  SwigPyObject are added into any module. No call to PyModule_AddObject
  is made, so isinstance cannot be used for any wrapped type, all of
  which are derived from SwigPyObject.

Closes #808
2016-10-14 07:30:44 +01:00
William S Fulton
ae32fb4f9a Python builtin minor tweaks
Remove internal Python struct names from generated code
Cosmetic code formatting
2016-08-22 19:28:52 +01:00
William S Fulton
5f93c94e87 Python tp_allocs -> tp_next corrections
Updates for Python 2.5 and later and for -builtin.
2015-12-14 01:56:11 +00:00
William S Fulton
24b4a0fb94 Cosmetic correction for Python tp_version -> tp_version_tag 2015-12-14 01:29:43 +00:00
Alec Cooper
e79349d886 Adding tp_finalize field to PyTypeObject for Python version 3.4 and up 2015-10-27 20:12:03 -04:00
Olly Betts
a89a4d9e84 [Python] Fix warning when compiling generated code with MSVC.
Fixes https://sourceforge.net/p/swig/patches/351/ reported by Mateusz
Szymański).
2015-05-19 15:48:25 +12:00
William S Fulton
1db561cf08 Improve Python builtin and %constant structs
Tweak to previous commit from issue #250 for C compatibility.
Set self to zero too.
2014-12-18 07:01:08 +00:00
Paweł Tomulik
0ad384bb28 fixed python global object constants
Fix for Python and -builtin
Fix from Github issue #250
2014-12-18 07:01:08 +00:00
William S Fulton
7a96fba836 Correct exception thrown attempting to access a non-existent C/C++ global variable on the 'cvar' object.
The exception thrown used to be a NameError. However, as this access is
via a primary, an AttributeError is more correct and so the exception
thrown now is an AttributeError. Reference:
http://docs.python.org/2/reference/expressions.html#attribute-references

SF Patch #346.
2014-03-02 01:31:36 +00:00
Jens Krüger
da44064d6c 'swig_varlink_getattr' throws a wrong exception
If the attribute of a python object could not found a AttributeException
should be thrown instead of a NameException.
2014-03-02 00:24:23 +00:00
William S Fulton
0e54a51c10 Add missing #include <stddef.h> for offsetof when using -builtin.
Fixes SF #1345
2013-10-17 19:56:18 +01:00
William S Fulton
3b8bc08be7 Suppress -Werror=unused-but-set-variable gcc warning in Python wrappers
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13571 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-08 22:24:46 +00:00
William S Fulton
63f21af8d0 PyVarObject_HEAD_INIT to conform to C standard - pointers cannot be used in static initializers
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12660 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-05-12 20:20:36 +00:00
Stefan Zager
a52612f845 Fixed PyGetSetDescr for python3.2.
Fixed memory management in special_variable_macros test.

Don't define asdict() for multimap.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12659 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-05-08 06:54:21 +00:00
Stefan Zager
7a0726c8b6 Fix ISO C90 errors.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12619 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-09 04:59:16 +00:00
William S Fulton
070893434b Cosmetic formatting in generated code
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12610 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-05 20:59:24 +00:00
William S Fulton
b2b9e2eb91 Python builtin - warning suppression/fixes for 'gcc -Wall' and cosmetic changes in generated code.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12609 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-05 20:39:44 +00:00
William S Fulton
5f6389ab31 Cosmetic Python changes and replace DOH types
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12608 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-04 20:13:14 +00:00
Stefan Zager
96ec495858 Fix compiler warnings about uninitialized members.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12607 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-04 07:11:02 +00:00
Stefan Zager
cd7fc2047b Factored some #ifdef noise out of the initialization function by adding
SwigPyBuiltin_SetMetaType.

For %import statements, move the runtime import out of SWIG_init and into the
.py file.  The reason for this is that the import must be executed within the
python execution frame of the module, which is true in the .py file, but *not*
true in the initialization function.  Had to re-order the .py file slightly
to put the 'import' statements at the top; that's necessary to make sure base
types from an imported module are initialized first.  If -builtin isn't used,
then the .py code is not re-ordered.

Added an explanation and workaround for the limitation that wrapped types are
not raise-able.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12585 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-01 19:35:30 +00:00
William S Fulton
960b503a72 Python warning fixes for gcc -Wall -Wextra
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12584 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-01 06:46:14 +00:00
Stefan Zager
3d444101d1 A slew of changes based on William Fulton's code review.
- Fixed naming conventions; SwigPyBuiltin is used a lot
- Removed use of std::vector
- builtin.swg isn't included if -builtin isn't specified
- Changed many feature names to use a "python:" prefix
- Eliminated static vars in std_pair.i
- Eliminated C++-style comments (//)
- Enabled autodoc and docstring with -builtin
- Fixed non-ansi generated C code
- Detect and complain if two incompatible swig modules are loaded
- Removed argcargvtest_runme3.py, and fixed argcargvtest_runme.py
  so that 2to3 handles it better
- Removed anonymous namespaces
- Eliminated builtin_init typemaps; consolidated functionality into
  SWIG_Python_NewPointerObj
- Eliminate printf warnings from %U conversion character by switching
  to %S, which works just as well
- Fixed li_std_set_runme.py for python3, which returns set members in
  a different order from python2





git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12562 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-03-29 06:57:02 +00:00
William S Fulton
908c37cef8 Coding style fixes for Python builtin changes added on the szager-builtin branch
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12515 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-03-03 19:34:18 +00:00
Stefan Zager
288c37f5bf Regressions pass! With a few tweaks for unsupported features, primarily:
- Throwing wrapped types as exceptions is unsupported.
- Reverse comparison operators (e.g., __radd__) aren't supported.

Rationalized destructors.

Finished std::map implementation.  Required fixes to typecheck for
SWIGTYPE* const&.

Need a little special handling of the swig_type_info for SwigPyObject
when multiple modules are loaded.

Fall back to SwigPyObject_richcompare if there's no operator overload.

"memberget" and "memberset" attrs are applied strangely; work around
them.

Added 'this' attribute.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12415 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-01-30 03:17:28 +00:00
Stefan Zager
8ac54d1d5e Director issues should be mostly clean now.
Refactored some type initialization out of SWIG_init.

Use __all__ attribute of module to define public interface.
This is necessary to make available symbols starting with '_'.

Now dying on li_boost_shared_ptr.  Looks like it's gonna be ugly.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12373 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-01-06 00:09:25 +00:00
Stefan Zager
b77b64944b Static member variables are working.
Fixed some corner cases with protected members of director classes.

Now dying in director_finalizer.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12371 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-01-05 08:35:28 +00:00
Stefan Zager
3a86f2068f Added support for multiple inheritance. Not as hard as I feared.
Apply operator features to both the operator name, and the renamed
"__*__" method.  That's the only way to hit all corners.

Added support for %pythonnondynamic.  I believe this implementation
is more correct than the existing implementation, but I'm still
waiting for an adjudication on the behavior of the python_nondynamic
test.

Current list of unsupported features that require minor tweaks
to the test suite:

- 'this' member variable is obsolete.

- No support for reversible operator overloads (e.g., __radd__).  You
can still support this:

a = MyString("foo")
b = "bar"
c = a + b

... but you can't do this:

a = "foo"
b = MyString("bar")
c = a + b

With the tweaks, the test suite now fails on python_nondynamic.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12353 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-20 23:35:18 +00:00