~ubuntu-branches/ubuntu/wily/aegisub/wily-proposed

« back to all changes in this revision

Viewing changes to vendor/luabins/src/saveload.h

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel, Pascal De Vuyst, Juan Picca, Sebastian Reichel
  • Date: 2015-08-04 21:40:50 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150804214050-y2aghm9vdksoc8t7
Tags: 3.2.2+dfsg-1
[ Pascal De Vuyst ]
* Fix Typo in package description (Closes: #739219)

[ Juan Picca ]
* Add patch to fix reproducible build (Closes: #789728)

[ Sebastian Reichel ]
* New upstream release
 - remove vendor directory from orig tarball
* Update Debian Standards Version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* saveload.h
 
3
* Luabins internal constants and helper macros
 
4
* See copyright notice in luabins.h
 
5
*/
 
6
 
 
7
#ifndef LUABINS_SAVELOAD_H_INCLUDED_
 
8
#define LUABINS_SAVELOAD_H_INCLUDED_
 
9
 
 
10
/* Find minimum of two values */
 
11
#define luabins_min(a, b) \
 
12
  ( ((a) < (b)) ? (a) : (b) )
 
13
 
 
14
/* Find maximum of two values */
 
15
#define luabins_max(a, b) \
 
16
  ( ((a) > (b)) ? (a) : (b) )
 
17
 
 
18
/* Find minimum of three values */
 
19
#define luabins_min3(a, b, c) \
 
20
  ( ((a) < (b)) ? luabins_min((a), (c)) : luabins_min((b), (c)) )
 
21
 
 
22
/* Preprocessor concatenation */
 
23
#define LUABINS_CAT(a, b) a##b
 
24
 
 
25
/* Static assert helper macro */
 
26
#define luabins_static_assert_line(pred, line) \
 
27
  typedef char LUABINS_CAT( \
 
28
      static_assertion_failed_at_line_, \
 
29
      line \
 
30
    )[2 * !!(pred) - 1]
 
31
 
 
32
/* Static (compile-time) assert */
 
33
#define luabins_static_assert(pred) \
 
34
  luabins_static_assert_line(pred, __LINE__)
 
35
 
 
36
/* Internal error codes */
 
37
#define LUABINS_ESUCCESS (0)
 
38
#define LUABINS_EFAILURE (1)
 
39
#define LUABINS_EBADTYPE (2)
 
40
#define LUABINS_ETOODEEP (3)
 
41
#define LUABINS_ENOSTACK (4)
 
42
#define LUABINS_EBADDATA (5)
 
43
#define LUABINS_ETAILEFT (6)
 
44
#define LUABINS_EBADSIZE (7)
 
45
#define LUABINS_ETOOLONG (8)
 
46
 
 
47
/* Type bytes */
 
48
#define LUABINS_CNIL    '-' /* 0x2D (45) */
 
49
#define LUABINS_CFALSE  '0' /* 0x30 (48) */
 
50
#define LUABINS_CTRUE   '1' /* 0x31 (49) */
 
51
#define LUABINS_CNUMBER 'N' /* 0x4E (78) */
 
52
#define LUABINS_CSTRING 'S' /* 0x53 (83) */
 
53
#define LUABINS_CTABLE  'T' /* 0x54 (84) */
 
54
 
 
55
/*
 
56
* PORTABILITY WARNING!
 
57
* You have to ensure manually that length constants below are the same
 
58
* for both code that does the save and code that does the load.
 
59
* Also these constants must be actual or code below would break.
 
60
* Beware of endianness and lua_Number actual type as well.
 
61
* Note also that luabins does not check for overflow on save,
 
62
* if your integer does not fit, it would be truncated.
 
63
*/
 
64
#define LUABINS_LINT      (4)
 
65
#define LUABINS_LSIZET    (4)
 
66
#define LUABINS_LNUMBER   (8)
 
67
 
 
68
/*
 
69
* Derived lengths
 
70
*
 
71
* WARNING: Change these if format is changed!
 
72
*/
 
73
 
 
74
/* One type byte */
 
75
#define LUABINS_LTYPEBYTE  (1)
 
76
 
 
77
/* Minimal table: type, array size, hash size, no data */
 
78
#define LUABINS_LMINTABLE  (LUABINS_LTYPEBYTE + LUABINS_LINT + LUABINS_LINT)
 
79
 
 
80
/* Minimal number: type, number value */
 
81
#define LUABINS_LMINNUMBER (LUABINS_LTYPEBYTE + LUABINS_LNUMBER)
 
82
 
 
83
/* Minimal string: type, length, no data */
 
84
#define LUABINS_LMINSTRING (LUABINS_LTYPEBYTE + LUABINS_LSIZET)
 
85
 
 
86
/* Minimum large (non-boolean non-nil) value length */
 
87
#define LUABINS_LMINLARGEVALUE \
 
88
  ( luabins_min3(LUABINS_LMINTABLE, LUABINS_LMINSTRING, LUABINS_LMINSTRING) )
 
89
 
 
90
/*
 
91
* Lower limit on total table data size is determined as follows:
 
92
* -- All entries are always key and value.
 
93
* -- Minimum value size is one byte for nil and boolean,
 
94
*    but that is two keys maximum (nil can'be the key).
 
95
* -- All the rest of key types are mimimum of LUABINS_MINLARGEVALUELEN
 
96
*    bytes (type byte plus data bytes).
 
97
* -- All values in the table may be booleans.
 
98
*
 
99
* WARNING: Change this if format is changed!
 
100
*
 
101
* Note this formula does NOT take in account
 
102
* table header (type byte and array/hash sizes).
 
103
*/
 
104
#define luabins_min_table_data_size(total_size) \
 
105
  ( \
 
106
    (total_size > 2) \
 
107
      ? ( \
 
108
          2 * (LUABINS_LTYPEBYTE + LUABINS_LTYPEBYTE) \
 
109
        + (total_size - 2) * (LUABINS_LMINLARGEVALUE + LUABINS_LTYPEBYTE) \
 
110
      ) \
 
111
      : (total_size * (LUABINS_LTYPEBYTE + LUABINS_LTYPEBYTE)) \
 
112
  )
 
113
 
 
114
#endif /* LUABINS_SAVELOAD_H_INCLUDED_ */