Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6269fec1
Commit
6269fec1
authored
Jan 01, 2009
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4228: Pack negative values the same way as 2.4
in struct's L format.
parent
775c3070
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
6 deletions
+15
-6
Lib/test/test_struct.py
Lib/test/test_struct.py
+7
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_struct.c
Modules/_struct.c
+6
-6
No files found.
Lib/test/test_struct.py
View file @
6269fec1
...
@@ -2,6 +2,8 @@ import array
...
@@ -2,6 +2,8 @@ import array
import
unittest
import
unittest
import
struct
import
struct
import
warnings
import
warnings
warnings
.
filterwarnings
(
"ignore"
,
"struct integer overflow masking is deprecated"
,
DeprecationWarning
)
from
functools
import
wraps
from
functools
import
wraps
from
test.test_support
import
TestFailed
,
verbose
,
run_unittest
from
test.test_support
import
TestFailed
,
verbose
,
run_unittest
...
@@ -461,6 +463,11 @@ class StructTest(unittest.TestCase):
...
@@ -461,6 +463,11 @@ class StructTest(unittest.TestCase):
self
.
check_float_coerce
(
endian
+
fmt
,
1.0
)
self
.
check_float_coerce
(
endian
+
fmt
,
1.0
)
self
.
check_float_coerce
(
endian
+
fmt
,
1.5
)
self
.
check_float_coerce
(
endian
+
fmt
,
1.5
)
def
test_issue4228
(
self
):
# Packing a long may yield either 32 or 64 bits
x
=
struct
.
pack
(
'L'
,
-
1
)[:
4
]
self
.
assertEqual
(
x
,
'
\
xff
'
*
4
)
def
test_unpack_from
(
self
):
def
test_unpack_from
(
self
):
test_string
=
'abcd01234'
test_string
=
'abcd01234'
fmt
=
'4s'
fmt
=
'4s'
...
...
Misc/NEWS
View file @
6269fec1
...
@@ -258,6 +258,8 @@ C-API
...
@@ -258,6 +258,8 @@ C-API
Extension Modules
Extension Modules
-----------------
-----------------
- Issue #4228: Pack negative values the same way as 2.4 in struct's L format.
- Issue #1040026: Fix os.times result on systems where HZ is incorrect.
- Issue #1040026: Fix os.times result on systems where HZ is incorrect.
- Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris,
- Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris,
...
...
Modules/_struct.c
View file @
6269fec1
...
@@ -663,7 +663,7 @@ np_int(char *p, PyObject *v, const formatdef *f)
...
@@ -663,7 +663,7 @@ np_int(char *p, PyObject *v, const formatdef *f)
return
-
1
;
return
-
1
;
#if (SIZEOF_LONG > SIZEOF_INT)
#if (SIZEOF_LONG > SIZEOF_INT)
if
((
x
<
((
long
)
INT_MIN
))
||
(
x
>
((
long
)
INT_MAX
)))
if
((
x
<
((
long
)
INT_MIN
))
||
(
x
>
((
long
)
INT_MAX
)))
return
_range_error
(
f
,
0
);
RANGE_ERROR
(
x
,
f
,
0
,
-
1
);
#endif
#endif
y
=
(
int
)
x
;
y
=
(
int
)
x
;
memcpy
(
p
,
(
char
*
)
&
y
,
sizeof
y
);
memcpy
(
p
,
(
char
*
)
&
y
,
sizeof
y
);
...
@@ -675,12 +675,12 @@ np_uint(char *p, PyObject *v, const formatdef *f)
...
@@ -675,12 +675,12 @@ np_uint(char *p, PyObject *v, const formatdef *f)
{
{
unsigned
long
x
;
unsigned
long
x
;
unsigned
int
y
;
unsigned
int
y
;
if
(
get_ulong
(
v
,
&
x
)
<
0
)
if
(
get_
wrapped_
ulong
(
v
,
&
x
)
<
0
)
return
_range_error
(
f
,
1
)
;
return
-
1
;
y
=
(
unsigned
int
)
x
;
y
=
(
unsigned
int
)
x
;
#if (SIZEOF_LONG > SIZEOF_INT)
#if (SIZEOF_LONG > SIZEOF_INT)
if
(
x
>
((
unsigned
long
)
UINT_MAX
))
if
(
x
>
((
unsigned
long
)
UINT_MAX
))
return
_range_error
(
f
,
1
);
RANGE_ERROR
(
y
,
f
,
1
,
-
1
);
#endif
#endif
memcpy
(
p
,
(
char
*
)
&
y
,
sizeof
y
);
memcpy
(
p
,
(
char
*
)
&
y
,
sizeof
y
);
return
0
;
return
0
;
...
@@ -700,8 +700,8 @@ static int
...
@@ -700,8 +700,8 @@ static int
np_ulong
(
char
*
p
,
PyObject
*
v
,
const
formatdef
*
f
)
np_ulong
(
char
*
p
,
PyObject
*
v
,
const
formatdef
*
f
)
{
{
unsigned
long
x
;
unsigned
long
x
;
if
(
get_ulong
(
v
,
&
x
)
<
0
)
if
(
get_
wrapped_
ulong
(
v
,
&
x
)
<
0
)
return
_range_error
(
f
,
1
)
;
return
-
1
;
memcpy
(
p
,
(
char
*
)
&
x
,
sizeof
x
);
memcpy
(
p
,
(
char
*
)
&
x
,
sizeof
x
);
return
0
;
return
0
;
}
}
...
...
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