Author: hwright
Date: Fri Aug 5 16:47:19 2011
New Revision: 1154306
URL: http://svn.apache.org/viewvc?rev=1154306&view=rev
Log:
On the fs-py branch:
Add an empty fs module, and load it when initializing libsvn_fs_py.
* subversion/python/svn:
New module, with stub contents.
* subversion/libsvn_fs_py/fs.c
(svn_fs_py__init): Initialize the python system.
* subversion/libsvn_fs_py/fs.h:
Include Python.h.
* subversion/libsvn_fs_py/py_util.c:
New.
* subversion/libsvn_fs_py/py_util.h:
New.
Added:
subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c (with props)
subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h (with props)
subversion/branches/fs-py/subversion/python/
subversion/branches/fs-py/subversion/python/svn/ (with props)
subversion/branches/fs-py/subversion/python/svn/__init__.py (with props)
subversion/branches/fs-py/subversion/python/svn/fs.py (with props)
Modified:
subversion/branches/fs-py/subversion/libsvn_fs_py/fs.c
subversion/branches/fs-py/subversion/libsvn_fs_py/fs.h
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=1154306&r1=1154305&r2=1154306&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 16:47:19
2011
@@ -38,6 +38,7 @@
#include "tree.h"
#include "lock.h"
#include "id.h"
+#include "py_util.h"
#include "svn_private_config.h"
#include "private/svn_fs_util.h"
@@ -385,6 +386,9 @@ svn_fs_py__init(const svn_version_t *loa
loader_version->major);
SVN_ERR(svn_ver_check_list(fs_version(), checklist));
+ /* Initialize Python */
+ SVN_ERR(svn_fs_py__init_python(common_pool));
+
*vtable = &library_vtable;
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=1154306&r1=1154305&r2=1154306&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 16:47:19
2011
@@ -28,6 +28,8 @@
#include <apr_thread_mutex.h>
#include <apr_network_io.h>
+#include <Python.h>
+
#include "svn_fs.h"
#include "svn_config.h"
#include "private/svn_atomic.h"
Added: 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=1154306&view=auto
==============================================================================
--- subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c (added)
+++ subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c Fri Aug 5
16:47:19 2011
@@ -0,0 +1,115 @@
+/* py_util.c : some help for the embedded python interpreter
+ *
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ */
+
+#include <apr_pools.h>
+
+#include "svn_error.h"
+
+#include "py_util.h"
+
+#include "svn_private_config.h"
+
+#define ROOT_MODULE_NAME "svn"
+
+static PyObject *p_root_module;
+
+static svn_error_t *
+load_module(PyObject **p_module_out,
+ const char *module_name)
+{
+ PyObject *p_module_name = NULL;
+ PyObject *p_module = NULL;
+
+ p_module_name = PyString_FromString(module_name);
+ if (PyErr_Occurred())
+ goto load_error;
+
+ p_module = PyImport_Import(p_module_name);
+ Py_DECREF(p_module_name);
+ if (PyErr_Occurred())
+ goto load_error;
+
+ *p_module_out = p_module;
+
+ return SVN_NO_ERROR;
+
+load_error:
+ {
+ PyObject *p_type, *p_exception, *p_traceback;
+ PyObject *p_reason;
+ const char *reason;
+ svn_error_t *err;
+
+ /* Release the values above. */
+ Py_XDECREF(p_module);
+ *p_module_out = NULL;
+
+ PyErr_Fetch(&p_type, &p_exception, &p_traceback);
+
+ if (p_exception)
+ {
+ p_reason = PyObject_Str(p_exception);
+ reason = PyString_AsString(p_reason);
+
+ err = svn_error_createf(SVN_ERR_FS_GENERAL, NULL,
+ _("Cannot load Python module, cause: %s"),
+ reason);
+ }
+ else
+ err = svn_error_create(SVN_ERR_FS_GENERAL, NULL, NULL);
+
+ Py_XDECREF(p_exception);
+ Py_XDECREF(p_type);
+ Py_XDECREF(p_traceback);
+
+ Py_XDECREF(p_reason);
+ return err;
+ }
+}
+
+static apr_status_t
+finalize_python(void *data)
+{
+ Py_DECREF(p_root_module);
+ p_root_module = NULL;
+
+ /* Cleanup the python interpreter. */
+ Py_Finalize();
+
+ return APR_SUCCESS;
+}
+
+svn_error_t *
+svn_fs_py__init_python(apr_pool_t *pool)
+{
+ if (Py_IsInitialized())
+ return SVN_NO_ERROR;
+
+ Py_SetProgramName((char *) "svn");
+ Py_InitializeEx(0);
+ apr_pool_cleanup_register(pool, NULL, finalize_python,
+ apr_pool_cleanup_null);
+
+ SVN_ERR(load_module(&p_root_module, ROOT_MODULE_NAME));
+
+ return SVN_NO_ERROR;
+}
Propchange: subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1154306&view=auto
==============================================================================
--- subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h (added)
+++ subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h Fri Aug 5
16:47:19 2011
@@ -0,0 +1,27 @@
+/* py_util.h : some help for the embedded python interpreter
+ *
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ */
+
+#include "fs.h"
+
+/* Initialize the python interpreter and load the fs module */
+svn_error_t *
+svn_fs_py__init_python(apr_pool_t *pool);
Propchange: subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: subversion/branches/fs-py/subversion/python/svn/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug 5 16:47:19 2011
@@ -0,0 +1 @@
+*.pyc
Added: subversion/branches/fs-py/subversion/python/svn/__init__.py
URL:
http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/python/svn/__init__.py?rev=1154306&view=auto
==============================================================================
(empty)
Propchange: subversion/branches/fs-py/subversion/python/svn/__init__.py
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1154306&view=auto
==============================================================================
(empty)
Propchange: subversion/branches/fs-py/subversion/python/svn/fs.py
------------------------------------------------------------------------------
svn:eol-style = native