Commit graph

111 commits

Author SHA1 Message Date
Clinton Stimpson
e683168018 Use PyObject instead of PySliceObject throughout with Python 3.2+
This supports use of the Py_LIMITED_API.
2022-09-05 22:04:51 -06:00
Julien Schueller
96c6bf4cc2 Fix unused-parameter warning in pycontainer.swg 2020-01-17 11:09:57 +01:00
William S Fulton
719eea090d Improve error handling calling PyObject_SetAttr
Less obscure error when setting 'this' on the SWIG proxy object
attempting to override __setattr__ in C++ (swig-user mailing list
query 19 Aug 2019).
2019-09-13 07:37:03 +01:00
William S Fulton
86cb3a9532 Python STL container method overloading fix
Fix method overloading of methods that take STL containers of different types.
Due to some error handling that was not cleared during typehecking.
2019-08-06 19:36:14 +01:00
William S Fulton
2786bf37a1 Fix multiple definitions of swig::container_owner_attribute 2019-02-21 17:57:11 +00:00
William S Fulton
a628bf9b6f Python std::vector back-reference changes
Give reference in container_owner a more unique name (back_reference).
Change back-reference 'ret' typemap to have a function name so that they
are less unwittingly be used elsewhere where not intended.

Note that they can be overridden by users if needed using:

%extend std::vector {
%typemap(ret)
  value_type const& __getitem__,
  value_type const& front,
  value_type const& back
  { ...  }
}

These override the SWIG supplied versions because the SWIG supplied
typemaps use non-const value_type&, but the methods use const, so the
above have a higher precedence in the typemap search algorithm.
2019-02-18 18:50:22 +00:00
William S Fulton
62417708fd Better name for container back-reference attribute
Mangle name with swig so as not to clash with any attribute names a
user might use.
Remove Doxygen style comments - we don't use Doxygen in SWIG.
2019-02-15 22:01:38 +00:00
Jake Cobb
30f16b9138 Python - Struct spec. for container owner
Use a struct with specialization to dispatch the container
owner reference function instead of a function.  Avoids
possible future problems if overloading were introduced.
2019-02-04 13:48:52 -05:00
Jake Cobb
40e327d742 Python: Avoid container owner check for value types 2019-01-23 16:10:26 -05:00
Jake Cobb
5185ce67b5 Python: Init container owner attribute in thread-safe way 2019-01-23 15:12:45 -05:00
Jake Cobb
92df196408 Python: Use PyObject_SetAttr instead of PyObject_GenericSetAttr for back-ref 2018-04-19 10:32:11 -04:00
Jake Cobb
cc2dc6b192 Python: Cleanup container back ref
Use a single function in a fragment.
Use SWIG_Python_GetSwigThis instead of
directly grabbing the 'this' attribute.
2018-04-18 20:39:56 -04:00
Jake Cobb
65dd1c49bc Python: Keep reference to owning container during element access 2018-04-18 17:28:31 -04:00
Mike Romberg
b229d92f9b remove bool from as() (it now always throws).
catch std::invalid_argument (what is expected) instread of std::exception.
2017-07-03 12:49:30 -06:00
William S Fulton
430f20a533 Merge branch 'tamuratak-fix_python_unordered_2'
* tamuratak-fix_python_unordered_2:
  [python] add %swig_sequence_iterator_with_making_function and          make %swig_sequence_iterator forward to it.          add %swig_sequence_forward_iterator too.
  [python] make SwigPyIteratorClosed_T and SwigPyIteratorOpen_T          inherit from forward iterator classes.
  [python] fix std unordered containers
2017-04-25 07:55:21 +01:00
William S Fulton
ea118c945b Merge branch 'srepmub-coverity_replacecount'
* srepmub-coverity_replacecount:
  Fix Coverity issue reported for setslice (pycontainer.swg):
2017-03-24 07:42:59 +00:00
William S Fulton
fa65b24b78 Add stddef.h back in to SwigPySequence_Base fragment 2017-03-17 19:20:02 +00:00
Vadim Zeitlin
51aa2bdea1 Fix dependency of SwigPySequence_Base fragment
This fragment needs to depend on StdTraits fragment as it specializes the
template struct traits<> defined there and it could happen that the struct was
not declared before being specialized, resulting in compilation errors in the
generated code.

It doesn't seem to need to depend on stddef.h inclusion, however, so replace
it with the correct dependency instead of keeping both.
2017-03-11 18:07:51 +01:00
Mark Dufour
5803e81d48 Fix Coverity issue reported for setslice (pycontainer.swg):
"CID 11151 (#3-1 of 3): Using invalid iterator (INVALIDATE_ITERATOR)18.
increment_iterator: Incrementing iterator it though it is already past
the end of its container."

Coverity does not understand 'replace_count', so warns that we may go
past self->end() (or self->rend() I guess).
2017-03-06 21:16:41 +01:00
Takashi Tamura
3174e1488c [python] add %swig_sequence_iterator_with_making_function and
make %swig_sequence_iterator forward to it.
         add %swig_sequence_forward_iterator too.
2017-02-11 15:26:52 +09:00
Takashi Tamura
db8bc1c9c7 [python] fix std unordered containers 2017-02-11 15:26:52 +09:00
Anthony Heading
1871acd4bc Remove inheritance from std::unary_function and std::binary_function,
they are deprecated in C++11 and already removed in Visual C++ '15'
running with /std:c++latest

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3145.html
2016-12-29 00:56:46 -05:00
William S Fulton
bdda0a0829 Python - fix compilation error when using -extranative and -builtin.
Closes #816
2016-11-02 22:00:54 +00:00
William S Fulton
5abb3e8008 More efficient Python slicing
Call reserve for container types that support it to avoid repeated
memory reallocations for new slices or slices that grow in size.
2016-09-01 23:49:30 +01:00
William S Fulton
5ebf1cfa5d Slight simplification of Python slicing 2016-09-01 23:49:30 +01:00
William S Fulton
91aba9f719 UTL STL container descriptor checks
The vector of pointers (just fixed) were not working correctly because the
descriptors returned from swig::type_info() were sometimes returning
zero. Zero should only be used for void * as the subsequent call to
SWIG_ConvertPtr will blindly cast the pointer without checking
descriptor.

