~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/pjlib/src/pj/pool_dbg.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: pool_dbg.c 3553 2011-05-05 06:14:19Z nanang $ */
 
2
/* 
 
3
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
 
4
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 
19
 */
 
20
#include <pj/pool.h>
 
21
#include <pj/string.h>
 
22
 
 
23
#if PJ_HAS_POOL_ALT_API
 
24
 
 
25
#if PJ_HAS_MALLOC_H
 
26
#   include <malloc.h>
 
27
#endif
 
28
 
 
29
 
 
30
#if PJ_HAS_STDLIB_H
 
31
#   include <stdlib.h>
 
32
#endif
 
33
 
 
34
 
 
35
#if defined(PJ_WIN32) && PJ_WIN32!=0 && defined(PJ_DEBUG) && PJ_DEBUG!=0 \
 
36
    && !PJ_NATIVE_STRING_IS_UNICODE
 
37
#   include <windows.h>
 
38
#   define TRACE_(msg)  OutputDebugString(msg)
 
39
#endif
 
40
 
 
41
/* Uncomment this to enable TRACE_ */
 
42
//#undef TRACE_
 
43
 
 
44
 
 
45
 
 
46
int PJ_NO_MEMORY_EXCEPTION;
 
47
 
 
48
 
 
49
PJ_DEF(int) pj_NO_MEMORY_EXCEPTION()
 
50
{
 
51
    return PJ_NO_MEMORY_EXCEPTION;
 
52
}
 
53
 
 
54
/* Create pool */
 
55
PJ_DEF(pj_pool_t*) pj_pool_create_imp( const char *file, int line,
 
56
                                       void *factory,
 
57
                                       const char *name,
 
58
                                       pj_size_t initial_size,
 
59
                                       pj_size_t increment_size,
 
60
                                       pj_pool_callback *callback)
 
61
{
 
62
    pj_pool_t *pool;
 
63
 
 
64
    PJ_UNUSED_ARG(file);
 
65
    PJ_UNUSED_ARG(line);
 
66
    PJ_UNUSED_ARG(factory);
 
67
    PJ_UNUSED_ARG(initial_size);
 
68
    PJ_UNUSED_ARG(increment_size);
 
69
 
 
70
    pool = malloc(sizeof(struct pj_pool_t));
 
71
    if (!pool)
 
72
        return NULL;
 
73
 
 
74
    if (name) {
 
75
        pj_ansi_strncpy(pool->obj_name, name, sizeof(pool->obj_name));
 
76
        pool->obj_name[sizeof(pool->obj_name)-1] = '\0';
 
77
    } else {
 
78
        strcpy(pool->obj_name, "altpool");
 
79
    }
 
80
 
 
81
    pool->factory = NULL;
 
82
    pool->first_mem = NULL;
 
83
    pool->used_size = 0;
 
84
    pool->cb = callback;
 
85
 
 
86
    return pool;
 
87
}
 
88
 
 
89
 
 
90
/* Release pool */
 
91
PJ_DEF(void) pj_pool_release_imp(pj_pool_t *pool)
 
92
{
 
93
    pj_pool_reset(pool);
 
94
    free(pool);
 
95
}
 
96
 
 
97
/* Get pool name */
 
98
PJ_DEF(const char*) pj_pool_getobjname_imp(pj_pool_t *pool)
 
99
{
 
100
    PJ_UNUSED_ARG(pool);
 
101
    return "pooldbg";
 
102
}
 
103
 
 
104
/* Reset pool */
 
105
PJ_DEF(void) pj_pool_reset_imp(pj_pool_t *pool)
 
106
{
 
107
    struct pj_pool_mem *mem;
 
108
 
 
109
    mem = pool->first_mem;
 
110
    while (mem) {
 
111
        struct pj_pool_mem *next = mem->next;
 
112
        free(mem);
 
113
        mem = next;
 
114
    }
 
115
 
 
116
    pool->first_mem = NULL;
 
117
}
 
118
 
 
119
/* Get capacity */
 
120
PJ_DEF(pj_size_t) pj_pool_get_capacity_imp(pj_pool_t *pool)
 
121
{
 
122
    PJ_UNUSED_ARG(pool);
 
123
 
 
124
    /* Unlimited capacity */
 
125
    return 0x7FFFFFFFUL;
 
126
}
 
127
 
 
128
/* Get total used size */
 
129
PJ_DEF(pj_size_t) pj_pool_get_used_size_imp(pj_pool_t *pool)
 
130
{
 
131
    return pool->used_size;
 
132
}
 
133
 
 
134
/* Allocate memory from the pool */
 
135
PJ_DEF(void*) pj_pool_alloc_imp( const char *file, int line, 
 
136
                                 pj_pool_t *pool, pj_size_t sz)
 
137
{
 
138
    struct pj_pool_mem *mem;
 
139
 
 
140
    PJ_UNUSED_ARG(file);
 
141
    PJ_UNUSED_ARG(line);
 
142
 
 
143
    mem = malloc(sz + sizeof(struct pj_pool_mem));
 
144
    if (!mem) {
 
145
        if (pool->cb)
 
146
            (*pool->cb)(pool, sz);
 
147
        return NULL;
 
148
    }
 
149
 
 
150
    mem->next = pool->first_mem;
 
151
    pool->first_mem = mem;
 
152
 
 
153
#ifdef TRACE_
 
154
    {
 
155
        char msg[120];
 
156
        pj_ansi_sprintf(msg, "Mem %X (%d+%d bytes) allocated by %s:%d\r\n",
 
157
                        mem, sz, sizeof(struct pj_pool_mem), 
 
158
                        file, line);
 
159
        TRACE_(msg);
 
160
    }
 
161
#endif
 
162
 
 
163
    return ((char*)mem) + sizeof(struct pj_pool_mem);
 
164
}
 
165
 
 
166
/* Allocate memory from the pool and zero the memory */
 
167
PJ_DEF(void*) pj_pool_calloc_imp( const char *file, int line, 
 
168
                                  pj_pool_t *pool, unsigned cnt, 
 
169
                                  unsigned elemsz)
 
170
{
 
171
    void *mem;
 
172
 
 
173
    mem = pj_pool_alloc_imp(file, line, pool, cnt*elemsz);
 
174
    if (!mem)
 
175
        return NULL;
 
176
 
 
177
    pj_bzero(mem, cnt*elemsz);
 
178
    return mem;
 
179
}
 
180
 
 
181
/* Allocate memory from the pool and zero the memory */
 
182
PJ_DEF(void*) pj_pool_zalloc_imp( const char *file, int line, 
 
183
                                  pj_pool_t *pool, pj_size_t sz)
 
184
{
 
185
    return pj_pool_calloc_imp(file, line, pool, 1, sz); 
 
186
}
 
187
 
 
188
 
 
189
 
 
190
#endif  /* PJ_HAS_POOL_ALT_API */