From 5afd5a23600bd1f2aab11d3f6009ca63e6ee09c7 Mon Sep 17 00:00:00 2001 From: Yichao Yu <yyc1992@gmail.com> Date: Sat, 17 May 2014 10:26:50 -0400 Subject: [PATCH] MemoryObject.release --- pyopencl/c_wrapper/wrap_cl_core.h | 1 + pyopencl/cffi_cl.py | 4 ++-- src/c_wrapper/wrap_cl.cpp | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pyopencl/c_wrapper/wrap_cl_core.h b/pyopencl/c_wrapper/wrap_cl_core.h index 458f6c3a..594bacd9 100644 --- a/pyopencl/c_wrapper/wrap_cl_core.h +++ b/pyopencl/c_wrapper/wrap_cl_core.h @@ -91,6 +91,7 @@ intptr_t _int_ptr(void*, class_t); void* _from_int_ptr(void **ptr_out, intptr_t int_ptr_value, class_t); error *_get_info(void *ptr, class_t class_, cl_uint param, generic_info *out); void _delete(void *ptr, class_t class_); +error *_release_memobj(void* ptr); void pyopencl_free_pointer(void*); void pyopencl_free_pointer_array(void**, uint32_t size); diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index 3aeb863c..b2cb1ffb 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -435,8 +435,8 @@ class MemoryObjectHolder(_Common): class MemoryObject(MemoryObjectHolder): - pass - + def release(self): + _handle_error(_lib._release_memobj(self.ptr)) def _c_buffer_from_obj(obj, writable=False): """Convert a Python object to a tuple (cdata('void *'), num_bytes, dummy) diff --git a/src/c_wrapper/wrap_cl.cpp b/src/c_wrapper/wrap_cl.cpp index 33619a43..74c47cb8 100644 --- a/src/c_wrapper/wrap_cl.cpp +++ b/src/c_wrapper/wrap_cl.cpp @@ -3432,7 +3432,6 @@ intptr_t _int_ptr(void* ptr, class_t class_) { SWITCHCLASS(INT_PTR); } - void* _from_int_ptr(void **ptr_out, intptr_t int_ptr_value, class_t class_) { #define FROM_INT_PTR(CLSU, CLS) \ BEGIN_C_HANDLE_ERROR \ @@ -3465,6 +3464,14 @@ void _delete(void *ptr, class_t class_) { SWITCHCLASS(DELETE); } +::error* +_release_memobj(void* ptr) +{ + BEGIN_C_HANDLE_ERROR; + static_cast<pyopencl::memory_object*>(ptr)->release(); + END_C_HANDLE_ERROR; + return NULL; +} int pyopencl_get_cl_version(void) { return PYOPENCL_CL_VERSION; -- GitLab