| 39871 |
ripley |
1 |
The changes for R are all to do with portability:
|
|
|
2 |
|
| 41626 |
ripley |
3 |
__inline__ is not portable. We make use of static inlining in the
|
|
|
4 |
file bzlib.c and decompress.c to avoid issues with semantics of
|
|
|
5 |
'extern inline'.
|
|
|
6 |
|
| 39871 |
ripley |
7 |
fdopen is POSIX but not C89
|
|
|
8 |
Solaris' cc objects to inlining functions with names starting with 'main'.
|
| 41464 |
ripley |
9 |
C character strings are limited to ca 500 chars.
|
|
|
10 |
Various casts were missing.
|
| 39871 |
ripley |
11 |
|
| 41464 |
ripley |
12 |
*** further changes made in November 2006 were not documented ***
|
|
|
13 |
|
|
|
14 |
diff -u bzip2-1.0.4/blocksort.c bzip2/blocksort.c
|
|
|
15 |
--- bzip2-1.0.4/blocksort.c 2007-01-03 02:00:55.000000000 +0000
|
|
|
16 |
+++ bzip2/blocksort.c 2007-05-07 12:56:52.000000000 +0100
|
|
|
17 |
@@ -28,7 +28,7 @@
|
| 39871 |
ripley |
18 |
|
|
|
19 |
/*---------------------------------------------*/
|
|
|
20 |
static
|
|
|
21 |
-__inline__
|
|
|
22 |
+R_INLINE
|
|
|
23 |
void fallbackSimpleSort ( UInt32* fmap,
|
|
|
24 |
UInt32* eclass,
|
|
|
25 |
Int32 lo,
|
| 41464 |
ripley |
26 |
@@ -342,9 +342,10 @@
|
| 39871 |
ripley |
27 |
/*---------------------------------------------*/
|
|
|
28 |
|
|
|
29 |
/*---------------------------------------------*/
|
|
|
30 |
+/* Solaris cc objects to inlining functions whose names start with `main' */
|
|
|
31 |
static
|
|
|
32 |
-__inline__
|
|
|
33 |
-Bool mainGtU ( UInt32 i1,
|
|
|
34 |
+R_INLINE
|
|
|
35 |
+Bool BZmainGtU ( UInt32 i1,
|
|
|
36 |
UInt32 i2,
|
|
|
37 |
UChar* block,
|
|
|
38 |
UInt16* quadrant,
|
| 41464 |
ripley |
39 |
@@ -355,7 +356,7 @@
|
| 39871 |
ripley |
40 |
UChar c1, c2;
|
|
|
41 |
UInt16 s1, s2;
|
|
|
42 |
|
|
|
43 |
- AssertD ( i1 != i2, "mainGtU" );
|
|
|
44 |
+ AssertD ( i1 != i2, "BZmainGtU" );
|
|
|
45 |
/* 1 */
|
|
|
46 |
c1 = block[i1]; c2 = block[i2];
|
|
|
47 |
if (c1 != c2) return (c1 > c2);
|
| 41464 |
ripley |
48 |
@@ -511,7 +512,7 @@
|
| 39871 |
ripley |
49 |
if (i > hi) break;
|
|
|
50 |
v = ptr[i];
|
|
|
51 |
j = i;
|
|
|
52 |
- while ( mainGtU (
|
|
|
53 |
+ while ( BZmainGtU (
|
|
|
54 |
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
|
|
55 |
) ) {
|
|
|
56 |
ptr[j] = ptr[j-h];
|
| 41464 |
ripley |
57 |
@@ -525,7 +526,7 @@
|
| 39871 |
ripley |
58 |
if (i > hi) break;
|
|
|
59 |
v = ptr[i];
|
|
|
60 |
j = i;
|
|
|
61 |
- while ( mainGtU (
|
|
|
62 |
+ while ( BZmainGtU (
|
|
|
63 |
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
|
|
64 |
) ) {
|
|
|
65 |
ptr[j] = ptr[j-h];
|
| 41464 |
ripley |
66 |
@@ -539,7 +540,7 @@
|
| 39871 |
ripley |
67 |
if (i > hi) break;
|
|
|
68 |
v = ptr[i];
|
|
|
69 |
j = i;
|
|
|
70 |
- while ( mainGtU (
|
|
|
71 |
+ while ( BZmainGtU (
|
|
|
72 |
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
|
|
73 |
) ) {
|
|
|
74 |
ptr[j] = ptr[j-h];
|
| 41464 |
ripley |
75 |
@@ -579,7 +580,7 @@
|
| 39871 |
ripley |
76 |
}
|
|
|
77 |
|
|
|
78 |
static
|
|
|
79 |
-__inline__
|
|
|
80 |
+R_INLINE
|
|
|
81 |
UChar mmed3 ( UChar a, UChar b, UChar c )
|
|
|
82 |
{
|
|
|
83 |
UChar t;
|
| 41464 |
ripley |
84 |
diff -u bzip2-1.0.4/bzlib.c bzip2/bzlib.c
|
|
|
85 |
--- bzip2-1.0.4/bzlib.c 2007-01-03 02:00:55.000000000 +0000
|
|
|
86 |
+++ bzip2/bzlib.c 2007-05-07 12:56:52.000000000 +0100
|
|
|
87 |
@@ -53,8 +53,9 @@
|
| 39871 |
ripley |
88 |
BZ2_bzlibVersion()
|
|
|
89 |
);
|
|
|
90 |
|
|
|
91 |
+ /* split up over-long message */
|
|
|
92 |
if (errcode == 1007) {
|
|
|
93 |
- fprintf(stderr,
|
|
|
94 |
+ fprintf(stderr, "%s%s%s",
|
|
|
95 |
"\n*** A special note about internal error number 1007 ***\n"
|
|
|
96 |
"\n"
|
|
|
97 |
"Experience suggests that a common cause of i.e. 1007\n"
|
| 41464 |
ripley |
98 |
@@ -62,7 +63,7 @@
|
| 39871 |
ripley |
99 |
"just happens to cross-check the results of huge numbers of\n"
|
|
|
100 |
"memory reads/writes, and so acts (unintendedly) as a stress\n"
|
|
|
101 |
"test of your memory system.\n"
|
|
|
102 |
- "\n"
|
|
|
103 |
+ "\n",
|
|
|
104 |
"I suggest the following: try compressing the file again,\n"
|
|
|
105 |
"possibly monitoring progress in detail with the -vv flag.\n"
|
|
|
106 |
"\n"
|
| 41464 |
ripley |
107 |
@@ -72,7 +73,7 @@
|
| 39871 |
ripley |
108 |
" (www.memtest86.com). At the time of writing it is free (GPLd).\n"
|
|
|
109 |
" Memtest86 tests memory much more thorougly than your BIOSs\n"
|
|
|
110 |
" power-on test, and may find failures that the BIOS doesn't.\n"
|
|
|
111 |
- "\n"
|
|
|
112 |
+ "\n",
|
|
|
113 |
"* If the error can be repeatably reproduced, this is a bug in\n"
|
|
|
114 |
" bzip2, and I would very much like to hear about it. Please\n"
|
|
|
115 |
" let me know, and, ideally, save a copy of the file causing the\n"
|
| 41464 |
ripley |
116 |
@@ -165,7 +166,7 @@
|
|
|
117 |
if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
|
|
|
118 |
if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
|
| 39871 |
ripley |
119 |
|
| 41464 |
ripley |
120 |
- s = BZALLOC( sizeof(EState) );
|
|
|
121 |
+ s = (EState *) BZALLOC( sizeof(EState) );
|
|
|
122 |
if (s == NULL) return BZ_MEM_ERROR;
|
|
|
123 |
s->strm = strm;
|
| 39871 |
ripley |
124 |
|
| 41464 |
ripley |
125 |
@@ -174,9 +175,9 @@
|
|
|
126 |
s->ftab = NULL;
|
|
|
127 |
|
|
|
128 |
n = 100000 * blockSize100k;
|
|
|
129 |
- s->arr1 = BZALLOC( n * sizeof(UInt32) );
|
|
|
130 |
- s->arr2 = BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
|
|
|
131 |
- s->ftab = BZALLOC( 65537 * sizeof(UInt32) );
|
|
|
132 |
+ s->arr1 = (UInt32 *) BZALLOC( n * sizeof(UInt32) );
|
|
|
133 |
+ s->arr2 = (UInt32 *) BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
|
|
|
134 |
+ s->ftab = (UInt32 *) BZALLOC( 65537 * sizeof(UInt32) );
|
|
|
135 |
|
|
|
136 |
if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) {
|
|
|
137 |
if (s->arr1 != NULL) BZFREE(s->arr1);
|
|
|
138 |
@@ -362,7 +363,7 @@
|
|
|
139 |
{
|
|
|
140 |
Bool progress_in = False;
|
|
|
141 |
Bool progress_out = False;
|
|
|
142 |
- EState* s = strm->state;
|
|
|
143 |
+ EState* s = (EState *) strm->state;
|
|
|
144 |
|
|
|
145 |
while (True) {
|
|
|
146 |
|
|
|
147 |
@@ -409,7 +410,7 @@
|
|
|
148 |
Bool progress;
|
|
|
149 |
EState* s;
|
|
|
150 |
if (strm == NULL) return BZ_PARAM_ERROR;
|
|
|
151 |
- s = strm->state;
|
|
|
152 |
+ s = (EState *) strm->state;
|
|
|
153 |
if (s == NULL) return BZ_PARAM_ERROR;
|
|
|
154 |
if (s->strm != strm) return BZ_PARAM_ERROR;
|
|
|
155 |
|
|
|
156 |
@@ -469,7 +470,7 @@
|
|
|
157 |
{
|
|
|
158 |
EState* s;
|
|
|
159 |
if (strm == NULL) return BZ_PARAM_ERROR;
|
|
|
160 |
- s = strm->state;
|
|
|
161 |
+ s = (EState *) strm->state;
|
|
|
162 |
if (s == NULL) return BZ_PARAM_ERROR;
|
|
|
163 |
if (s->strm != strm) return BZ_PARAM_ERROR;
|
|
|
164 |
|
|
|
165 |
@@ -505,7 +506,7 @@
|
|
|
166 |
if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
|
|
|
167 |
if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
|
|
|
168 |
|
|
|
169 |
- s = BZALLOC( sizeof(DState) );
|
|
|
170 |
+ s = (DState *) BZALLOC( sizeof(DState) );
|
|
|
171 |
if (s == NULL) return BZ_MEM_ERROR;
|
|
|
172 |
s->strm = strm;
|
|
|
173 |
strm->state = s;
|
|
|
174 |
@@ -683,7 +684,10 @@
|
|
|
175 |
|
|
|
176 |
|
| 39871 |
ripley |
177 |
/*---------------------------------------------------*/
|
|
|
178 |
-__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
|
| 41464 |
ripley |
179 |
+#ifndef __cplusplus
|
|
|
180 |
+R_INLINE
|
|
|
181 |
+#endif
|
|
|
182 |
+Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
|
| 39871 |
ripley |
183 |
{
|
|
|
184 |
Int32 nb, na, mid;
|
|
|
185 |
nb = 0;
|
| 41464 |
ripley |
186 |
@@ -809,7 +813,7 @@
|
|
|
187 |
Bool corrupt;
|
|
|
188 |
DState* s;
|
|
|
189 |
if (strm == NULL) return BZ_PARAM_ERROR;
|
|
|
190 |
- s = strm->state;
|
|
|
191 |
+ s = (DState *) strm->state;
|
|
|
192 |
if (s == NULL) return BZ_PARAM_ERROR;
|
|
|
193 |
if (s->strm != strm) return BZ_PARAM_ERROR;
|
|
|
194 |
|
|
|
195 |
@@ -862,7 +866,7 @@
|
|
|
196 |
{
|
|
|
197 |
DState* s;
|
|
|
198 |
if (strm == NULL) return BZ_PARAM_ERROR;
|
|
|
199 |
- s = strm->state;
|
|
|
200 |
+ s = (DState *) strm->state;
|
|
|
201 |
if (s == NULL) return BZ_PARAM_ERROR;
|
|
|
202 |
if (s->strm != strm) return BZ_PARAM_ERROR;
|
|
|
203 |
|
|
|
204 |
@@ -933,7 +937,7 @@
|
|
|
205 |
if (ferror(f))
|
|
|
206 |
{ BZ_SETERR(BZ_IO_ERROR); return NULL; };
|
|
|
207 |
|
|
|
208 |
- bzf = malloc ( sizeof(bzFile) );
|
|
|
209 |
+ bzf = (bzFile *) malloc ( sizeof(bzFile) );
|
|
|
210 |
if (bzf == NULL)
|
|
|
211 |
{ BZ_SETERR(BZ_MEM_ERROR); return NULL; };
|
|
|
212 |
|
|
|
213 |
@@ -981,7 +985,7 @@
|
|
|
214 |
{ BZ_SETERR(BZ_OK); return; };
|
|
|
215 |
|
|
|
216 |
bzf->strm.avail_in = len;
|
|
|
217 |
- bzf->strm.next_in = buf;
|
|
|
218 |
+ bzf->strm.next_in = (char *) buf;
|
|
|
219 |
|
|
|
220 |
while (True) {
|
|
|
221 |
bzf->strm.avail_out = BZ_MAX_UNUSED;
|
|
|
222 |
@@ -1106,7 +1110,7 @@
|
|
|
223 |
if (ferror(f))
|
|
|
224 |
{ BZ_SETERR(BZ_IO_ERROR); return NULL; };
|
|
|
225 |
|
|
|
226 |
- bzf = malloc ( sizeof(bzFile) );
|
|
|
227 |
+ bzf = (bzFile *) malloc ( sizeof(bzFile) );
|
|
|
228 |
if (bzf == NULL)
|
|
|
229 |
{ BZ_SETERR(BZ_MEM_ERROR); return NULL; };
|
|
|
230 |
|
|
|
231 |
@@ -1178,7 +1182,7 @@
|
|
|
232 |
{ BZ_SETERR(BZ_OK); return 0; };
|
|
|
233 |
|
|
|
234 |
bzf->strm.avail_out = len;
|
|
|
235 |
- bzf->strm.next_out = buf;
|
|
|
236 |
+ bzf->strm.next_out = (char *) buf;
|
|
|
237 |
|
|
|
238 |
while (True) {
|
|
|
239 |
|
|
|
240 |
@@ -1378,6 +1382,15 @@
|
| 39871 |
ripley |
241 |
#else
|
|
|
242 |
# define SET_BINARY_MODE(file)
|
|
|
243 |
#endif
|
|
|
244 |
+
|
|
|
245 |
+#if !defined(fdopen) && defined(HAVE_FDOPEN)
|
| 41464 |
ripley |
246 |
+ FILE *fdopen(int fildes, const char *mode)
|
|
|
247 |
+#ifdef __cplusplus
|
|
|
248 |
+ throw ()
|
| 39871 |
ripley |
249 |
+#endif
|
| 41464 |
ripley |
250 |
+ ;
|
|
|
251 |
+#endif
|
| 39871 |
ripley |
252 |
+
|
|
|
253 |
static
|
|
|
254 |
BZFILE * bzopen_or_bzdopen
|
|
|
255 |
( const char *path, /* no use when bzdopen */
|
| 41464 |
ripley |
256 |
@@ -1424,7 +1437,7 @@
|
| 39871 |
ripley |
257 |
fp = fopen(path,mode2);
|
|
|
258 |
}
|
|
|
259 |
} else {
|
|
|
260 |
-#ifdef BZ_STRICT_ANSI
|
|
|
261 |
+#ifndef HAVE_FDOPEN
|
|
|
262 |
fp = NULL;
|
|
|
263 |
#else
|
|
|
264 |
fp = fdopen(fd,mode2);
|
| 41464 |
ripley |
265 |
@@ -1513,10 +1526,9 @@
|
|
|
266 |
void BZ_API(BZ2_bzclose) (BZFILE* b)
|
|
|
267 |
{
|
|
|
268 |
int bzerr;
|
|
|
269 |
- FILE *fp;
|
|
|
270 |
+ FILE *fp = ((bzFile *)b)->handle;
|
|
|
271 |
|
|
|
272 |
if (b==NULL) {return;}
|
|
|
273 |
- fp = ((bzFile *)b)->handle;
|
|
|
274 |
if(((bzFile*)b)->writing){
|
|
|
275 |
BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
|
|
|
276 |
if(bzerr != BZ_OK){
|
|
|
277 |
diff -u bzip2-1.0.4/bzlib_private.h bzip2/bzlib_private.h
|
|
|
278 |
--- bzip2-1.0.4/bzlib_private.h 2007-01-03 02:00:55.000000000 +0000
|
|
|
279 |
+++ bzip2/bzlib_private.h 2007-05-07 12:56:51.000000000 +0100
|
|
|
280 |
@@ -22,6 +22,7 @@
|
| 39871 |
ripley |
281 |
#ifndef _BZLIB_PRIVATE_H
|
|
|
282 |
#define _BZLIB_PRIVATE_H
|
|
|
283 |
|
|
|
284 |
+#include <config.h> /* for R_INLINE */
|
|
|
285 |
#include <stdlib.h>
|
|
|
286 |
|
|
|
287 |
#ifndef BZ_NO_STDIO
|
| 41464 |
ripley |
288 |
diff -u bzip2-1.0.4/compress.c bzip2/compress.c
|
|
|
289 |
--- bzip2-1.0.4/compress.c 2007-01-03 02:00:55.000000000 +0000
|
|
|
290 |
+++ bzip2/compress.c 2007-05-07 12:56:50.000000000 +0100
|
|
|
291 |
@@ -69,7 +69,7 @@
|
| 39871 |
ripley |
292 |
|
|
|
293 |
/*---------------------------------------------------*/
|
|
|
294 |
static
|
|
|
295 |
-__inline__
|
|
|
296 |
+R_INLINE
|
|
|
297 |
void bsW ( EState* s, Int32 n, UInt32 v )
|
|
|
298 |
{
|
|
|
299 |
bsNEEDW ( n );
|
| 41464 |
ripley |
300 |
diff -u bzip2-1.0.4/decompress.c bzip2/decompress.c
|
|
|
301 |
--- bzip2-1.0.4/decompress.c 2007-01-03 02:00:55.000000000 +0000
|
|
|
302 |
+++ bzip2/decompress.c 2007-05-07 12:56:50.000000000 +0100
|
|
|
303 |
@@ -209,13 +209,13 @@
|
|
|
304 |
s->blockSize100k -= BZ_HDR_0;
|
|
|
305 |
|
|
|
306 |
if (s->smallDecompress) {
|
|
|
307 |
- s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
|
|
|
308 |
- s->ll4 = BZALLOC(
|
|
|
309 |
- ((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
|
|
|
310 |
- );
|
|
|
311 |
+ s->ll16 = (UInt16*) BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
|
|
|
312 |
+ s->ll4 = (UChar *) BZALLOC(
|
|
|
313 |
+ ((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
|
|
|
314 |
+ );
|
|
|
315 |
if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
|
|
|
316 |
} else {
|
|
|
317 |
- s->tt = BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
|
|
|
318 |
+ s->tt = (UInt32 *) BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
|
|
|
319 |
if (s->tt == NULL) RETURN(BZ_MEM_ERROR);
|
|
|
320 |
}
|
|
|
321 |
|