PageRenderTime 3ms CodeModel.GetById 1ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/xml/example_inl.i

#
Swig | 30 lines | 20 code | 7 blank | 3 comment | 0 complexity | 9620de66d47f1db012ddd07efc62c5f9 MD5 | raw file
 1// Tests SWIG's handling of pass-by-value for complex datatypes
 2%module example
 3
 4%{
 5#include "example.h"
 6%}
 7
 8/* Some functions that manipulate Vectors by value */
 9extern double dot_product(Vector a, Vector b);
10extern Vector vector_add(Vector a, Vector b);
11
12/* Include this because the vector_add() function will leak memory */
13void   free(void *);
14
15/* Some helper functions for our interface */
16%inline %{
17
18Vector *new_Vector(double x, double y, double z) {
19   Vector *v = (Vector *) malloc(sizeof(Vector));
20   v->x = x;
21   v->y = y;
22   v->z = z;
23   return v;
24}
25
26void vector_print(Vector *v) {
27  printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z);
28}
29%}
30