From 31f6b54d8299d2aee45a51bc270d6844860a14ed Mon Sep 17 00:00:00 2001
From: Wim Lavrijsen <WLavrijsen@lbl.gov>
Date: Wed, 26 Oct 2011 18:35:11 +0000
Subject: [PATCH] (partly) conform to R.RS4

git-svn-id: http://root.cern.ch/svn/root/trunk@41603 27541ba8-7e3a-0410-8455-c3a389f83636
---
 bindings/pyroot/src/MethodHolder.cxx    | 2 ++
 bindings/pyroot/src/MethodProxy.cxx     | 2 ++
 bindings/pyroot/src/MethodProxy.h       | 2 ++
 bindings/pyroot/src/ObjectProxy.cxx     | 9 ++++++++-
 bindings/pyroot/src/ObjectProxy.h       | 5 ++++-
 bindings/pyroot/src/PropertyProxy.cxx   | 3 +++
 bindings/pyroot/src/PropertyProxy.h     | 1 +
 bindings/pyroot/src/PyBufferFactory.cxx | 4 ++++
 bindings/pyroot/src/PyStrings.cxx       | 3 +++
 bindings/pyroot/src/TemplateProxy.cxx   | 4 ++++
 bindings/pyroot/src/TemplateProxy.h     | 2 ++
 11 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/bindings/pyroot/src/MethodHolder.cxx b/bindings/pyroot/src/MethodHolder.cxx
