File: python_bindings.cc

package info (click to toggle)
gr-iqbal 0.38.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,956 kB
  • sloc: python: 9,396; ansic: 816; cpp: 307; makefile: 72; sh: 56
file content (41 lines) | stat: -rw-r--r-- 908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright 2020-2021 Free Software Foundation, Inc.
 * Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com>
 *
 * This file is part of gr-iqbalance
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <pybind11/pybind11.h>

#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>

namespace py = pybind11;

void bind_fix_cc(py::module& m);
void bind_optimize_c(py::module& m);

// We need this hack because import_array() returns NULL
// for newer Python versions.
// This function is also necessary because it ensures access to the C API
// and removes a warning.
void* init_numpy()
{
	import_array();
	return NULL;
}

PYBIND11_MODULE(iqbalance_python, m)
{
	// Initialize the numpy C API
	// (otherwise we will see segmentation faults)
	init_numpy();

	// Allow access to base block methods
	py::module::import("gnuradio.gr");

	bind_fix_cc(m);
	bind_optimize_c(m);
}