tools: ratbag-command.py: fix new resolutions list

This one gets a little bit meesy given that the libratbag expects a
C array. Provide some wrapping aound it and hope we won't have to
do it again and again.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2017-10-16 15:31:46 +02:00
parent 558f59b52c
commit f1d20f1f35
2 changed files with 42 additions and 0 deletions

View File

@@ -9,6 +9,41 @@
#include <shared.h>
%}
#define __attribute__(x)
/* custom typemap for handling ratbag_resolution_get_dpi */
%typemap(in) (unsigned int *resolutions, size_t nres) {
unsigned int i;
if (!PyList_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting a list");
return NULL;
}
$2 = PyList_Size($input);
$1 = (unsigned int *) malloc(($2 + 1) * sizeof(unsigned int));
for (i = 0; i < $2; i++) {
PyObject *s = PyList_GetItem($input, i);
if (!PyInt_Check(s)) {
free($1);
PyErr_SetString(PyExc_ValueError, "List items must be integers");
return NULL;
}
$1[i] = PyInt_AsLong(s);
}
$1[i] = 0;
}
%typemap(argout) (unsigned int *resolutions, size_t nres) {
unsigned int i;
for (i = 0; i < $2; i++) {
PyList_SetItem($input, i, PyInt_FromLong($1[i]));
}
}
%typemap(freearg) (unsigned int *resolutions, size_t nres) {
if ($1)
free($1);
}
/* END OF custom typemap for handling ratbag_resolution_get_dpi */
/* Parse the header file to generate wrappers */
%include "libratbag.h"
%include "libratbag-enums.h"