Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1547d9

Browse files
committed
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Tested with AMK's help.
1 parent 1a2c5cb commit c1547d9

1 file changed

Lines changed: 18 additions & 30 deletions

File tree

Python/marshal.c

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,16 @@ w_long(x, p)
127127
w_byte((int)((x>>24) & 0xff), p);
128128
}
129129

130+
#if SIZEOF_LONG > 4
130131
static void
131132
w_long64(x, p)
132133
long x;
133134
WFILE *p;
134135
{
135136
w_long(x, p);
136-
w_byte((int)((x>>32) & 0xff), p);
137-
w_byte((int)((x>>40) & 0xff), p);
138-
w_byte((int)((x>>48) & 0xff), p);
139-
w_byte((int)((x>>56) & 0xff), p);
137+
w_long(x>>32, p);
140138
}
139+
#endif
141140

142141
static void
143142
w_object(v, p)
@@ -154,12 +153,15 @@ w_object(v, p)
154153
w_byte(TYPE_ELLIPSIS, p);
155154
else if (is_intobject(v)) {
156155
long x = GETINTVALUE((intobject *)v);
156+
#if SIZEOF_LONG > 4
157157
long y = x>>31;
158158
if (y && y != -1) {
159159
w_byte(TYPE_INT64, p);
160160
w_long64(x, p);
161161
}
162-
else {
162+
else
163+
#endif
164+
{
163165
w_byte(TYPE_INT, p);
164166
w_long(x, p);
165167
}
@@ -328,9 +330,11 @@ r_long(p)
328330
x |= (long)rs_byte(p) << 16;
329331
x |= (long)rs_byte(p) << 24;
330332
}
333+
#if SIZEOF_LONG > 4
331334
/* Sign extension for 64-bit machines */
332335
x <<= (8*sizeof(long) - 32);
333336
x >>= (8*sizeof(long) - 32);
337+
#endif
334338
return x;
335339
}
336340

@@ -339,35 +343,19 @@ r_long64(p)
339343
RFILE *p;
340344
{
341345
register long x;
342-
register FILE *fp = p->fp;
343-
if (sizeof(long) < 8) {
346+
x = r_long(p);
347+
#if SIZEOF_LONG > 4
348+
x = (x & 0xFFFFFFFF) | (r_long(p) << 32);
349+
#else
350+
if (r_long(p) != 0) {
344351
object *f = sysget("stderr");
345352
err_clear();
346-
if (f != NULL) {
353+
if (f != NULL)
347354
writestring(
348-
"Warning: un-marshal 64-bit int in 32-bit mode\n", f);
349-
}
350-
}
351-
if (fp) {
352-
x = getc(fp);
353-
x |= (long)getc(fp) << 8;
354-
x |= (long)getc(fp) << 16;
355-
x |= (long)getc(fp) << 24;
356-
x |= (long)getc(fp) << 32;
357-
x |= (long)getc(fp) << 40;
358-
x |= (long)getc(fp) << 48;
359-
x |= (long)getc(fp) << 56;
360-
}
361-
else {
362-
x = rs_byte(p);
363-
x |= (long)rs_byte(p) << 8;
364-
x |= (long)rs_byte(p) << 16;
365-
x |= (long)rs_byte(p) << 24;
366-
x |= (long)rs_byte(p) << 32;
367-
x |= (long)rs_byte(p) << 40;
368-
x |= (long)rs_byte(p) << 48;
369-
x |= (long)rs_byte(p) << 56;
355+
"Warning: un-marshal 64-bit int in 32-bit mode\n",
356+
f);
370357
}
358+
#endif
371359
return x;
372360
}
373361

0 commit comments

Comments
 (0)