Author: hwright
Date: Fri Aug  5 22:13:44 2011
New Revision: 1154393

URL: http://svn.apache.org/viewvc?rev=1154393&view=rev
Log:
On the fs-py branch:
Load the FS Python module, and call a stub create method on it when the
cooresponding C API is called.

* subversion/python/svn/fs.py:
  Implement.

* subversion/libsvn_fs_py/fs.c
  (initialize_fs_struct): Load the FS module.

* subversion/libsvn_fs_py/fs.h
  (fs_fs_data_t): Add p_module and p_fs object references.
 
* subversion/libsvn_fs_py/fs_fs.c
  (svn_fs_py__create): Call the creation method, and ensure we cleanup the
    result.

* subversion/libsvn_fs_py/py_util.c
  (svn_fs_py__destroy_py_object,
   svn_fs_py__call_method,
   svn_fs_py__convert_hash,
   svn_fs_py__load_module): New.

* subversion/libsvn_fs_py/py_util.h
  (svn_fs_py__destroy_py_object,
   svn_fs_py__call_method,
   svn_fs_py__convert_hash,
   svn_fs_py__load_module): New.

Modified:
    subversion/branches/fs-py/subversion/libsvn_fs_py/fs.c
    subversion/branches/fs-py/subversion/libsvn_fs_py/fs.h
    subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c
    subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c
    subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h
    subversion/branches/fs-py/subversion/python/svn/fs.py

Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/fs.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/fs.c?rev=1154393&r1=1154392&r2=1154393&view=diff
==============================================================================
--- subversion/branches/fs-py/subversion/libsvn_fs_py/fs.c (original)
+++ subversion/branches/fs-py/subversion/libsvn_fs_py/fs.c Fri Aug  5 22:13:44 
2011
@@ -171,6 +171,12 @@ static svn_error_t *
 initialize_fs_struct(svn_fs_t *fs)
 {
   fs_fs_data_t *ffd = apr_pcalloc(fs->pool, sizeof(*ffd));
+
+  SVN_ERR(svn_fs_py__load_module(ffd));
+  apr_pool_cleanup_register(fs->pool, ffd->p_module,
+                            svn_fs_py__destroy_py_object,
+                            apr_pool_cleanup_null);
+
   fs->vtable = &fs_vtable;
   fs->fsap_data = ffd;
   return SVN_NO_ERROR;

Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/fs.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/fs.h?rev=1154393&r1=1154392&r2=1154393&view=diff
==============================================================================
--- subversion/branches/fs-py/subversion/libsvn_fs_py/fs.h (original)
+++ subversion/branches/fs-py/subversion/libsvn_fs_py/fs.h Fri Aug  5 22:13:44 
2011
@@ -274,6 +274,12 @@ typedef struct fs_fs_data_t
   /* Whether rep-sharing is supported by the filesystem
    * and allowed by the configuration. */
   svn_boolean_t rep_sharing_allowed;
+
+  /* The Python FS module object. */
+  PyObject *p_module;
+
+  /* The Python FS object. */
+  PyObject *p_fs;
 } fs_fs_data_t;
 
 

Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c?rev=1154393&r1=1154392&r2=1154393&view=diff
==============================================================================
--- subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c (original)
+++ subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c Fri Aug  5 
22:13:44 2011
@@ -58,6 +58,7 @@
 #include "id.h"
 #include "rep-cache.h"
 #include "temp_serializer.h"
+#include "py_util.h"
 
 #include "private/svn_fs_util.h"
 #include "../libsvn_fs/fs-loader.h"
