Commit graph

784 commits

Author SHA1 Message Date
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
4963a7f88f Fix Python 2 builtin tp_hash hashfunc closure regression when using "python:slot"
Closes https://github.com/swig/swig/issues/843
2016-12-23 23:41:07 +00:00
William S Fulton
6f0af6bec6 Merge branch 'ezralanglois-fix-memory-leak'
* ezralanglois-fix-memory-leak:
  Replicate Python memory leak fix in std::pair for Octave and Ruby
  Fix memory leak in std::pair Python binding

Conflicts:
	CHANGES.current
2016-12-18 20:02:40 +00:00
William S Fulton
364fa82499 Replicate Python memory leak fix in std::pair for Octave and Ruby
https://github.com/swig/swig/pull/851
2016-12-18 20:00:40 +00:00
Tsutomu IKEGAMI
b630cc603c Fix %array_class in carrays.i for Python -builtin
Closes https://github.com/swig/swig/issues/446
2016-12-18 17:49:47 +00:00
Robert Langlois
631f0c34cc Fix memory leak in std::pair Python binding 2016-12-17 13:27:25 -08:00
William S Fulton
1079ba7ff8 Merge branch 'm7thon-python23-division-operators'
* m7thon-python23-division-operators:
  [Python] improved wrapping of division operators
2016-11-26 22:00:21 +00:00
Daniel Vollmer
e4c5d82c71 Python: Fix mixed signedness warning for std::array 2016-11-23 22:21:46 +01: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
87bede9a99 Return to Python builtin tp_new initialization in init function. 2016-10-15 22:43:42 +01: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
777c825cd2 Rework Python builtin CLOSURE macros
The new approach uses support functions and minimal code in the macros
to make debugging easier.
2016-09-25 14:15:38 +01:00
William S Fulton
848628ae91 More flexible python builtin slots
The closure names used for builtin slots are mangled with their functype so
 that overloaded C++ method names can be used for multiple slots.
For example:
%feature("python:slot", "mp_subscript", functype="binaryfunc") SimpleArray::__getitem__;
%feature("python:slot", "sq_item", functype="ssizeargfunc") SimpleArray::__getitem__(Py_ssize_t n);
will generate closures:
  SWIGPY_SSIZEARGFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___ssizeargfunc_closure */
  SWIGPY_BINARYFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___binaryfunc_closure */
2016-09-25 14:15:38 +01:00
William S Fulton
0769e9b727 Fix iterators for containers of NULL pointers (or Python None) when using -builtin.
Previously iteration would stop at the first element that had a NULL pointer value.
2016-09-17 17:53:48 +01:00
brgirgis
0f48af8a05 Fix one casting warning on Linux (#787) 2016-09-12 09:21:20 +12: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
5b7c08c214 Make Python builtin types hashable by default
Default hash is the underlying C/C++ pointer.
This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare)
which compares the pointers.
2016-08-23 19:06:36 +01:00
William S Fulton
253a39fdff Fix hash function type checking for older versions of Python
Python 2.6 was asserting instead of throwing a Python TypeError.
2016-08-23 18:46:28 +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
4f777b181c Correct notes on customising Python builtin comparison operators
Also add example for python:compare feature
2016-08-22 07:22:40 +01:00
William S Fulton
4f681f751d Update Python docs on builtin slots 2016-08-18 07:11:00 +01:00
William S Fulton
f778ee19df Python builtin hashfunc closure fix
If the wrong return type in the hash function was used, an error:
  SystemError: error return without exception set
was raised

Add some tests for testing builtin slots
2016-08-18 07:10:54 +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
Mike Romberg
7dc5879714 castmode was failing overflow tests. Fix it. 2016-06-25 21:17:38 +01:00
Michael Thon
59f72544fa [Python] improved wrapping of division operators
The division operators `operator /` and `operator /=` are now
wrapped as `__truediv__` and `__itruediv__`, with alias methods
`__div__` and `__idiv__` generated for compatibility with Python 2.

This allows correct wrapping independent of the `-py3` flag, and
fixes these operators for Python 2 when using `from __future__
import division` (this was broken).
2016-06-12 23:29:31 +02:00
William S Fulton
5e6ab1d61d Merge branch 'ejulien-python_operator_overload_test_suite'
* ejulien-python_operator_overload_test_suite:
  Add __str__ to operator_overload testcase for python builtin
  Python operator_overload runtime testcase cleanup
  Work around a limitation of the Python binding generator related to the += family of operators.
  Fix Python 3 division member operator when -builtin is not used.
  Fix class member division operator.
  Remove the PY3BUILTIN switch as its behavior can be achieved with the existing SWIG_FEATURES=-builtin switch.
  Implement the operator overload test suite for Python.

Conflicts:
	Examples/test-suite/operator_overload.i
2016-05-05 23:01:35 +01:00
Paweł Tomulik
350d43d988 handle const pointers to functions 2016-03-24 10:59:23 +01:00
Emmanuel Julien
8df7c5fb7e Fix Python 3 division member operator when -builtin is not used. 2016-02-22 16:30:24 +01:00
Emmanuel Julien
cf370fb504 Fix class member division operator.
Define the nb_divide/nb_inplace_divide slots in the interface and use it them as nb_divide/nb_inplace_divide for Python 2.x and as nb_true_divide/nb_inplace_trus_divide for Python 3.x.