std::vector<void *> does not work and will require further changes:
specializing traits_info<void *> to return 0 and traits_asptr<void *>.
I tried this and traits_asptr<void> also needs to be added in which
seems odd and requires further investigation...

Lib/python/pystdcommon.swg:
  template <> struct traits_info<void *> {
    static swig_type_info *type_info() {
      static swig_type_info *info = 0;
    }
  };

Lib/std/std_common.i:
  template <>
  struct traits_asptr<void *> {
    static int asptr(PyObject *obj, void ***val) {
      void **p;
      swig_type_info *descriptor = 0;
      int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
      if (SWIG_IsOK(res)) {
	if (val) *val = p;
      }
      return res;
    }
  };

  // this is needed, but am not sure this is expected
  template <>
  struct traits_asptr<void> {
    static int asptr(PyObject *obj, void **val) {
      void **p;
      swig_type_info *descriptor = 0;
      int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
      if (SWIG_IsOK(res)) {
	if (val) *val = p;
      }
      return res;
    }
  };
2016-07-28 22:51:29 +01:00
William S Fulton
c5322a9ecb Python use Py_ssize_t instead of int for better portability 2015-12-05 09:00:04 +00:00
William S Fulton
327b59a574 size_type correction for SwigPySequence_Cont 2015-12-05 09:00:04 +00:00
William S Fulton
55bbf68512 Add std::array container wrappers for Python
These work much like any of the other STL containers except Python slicing
is somewhat limited because the array is a fixed size. Only slices of
the full size are supported.
2015-11-17 07:27:48 +00:00
Olly Betts
c8a7322a4d Use %{ %} instead of { } after %pythoncode
Simpler and safer change to address PR#357.
2015-03-20 13:45:19 +13:00
William S Fulton
a89a892843 Fixes when using python -builtin and STL container wrappers.
Deletion of single elements previously failed.
Test case li_std_containers_int now works.
2014-10-07 20:58:40 +01:00
Julien Schueller
f4fffbf668 Fixed another E701 2014-06-06 15:13:23 +02:00
William S Fulton
0d9a8721f4 Move some header file includes into fragments for UTL languages 2014-02-21 19:02:14 +00:00
William S Fulton
38b2b95c30 Fix some invalid iterator usage in Python when deleting/inserting slices from/into containers 2013-03-26 21:38:45 +00:00
William S Fulton
7eda619741 Fix invalid iterators used with -ve ranges - Python
Fixes li_std_containers_int testcase.
Valgrind reports no more problems for this testcase.
2013-03-26 21:38:44 +00:00
William S Fulton
52fe61820a More for Mac OSX STL fixes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13020 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-04-28 14:27:55 +00:00
William S Fulton
c13131986e Warning fix in python STL wrappers
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13019 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-04-28 11:39:13 +00:00
William S Fulton
e39322cd01 Fix STL wrapper compilation errors on Mac OSX 64bit
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13018 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-04-28 11:18:10 +00:00
William S Fulton
a6219a855e signed unsigned fix
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12997 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-04-16 19:55:33 +00:00
William S Fulton
347f2782d2 Fix missing stddef.h when %import of STL containers. Was causing compile failures witht g++-4.6.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12939 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-03-20 20:07:56 +00:00
William S Fulton
7c58a044d2 Add support for negative steps in Python slices on the STL containers
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12903 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-01-24 23:41:40 +00:00
William S Fulton
1b47ddf8f0 Add support for slicing steps to Python STL wrappers (positive step only atm - these work the same as other Python sequences such as list)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12898 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-01-20 21:14:03 +00:00
Stefan Zager
bdc9b61dc2 Fix for bug 3447426: memory leak in vector.__getitem__
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12855 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-12-01 20:59:19 +00:00
Stefan Zager
17af467132 Fix for bug #3057804: migrate PyCObject to PyCapsule.
Other misc. fixes for python3.2, mostly dealing with changed
interfaces to python functions.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12620 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-04-09 22:07:22 +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
Stefan Zager
62fef1bf99 python3 support; passes all regressions.
Adding argcargvtest_runme3.py, because 2to3 can't handle it.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12425 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-02-03 07:21:37 +00:00
Stefan Zager
d4b8048e9a Stopped using template class SwigPyBuiltin, because it caused problems
when two typedef-equivalent types are wrapped as separate classes.

Now failing on refcount.cpptest.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12392 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-01-12 00:43:01 +00:00
Stefan Zager
dd465f9588 Finished std::pair and std::map support.
li_std_pair_extra test fails, because the _runme.py uses the
secret 'this' member variable, which doesn't exist when the
-builtin option is used.  Seems like a flaw in the test.

Test suite now fails on li_std_string_extra, because static
member variables are not fully implemented.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12351 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-15 23:04:20 +00:00
Stefan Zager
8a7ad756d0 Added sequence and mapping support for builtin types.
Fixed object ownership in %pyswigbinoperator.

Test suite now fails on li_std_vector_extra.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12346 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-14 21:11:02 +00:00
Stefan Zager
ee3a6623da First cut. Works for wrapping OpenAccess, but there's plenty
left to do.

Currently, the test suite hurls at director_stl.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12332 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-07 21:50:00 +00:00