2 * swigutil_py.c: utility functions for the SWIG Python bindings
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* Tell swigutil_py.h that we're inside the implementation */
20 #define SVN_SWIG_SWIGUTIL_PY_C
24 #include <sys/types.h>
28 #include <apr_pools.h>
30 #include <apr_portable.h>
31 #include <apr_thread_proc.h>
33 #include "svn_client.h"
34 #include "svn_string.h"
36 #include "svn_delta.h"
38 #include "svn_pools.h"
39 #include "svn_mergeinfo.h"
40 #include "svn_types.h"
42 #include "svn_private_config.h" /* for SVN_APR_INT64_T_PYCFMT */
44 #include "swig_python_external_runtime.swg"
45 #include "swigutil_py.h"
47 /* Define handy Python 2.4 macro if this is older Python. */
48 #ifndef Py_RETURN_NONE
49 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
54 /*** Manage the Global Interpreter Lock ***/
56 /* If both Python and APR have threads available, we can optimize ourselves
57 * by releasing the global interpreter lock when we drop into our SVN calls.
59 * In svn_types.i, svn_swig_py_release_py_lock is called before every
60 * function, then svn_swig_py_acquire_py_lock is called after every
61 * function. So, if these functions become no-ops, then Python will
64 * The Subversion libraries can be assumed to be thread-safe *only* when
65 * APR_HAS_THREAD is 1. The APR pool allocations aren't thread-safe unless
66 * APR_HAS_THREAD is 1.
69 #if defined(WITH_THREAD) && APR_HAS_THREADS
70 #define ACQUIRE_PYTHON_LOCK
73 #ifdef ACQUIRE_PYTHON_LOCK
74 static apr_threadkey_t
*_saved_thread_key
= NULL
;
75 static apr_pool_t
*_saved_thread_pool
= NULL
;
78 void svn_swig_py_release_py_lock(void)
80 #ifdef ACQUIRE_PYTHON_LOCK
81 PyThreadState
*thread_state
;
83 if (_saved_thread_key
== NULL
)
85 /* Obviously, creating a top-level pool for this is pretty stupid. */
86 apr_pool_create(&_saved_thread_pool
, NULL
);
87 apr_threadkey_private_create(&_saved_thread_key
, NULL
,
91 thread_state
= PyEval_SaveThread();
92 apr_threadkey_private_set(thread_state
, _saved_thread_key
);
96 void svn_swig_py_acquire_py_lock(void)
98 #ifdef ACQUIRE_PYTHON_LOCK
100 PyThreadState
*thread_state
;
101 apr_threadkey_private_get(&val
, _saved_thread_key
);
103 PyEval_RestoreThread(thread_state
);
109 /*** Automatic Pool Management Functions ***/
111 /* The application pool */
112 static apr_pool_t
*application_pool
= NULL
;
113 static PyObject
*application_py_pool
= NULL
;
114 static char assertValid
[] = "assert_valid";
115 static char markValid
[] = "_mark_valid";
116 static char parentPool
[] = "_parent_pool";
117 static char wrap
[] = "_wrap";
118 static char unwrap
[] = "_unwrap";
119 static char setParentPool
[] = "set_parent_pool";
120 static char emptyTuple
[] = "()";
121 static char objectTuple
[] = "(O)";
124 apr_status_t
svn_swig_py_initialize(void)
128 if ((status
= apr_initialize()) != APR_SUCCESS
)
130 if (atexit(apr_terminate
) != 0)
135 int svn_swig_py_get_pool_arg(PyObject
*args
, swig_type_info
*type
,
136 PyObject
**py_pool
, apr_pool_t
**pool
)
138 int argnum
= PyTuple_GET_SIZE(args
) - 1;
142 PyObject
*input
= PyTuple_GET_ITEM(args
, argnum
);
143 if (input
!= Py_None
&& PyObject_HasAttrString(input
, markValid
))
145 *pool
= svn_swig_MustGetPtr(input
, type
, argnum
+1);
154 /* We couldn't find a pool argument, so we'll create a subpool */
155 *pool
= svn_pool_create(application_pool
);
156 *py_pool
= svn_swig_NewPointerObj(*pool
, type
, application_py_pool
,
158 if (*py_pool
== NULL
)
164 int svn_swig_py_get_parent_pool(PyObject
*args
, swig_type_info
*type
,
165 PyObject
**py_pool
, apr_pool_t
**pool
)
167 PyObject
*proxy
= PyTuple_GetItem(args
, 0);
172 *py_pool
= PyObject_GetAttrString(proxy
, parentPool
);
174 if (*py_pool
== NULL
)
176 PyErr_SetString(PyExc_TypeError
,
177 "Unexpected NULL parent pool on proxy object");
183 *pool
= svn_swig_MustGetPtr(*py_pool
, type
, 1);
191 /* Set the application pool */
192 void svn_swig_py_set_application_pool(PyObject
*py_pool
, apr_pool_t
*pool
)
194 application_pool
= pool
;
195 application_py_pool
= py_pool
;
198 /* Clear the application pool */
199 void svn_swig_py_clear_application_pool()
201 application_pool
= NULL
;
202 application_py_pool
= NULL
;
205 /* Set the parent pool of a proxy object */
206 static int proxy_set_pool(PyObject
**proxy
, PyObject
*pool
)
214 if (PyObject_HasAttrString(*proxy
, setParentPool
))
216 result
= PyObject_CallMethod(*proxy
, setParentPool
, emptyTuple
);
224 result
= PyObject_CallMethod(pool
, wrap
, objectTuple
, *proxy
);
234 /* Wrapper for SWIG_TypeQuery */
235 #define svn_swig_TypeQuery(x) SWIG_TypeQuery(x)
237 /** Wrapper for SWIG_NewPointerObj */
238 PyObject
*svn_swig_NewPointerObj(void *obj
, swig_type_info
*type
,
239 PyObject
*pool
, PyObject
*args
)
241 PyObject
*proxy
= SWIG_NewPointerObj(obj
, type
, 0);
246 if (pool
== NULL
&& args
!= NULL
)
249 if (svn_swig_py_get_parent_pool(args
,
250 svn_swig_TypeQuery("apr_pool_t *"), &pool
, &tmp
))
254 if (proxy_set_pool(&proxy
, pool
))
263 /** svn_swig_NewPointerObj, except a string is used to describe the type */
264 static PyObject
*svn_swig_NewPointerObjString(void *ptr
, const char *type
,
267 swig_type_info
*typeinfo
= svn_swig_TypeQuery(type
);
268 if (typeinfo
== NULL
)
270 PyErr_SetString(PyExc_TypeError
, "Cannot find required typeobject");
274 /* ### cache the swig_type_info at some point? */
275 return svn_swig_NewPointerObj(ptr
, typeinfo
, py_pool
, NULL
);
278 /** Wrapper for SWIG_ConvertPtr */
279 int svn_swig_ConvertPtr(PyObject
*input
, void **obj
, swig_type_info
*type
)
281 if (PyObject_HasAttrString(input
, assertValid
))
283 PyObject
*result
= PyObject_CallMethod(input
, assertValid
, emptyTuple
);
288 if (PyObject_HasAttrString(input
, unwrap
))
290 input
= PyObject_CallMethod(input
, unwrap
, emptyTuple
);
296 return SWIG_ConvertPtr(input
, obj
, type
, SWIG_POINTER_EXCEPTION
| 0);
299 /** svn_swig_ConvertPtr, except a string is used to describe the type */
300 static int svn_swig_ConvertPtrString(PyObject
*input
,
301 void **obj
, const char *type
)
303 return svn_swig_ConvertPtr(input
, obj
, svn_swig_TypeQuery(type
));
306 /** Wrapper for SWIG_MustGetPtr */
307 void *svn_swig_MustGetPtr(void *input
, swig_type_info
*type
, int argnum
)
309 if (PyObject_HasAttrString(input
, assertValid
))
311 PyObject
*result
= PyObject_CallMethod(input
, assertValid
, emptyTuple
);
317 if (PyObject_HasAttrString(input
, unwrap
))
319 input
= PyObject_CallMethod(input
, unwrap
, emptyTuple
);
322 Py_DECREF((PyObject
*) input
);
325 return SWIG_MustGetPtr(input
, type
, argnum
, SWIG_POINTER_EXCEPTION
| 0);
330 /*** Custom SubversionException stuffs. ***/
332 void svn_swig_py_svn_exception(svn_error_t
*error_chain
)
334 PyObject
*args_list
, *args
, *apr_err_ob
, *message_ob
, *file_ob
, *line_ob
;
335 PyObject
*svn_module
, *exc_class
, *exc_ob
;
338 if (error_chain
== NULL
)
341 /* Start with no references. */
342 args_list
= args
= apr_err_ob
= message_ob
= file_ob
= line_ob
= NULL
;
343 svn_module
= exc_class
= exc_ob
= NULL
;
345 if ((args_list
= PyList_New(0)) == NULL
)
348 for (err
= error_chain
; err
; err
= err
->child
)
352 if ((args
= PyTuple_New(4)) == NULL
)
355 /* Convert the fields of the svn_error_t to Python objects. */
356 if ((apr_err_ob
= PyInt_FromLong(err
->apr_err
)) == NULL
)
358 if (err
->message
== NULL
)
361 message_ob
= Py_None
;
363 else if ((message_ob
= PyString_FromString(err
->message
)) == NULL
)
365 if (err
->file
== NULL
)
370 else if ((file_ob
= PyString_FromString(err
->file
)) == NULL
)
372 if ((line_ob
= PyInt_FromLong(err
->line
)) == NULL
)
375 /* Store the objects in the tuple. */
377 #define append(item) \
378 if (PyTuple_SetItem(args, i++, item) == 0) \
379 /* tuple stole our reference, so don't DECREF */ \
389 /* Append the tuple to the args list. */
390 if (PyList_Append(args_list
, args
) == -1)
392 /* The list takes its own reference, so release ours. */
394 /* Let's not decref in 'finished:' after the final iteration. */
397 svn_error_clear(error_chain
);
399 /* Create the exception object chain. */
400 if ((svn_module
= PyImport_ImportModule((char *)"svn.core")) == NULL
)
402 if ((exc_class
= PyObject_GetAttrString(svn_module
,
403 (char *)"SubversionException")) == NULL
)
405 if ((exc_ob
= PyObject_CallMethod(exc_class
, (char *)"_new_from_err_list",
406 (char *)"O", args_list
)) == NULL
)
409 /* Raise the exception. */
410 PyErr_SetObject(exc_class
, exc_ob
);
413 /* Release any references. */
414 Py_XDECREF(args_list
);
416 Py_XDECREF(apr_err_ob
);
417 Py_XDECREF(message_ob
);
420 Py_XDECREF(svn_module
);
421 Py_XDECREF(exc_class
);
427 /*** Helper/Conversion Routines ***/
429 /* Functions for making Python wrappers around Subversion structs */
430 static PyObject
*make_ob_pool(void *pool
)
432 /* Return a brand new default pool to Python. This pool isn't
433 * normally used for anything. It's just here for compatibility
434 * with Subversion 1.2. */
435 apr_pool_t
*new_pool
= svn_pool_create(application_pool
);
436 PyObject
*new_py_pool
= svn_swig_NewPointerObj(new_pool
,
437 svn_swig_TypeQuery("apr_pool_t *"), application_py_pool
, NULL
);
438 (void) pool
; /* Silence compiler warnings about unused parameter. */
441 static PyObject
*make_ob_fs_root(svn_fs_root_t
*ptr
, PyObject
*py_pool
)
443 return svn_swig_NewPointerObjString(ptr
, "svn_fs_root_t *", py_pool
);
447 /* Conversion from Python single objects (not hashes/lists/etc.) to
449 static const char *make_string_from_ob(PyObject
*ob
, apr_pool_t
*pool
)
453 if (! PyString_Check(ob
))
455 PyErr_SetString(PyExc_TypeError
, "not a string");
458 return apr_pstrdup(pool
, PyString_AS_STRING(ob
));
460 static svn_string_t
*make_svn_string_from_ob(PyObject
*ob
, apr_pool_t
*pool
)
464 if (! PyString_Check(ob
))
466 PyErr_SetString(PyExc_TypeError
, "not a string");
469 return svn_string_create(PyString_AS_STRING(ob
), pool
);
475 static PyObject
*convert_hash(apr_hash_t
*hash
,
476 PyObject
* (*converter_func
)(void *value
,
479 void *ctx
, PyObject
*py_pool
)
481 apr_hash_index_t
*hi
;
487 if ((dict
= PyDict_New()) == NULL
)
490 for (hi
= apr_hash_first(NULL
, hash
); hi
; hi
= apr_hash_next(hi
))
496 apr_hash_this(hi
, &key
, NULL
, &val
);
497 value
= (*converter_func
)(val
, ctx
, py_pool
);
503 /* ### gotta cast this thing cuz Python doesn't use "const" */
504 if (PyDict_SetItemString(dict
, (char *)key
, value
) == -1)
516 static PyObject
*convert_to_swigtype(void *value
, void *ctx
, PyObject
*py_pool
)
518 /* ctx is a 'swig_type_info *' */
519 return svn_swig_NewPointerObj(value
, ctx
, py_pool
, NULL
);
522 static PyObject
*convert_svn_string_t(void *value
, void *ctx
,
527 const svn_string_t
*s
= value
;
529 /* ### gotta cast this thing cuz Python doesn't use "const" */
530 return PyString_FromStringAndSize((void *)s
->data
, s
->len
);
533 static PyObject
*convert_svn_client_commit_item3_t(void *value
, void *ctx
)
536 PyObject
*path
, *kind
, *url
, *rev
, *cf_url
, *cf_rev
, *state
,
537 *incoming_prop_changes
, *outgoing_prop_changes
;
538 svn_client_commit_item3_t
*item
= value
;
542 list
= PyList_New(9);
545 path
= PyString_FromString(item
->path
);
553 url
= PyString_FromString(item
->url
);
560 if (item
->copyfrom_url
)
561 cf_url
= PyString_FromString(item
->copyfrom_url
);
568 kind
= PyInt_FromLong(item
->kind
);
569 rev
= PyInt_FromLong(item
->revision
);
570 cf_rev
= PyInt_FromLong(item
->copyfrom_rev
);
571 state
= PyInt_FromLong(item
->state_flags
);
573 if (item
->incoming_prop_changes
)
574 incoming_prop_changes
=
575 svn_swig_py_array_to_list(item
->incoming_prop_changes
);
578 incoming_prop_changes
= Py_None
;
582 if (item
->outgoing_prop_changes
)
583 outgoing_prop_changes
=
584 svn_swig_py_array_to_list(item
->outgoing_prop_changes
);
587 outgoing_prop_changes
= Py_None
;
591 if (! (list
&& path
&& kind
&& url
&& rev
&& cf_url
&& cf_rev
&& state
&&
592 incoming_prop_changes
&& outgoing_prop_changes
))
602 Py_XDECREF(incoming_prop_changes
);
603 Py_XDECREF(outgoing_prop_changes
);
607 PyList_SET_ITEM(list
, 0, path
);
608 PyList_SET_ITEM(list
, 1, kind
);
609 PyList_SET_ITEM(list
, 2, url
);
610 PyList_SET_ITEM(list
, 3, rev
);
611 PyList_SET_ITEM(list
, 4, cf_url
);
612 PyList_SET_ITEM(list
, 5, cf_rev
);
613 PyList_SET_ITEM(list
, 6, state
);
614 PyList_SET_ITEM(list
, 7, incoming_prop_changes
);
615 PyList_SET_ITEM(list
, 8, outgoing_prop_changes
);
619 PyObject
*svn_swig_py_prophash_to_dict(apr_hash_t
*hash
)
621 return convert_hash(hash
, convert_svn_string_t
, NULL
, NULL
);
624 static PyObject
*convert_string(void *value
, void *ctx
,
627 /* ### gotta cast this thing cuz Python doesn't use "const" */
628 return PyString_FromString((const char *)value
);
631 PyObject
*svn_swig_py_stringhash_to_dict(apr_hash_t
*hash
)
633 return convert_hash(hash
, convert_string
, NULL
, NULL
);
636 static PyObject
*convert_rangelist(void *value
, void *ctx
, PyObject
*py_pool
)
640 apr_array_header_t
*array
= value
;
642 list
= PyList_New(0);
643 for (i
= 0; i
< array
->nelts
; i
++)
645 svn_merge_range_t
*range
= APR_ARRAY_IDX(array
, i
, svn_merge_range_t
*);
646 if (PyList_Append(list
, convert_to_swigtype(range
, ctx
, py_pool
)) == -1)
655 PyObject
*svn_swig_py_rangelist_to_list(apr_array_header_t
*rangelist
,
656 swig_type_info
*type
,
659 return convert_rangelist(rangelist
, type
, py_pool
);
662 PyObject
*svn_swig_py_mergeinfo_to_dict(apr_hash_t
*hash
,
663 swig_type_info
*type
,
666 return convert_hash(hash
, convert_rangelist
, type
, py_pool
);
669 static PyObject
*convert_mergeinfo_hash(void *value
, void *ctx
,
672 return svn_swig_py_mergeinfo_to_dict(value
, ctx
, py_pool
);
675 PyObject
*svn_swig_py_mergeinfo_catalog_to_dict(apr_hash_t
*hash
,
676 swig_type_info
*type
,
679 return convert_hash(hash
, convert_mergeinfo_hash
, type
, py_pool
);
682 PyObject
*svn_swig_py_proparray_to_dict(const apr_array_header_t
*array
)
684 PyObject
*dict
= PyDict_New();
690 for (i
= 0; i
< array
->nelts
; ++i
)
693 PyObject
*py_key
, *py_value
;
695 prop
= APR_ARRAY_IDX(array
, i
, svn_prop_t
);
697 py_key
= PyString_FromString(prop
.name
);
701 if (prop
.value
== NULL
)
708 py_value
= PyString_FromStringAndSize((void *)prop
.value
->data
,
710 if (py_value
== NULL
)
717 PyDict_SetItem(dict
, py_key
, py_value
);
728 PyObject
*svn_swig_py_locationhash_to_dict(apr_hash_t
*hash
)
730 /* Need special code for this because of the darned svn_revnum_t
732 apr_hash_index_t
*hi
;
733 PyObject
*dict
= PyDict_New();
738 for (hi
= apr_hash_first(NULL
, hash
); hi
; hi
= apr_hash_next(hi
))
742 PyObject
*key
, *value
;
744 apr_hash_this(hi
, &k
, NULL
, &v
);
745 key
= PyLong_FromLong(*(svn_revnum_t
*)k
);
751 value
= PyString_FromString((char *)v
);
758 if (PyDict_SetItem(dict
, key
, value
) == -1)
770 PyObject
*svn_swig_py_convert_hash(apr_hash_t
*hash
, swig_type_info
*type
,
773 return convert_hash(hash
, convert_to_swigtype
, type
, py_pool
);
776 #define DECLARE_SWIG_CONSTRUCTOR(type, dup) \
777 static PyObject *make_ob_##type(void *value) \
779 apr_pool_t *new_pool = svn_pool_create(application_pool); \
780 PyObject *new_py_pool = svn_swig_NewPointerObj(new_pool, \
781 svn_swig_TypeQuery("apr_pool_t *"), application_py_pool, NULL); \
782 svn_##type##_t *new_value = dup(value, new_pool); \
783 PyObject *obj = svn_swig_NewPointerObjString(new_value, "svn_" #type "_t *", \
785 Py_XDECREF(new_py_pool); \
789 DECLARE_SWIG_CONSTRUCTOR(txdelta_window
, svn_txdelta_window_dup
)
790 DECLARE_SWIG_CONSTRUCTOR(log_changed_path
, svn_log_changed_path_dup
)
791 DECLARE_SWIG_CONSTRUCTOR(wc_status
, svn_wc_dup_status
)
792 DECLARE_SWIG_CONSTRUCTOR(lock
, svn_lock_dup
)
793 DECLARE_SWIG_CONSTRUCTOR(auth_ssl_server_cert_info
,
794 svn_auth_ssl_server_cert_info_dup
)
795 DECLARE_SWIG_CONSTRUCTOR(info
, svn_info_dup
)
796 DECLARE_SWIG_CONSTRUCTOR(location_segment
, svn_location_segment_dup
)
797 DECLARE_SWIG_CONSTRUCTOR(commit_info
, svn_commit_info_dup
)
798 DECLARE_SWIG_CONSTRUCTOR(wc_notify
, svn_wc_dup_notify
)
800 static PyObject
*convert_log_changed_path(void *value
, void *ctx
,
803 return make_ob_log_changed_path(value
);
806 PyObject
*svn_swig_py_c_strings_to_list(char **strings
)
808 PyObject
*list
= PyList_New(0);
811 while ((s
= *strings
++) != NULL
)
813 PyObject
*ob
= PyString_FromString(s
);
817 if (PyList_Append(list
, ob
) == -1)
828 PyObject
*svn_swig_py_changed_path_hash_to_dict(apr_hash_t
*hash
)
830 apr_hash_index_t
*hi
;
836 if ((dict
= PyDict_New()) == NULL
)
839 for (hi
= apr_hash_first(NULL
, hash
); hi
; hi
= apr_hash_next(hi
))
845 apr_hash_this(hi
, &key
, NULL
, &val
);
846 value
= make_ob_log_changed_path(val
);
852 if (PyDict_SetItemString(dict
, (char *)key
, value
) == -1)
864 apr_array_header_t
*svn_swig_py_rangelist_to_array(PyObject
*list
,
868 apr_array_header_t
*temp
;
870 if (!PySequence_Check(list
)) {
871 PyErr_SetString(PyExc_TypeError
, "not a sequence");
874 targlen
= PySequence_Length(list
);
875 temp
= apr_array_make(pool
, targlen
, sizeof(svn_merge_range_t
*));
876 /* APR_ARRAY_IDX doesn't actually increment the array item count
877 (like, say, apr_array_push would). */
878 temp
->nelts
= targlen
;
880 PyObject
*o
= PySequence_GetItem(list
, targlen
);
881 svn_merge_range_t
*range
;
882 svn_merge_range_t
*newrange
;
886 if (svn_swig_ConvertPtrString(o
, (void **)&range
,
887 "svn_merge_range_t *"))
889 PyErr_SetString(PyExc_TypeError
,
890 "list values are not svn_merge_range_t *'s");
894 newrange
= svn_merge_range_dup(range
, pool
);
896 APR_ARRAY_IDX(temp
, targlen
, svn_merge_range_t
*) = newrange
;
902 apr_hash_t
*svn_swig_py_stringhash_from_dict(PyObject
*dict
,
912 if (!PyDict_Check(dict
))
914 PyErr_SetString(PyExc_TypeError
, "not a dictionary");
918 hash
= apr_hash_make(pool
);
919 keys
= PyDict_Keys(dict
);
920 num_keys
= PyList_Size(keys
);
921 for (i
= 0; i
< num_keys
; i
++)
923 PyObject
*key
= PyList_GetItem(keys
, i
);
924 PyObject
*value
= PyDict_GetItem(dict
, key
);
925 const char *propname
= make_string_from_ob(key
, pool
);
926 const char *propval
= make_string_from_ob(value
, pool
);
927 if (! (propname
&& propval
))
929 PyErr_SetString(PyExc_TypeError
,
930 "dictionary keys/values aren't strings");
934 apr_hash_set(hash
, propname
, APR_HASH_KEY_STRING
, propval
);
940 apr_hash_t
*svn_swig_py_mergeinfo_from_dict(PyObject
*dict
,
950 if (!PyDict_Check(dict
)) {
951 PyErr_SetString(PyExc_TypeError
, "not a dictionary");
955 hash
= apr_hash_make(pool
);
956 keys
= PyDict_Keys(dict
);
957 num_keys
= PyList_Size(keys
);
958 for (i
= 0; i
< num_keys
; i
++)
960 PyObject
*key
= PyList_GetItem(keys
, i
);
961 PyObject
*value
= PyDict_GetItem(dict
, key
);
962 const char *pathname
= make_string_from_ob(key
, pool
);
963 apr_array_header_t
*ranges
= svn_swig_py_rangelist_to_array(value
, pool
);
965 if (! (pathname
&& ranges
))
967 PyErr_SetString(PyExc_TypeError
,
968 "dictionary keys aren't strings or values aren't svn_merge_range_t *'s");
972 apr_hash_set(hash
, pathname
, APR_HASH_KEY_STRING
, ranges
);
978 apr_array_header_t
*svn_swig_py_proparray_from_dict(PyObject
*dict
,
981 apr_array_header_t
*array
;
988 if (!PyDict_Check(dict
))
990 PyErr_SetString(PyExc_TypeError
, "not a dictionary");
994 keys
= PyDict_Keys(dict
);
995 num_keys
= PyList_Size(keys
);
996 array
= apr_array_make(pool
, num_keys
, sizeof(svn_prop_t
*));
997 for (i
= 0; i
< num_keys
; i
++)
999 PyObject
*key
= PyList_GetItem(keys
, i
);
1000 PyObject
*value
= PyDict_GetItem(dict
, key
);
1001 svn_prop_t
*prop
= apr_palloc(pool
, sizeof(*prop
));
1002 prop
->name
= make_string_from_ob(key
, pool
);
1003 prop
->value
= make_svn_string_from_ob(value
, pool
);
1004 if (! (prop
->name
&& prop
->value
))
1006 PyErr_SetString(PyExc_TypeError
,
1007 "dictionary keys/values aren't strings");
1011 APR_ARRAY_PUSH(array
, svn_prop_t
*) = prop
;
1017 apr_hash_t
*svn_swig_py_prophash_from_dict(PyObject
*dict
,
1024 if (dict
== Py_None
)
1027 if (!PyDict_Check(dict
))
1029 PyErr_SetString(PyExc_TypeError
, "not a dictionary");
1033 hash
= apr_hash_make(pool
);
1034 keys
= PyDict_Keys(dict
);
1035 num_keys
= PyList_Size(keys
);
1036 for (i
= 0; i
< num_keys
; i
++)
1038 PyObject
*key
= PyList_GetItem(keys
, i
);
1039 PyObject
*value
= PyDict_GetItem(dict
, key
);
1040 const char *propname
= make_string_from_ob(key
, pool
);
1041 svn_string_t
*propval
= make_svn_string_from_ob(value
, pool
);
1042 if (! (propname
&& propval
))
1044 PyErr_SetString(PyExc_TypeError
,
1045 "dictionary keys/values aren't strings");
1049 apr_hash_set(hash
, propname
, APR_HASH_KEY_STRING
, propval
);
1055 apr_hash_t
*svn_swig_py_path_revs_hash_from_dict(PyObject
*dict
,
1062 if (dict
== Py_None
)
1065 if (!PyDict_Check(dict
))
1067 PyErr_SetString(PyExc_TypeError
, "not a dictionary");
1071 hash
= apr_hash_make(pool
);
1072 keys
= PyDict_Keys(dict
);
1073 num_keys
= PyList_Size(keys
);
1074 for (i
= 0; i
< num_keys
; i
++)
1076 PyObject
*key
= PyList_GetItem(keys
, i
);
1077 PyObject
*value
= PyDict_GetItem(dict
, key
);
1078 const char *path
= make_string_from_ob(key
, pool
);
1079 svn_revnum_t
*revnum
;
1083 PyErr_SetString(PyExc_TypeError
,
1084 "dictionary keys aren't strings");
1089 revnum
= apr_palloc(pool
, sizeof(svn_revnum_t
));
1091 if (PyInt_Check(value
))
1092 *revnum
= PyInt_AsLong(value
);
1093 else if (PyLong_Check(value
))
1094 *revnum
= PyLong_AsLong(value
);
1097 PyErr_SetString(PyExc_TypeError
, "dictionary values aren't revnums");
1102 apr_hash_set(hash
, path
, APR_HASH_KEY_STRING
, revnum
);
1108 apr_hash_t
*svn_swig_py_changed_path_hash_from_dict(PyObject
*dict
,
1115 if (dict
== Py_None
)
1118 if (!PyDict_Check(dict
))
1120 PyErr_SetString(PyExc_TypeError
, "not a dictionary");
1124 hash
= apr_hash_make(pool
);
1125 keys
= PyDict_Keys(dict
);
1126 num_keys
= PyList_Size(keys
);
1127 for (i
= 0; i
< num_keys
; i
++)
1129 PyObject
*key
= PyList_GetItem(keys
, i
);
1130 PyObject
*py_changed_path
= PyDict_GetItem(dict
, key
);
1131 const char *path
= make_string_from_ob(key
, pool
);
1132 svn_log_changed_path_t
*changed_path
;
1135 PyErr_SetString(PyExc_TypeError
,
1136 "dictionary keys aren't strings");
1140 svn_swig_ConvertPtrString(py_changed_path
, (void *)&changed_path
,
1141 "svn_log_changed_path_t *");
1144 PyErr_SetString(PyExc_TypeError
,
1145 "dictionary values aren't svn_log_changed_path_t");
1149 apr_hash_set(hash
, path
, APR_HASH_KEY_STRING
, changed_path
);
1155 const apr_array_header_t
*svn_swig_py_strings_to_array(PyObject
*source
,
1159 apr_array_header_t
*temp
;
1161 if (source
== Py_None
)
1164 if (!PySequence_Check(source
))
1166 PyErr_SetString(PyExc_TypeError
, "not a sequence");
1169 targlen
= PySequence_Length(source
);
1170 temp
= apr_array_make(pool
, targlen
, sizeof(const char *));
1171 /* APR_ARRAY_IDX doesn't actually increment the array item count
1172 (like, say, apr_array_push would). */
1173 temp
->nelts
= targlen
;
1176 PyObject
*o
= PySequence_GetItem(source
, targlen
);
1179 if (!PyString_Check(o
))
1182 PyErr_SetString(PyExc_TypeError
, "not a string");
1185 APR_ARRAY_IDX(temp
, targlen
, const char *) = PyString_AS_STRING(o
);
1192 const apr_array_header_t
*svn_swig_py_revnums_to_array(PyObject
*source
,
1196 apr_array_header_t
*temp
;
1198 if (!PySequence_Check(source
))
1200 PyErr_SetString(PyExc_TypeError
, "not a sequence");
1203 targlen
= PySequence_Length(source
);
1204 temp
= apr_array_make(pool
, targlen
, sizeof(svn_revnum_t
));
1205 /* APR_ARRAY_IDX doesn't actually increment the array item count
1206 (like, say, apr_array_push would). */
1207 temp
->nelts
= targlen
;
1210 PyObject
*o
= PySequence_GetItem(source
, targlen
);
1213 if (PyLong_Check(o
))
1215 APR_ARRAY_IDX(temp
, targlen
, svn_revnum_t
) =
1216 (svn_revnum_t
)PyLong_AsLong(o
);
1218 else if (PyInt_Check(o
))
1220 APR_ARRAY_IDX(temp
, targlen
, svn_revnum_t
) =
1221 (svn_revnum_t
)PyInt_AsLong(o
);
1226 PyErr_SetString(PyExc_TypeError
, "not an integer type");
1236 /*** apr_array_header_t conversions. To create a new type of
1237 converter, simply copy-n-paste one of these function and tweak
1238 the creation of the PyObject *ob. ***/
1240 PyObject
*svn_swig_py_array_to_list(const apr_array_header_t
*array
)
1242 PyObject
*list
= PyList_New(array
->nelts
);
1245 for (i
= 0; i
< array
->nelts
; ++i
)
1248 PyString_FromString(APR_ARRAY_IDX(array
, i
, const char *));
1251 PyList_SET_ITEM(list
, i
, ob
);
1260 PyObject
*svn_swig_py_revarray_to_list(const apr_array_header_t
*array
)
1262 PyObject
*list
= PyList_New(array
->nelts
);
1265 for (i
= 0; i
< array
->nelts
; ++i
)
1268 = PyInt_FromLong(APR_ARRAY_IDX(array
, i
, svn_revnum_t
));
1271 PyList_SET_ITEM(list
, i
, ob
);
1281 commit_item_array_to_list(const apr_array_header_t
*array
)
1283 PyObject
*list
= PyList_New(array
->nelts
);
1286 for (i
= 0; i
< array
->nelts
; ++i
)
1288 PyObject
*ob
= convert_svn_client_commit_item3_t
1289 (APR_ARRAY_IDX(array
, i
, svn_client_commit_item3_t
*), NULL
);
1292 PyList_SET_ITEM(list
, i
, ob
);
1305 /* Return a Subversion error about a failed callback. */
1306 static svn_error_t
*callback_exception_error(void)
1308 return svn_error_create(SVN_ERR_SWIG_PY_EXCEPTION_SET
, NULL
,
1309 "Python callback raised an exception");
1312 /* Raise a TypeError exception with MESSAGE, and return a Subversion
1313 error about an invalid return from a callback. */
1314 static svn_error_t
*callback_bad_return_error(const char *message
)
1316 PyErr_SetString(PyExc_TypeError
, message
);
1317 return svn_error_create(APR_EGENERAL
, NULL
,
1318 "Python callback returned an invalid object");
1321 /* Return a generic error about not being able to map types. */
1322 static svn_error_t
*type_conversion_error(const char *datatype
)
1324 return svn_error_createf(APR_EGENERAL
, NULL
,
1325 "Error converting object of type '%s'", datatype
);
1330 /*** Editor Wrapping ***/
1332 /* this baton is used for the editor, directory, and file batons. */
1334 PyObject
*editor
; /* the editor handling the callbacks */
1335 PyObject
*baton
; /* the dir/file baton (or NULL for edit baton) */
1338 static item_baton
*make_baton(apr_pool_t
*pool
,
1342 item_baton
*newb
= apr_palloc(pool
, sizeof(*newb
));
1344 /* Note: We steal the caller's reference to 'baton'. Also, to avoid
1345 memory leaks, we borrow the caller's reference to 'editor'. In this
1346 case, borrowing the reference to 'editor' is safe because the contents
1347 of an item_baton struct are only used by functino calls which operate on
1348 the editor itself. */
1349 newb
->editor
= editor
;
1350 newb
->baton
= baton
;
1355 static svn_error_t
*close_baton(void *baton
,
1358 item_baton
*ib
= baton
;
1362 svn_swig_py_acquire_py_lock();
1364 /* If there is no baton object, then it is an edit_baton, and we should
1365 not bother to pass an object. Note that we still shove a NULL onto
1366 the stack, but the format specified just won't reference it. */
1367 /* ### python doesn't have 'const' on the method name and format */
1368 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)method
,
1369 ib
->baton
? (char *)"(O)" : NULL
,
1370 ib
->baton
)) == NULL
)
1372 err
= callback_exception_error();
1376 /* there is no return value, so just toss this object (probably Py_None) */
1379 /* We're now done with the baton. Since there isn't really a free, all
1380 we need to do is note that its objects are no longer referenced by
1382 Py_XDECREF(ib
->baton
);
1385 ib
->editor
= ib
->baton
= NULL
;
1391 svn_swig_py_release_py_lock();
1395 static svn_error_t
*set_target_revision(void *edit_baton
,
1396 svn_revnum_t target_revision
,
1399 item_baton
*ib
= edit_baton
;
1403 svn_swig_py_acquire_py_lock();
1405 /* ### python doesn't have 'const' on the method name and format */
1406 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"set_target_revision",
1407 (char *)"l", target_revision
)) == NULL
)
1409 err
= callback_exception_error();
1413 /* there is no return value, so just toss this object (probably Py_None) */
1418 svn_swig_py_release_py_lock();
1422 static svn_error_t
*open_root(void *edit_baton
,
1423 svn_revnum_t base_revision
,
1424 apr_pool_t
*dir_pool
,
1427 item_baton
*ib
= edit_baton
;
1431 svn_swig_py_acquire_py_lock();
1433 /* ### python doesn't have 'const' on the method name and format */
1434 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"open_root",
1435 (char *)"lO&", base_revision
,
1436 make_ob_pool
, dir_pool
)) == NULL
)
1438 err
= callback_exception_error();
1442 /* make_baton takes our 'result' reference */
1443 *root_baton
= make_baton(dir_pool
, ib
->editor
, result
);
1447 svn_swig_py_release_py_lock();
1451 static svn_error_t
*delete_entry(const char *path
,
1452 svn_revnum_t revision
,
1456 item_baton
*ib
= parent_baton
;
1460 svn_swig_py_acquire_py_lock();
1462 /* ### python doesn't have 'const' on the method name and format */
1463 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"delete_entry",
1464 (char *)"slOO&", path
, revision
, ib
->baton
,
1465 make_ob_pool
, pool
)) == NULL
)
1467 err
= callback_exception_error();
1471 /* there is no return value, so just toss this object (probably Py_None) */
1476 svn_swig_py_release_py_lock();
1480 static svn_error_t
*add_directory(const char *path
,
1482 const char *copyfrom_path
,
1483 svn_revnum_t copyfrom_revision
,
1484 apr_pool_t
*dir_pool
,
1487 item_baton
*ib
= parent_baton
;
1491 svn_swig_py_acquire_py_lock();
1493 /* ### python doesn't have 'const' on the method name and format */
1494 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"add_directory",
1495 (char *)"sOslO&", path
, ib
->baton
,
1496 copyfrom_path
, copyfrom_revision
,
1497 make_ob_pool
, dir_pool
)) == NULL
)
1499 err
= callback_exception_error();
1503 /* make_baton takes our 'result' reference */
1504 *child_baton
= make_baton(dir_pool
, ib
->editor
, result
);
1508 svn_swig_py_release_py_lock();
1512 static svn_error_t
*open_directory(const char *path
,
1514 svn_revnum_t base_revision
,
1515 apr_pool_t
*dir_pool
,
1518 item_baton
*ib
= parent_baton
;
1522 svn_swig_py_acquire_py_lock();
1524 /* ### python doesn't have 'const' on the method name and format */
1525 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"open_directory",
1526 (char *)"sOlO&", path
, ib
->baton
,
1528 make_ob_pool
, dir_pool
)) == NULL
)
1530 err
= callback_exception_error();
1534 /* make_baton takes our 'result' reference */
1535 *child_baton
= make_baton(dir_pool
, ib
->editor
, result
);
1539 svn_swig_py_release_py_lock();
1543 static svn_error_t
*change_dir_prop(void *dir_baton
,
1545 const svn_string_t
*value
,
1548 item_baton
*ib
= dir_baton
;
1552 svn_swig_py_acquire_py_lock();
1554 /* ### python doesn't have 'const' on the method name and format */
1555 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"change_dir_prop",
1556 (char *)"Oss#O&", ib
->baton
, name
,
1557 value
? value
->data
: NULL
,
1558 value
? value
->len
: 0,
1559 make_ob_pool
, pool
)) == NULL
)
1561 err
= callback_exception_error();
1565 /* there is no return value, so just toss this object (probably Py_None) */
1570 svn_swig_py_release_py_lock();
1574 static svn_error_t
*close_directory(void *dir_baton
,
1577 return close_baton(dir_baton
, "close_directory");
1580 static svn_error_t
*add_file(const char *path
,
1582 const char *copyfrom_path
,
1583 svn_revnum_t copyfrom_revision
,
1584 apr_pool_t
*file_pool
,
1587 item_baton
*ib
= parent_baton
;
1591 svn_swig_py_acquire_py_lock();
1593 /* ### python doesn't have 'const' on the method name and format */
1594 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"add_file",
1595 (char *)"sOslO&", path
, ib
->baton
,
1596 copyfrom_path
, copyfrom_revision
,
1597 make_ob_pool
, file_pool
)) == NULL
)
1599 err
= callback_exception_error();
1603 /* make_baton takes our 'result' reference */
1604 *file_baton
= make_baton(file_pool
, ib
->editor
, result
);
1609 svn_swig_py_release_py_lock();
1613 static svn_error_t
*open_file(const char *path
,
1615 svn_revnum_t base_revision
,
1616 apr_pool_t
*file_pool
,
1619 item_baton
*ib
= parent_baton
;
1623 svn_swig_py_acquire_py_lock();
1625 /* ### python doesn't have 'const' on the method name and format */
1626 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"open_file",
1627 (char *)"sOlO&", path
, ib
->baton
,
1629 make_ob_pool
, file_pool
)) == NULL
)
1631 err
= callback_exception_error();
1635 /* make_baton takes our 'result' reference */
1636 *file_baton
= make_baton(file_pool
, ib
->editor
, result
);
1640 svn_swig_py_release_py_lock();
1644 static svn_error_t
*window_handler(svn_txdelta_window_t
*window
,
1647 PyObject
*handler
= baton
;
1651 svn_swig_py_acquire_py_lock();
1655 /* the last call; it closes the handler */
1657 /* invoke the handler with None for the window */
1658 /* ### python doesn't have 'const' on the format */
1659 result
= PyObject_CallFunction(handler
, (char *)"O", Py_None
);
1661 /* we no longer need to refer to the handler object */
1666 /* invoke the handler with the window */
1667 /* ### python doesn't have 'const' on the format */
1668 result
= PyObject_CallFunction(handler
, (char *)"O&",
1669 make_ob_txdelta_window
, window
);
1674 err
= callback_exception_error();
1678 /* there is no return value, so just toss this object (probably Py_None) */
1683 svn_swig_py_release_py_lock();
1687 static svn_error_t
*apply_textdelta(void *file_baton
,
1688 const char *base_checksum
,
1690 svn_txdelta_window_handler_t
*handler
,
1693 item_baton
*ib
= file_baton
;
1697 svn_swig_py_acquire_py_lock();
1699 /* ### python doesn't have 'const' on the method name and format */
1700 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"apply_textdelta",
1701 (char *)"(Os)", ib
->baton
,
1702 base_checksum
)) == NULL
)
1704 err
= callback_exception_error();
1708 /* Interpret None to mean svn_delta_noop_window_handler. This is much
1709 easier/faster than making code always have to write a NOOP handler
1711 if (result
== Py_None
)
1715 *handler
= svn_delta_noop_window_handler
;
1720 /* return the thunk for invoking the handler. the baton takes our
1721 'result' reference, which is the handler. */
1722 *handler
= window_handler
;
1729 svn_swig_py_release_py_lock();
1733 static svn_error_t
*change_file_prop(void *file_baton
,
1735 const svn_string_t
*value
,
1738 item_baton
*ib
= file_baton
;
1742 svn_swig_py_acquire_py_lock();
1744 /* ### python doesn't have 'const' on the method name and format */
1745 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"change_file_prop",
1746 (char *)"Oss#O&", ib
->baton
, name
,
1747 value
? value
->data
: NULL
,
1748 value
? value
->len
: 0,
1749 make_ob_pool
, pool
)) == NULL
)
1751 err
= callback_exception_error();
1755 /* there is no return value, so just toss this object (probably Py_None) */
1760 svn_swig_py_release_py_lock();
1764 static svn_error_t
*close_file(void *file_baton
,
1765 const char *text_checksum
,
1768 item_baton
*ib
= file_baton
;
1772 svn_swig_py_acquire_py_lock();
1774 /* ### python doesn't have 'const' on the method name and format */
1775 if ((result
= PyObject_CallMethod(ib
->editor
, (char *)"close_file",
1776 (char *)"(Os)", ib
->baton
,
1777 text_checksum
)) == NULL
)
1779 err
= callback_exception_error();
1783 /* there is no return value, so just toss this object (probably Py_None) */
1786 /* We're now done with the baton. Since there isn't really a free, all
1787 we need to do is note that its objects are no longer referenced by
1789 Py_XDECREF(ib
->baton
);
1792 ib
->editor
= ib
->baton
= NULL
;
1798 svn_swig_py_release_py_lock();
1802 static svn_error_t
*close_edit(void *edit_baton
,
1805 return close_baton(edit_baton
, "close_edit");
1808 static svn_error_t
*abort_edit(void *edit_baton
,
1811 return close_baton(edit_baton
, "abort_edit");
1814 void svn_swig_py_make_editor(const svn_delta_editor_t
**editor
,
1816 PyObject
*py_editor
,
1819 svn_delta_editor_t
*thunk_editor
= svn_delta_default_editor(pool
);
1821 thunk_editor
->set_target_revision
= set_target_revision
;
1822 thunk_editor
->open_root
= open_root
;
1823 thunk_editor
->delete_entry
= delete_entry
;
1824 thunk_editor
->add_directory
= add_directory
;
1825 thunk_editor
->open_directory
= open_directory
;
1826 thunk_editor
->change_dir_prop
= change_dir_prop
;
1827 thunk_editor
->close_directory
= close_directory
;
1828 thunk_editor
->add_file
= add_file
;
1829 thunk_editor
->open_file
= open_file
;
1830 thunk_editor
->apply_textdelta
= apply_textdelta
;
1831 thunk_editor
->change_file_prop
= change_file_prop
;
1832 thunk_editor
->close_file
= close_file
;
1833 thunk_editor
->close_edit
= close_edit
;
1834 thunk_editor
->abort_edit
= abort_edit
;
1836 *editor
= thunk_editor
;
1837 *edit_baton
= make_baton(pool
, py_editor
, NULL
);
1842 /*** Other Wrappers for SVN Functions ***/
1845 apr_file_t
*svn_swig_py_make_file(PyObject
*py_file
,
1848 apr_file_t
*apr_file
= NULL
;
1849 apr_status_t apr_err
;
1851 if (py_file
== NULL
|| py_file
== Py_None
)
1854 if (PyString_Check(py_file
))
1856 /* input is a path -- just open an apr_file_t */
1857 char* fname
= PyString_AS_STRING(py_file
);
1858 apr_err
= apr_file_open(&apr_file
, fname
,
1859 APR_CREATE
| APR_READ
| APR_WRITE
,
1860 APR_OS_DEFAULT
, pool
);
1864 apr_strerror(apr_err
, buf
, sizeof(buf
));
1865 PyErr_Format(PyExc_IOError
, "apr_file_open failed: %s: '%s'",
1870 else if (PyFile_Check(py_file
))
1873 apr_os_file_t osfile
;
1875 /* input is a file object -- convert to apr_file_t */
1876 file
= PyFile_AsFile(py_file
);
1878 osfile
= (apr_os_file_t
)_get_osfhandle(_fileno(file
));
1880 osfile
= (apr_os_file_t
)fileno(file
);
1882 apr_err
= apr_os_file_put(&apr_file
, &osfile
, O_CREAT
| O_WRONLY
, pool
);
1886 apr_strerror(apr_err
, buf
, sizeof(buf
));
1887 PyErr_Format(PyExc_IOError
, "apr_os_file_put failed: %s", buf
);
1895 static svn_error_t
*
1896 read_handler_pyio(void *baton
, char *buffer
, apr_size_t
*len
)
1899 PyObject
*py_io
= baton
;
1901 svn_error_t
*err
= SVN_NO_ERROR
;
1903 if (py_io
== Py_None
)
1905 /* Return the empty string to indicate a short read */
1908 return SVN_NO_ERROR
;
1911 svn_swig_py_acquire_py_lock();
1912 if ((result
= PyObject_CallMethod(py_io
, (char *)"read",
1913 (char *)"i", *len
)) == NULL
)
1915 err
= callback_exception_error();
1917 else if (PyString_Check(result
))
1919 bytes
= PyString_GET_SIZE(result
);
1922 err
= callback_bad_return_error("Too many bytes");
1926 /* Writeback, in case this was a short read, indicating EOF */
1928 memcpy(buffer
, PyString_AS_STRING(result
), *len
);
1933 err
= callback_bad_return_error("Not a string");
1936 svn_swig_py_release_py_lock();
1941 static svn_error_t
*
1942 write_handler_pyio(void *baton
, const char *data
, apr_size_t
*len
)
1945 PyObject
*py_io
= baton
;
1946 svn_error_t
*err
= SVN_NO_ERROR
;
1948 if (data
!= NULL
&& py_io
!= Py_None
)
1950 svn_swig_py_acquire_py_lock();
1951 if ((result
= PyObject_CallMethod(py_io
, (char *)"write",
1952 (char *)"s#", data
, *len
)) == NULL
)
1954 err
= callback_exception_error();
1957 svn_swig_py_release_py_lock();
1963 static svn_error_t
*
1964 close_handler_pyio(void *baton
)
1966 PyObject
*py_io
= baton
;
1967 svn_swig_py_acquire_py_lock();
1969 svn_swig_py_release_py_lock();
1970 return SVN_NO_ERROR
;
1974 svn_swig_py_make_stream(PyObject
*py_io
, apr_pool_t
*pool
)
1976 svn_stream_t
*stream
;
1978 stream
= svn_stream_create(py_io
, pool
);
1979 svn_stream_set_read(stream
, read_handler_pyio
);
1980 svn_stream_set_write(stream
, write_handler_pyio
);
1981 svn_stream_set_close(stream
, close_handler_pyio
);
1988 void svn_swig_py_notify_func(void *baton
,
1990 svn_wc_notify_action_t action
,
1991 svn_node_kind_t kind
,
1992 const char *mime_type
,
1993 svn_wc_notify_state_t content_state
,
1994 svn_wc_notify_state_t prop_state
,
1995 svn_revnum_t revision
)
1997 PyObject
*function
= baton
;
1999 svn_error_t
*err
= SVN_NO_ERROR
;
2001 if (function
== NULL
|| function
== Py_None
)
2004 svn_swig_py_acquire_py_lock();
2005 if ((result
= PyObject_CallFunction(function
,
2006 (char *)"(siisiii)",
2009 content_state
, prop_state
,
2012 err
= callback_exception_error();
2016 /* The callback shouldn't be returning anything. */
2017 if (result
!= Py_None
)
2018 err
= callback_bad_return_error("Not None");
2022 /* Our error has no place to go. :-( */
2023 svn_error_clear(err
);
2025 svn_swig_py_release_py_lock();
2029 void svn_swig_py_notify_func2(void *baton
,
2030 const svn_wc_notify_t
*notify
,
2033 PyObject
*function
= baton
;
2035 svn_error_t
*err
= SVN_NO_ERROR
;
2037 if (function
== NULL
|| function
== Py_None
)
2040 svn_swig_py_acquire_py_lock();
2042 if ((result
= PyObject_CallFunction(function
,
2044 make_ob_wc_notify
, notify
,
2045 make_ob_pool
, pool
)) == NULL
)
2047 err
= callback_exception_error();
2051 /* The callback shouldn't be returning anything. */
2052 if (result
!= Py_None
)
2053 err
= callback_bad_return_error("Not None");
2057 /* Our error has no place to go. :-( */
2058 svn_error_clear(err
);
2060 svn_swig_py_release_py_lock();
2063 void svn_swig_py_status_func(void *baton
,
2065 svn_wc_status_t
*status
)
2067 PyObject
*function
= baton
;
2069 svn_error_t
*err
= SVN_NO_ERROR
;
2071 if (function
== NULL
|| function
== Py_None
)
2074 svn_swig_py_acquire_py_lock();
2075 if ((result
= PyObject_CallFunction(function
, (char *)"sO&", path
,
2076 make_ob_wc_status
, status
)) == NULL
)
2078 err
= callback_exception_error();
2082 /* The callback shouldn't be returning anything. */
2083 if (result
!= Py_None
)
2084 err
= callback_bad_return_error("Not None");
2088 /* Our error has no place to go. :-( */
2089 svn_error_clear(err
);
2091 svn_swig_py_release_py_lock();
2095 svn_error_t
*svn_swig_py_delta_path_driver_cb_func(void **dir_baton
,
2097 void *callback_baton
,
2101 PyObject
*function
= callback_baton
;
2103 svn_error_t
*err
= SVN_NO_ERROR
;
2105 if (function
== NULL
|| function
== Py_None
)
2108 svn_swig_py_acquire_py_lock();
2109 result
= PyObject_CallFunction(function
, (char *)"OsO&",
2110 svn_swig_NewPointerObjString(parent_baton
,
2112 application_py_pool
),
2113 path
, make_ob_pool
, pool
);
2116 err
= callback_exception_error();
2118 else if (result
== Py_None
)
2124 if (svn_swig_ConvertPtrString(result
, dir_baton
, "void *") == -1)
2126 err
= type_conversion_error("void *");
2130 svn_swig_py_release_py_lock();
2135 void svn_swig_py_status_func2(void *baton
,
2137 svn_wc_status2_t
*status
)
2139 PyObject
*function
= baton
;
2141 svn_error_t
*err
= SVN_NO_ERROR
;
2143 if (function
== NULL
|| function
== Py_None
)
2146 svn_swig_py_acquire_py_lock();
2147 if ((result
= PyObject_CallFunction(function
, (char *)"sO&", path
,
2148 make_ob_wc_status
, status
)) == NULL
)
2150 err
= callback_exception_error();
2154 /* The callback shouldn't be returning anything. */
2155 if (result
!= Py_None
)
2156 err
= callback_bad_return_error("Not None");
2160 /* Our error has no place to go. :-( */
2162 svn_error_clear(err
);
2164 svn_swig_py_release_py_lock();
2168 svn_error_t
*svn_swig_py_cancel_func(void *cancel_baton
)
2170 PyObject
*function
= cancel_baton
;
2172 svn_error_t
*err
= SVN_NO_ERROR
;
2174 if (function
== NULL
|| function
== Py_None
)
2175 return SVN_NO_ERROR
;
2177 svn_swig_py_acquire_py_lock();
2178 if ((result
= PyObject_CallFunction(function
, NULL
)) == NULL
)
2180 err
= callback_exception_error();
2184 if (PyInt_Check(result
))
2186 if (PyInt_AsLong(result
))
2187 err
= svn_error_create(SVN_ERR_CANCELLED
, 0, NULL
);
2189 else if (PyLong_Check(result
))
2191 if (PyLong_AsLong(result
))
2192 err
= svn_error_create(SVN_ERR_CANCELLED
, 0, NULL
);
2194 else if (result
!= Py_None
)
2196 err
= callback_bad_return_error("Not an integer or None");
2200 svn_swig_py_release_py_lock();
2204 svn_error_t
*svn_swig_py_fs_get_locks_func(void *baton
,
2208 PyObject
*function
= baton
;
2210 svn_error_t
*err
= SVN_NO_ERROR
;
2212 if (function
== NULL
|| function
== Py_None
)
2213 return SVN_NO_ERROR
;
2215 svn_swig_py_acquire_py_lock();
2217 if ((result
= PyObject_CallFunction(function
, (char *)"O&O&",
2219 make_ob_pool
, pool
)) == NULL
)
2221 err
= callback_exception_error();
2225 /* The callback shouldn't be returning anything. */
2226 if (result
!= Py_None
)
2227 err
= callback_bad_return_error("Not None");
2231 svn_swig_py_release_py_lock();
2235 svn_error_t
*svn_swig_py_get_commit_log_func(const char **log_msg
,
2236 const char **tmp_file
,
2237 const apr_array_header_t
*
2242 PyObject
*function
= baton
;
2244 PyObject
*cmt_items
;
2250 /* ### todo: for now, just ignore the whole tmp_file thing. */
2252 if ((function
== NULL
) || (function
== Py_None
))
2253 return SVN_NO_ERROR
;
2255 svn_swig_py_acquire_py_lock();
2259 cmt_items
= commit_item_array_to_list(commit_items
);
2263 cmt_items
= Py_None
;
2267 if ((result
= PyObject_CallFunction(function
,
2270 make_ob_pool
, pool
)) == NULL
)
2272 Py_DECREF(cmt_items
);
2273 err
= callback_exception_error();
2277 Py_DECREF(cmt_items
);
2279 if (result
== Py_None
)
2285 else if (PyString_Check(result
))
2287 *log_msg
= apr_pstrdup(pool
, PyString_AS_STRING(result
));
2294 err
= callback_bad_return_error("Not a string");
2298 svn_swig_py_release_py_lock();
2303 svn_error_t
*svn_swig_py_repos_authz_func(svn_boolean_t
*allowed
,
2304 svn_fs_root_t
*root
,
2309 PyObject
*function
= baton
;
2311 PyObject
*py_pool
, *py_root
;
2312 svn_error_t
*err
= SVN_NO_ERROR
;
2316 if (function
== NULL
|| function
== Py_None
)
2317 return SVN_NO_ERROR
;
2319 svn_swig_py_acquire_py_lock();
2321 py_pool
= make_ob_pool(pool
);
2322 if (py_pool
== NULL
)
2324 err
= callback_exception_error();
2327 py_root
= make_ob_fs_root(root
, py_pool
);
2328 if (py_root
== NULL
)
2331 err
= callback_exception_error();
2335 if ((result
= PyObject_CallFunction(function
,
2337 py_root
, path
, py_pool
)) == NULL
)
2339 err
= callback_exception_error();
2343 if (PyInt_Check(result
))
2344 *allowed
= PyInt_AsLong(result
);
2345 else if (PyLong_Check(result
))
2346 *allowed
= PyLong_AsLong(result
);
2348 err
= callback_bad_return_error("Not an integer");
2354 svn_swig_py_release_py_lock();
2359 svn_error_t
*svn_swig_py_repos_history_func(void *baton
,
2361 svn_revnum_t revision
,
2364 PyObject
*function
= baton
;
2366 svn_error_t
*err
= SVN_NO_ERROR
;
2368 if (function
== NULL
|| function
== Py_None
)
2369 return SVN_NO_ERROR
;
2371 svn_swig_py_acquire_py_lock();
2372 if ((result
= PyObject_CallFunction(function
,
2375 make_ob_pool
, pool
)) == NULL
)
2377 err
= callback_exception_error();
2381 if (result
!= Py_None
)
2382 err
= callback_bad_return_error("Not None");
2385 svn_swig_py_release_py_lock();
2390 svn_error_t
*svn_swig_py_log_receiver(void *baton
,
2391 apr_hash_t
*changed_paths
,
2398 PyObject
*receiver
= baton
;
2399 PyObject
*result
, *py_pool
;
2401 svn_error_t
*err
= SVN_NO_ERROR
;
2403 if ((receiver
== NULL
) || (receiver
== Py_None
))
2404 return SVN_NO_ERROR
;
2406 svn_swig_py_acquire_py_lock();
2408 py_pool
= make_ob_pool(pool
);
2409 if (py_pool
== NULL
)
2411 err
= callback_exception_error();
2417 chpaths
= convert_hash(changed_paths
, convert_log_changed_path
,
2426 if ((result
= PyObject_CallFunction(receiver
,
2428 chpaths
, rev
, author
, date
, msg
,
2431 err
= callback_exception_error();
2435 if (result
!= Py_None
)
2436 err
= callback_bad_return_error("Not None");
2443 svn_swig_py_release_py_lock();
2447 svn_error_t
*svn_swig_py_log_entry_receiver(void *baton
,
2448 svn_log_entry_t
*log_entry
,
2451 PyObject
*receiver
= baton
;
2452 PyObject
*result
, *py_pool
;
2453 svn_error_t
*err
= SVN_NO_ERROR
;
2454 PyObject
*py_log_entry
;
2456 if ((receiver
== NULL
) || (receiver
== Py_None
))
2457 return SVN_NO_ERROR
;
2459 svn_swig_py_acquire_py_lock();
2461 py_pool
= make_ob_pool(pool
);
2462 if (py_pool
== NULL
)
2464 err
= callback_exception_error();
2468 py_log_entry
= svn_swig_NewPointerObjString(log_entry
, "svn_log_entry_t *",
2470 if ((result
= PyObject_CallFunction(receiver
,
2471 (char *)"OO", py_log_entry
,
2474 err
= callback_exception_error();
2478 if (result
!= Py_None
)
2479 err
= callback_bad_return_error("Not None");
2483 Py_DECREF(py_log_entry
);
2486 svn_swig_py_release_py_lock();
2490 svn_error_t
*svn_swig_py_info_receiver_func(void *baton
,
2492 const svn_info_t
*info
,
2495 PyObject
*receiver
= baton
;
2497 svn_error_t
*err
= SVN_NO_ERROR
;
2499 if ((receiver
== NULL
) || (receiver
== Py_None
))
2500 return SVN_NO_ERROR
;
2502 svn_swig_py_acquire_py_lock();
2504 if ((result
= PyObject_CallFunction(receiver
,
2506 path
, make_ob_info
, info
,
2507 make_ob_pool
, pool
)) == NULL
)
2509 err
= callback_exception_error();
2513 if (result
!= Py_None
)
2514 err
= callback_bad_return_error("Not None");
2518 svn_swig_py_release_py_lock();
2524 svn_swig_py_location_segment_receiver_func(svn_location_segment_t
*segment
,
2528 PyObject
*receiver
= baton
;
2530 svn_error_t
*err
= SVN_NO_ERROR
;
2532 if ((receiver
== NULL
) || (receiver
== Py_None
))
2533 return SVN_NO_ERROR
;
2535 svn_swig_py_acquire_py_lock();
2537 if ((result
= PyObject_CallFunction(receiver
,
2539 make_ob_location_segment
, segment
,
2540 make_ob_pool
, pool
)) == NULL
)
2542 err
= callback_exception_error();
2546 if (result
!= Py_None
)
2547 err
= callback_bad_return_error("Not None");
2551 svn_swig_py_release_py_lock();
2556 svn_error_t
*svn_swig_py_client_blame_receiver_func(void *baton
,
2557 apr_int64_t line_no
,
2558 svn_revnum_t revision
,
2564 PyObject
*receiver
= baton
;
2566 svn_error_t
*err
= SVN_NO_ERROR
;
2568 if ((receiver
== NULL
) || (receiver
== Py_None
))
2569 return SVN_NO_ERROR
;
2571 svn_swig_py_acquire_py_lock();
2573 if ((result
= PyObject_CallFunction(receiver
,
2575 (SVN_APR_INT64_T_PYCFMT
"lsssO&"),
2576 line_no
, revision
, author
, date
, line
,
2577 make_ob_pool
, pool
)) == NULL
)
2579 err
= callback_exception_error();
2583 if (result
!= Py_None
)
2584 err
= callback_bad_return_error("Not None");
2588 svn_swig_py_release_py_lock();
2592 svn_error_t
*svn_swig_py_changelist_receiver_func(void *baton
,
2594 const char *changelist
,
2597 PyObject
*receiver
= baton
;
2599 svn_error_t
*err
= SVN_NO_ERROR
;
2601 if ((receiver
== NULL
) || (receiver
== Py_None
))
2602 return SVN_NO_ERROR
;
2604 svn_swig_py_acquire_py_lock();
2606 if ((result
= PyObject_CallFunction(receiver
,
2609 make_ob_pool
, pool
)) == NULL
)
2611 err
= callback_exception_error();
2615 if (result
!= Py_None
)
2616 err
= callback_bad_return_error("Not None");
2620 svn_swig_py_release_py_lock();
2625 svn_swig_py_auth_simple_prompt_func(svn_auth_cred_simple_t
**cred
,
2628 const char *username
,
2629 svn_boolean_t may_save
,
2632 PyObject
*function
= baton
;
2634 svn_auth_cred_simple_t
*creds
= NULL
;
2635 svn_error_t
*err
= SVN_NO_ERROR
;
2637 if ((function
== NULL
) || (function
== Py_None
))
2638 return SVN_NO_ERROR
;
2640 svn_swig_py_acquire_py_lock();
2642 if ((result
= PyObject_CallFunction(function
,
2644 realm
, username
, may_save
,
2645 make_ob_pool
, pool
)) == NULL
)
2647 err
= callback_exception_error();
2651 if (result
!= Py_None
)
2653 svn_auth_cred_simple_t
*tmp_creds
= NULL
;
2654 if (svn_swig_ConvertPtrString(result
, (void **)&tmp_creds
,
2655 "svn_auth_cred_simple_t *"))
2657 err
= type_conversion_error("svn_auth_cred_simple_t *");
2661 creds
= apr_pcalloc(pool
, sizeof(*creds
));
2662 creds
->username
= tmp_creds
->username
?
2663 apr_pstrdup(pool
, tmp_creds
->username
) : NULL
;
2664 creds
->password
= tmp_creds
->password
?
2665 apr_pstrdup(pool
, tmp_creds
->password
) : NULL
;
2666 creds
->may_save
= tmp_creds
->may_save
;
2671 svn_swig_py_release_py_lock();
2677 svn_swig_py_auth_username_prompt_func(svn_auth_cred_username_t
**cred
,
2680 svn_boolean_t may_save
,
2683 PyObject
*function
= baton
;
2685 svn_auth_cred_username_t
*creds
= NULL
;
2686 svn_error_t
*err
= SVN_NO_ERROR
;
2688 if ((function
== NULL
) || (function
== Py_None
))
2689 return SVN_NO_ERROR
;
2691 svn_swig_py_acquire_py_lock();
2693 if ((result
= PyObject_CallFunction(function
,
2696 make_ob_pool
, pool
)) == NULL
)
2698 err
= callback_exception_error();
2702 if (result
!= Py_None
)
2704 svn_auth_cred_username_t
*tmp_creds
= NULL
;
2705 if (svn_swig_ConvertPtrString(result
, (void **)&tmp_creds
,
2706 "svn_auth_cred_username_t *"))
2708 err
= type_conversion_error("svn_auth_cred_username_t *");
2712 creds
= apr_pcalloc(pool
, sizeof(*creds
));
2713 creds
->username
= tmp_creds
->username
?
2714 apr_pstrdup(pool
, tmp_creds
->username
) : NULL
;
2715 creds
->may_save
= tmp_creds
->may_save
;
2720 svn_swig_py_release_py_lock();
2727 svn_swig_py_auth_ssl_server_trust_prompt_func(
2728 svn_auth_cred_ssl_server_trust_t
**cred
,
2731 apr_uint32_t failures
,
2732 const svn_auth_ssl_server_cert_info_t
*cert_info
,
2733 svn_boolean_t may_save
,
2736 PyObject
*function
= baton
;
2738 svn_auth_cred_ssl_server_trust_t
*creds
= NULL
;
2739 svn_error_t
*err
= SVN_NO_ERROR
;
2741 if ((function
== NULL
) || (function
== Py_None
))
2742 return SVN_NO_ERROR
;
2744 svn_swig_py_acquire_py_lock();
2746 if ((result
= PyObject_CallFunction(function
, (char *)"slO&lO&",
2747 realm
, failures
, make_ob_auth_ssl_server_cert_info
,
2748 cert_info
, may_save
, make_ob_pool
, pool
)) == NULL
)
2750 err
= callback_exception_error();
2754 if (result
!= Py_None
)
2756 svn_auth_cred_ssl_server_trust_t
*tmp_creds
= NULL
;
2757 if (svn_swig_ConvertPtrString
2758 (result
, (void **)&tmp_creds
,
2759 "svn_auth_cred_ssl_server_trust_t *"))
2761 err
= type_conversion_error
2762 ("svn_auth_cred_ssl_server_trust_t *");
2766 creds
= apr_pcalloc(pool
, sizeof(*creds
));
2767 *creds
= *tmp_creds
;
2773 svn_swig_py_release_py_lock();
2779 svn_swig_py_auth_ssl_client_cert_prompt_func(
2780 svn_auth_cred_ssl_client_cert_t
**cred
,
2783 svn_boolean_t may_save
,
2786 PyObject
*function
= baton
;
2788 svn_auth_cred_ssl_client_cert_t
*creds
= NULL
;
2789 svn_error_t
*err
= SVN_NO_ERROR
;
2791 if ((function
== NULL
) || (function
== Py_None
))
2792 return SVN_NO_ERROR
;
2794 svn_swig_py_acquire_py_lock();
2796 if ((result
= PyObject_CallFunction(function
,
2799 make_ob_pool
, pool
)) == NULL
)
2801 err
= callback_exception_error();
2805 if (result
!= Py_None
)
2807 svn_auth_cred_ssl_client_cert_t
*tmp_creds
= NULL
;
2808 if (svn_swig_ConvertPtrString
2809 (result
, (void **)&tmp_creds
,
2810 "svn_auth_cred_ssl_client_cert_t *"))
2812 err
= type_conversion_error("svn_auth_cred_ssl_client_cert_t *");
2816 creds
= apr_pcalloc(pool
, sizeof(*creds
));
2817 creds
->cert_file
= tmp_creds
->cert_file
?
2818 apr_pstrdup(pool
, tmp_creds
->cert_file
) : NULL
;
2819 creds
->may_save
= tmp_creds
->may_save
;
2824 svn_swig_py_release_py_lock();
2830 svn_swig_py_auth_ssl_client_cert_pw_prompt_func(
2831 svn_auth_cred_ssl_client_cert_pw_t
**cred
,
2834 svn_boolean_t may_save
,
2837 PyObject
*function
= baton
;
2839 svn_auth_cred_ssl_client_cert_pw_t
*creds
= NULL
;
2840 svn_error_t
*err
= SVN_NO_ERROR
;
2842 if ((function
== NULL
) || (function
== Py_None
))
2843 return SVN_NO_ERROR
;
2845 svn_swig_py_acquire_py_lock();
2847 if ((result
= PyObject_CallFunction(function
,
2850 make_ob_pool
, pool
)) == NULL
)
2852 err
= callback_exception_error();
2856 if (result
!= Py_None
)
2858 svn_auth_cred_ssl_client_cert_pw_t
*tmp_creds
= NULL
;
2859 if (svn_swig_ConvertPtrString
2860 (result
, (void **)&tmp_creds
,
2861 "svn_auth_cred_ssl_client_cert_pw_t *"))
2863 err
= type_conversion_error
2864 ("svn_auth_cred_ssl_client_cert_pw_t *");
2868 creds
= apr_pcalloc(pool
, sizeof(*creds
));
2869 creds
->password
= tmp_creds
->password
?
2870 apr_pstrdup(pool
, tmp_creds
->password
) : NULL
;
2871 creds
->may_save
= tmp_creds
->may_save
;
2876 svn_swig_py_release_py_lock();
2881 /* svn_ra_callbacks_t */
2882 static svn_error_t
*
2883 ra_callbacks_open_tmp_file(apr_file_t
**fp
,
2884 void *callback_baton
,
2887 PyObject
*callbacks
= (PyObject
*)callback_baton
;
2888 PyObject
*py_callback
, *result
;
2889 svn_error_t
*err
= SVN_NO_ERROR
;
2893 svn_swig_py_acquire_py_lock();
2895 py_callback
= PyObject_GetAttrString(callbacks
, (char *)"open_tmp_file");
2896 if (py_callback
== NULL
)
2898 err
= callback_exception_error();
2901 else if (py_callback
== Py_None
)
2906 if ((result
= PyObject_CallFunction(py_callback
,
2908 make_ob_pool
, pool
)) == NULL
)
2910 err
= callback_exception_error();
2912 else if (result
!= Py_None
)
2914 *fp
= svn_swig_py_make_file(result
, pool
);
2917 err
= callback_exception_error();
2923 Py_XDECREF(py_callback
);
2924 svn_swig_py_release_py_lock();
2928 /* svn_ra_callbacks_t */
2929 static svn_error_t
*
2930 ra_callbacks_get_wc_prop(void *baton
,
2933 const svn_string_t
**value
,
2936 PyObject
*callbacks
= (PyObject
*)baton
;
2937 PyObject
*py_callback
, *result
;
2938 svn_error_t
*err
= SVN_NO_ERROR
;
2942 svn_swig_py_acquire_py_lock();
2944 py_callback
= PyObject_GetAttrString(callbacks
, (char *)"get_wc_prop");
2945 if (py_callback
== NULL
)
2947 err
= callback_exception_error();
2950 else if (py_callback
== Py_None
)
2955 if ((result
= PyObject_CallFunction(py_callback
,
2956 (char *)"ssO&", path
, name
,
2957 make_ob_pool
, pool
)) == NULL
)
2959 err
= callback_exception_error();
2961 else if (result
!= Py_None
)
2965 if (PyString_AsStringAndSize(result
, &buf
, &len
) == -1)
2967 err
= callback_exception_error();
2971 *value
= svn_string_ncreate(buf
, len
, pool
);
2977 Py_XDECREF(py_callback
);
2978 svn_swig_py_release_py_lock();
2982 /* svn_ra_callbacks_t */
2983 static svn_error_t
*
2984 ra_callbacks_push_or_set_wc_prop(const char *callback
,
2988 const svn_string_t
*value
,
2991 PyObject
*callbacks
= (PyObject
*)baton
;
2992 PyObject
*py_callback
, *py_value
, *result
;
2993 svn_error_t
*err
= SVN_NO_ERROR
;
2995 svn_swig_py_acquire_py_lock();
2997 py_callback
= PyObject_GetAttrString(callbacks
, (char *)callback
);
2998 if (py_callback
== NULL
)
3000 err
= callback_exception_error();
3003 else if (py_callback
== Py_None
)
3008 if ((py_value
= PyString_FromStringAndSize(value
->data
, value
->len
)) == NULL
)
3010 err
= callback_exception_error();
3014 if ((result
= PyObject_CallFunction(py_callback
,
3015 (char *)"ssOO&", path
, name
, py_value
,
3016 make_ob_pool
, pool
)) == NULL
)
3018 err
= callback_exception_error();
3023 Py_XDECREF(py_callback
);
3024 svn_swig_py_release_py_lock();
3028 /* svn_ra_callbacks_t */
3029 static svn_error_t
*
3030 ra_callbacks_set_wc_prop(void *baton
,
3033 const svn_string_t
*value
,
3036 return ra_callbacks_push_or_set_wc_prop("set_wc_prop", baton
, path
,
3040 /* svn_ra_callbacks_t */
3041 static svn_error_t
*
3042 ra_callbacks_push_wc_prop(void *baton
,
3045 const svn_string_t
*value
,
3048 return ra_callbacks_push_or_set_wc_prop("push_wc_prop", baton
, path
,
3052 /* svn_ra_callbacks_t */
3053 static svn_error_t
*
3054 ra_callbacks_invalidate_wc_props(void *baton
,
3059 PyObject
*callbacks
= (PyObject
*)baton
;
3060 PyObject
*py_callback
, *result
;
3061 svn_error_t
*err
= SVN_NO_ERROR
;
3063 svn_swig_py_acquire_py_lock();
3065 py_callback
= PyObject_GetAttrString(callbacks
,
3066 (char *)"invalidate_wc_props");
3067 if (py_callback
== NULL
)
3069 err
= callback_exception_error();
3072 else if (py_callback
== Py_None
)
3077 if ((result
= PyObject_CallFunction(py_callback
,
3078 (char *)"ssO&", path
, name
,
3079 make_ob_pool
, pool
)) == NULL
)
3081 err
= callback_exception_error();
3086 Py_XDECREF(py_callback
);
3087 svn_swig_py_release_py_lock();
3091 /* svn_ra_callbacks_t */
3093 ra_callbacks_progress_func(apr_off_t progress
,
3098 PyObject
*callbacks
= (PyObject
*)baton
;
3099 PyObject
*py_callback
, *py_progress
, *py_total
, *result
;
3101 py_progress
= py_total
= NULL
;
3103 svn_swig_py_acquire_py_lock();
3105 py_callback
= PyObject_GetAttrString(callbacks
,
3106 (char *)"progress_func");
3107 if (py_callback
== NULL
)
3109 /* Ouch, no way to pass on exceptions! */
3110 /* err = callback_exception_error(); */
3113 else if (py_callback
== Py_None
)
3118 /* Create PyLongs for progress and total up-front, rather than
3119 passing them directly, so we don't have to worry about the size
3120 (if apr_off_t is 4 bytes, we'd better use the l specifier; if 8
3121 bytes, better use L...) */
3122 if ((py_progress
= PyLong_FromLongLong(progress
)) == NULL
)
3124 /* Ouch, no way to pass on exceptions! */
3125 /* err = callback_exception_error(); */
3128 if ((py_total
= PyLong_FromLongLong(total
)) == NULL
)
3130 /* Ouch, no way to pass on exceptions! */
3131 /* err = callback_exception_error(); */
3134 if ((result
= PyObject_CallFunction(py_callback
,
3135 (char *)"OOO&", py_progress
, py_total
,
3136 make_ob_pool
, pool
)) == NULL
)
3138 /* Ouch, no way to pass on exceptions! */
3139 /* err = callback_exception_error(); */
3144 Py_XDECREF(py_callback
);
3145 Py_XDECREF(py_progress
);
3146 Py_XDECREF(py_total
);
3147 svn_swig_py_release_py_lock();
3148 /* Sure hope nothing went wrong... */
3152 /* svn_ra_callbacks_t */
3153 static svn_error_t
*
3154 ra_callbacks_cancel_func(void *baton
)
3156 PyObject
*callbacks
= (PyObject
*)baton
;
3157 PyObject
*py_callback
;
3159 svn_swig_py_acquire_py_lock();
3160 py_callback
= PyObject_GetAttrString(callbacks
,
3161 (char *)"cancel_func");
3162 svn_swig_py_release_py_lock();
3163 return svn_swig_py_cancel_func(py_callback
);
3166 /* svn_ra_callbacks_t */
3167 static svn_error_t
*
3168 ra_callbacks_get_client_string(void *baton
,
3172 PyObject
*callbacks
= (PyObject
*)baton
;
3173 PyObject
*py_callback
, *result
;
3174 svn_error_t
*err
= SVN_NO_ERROR
;
3178 svn_swig_py_acquire_py_lock();
3180 py_callback
= PyObject_GetAttrString(callbacks
, (char *)"get_client_string");
3181 if (py_callback
== NULL
)
3183 err
= callback_exception_error();
3186 else if (py_callback
== Py_None
)
3191 if ((result
= PyObject_CallFunction(py_callback
,
3193 make_ob_pool
, pool
)) == NULL
)
3195 err
= callback_exception_error();
3197 else if (result
!= Py_None
)
3199 if ((*name
= PyString_AsString(result
)) == NULL
)
3201 err
= callback_exception_error();
3207 Py_XDECREF(py_callback
);
3208 svn_swig_py_release_py_lock();
3213 svn_swig_py_setup_ra_callbacks(svn_ra_callbacks2_t
**callbacks
,
3215 PyObject
*py_callbacks
,
3218 svn_error_t
*err
= svn_ra_create_callbacks(callbacks
, pool
);
3219 PyObject
*py_auth_baton
;
3223 svn_swig_py_svn_exception(err
);
3227 (*callbacks
)->open_tmp_file
= ra_callbacks_open_tmp_file
;
3229 py_auth_baton
= PyObject_GetAttrString(py_callbacks
, (char *)"auth_baton");
3231 if (svn_swig_ConvertPtrString(py_auth_baton
,
3232 (void **)&((*callbacks
)->auth_baton
),
3233 "svn_auth_baton_t *"))
3235 err
= type_conversion_error("svn_auth_baton_t *");
3236 svn_swig_py_svn_exception(err
);
3237 Py_XDECREF(py_auth_baton
);
3241 Py_XDECREF(py_auth_baton
);
3243 (*callbacks
)->get_wc_prop
= ra_callbacks_get_wc_prop
;
3244 (*callbacks
)->set_wc_prop
= ra_callbacks_set_wc_prop
;
3245 (*callbacks
)->push_wc_prop
= ra_callbacks_push_wc_prop
;
3246 (*callbacks
)->invalidate_wc_props
= ra_callbacks_invalidate_wc_props
;
3247 (*callbacks
)->progress_func
= ra_callbacks_progress_func
;
3248 (*callbacks
)->progress_baton
= py_callbacks
;
3249 (*callbacks
)->cancel_func
= ra_callbacks_cancel_func
;
3250 (*callbacks
)->get_client_string
= ra_callbacks_get_client_string
;
3252 *baton
= py_callbacks
;
3255 svn_error_t
*svn_swig_py_commit_callback2(const svn_commit_info_t
*commit_info
,
3259 PyObject
*receiver
= baton
;
3261 svn_error_t
*err
= SVN_NO_ERROR
;
3263 if ((receiver
== NULL
) || (receiver
== Py_None
))
3264 return SVN_NO_ERROR
;
3266 svn_swig_py_acquire_py_lock();
3268 if ((result
= PyObject_CallFunction(receiver
,
3270 make_ob_commit_info
, commit_info
,
3271 make_ob_pool
, pool
)) == NULL
)
3273 err
= callback_exception_error();
3277 if (result
!= Py_None
)
3278 err
= callback_bad_return_error("Not None");
3282 svn_swig_py_release_py_lock();
3287 svn_error_t
*svn_swig_py_commit_callback(svn_revnum_t new_revision
,
3292 PyObject
*receiver
= baton
;
3294 svn_error_t
*err
= SVN_NO_ERROR
;
3296 if ((receiver
== NULL
) || (receiver
== Py_None
))
3297 return SVN_NO_ERROR
;
3299 svn_swig_py_acquire_py_lock();
3301 if ((result
= PyObject_CallFunction(receiver
,
3303 new_revision
, date
, author
)) == NULL
)
3305 err
= callback_exception_error();
3309 if (result
!= Py_None
)
3310 err
= callback_bad_return_error("Not None");
3314 svn_swig_py_release_py_lock();
3319 svn_error_t
*svn_swig_py_ra_file_rev_handler_func(
3323 apr_hash_t
*rev_props
,
3324 svn_txdelta_window_handler_t
*delta_handler
,
3326 apr_array_header_t
*prop_diffs
,
3329 PyObject
*handler
= baton
;
3330 PyObject
*result
, *py_rev_props
= NULL
, *py_prop_diffs
= NULL
;
3331 svn_error_t
*err
= SVN_NO_ERROR
;
3333 if ((handler
== NULL
) || (handler
== Py_None
))
3334 return SVN_NO_ERROR
;
3336 svn_swig_py_acquire_py_lock();
3338 py_rev_props
= svn_swig_py_prophash_to_dict(rev_props
);
3339 if (py_rev_props
== NULL
)
3341 err
= type_conversion_error("apr_hash_t *");
3345 py_prop_diffs
= svn_swig_py_proparray_to_dict(prop_diffs
);
3347 if (py_prop_diffs
== NULL
)
3349 err
= type_conversion_error("apr_array_header_t *");
3353 if ((result
= PyObject_CallFunction(handler
,
3355 path
, rev
, py_rev_props
, py_prop_diffs
,
3356 make_ob_pool
, pool
)) == NULL
)
3358 err
= callback_exception_error();
3362 if (result
!= Py_None
)
3363 err
= callback_bad_return_error("Not None");
3365 /* FIXME: Support returned TxDeltaWindow object and
3366 * set delta_handler and delta_baton */
3367 *delta_handler
= NULL
;
3368 *delta_baton
= NULL
;
3375 Py_XDECREF(py_rev_props
);
3376 Py_XDECREF(py_prop_diffs
);
3378 svn_swig_py_release_py_lock();
3383 svn_error_t
*svn_swig_py_ra_lock_callback(
3386 svn_boolean_t do_lock
,
3387 const svn_lock_t
*lock
,
3388 svn_error_t
*ra_err
,
3391 svn_error_t
*err
= SVN_NO_ERROR
;
3392 PyObject
*py_callback
= baton
, *result
;
3394 if (py_callback
== NULL
|| py_callback
== Py_None
)
3395 return SVN_NO_ERROR
;
3397 svn_swig_py_acquire_py_lock();
3399 if ((result
= PyObject_CallFunction(py_callback
,
3403 make_ob_pool
, pool
)) == NULL
)
3405 err
= callback_exception_error();
3407 else if (result
!= Py_None
)
3409 err
= callback_bad_return_error("Not None");
3414 svn_swig_py_release_py_lock();
3419 static svn_error_t
*reporter_set_path(void *report_baton
,
3421 svn_revnum_t revision
,
3422 svn_boolean_t start_empty
,
3423 const char *lock_token
,
3426 svn_error_t
*err
= SVN_NO_ERROR
;
3427 PyObject
*py_reporter
= report_baton
, *result
;
3429 if (py_reporter
== NULL
|| py_reporter
== Py_None
)
3430 return SVN_NO_ERROR
;
3432 svn_swig_py_acquire_py_lock();
3434 if ((result
= PyObject_CallMethod(py_reporter
,
3438 start_empty
, lock_token
,
3439 make_ob_pool
, pool
)) == NULL
)
3441 err
= callback_exception_error();
3443 else if (result
!= Py_None
)
3445 err
= callback_bad_return_error("Not None");
3450 svn_swig_py_release_py_lock();
3455 static svn_error_t
*reporter_delete_path(void *report_baton
,
3459 svn_error_t
*err
= SVN_NO_ERROR
;
3460 PyObject
*py_reporter
= report_baton
, *result
;
3462 if (py_reporter
== NULL
|| py_reporter
== Py_None
)
3463 return SVN_NO_ERROR
;
3465 svn_swig_py_acquire_py_lock();
3467 if ((result
= PyObject_CallMethod(py_reporter
,
3468 (char *)"delete_path",
3471 make_ob_pool
, pool
)) == NULL
)
3473 err
= callback_exception_error();
3475 else if (result
!= Py_None
)
3477 err
= callback_bad_return_error("Not None");
3482 svn_swig_py_release_py_lock();
3487 static svn_error_t
*reporter_link_path(void *report_baton
,
3490 svn_revnum_t revision
,
3491 svn_boolean_t start_empty
,
3492 const char *lock_token
,
3495 svn_error_t
*err
= SVN_NO_ERROR
;
3496 PyObject
*py_reporter
= report_baton
, *result
;
3498 if (py_reporter
== NULL
|| py_reporter
== Py_None
)
3499 return SVN_NO_ERROR
;
3501 svn_swig_py_acquire_py_lock();
3503 if ((result
= PyObject_CallMethod(py_reporter
,
3504 (char *)"link_path",
3506 path
, url
, revision
,
3507 start_empty
, lock_token
,
3508 make_ob_pool
, pool
)) == NULL
)
3510 err
= callback_exception_error();
3512 else if (result
!= Py_None
)
3514 err
= callback_bad_return_error("Not None");
3519 svn_swig_py_release_py_lock();
3524 static svn_error_t
*reporter_finish_report(void *report_baton
,
3527 svn_error_t
*err
= SVN_NO_ERROR
;
3529 PyObject
*py_reporter
= report_baton
, *result
;
3531 if (py_reporter
== NULL
|| py_reporter
== Py_None
)
3532 return SVN_NO_ERROR
;
3534 svn_swig_py_acquire_py_lock();
3536 if ((result
= PyObject_CallMethod(py_reporter
,
3537 (char *)"finish_report",
3539 make_ob_pool
, pool
)) == NULL
)
3541 err
= callback_exception_error();
3543 else if (result
!= Py_None
)
3545 err
= callback_bad_return_error("Not None");
3550 svn_swig_py_release_py_lock();
3555 static svn_error_t
*reporter_abort_report(void *report_baton
,
3558 svn_error_t
*err
= SVN_NO_ERROR
;
3560 PyObject
*py_reporter
= report_baton
, *result
;
3562 if (py_reporter
== NULL
|| py_reporter
== Py_None
)
3563 return SVN_NO_ERROR
;
3565 svn_swig_py_acquire_py_lock();
3567 if ((result
= PyObject_CallMethod(py_reporter
,
3568 (char *)"abort_report",
3570 make_ob_pool
, pool
)) == NULL
)
3572 err
= callback_exception_error();
3574 else if (result
!= Py_None
)
3576 err
= callback_bad_return_error("Not None");
3581 svn_swig_py_release_py_lock();
3586 const svn_ra_reporter2_t swig_py_ra_reporter2
= {
3588 reporter_delete_path
,
3590 reporter_finish_report
,
3591 reporter_abort_report