Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
d173b366
Commit
d173b366
authored
Apr 10, 2001
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged Tim's fixes to cross-platform handling of binary integers.
parent
f7b9f3b2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
9 deletions
+32
-9
lib/Components/cPickle/cPickle.c
lib/Components/cPickle/cPickle.c
+32
-9
No files found.
lib/Components/cPickle/cPickle.c
View file @
d173b366
/*
* $Id: cPickle.c,v 1.7
2 2000/05/09 18:05:09
jim Exp $
* $Id: cPickle.c,v 1.7
3 2001/04/10 16:55:33
jim Exp $
*
* Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
* All rights reserved.
...
...
@@ -49,7 +49,7 @@
static
char
cPickle_module_documentation
[]
=
"C implementation and optimization of the Python pickle module
\n
"
"
\n
"
"$Id: cPickle.c,v 1.7
2 2000/05/09 18:05:09
jim Exp $
\n
"
"$Id: cPickle.c,v 1.7
3 2001/04/10 16:55:33
jim Exp $
\n
"
;
#include "Python.h"
...
...
@@ -69,6 +69,20 @@ static char cPickle_module_documentation[] =
#define WRITE_BUF_SIZE 256
/* --------------------------------------------------------------------------
NOTES on format codes.
XXX much more is needed here
Integer types
BININT1 8-bit unsigned integer; followed by 1 byte.
BININT2 16-bit unsigned integer; followed by 2 bytes, little-endian.
BININT 32-bit signed integer; followed by 4 bytes, little-endian.
INT Integer; natural decimal string conversion, then newline.
CAUTION: INT-reading code can't assume that what follows
fits in a Python int, because the size of Python ints varies
across platforms.
LONG Long (unbounded) integer; repr(i), then newline.
-------------------------------------------------------------------------- */
#define MARK '('
#define STOP '.'
...
...
@@ -905,18 +919,20 @@ save_int(Picklerobject *self, PyObject *args) {
if
(
!
self
->
bin
#if SIZEOF_LONG > 4
||
(
l
>>
32
)
||
l
>
0x7fffffffL
||
l
<
-
0x80000000L
#endif
)
{
/* Save extra-long ints in non-binary mode, so that
we can use python long parsing code to restore,
if necessary.
*/
/* Text-mode pickle, or long too big to fit in the 4-byte
* signed BININT format: store as a string.
*/
c_str
[
0
]
=
INT
;
sprintf
(
c_str
+
1
,
"%ld
\n
"
,
l
);
if
((
*
self
->
write_func
)(
self
,
c_str
,
strlen
(
c_str
))
<
0
)
return
-
1
;
}
else
{
/* Binary pickle and l fits in a signed 4-byte int. */
c_str
[
1
]
=
(
int
)(
l
&
0xff
);
c_str
[
2
]
=
(
int
)((
l
>>
8
)
&
0xff
);
c_str
[
3
]
=
(
int
)((
l
>>
16
)
&
0xff
);
...
...
@@ -2401,7 +2417,14 @@ calc_binint(char *s, int x) {
c
=
(
unsigned
char
)
s
[
i
];
l
|=
(
long
)
c
<<
(
i
*
8
);
}
#if SIZEOF_LONG > 4
/* Unlike BININT1 and BININT2, BININT (more accurately BININT4)
* is signed, so on a box with longs bigger than 4 bytes we need
* to extend a BININT's sign bit to the full width.
*/
if
(
x
==
4
&&
l
&
(
1L
<<
31
))
l
|=
(
~
0L
)
<<
32
;
#endif
return
l
;
}
...
...
@@ -4382,7 +4405,7 @@ init_stuff(PyObject *module, PyObject *module_dict) {
DL_EXPORT
(
void
)
initcPickle
()
{
PyObject
*
m
,
*
d
,
*
v
;
char
*
rev
=
"$Revision: 1.7
2
$"
;
char
*
rev
=
"$Revision: 1.7
3
$"
;
PyObject
*
format_version
;
PyObject
*
compatible_formats
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment