| commit 2153: | f67406ad6c4c |
| parent 2152: | 8743786d3c9f |
| branch: | default |
util: add 'apr_file_from_object' for converting Python files to APR.
Changed (Δ908 bytes):
raw changeset »
subvertpy/_ra.c (2 lines added, 12 lines removed)
subvertpy/util.c (25 lines added, 0 lines removed)
subvertpy/util.h (1 lines added, 0 lines removed)
Up to file-list subvertpy/_ra.c:
| … | … | @@ -673,18 +673,8 @@ static svn_error_t *py_open_tmp_file(apr |
673 |
673 |
} |
674 |
674 |
Py_DECREF(ret); |
675 |
675 |
} else if (PyFile_Check(ret)) { |
676 |
FILE *file; |
|
677 |
apr_os_file_t osfile; |
|
678 |
||
679 |
file = PyFile_AsFile(ret); |
|
680 |
#ifdef WIN32 |
|
681 |
osfile = (apr_os_file_t)_get_osfhandle(_fileno(file)); |
|
682 |
#else |
|
683 |
osfile = (apr_os_file_t)fileno(file); |
|
684 |
#endif |
|
685 |
status = apr_os_file_put(fp, &osfile, O_CREAT | O_WRONLY, pool); |
|
686 |
if (status) { |
|
687 |
PyErr_SetAprStatus(status); |
|
676 |
*fp = apr_file_from_object(ret, pool); |
|
677 |
if (!*fp) { |
|
688 |
678 |
Py_DECREF(ret); |
689 |
679 |
PyGILState_Release(state); |
690 |
680 |
return py_svn_error(); |
Up to file-list subvertpy/util.c:
19 |
19 |
#include <stdbool.h> |
20 |
20 |
#include <Python.h> |
21 |
21 |
#include <apr_general.h> |
22 |
#include <apr_file_io.h> |
|
23 |
#include <apr_portable.h> |
|
22 |
24 |
#include <svn_error.h> |
23 |
25 |
#include <svn_io.h> |
24 |
26 |
#include <apr_errno.h> |
| … | … | @@ -554,3 +556,26 @@ PyObject *py_dirent(svn_dirent_t *dirent |
554 |
556 |
return ret; |
555 |
557 |
} |
556 |
558 |
|
559 |
apr_file_t *apr_file_from_object(PyObject *object, apr_pool_t *pool) |
|
560 |
{ |
|
561 |
apr_status_t status; |
|
562 |
FILE *file; |
|
563 |
apr_file_t *fp; |
|
564 |
apr_os_file_t osfile; |
|
565 |
||
566 |
file = PyFile_AsFile(object); |
|
567 |
#ifdef WIN32 |
|
568 |
osfile = (apr_os_file_t)_get_osfhandle(_fileno(file)); |
|
569 |
#else |
|
570 |
osfile = (apr_os_file_t)fileno(file); |
|
571 |
#endif |
|
572 |
||
573 |
status = apr_os_file_put(&fp, &osfile, |
|
574 |
APR_FOPEN_WRITE | APR_FOPEN_CREATE, pool); |
|
575 |
if (status) { |
|
576 |
PyErr_SetAprStatus(status); |
|
577 |
return NULL; |
|
578 |
} |
|
579 |
||
580 |
return fp; |
|
581 |
} |
Up to file-list subvertpy/util.h:
| … | … | @@ -71,6 +71,7 @@ svn_error_t *py_cancel_func(void *cancel |
71 |
71 |
apr_hash_t *config_hash_from_object(PyObject *config, apr_pool_t *pool); |
72 |
72 |
void PyErr_SetAprStatus(apr_status_t status); |
73 |
73 |
PyObject *py_dirent(svn_dirent_t *dirent, int dirent_fields); |
74 |
apr_file_t *apr_file_from_object(PyObject *object, apr_pool_t *pool); |
|
74 |
75 |
|
75 |
76 |
#if SVN_VER_MAJOR == 1 && SVN_VER_MINOR >= 5 |
76 |
77 |
svn_error_t *py_svn_log_entry_receiver(void *baton, svn_log_entry_t *log_entry, apr_pool_t *pool); |
