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
5100171d
Commit
5100171d
authored
Apr 02, 2012
by
Stefan Krah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear the context flags if a context is initialized from the DefaultContext.
parent
41e03100
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+70
-0
Modules/_decimal/_decimal.c
Modules/_decimal/_decimal.c
+8
-0
No files found.
Lib/test/test_decimal.py
View file @
5100171d
...
...
@@ -56,6 +56,76 @@ sys.modules['decimal'] = C
fractions
=
{
C
:
cfractions
,
P
:
pfractions
}
sys
.
modules
[
'decimal'
]
=
orig_sys_decimal
############ RunFirst ############
class
RunFirst
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
save_default
=
self
.
decimal
.
DefaultContext
.
copy
()
def
tearDown
(
self
):
DefaultContext
=
self
.
decimal
.
DefaultContext
DefaultContext
.
prec
=
self
.
save_default
.
prec
DefaultContext
.
rounding
=
self
.
save_default
.
rounding
DefaultContext
.
Emax
=
self
.
save_default
.
Emax
DefaultContext
.
Emin
=
self
.
save_default
.
Emin
DefaultContext
.
capitals
=
self
.
save_default
.
capitals
DefaultContext
.
clamp
=
self
.
save_default
.
clamp
DefaultContext
.
flags
=
self
.
save_default
.
flags
DefaultContext
.
traps
=
self
.
save_default
.
traps
self
.
decimal
.
setcontext
(
self
.
decimal
.
DefaultContext
)
def
test_00default_context
(
self
):
# The test depends on the fact that getcontext() is called
# for the first time.
DefaultContext
=
self
.
decimal
.
DefaultContext
ROUND_05UP
=
self
.
decimal
.
ROUND_05UP
Clamped
=
self
.
decimal
.
Clamped
InvalidOperation
=
self
.
decimal
.
InvalidOperation
DefaultContext
.
prec
=
5001
DefaultContext
.
rounding
=
ROUND_05UP
DefaultContext
.
Emax
=
10025
DefaultContext
.
Emin
=
-
10025
DefaultContext
.
capitals
=
0
DefaultContext
.
clamp
=
1
DefaultContext
.
flags
[
InvalidOperation
]
=
True
DefaultContext
.
clear_traps
()
DefaultContext
.
traps
[
Clamped
]
=
True
# implicit initialization on first access
c
=
self
.
decimal
.
getcontext
()
self
.
assertEqual
(
c
.
prec
,
5001
)
self
.
assertEqual
(
c
.
rounding
,
ROUND_05UP
)
self
.
assertEqual
(
c
.
Emax
,
10025
)
self
.
assertEqual
(
c
.
Emin
,
-
10025
)
self
.
assertEqual
(
c
.
capitals
,
0
)
self
.
assertEqual
(
c
.
clamp
,
1
)
for
k
in
c
.
flags
:
self
.
assertFalse
(
c
.
flags
[
k
])
for
k
in
c
.
traps
:
if
k
is
Clamped
:
self
.
assertTrue
(
c
.
traps
[
k
])
else
:
self
.
assertFalse
(
c
.
traps
[
k
])
# explicit initialization
self
.
decimal
.
setcontext
(
DefaultContext
)
c
=
self
.
decimal
.
getcontext
()
for
k
in
c
.
flags
:
self
.
assertFalse
(
c
.
flags
[
k
])
class
CRunFirst
(
RunFirst
):
decimal
=
C
class
PyRunFirst
(
RunFirst
):
decimal
=
P
if
C
:
run_unittest
(
CRunFirst
,
PyRunFirst
)
else
:
run_unittest
(
PyRunFirst
)
############ END RunFirst ############
# Useful Test Constant
Signals
=
{
...
...
Modules/_decimal/_decimal.c
View file @
5100171d
...
...
@@ -1494,6 +1494,10 @@ current_context(void)
}
*
CTX
(
module_context
)
=
*
CTX
(
default_context_template
);
CTX
(
module_context
)
->
status
=
0
;
CTX
(
module_context
)
->
newtrap
=
0
;
CtxCaps
(
module_context
)
=
CtxCaps
(
default_context_template
);
module_context_set
=
1
;
return
module_context
;
}
...
...
@@ -1533,6 +1537,7 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
if
(
v
==
NULL
)
{
return
NULL
;
}
CTX
(
v
)
->
status
=
0
;
}
else
{
Py_INCREF
(
v
);
...
...
@@ -1581,6 +1586,8 @@ current_context(void)
if
(
tl_context
==
NULL
)
{
return
NULL
;
}
CTX
(
tl_context
)
->
status
=
0
;
if
(
PyDict_SetItem
(
dict
,
tls_context_key
,
tl_context
)
<
0
)
{
Py_DECREF
(
tl_context
);
return
NULL
;
...
...
@@ -1646,6 +1653,7 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
if
(
v
==
NULL
)
{
return
NULL
;
}
CTX
(
v
)
->
status
=
0
;
}
else
{
Py_INCREF
(
v
);
...
...
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