1

Im new using SWIG to wrapped C shared library.

I have problem to call a C function with Struct pointer in python.

My files:

ST_Param.h:

typedef struct {
       unsigned int* device_Address;
       ....
       ....
       unsigned int lock;
}ST_param_ST;      


unsigned char ST_Param_Initialize(ST_param_ST * ST_param, unsigned int device_Address);

ST_Param.c

......... Rest of file.............

unsigned char ST_Param_Initialize(ST_param_ST * ST_param, unsigned int device_Address){

    if(ST_param == NULL){
    .......... rest of funtion .......................

    return 0;
}

Within ST_Param_Initialize I confirm that the pointer exists, if not believe

ST_Param.i:

/* File : ST_Param.i */
%module ST_Param

%{
#define SWIG_FILE_WITH_INIT
#include "ST_Param.h"
%}




%include "typemaps.i" 
%include "ST_Param.h"

I compiled and generated a .so file good. In python I can import a library but I cant call a ST_Param_Initialize because a need a ST_Param_ST * parameter:

ST_param_ST * error

How can I do this?

Note: i cant modify a .c and .h file. Only a .i file.

A search in google but I dont understand how to do it

Thanks Regards.

1 Answer 1

2

You do this essentially the same way you do it in C: You first create a ST_param_ST struct and then pass this to the initialization function ST_Param_Initialize(). Here is an example in Python, assuming your module is called ex:

>>> import ex
>>> ST_Param = ex.ST_param_ST()
>>> ex.ST_Param_Initialize(ST_param, 42)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.