I am have tried to communicate c with python using python object.. in the c side I store values to a pointer variable.. and when I return it I get a python object in the python side.. is it possible to retrieve "those pointer values from the python object" in python side??
test.c file
#include <stdio.h>
#include <stdlib.h>
int *getval() {
int *var;
int *var1;
int i;
var1=var;
*var=5;
var++;
*var=6;
return var1;
}
test1.c file
#include <Python.h>
static PyObject * getvals(PyObject * self, PyObject * args)
{
int *x;
x=getval();
PyObject * test = PyCapsule_New((int *)x, "int", NULL);
return test;
}
python file
import test1
x=test1.getvals()
something like this .. I want to get the values of the var file I have assigned in test.c in python file.
I have modified to this please check How can I retrive values in python side
test.c
uint64_t * getvar()
{
int i=0;
uint64_t * vars=(uint64_t *)malloc(sizeof(uint64_t));
for(i=0;i<3;i++)
{
var[i]=i;
printf("%llu\n",var[i]);
}
return vars;
}
test1.c
static PyObject * getlist(PyObject * self, PyObject * args)
{
int i;
uint64_t * mylist;
mylist=getvar();
for(i=0;i<3;i++)
printf("%llu\n",mylist[i]);
PyObject * my_list = PyCapsule_New((void *)my_list, "uint64_t", NULL);
return my_list;
}
test.py
import test1
x=test.getvals()
print x
while compiling c files I get such warnings
format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’ [-Wformat]
warning: ‘vars’ may be used uninitialized in this function [-Wuninitialized]
but still the values get printed,, How can I initialize 'vars'?? and how to retrieve values assigned in test.c in test.py
please suggest..