Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
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
Boxiang Sun
pyodide
Commits
222457c2
Commit
222457c2
authored
Oct 03, 2018
by
Roman Yurchak
Committed by
GitHub
Oct 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #208 from mdboom/long-ints
Handle Python long ints as Javascript floats
parents
95379aa0
b7769908
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
+26
-3
src/python2js.c
src/python2js.c
+17
-3
test/test_python.py
test/test_python.py
+9
-0
No files found.
src/python2js.c
View file @
222457c2
...
@@ -127,10 +127,24 @@ _python2js(PyObject* x, PyObject* map)
...
@@ -127,10 +127,24 @@ _python2js(PyObject* x, PyObject* map)
}
else
if
(
x
==
Py_False
)
{
}
else
if
(
x
==
Py_False
)
{
return
hiwire_false
();
return
hiwire_false
();
}
else
if
(
PyLong_Check
(
x
))
{
}
else
if
(
PyLong_Check
(
x
))
{
long
x_long
=
PyLong_AsLongLong
(
x
);
int
overflow
;
if
(
x_long
==
-
1
&&
PyErr_Occurred
())
{
long
x_long
=
PyLong_AsLongAndOverflow
(
x
,
&
overflow
);
if
(
x_long
==
-
1
)
{
if
(
overflow
)
{
PyObject
*
py_float
=
PyNumber_Float
(
x
);
if
(
py_float
==
NULL
)
{
return
HW_ERROR
;
return
HW_ERROR
;
}
}
double
x_double
=
PyFloat_AsDouble
(
py_float
);
Py_DECREF
(
py_float
);
if
(
x_double
==
-
1
.
0
&&
PyErr_Occurred
())
{
return
HW_ERROR
;
}
return
hiwire_double
(
x_double
);
}
else
if
(
PyErr_Occurred
())
{
return
HW_ERROR
;
}
}
return
hiwire_int
(
x_long
);
return
hiwire_int
(
x_long
);
}
else
if
(
PyFloat_Check
(
x
))
{
}
else
if
(
PyFloat_Check
(
x
))
{
double
x_double
=
PyFloat_AsDouble
(
x
);
double
x_double
=
PyFloat_AsDouble
(
x
);
...
...
test/test_python.py
View file @
222457c2
...
@@ -58,6 +58,15 @@ def test_python2js(selenium):
...
@@ -58,6 +58,15 @@ def test_python2js(selenium):
"""
)
"""
)
def
test_python2js_long_ints
(
selenium
):
assert
selenium
.
run
(
'2**30'
)
==
2
**
30
assert
selenium
.
run
(
'2**31'
)
==
2
**
31
assert
selenium
.
run
(
'2**30 - 1 + 2**30'
)
==
(
2
**
30
-
1
+
2
**
30
)
assert
selenium
.
run
(
'2**32 / 2**4'
)
==
(
2
**
32
/
2
**
4
)
assert
selenium
.
run
(
'-2**30'
)
==
-
2
**
30
assert
selenium
.
run
(
'-2**31'
)
==
-
2
**
31
def
test_pythonexc2js
(
selenium
):
def
test_pythonexc2js
(
selenium
):
try
:
try
:
selenium
.
run_js
(
'return pyodide.runPython("5 / 0")'
)
selenium
.
run_js
(
'return pyodide.runPython("5 / 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