@@ -6577,6 +6578,13 @@ svn_fs_py__create(svn_fs_t *fs,
   fs_fs_data_t *ffd = fs->fsap_data;
 
   fs->path = apr_pstrdup(pool, path);
+
+  SVN_ERR(svn_fs_py__call_method(&ffd->p_fs, ffd->p_module, "_create_fs",
+                                 "(sO&)", path,
+                                 svn_fs_py__convert_hash, fs->config));
+  apr_pool_cleanup_register(fs->pool, ffd->p_fs, svn_fs_py__destroy_py_object,
+                            apr_pool_cleanup_null);
+
   /* See if compatibility with older versions was explicitly requested. */
   if (fs->config)
     {

Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c?rev=1154393&r1=1154392&r2=1154393&view=diff
==============================================================================
--- subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c (original)
+++ subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c Fri Aug  5 
22:13:44 2011
@@ -29,6 +29,7 @@
 #include "svn_private_config.h"
 
 #define ROOT_MODULE_NAME "svn"
+#define FS_MODULE_NAME "svn.fs"
 
 static PyObject *p_exception_type;
 static PyObject *p_root_module;
@@ -196,3 +197,130 @@ svn_fs_py__init_python(apr_pool_t *pool)
 
   return SVN_NO_ERROR;
 }
+
+
+apr_status_t
+svn_fs_py__destroy_py_object(void *data)
+{
+  PyObject *p_fs = data;
+  Py_XDECREF(p_fs);
+
+  return APR_SUCCESS;
+}
+
+
+svn_error_t*
+svn_fs_py__call_method(PyObject **p_result,
+                       PyObject *p_obj,
+                       const char *name,
+                       const char *format,
+                       ...)
+{
+  PyObject *p_func = NULL;
+  PyObject *p_value = NULL;
+  PyObject *p_args = NULL;
+  va_list argp;
+
+  SVN_ERR_ASSERT(p_obj != NULL);
+
+  va_start(argp, format);
+
+  p_args = Py_VaBuildValue(format, argp);
+  if (PyErr_Occurred())
+    goto create_error;
+
+  p_func = PyObject_GetAttrString(p_obj, name);
+  if (PyErr_Occurred())
+    goto create_error;
+    
+  /* ### Need a callable check here? */
+
+  p_value = PyObject_CallObject(p_func, p_args);
+  Py_DECREF(p_args);
+  p_args = NULL;
+  if (PyErr_Occurred())
+    goto create_error;
+
+  if (p_result)
+    *p_result = p_value;
+  else
+    Py_DECREF(p_value);
+
+  Py_DECREF(p_func);
+
+  va_end(argp);
+  return SVN_NO_ERROR;
+
+create_error:
+  {
+    PyObject *p_type = NULL;
+    PyObject *p_exception = NULL;
+    PyObject *p_traceback = NULL;
+    svn_error_t *err;
+
+    va_end(argp);
+    Py_XDECREF(p_args);
+    Py_XDECREF(p_func);
+
+    PyErr_Fetch(&p_type, &p_exception, &p_traceback);
+
+    if (p_exception && p_traceback)
+      err = create_py_stack(p_exception, p_traceback);
+    else
+      err = svn_error_create(SVN_ERR_BAD_PYTHON, NULL,
+                             _("Error calling method"));
+
+    PyErr_Clear();
+
+    Py_DECREF(p_type);
+    Py_XDECREF(p_exception);
+    Py_XDECREF(p_traceback);
+
+    return err;
+  }
+}
+
+PyObject *
+svn_fs_py__convert_hash(void *object)
+{
+  apr_hash_t *hash = object;
+  apr_hash_index_t *hi;
+  PyObject *p_dict;
+
+  if (hash == NULL)
+    Py_RETURN_NONE;
+
+  if ((p_dict = PyDict_New()) == NULL)
+    return NULL;
+
+  for (hi = apr_hash_first(NULL, hash); hi; hi = apr_hash_next(hi))
+    {
+      const void *key;
+      void *val;
+      PyObject *value;
+
+      apr_hash_this(hi, &key, NULL, &val);
+      value = PyString_FromString(val);
+      if (value == NULL)
+        {
+          Py_DECREF(p_dict);
+          return NULL;
+        }
+      /* ### gotta cast this thing cuz Python doesn't use "const" */
+      if (PyDict_SetItemString(p_dict, (char *)key, value) == -1)
+        {
+          Py_DECREF(value);
+          Py_DECREF(p_dict);
+          return NULL;
+        }
+      Py_DECREF(value);
+    }
+
+  return p_dict;
+}
+
+svn_error_t *
+svn_fs_py__load_module(fs_fs_data_t *ffd)
+{
+  return svn_error_trace(load_module(&ffd->p_module, FS_MODULE_NAME));
+}

Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h?rev=1154393&r1=1154392&r2=1154393&view=diff
==============================================================================
--- subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h (original)
+++ subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h Fri Aug  5 
22:13:44 2011
@@ -25,3 +25,24 @@
 /* Initialize the python interpreter and load the fs module */
 svn_error_t *
 svn_fs_py__init_python(apr_pool_t *pool);
+
+/* Destroy the PyObject pointed to by DATA.
+ * This function in mainly used to cleanup Python objects on pool cleanup. */
+apr_status_t
+svn_fs_py__destroy_py_object(void *data);
+
+/* Call NAME method of P_OBJ, putting the result in *P_RESULT.  If an
+ * exception is raised by the Python method, convert it to an svn_error_t. */
+svn_error_t*
+svn_fs_py__call_method(PyObject **p_result,
+                       PyObject *p_obj,
+                       const char *name,
+                       const char *format,
+                       ...);
+
+PyObject *
+svn_fs_py__convert_hash(void *object);
+
+/* Load a reference to the FS Python module into the shared data. */
+svn_error_t *
+svn_fs_py__load_module(fs_fs_data_t *ffd);

Modified: subversion/branches/fs-py/subversion/python/svn/fs.py
URL: 
http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/python/svn/fs.py?rev=1154393&r1=1154392&r2=1154393&view=diff
==============================================================================
--- subversion/branches/fs-py/subversion/python/svn/fs.py (original)
+++ subversion/branches/fs-py/subversion/python/svn/fs.py Fri Aug  5 22:13:44 
2011
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+
+# A few helper functions for C callers
+def _create_fs(path, config=None):
+    return "this is a filesystem object"


Reply via email to