[pygobject/llvm: 9/17] Add support for Py_INCREF()
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/llvm: 9/17] Add support for Py_INCREF()
- Date: Wed, 21 Jul 2010 22:35:37 +0000 (UTC)
commit 14d0ea8092f60fcc38d6897b78e24020b5940b8e
Author: Johan Dahlin <johan gnome org>
Date: Tue Jul 6 10:24:19 2010 -0300
Add support for Py_INCREF()
gi/llvm-compiler.cpp | 11 +++++++++++
gi/llvm-compiler.h | 1 +
2 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/gi/llvm-compiler.cpp b/gi/llvm-compiler.cpp
index 71694ae..dbb1e10 100644
--- a/gi/llvm-compiler.cpp
+++ b/gi/llvm-compiler.cpp
@@ -399,6 +399,7 @@ LLVMCompiler::valueFromNative(GITypeInfo *typeInfo,
switch (infoType) {
case GI_INFO_TYPE_OBJECT: {
retval = Builder.CreateCall(_PyGObject_NewFunc, value);
+ this->pyIncRef(retval);
break;
}
default:
@@ -474,6 +475,15 @@ LLVMCompiler::createPyNone()
return retval;
}
+// (PyObject*(ob))->ob_refcnt++
+void
+LLVMCompiler::pyIncRef(llvm::Value *value)
+{
+ assert(value->getType() == pyObjectPtr);
+ llvm::Value *refCnt = Builder.CreateStructGEP(value, 0, "ob_refcnt");
+ Builder.CreateAdd(Builder.CreateLoad(refCnt), llvm::ConstantInt::get(llvm::Type::getInt32Ty(mCtx), 1));
+}
+
void
LLVMCompiler::loadSymbols()
{
@@ -594,6 +604,7 @@ LLVMCompiler::compile(GIFunctionInfo *info)
llvm::Value *retval;
if (g_type_info_get_tag(retTypeInfo) == GI_TYPE_TAG_VOID) {
retval = this->createPyNone();
+ this->pyIncRef(Builder.CreateLoad(retval));
} else {
retval = this->valueFromNative(retTypeInfo, nativeCallRetval);
}
diff --git a/gi/llvm-compiler.h b/gi/llvm-compiler.h
index 72bef5f..c0494bb 100644
--- a/gi/llvm-compiler.h
+++ b/gi/llvm-compiler.h
@@ -66,6 +66,7 @@ namespace pygi {
const char * formatTypeForException(GITypeInfo *typeInfo);
char * getFunctionName(GIFunctionInfo *info);
llvm::Value * createPyNone();
+ void pyIncRef(llvm::Value *value);
void loadSymbols();
llvm::Function * createNativeCall(GIFunctionInfo *functionInfo,
const llvm::Type *nativeRetvalType,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]