Re: Custom director overrides

Dima Kogan <[email protected]> Sun, 25 Aug 2024 17:41:24 -0700
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
--=-=-=
Content-Type: text/plain

Hi. Thanks for replying.


Rokas Kupstys via Swig-user <[email protected]> writes:

> In case of python, output parameters are returned by function itself.
> If your f function had a void return type then wrapped function would
> return modified string s. If return type was say int, then function
> would return a tuple (result_int, output_s). See
> https://www.swig.org/Doc4.2/Python.html#Python_nn46

These functions work to allow a python program to call a swig-wrapped
function.

But as far as I can tell, they do NOT work to allow a Python director
overload to provide its own flavor of the virtual function. The
documentation of the various functions in

  https://www.swig.org/Doc4.2/Library.html#Library_nn12

makes that clear; it says:

  It is important to emphasize that this function does not mutate the
  string value passed---instead it makes a copy of the input value,
  mutates it, and returns it as a result.

I think I need to %extend or %rename something to change the
director-generated wrapping function to be able to write into the char*
buffer.

I'm attaching a trivial example. This can be built on my Debian box with

  swig \
    -c++ \
    -python \
    -o Tst_wrap.cpp \
    Tst.i && \
  g++ \
    -shared \
    -fPIC \
    -o _Tst.cpython-312-x86_64-linux-gnu.so Tst_wrap.cpp Tst.cc \
    -I/usr/include/python3.12 \
    -I. && \
  python3 tst.py

This has a class Tst with two virtual functions: f0() and f1(). And a
non-virtual function g() that calls f0() and f1(). The non-derived
implementation of f0() and f1() modify the memory pointed to by its
argument.

The sample program tst.py calls Tst::g() to show that indeed f0() and
f1() do modify the input memory.

And the sample program tst.py ALSO creates a derived class Tst2 using a
swig director. It provides its own implentations of f0() and f1(), but
those cannot modify the input memory, without some extra swig stuff that
I cannot figure out.

Help appreciated.

Thanks


--=-=-=
Content-Type: application/gzip
Content-Disposition: attachment; filename=pyfltk-swig-test.tar.gz
Content-Transfer-Encoding: base64

H4sIAAAAAAAAA+2XXW/aMBSGuc6v8FKhJGiFOCRhgnUS3O1uF7vrJhQSB6xCEtkOVVV1v33HTviG
sUmUaqqfCwj2yXltnPfYKZ7SuXi45Y90eisIF53G5XGBXhDIb9wL3O3vFQ3sh6HX80Mv6DZcDFdu
AwWvMJYDSi4ihlAjoYvoT3Hn+v9Tiv31/85FO44vqiEXOPT9k+sf4nC1/nANcdiHgAZyLzqKE7zz
9b+hWTwvE4I+y4Wfzb4YxjKnCYJf/X7q2vEsYi0UOSjOMy6MZwMBBaOZSG2zyW3nR2Z+RONxWmbx
eOwMVH907/5Ed8gaWgPjZSchrhNO/i3hpE44qhJCcJVvasvcTp1FpkaTMnXvsfdJxpvwcJmDnT68
7sMY130wTXlXrQVjlHHwa29ofZX7zmpyS2VSV3K0Kq5mNfCdRnnffsNagBFRsgwFcmbXX/+j/p/N
Lqpxzv9esK7/2Jft4H/P0/6/BjcFi6aLCOVZTIxNMeAioXlbVoN4HnEu3QYmK8rJnMZ99dguKRNl
NEfK3AeFYnAkZt/79fO/CvoFGraDnl9Uq7R47W4wxuANnPE+OPC/AP8XTxfVOON/7Ppr/wdeT57/
fOy52v/X4OZDp+SsM6FZp3gSszzrGkbK8oV0PKKLImdqq92qA54NH05VBBKSwo5HMyrGY5uTebqz
y1W0Ijblx9pbD4+yq061tRXysiDMdtrrzFWKzR3GWhwKj5JF22nUlm2bXzNUTUlGOaazL2MNh0Pr
lLZMvK2D/0oHH9UZjUandbDSqVJZrVZL/fGTiBOk/nHLMYQLxxVVHOGyPbUPwj0YIqNLklS39FHJ
CUcRSigjscgZErmcBM0I+lYNNF8SxmgCUSl0w+EEhi6VvErJk1Keknrr51Pzuhw9/9HLapw7/+Hu
1vtft9eQDaGv6/81aC7ypJwTe1Ur+J2JTacq+c2URFCsiG2uek350tJ83hwUzep1wTSa8FrWPGh9
69lpNBqNRqPRaDQajUaj0Wg0Gs375TercMSfACgAAA==
--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user

--=-=-=--