Commit 14d0ea80 authored by Johan Dahlin's avatar Johan Dahlin

Add support for Py_INCREF()

parent 38ba6f50
......@@ -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);
}
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment