diff --git a/pybindgen/cppclass_typehandlers.py b/pybindgen/cppclass_typehandlers.py index e1d5701..29e0ff6 100644 --- a/pybindgen/cppclass_typehandlers.py +++ b/pybindgen/cppclass_typehandlers.py @@ -669,6 +669,8 @@ class CppClassPtrParameter(CppClassParameterBase): def __init__(self, ctype, name, transfer_ownership=None, custodian=None, is_const=False, null_ok=False, default_value=None): """ + Type handler for a pointer-to-class parameter (MyClass*) + @param ctype: C type, normally 'MyClass*' @param name: parameter name @@ -682,27 +684,27 @@ class CppClassPtrParameter(CppClassParameterBase): pointer dereference and crash the program). @param custodian: if given, points to an object (custodian) - that keeps the python wrapper for the - parameter alive. Possible values are: + that keeps the python wrapper for the + parameter alive. Possible values are: - None: no object is custodian; - -1: the return value object; - 0: the instance of the method in which - the ReturnValue is being used will become the - custodian; + the ReturnValue is being used will become the + custodian; - integer > 0: parameter number, starting at 1 - (i.e. not counting the self/this parameter), - whose object will be used as custodian. + (i.e. not counting the self/this parameter), + whose object will be used as custodian. @param is_const: if true, the parameter has a const attached to the leftmost @param null_ok: if true, None is accepted and mapped into a C NULL pointer @param default_value: default parameter value (as C expression - string); probably, the only default value that makes sense - here is probably 'NULL'. + string); probably, the only default value that makes sense + here is probably 'NULL'. @note: only arguments which are instances of C++ classes - wrapped by PyBindGen can be used as custodians. + wrapped by PyBindGen can be used as custodians. """ if ctype == self.cpp_class.name: ctype = self.cpp_class.full_name @@ -961,16 +963,16 @@ class CppClassPtrReturnValue(CppClassReturnValueBase): is transferred to the caller @param custodian: bind the life cycle of the python wrapper - for the return value object (ward) to that - of the object indicated by this parameter - (custodian). Possible values are: + for the return value object (ward) to that + of the object indicated by this parameter + (custodian). Possible values are: - None: no object is custodian; - 0: the instance of the method in which - the ReturnValue is being used will become the - custodian; + the ReturnValue is being used will become the + custodian; - integer > 0: parameter number, starting at 1 - (i.e. not counting the self/this parameter), - whose object will be used as custodian. + (i.e. not counting the self/this parameter), + whose object will be used as custodian. @param reference_existing_object: if true, ownership of the pointed-to object remains to be the caller's, but we @@ -990,7 +992,7 @@ class CppClassPtrReturnValue(CppClassReturnValueBase): return value. @note: only arguments which are instances of C++ classes - wrapped by PyBindGen can be used as custodians. + wrapped by PyBindGen can be used as custodians. """ if ctype == self.cpp_class.name: ctype = self.cpp_class.full_name diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index ea57509..cd60c4f 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -128,7 +128,34 @@ class CppMethod(ForwardWrapperBase): def add_custodian_and_ward(self, custodian, ward, postcall=None): - """ TODO: document this """ + """Add a custodian/ward relationship to the method wrapper + + A custodian/ward relationship is one where one object + (custodian) keeps a references to another object (ward), thus + keeping it alive. When the custodian is destroyed, the + reference to the ward is released, allowing the ward to be + freed if no other reference to it is being kept by the user + code. Please note that custodian/ward manages the lifecycle + of Python wrappers, not the C/C++ objects referenced by the + wrappers. In most cases, the wrapper owns the C/C++ object, + and so the lifecycle of the C/C++ object is also managed by + this. However, there are cases when a Python wrapper does not + own the underlying C/C++ object, only references it. + + The custodian and ward objects are indicated by an integer + with the following meaning: + - C{-1}: the return value of the function + - C{0}: the instance of the method (self) + - value > 0: the nth parameter of the function, starting at 1 + + @parameter custodian: number of the object that assumes the role of custodian + @parameter ward: number of the object that assumes the role of ward + + @parameter postcall: if True, the relationship is added after + the C function call, if False it is added before the + call. If not given, the value False is assumed if the + return value is not involved, else postcall=True is used. + """ if custodian == -1 or ward == -1: if postcall is None: postcall = True @@ -490,7 +517,33 @@ class CppConstructor(ForwardWrapperBase): def add_custodian_and_ward(self, custodian, ward, postcall=None): - """ TODO: document this """ + """Add a custodian/ward relationship to the constructor wrapper + + A custodian/ward relationship is one where one object + (custodian) keeps a references to another object (ward), thus + keeping it alive. When the custodian is destroyed, the + reference to the ward is released, allowing the ward to be + freed if no other reference to it is being kept by the user + code. Please note that custodian/ward manages the lifecycle + of Python wrappers, not the C/C++ objects referenced by the + wrappers. In most cases, the wrapper owns the C/C++ object, + and so the lifecycle of the C/C++ object is also managed by + this. However, there are cases when a Python wrapper does not + own the underlying C/C++ object, only references it. + + The custodian and ward objects are indicated by an integer + with the following meaning: + - C{0}: the object being constructed (self) + - value > 0: the nth parameter of the function, starting at 1 + + @parameter custodian: number of the object that assumes the role of custodian + @parameter ward: number of the object that assumes the role of ward + + @parameter postcall: if True, the relationship is added after + the C function call, if False it is added before the + call. If not given, the value False is assumed if the + return value is not involved, else postcall=True is used. + """ if custodian == -1 or ward == -1: if postcall is None: postcall = True diff --git a/pybindgen/function.py b/pybindgen/function.py index a633360..331a10a 100644 --- a/pybindgen/function.py +++ b/pybindgen/function.py @@ -104,7 +104,33 @@ class Function(ForwardWrapperBase): return func def add_custodian_and_ward(self, custodian, ward, postcall=None): - """ TODO: document this """ + """Add a custodian/ward relationship to the function wrapper + + A custodian/ward relationship is one where one object + (custodian) keeps a references to another object (ward), thus + keeping it alive. When the custodian is destroyed, the + reference to the ward is released, allowing the ward to be + freed if no other reference to it is being kept by the user + code. Please note that custodian/ward manages the lifecycle + of Python wrappers, not the C/C++ objects referenced by the + wrappers. In most cases, the wrapper owns the C/C++ object, + and so the lifecycle of the C/C++ object is also managed by + this. However, there are cases when a Python wrapper does not + own the underlying C/C++ object, only references it. + + The custodian and ward objects are indicated by an integer + with the following meaning: + - C{-1}: the return value of the function + - value > 0: the nth parameter of the function, starting at 1 + + @parameter custodian: number of the object that assumes the role of custodian + @parameter ward: number of the object that assumes the role of ward + + @parameter postcall: if True, the relationship is added after + the C function call, if False it is added before the + call. If not given, the value False is assumed if the + return value is not involved, else postcall=True is used. + """ if custodian == -1 or ward == -1: if postcall is None: postcall = True diff --git a/wscript b/wscript index f3005dc..0f1bbf0 100644 --- a/wscript +++ b/wscript @@ -333,6 +333,7 @@ def generate_api_docs(ctx): "--pstat=build/foomodulegen.pstat", "--pstat=build/hellomodulegen.pstat", "--no-private", + #"--graph-image-format=png", ]).wait() if retval: Logs.error("epydoc returned with code %i" % retval)