rpm  5.4.15
rpmsvn.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #include <rpmiotypes.h>
8 #include <rpmio.h> /* for *Pool methods */
9 #include <rpmlog.h>
10 #include <rpmurl.h>
11 
12 #if defined(WITH_SUBVERSION)
13 #include "svn_pools.h"
14 #include "svn_client.h"
15 #include "svn_repos.h"
16 #include "svn_subst.h"
17 #endif
18 
19 #define _RPMSVN_INTERNAL
20 #include <rpmsvn.h>
21 
22 #include "debug.h"
23 
24 /*@unchecked@*/
25 int _rpmsvn_debug = 0;
26 
27 /*==============================================================*/
28 
29 /*==============================================================*/
30 
31 static int npools;
32 
33 static void rpmsvnFini(void * _svn)
34  /*@globals fileSystem @*/
35  /*@modifies *_svn, fileSystem @*/
36 {
37  rpmsvn svn = (rpmsvn) _svn;
38 
39 #if defined(WITH_SUBVERSION)
40  if (svn->pool) {
41  svn_pool_destroy(svn->pool);
42  svn->pool = NULL;
43  }
44  if (--npools <= 0)
45  apr_terminate();
46  svn->allocator = NULL;
47 #endif
48 
49  svn->fn = _free(svn->fn);
50 
51 }
52 
53 /*@unchecked@*/ /*@only@*/ /*@null@*/
55 
56 static rpmsvn rpmsvnGetPool(/*@null@*/ rpmioPool pool)
57  /*@globals _rpmsvnPool, fileSystem @*/
58  /*@modifies pool, _rpmsvnPool, fileSystem @*/
59 {
60  rpmsvn svn;
61 
62  if (_rpmsvnPool == NULL) {
63  _rpmsvnPool = rpmioNewPool("svn", sizeof(*svn), -1, _rpmsvn_debug,
64  NULL, NULL, rpmsvnFini);
65  pool = _rpmsvnPool;
66  }
67  svn = (rpmsvn) rpmioGetPool(pool, sizeof(*svn));
68  memset(((char *)svn)+sizeof(svn->_item), 0, sizeof(*svn)-sizeof(svn->_item));
69  return svn;
70 }
71 
72 rpmsvn rpmsvnNew(const char * fn, int flags)
73 {
74  rpmsvn svn = rpmsvnGetPool(_rpmsvnPool);
75  int xx;
76 
77 #if defined(WITH_SUBVERSION)
78  if (npools++ <= 0) {
79  xx = apr_initialize();
80 assert(xx == APR_SUCCESS);
81  }
82  xx = apr_allocator_create(&svn->allocator);
83 assert(xx == 0);
84  apr_allocator_max_free_set(svn->allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
85  svn->pool = svn_pool_create_ex(NULL, svn->allocator);
86  apr_allocator_owner_set(svn->allocator, svn->pool);
87 
88 #endif
89 
90  if (fn)
91  svn->fn = xstrdup(fn);
92 
93 
94  return rpmsvnLink(svn);
95 }
rpmioPool _rpmsvnPool
Definition: rpmsvn.c:54
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
struct rpmsvn_s * rpmsvn
Definition: rpmsvn.h:15
static void rpmsvnFini(void *_svn)
Definition: rpmsvn.c:33
Yet Another syslog(3) API clone.
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
Definition: rpmmalloc.c:220
int _rpmsvn_debug
Definition: rpmsvn.c:25
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
Definition: rpmmalloc.c:109
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
rpmsvn rpmsvnNew(const char *fn, int flags)
Create and load a svn wrapper.
Definition: rpmsvn.c:72
static rpmsvn rpmsvnGetPool(rpmioPool pool)
Definition: rpmsvn.c:56
static int npools
Definition: rpmsvn.c:31
rpmsvn rpmsvnLink(rpmsvn svn)
Reference a svn wrapper instance.