Commit fa550210 authored by François Grisez's avatar François Grisez

Fix memory leak in the generated C++ wrapper

clone() methods sytematically took a reference on the freshly
created object whereas these had their reference counter set to one

This commit prevents the wrapper generator take an extra reference
by passing false as 'takeRef' argument of cPtrToSharedPtr().

This commit also introduce a new property for abstractapi.Method
objects, which tells whether the method returns an allocated object.
parent fc4bc693
......@@ -366,6 +366,10 @@ class Method(DocumentableObject):
def returnType(self, returnType):
self._returnType = returnType
returnType.parent = self
def returnAllocatedObject(self):
return[0] in ['create', 'new', 'clone']
def translate_as_prototype(self, translator, **params):
return translator.translate_method_as_prototype(self, **params)
......@@ -307,7 +307,7 @@ class CppTranslator(object):
if exprtype.desc.refcountable:
cppReturnType = CppTranslator.sharedPtrTypeExtractor.match(cppReturnType).group(2)
if isinstance(exprtype.parent, AbsApi.Method) and len( >=1 and ([0] == 'create' or[0] == 'new'):
if isinstance(exprtype.parent, AbsApi.Method) and len( >=1 and exprtype.parent.returnAllocatedObject:
return 'Object::cPtrToSharedPtr<{0}>({1}, false)'.format(cppReturnType, cExpr)
return 'Object::cPtrToSharedPtr<{0}>({1})'.format(cppReturnType, cExpr)
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