The Python 3.x nb_floor_divide/nb_inplace_floor_divide slots (operator // in Python) are not populated by the interface.
2016-02-22 14:54:19 +01:00
Olly Betts
611bbe7ddf [Python] Add missing keywords 'as' and 'with' to pythonkw.swg. 2016-02-17 14:19:08 +13:00
Olly Betts
c2228de096 Replace dead URLs with working equivalents 2016-02-17 14:18:21 +13:00
William S Fulton
bb01ed3286 Merge branch 'ahnolds-classic_python'
* ahnolds-classic_python:
  Updating changelog and marking -classic as passing CI
  Support checking names of old-style classic classes
  Don't claim to new-style support in classic mode
  Clean up setting _object
  Removing __swig_getmethods__ for static methods
  Support python(pre|ap)pend on static methods in classic mode
  Add support for static methods in classic mode
  When possible, use PyInt rather than PyLong
2016-02-06 08:01:08 +00:00
Alec Cooper
33edfa4a62 Add support for Python Bytes/Unicode distinction 2016-02-04 20:16:41 -05:00
Alec Cooper
2e1595a4d0 When possible, use PyInt rather than PyLong
This is especially important for the unsigned long typemap, which is used by
the size_t typemap, which is in turn used for lengths of std containers etc.
In Python2, len requires old-style classes' __len__ method return a PyIntObject
rather than a PyLongObject, so this supports that requirement.
2016-02-04 15:27:54 -05:00
Olly Betts
344d10935e Whitespace cleanup 2016-01-27 19:05:03 +13:00
Olly Betts
33da19d2ea Fix comment typo 2016-01-27 19:04:18 +13:00
Olly Betts
72691e5a49 Clean up Python embed.i
Remove duplicate (aside from comment formatting) embed15.i.

Remove references to Python 1.5.

Tested and remarkably still works with Python 2.7, so update
documentation and comments to reflect that.
2016-01-27 19:01:49 +13:00
Olly Betts
bfe3adbd0a Remove lingering code for compatibility with Python < 1.6 2016-01-27 15:17:36 +13:00
Alec Cooper
4e2fc7d115 Don't use long long if it isn't available
Adds preprocessor checks to avoid defining functions that use long long if it isn't available
Effects the following languages: javascript, octave, perl, python, r, ruby, tcl
2016-01-06 16:52:37 -05:00
Alec Cooper
ba01182ec4 Fixing Python primitive conversions
Don't mistakenly treat PyLong objects as PyInt objects in Python3.
  This resolves issues of large integers being incorrectly treated as -1 while also having
  an OverflowError set internally for converting PyLong->long and PyLong->double
Conversions from PyLong to long, unsigned long, long long, and unsigned long long now
raise OverflowError rather than TypeError when given an out of range value.
Removing unnecessary check for PyLong_AsLong when converting PyLong->unsigned long since the
call to PyLong_AsUnsignedLong will have covered this case.
2015-12-23 19:04:19 -05:00
William S Fulton
e07938ae8e pystrings.swg cosmetic formatting 2015-12-19 04:11:48 +00:00
William S Fulton
291186cfaf Refine Python 2 unicode strings patch 2015-12-19 03:46:44 +00:00
Brian Cole
edd36b28d2 Automatically coerce python 2.x unicode objects into UTF8 when passing to underlying code. 2015-12-19 03:44:27 +00:00
William S Fulton
7dc5b224cb Fix recent Python -builtin changes for C code 2015-12-16 18:13:31 +00:00
William S Fulton
b15ad9349e Merge branch 'coleb-python35_dtor_exception_fix'
* coleb-python35_dtor_exception_fix:
  Add test case for Python 3.5 assertion with a pending StopIteration
  Amend python_destructor_exception runtime test
  Call PyErr_WriteUnraisable if a destructor sets a Python exception (-builtin)
  Extended zjturner's changes to encompass all function dispatch and use PyErr_WriteUnraisable to handle exceptions during __del__.
  Python - Save and restore exception state before calling destroy.
2015-12-16 12:58:01 +00:00
William S Fulton
e4264e7ba8 Call PyErr_WriteUnraisable if a destructor sets a Python exception (-builtin)
This fixes the python_destructor_exception testcase for -builtin
2015-12-16 12:57:00 +00:00
Brian Cole
a863e98874 Extended zjturner's changes to encompass all function dispatch and use PyErr_WriteUnraisable to handle exceptions during __del__.
Also added test cases for the unnamed temporary destruction that is throwing assertions in Python 3.5.
2015-12-15 08:39:55 -07:00
William S Fulton
3e27d45b2a Merge branch 'ahnolds-python34'
* ahnolds-python34:
  Python tp_allocs -> tp_next corrections
  Cosmetic correction for Python tp_version -> tp_version_tag
  Add -Wmissing-field-initializers to python Travis testing
  Python 3.3 builtin missing field initializers added
  Adding tp_finalize field to PyTypeObject for Python 3.4 and -builtin
  Adding nb_matrix_multiply and nb_inplace_matrix_multiply fields to PyNumberMethods for Python version 3.5 and up
  Adding tp_finalize field to PyTypeObject for Python version 3.4 and up
2015-12-14 01:59:39 +00:00