pysus 0.4.0__py3.7-linux-x86_64.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +30 -0
- EGG-INFO/SOURCES.txt +75 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/native_libs.txt +3 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/requires.txt +7 -0
- EGG-INFO/top_level.txt +2 -0
- __pycache__/_readdbc.cpython-37.pyc +0 -0
- _readdbc.abi3.so +0 -0
- _readdbc.py +7 -0
- pysus/__init__.py +2 -0
- pysus/__pycache__/__init__.cpython-37.pyc +0 -0
- pysus/online_data/CIHA.py +62 -0
- pysus/online_data/CNES.py +24 -0
- pysus/online_data/SIA.py +92 -0
- pysus/online_data/SIH.py +61 -0
- pysus/online_data/SIM.py +155 -0
- pysus/online_data/SINAN.py +77 -0
- pysus/online_data/__init__.py +22 -0
- pysus/online_data/__pycache__/CIHA.cpython-37.pyc +0 -0
- pysus/online_data/__pycache__/CNES.cpython-37.pyc +0 -0
- pysus/online_data/__pycache__/SIA.cpython-37.pyc +0 -0
- pysus/online_data/__pycache__/SIH.cpython-37.pyc +0 -0
- pysus/online_data/__pycache__/SIM.cpython-37.pyc +0 -0
- pysus/online_data/__pycache__/SINAN.cpython-37.pyc +0 -0
- pysus/online_data/__pycache__/__init__.cpython-37.pyc +0 -0
- pysus/online_data/__pycache__/sinasc.cpython-37.pyc +0 -0
- pysus/online_data/sinasc.py +44 -0
- pysus/preprocessing/__init__.py +8 -0
- pysus/preprocessing/__pycache__/__init__.cpython-37.pyc +0 -0
- pysus/preprocessing/__pycache__/decoders.cpython-37.pyc +0 -0
- pysus/preprocessing/__pycache__/sinan.cpython-37.pyc +0 -0
- pysus/preprocessing/decoders.py +96 -0
- pysus/preprocessing/sinan.py +103 -0
- pysus/tests/__init__.py +8 -0
- pysus/tests/__pycache__/__init__.cpython-37.pyc +0 -0
- pysus/tests/__pycache__/test_decoders.cpython-37.pyc +0 -0
- pysus/tests/__pycache__/test_sinan.cpython-37.pyc +0 -0
- pysus/tests/__pycache__/test_utilities.cpython-37.pyc +0 -0
- pysus/tests/test_data/__init__.py +6 -0
- pysus/tests/test_data/__pycache__/__init__.cpython-37.pyc +0 -0
- pysus/tests/test_data/__pycache__/test_ciha.cpython-37.pyc +0 -0
- pysus/tests/test_data/__pycache__/test_sia.cpython-37.pyc +0 -0
- pysus/tests/test_data/__pycache__/test_sih.cpython-37.pyc +0 -0
- pysus/tests/test_data/__pycache__/test_sim.cpython-37.pyc +0 -0
- pysus/tests/test_data/__pycache__/test_sinasc.cpython-37.pyc +0 -0
- pysus/tests/test_data/test_ciha.py +23 -0
- pysus/tests/test_data/test_sia.py +25 -0
- pysus/tests/test_data/test_sih.py +18 -0
- pysus/tests/test_data/test_sim.py +41 -0
- pysus/tests/test_data/test_sinasc.py +20 -0
- pysus/tests/test_decoders.py +38 -0
- pysus/tests/test_sinan.py +44 -0
- pysus/tests/test_utilities.py +18 -0
- pysus/utilities/__init__.py +6 -0
- pysus/utilities/__pycache__/__init__.cpython-37.pyc +0 -0
- pysus/utilities/__pycache__/_build_readdbc.cpython-37.pyc +0 -0
- pysus/utilities/__pycache__/readdbc.cpython-37.pyc +0 -0
- pysus/utilities/_build_readdbc.py +32 -0
- pysus/utilities/_readdbc.c +966 -0
- pysus/utilities/_readdbc.cpython-36m-x86_64-linux-gnu.so +0 -0
- pysus/utilities/_readdbc.cpython-37m-x86_64-linux-gnu.so +0 -0
- pysus/utilities/_readdbc.o +0 -0
- pysus/utilities/blast.c +982 -0
- pysus/utilities/blast.h +75 -0
- pysus/utilities/blast.o +0 -0
- pysus/utilities/readdbc.py +52 -0
pysus/utilities/blast.c
ADDED
|
@@ -0,0 +1,982 @@
|
|
|
1
|
+
#define _CFFI_
|
|
2
|
+
#include <Python.h>
|
|
3
|
+
#ifdef __cplusplus
|
|
4
|
+
extern "C" {
|
|
5
|
+
#endif
|
|
6
|
+
#include <stddef.h>
|
|
7
|
+
|
|
8
|
+
/* This part is from file 'cffi/parse_c_type.h'. It is copied at the
|
|
9
|
+
beginning of C sources generated by CFFI's ffi.set_source(). */
|
|
10
|
+
|
|
11
|
+
typedef void *_cffi_opcode_t;
|
|
12
|
+
|
|
13
|
+
#define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
|
|
14
|
+
#define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode)
|
|
15
|
+
#define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8)
|
|
16
|
+
|
|
17
|
+
#define _CFFI_OP_PRIMITIVE 1
|
|
18
|
+
#define _CFFI_OP_POINTER 3
|
|
19
|
+
#define _CFFI_OP_ARRAY 5
|
|
20
|
+
#define _CFFI_OP_OPEN_ARRAY 7
|
|
21
|
+
#define _CFFI_OP_STRUCT_UNION 9
|
|
22
|
+
#define _CFFI_OP_ENUM 11
|
|
23
|
+
#define _CFFI_OP_FUNCTION 13
|
|
24
|
+
#define _CFFI_OP_FUNCTION_END 15
|
|
25
|
+
#define _CFFI_OP_NOOP 17
|
|
26
|
+
#define _CFFI_OP_BITFIELD 19
|
|
27
|
+
#define _CFFI_OP_TYPENAME 21
|
|
28
|
+
#define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs
|
|
29
|
+
#define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs
|
|
30
|
+
#define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg)
|
|
31
|
+
#define _CFFI_OP_CONSTANT 29
|
|
32
|
+
#define _CFFI_OP_CONSTANT_INT 31
|
|
33
|
+
#define _CFFI_OP_GLOBAL_VAR 33
|
|
34
|
+
#define _CFFI_OP_DLOPEN_FUNC 35
|
|
35
|
+
#define _CFFI_OP_DLOPEN_CONST 37
|
|
36
|
+
#define _CFFI_OP_GLOBAL_VAR_F 39
|
|
37
|
+
#define _CFFI_OP_EXTERN_PYTHON 41
|
|
38
|
+
|
|
39
|
+
#define _CFFI_PRIM_VOID 0
|
|
40
|
+
#define _CFFI_PRIM_BOOL 1
|
|
41
|
+
#define _CFFI_PRIM_CHAR 2
|
|
42
|
+
#define _CFFI_PRIM_SCHAR 3
|
|
43
|
+
#define _CFFI_PRIM_UCHAR 4
|
|
44
|
+
#define _CFFI_PRIM_SHORT 5
|
|
45
|
+
#define _CFFI_PRIM_USHORT 6
|
|
46
|
+
#define _CFFI_PRIM_INT 7
|
|
47
|
+
#define _CFFI_PRIM_UINT 8
|
|
48
|
+
#define _CFFI_PRIM_LONG 9
|
|
49
|
+
#define _CFFI_PRIM_ULONG 10
|
|
50
|
+
#define _CFFI_PRIM_LONGLONG 11
|
|
51
|
+
#define _CFFI_PRIM_ULONGLONG 12
|
|
52
|
+
#define _CFFI_PRIM_FLOAT 13
|
|
53
|
+
#define _CFFI_PRIM_DOUBLE 14
|
|
54
|
+
#define _CFFI_PRIM_LONGDOUBLE 15
|
|
55
|
+
|
|
56
|
+
#define _CFFI_PRIM_WCHAR 16
|
|
57
|
+
#define _CFFI_PRIM_INT8 17
|
|
58
|
+
#define _CFFI_PRIM_UINT8 18
|
|
59
|
+
#define _CFFI_PRIM_INT16 19
|
|
60
|
+
#define _CFFI_PRIM_UINT16 20
|
|
61
|
+
#define _CFFI_PRIM_INT32 21
|
|
62
|
+
#define _CFFI_PRIM_UINT32 22
|
|
63
|
+
#define _CFFI_PRIM_INT64 23
|
|
64
|
+
#define _CFFI_PRIM_UINT64 24
|
|
65
|
+
#define _CFFI_PRIM_INTPTR 25
|
|
66
|
+
#define _CFFI_PRIM_UINTPTR 26
|
|
67
|
+
#define _CFFI_PRIM_PTRDIFF 27
|
|
68
|
+
#define _CFFI_PRIM_SIZE 28
|
|
69
|
+
#define _CFFI_PRIM_SSIZE 29
|
|
70
|
+
#define _CFFI_PRIM_INT_LEAST8 30
|
|
71
|
+
#define _CFFI_PRIM_UINT_LEAST8 31
|
|
72
|
+
#define _CFFI_PRIM_INT_LEAST16 32
|
|
73
|
+
#define _CFFI_PRIM_UINT_LEAST16 33
|
|
74
|
+
#define _CFFI_PRIM_INT_LEAST32 34
|
|
75
|
+
#define _CFFI_PRIM_UINT_LEAST32 35
|
|
76
|
+
#define _CFFI_PRIM_INT_LEAST64 36
|
|
77
|
+
#define _CFFI_PRIM_UINT_LEAST64 37
|
|
78
|
+
#define _CFFI_PRIM_INT_FAST8 38
|
|
79
|
+
#define _CFFI_PRIM_UINT_FAST8 39
|
|
80
|
+
#define _CFFI_PRIM_INT_FAST16 40
|
|
81
|
+
#define _CFFI_PRIM_UINT_FAST16 41
|
|
82
|
+
#define _CFFI_PRIM_INT_FAST32 42
|
|
83
|
+
#define _CFFI_PRIM_UINT_FAST32 43
|
|
84
|
+
#define _CFFI_PRIM_INT_FAST64 44
|
|
85
|
+
#define _CFFI_PRIM_UINT_FAST64 45
|
|
86
|
+
#define _CFFI_PRIM_INTMAX 46
|
|
87
|
+
#define _CFFI_PRIM_UINTMAX 47
|
|
88
|
+
|
|
89
|
+
#define _CFFI__NUM_PRIM 48
|
|
90
|
+
#define _CFFI__UNKNOWN_PRIM (-1)
|
|
91
|
+
#define _CFFI__UNKNOWN_FLOAT_PRIM (-2)
|
|
92
|
+
#define _CFFI__UNKNOWN_LONG_DOUBLE (-3)
|
|
93
|
+
|
|
94
|
+
#define _CFFI__IO_FILE_STRUCT (-1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
struct _cffi_global_s {
|
|
98
|
+
const char *name;
|
|
99
|
+
void *address;
|
|
100
|
+
_cffi_opcode_t type_op;
|
|
101
|
+
void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown
|
|
102
|
+
// OP_CPYTHON_BLTN_*: addr of direct function
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
struct _cffi_getconst_s {
|
|
106
|
+
unsigned long long value;
|
|
107
|
+
const struct _cffi_type_context_s *ctx;
|
|
108
|
+
int gindex;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
struct _cffi_struct_union_s {
|
|
112
|
+
const char *name;
|
|
113
|
+
int type_index; // -> _cffi_types, on a OP_STRUCT_UNION
|
|
114
|
+
int flags; // _CFFI_F_* flags below
|
|
115
|
+
size_t size;
|
|
116
|
+
int alignment;
|
|
117
|
+
int first_field_index; // -> _cffi_fields array
|
|
118
|
+
int num_fields;
|
|
119
|
+
};
|
|
120
|
+
#define _CFFI_F_UNION 0x01 // is a union, not a struct
|
|
121
|
+
#define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the
|
|
122
|
+
// "standard layout" or if some are missing
|
|
123
|
+
#define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct
|
|
124
|
+
#define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include()
|
|
125
|
+
#define _CFFI_F_OPAQUE 0x10 // opaque
|
|
126
|
+
|
|
127
|
+
struct _cffi_field_s {
|
|
128
|
+
const char *name;
|
|
129
|
+
size_t field_offset;
|
|
130
|
+
size_t field_size;
|
|
131
|
+
_cffi_opcode_t field_type_op;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
struct _cffi_enum_s {
|
|
135
|
+
const char *name;
|
|
136
|
+
int type_index; // -> _cffi_types, on a OP_ENUM
|
|
137
|
+
int type_prim; // _CFFI_PRIM_xxx
|
|
138
|
+
const char *enumerators; // comma-delimited string
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
struct _cffi_typename_s {
|
|
142
|
+
const char *name;
|
|
143
|
+
int type_index; /* if opaque, points to a possibly artificial
|
|
144
|
+
OP_STRUCT which is itself opaque */
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
struct _cffi_type_context_s {
|
|
148
|
+
_cffi_opcode_t *types;
|
|
149
|
+
const struct _cffi_global_s *globals;
|
|
150
|
+
const struct _cffi_field_s *fields;
|
|
151
|
+
const struct _cffi_struct_union_s *struct_unions;
|
|
152
|
+
const struct _cffi_enum_s *enums;
|
|
153
|
+
const struct _cffi_typename_s *typenames;
|
|
154
|
+
int num_globals;
|
|
155
|
+
int num_struct_unions;
|
|
156
|
+
int num_enums;
|
|
157
|
+
int num_typenames;
|
|
158
|
+
const char *const *includes;
|
|
159
|
+
int num_types;
|
|
160
|
+
int flags; /* future extension */
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
struct _cffi_parse_info_s {
|
|
164
|
+
const struct _cffi_type_context_s *ctx;
|
|
165
|
+
_cffi_opcode_t *output;
|
|
166
|
+
unsigned int output_size;
|
|
167
|
+
size_t error_location;
|
|
168
|
+
const char *error_message;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
struct _cffi_externpy_s {
|
|
172
|
+
const char *name;
|
|
173
|
+
size_t size_of_result;
|
|
174
|
+
void *reserved1, *reserved2;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
#ifdef _CFFI_INTERNAL
|
|
178
|
+
static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
|
|
179
|
+
static int search_in_globals(const struct _cffi_type_context_s *ctx,
|
|
180
|
+
const char *search, size_t search_len);
|
|
181
|
+
static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
|
|
182
|
+
const char *search, size_t search_len);
|
|
183
|
+
#endif
|
|
184
|
+
|
|
185
|
+
/* this block of #ifs should be kept exactly identical between
|
|
186
|
+
c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
|
|
187
|
+
and cffi/_cffi_include.h */
|
|
188
|
+
#if defined(_MSC_VER)
|
|
189
|
+
# include <malloc.h> /* for alloca() */
|
|
190
|
+
# if _MSC_VER < 1600 /* MSVC < 2010 */
|
|
191
|
+
typedef __int8 int8_t;
|
|
192
|
+
typedef __int16 int16_t;
|
|
193
|
+
typedef __int32 int32_t;
|
|
194
|
+
typedef __int64 int64_t;
|
|
195
|
+
typedef unsigned __int8 uint8_t;
|
|
196
|
+
typedef unsigned __int16 uint16_t;
|
|
197
|
+
typedef unsigned __int32 uint32_t;
|
|
198
|
+
typedef unsigned __int64 uint64_t;
|
|
199
|
+
typedef __int8 int_least8_t;
|
|
200
|
+
typedef __int16 int_least16_t;
|
|
201
|
+
typedef __int32 int_least32_t;
|
|
202
|
+
typedef __int64 int_least64_t;
|
|
203
|
+
typedef unsigned __int8 uint_least8_t;
|
|
204
|
+
typedef unsigned __int16 uint_least16_t;
|
|
205
|
+
typedef unsigned __int32 uint_least32_t;
|
|
206
|
+
typedef unsigned __int64 uint_least64_t;
|
|
207
|
+
typedef __int8 int_fast8_t;
|
|
208
|
+
typedef __int16 int_fast16_t;
|
|
209
|
+
typedef __int32 int_fast32_t;
|
|
210
|
+
typedef __int64 int_fast64_t;
|
|
211
|
+
typedef unsigned __int8 uint_fast8_t;
|
|
212
|
+
typedef unsigned __int16 uint_fast16_t;
|
|
213
|
+
typedef unsigned __int32 uint_fast32_t;
|
|
214
|
+
typedef unsigned __int64 uint_fast64_t;
|
|
215
|
+
typedef __int64 intmax_t;
|
|
216
|
+
typedef unsigned __int64 uintmax_t;
|
|
217
|
+
# else
|
|
218
|
+
# include <stdint.h>
|
|
219
|
+
# endif
|
|
220
|
+
# if _MSC_VER < 1800 /* MSVC < 2013 */
|
|
221
|
+
typedef unsigned char _Bool;
|
|
222
|
+
# endif
|
|
223
|
+
#else
|
|
224
|
+
# include <stdint.h>
|
|
225
|
+
# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
|
|
226
|
+
# include <alloca.h>
|
|
227
|
+
# endif
|
|
228
|
+
#endif
|
|
229
|
+
|
|
230
|
+
#ifdef __GNUC__
|
|
231
|
+
# define _CFFI_UNUSED_FN __attribute__((unused))
|
|
232
|
+
#else
|
|
233
|
+
# define _CFFI_UNUSED_FN /* nothing */
|
|
234
|
+
#endif
|
|
235
|
+
|
|
236
|
+
#ifdef __cplusplus
|
|
237
|
+
# ifndef _Bool
|
|
238
|
+
# define _Bool bool /* semi-hackish: C++ has no _Bool; bool is builtin */
|
|
239
|
+
# endif
|
|
240
|
+
#endif
|
|
241
|
+
|
|
242
|
+
/********** CPython-specific section **********/
|
|
243
|
+
#ifndef PYPY_VERSION
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
#if PY_MAJOR_VERSION >= 3
|
|
247
|
+
# define PyInt_FromLong PyLong_FromLong
|
|
248
|
+
#endif
|
|
249
|
+
|
|
250
|
+
#define _cffi_from_c_double PyFloat_FromDouble
|
|
251
|
+
#define _cffi_from_c_float PyFloat_FromDouble
|
|
252
|
+
#define _cffi_from_c_long PyInt_FromLong
|
|
253
|
+
#define _cffi_from_c_ulong PyLong_FromUnsignedLong
|
|
254
|
+
#define _cffi_from_c_longlong PyLong_FromLongLong
|
|
255
|
+
#define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
|
|
256
|
+
|
|
257
|
+
#define _cffi_to_c_double PyFloat_AsDouble
|
|
258
|
+
#define _cffi_to_c_float PyFloat_AsDouble
|
|
259
|
+
|
|
260
|
+
#define _cffi_from_c_int(x, type) \
|
|
261
|
+
(((type)-1) > 0 ? /* unsigned */ \
|
|
262
|
+
(sizeof(type) < sizeof(long) ? \
|
|
263
|
+
PyInt_FromLong((long)x) : \
|
|
264
|
+
sizeof(type) == sizeof(long) ? \
|
|
265
|
+
PyLong_FromUnsignedLong((unsigned long)x) : \
|
|
266
|
+
PyLong_FromUnsignedLongLong((unsigned long long)x)) : \
|
|
267
|
+
(sizeof(type) <= sizeof(long) ? \
|
|
268
|
+
PyInt_FromLong((long)x) : \
|
|
269
|
+
PyLong_FromLongLong((long long)x)))
|
|
270
|
+
|
|
271
|
+
#define _cffi_to_c_int(o, type) \
|
|
272
|
+
((type)( \
|
|
273
|
+
sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \
|
|
274
|
+
: (type)_cffi_to_c_i8(o)) : \
|
|
275
|
+
sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \
|
|
276
|
+
: (type)_cffi_to_c_i16(o)) : \
|
|
277
|
+
sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \
|
|
278
|
+
: (type)_cffi_to_c_i32(o)) : \
|
|
279
|
+
sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \
|
|
280
|
+
: (type)_cffi_to_c_i64(o)) : \
|
|
281
|
+
(Py_FatalError("unsupported size for type " #type), (type)0)))
|
|
282
|
+
|
|
283
|
+
#define _cffi_to_c_i8 \
|
|
284
|
+
((int(*)(PyObject *))_cffi_exports[1])
|
|
285
|
+
#define _cffi_to_c_u8 \
|
|
286
|
+
((int(*)(PyObject *))_cffi_exports[2])
|
|
287
|
+
#define _cffi_to_c_i16 \
|
|
288
|
+
((int(*)(PyObject *))_cffi_exports[3])
|
|
289
|
+
#define _cffi_to_c_u16 \
|
|
290
|
+
((int(*)(PyObject *))_cffi_exports[4])
|
|
291
|
+
#define _cffi_to_c_i32 \
|
|
292
|
+
((int(*)(PyObject *))_cffi_exports[5])
|
|
293
|
+
#define _cffi_to_c_u32 \
|
|
294
|
+
((unsigned int(*)(PyObject *))_cffi_exports[6])
|
|
295
|
+
#define _cffi_to_c_i64 \
|
|
296
|
+
((long long(*)(PyObject *))_cffi_exports[7])
|
|
297
|
+
#define _cffi_to_c_u64 \
|
|
298
|
+
((unsigned long long(*)(PyObject *))_cffi_exports[8])
|
|
299
|
+
#define _cffi_to_c_char \
|
|
300
|
+
((int(*)(PyObject *))_cffi_exports[9])
|
|
301
|
+
#define _cffi_from_c_pointer \
|
|
302
|
+
((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[10])
|
|
303
|
+
#define _cffi_to_c_pointer \
|
|
304
|
+
((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11])
|
|
305
|
+
#define _cffi_get_struct_layout \
|
|
306
|
+
not used any more
|
|
307
|
+
#define _cffi_restore_errno \
|
|
308
|
+
((void(*)(void))_cffi_exports[13])
|
|
309
|
+
#define _cffi_save_errno \
|
|
310
|
+
((void(*)(void))_cffi_exports[14])
|
|
311
|
+
#define _cffi_from_c_char \
|
|
312
|
+
((PyObject *(*)(char))_cffi_exports[15])
|
|
313
|
+
#define _cffi_from_c_deref \
|
|
314
|
+
((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[16])
|
|
315
|
+
#define _cffi_to_c \
|
|
316
|
+
((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[17])
|
|
317
|
+
#define _cffi_from_c_struct \
|
|
318
|
+
((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[18])
|
|
319
|
+
#define _cffi_to_c_wchar_t \
|
|
320
|
+
((wchar_t(*)(PyObject *))_cffi_exports[19])
|
|
321
|
+
#define _cffi_from_c_wchar_t \
|
|
322
|
+
((PyObject *(*)(wchar_t))_cffi_exports[20])
|
|
323
|
+
#define _cffi_to_c_long_double \
|
|
324
|
+
((long double(*)(PyObject *))_cffi_exports[21])
|
|
325
|
+
#define _cffi_to_c__Bool \
|
|
326
|
+
((_Bool(*)(PyObject *))_cffi_exports[22])
|
|
327
|
+
#define _cffi_prepare_pointer_call_argument \
|
|
328
|
+
((Py_ssize_t(*)(CTypeDescrObject *, PyObject *, char **))_cffi_exports[23])
|
|
329
|
+
#define _cffi_convert_array_from_object \
|
|
330
|
+
((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[24])
|
|
331
|
+
#define _CFFI_CPIDX 25
|
|
332
|
+
#define _cffi_call_python \
|
|
333
|
+
((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX])
|
|
334
|
+
#define _CFFI_NUM_EXPORTS 26
|
|
335
|
+
|
|
336
|
+
typedef struct _ctypedescr CTypeDescrObject;
|
|
337
|
+
|
|
338
|
+
static void *_cffi_exports[_CFFI_NUM_EXPORTS];
|
|
339
|
+
|
|
340
|
+
#define _cffi_type(index) ( \
|
|
341
|
+
assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \
|
|
342
|
+
(CTypeDescrObject *)_cffi_types[index])
|
|
343
|
+
|
|
344
|
+
static PyObject *_cffi_init(const char *module_name, Py_ssize_t version,
|
|
345
|
+
const struct _cffi_type_context_s *ctx)
|
|
346
|
+
{
|
|
347
|
+
PyObject *module, *o_arg, *new_module;
|
|
348
|
+
void *raw[] = {
|
|
349
|
+
(void *)module_name,
|
|
350
|
+
(void *)version,
|
|
351
|
+
(void *)_cffi_exports,
|
|
352
|
+
(void *)ctx,
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
module = PyImport_ImportModule("_cffi_backend");
|
|
356
|
+
if (module == NULL)
|
|
357
|
+
goto failure;
|
|
358
|
+
|
|
359
|
+
o_arg = PyLong_FromVoidPtr((void *)raw);
|
|
360
|
+
if (o_arg == NULL)
|
|
361
|
+
goto failure;
|
|
362
|
+
|
|
363
|
+
new_module = PyObject_CallMethod(
|
|
364
|
+
module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg);
|
|
365
|
+
|
|
366
|
+
Py_DECREF(o_arg);
|
|
367
|
+
Py_DECREF(module);
|
|
368
|
+
return new_module;
|
|
369
|
+
|
|
370
|
+
failure:
|
|
371
|
+
Py_XDECREF(module);
|
|
372
|
+
return NULL;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
_CFFI_UNUSED_FN
|
|
376
|
+
static PyObject **_cffi_unpack_args(PyObject *args_tuple, Py_ssize_t expected,
|
|
377
|
+
const char *fnname)
|
|
378
|
+
{
|
|
379
|
+
if (PyTuple_GET_SIZE(args_tuple) != expected) {
|
|
380
|
+
PyErr_Format(PyExc_TypeError,
|
|
381
|
+
"%.150s() takes exactly %zd arguments (%zd given)",
|
|
382
|
+
fnname, expected, PyTuple_GET_SIZE(args_tuple));
|
|
383
|
+
return NULL;
|
|
384
|
+
}
|
|
385
|
+
return &PyTuple_GET_ITEM(args_tuple, 0); /* pointer to the first item,
|
|
386
|
+
the others follow */
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/********** end CPython-specific section **********/
|
|
390
|
+
#else
|
|
391
|
+
_CFFI_UNUSED_FN
|
|
392
|
+
static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *);
|
|
393
|
+
# define _cffi_call_python _cffi_call_python_org
|
|
394
|
+
#endif
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
#define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
|
|
398
|
+
|
|
399
|
+
#define _cffi_prim_int(size, sign) \
|
|
400
|
+
((size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) : \
|
|
401
|
+
(size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) : \
|
|
402
|
+
(size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) : \
|
|
403
|
+
(size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) : \
|
|
404
|
+
_CFFI__UNKNOWN_PRIM)
|
|
405
|
+
|
|
406
|
+
#define _cffi_prim_float(size) \
|
|
407
|
+
((size) == sizeof(float) ? _CFFI_PRIM_FLOAT : \
|
|
408
|
+
(size) == sizeof(double) ? _CFFI_PRIM_DOUBLE : \
|
|
409
|
+
(size) == sizeof(long double) ? _CFFI__UNKNOWN_LONG_DOUBLE : \
|
|
410
|
+
_CFFI__UNKNOWN_FLOAT_PRIM)
|
|
411
|
+
|
|
412
|
+
#define _cffi_check_int(got, got_nonpos, expected) \
|
|
413
|
+
((got_nonpos) == (expected <= 0) && \
|
|
414
|
+
(got) == (unsigned long long)expected)
|
|
415
|
+
|
|
416
|
+
#ifdef MS_WIN32
|
|
417
|
+
# define _cffi_stdcall __stdcall
|
|
418
|
+
#else
|
|
419
|
+
# define _cffi_stdcall /* nothing */
|
|
420
|
+
#endif
|
|
421
|
+
|
|
422
|
+
#ifdef __cplusplus
|
|
423
|
+
}
|
|
424
|
+
#endif
|
|
425
|
+
|
|
426
|
+
/************************************************************/
|
|
427
|
+
|
|
428
|
+
/* blast.c
|
|
429
|
+
* Copyright (C) 2003, 2012 Mark Adler
|
|
430
|
+
* For conditions of distribution and use, see copyright notice in blast.h
|
|
431
|
+
* version 1.2, 24 Oct 2012
|
|
432
|
+
*
|
|
433
|
+
* blast.c decompresses data compressed by the PKWare Compression Library.
|
|
434
|
+
* This function provides functionality similar to the explode() function of
|
|
435
|
+
* the PKWare library, hence the name "blast".
|
|
436
|
+
*
|
|
437
|
+
* This decompressor is based on the excellent format description provided by
|
|
438
|
+
* Ben Rudiak-Gould in comp.compression on August 13, 2001. Interestingly, the
|
|
439
|
+
* example Ben provided in the post is incorrect. The distance 110001 should
|
|
440
|
+
* instead be 111000. When corrected, the example byte stream becomes:
|
|
441
|
+
*
|
|
442
|
+
* 00 04 82 24 25 8f 80 7f
|
|
443
|
+
*
|
|
444
|
+
* which decompresses to "AIAIAIAIAIAIA" (without the quotes).
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
/*
|
|
448
|
+
* Change history:
|
|
449
|
+
*
|
|
450
|
+
* 1.0 12 Feb 2003 - First version
|
|
451
|
+
* 1.1 16 Feb 2003 - Fixed distance check for > 4 GB uncompressed data
|
|
452
|
+
* 1.2 24 Oct 2012 - Add note about using binary mode in stdio
|
|
453
|
+
* - Fix comparisons of differently signed integers
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
|
|
457
|
+
#include "blast.h" /* prototype for blast() */
|
|
458
|
+
|
|
459
|
+
#define MAXBITS 13 /* maximum code length */
|
|
460
|
+
#define MAXWIN 4096 /* maximum window size */
|
|
461
|
+
|
|
462
|
+
/* input and output state */
|
|
463
|
+
struct state {
|
|
464
|
+
/* input state */
|
|
465
|
+
blast_in infun; /* input function provided by user */
|
|
466
|
+
void *inhow; /* opaque information passed to infun() */
|
|
467
|
+
unsigned char *in; /* next input location */
|
|
468
|
+
unsigned left; /* available input at in */
|
|
469
|
+
int bitbuf; /* bit buffer */
|
|
470
|
+
int bitcnt; /* number of bits in bit buffer */
|
|
471
|
+
|
|
472
|
+
/* input limit error return state for bits() and decode() */
|
|
473
|
+
jmp_buf env;
|
|
474
|
+
|
|
475
|
+
/* output state */
|
|
476
|
+
blast_out outfun; /* output function provided by user */
|
|
477
|
+
void *outhow; /* opaque information passed to outfun() */
|
|
478
|
+
unsigned next; /* index of next write location in out[] */
|
|
479
|
+
int first; /* true to check distances (for first 4K) */
|
|
480
|
+
unsigned char out[MAXWIN]; /* output buffer and sliding window */
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
/*
|
|
484
|
+
* Return need bits from the input stream. This always leaves less than
|
|
485
|
+
* eight bits in the buffer. bits() works properly for need == 0.
|
|
486
|
+
*
|
|
487
|
+
* Format notes:
|
|
488
|
+
*
|
|
489
|
+
* - Bits are stored in bytes from the least significant bit to the most
|
|
490
|
+
* significant bit. Therefore bits are dropped from the bottom of the bit
|
|
491
|
+
* buffer, using shift right, and new bytes are appended to the top of the
|
|
492
|
+
* bit buffer, using shift left.
|
|
493
|
+
*/
|
|
494
|
+
static int bits(struct state *s, int need)
|
|
495
|
+
{
|
|
496
|
+
int val; /* bit accumulator */
|
|
497
|
+
|
|
498
|
+
/* load at least need bits into val */
|
|
499
|
+
val = s->bitbuf;
|
|
500
|
+
while (s->bitcnt < need) {
|
|
501
|
+
if (s->left == 0) {
|
|
502
|
+
s->left = s->infun(s->inhow, &(s->in));
|
|
503
|
+
if (s->left == 0) longjmp(s->env, 1); /* out of input */
|
|
504
|
+
}
|
|
505
|
+
val |= (int)(*(s->in)++) << s->bitcnt; /* load eight bits */
|
|
506
|
+
s->left--;
|
|
507
|
+
s->bitcnt += 8;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/* drop need bits and update buffer, always zero to seven bits left */
|
|
511
|
+
s->bitbuf = val >> need;
|
|
512
|
+
s->bitcnt -= need;
|
|
513
|
+
|
|
514
|
+
/* return need bits, zeroing the bits above that */
|
|
515
|
+
return val & ((1 << need) - 1);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/*
|
|
519
|
+
* Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of
|
|
520
|
+
* each length, which for a canonical code are stepped through in order.
|
|
521
|
+
* symbol[] are the symbol values in canonical order, where the number of
|
|
522
|
+
* entries is the sum of the counts in count[]. The decoding process can be
|
|
523
|
+
* seen in the function decode() below.
|
|
524
|
+
*/
|
|
525
|
+
struct huffman {
|
|
526
|
+
short *count; /* number of symbols of each length */
|
|
527
|
+
short *symbol; /* canonically ordered symbols */
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/*
|
|
531
|
+
* Decode a code from the stream s using huffman table h. Return the symbol or
|
|
532
|
+
* a negative value if there is an error. If all of the lengths are zero, i.e.
|
|
533
|
+
* an empty code, or if the code is incomplete and an invalid code is received,
|
|
534
|
+
* then -9 is returned after reading MAXBITS bits.
|
|
535
|
+
*
|
|
536
|
+
* Format notes:
|
|
537
|
+
*
|
|
538
|
+
* - The codes as stored in the compressed data are bit-reversed relative to
|
|
539
|
+
* a simple integer ordering of codes of the same lengths. Hence below the
|
|
540
|
+
* bits are pulled from the compressed data one at a time and used to
|
|
541
|
+
* build the code value reversed from what is in the stream in order to
|
|
542
|
+
* permit simple integer comparisons for decoding.
|
|
543
|
+
*
|
|
544
|
+
* - The first code for the shortest length is all ones. Subsequent codes of
|
|
545
|
+
* the same length are simply integer decrements of the previous code. When
|
|
546
|
+
* moving up a length, a one bit is appended to the code. For a complete
|
|
547
|
+
* code, the last code of the longest length will be all zeros. To support
|
|
548
|
+
* this ordering, the bits pulled during decoding are inverted to apply the
|
|
549
|
+
* more "natural" ordering starting with all zeros and incrementing.
|
|
550
|
+
*/
|
|
551
|
+
static int decode(struct state *s, struct huffman *h)
|
|
552
|
+
{
|
|
553
|
+
int len; /* current number of bits in code */
|
|
554
|
+
int code; /* len bits being decoded */
|
|
555
|
+
int first; /* first code of length len */
|
|
556
|
+
int count; /* number of codes of length len */
|
|
557
|
+
int index; /* index of first code of length len in symbol table */
|
|
558
|
+
int bitbuf; /* bits from stream */
|
|
559
|
+
int left; /* bits left in next or left to process */
|
|
560
|
+
short *next; /* next number of codes */
|
|
561
|
+
|
|
562
|
+
bitbuf = s->bitbuf;
|
|
563
|
+
left = s->bitcnt;
|
|
564
|
+
code = first = index = 0;
|
|
565
|
+
len = 1;
|
|
566
|
+
next = h->count + 1;
|
|
567
|
+
while (1) {
|
|
568
|
+
while (left--) {
|
|
569
|
+
code |= (bitbuf & 1) ^ 1; /* invert code */
|
|
570
|
+
bitbuf >>= 1;
|
|
571
|
+
count = *next++;
|
|
572
|
+
if (code < first + count) { /* if length len, return symbol */
|
|
573
|
+
s->bitbuf = bitbuf;
|
|
574
|
+
s->bitcnt = (s->bitcnt - len) & 7;
|
|
575
|
+
return h->symbol[index + (code - first)];
|
|
576
|
+
}
|
|
577
|
+
index += count; /* else update for next length */
|
|
578
|
+
first += count;
|
|
579
|
+
first <<= 1;
|
|
580
|
+
code <<= 1;
|
|
581
|
+
len++;
|
|
582
|
+
}
|
|
583
|
+
left = (MAXBITS+1) - len;
|
|
584
|
+
if (left == 0) break;
|
|
585
|
+
if (s->left == 0) {
|
|
586
|
+
s->left = s->infun(s->inhow, &(s->in));
|
|
587
|
+
if (s->left == 0) longjmp(s->env, 1); /* out of input */
|
|
588
|
+
}
|
|
589
|
+
bitbuf = *(s->in)++;
|
|
590
|
+
s->left--;
|
|
591
|
+
if (left > 8) left = 8;
|
|
592
|
+
}
|
|
593
|
+
return -9; /* ran out of codes */
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/*
|
|
597
|
+
* Given a list of repeated code lengths rep[0..n-1], where each byte is a
|
|
598
|
+
* count (high four bits + 1) and a code length (low four bits), generate the
|
|
599
|
+
* list of code lengths. This compaction reduces the size of the object code.
|
|
600
|
+
* Then given the list of code lengths length[0..n-1] representing a canonical
|
|
601
|
+
* Huffman code for n symbols, construct the tables required to decode those
|
|
602
|
+
* codes. Those tables are the number of codes of each length, and the symbols
|
|
603
|
+
* sorted by length, retaining their original order within each length. The
|
|
604
|
+
* return value is zero for a complete code set, negative for an over-
|
|
605
|
+
* subscribed code set, and positive for an incomplete code set. The tables
|
|
606
|
+
* can be used if the return value is zero or positive, but they cannot be used
|
|
607
|
+
* if the return value is negative. If the return value is zero, it is not
|
|
608
|
+
* possible for decode() using that table to return an error--any stream of
|
|
609
|
+
* enough bits will resolve to a symbol. If the return value is positive, then
|
|
610
|
+
* it is possible for decode() using that table to return an error for received
|
|
611
|
+
* codes past the end of the incomplete lengths.
|
|
612
|
+
*/
|
|
613
|
+
static int construct(struct huffman *h, const unsigned char *rep, int n)
|
|
614
|
+
{
|
|
615
|
+
int symbol; /* current symbol when stepping through length[] */
|
|
616
|
+
int len; /* current length when stepping through h->count[] */
|
|
617
|
+
int left; /* number of possible codes left of current length */
|
|
618
|
+
short offs[MAXBITS+1]; /* offsets in symbol table for each length */
|
|
619
|
+
short length[256]; /* code lengths */
|
|
620
|
+
|
|
621
|
+
/* convert compact repeat counts into symbol bit length list */
|
|
622
|
+
symbol = 0;
|
|
623
|
+
do {
|
|
624
|
+
len = *rep++;
|
|
625
|
+
left = (len >> 4) + 1;
|
|
626
|
+
len &= 15;
|
|
627
|
+
do {
|
|
628
|
+
length[symbol++] = len;
|
|
629
|
+
} while (--left);
|
|
630
|
+
} while (--n);
|
|
631
|
+
n = symbol;
|
|
632
|
+
|
|
633
|
+
/* count number of codes of each length */
|
|
634
|
+
for (len = 0; len <= MAXBITS; len++)
|
|
635
|
+
h->count[len] = 0;
|
|
636
|
+
for (symbol = 0; symbol < n; symbol++)
|
|
637
|
+
(h->count[length[symbol]])++; /* assumes lengths are within bounds */
|
|
638
|
+
if (h->count[0] == n) /* no codes! */
|
|
639
|
+
return 0; /* complete, but decode() will fail */
|
|
640
|
+
|
|
641
|
+
/* check for an over-subscribed or incomplete set of lengths */
|
|
642
|
+
left = 1; /* one possible code of zero length */
|
|
643
|
+
for (len = 1; len <= MAXBITS; len++) {
|
|
644
|
+
left <<= 1; /* one more bit, double codes left */
|
|
645
|
+
left -= h->count[len]; /* deduct count from possible codes */
|
|
646
|
+
if (left < 0) return left; /* over-subscribed--return negative */
|
|
647
|
+
} /* left > 0 means incomplete */
|
|
648
|
+
|
|
649
|
+
/* generate offsets into symbol table for each length for sorting */
|
|
650
|
+
offs[1] = 0;
|
|
651
|
+
for (len = 1; len < MAXBITS; len++)
|
|
652
|
+
offs[len + 1] = offs[len] + h->count[len];
|
|
653
|
+
|
|
654
|
+
/*
|
|
655
|
+
* put symbols in table sorted by length, by symbol order within each
|
|
656
|
+
* length
|
|
657
|
+
*/
|
|
658
|
+
for (symbol = 0; symbol < n; symbol++)
|
|
659
|
+
if (length[symbol] != 0)
|
|
660
|
+
h->symbol[offs[length[symbol]]++] = symbol;
|
|
661
|
+
|
|
662
|
+
/* return zero for complete set, positive for incomplete set */
|
|
663
|
+
return left;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/*
|
|
667
|
+
* Decode PKWare Compression Library stream.
|
|
668
|
+
*
|
|
669
|
+
* Format notes:
|
|
670
|
+
*
|
|
671
|
+
* - First byte is 0 if literals are uncoded or 1 if they are coded. Second
|
|
672
|
+
* byte is 4, 5, or 6 for the number of extra bits in the distance code.
|
|
673
|
+
* This is the base-2 logarithm of the dictionary size minus six.
|
|
674
|
+
*
|
|
675
|
+
* - Compressed data is a combination of literals and length/distance pairs
|
|
676
|
+
* terminated by an end code. Literals are either Huffman coded or
|
|
677
|
+
* uncoded bytes. A length/distance pair is a coded length followed by a
|
|
678
|
+
* coded distance to represent a string that occurs earlier in the
|
|
679
|
+
* uncompressed data that occurs again at the current location.
|
|
680
|
+
*
|
|
681
|
+
* - A bit preceding a literal or length/distance pair indicates which comes
|
|
682
|
+
* next, 0 for literals, 1 for length/distance.
|
|
683
|
+
*
|
|
684
|
+
* - If literals are uncoded, then the next eight bits are the literal, in the
|
|
685
|
+
* normal bit order in th stream, i.e. no bit-reversal is needed. Similarly,
|
|
686
|
+
* no bit reversal is needed for either the length extra bits or the distance
|
|
687
|
+
* extra bits.
|
|
688
|
+
*
|
|
689
|
+
* - Literal bytes are simply written to the output. A length/distance pair is
|
|
690
|
+
* an instruction to copy previously uncompressed bytes to the output. The
|
|
691
|
+
* copy is from distance bytes back in the output stream, copying for length
|
|
692
|
+
* bytes.
|
|
693
|
+
*
|
|
694
|
+
* - Distances pointing before the beginning of the output data are not
|
|
695
|
+
* permitted.
|
|
696
|
+
*
|
|
697
|
+
* - Overlapped copies, where the length is greater than the distance, are
|
|
698
|
+
* allowed and common. For example, a distance of one and a length of 518
|
|
699
|
+
* simply copies the last byte 518 times. A distance of four and a length of
|
|
700
|
+
* twelve copies the last four bytes three times. A simple forward copy
|
|
701
|
+
* ignoring whether the length is greater than the distance or not implements
|
|
702
|
+
* this correctly.
|
|
703
|
+
*/
|
|
704
|
+
static int decomp(struct state *s)
|
|
705
|
+
{
|
|
706
|
+
int lit; /* true if literals are coded */
|
|
707
|
+
int dict; /* log2(dictionary size) - 6 */
|
|
708
|
+
int symbol; /* decoded symbol, extra bits for distance */
|
|
709
|
+
int len; /* length for copy */
|
|
710
|
+
unsigned dist; /* distance for copy */
|
|
711
|
+
int copy; /* copy counter */
|
|
712
|
+
unsigned char *from, *to; /* copy pointers */
|
|
713
|
+
static int virgin = 1; /* build tables once */
|
|
714
|
+
static short litcnt[MAXBITS+1], litsym[256]; /* litcode memory */
|
|
715
|
+
static short lencnt[MAXBITS+1], lensym[16]; /* lencode memory */
|
|
716
|
+
static short distcnt[MAXBITS+1], distsym[64]; /* distcode memory */
|
|
717
|
+
static struct huffman litcode = {litcnt, litsym}; /* length code */
|
|
718
|
+
static struct huffman lencode = {lencnt, lensym}; /* length code */
|
|
719
|
+
static struct huffman distcode = {distcnt, distsym};/* distance code */
|
|
720
|
+
/* bit lengths of literal codes */
|
|
721
|
+
static const unsigned char litlen[] = {
|
|
722
|
+
11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8,
|
|
723
|
+
9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5,
|
|
724
|
+
7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12,
|
|
725
|
+
8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27,
|
|
726
|
+
44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45,
|
|
727
|
+
44, 173};
|
|
728
|
+
/* bit lengths of length codes 0..15 */
|
|
729
|
+
static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23};
|
|
730
|
+
/* bit lengths of distance codes 0..63 */
|
|
731
|
+
static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248};
|
|
732
|
+
static const short base[16] = { /* base for length codes */
|
|
733
|
+
3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264};
|
|
734
|
+
static const char extra[16] = { /* extra bits for length codes */
|
|
735
|
+
0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8};
|
|
736
|
+
|
|
737
|
+
/* set up decoding tables (once--might not be thread-safe) */
|
|
738
|
+
if (virgin) {
|
|
739
|
+
construct(&litcode, litlen, sizeof(litlen));
|
|
740
|
+
construct(&lencode, lenlen, sizeof(lenlen));
|
|
741
|
+
construct(&distcode, distlen, sizeof(distlen));
|
|
742
|
+
virgin = 0;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/* read header */
|
|
746
|
+
lit = bits(s, 8);
|
|
747
|
+
if (lit > 1) return -1;
|
|
748
|
+
dict = bits(s, 8);
|
|
749
|
+
if (dict < 4 || dict > 6) return -2;
|
|
750
|
+
|
|
751
|
+
/* decode literals and length/distance pairs */
|
|
752
|
+
do {
|
|
753
|
+
if (bits(s, 1)) {
|
|
754
|
+
/* get length */
|
|
755
|
+
symbol = decode(s, &lencode);
|
|
756
|
+
len = base[symbol] + bits(s, extra[symbol]);
|
|
757
|
+
if (len == 519) break; /* end code */
|
|
758
|
+
|
|
759
|
+
/* get distance */
|
|
760
|
+
symbol = len == 2 ? 2 : dict;
|
|
761
|
+
dist = decode(s, &distcode) << symbol;
|
|
762
|
+
dist += bits(s, symbol);
|
|
763
|
+
dist++;
|
|
764
|
+
if (s->first && dist > s->next)
|
|
765
|
+
return -3; /* distance too far back */
|
|
766
|
+
|
|
767
|
+
/* copy length bytes from distance bytes back */
|
|
768
|
+
do {
|
|
769
|
+
to = s->out + s->next;
|
|
770
|
+
from = to - dist;
|
|
771
|
+
copy = MAXWIN;
|
|
772
|
+
if (s->next < dist) {
|
|
773
|
+
from += copy;
|
|
774
|
+
copy = dist;
|
|
775
|
+
}
|
|
776
|
+
copy -= s->next;
|
|
777
|
+
if (copy > len) copy = len;
|
|
778
|
+
len -= copy;
|
|
779
|
+
s->next += copy;
|
|
780
|
+
do {
|
|
781
|
+
*to++ = *from++;
|
|
782
|
+
} while (--copy);
|
|
783
|
+
if (s->next == MAXWIN) {
|
|
784
|
+
if (s->outfun(s->outhow, s->out, s->next)) return 1;
|
|
785
|
+
s->next = 0;
|
|
786
|
+
s->first = 0;
|
|
787
|
+
}
|
|
788
|
+
} while (len != 0);
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
/* get literal and write it */
|
|
792
|
+
symbol = lit ? decode(s, &litcode) : bits(s, 8);
|
|
793
|
+
s->out[s->next++] = symbol;
|
|
794
|
+
if (s->next == MAXWIN) {
|
|
795
|
+
if (s->outfun(s->outhow, s->out, s->next)) return 1;
|
|
796
|
+
s->next = 0;
|
|
797
|
+
s->first = 0;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
} while (1);
|
|
801
|
+
return 0;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/* See comments in blast.h */
|
|
805
|
+
int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
|
|
806
|
+
{
|
|
807
|
+
struct state s; /* input/output state */
|
|
808
|
+
int err; /* return value */
|
|
809
|
+
|
|
810
|
+
/* initialize input state */
|
|
811
|
+
s.infun = infun;
|
|
812
|
+
s.inhow = inhow;
|
|
813
|
+
s.left = 0;
|
|
814
|
+
s.bitbuf = 0;
|
|
815
|
+
s.bitcnt = 0;
|
|
816
|
+
|
|
817
|
+
/* initialize output state */
|
|
818
|
+
s.outfun = outfun;
|
|
819
|
+
s.outhow = outhow;
|
|
820
|
+
s.next = 0;
|
|
821
|
+
s.first = 1;
|
|
822
|
+
|
|
823
|
+
/* return if bits() or decode() tries to read past available input */
|
|
824
|
+
if (setjmp(s.env) != 0) /* if came back here via longjmp(), */
|
|
825
|
+
err = 2; /* then skip decomp(), return error */
|
|
826
|
+
else
|
|
827
|
+
err = decomp(&s); /* decompress */
|
|
828
|
+
|
|
829
|
+
/* write any leftover output and update the error code if needed */
|
|
830
|
+
if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0)
|
|
831
|
+
err = 1;
|
|
832
|
+
return err;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
/************************************************************/
|
|
837
|
+
|
|
838
|
+
static void *_cffi_types[] = {
|
|
839
|
+
/* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 15), // int()(unsigned int(*)(void *, unsigned char * *), void *, int(*)(void *, unsigned char *, unsigned int), void *)
|
|
840
|
+
/* 1 */ _CFFI_OP(_CFFI_OP_POINTER, 11), // unsigned int(*)(void *, unsigned char * *)
|
|
841
|
+
/* 2 */ _CFFI_OP(_CFFI_OP_POINTER, 17), // void *
|
|
842
|
+
/* 3 */ _CFFI_OP(_CFFI_OP_POINTER, 6), // int(*)(void *, unsigned char *, unsigned int)
|
|
843
|
+
/* 4 */ _CFFI_OP(_CFFI_OP_NOOP, 2),
|
|
844
|
+
/* 5 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
|
|
845
|
+
/* 6 */ _CFFI_OP(_CFFI_OP_FUNCTION, 15), // int()(void *, unsigned char *, unsigned int)
|
|
846
|
+
/* 7 */ _CFFI_OP(_CFFI_OP_NOOP, 2),
|
|
847
|
+
/* 8 */ _CFFI_OP(_CFFI_OP_POINTER, 16), // unsigned char *
|
|
848
|
+
/* 9 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 8), // unsigned int
|
|
849
|
+
/* 10 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
|
|
850
|
+
/* 11 */ _CFFI_OP(_CFFI_OP_FUNCTION, 9), // unsigned int()(void *, unsigned char * *)
|
|
851
|
+
/* 12 */ _CFFI_OP(_CFFI_OP_NOOP, 2),
|
|
852
|
+
/* 13 */ _CFFI_OP(_CFFI_OP_POINTER, 8), // unsigned char * *
|
|
853
|
+
/* 14 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
|
|
854
|
+
/* 15 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int
|
|
855
|
+
/* 16 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 4), // unsigned char
|
|
856
|
+
/* 17 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 0), // void
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
static int _cffi_d_blast(unsigned int(* x0)(void *, unsigned char * *), void * x1, int(* x2)(void *, unsigned char *, unsigned int), void * x3)
|
|
860
|
+
{
|
|
861
|
+
return blast(x0, x1, x2, x3);
|
|
862
|
+
}
|
|
863
|
+
#ifndef PYPY_VERSION
|
|
864
|
+
static PyObject *
|
|
865
|
+
_cffi_f_blast(PyObject *self, PyObject *args)
|
|
866
|
+
{
|
|
867
|
+
unsigned int(* x0)(void *, unsigned char * *);
|
|
868
|
+
void * x1;
|
|
869
|
+
int(* x2)(void *, unsigned char *, unsigned int);
|
|
870
|
+
void * x3;
|
|
871
|
+
Py_ssize_t datasize;
|
|
872
|
+
int result;
|
|
873
|
+
PyObject *arg0;
|
|
874
|
+
PyObject *arg1;
|
|
875
|
+
PyObject *arg2;
|
|
876
|
+
PyObject *arg3;
|
|
877
|
+
PyObject **aa;
|
|
878
|
+
|
|
879
|
+
aa = _cffi_unpack_args(args, 4, "blast");
|
|
880
|
+
if (aa == NULL)
|
|
881
|
+
return NULL;
|
|
882
|
+
arg0 = aa[0];
|
|
883
|
+
arg1 = aa[1];
|
|
884
|
+
arg2 = aa[2];
|
|
885
|
+
arg3 = aa[3];
|
|
886
|
+
|
|
887
|
+
x0 = (unsigned int(*)(void *, unsigned char * *))_cffi_to_c_pointer(arg0, _cffi_type(1));
|
|
888
|
+
if (x0 == (unsigned int(*)(void *, unsigned char * *))NULL && PyErr_Occurred())
|
|
889
|
+
return NULL;
|
|
890
|
+
|
|
891
|
+
datasize = _cffi_prepare_pointer_call_argument(
|
|
892
|
+
_cffi_type(2), arg1, (char **)&x1);
|
|
893
|
+
if (datasize != 0) {
|
|
894
|
+
if (datasize < 0)
|
|
895
|
+
return NULL;
|
|
896
|
+
x1 = (void *)alloca((size_t)datasize);
|
|
897
|
+
memset((void *)x1, 0, (size_t)datasize);
|
|
898
|
+
if (_cffi_convert_array_from_object((char *)x1, _cffi_type(2), arg1) < 0)
|
|
899
|
+
return NULL;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
x2 = (int(*)(void *, unsigned char *, unsigned int))_cffi_to_c_pointer(arg2, _cffi_type(3));
|
|
903
|
+
if (x2 == (int(*)(void *, unsigned char *, unsigned int))NULL && PyErr_Occurred())
|
|
904
|
+
return NULL;
|
|
905
|
+
|
|
906
|
+
datasize = _cffi_prepare_pointer_call_argument(
|
|
907
|
+
_cffi_type(2), arg3, (char **)&x3);
|
|
908
|
+
if (datasize != 0) {
|
|
909
|
+
if (datasize < 0)
|
|
910
|
+
return NULL;
|
|
911
|
+
x3 = (void *)alloca((size_t)datasize);
|
|
912
|
+
memset((void *)x3, 0, (size_t)datasize);
|
|
913
|
+
if (_cffi_convert_array_from_object((char *)x3, _cffi_type(2), arg3) < 0)
|
|
914
|
+
return NULL;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
Py_BEGIN_ALLOW_THREADS
|
|
918
|
+
_cffi_restore_errno();
|
|
919
|
+
{ result = blast(x0, x1, x2, x3); }
|
|
920
|
+
_cffi_save_errno();
|
|
921
|
+
Py_END_ALLOW_THREADS
|
|
922
|
+
|
|
923
|
+
(void)self; /* unused */
|
|
924
|
+
return _cffi_from_c_int(result, int);
|
|
925
|
+
}
|
|
926
|
+
#else
|
|
927
|
+
# define _cffi_f_blast _cffi_d_blast
|
|
928
|
+
#endif
|
|
929
|
+
|
|
930
|
+
static const struct _cffi_global_s _cffi_globals[] = {
|
|
931
|
+
{ "blast", (void *)_cffi_f_blast, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 0), (void *)_cffi_d_blast },
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
static const struct _cffi_typename_s _cffi_typenames[] = {
|
|
935
|
+
{ "blast_in", 1 },
|
|
936
|
+
{ "blast_out", 3 },
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
static const struct _cffi_type_context_s _cffi_type_context = {
|
|
940
|
+
_cffi_types,
|
|
941
|
+
_cffi_globals,
|
|
942
|
+
NULL, /* no fields */
|
|
943
|
+
NULL, /* no struct_unions */
|
|
944
|
+
NULL, /* no enums */
|
|
945
|
+
_cffi_typenames,
|
|
946
|
+
1, /* num_globals */
|
|
947
|
+
0, /* num_struct_unions */
|
|
948
|
+
0, /* num_enums */
|
|
949
|
+
2, /* num_typenames */
|
|
950
|
+
NULL, /* no includes */
|
|
951
|
+
18, /* num_types */
|
|
952
|
+
0, /* flags */
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
#ifdef PYPY_VERSION
|
|
956
|
+
PyMODINIT_FUNC
|
|
957
|
+
_cffi_pypyinit_blast(const void *p[])
|
|
958
|
+
{
|
|
959
|
+
p[0] = (const void *)0x2601;
|
|
960
|
+
p[1] = &_cffi_type_context;
|
|
961
|
+
}
|
|
962
|
+
# ifdef _MSC_VER
|
|
963
|
+
PyMODINIT_FUNC
|
|
964
|
+
# if PY_MAJOR_VERSION >= 3
|
|
965
|
+
PyInit_blast(void) { return NULL; }
|
|
966
|
+
# else
|
|
967
|
+
initblast(void) { }
|
|
968
|
+
# endif
|
|
969
|
+
# endif
|
|
970
|
+
#elif PY_MAJOR_VERSION >= 3
|
|
971
|
+
PyMODINIT_FUNC
|
|
972
|
+
PyInit_blast(void)
|
|
973
|
+
{
|
|
974
|
+
return _cffi_init("blast", 0x2601, &_cffi_type_context);
|
|
975
|
+
}
|
|
976
|
+
#else
|
|
977
|
+
PyMODINIT_FUNC
|
|
978
|
+
initblast(void)
|
|
979
|
+
{
|
|
980
|
+
_cffi_init("blast", 0x2601, &_cffi_type_context);
|
|
981
|
+
}
|
|
982
|
+
#endif
|