projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[llvm.py] Make ObjectFile destructor work
[oota-llvm.git]
/
bindings
/
python
/
llvm
/
core.py
diff --git
a/bindings/python/llvm/core.py
b/bindings/python/llvm/core.py
index 5a3bd51cfa57288e48171c5d4f650440e8e16dde..bd9f8aaa2b7256906198a022ed4a7506b0ff76e1 100644
(file)
--- a/
bindings/python/llvm/core.py
+++ b/
bindings/python/llvm/core.py
@@
-7,6
+7,7
@@
#
#===------------------------------------------------------------------------===#
#
#===------------------------------------------------------------------------===#
+from .common import LLVMObject
from .common import get_library
from ctypes import POINTER
from .common import get_library
from ctypes import POINTER
@@
-33,7
+34,7
@@
class MemoryBuffer(object):
if filename is None:
raise Exception("filename argument must be defined")
if filename is None:
raise Exception("filename argument must be defined")
- memory =
c_void_p(None
)
+ memory =
LLVMObject(
)
out = c_char_p(None)
result = lib.LLVMCreateMemoryBufferWithContentsOfFile(filename,
out = c_char_p(None)
result = lib.LLVMCreateMemoryBufferWithContentsOfFile(filename,
@@
-43,17
+44,23
@@
class MemoryBuffer(object):
raise Exception("Could not create memory buffer: %s" % out.value)
self._memory = memory
raise Exception("Could not create memory buffer: %s" % out.value)
self._memory = memory
+ self._as_parameter_ = self._memory
+ self._owned = True
def __del__(self):
def __del__(self):
- lib.LLVMDisposeMemoryBuffer(self._memory)
+ if self._owned:
+ lib.LLVMDisposeMemoryBuffer(self._memory)
def from_param(self):
def from_param(self):
- return self._memory
+ return self._as_parameter_
+
+ def release_ownership(self):
+ self._owned = False
def register_library(library):
library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
def register_library(library):
library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
- POINTER(
c_void_p
), POINTER(c_char_p)]
+ POINTER(
LLVMObject
), POINTER(c_char_p)]
library.LLVMCreateMemoryBufferWithContentsOfFile.restype = bool
library.LLVMDisposeMemoryBuffer.argtypes = [c_void_p]
library.LLVMCreateMemoryBufferWithContentsOfFile.restype = bool
library.LLVMDisposeMemoryBuffer.argtypes = [c_void_p]