Gentoo Archives: gentoo-commits

From: Alexandre Restovtsev <tetromino@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gnome:gnome-next commit in: media-libs/rply/, media-libs/rply/files/
Date: Mon, 26 Sep 2011 10:26:29
Message-Id: a3d21a5db0c24475cc20ea207952205bc954f0b7.tetromino@gentoo
1 commit: a3d21a5db0c24475cc20ea207952205bc954f0b7
2 Author: Alexandre Rostovtsev <tetromino <AT> gmail <DOT> com>
3 AuthorDate: Mon Sep 26 10:13:33 2011 +0000
4 Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
5 CommitDate: Mon Sep 26 10:13:33 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gnome.git;a=commit;h=a3d21a5d
7
8 media-libs/rply: 1.01 → 1.01-r1
9
10 Add patches to fix horrible bugs in upstream code:
11 1. Use int16_t and int32_t instead of assuming e.g. that sizeof(long)
12 and sizeof(short) are some specific number of bytes (yes, rply is a very
13 old piece of software).
14 2. Switch LC_NUMERIC locale to "C" to ensure "." is used as the decimal
15 separator.
16
17 ---
18 media-libs/rply/files/rply-1.01-lc_numeric.patch | 86 +++++++++
19 media-libs/rply/files/rply-1.01-stdint.h.patch | 185 ++++++++++++++++++++
20 .../rply/{rply-1.01.ebuild => rply-1.01-r1.ebuild} | 6 +
21 3 files changed, 277 insertions(+), 0 deletions(-)
22
23 diff --git a/media-libs/rply/files/rply-1.01-lc_numeric.patch b/media-libs/rply/files/rply-1.01-lc_numeric.patch
24 new file mode 100644
25 index 0000000..6d98abd
26 --- /dev/null
27 +++ b/media-libs/rply/files/rply-1.01-lc_numeric.patch
28 @@ -0,0 +1,86 @@
29 +From 8a7a76b7dcc94e8e71725e26a146330c73377ebd Mon Sep 17 00:00:00 2001
30 +From: Alexandre Rostovtsev <tetromino@×××××.com>
31 +Date: Mon, 26 Sep 2011 04:46:44 -0400
32 +Subject: [PATCH 2/2] Switch LC_NUMERIC locale to "C" for decimal point
33 + separator safety
34 +
35 +Make sure to switch the LC_NUMERIC locale to "C" when using strtod() and
36 +fpritnf("%g",...) to ensure that '.' is used as the decimal point
37 +separator when reading and writing .ply files.
38 +---
39 + rply.c | 31 +++++++++++++++++++++++++++----
40 + 1 files changed, 27 insertions(+), 4 deletions(-)
41 +
42 +diff --git a/rply.c b/rply.c
43 +index 9eaa77f..789c002 100644
44 +--- a/rply.c
45 ++++ b/rply.c
46 +@@ -12,6 +12,7 @@
47 + #include <string.h>
48 + #include <limits.h>
49 + #include <float.h>
50 ++#include <locale.h>
51 + #include <stdarg.h>
52 + #include <stdlib.h>
53 + #include <stddef.h>
54 +@@ -1229,13 +1230,27 @@ static int oascii_uint32(p_ply ply, double value) {
55 + }
56 +
57 + static int oascii_float32(p_ply ply, double value) {
58 ++ char *curr_locale;
59 ++ int ret;
60 + if (value < -FLT_MAX || value > FLT_MAX) return 0;
61 +- return fprintf(ply->fp, "%g ", (float) value) > 0;
62 ++ /* Switch locale to C to use '.' as the decimal point separator */
63 ++ curr_locale = setlocale(LC_NUMERIC, NULL);
64 ++ setlocale(LC_NUMERIC, "C");
65 ++ ret = fprintf(ply->fp, "%g ", (float) value);
66 ++ setlocale(LC_NUMERIC, curr_locale);
67 ++ return ret > 0;
68 + }
69 +
70 + static int oascii_float64(p_ply ply, double value) {
71 ++ char *curr_locale;
72 ++ int ret;
73 + if (value < -DBL_MAX || value > DBL_MAX) return 0;
74 +- return fprintf(ply->fp, "%g ", value) > 0;
75 ++ /* Switch locale to C to use '.' as the decimal point separator */
76 ++ curr_locale = setlocale(LC_NUMERIC, NULL);
77 ++ setlocale(LC_NUMERIC, "C");
78 ++ ret = fprintf(ply->fp, "%g ", value);
79 ++ setlocale(LC_NUMERIC, curr_locale);
80 ++ return ret > 0;
81 + }
82 +
83 + static int obinary_int8(p_ply ply, double value) {
84 +@@ -1336,17 +1351,25 @@ static int iascii_uint32(p_ply ply, double *value) {
85 + }
86 +
87 + static int iascii_float32(p_ply ply, double *value) {
88 +- char *end;
89 ++ char *end, *curr_locale;
90 + if (!ply_read_word(ply)) return 0;
91 ++ /* Switch locale to C to use '.' as the decimal point separator */
92 ++ curr_locale = setlocale(LC_NUMERIC, NULL);
93 ++ setlocale(LC_NUMERIC, "C");
94 + *value = strtod(BWORD(ply), &end);
95 ++ setlocale(LC_NUMERIC, curr_locale);
96 + if (*end || *value < -FLT_MAX || *value > FLT_MAX) return 0;
97 + return 1;
98 + }
99 +
100 + static int iascii_float64(p_ply ply, double *value) {
101 +- char *end;
102 ++ char *end, *curr_locale;
103 + if (!ply_read_word(ply)) return 0;
104 ++ /* Switch locale to C to use '.' as the decimal point separator */
105 ++ curr_locale = setlocale(LC_NUMERIC, NULL);
106 ++ setlocale(LC_NUMERIC, "C");
107 + *value = strtod(BWORD(ply), &end);
108 ++ setlocale(LC_NUMERIC, curr_locale);
109 + if (*end || *value < -DBL_MAX || *value > DBL_MAX) return 0;
110 + return 1;
111 + }
112 +--
113 +1.7.6.1
114 +
115
116 diff --git a/media-libs/rply/files/rply-1.01-stdint.h.patch b/media-libs/rply/files/rply-1.01-stdint.h.patch
117 new file mode 100644
118 index 0000000..45c9116
119 --- /dev/null
120 +++ b/media-libs/rply/files/rply-1.01-stdint.h.patch
121 @@ -0,0 +1,185 @@
122 +From eeb09032068baed6d81cff01cdfcccd6d55a8152 Mon Sep 17 00:00:00 2001
123 +From: Alexandre Rostovtsev <tetromino@×××××.com>
124 +Date: Mon, 26 Sep 2011 04:45:49 -0400
125 +Subject: [PATCH 1/2] Use stdint.h types
126 +
127 +Use stdint.h types (int16_t and int32_t) instead of assuming that short
128 +and long must always a specific number of bytes. Also, use strtoul for
129 +reading uint32_t values.
130 +---
131 + rply.c | 61 ++++++++++++++++++++++++++++---------------------------------
132 + 1 files changed, 28 insertions(+), 33 deletions(-)
133 +
134 +diff --git a/rply.c b/rply.c
135 +index 042244f..9eaa77f 100644
136 +--- a/rply.c
137 ++++ b/rply.c
138 +@@ -15,6 +15,7 @@
139 + #include <stdarg.h>
140 + #include <stdlib.h>
141 + #include <stddef.h>
142 ++#include <stdint.h>
143 +
144 + #include "rply.h"
145 +
146 +@@ -1183,18 +1184,12 @@ static e_ply_storage_mode ply_arch_endian(void) {
147 + static int ply_type_check(void) {
148 + assert(sizeof(char) == 1);
149 + assert(sizeof(unsigned char) == 1);
150 +- assert(sizeof(short) == 2);
151 +- assert(sizeof(unsigned short) == 2);
152 +- assert(sizeof(long) == 4);
153 +- assert(sizeof(unsigned long) == 4);
154 ++ assert(sizeof(long) >= 4);
155 + assert(sizeof(float) == 4);
156 + assert(sizeof(double) == 8);
157 + if (sizeof(char) != 1) return 0;
158 + if (sizeof(unsigned char) != 1) return 0;
159 +- if (sizeof(short) != 2) return 0;
160 +- if (sizeof(unsigned short) != 2) return 0;
161 +- if (sizeof(long) != 4) return 0;
162 +- if (sizeof(unsigned long) != 4) return 0;
163 ++ if (sizeof(long) < 4) return 0;
164 + if (sizeof(float) != 4) return 0;
165 + if (sizeof(double) != 8) return 0;
166 + return 1;
167 +@@ -1214,23 +1209,23 @@ static int oascii_uint8(p_ply ply, double value) {
168 + }
169 +
170 + static int oascii_int16(p_ply ply, double value) {
171 +- if (value > SHRT_MAX || value < SHRT_MIN) return 0;
172 +- return fprintf(ply->fp, "%d ", (short) value) > 0;
173 ++ if (value > INT16_MAX || value < INT16_MIN) return 0;
174 ++ return fprintf(ply->fp, "%d ", (int16_t) value) > 0;
175 + }
176 +
177 + static int oascii_uint16(p_ply ply, double value) {
178 +- if (value > USHRT_MAX || value < 0) return 0;
179 +- return fprintf(ply->fp, "%d ", (unsigned short) value) > 0;
180 ++ if (value > UINT16_MAX || value < 0) return 0;
181 ++ return fprintf(ply->fp, "%d ", (uint16_t) value) > 0;
182 + }
183 +
184 + static int oascii_int32(p_ply ply, double value) {
185 +- if (value > LONG_MAX || value < LONG_MIN) return 0;
186 +- return fprintf(ply->fp, "%d ", (int) value) > 0;
187 ++ if (value > INT32_MAX || value < INT32_MIN) return 0;
188 ++ return fprintf(ply->fp, "%d ", (int32_t) value) > 0;
189 + }
190 +
191 + static int oascii_uint32(p_ply ply, double value) {
192 +- if (value > ULONG_MAX || value < 0) return 0;
193 +- return fprintf(ply->fp, "%d ", (unsigned int) value) > 0;
194 ++ if (value > UINT32_MAX || value < 0) return 0;
195 ++ return fprintf(ply->fp, "%d ", (uint32_t) value) > 0;
196 + }
197 +
198 + static int oascii_float32(p_ply ply, double value) {
199 +@@ -1256,26 +1251,26 @@ static int obinary_uint8(p_ply ply, double value) {
200 + }
201 +
202 + static int obinary_int16(p_ply ply, double value) {
203 +- short int16 = (short) value;
204 +- if (value > SHRT_MAX || value < SHRT_MIN) return 0;
205 ++ int16_t int16 = value;
206 ++ if (value > INT16_MAX || value < INT16_MIN) return 0;
207 + return ply->odriver->ochunk(ply, &int16, sizeof(int16));
208 + }
209 +
210 + static int obinary_uint16(p_ply ply, double value) {
211 +- unsigned short uint16 = (unsigned short) value;
212 +- if (value > USHRT_MAX || value < 0) return 0;
213 ++ uint16_t uint16 = value;
214 ++ if (value > UINT16_MAX || value < 0) return 0;
215 + return ply->odriver->ochunk(ply, &uint16, sizeof(uint16));
216 + }
217 +
218 + static int obinary_int32(p_ply ply, double value) {
219 +- long int32 = (long) value;
220 +- if (value > LONG_MAX || value < LONG_MIN) return 0;
221 ++ int32_t int32 = value;
222 ++ if (value > INT32_MAX || value < INT32_MIN) return 0;
223 + return ply->odriver->ochunk(ply, &int32, sizeof(int32));
224 + }
225 +
226 + static int obinary_uint32(p_ply ply, double value) {
227 +- unsigned long uint32 = (unsigned long) value;
228 +- if (value > ULONG_MAX || value < 0) return 0;
229 ++ uint32_t uint32 = value;
230 ++ if (value > UINT32_MAX || value < 0) return 0;
231 + return ply->odriver->ochunk(ply, &uint32, sizeof(uint32));
232 + }
233 +
234 +@@ -1312,7 +1307,7 @@ static int iascii_int16(p_ply ply, double *value) {
235 + char *end;
236 + if (!ply_read_word(ply)) return 0;
237 + *value = strtol(BWORD(ply), &end, 10);
238 +- if (*end || *value > SHRT_MAX || *value < SHRT_MIN) return 0;
239 ++ if (*end || *value > INT16_MAX || *value < INT16_MIN) return 0;
240 + return 1;
241 + }
242 +
243 +@@ -1320,7 +1315,7 @@ static int iascii_uint16(p_ply ply, double *value) {
244 + char *end;
245 + if (!ply_read_word(ply)) return 0;
246 + *value = strtol(BWORD(ply), &end, 10);
247 +- if (*end || *value > USHRT_MAX || *value < 0) return 0;
248 ++ if (*end || *value > UINT16_MAX || *value < 0) return 0;
249 + return 1;
250 + }
251 +
252 +@@ -1328,15 +1323,15 @@ static int iascii_int32(p_ply ply, double *value) {
253 + char *end;
254 + if (!ply_read_word(ply)) return 0;
255 + *value = strtol(BWORD(ply), &end, 10);
256 +- if (*end || *value > LONG_MAX || *value < LONG_MIN) return 0;
257 ++ if (*end || *value > INT32_MAX || *value < INT32_MIN) return 0;
258 + return 1;
259 + }
260 +
261 + static int iascii_uint32(p_ply ply, double *value) {
262 + char *end;
263 + if (!ply_read_word(ply)) return 0;
264 +- *value = strtol(BWORD(ply), &end, 10);
265 +- if (*end || *value < 0) return 0;
266 ++ *value = strtoul(BWORD(ply), &end, 10);
267 ++ if (*end || *value > UINT32_MAX || *value < 0) return 0;
268 + return 1;
269 + }
270 +
271 +@@ -1371,28 +1366,28 @@ static int ibinary_uint8(p_ply ply, double *value) {
272 + }
273 +
274 + static int ibinary_int16(p_ply ply, double *value) {
275 +- short int16;
276 ++ int16_t int16;
277 + if (!ply->idriver->ichunk(ply, &int16, sizeof(int16))) return 0;
278 + *value = int16;
279 + return 1;
280 + }
281 +
282 + static int ibinary_uint16(p_ply ply, double *value) {
283 +- unsigned short uint16;
284 ++ uint16_t uint16;
285 + if (!ply->idriver->ichunk(ply, &uint16, sizeof(uint16))) return 0;
286 + *value = uint16;
287 + return 1;
288 + }
289 +
290 + static int ibinary_int32(p_ply ply, double *value) {
291 +- long int32;
292 ++ int32_t int32;
293 + if (!ply->idriver->ichunk(ply, &int32, sizeof(int32))) return 0;
294 + *value = int32;
295 + return 1;
296 + }
297 +
298 + static int ibinary_uint32(p_ply ply, double *value) {
299 +- unsigned long uint32;
300 ++ uint32_t uint32;
301 + if (!ply->idriver->ichunk(ply, &uint32, sizeof(uint32))) return 0;
302 + *value = uint32;
303 + return 1;
304 +--
305 +1.7.6.1
306 +
307
308 diff --git a/media-libs/rply/rply-1.01.ebuild b/media-libs/rply/rply-1.01-r1.ebuild
309 similarity index 74%
310 rename from media-libs/rply/rply-1.01.ebuild
311 rename to media-libs/rply/rply-1.01-r1.ebuild
312 index 8c9bdd4..d776145 100644
313 --- a/media-libs/rply/rply-1.01.ebuild
314 +++ b/media-libs/rply/rply-1.01-r1.ebuild
315 @@ -27,4 +27,10 @@ src_prepare() {
316 # For simplicity, use the cmake file that Fedora maintainers have created
317 cp "${FILESDIR}/rply_CMakeLists.txt" CMakeLists.txt
318 mkdir -p CMake/export
319 +
320 + # Use int16_t and int32_t instead of assuming e.g. that sizeof(long) == 4
321 + epatch "${FILESDIR}/${P}-stdint.h.patch"
322 +
323 + # Switch LC_NUMERIC locale to "C" to ensure "." is the decimal separator
324 + epatch "${FILESDIR}/${P}-lc_numeric.patch"
325 }