##// END OF EJS Templates
zstd: fix compilation with Solaris Studio...
Danek Duvall -
r30498:d7a05d83 default
parent child Browse files
Show More
@@ -1,226 +1,226
1 1 /**
2 2 * Copyright (c) 2016-present, Gregory Szorc
3 3 * All rights reserved.
4 4 *
5 5 * This software may be modified and distributed under the terms
6 6 * of the BSD license. See the LICENSE file for details.
7 7 */
8 8
9 9 #include "python-zstandard.h"
10 10
11 11 void ztopy_compression_parameters(CompressionParametersObject* params, ZSTD_compressionParameters* zparams) {
12 12 zparams->windowLog = params->windowLog;
13 13 zparams->chainLog = params->chainLog;
14 14 zparams->hashLog = params->hashLog;
15 15 zparams->searchLog = params->searchLog;
16 16 zparams->searchLength = params->searchLength;
17 17 zparams->targetLength = params->targetLength;
18 18 zparams->strategy = params->strategy;
19 19 }
20 20
21 21 CompressionParametersObject* get_compression_parameters(PyObject* self, PyObject* args) {
22 22 int compressionLevel;
23 23 unsigned PY_LONG_LONG sourceSize = 0;
24 24 Py_ssize_t dictSize = 0;
25 25 ZSTD_compressionParameters params;
26 26 CompressionParametersObject* result;
27 27
28 28 if (!PyArg_ParseTuple(args, "i|Kn", &compressionLevel, &sourceSize, &dictSize)) {
29 29 return NULL;
30 30 }
31 31
32 32 params = ZSTD_getCParams(compressionLevel, sourceSize, dictSize);
33 33
34 34 result = PyObject_New(CompressionParametersObject, &CompressionParametersType);
35 35 if (!result) {
36 36 return NULL;
37 37 }
38 38
39 39 result->windowLog = params.windowLog;
40 40 result->chainLog = params.chainLog;
41 41 result->hashLog = params.hashLog;
42 42 result->searchLog = params.searchLog;
43 43 result->searchLength = params.searchLength;
44 44 result->targetLength = params.targetLength;
45 45 result->strategy = params.strategy;
46 46
47 47 return result;
48 48 }
49 49
50 50 PyObject* estimate_compression_context_size(PyObject* self, PyObject* args) {
51 51 CompressionParametersObject* params;
52 52 ZSTD_compressionParameters zparams;
53 53 PyObject* result;
54 54
55 55 if (!PyArg_ParseTuple(args, "O!", &CompressionParametersType, &params)) {
56 56 return NULL;
57 57 }
58 58
59 59 ztopy_compression_parameters(params, &zparams);
60 60 result = PyLong_FromSize_t(ZSTD_estimateCCtxSize(zparams));
61 61 return result;
62 62 }
63 63
64 64 PyDoc_STRVAR(CompressionParameters__doc__,
65 65 "CompressionParameters: low-level control over zstd compression");
66 66
67 67 static PyObject* CompressionParameters_new(PyTypeObject* subtype, PyObject* args, PyObject* kwargs) {
68 68 CompressionParametersObject* self;
69 69 unsigned windowLog;
70 70 unsigned chainLog;
71 71 unsigned hashLog;
72 72 unsigned searchLog;
73 73 unsigned searchLength;
74 74 unsigned targetLength;
75 75 unsigned strategy;
76 76
77 77 if (!PyArg_ParseTuple(args, "IIIIIII", &windowLog, &chainLog, &hashLog, &searchLog,
78 78 &searchLength, &targetLength, &strategy)) {
79 79 return NULL;
80 80 }
81 81
82 82 if (windowLog < ZSTD_WINDOWLOG_MIN || windowLog > ZSTD_WINDOWLOG_MAX) {
83 83 PyErr_SetString(PyExc_ValueError, "invalid window log value");
84 84 return NULL;
85 85 }
86 86
87 87 if (chainLog < ZSTD_CHAINLOG_MIN || chainLog > ZSTD_CHAINLOG_MAX) {
88 88 PyErr_SetString(PyExc_ValueError, "invalid chain log value");
89 89 return NULL;
90 90 }
91 91
92 92 if (hashLog < ZSTD_HASHLOG_MIN || hashLog > ZSTD_HASHLOG_MAX) {
93 93 PyErr_SetString(PyExc_ValueError, "invalid hash log value");
94 94 return NULL;
95 95 }
96 96
97 97 if (searchLog < ZSTD_SEARCHLOG_MIN || searchLog > ZSTD_SEARCHLOG_MAX) {
98 98 PyErr_SetString(PyExc_ValueError, "invalid search log value");
99 99 return NULL;
100 100 }
101 101
102 102 if (searchLength < ZSTD_SEARCHLENGTH_MIN || searchLength > ZSTD_SEARCHLENGTH_MAX) {
103 103 PyErr_SetString(PyExc_ValueError, "invalid search length value");
104 104 return NULL;
105 105 }
106 106
107 107 if (targetLength < ZSTD_TARGETLENGTH_MIN || targetLength > ZSTD_TARGETLENGTH_MAX) {
108 108 PyErr_SetString(PyExc_ValueError, "invalid target length value");
109 109 return NULL;
110 110 }
111 111
112 112 if (strategy < ZSTD_fast || strategy > ZSTD_btopt) {
113 113 PyErr_SetString(PyExc_ValueError, "invalid strategy value");
114 114 return NULL;
115 115 }
116 116
117 117 self = (CompressionParametersObject*)subtype->tp_alloc(subtype, 1);
118 118 if (!self) {
119 119 return NULL;
120 120 }
121 121
122 122 self->windowLog = windowLog;
123 123 self->chainLog = chainLog;
124 124 self->hashLog = hashLog;
125 125 self->searchLog = searchLog;
126 126 self->searchLength = searchLength;
127 127 self->targetLength = targetLength;
128 128 self->strategy = strategy;
129 129
130 130 return (PyObject*)self;
131 131 }
132 132
133 133 static void CompressionParameters_dealloc(PyObject* self) {
134 134 PyObject_Del(self);
135 135 }
136 136
137 137 static Py_ssize_t CompressionParameters_length(PyObject* self) {
138 138 return 7;
139 };
139 }
140 140
141 141 static PyObject* CompressionParameters_item(PyObject* o, Py_ssize_t i) {
142 142 CompressionParametersObject* self = (CompressionParametersObject*)o;
143 143
144 144 switch (i) {
145 145 case 0:
146 146 return PyLong_FromLong(self->windowLog);
147 147 case 1:
148 148 return PyLong_FromLong(self->chainLog);
149 149 case 2:
150 150 return PyLong_FromLong(self->hashLog);
151 151 case 3:
152 152 return PyLong_FromLong(self->searchLog);
153 153 case 4:
154 154 return PyLong_FromLong(self->searchLength);
155 155 case 5:
156 156 return PyLong_FromLong(self->targetLength);
157 157 case 6:
158 158 return PyLong_FromLong(self->strategy);
159 159 default:
160 160 PyErr_SetString(PyExc_IndexError, "index out of range");
161 161 return NULL;
162 162 }
163 163 }
164 164
165 165 static PySequenceMethods CompressionParameters_sq = {
166 166 CompressionParameters_length, /* sq_length */
167 167 0, /* sq_concat */
168 168 0, /* sq_repeat */
169 169 CompressionParameters_item, /* sq_item */
170 170 0, /* sq_ass_item */
171 171 0, /* sq_contains */
172 172 0, /* sq_inplace_concat */
173 173 0 /* sq_inplace_repeat */
174 174 };
175 175
176 176 PyTypeObject CompressionParametersType = {
177 177 PyVarObject_HEAD_INIT(NULL, 0)
178 178 "CompressionParameters", /* tp_name */
179 179 sizeof(CompressionParametersObject), /* tp_basicsize */
180 180 0, /* tp_itemsize */
181 181 (destructor)CompressionParameters_dealloc, /* tp_dealloc */
182 182 0, /* tp_print */
183 183 0, /* tp_getattr */
184 184 0, /* tp_setattr */
185 185 0, /* tp_compare */
186 186 0, /* tp_repr */
187 187 0, /* tp_as_number */
188 188 &CompressionParameters_sq, /* tp_as_sequence */
189 189 0, /* tp_as_mapping */
190 190 0, /* tp_hash */
191 191 0, /* tp_call */
192 192 0, /* tp_str */
193 193 0, /* tp_getattro */
194 194 0, /* tp_setattro */
195 195 0, /* tp_as_buffer */
196 196 Py_TPFLAGS_DEFAULT, /* tp_flags */
197 197 CompressionParameters__doc__, /* tp_doc */
198 198 0, /* tp_traverse */
199 199 0, /* tp_clear */
200 200 0, /* tp_richcompare */
201 201 0, /* tp_weaklistoffset */
202 202 0, /* tp_iter */
203 203 0, /* tp_iternext */
204 204 0, /* tp_methods */
205 205 0, /* tp_members */
206 206 0, /* tp_getset */
207 207 0, /* tp_base */
208 208 0, /* tp_dict */
209 209 0, /* tp_descr_get */
210 210 0, /* tp_descr_set */
211 211 0, /* tp_dictoffset */
212 212 0, /* tp_init */
213 213 0, /* tp_alloc */
214 214 CompressionParameters_new, /* tp_new */
215 215 };
216 216
217 217 void compressionparams_module_init(PyObject* mod) {
218 218 Py_TYPE(&CompressionParametersType) = &PyType_Type;
219 219 if (PyType_Ready(&CompressionParametersType) < 0) {
220 220 return;
221 221 }
222 222
223 223 Py_IncRef((PyObject*)&CompressionParametersType);
224 224 PyModule_AddObject(mod, "CompressionParameters",
225 225 (PyObject*)&CompressionParametersType);
226 226 }
@@ -1,125 +1,125
1 1 /**
2 2 * Copyright (c) 2016-present, Gregory Szorc
3 3 * All rights reserved.
4 4 *
5 5 * This software may be modified and distributed under the terms
6 6 * of the BSD license. See the LICENSE file for details.
7 7 */
8 8
9 9 #include "python-zstandard.h"
10 10
11 11 PyDoc_STRVAR(DictParameters__doc__,
12 12 "DictParameters: low-level control over dictionary generation");
13 13
14 14 static PyObject* DictParameters_new(PyTypeObject* subtype, PyObject* args, PyObject* kwargs) {
15 15 DictParametersObject* self;
16 16 unsigned selectivityLevel;
17 17 int compressionLevel;
18 18 unsigned notificationLevel;
19 19 unsigned dictID;
20 20
21 21 if (!PyArg_ParseTuple(args, "IiII", &selectivityLevel, &compressionLevel,
22 22 &notificationLevel, &dictID)) {
23 23 return NULL;
24 24 }
25 25
26 26 self = (DictParametersObject*)subtype->tp_alloc(subtype, 1);
27 27 if (!self) {
28 28 return NULL;
29 29 }
30 30
31 31 self->selectivityLevel = selectivityLevel;
32 32 self->compressionLevel = compressionLevel;
33 33 self->notificationLevel = notificationLevel;
34 34 self->dictID = dictID;
35 35
36 36 return (PyObject*)self;
37 37 }
38 38
39 39 static void DictParameters_dealloc(PyObject* self) {
40 40 PyObject_Del(self);
41 41 }
42 42
43 43 static Py_ssize_t DictParameters_length(PyObject* self) {
44 44 return 4;
45 };
45 }
46 46
47 47 static PyObject* DictParameters_item(PyObject* o, Py_ssize_t i) {
48 48 DictParametersObject* self = (DictParametersObject*)o;
49 49
50 50 switch (i) {
51 51 case 0:
52 52 return PyLong_FromLong(self->selectivityLevel);
53 53 case 1:
54 54 return PyLong_FromLong(self->compressionLevel);
55 55 case 2:
56 56 return PyLong_FromLong(self->notificationLevel);
57 57 case 3:
58 58 return PyLong_FromLong(self->dictID);
59 59 default:
60 60 PyErr_SetString(PyExc_IndexError, "index out of range");
61 61 return NULL;
62 62 }
63 63 }
64 64
65 65 static PySequenceMethods DictParameters_sq = {
66 66 DictParameters_length, /* sq_length */
67 67 0, /* sq_concat */
68 68 0, /* sq_repeat */
69 69 DictParameters_item, /* sq_item */
70 70 0, /* sq_ass_item */
71 71 0, /* sq_contains */
72 72 0, /* sq_inplace_concat */
73 73 0 /* sq_inplace_repeat */
74 74 };
75 75
76 76 PyTypeObject DictParametersType = {
77 77 PyVarObject_HEAD_INIT(NULL, 0)
78 78 "DictParameters", /* tp_name */
79 79 sizeof(DictParametersObject), /* tp_basicsize */
80 80 0, /* tp_itemsize */
81 81 (destructor)DictParameters_dealloc, /* tp_dealloc */
82 82 0, /* tp_print */
83 83 0, /* tp_getattr */
84 84 0, /* tp_setattr */
85 85 0, /* tp_compare */
86 86 0, /* tp_repr */
87 87 0, /* tp_as_number */
88 88 &DictParameters_sq, /* tp_as_sequence */
89 89 0, /* tp_as_mapping */
90 90 0, /* tp_hash */
91 91 0, /* tp_call */
92 92 0, /* tp_str */
93 93 0, /* tp_getattro */
94 94 0, /* tp_setattro */
95 95 0, /* tp_as_buffer */
96 96 Py_TPFLAGS_DEFAULT, /* tp_flags */
97 97 DictParameters__doc__, /* tp_doc */
98 98 0, /* tp_traverse */
99 99 0, /* tp_clear */
100 100 0, /* tp_richcompare */
101 101 0, /* tp_weaklistoffset */
102 102 0, /* tp_iter */
103 103 0, /* tp_iternext */
104 104 0, /* tp_methods */
105 105 0, /* tp_members */
106 106 0, /* tp_getset */
107 107 0, /* tp_base */
108 108 0, /* tp_dict */
109 109 0, /* tp_descr_get */
110 110 0, /* tp_descr_set */
111 111 0, /* tp_dictoffset */
112 112 0, /* tp_init */
113 113 0, /* tp_alloc */
114 114 DictParameters_new, /* tp_new */
115 115 };
116 116
117 117 void dictparams_module_init(PyObject* mod) {
118 118 Py_TYPE(&DictParametersType) = &PyType_Type;
119 119 if (PyType_Ready(&DictParametersType) < 0) {
120 120 return;
121 121 }
122 122
123 123 Py_IncRef((PyObject*)&DictParametersType);
124 124 PyModule_AddObject(mod, "DictParameters", (PyObject*)&DictParametersType);
125 125 }
General Comments 0
You need to be logged in to leave comments. Login now