📄 swigutil_py.c
字号:
#define DECLARE_SWIG_CONSTRUCTOR(type, dup) \static PyObject *make_ob_##type(void *value) \{ \ apr_pool_t *new_pool = svn_pool_create(_global_pool); \ PyObject *new_py_pool = svn_swig_NewPointerObj(new_pool, \ svn_swig_TypeQuery("apr_pool_t *"), _global_svn_swig_py_pool); \ svn_##type##_t *new_value = dup(value, new_pool); \ return svn_swig_NewPointerObjString(new_value, "svn_" #type "_t *", \ new_py_pool); \} DECLARE_SWIG_CONSTRUCTOR(txdelta_window, svn_txdelta_window_dup)DECLARE_SWIG_CONSTRUCTOR(log_changed_path, svn_log_changed_path_dup)DECLARE_SWIG_CONSTRUCTOR(wc_status, svn_wc_dup_status)DECLARE_SWIG_CONSTRUCTOR(lock, svn_lock_dup)DECLARE_SWIG_CONSTRUCTOR(auth_ssl_server_cert_info, svn_auth_ssl_server_cert_info_dup)DECLARE_SWIG_CONSTRUCTOR(info, svn_info_dup)static PyObject *convert_log_changed_path(void *value, void *ctx, PyObject *py_pool){ return make_ob_log_changed_path(value);}PyObject *svn_swig_py_c_strings_to_list(char **strings){ PyObject *list = PyList_New(0); char *s; while ((s = *strings++) != NULL) { PyObject *ob = PyString_FromString(s); if (ob == NULL) goto error; if (PyList_Append(list, ob) == -1) goto error; } return list; error: Py_DECREF(list); return NULL;}apr_hash_t *svn_swig_py_stringhash_from_dict(PyObject *dict, apr_pool_t *pool){ apr_hash_t *hash; PyObject *keys; int i, num_keys; if (dict == Py_None) return NULL; if (!PyDict_Check(dict)) { PyErr_SetString(PyExc_TypeError, "not a dictionary"); return NULL; } hash = apr_hash_make(pool); keys = PyDict_Keys(dict); num_keys = PyList_Size(keys); for (i = 0; i < num_keys; i++) { PyObject *key = PyList_GetItem(keys, i); PyObject *value = PyDict_GetItem(dict, key); const char *propname = make_string_from_ob(key, pool); const char *propval = make_string_from_ob(value, pool); if (! (propname && propval)) { PyErr_SetString(PyExc_TypeError, "dictionary keys/values aren't strings"); Py_DECREF(keys); return NULL; } apr_hash_set(hash, propname, APR_HASH_KEY_STRING, propval); } Py_DECREF(keys); return hash;}apr_hash_t *svn_swig_py_prophash_from_dict(PyObject *dict, apr_pool_t *pool){ apr_hash_t *hash; PyObject *keys; int i, num_keys; if (dict == Py_None) return NULL; if (!PyDict_Check(dict)) { PyErr_SetString(PyExc_TypeError, "not a dictionary"); return NULL; } hash = apr_hash_make(pool); keys = PyDict_Keys(dict); num_keys = PyList_Size(keys); for (i = 0; i < num_keys; i++) { PyObject *key = PyList_GetItem(keys, i); PyObject *value = PyDict_GetItem(dict, key); const char *propname = make_string_from_ob(key, pool); svn_string_t *propval = make_svn_string_from_ob(value, pool); if (! (propname && propval)) { PyErr_SetString(PyExc_TypeError, "dictionary keys/values aren't strings"); Py_DECREF(keys); return NULL; } apr_hash_set(hash, propname, APR_HASH_KEY_STRING, propval); } Py_DECREF(keys); return hash;}const apr_array_header_t *svn_swig_py_strings_to_array(PyObject *source, apr_pool_t *pool){ int targlen; apr_array_header_t *temp; if (!PySequence_Check(source)) { PyErr_SetString(PyExc_TypeError, "not a sequence"); return NULL; } targlen = PySequence_Length(source); temp = apr_array_make(pool, targlen, sizeof(const char *)); /* APR_ARRAY_IDX doesn't actually increment the array item count (like, say, apr_array_push would). */ temp->nelts = targlen; while (targlen--) { PyObject *o = PySequence_GetItem(source, targlen); if (o == NULL) return NULL; if (!PyString_Check(o)) { Py_DECREF(o); PyErr_SetString(PyExc_TypeError, "not a string"); return NULL; } APR_ARRAY_IDX(temp, targlen, const char *) = PyString_AS_STRING(o); Py_DECREF(o); } return temp;}const apr_array_header_t *svn_swig_py_revnums_to_array(PyObject *source, apr_pool_t *pool){ int targlen; apr_array_header_t *temp; if (!PySequence_Check(source)) { PyErr_SetString(PyExc_TypeError, "not a sequence"); return NULL; } targlen = PySequence_Length(source); temp = apr_array_make(pool, targlen, sizeof(svn_revnum_t)); /* APR_ARRAY_IDX doesn't actually increment the array item count (like, say, apr_array_push would). */ temp->nelts = targlen; while (targlen--) { PyObject *o = PySequence_GetItem(source, targlen); if (o == NULL) return NULL; if (PyLong_Check(o)) { APR_ARRAY_IDX(temp, targlen, svn_revnum_t) = (svn_revnum_t)PyLong_AsLong(o); } else if (PyInt_Check(o)) { APR_ARRAY_IDX(temp, targlen, svn_revnum_t) = (svn_revnum_t)PyInt_AsLong(o); } else { Py_DECREF(o); PyErr_SetString(PyExc_TypeError, "not an integer type"); return NULL; } Py_DECREF(o); } return temp;}/*** apr_array_header_t conversions. To create a new type of converter, simply copy-n-paste one of these function and tweak the creation of the PyObject *ob. ***/PyObject *svn_swig_py_array_to_list(const apr_array_header_t *array){ PyObject *list = PyList_New(array->nelts); int i; for (i = 0; i < array->nelts; ++i) { PyObject *ob = PyString_FromString(APR_ARRAY_IDX(array, i, const char *)); if (ob == NULL) goto error; PyList_SET_ITEM(list, i, ob); } return list; error: Py_DECREF(list); return NULL;}/* Formerly used by pre-1.0 APIs. Now unusedPyObject *svn_swig_py_revarray_to_list(const apr_array_header_t *array){ PyObject *list = PyList_New(array->nelts); int i; for (i = 0; i < array->nelts; ++i) { PyObject *ob = PyInt_FromLong(APR_ARRAY_IDX(array, i, svn_revnum_t)); if (ob == NULL) goto error; PyList_SET_ITEM(list, i, ob); } return list; error: Py_DECREF(list); return NULL;}*/static PyObject *commit_item_array_to_list(const apr_array_header_t *array){ PyObject *list = PyList_New(array->nelts); int i; for (i = 0; i < array->nelts; ++i) { PyObject *ob = convert_svn_client_commit_item_t (APR_ARRAY_IDX(array, i, svn_client_commit_item_t *), NULL); if (ob == NULL) goto error; PyList_SET_ITEM(list, i, ob); } return list; error: Py_DECREF(list); return NULL;}/*** Errors ***//* Return a Subversion error about a failed callback. */static svn_error_t *callback_exception_error(void){ return svn_error_create(SVN_ERR_SWIG_PY_EXCEPTION_SET, NULL, "Python callback raised an exception");}/* Raise a TypeError exception with MESSAGE, and return a Subversion error about an invalid return from a callback. */static svn_error_t *callback_bad_return_error(const char *message){ PyErr_SetString(PyExc_TypeError, message); return svn_error_create(APR_EGENERAL, NULL, "Python callback returned an invalid object");}/* Return a generic error about not being able to map types. */static svn_error_t *type_conversion_error(const char *datatype){ return svn_error_createf(APR_EGENERAL, NULL, "Error converting object of type '%s'", datatype);}/*** Editor Wrapping ***//* this baton is used for the editor, directory, and file batons. */typedef struct { PyObject *editor; /* the editor handling the callbacks */ PyObject *baton; /* the dir/file baton (or NULL for edit baton) */} item_baton;static item_baton *make_baton(apr_pool_t *pool, PyObject *editor, PyObject *baton){ item_baton *newb = apr_palloc(pool, sizeof(*newb)); /* Note: We steal the caller's reference to 'baton'. Also, to avoid memory leaks, we borrow the caller's reference to 'editor'. In this case, borrowing the reference to 'editor' is safe because the contents of an item_baton struct are only used by functino calls which operate on the editor itself. */ newb->editor = editor; newb->baton = baton; return newb;}static svn_error_t *close_baton(void *baton, const char *method){ item_baton *ib = baton; PyObject *result; svn_error_t *err; svn_swig_py_acquire_py_lock(); /* If there is no baton object, then it is an edit_baton, and we should not bother to pass an object. Note that we still shove a NULL onto the stack, but the format specified just won't reference it. */ /* ### python doesn't have 'const' on the method name and format */ if ((result = PyObject_CallMethod(ib->editor, (char *)method, ib->baton ? (char *)"(O)" : NULL, ib->baton)) == NULL) { err = callback_exception_error(); goto finished; } /* there is no return value, so just toss this object (probably Py_None) */ Py_DECREF(result); /* We're now done with the baton. Since there isn't really a free, all we need to do is note that its objects are no longer referenced by the baton. */ Py_XDECREF(ib->baton);#ifdef SVN_DEBUG ib->editor = ib->baton = NULL;#endif err = SVN_NO_ERROR; finished: svn_swig_py_release_py_lock(); return err;}static svn_error_t *set_target_revision(void *edit_baton, svn_revnum_t target_revision, apr_pool_t *pool){ item_baton *ib = edit_baton; PyObject *result; svn_error_t *err; svn_swig_py_acquire_py_lock(); /* ### python doesn't have 'const' on the method name and format */ if ((result = PyObject_CallMethod(ib->editor, (char *)"set_target_revision", (char *)"l", target_revision)) == NULL) { err = callback_exception_error(); goto finished; } /* there is no return value, so just toss this object (probably Py_None) */ Py_DECREF(result); err = SVN_NO_ERROR; finished: svn_swig_py_release_py_lock(); return err;}static svn_error_t *open_root(void *edit_baton, svn_revnum_t base_revision, apr_pool_t *dir_pool, void **root_baton){ item_baton *ib = edit_baton; PyObject *result; svn_error_t *err; svn_swig_py_acquire_py_lock(); /* ### python doesn't have 'const' on the method name and format */ if ((result = PyObject_CallMethod(ib->editor, (char *)"open_root", (char *)"lO&", base_revision, make_ob_pool, dir_pool)) == NULL) { err = callback_exception_error(); goto finished; } /* make_baton takes our 'result' reference */ *root_baton = make_baton(dir_pool, ib->editor, result); err = SVN_NO_ERROR; finished: svn_swig_py_release_py_lock(); return err;}static svn_error_t *delete_entry(const char *path, svn_revnum_t revision, void *parent_baton, apr_pool_t *pool){ item_baton *ib = parent_baton; PyObject *result; svn_error_t *err; svn_swig_py_acquire_py_lock(); /* ### python doesn't have 'const' on the method name and format */ if ((result = PyObject_CallMethod(ib->editor, (char *)"delete_entry", (char *)"slOO&", path, revision, ib->baton, make_ob_pool, pool)) == NULL) { err = callback_exception_error(); goto finished; } /* there is no return value, so just toss this object (probably Py_None) */ Py_DECREF(result); err = SVN_NO_ERROR; finished: svn_swig_py_release_py_lock(); return err;}static svn_error_t *add_directory(const char *path, void *parent_baton, const char *copyfrom_path, svn_revnum_t copyfrom_revision, apr_pool_t *dir_pool, void **child_baton){ item_baton *ib = parent_baton; PyObject *result; svn_error_t *err; svn_swig_py_acquire_py_lock(); /* ### python doesn't have 'const' on the method name and format */ if ((result = PyObject_CallMethod(ib->editor, (char *)"add_directory", (char *)"sOslO&", path, ib->baton, copyfrom_path, copyfrom_revision, make_ob_pool, dir_pool)) == NULL) { err = callback_exception_error(); goto finished; } /* make_baton takes our 'result' reference */ *child_baton = make_baton(dir_pool, ib->editor, result); err = SVN_NO_ERROR; finished: svn_swig_py_release_py_lock(); return err;}static svn_error_t *open_directory(const char *path, void *parent_baton, svn_revnum_t base_revision, apr_pool_t *dir_pool, void **child_baton){ item_baton *ib = parent_baton; PyObject *result; svn_error_t *err; svn_swig_py_acquire_py_lock(); /* ### python doesn't have 'const' on the method name and format */ if ((result = PyObject_CallMethod(ib->editor, (char *)"open_directory", (char *)"sOlO&", path, ib->baton, base_revision, make_ob_pool, dir_pool)) == NULL) { err = callback_exception_error(); goto finished; } /* make_baton takes our 'result' reference */ *child_baton = make_baton(dir_pool, ib->editor, result); err = SVN_NO_ERROR; finished: svn_swig_py_release_py_lock(); return err;}static svn_error_t *change_dir_prop(void *dir_baton, const char *name, const svn_string_t *value, apr_pool_t *pool){ item_baton *ib = dir_baton; PyObject *result; svn_error_t *err; svn_swig_py_acquire_py_lock(); /* ### python doesn't have 'const' on the method name and format */ if ((result = PyObject_CallMethod(ib->editor, (char *)"change_dir_prop", (char *)"Oss#O&", ib->baton, name, value ? value->data : NULL, value ? value->len : 0, make_ob_pool, pool)) == NULL) { err = callback_exception_error(); goto finished; } /* there is no return value, so just toss this object (probably Py_None) */ Py_DECREF(result); err = SVN_NO_ERROR; finished: svn_swig_py_release_py_lock(); return err;}static svn_error_t *close_directory(void *dir_baton, apr_pool_t *pool){ return close_baton(dir_baton, "close_directory");}static svn_error_t *add_file(const char *path,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -