From a4f3ac0b00694287e791cd7d753b420976d9f22a Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Fri, 12 Feb 2016 18:12:08 +0100 Subject: Add destructor for returning PyCObject in create_pcilib_instance function --- pywrap/pcipywrap.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'pywrap/pcipywrap.c') diff --git a/pywrap/pcipywrap.c b/pywrap/pcipywrap.c index 8ef1dc0..a33566a 100644 --- a/pywrap/pcipywrap.c +++ b/pywrap/pcipywrap.c @@ -79,7 +79,6 @@ void pcilib_print_error_to_py(void *arg, const char *file, int line, { //copy received message to log char* buf = full_log; - char* buf_start = buf; full_log = make_str("%s%s", buf, buf_wrapped_message); free(buf); } @@ -104,6 +103,16 @@ void __redirect_logs_to_exeption() pcilib_get_logger_argument()); } +/*! + * Destructor for pcilib_t + */ +void close_pcilib_instance(void *ctx) +{ + if(ctx == __ctx) + __ctx = NULL; + pcilib_close(ctx); +} + /*! * \brief Wraps for pcilib_open function. * \param[in] fpga_device path to the device file [/dev/fpga0] @@ -120,7 +129,7 @@ PyObject* create_pcilib_instance(const char *fpga_device, const char *model) return NULL; } - return PyCObject_FromVoidPtr((void*)ctx, NULL); + return PyCObject_FromVoidPtr((void*)ctx, close_pcilib_instance); } /*! -- cgit v1.2.3