index 04a60be095d..cec80cb1f24 100644
--- a/bindings/pyroot/src/MethodHolder.cxx
+++ b/bindings/pyroot/src/MethodHolder.cxx
@@ -442,6 +442,7 @@ Int_t PyROOT::TMethodHolder< T, M >::GetMaxArgs()
 template< class T, class M>
 PyObject* PyROOT::TMethodHolder< T, M >::GetArgSpec( Int_t iarg )
 {
+// Build a string representation of the arguments list.
    if ( iarg >= (int)fMethod.FunctionParameterSize() )
       return 0;
 
@@ -485,6 +486,7 @@ PyObject* PyROOT::TMethodHolder< T, M >::GetArgDefault( Int_t iarg )
 template< class T, class M>
 PyObject* PyROOT::TMethodHolder< T, M >::GetScope()
 {
+// Get or build the scope of this method.
    return MakeRootClassFromString< TScopeAdapter, TBaseAdapter, TMemberAdapter >(
       fMethod.DeclaringScope().Name( ROOT::Reflex::SCOPED | ROOT::Reflex::FINAL ) );
 }
diff --git a/bindings/pyroot/src/MethodProxy.cxx b/bindings/pyroot/src/MethodProxy.cxx
index 7e0d91517f9..d97ed7e2467 100644
--- a/bindings/pyroot/src/MethodProxy.cxx
+++ b/bindings/pyroot/src/MethodProxy.cxx
@@ -42,6 +42,7 @@ namespace {
 
       static void Clear( PyError_t& e )
       {
+      // Remove exception information.
          Py_XDECREF( e.fType ); Py_XDECREF( e.fValue ); Py_XDECREF( e.fTrace );
          e.fType = e.fValue = e.fTrace = 0;
       }
@@ -52,6 +53,7 @@ namespace {
 // helper to hash tuple (using tuple hash would cause self-tailing loops)
    inline Long_t HashSignature( PyObject* args )
    {
+   // Build a hash from the types of the given python function arguments.
       ULong_t hash = 0;
 
       Int_t nargs = PyTuple_GET_SIZE( args );
diff --git a/bindings/pyroot/src/MethodProxy.h b/bindings/pyroot/src/MethodProxy.h
index 5d449d4fc5b..6c3c5e2ae7c 100644
--- a/bindings/pyroot/src/MethodProxy.h
+++ b/bindings/pyroot/src/MethodProxy.h
@@ -87,6 +87,7 @@ namespace PyROOT {
    inline MethodProxy* MethodProxy_New(
          const std::string& name, std::vector< PyCallable* >& methods )
    {
+   // Create and initialize a new method proxy from the overloads.
       MethodProxy* pymeth = (MethodProxy*)MethodProxy_Type.tp_new( &MethodProxy_Type, 0, 0 );
       pymeth->Set( name, methods );
       return pymeth;
@@ -94,6 +95,7 @@ namespace PyROOT {
 
    inline MethodProxy* MethodProxy_New( const std::string& name, PyCallable* method )
    {
+   // Create and initialize a new method proxy from the method.
       std::vector< PyCallable* > p;
       p.push_back( method );
       return MethodProxy_New( name, p );
diff --git a/bindings/pyroot/src/ObjectProxy.cxx b/bindings/pyroot/src/ObjectProxy.cxx
index d4d65bd3127..4c47ed7a726 100644
--- a/bindings/pyroot/src/ObjectProxy.cxx
+++ b/bindings/pyroot/src/ObjectProxy.cxx
@@ -17,6 +17,7 @@ R__EXTERN PyObject* gRootModule;
 
 //____________________________________________________________________________
 void PyROOT::op_dealloc_nofree( ObjectProxy* pyobj ) {
+// Destroy the held C++ object, if owned; does not deallocate the proxy.
    if ( pyobj->fObject && ( pyobj->fFlags & ObjectProxy::kIsOwner ) ) {
       pyobj->ObjectIsA()->Destructor( pyobj->fObject );
    }
@@ -28,9 +29,10 @@ namespace PyROOT {
 
 namespace {
 
-//= PyROOT object proxy nullness checking ====================================
+//= PyROOT object proxy null-ness checking ===================================
    PyObject* op_nonzero( ObjectProxy* self )
    {
+   // Null of the proxy is determined by null-ness of the held C++ object.
       PyObject* result = self->GetObject() ? Py_True : Py_False;
       Py_INCREF( result );
       return result;
@@ -97,6 +99,7 @@ namespace {
 //= PyROOT object proxy construction/destruction =============================
    ObjectProxy* op_new( PyTypeObject* subtype, PyObject*, PyObject* )
    {
+   // Create a new object proxy (holder only).
       ObjectProxy* pyobj = (ObjectProxy*)subtype->tp_alloc( subtype, 0 );
       pyobj->fObject = NULL;
       pyobj->fFlags  = 0;
@@ -107,6 +110,7 @@ namespace {
 //____________________________________________________________________________
    void op_dealloc( ObjectProxy* pyobj )
    {
+   // Remove memory held by the object proxy.
       op_dealloc_nofree( pyobj );
       Py_TYPE(pyobj)->tp_free( (PyObject*)pyobj );
    }
@@ -114,6 +118,7 @@ namespace {
 //____________________________________________________________________________
    PyObject* op_richcompare( ObjectProxy* self, ObjectProxy* other, int op )
    {
+   // Rich set of comparison objects; only equals and not-equals are defined.
       if ( op != Py_EQ && op != Py_NE ) {
          Py_INCREF( Py_NotImplemented );
          return Py_NotImplemented;
@@ -142,6 +147,8 @@ namespace {
 //____________________________________________________________________________
    PyObject* op_repr( ObjectProxy* pyobj )
    {
+   // Build a representation string of the object proxy that shows the address
+   // of the C++ object that is held, as well as its type.
       TClass* klass = pyobj->ObjectIsA();
       std::string clName = klass ? klass->GetName() : "<unknown>";
       if ( pyobj->fFlags & ObjectProxy::kIsReference )
diff --git a/bindings/pyroot/src/ObjectProxy.h b/bindings/pyroot/src/ObjectProxy.h
index 2440915c205..f43c66df4e0 100644
--- a/bindings/pyroot/src/ObjectProxy.h
+++ b/bindings/pyroot/src/ObjectProxy.h
@@ -29,18 +29,21 @@ namespace PyROOT {
    public:
       void Set( void** address, EFlags flags = kNone )
       {
+      // Initialize the proxy with the pointer value 'address.'
          fObject = (void*) address;
          fFlags  = flags | kIsReference;
       }
  
       void Set( void* object, EFlags flags = kNone )
       {
+      // Initialize the proxy with the given 'object.'
          fObject = object;
          fFlags  = flags & ~kIsReference;
       }
 
       void* GetObject() const
       {
+      // Retrieve a pointer to the held C++ object.
          if ( fObject && ( fFlags & kIsReference ) )
             return *(reinterpret_cast< void** >( const_cast< void* >( fObject ) ));
          else
@@ -49,7 +52,7 @@ namespace PyROOT {
 
       TClass* ObjectIsA() const
       {
-      // the following may return null
+      // Retrieve a pointer to the C++ type; may return NULL.
          return ((PyRootClass*)Py_TYPE(this))->fClass.GetClass();
       }
 
diff --git a/bindings/pyroot/src/PropertyProxy.cxx b/bindings/pyroot/src/PropertyProxy.cxx
index 832a2778ba5..be09918c38f 100644
--- a/bindings/pyroot/src/PropertyProxy.cxx
+++ b/bindings/pyroot/src/PropertyProxy.cxx
@@ -68,6 +68,7 @@ namespace {
 //____________________________________________________________________________
    int pp_set( PropertyProxy* pyprop, ObjectProxy* pyobj, PyObject* value )
    {
+   // Set the value of the C++ datum held.
       const int errret = -1;
 
    // filter const objects and enums to prevent changing their values
@@ -101,6 +102,7 @@ namespace {
 //= PyROOT property proxy construction/destruction ===========================
    PropertyProxy* pp_new( PyTypeObject* pytype, PyObject*, PyObject* )
    {
+   // Create and initialize a new property descriptor.
       PropertyProxy* pyprop = (PropertyProxy*)pytype->tp_alloc( pytype, 0 );
       pyprop->fConverter = 0;
       new ( &pyprop->fName ) std::string();
@@ -111,6 +113,7 @@ namespace {
 //____________________________________________________________________________
    void pp_dealloc( PropertyProxy* pyprop )
    {
+   // Deallocate memory held by this descriptor.
       using namespace std;
       pyprop->fName.~string();
       delete pyprop->fConverter;
diff --git a/bindings/pyroot/src/PropertyProxy.h b/bindings/pyroot/src/PropertyProxy.h
index 7d97b426e9d..bb05cdbb52d 100644
--- a/bindings/pyroot/src/PropertyProxy.h
+++ b/bindings/pyroot/src/PropertyProxy.h
@@ -79,6 +79,7 @@ namespace PyROOT {
    template< class T >
    inline PropertyProxy* PropertyProxy_New( const T& dmi )
    {
+   // Create an initialize a new property descriptor, given the C++ datum.
       PropertyProxy* pyprop =
          (PropertyProxy*)PropertyProxy_Type.tp_new( &PropertyProxy_Type, 0, 0 );
       pyprop->Set( dmi );
diff --git a/bindings/pyroot/src/PyBufferFactory.cxx b/bindings/pyroot/src/PyBufferFactory.cxx
index ab7bade3ae0..fb07b17ff2f 100644
--- a/bindings/pyroot/src/PyBufferFactory.cxx
+++ b/bindings/pyroot/src/PyBufferFactory.cxx
@@ -52,6 +52,7 @@ namespace {
 // implement get, str, and length functions
    Py_ssize_t buffer_length( PyObject* self )
    {
+   // Retrieve the (type-strided) size of the the buffer; may be a guess.
 #if PY_VERSION_HEX < 0x03000000
       Py_ssize_t nlen = (*(PyBuffer_Type.tp_as_sequence->sq_length))(self);
 #else
@@ -80,6 +81,7 @@ namespace {
 //____________________________________________________________________________
    const char* buffer_get( PyObject* self, int idx )
    {
+   // Retrieve the buffer as a linear char array.
       if ( idx < 0 || idx >= buffer_length( self ) ) {
          PyErr_SetString( PyExc_IndexError, "buffer index out of range" );
          return 0;
@@ -152,6 +154,7 @@ namespace {
    PYROOT_IMPLEMENT_PYBUFFER_METHODS( Double, Double_t, Double_t, PyFloat_FromDouble, PyFloat_AsDouble )
 
    int pyroot_buffer_ass_subscript( PyObject* self, PyObject* idx, PyObject* val ) {
+   // Assign the given value 'val' to the item at index 'idx.'
       if ( PyIndex_Check( idx ) ) {
          Py_ssize_t i = PyNumber_AsSsize_t( idx, PyExc_IndexError );
          if ( i == -1 && PyErr_Occurred() )
@@ -167,6 +170,7 @@ namespace {
 //____________________________________________________________________________
    PyObject* buffer_setsize( PyObject* self, PyObject* pynlen )
    {
+   // Allow the user to fix up the actual (type-strided) size of the buffer.
       Py_ssize_t nlen = PyInt_AsSsize_t( pynlen );
       if ( nlen == -1 && PyErr_Occurred() )
          return 0;
diff --git a/bindings/pyroot/src/PyStrings.cxx b/bindings/pyroot/src/PyStrings.cxx
index 78c03d0f1c3..63ce341b7b5 100644
--- a/bindings/pyroot/src/PyStrings.cxx
+++ b/bindings/pyroot/src/PyStrings.cxx
@@ -55,6 +55,8 @@ PyObject* PyROOT::PyStrings::gTClassDynCast = 0;
       return kFALSE
 
 Bool_t PyROOT::CreatePyStrings() {
+// Build cache of commonly used python strings (the cache is python intern, so
+// all strings are shared python-wide, not just in PyROOT).
    PYROOT_INITIALIZE_STRING( gBases, __bases__ );
    PYROOT_INITIALIZE_STRING( gBase, __base__ );
    PYROOT_INITIALIZE_STRING( gClass, __class__ );
@@ -103,6 +105,7 @@ Bool_t PyROOT::CreatePyStrings() {
 
 //____________________________________________________________________________
 PyObject* PyROOT::DestroyPyStrings() {
+// Remove all cached python strings.
    Py_DECREF( PyStrings::gBases ); PyStrings::gBases = 0;
    Py_DECREF( PyStrings::gBase ); PyStrings::gBase = 0;
    Py_DECREF( PyStrings::gClass ); PyStrings::gClass = 0;
diff --git a/bindings/pyroot/src/TemplateProxy.cxx b/bindings/pyroot/src/TemplateProxy.cxx
index 1ea1caaac43..cddcf39050d 100644
--- a/bindings/pyroot/src/TemplateProxy.cxx
+++ b/bindings/pyroot/src/TemplateProxy.cxx
@@ -13,6 +13,7 @@ namespace {
 //= PyROOT template proxy construction/destruction ===========================
    TemplateProxy* tpp_new( PyTypeObject*, PyObject*, PyObject* )
    {
+   // Create a new empty template method proxy.
       TemplateProxy* pytmpl = PyObject_GC_New( TemplateProxy, &TemplateProxy_Type );
       pytmpl->fPyName  = NULL;
       pytmpl->fPyClass = NULL;
@@ -25,6 +26,7 @@ namespace {
 //____________________________________________________________________________
    void tpp_dealloc( TemplateProxy* pytmpl )
    {
+   // Destroy the given template method proxy.
       PyObject_GC_UnTrack( pytmpl );
       PyObject_GC_Del( pytmpl );
    }
@@ -32,6 +34,7 @@ namespace {
 //____________________________________________________________________________
    int tpp_traverse( TemplateProxy* pytmpl, visitproc visit, void* args )
    {
+   // Garbage collector traverse of held python member objects.
       if ( pytmpl->fPyName ) {
          int err = visit( (PyObject*)pytmpl->fPyName, args );
          if ( err )
@@ -56,6 +59,7 @@ namespace {
 //____________________________________________________________________________
    int tpp_clear( TemplateProxy* pytmpl )
    {
+   // Garbage collector clear of held python member objects.
       Py_XDECREF( (PyObject*)pytmpl->fPyName );
       pytmpl->fPyName = NULL;
 
diff --git a/bindings/pyroot/src/TemplateProxy.h b/bindings/pyroot/src/TemplateProxy.h
index bce8ea610ae..1b78d3d8312 100644
--- a/bindings/pyroot/src/TemplateProxy.h
+++ b/bindings/pyroot/src/TemplateProxy.h
@@ -22,6 +22,7 @@ namespace PyROOT {
    public:
       void Set( const std::string& name, PyObject* pyclass )
       {
+      // Initialize the proxy for the given 'pyclass.'
          fPyName  = PyROOT_PyUnicode_FromString( const_cast< char* >( name.c_str() ) );
          Py_XINCREF( pyclass );
          fPyClass = pyclass;
@@ -56,6 +57,7 @@ namespace PyROOT {
 //- creation -----------------------------------------------------------------
    inline TemplateProxy* TemplateProxy_New( const std::string& name, PyObject* pyclass )
    {
+   // Create and initialize a new template method proxy for the class.
       TemplateProxy* pytmpl = (TemplateProxy*)TemplateProxy_Type.tp_new( &TemplateProxy_Type, 0, 0 );
       pytmpl->Set( name, pyclass );
       return pytmpl;
-- 
GitLab