@@ -103,6 +103,7 @@ def Export(self, codeunit, exported_names):
103103 self .ExportNestedEnums (exported_names )
104104 self .ExportSmartPointer ()
105105 self .ExportOpaquePointerPolicies ()
106+ self .ExportAddedCode ()
106107 self .Write (codeunit )
107108 exported_names [self .Name ()] = 1
108109
@@ -372,7 +373,7 @@ def IsExportable(m):
372373 policy = ', %s%s()' % (namespaces .python , policy .Code ())
373374 # check for overloads
374375 overload = ''
375- if method .minArgs != method .maxArgs :
376+ if method .minArgs != method .maxArgs and not method_info . wrapper :
376377 # add the overloads for this method
377378 DeclareOverloads (method )
378379 overload_name = self .OverloadName (method )
@@ -637,6 +638,11 @@ def ExportOpaquePointerPolicies(self):
637638 if macro :
638639 self .Add ('declaration-outside' , macro )
639640
641+ def ExportAddedCode (self ):
642+ if self .info .__code__ :
643+ for code in self .info .__code__ :
644+ self .Add ('inside' , code )
645+
640646
641647#==============================================================================
642648# Virtual Wrapper utils
@@ -670,6 +676,9 @@ def __init__(self, class_, bases, info, codeunit):
670676 self .GenerateVirtualMethods ()
671677
672678
679+ SELF = 'py_self'
680+
681+
673682 def DefaultImplementationNames (self , method ):
674683 '''Returns a list of default implementations for this method, one for each
675684 number of default arguments. Always returns at least one name, and return from
@@ -706,8 +715,11 @@ def Declaration(self, method, indent):
706715 param_names_str = ', ' .join (param_names )
707716 if param_names_str :
708717 param_names_str = ', ' + param_names_str
709- decl += indent * 2 + '%s%scall_method< %s >(self, "%s"%s);\n ' % \
710- (return_str , python , result , rename , param_names_str )
718+
719+ self_str = self .SELF
720+
721+ decl += indent * 2 + '%(return_str)s%(python)scall_method< %(result)s >' \
722+ '(%(self_str)s, "%(rename)s"%(param_names_str)s);\n ' % locals ()
711723 decl += indent + '}\n '
712724
713725 # default implementations (with overloading)
@@ -775,8 +787,12 @@ def MethodDefinition(self, method):
775787 if method .abstract :
776788 pointer = namespaces .python + ('pure_virtual(%s)' % pointer )
777789
790+ # warn the user if this method needs a policy and doesn't have one
791+ method_info = self .info [method .name ]
792+ method_info .policy = exporterutils .HandlePolicy (method , method_info .policy )
793+
778794 # Add policy to overloaded methods also
779- policy = self . info [ method . name ]. policy or ''
795+ policy = method_info . policy or ''
780796 if policy :
781797 policy = ', %s%s()' % (namespaces .python , policy .Code ())
782798
@@ -880,10 +896,10 @@ def GenerateVirtualWrapper(self, indent):
880896 params , param_names , param_types = _ParamsInfo (cons , argNum )
881897 if params :
882898 params = ', ' + params
883- cons_code += indent + '%s(PyObject* self_ %s):\n ' % \
884- (self .wrapper_name , params )
885- cons_code += indent * 2 + '%s(%s), self(self_ ) {}\n \n ' % \
886- (class_name , ', ' .join (param_names ))
899+ cons_code += indent + '%s(PyObject* %s_ %s):\n ' % \
900+ (self .wrapper_name , self . SELF , params )
901+ cons_code += indent * 2 + '%s(%s), %s(%s_ ) {}\n \n ' % \
902+ (class_name , ', ' .join (param_names ), self . SELF , self . SELF )
887903 code += cons_code
888904 # generate the body
889905 body = []
@@ -893,6 +909,6 @@ def GenerateVirtualWrapper(self, indent):
893909 body = '\n ' .join (body )
894910 code += body + '\n '
895911 # add the self member
896- code += indent + 'PyObject* self ;\n '
912+ code += indent + 'PyObject* %s ;\n ' % self . SELF
897913 code += '};\n '
898914 return code
0 commit comments