From 768861a4d085002f8e454e40849e2b5e13e6c7d7 Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Thu, 1 Feb 2001 03:44:35 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/ffi/FFISpecs.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/direct/src/ffi/FFISpecs.py b/direct/src/ffi/FFISpecs.py index 146efe1f3b..3d1edc97ef 100644 --- a/direct/src/ffi/FFISpecs.py +++ b/direct/src/ffi/FFISpecs.py @@ -6,6 +6,10 @@ import string from PythonUtil import * +augmentedAssignments = ['__iadd__', '__isub__', '__imul__', '__idiv__', + '__ior__', '__iand__', '__ixor__', + '__ilshift__', '__irshift__'] + class FunctionSpecification: def __init__(self): self.name = '' @@ -364,8 +368,18 @@ class MethodSpecification(FunctionSpecification): if (i < (len(thislessArgTypes)-1)): file.write(', ') file.write(')\n') - returnType = self.typeDescriptor.returnType.recursiveTypeDescriptor() - returnType.generateReturnValueWrapper(file, self.typeDescriptor.userManagesMemory, needsDowncast, nesting+2) + # If this is an augmented assignment operator like +=, we have special rules + # In this case we simply call the C++ function, make sure we got the same + # return value back, then return self. Otherwise if you let it go through the + # normal system, it actually deletes the old Python object causing the C++ memory + # to be deleted then returns a new Python shadow object with the old C++ pointer... BAD! + if self.getFinalName() in augmentedAssignments: + indent(file, nesting+2, 'assert(self.this == returnValue)\n') + indent(file, nesting+2, 'return self\n') + else: + returnType = self.typeDescriptor.returnType.recursiveTypeDescriptor() + returnType.generateReturnValueWrapper(file, self.typeDescriptor.userManagesMemory, + needsDowncast, nesting+2) def outputMethodFooter(self, methodClass, file, nesting): indent(file, nesting+1, '\n')