|
From: debutant <mic...@ho...> - 2008-09-24 10:31:19
|
Hello,
I tried to solve the typemap problem but there are still
few things that I don't understand. I use a global function
rather than a class constructor.
Here is what was supposed to be a very simple example.
example.h:
#include <iostream>
#include <vector>
void globale_print(std::vector<int> vint)
{
std::cout<<"globale print vecteur: ";
for (size_t i=0; i<vint.size(); i++)
{
std::cout<<vint[i]<<" - ";
}
std::cout<<"\n";
}
example.i:
%module example
%{
#include "example.h"
#include "arrayobject.h"
%}
%typemap(in) std::vector<int>
{
PyArrayObject* aa=(PyArrayObject *) $input;
$1.resize(aa->dimensions[0]);
for (unsigned int i=0; i<aa->dimensions[0]; i++)
{
$1[i]= *(int *) (aa->data + i* aa->strides[0] );
}
};
%include "example.h"
runme.py:
import example
import Numeric
array=Numeric.array(range(5))
print array
print type(array)
example.globale_print(array)
Like it is, it works. But there are a lot of things that I don't
understand.
If I want to make a check of aa, something like:
"""
if (!PyArray_Check(aa)) {
return NULL;
}
"""
the compilation of the wrapper is ok but when I run the python
script runme.py, I have a segmentation fault because of the first line.
Here I really need help.
Please keep in mind that it is my first try to make a typemap ....
Thanks a lot
Michel
--
View this message in context: http://www.nabble.com/Help-to-wrap-a-method-with-a-std%3A%3Avector-argument-tp19627706p19646078.html
Sent from the swig-user mailing list archive at Nabble.com.
|