~ubuntu-branches/ubuntu/vivid/mpv/vivid

« back to all changes in this revision

Viewing changes to mpvcore/mp_talloc.h

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-12-29 20:04:26 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20131229200426-w0qsj8clnui1pxaw
Tags: 0.3.0-1
* New upstream release
  - Fix --vf=expand example in manpage (Closes: #732271)
* Add 03_waf.patch to provide uncompressed waf scripts and modules
* Switch to waf build script
* Drop libmng-dev Build-Depends (not used anymore)
* Bump Standards-Version to 3.9.5 (no changes needed)
* Enable support for dvdnav
* Install more docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of mpv.
3
 
 *
4
 
 * mpv is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * mpv is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License along
15
 
 * with mpv; if not, write to the Free Software Foundation, Inc.,
16
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 
 */
18
 
 
19
 
#ifndef MPV_TALLOC_H
20
 
#define MPV_TALLOC_H
21
 
 
22
 
#include "talloc.h"
23
 
#include "compat/compiler.h"
24
 
 
25
 
#define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0]))
26
 
#define MP_GROW_ARRAY(p, nextidx) do {          \
27
 
    if ((nextidx) == MP_TALLOC_ELEMS(p))        \
28
 
        (p) = talloc_realloc_size(NULL, p, talloc_get_size(p) * 2); } while (0)
29
 
#define MP_RESIZE_ARRAY(ctx, p, count) do {     \
30
 
        (p) = talloc_realloc_size((ctx), p, (count) * sizeof((p)[0])); } while (0)
31
 
 
32
 
#define MP_TARRAY_GROW(ctx, p, nextidx)             \
33
 
    do {                                            \
34
 
        size_t nextidx_ = (nextidx);                \
35
 
        size_t nelems_ = MP_TALLOC_ELEMS(p);        \
36
 
        if (nextidx_ >= nelems_)                    \
37
 
            (p) = talloc_realloc_size(ctx, p,       \
38
 
                  (nextidx_ + 1) * sizeof((p)[0]) * 2);\
39
 
    } while (0)
40
 
 
41
 
#define MP_TARRAY_APPEND(ctx, p, idxvar, ...)       \
42
 
    do {                                            \
43
 
        MP_TARRAY_GROW(ctx, p, idxvar);             \
44
 
        (p)[(idxvar)] = (MP_EXPAND_ARGS(__VA_ARGS__));\
45
 
        (idxvar)++;                                 \
46
 
    } while (0)
47
 
 
48
 
// Doesn't actually free any memory, or do any other talloc calls.
49
 
#define MP_TARRAY_REMOVE_AT(p, idxvar, at)          \
50
 
    do {                                            \
51
 
        size_t at_ = (at);                          \
52
 
        assert(at_ <= (idxvar));                    \
53
 
        memmove((p) + at_, (p) + at_ + 1,           \
54
 
                ((idxvar) - at_ - 1) * sizeof((p)[0])); \
55
 
        (idxvar)--;                                 \
56
 
    } while (0)
57
 
 
58
 
#define talloc_struct(ctx, type, ...) \
59
 
    talloc_memdup(ctx, &(type) MP_EXPAND_ARGS(__VA_ARGS__), sizeof(type))
60
 
 
61
 
#endif