1

I am writing a Python extension for an existing library. Some of the functions accept a pointer to a primitive, so the arg can act as output.

This is not very pythonic, so I want to use typemaps as explained in the SWIG documentation here so that the functions return tuples instead.

Here is a snippet of my SWIG interface file (only relevant parts to this question shown)

%include "typemaps.i"                           // For pointers to primitive types

%apply double *OUTPUT { double *a1, double *a2, double *a3 };
%apply double *OUTPUT { double *b1, double *b2, double *b3 };
%apply double *OUTPUT { double *c1, double *c2 };


class FooBar
{
public:
    FooBar();
    ~FooBar();

    int     do(char* s, double *a1, double *a2, double *a3);
    double  something(int i, double *b1, double *b2, double *b3);
    void    great(double *c1, double *c2);
};

The SWIG doc do not appear to clarify if I can use multiple OUTPUT (macros?) in the way I have done above - is this safe?

Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341

0 Answers0