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
dbc0de25
Commit
dbc0de25
authored
Jun 19, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error handling in python2js
parent
27c97fb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
src/python2js.c
src/python2js.c
+21
-14
No files found.
src/python2js.c
View file @
dbc0de25
...
...
@@ -108,8 +108,8 @@ is_type_name(PyObject* x, const char* name)
return
result
;
}
int
python2js
(
PyObject
*
x
)
static
int
python2js
_int
(
PyObject
*
x
)
{
if
(
x
==
Py_None
)
{
return
hiwire_undefined
();
...
...
@@ -120,27 +120,27 @@ python2js(PyObject* x)
}
else
if
(
PyLong_Check
(
x
))
{
long
x_long
=
PyLong_AsLongLong
(
x
);
if
(
x_long
==
-
1
&&
PyErr_Occurred
())
{
return
pythonexc2js
()
;
return
-
1
;
}
return
hiwire_int
(
x_long
);
}
else
if
(
PyFloat_Check
(
x
))
{
double
x_double
=
PyFloat_AsDouble
(
x
);
if
(
x_double
==
-
1
.
0
&&
PyErr_Occurred
())
{
return
pythonexc2js
()
;
return
-
1
;
}
return
hiwire_double
(
x_double
);
}
else
if
(
PyUnicode_Check
(
x
))
{
Py_ssize_t
length
;
char
*
chars
=
PyUnicode_AsUTF8AndSize
(
x
,
&
length
);
if
(
chars
==
NULL
)
{
return
pythonexc2js
()
;
return
-
1
;
}
return
hiwire_string_utf8_length
((
int
)(
void
*
)
chars
,
length
);
}
else
if
(
PyBytes_Check
(
x
))
{
char
*
x_buff
;
Py_ssize_t
length
;
if
(
PyBytes_AsStringAndSize
(
x
,
&
x_buff
,
&
length
))
{
return
pythonexc2js
()
;
return
-
1
;
}
return
hiwire_bytes
((
int
)(
void
*
)
x_buff
,
length
);
}
else
if
(
JsProxy_Check
(
x
))
{
...
...
@@ -158,11 +158,11 @@ python2js(PyObject* x)
Py_INCREF
(
x
);
return
pyproxy_new
((
int
)
x
);
}
int
jsitem
=
python2js
(
pyitem
);
int
jsitem
=
python2js
_int
(
pyitem
);
if
(
jsitem
==
-
1
)
{
Py_DECREF
(
pyitem
);
hiwire_decref
(
jsarray
);
return
pythonexc2js
()
;
return
-
1
;
}
Py_DECREF
(
pyitem
);
hiwire_push_array
(
jsarray
,
jsitem
);
...
...
@@ -174,18 +174,16 @@ python2js(PyObject* x)
PyObject
*
pykey
,
*
pyval
;
Py_ssize_t
pos
=
0
;
while
(
PyDict_Next
(
x
,
&
pos
,
&
pykey
,
&
pyval
))
{
int
jskey
=
python2js
(
pykey
);
int
jskey
=
python2js
_int
(
pykey
);
if
(
jskey
==
-
1
)
{
hiwire_decref
(
jsdict
);
// TODO: Return a proxy instead here???
return
pythonexc2js
();
return
-
1
;
}
int
jsval
=
python2js
(
pyval
);
int
jsval
=
python2js
_int
(
pyval
);
if
(
jsval
==
-
1
)
{
// TODO: Return a proxy instead here???
hiwire_decref
(
jskey
);
hiwire_decref
(
jsdict
);
return
pythonexc2js
()
;
return
-
1
;
}
hiwire_push_object_pair
(
jsdict
,
jskey
,
jsval
);
hiwire_decref
(
jskey
);
...
...
@@ -198,6 +196,15 @@ python2js(PyObject* x)
}
}
int
python2js
(
PyObject
*
x
)
{
int
result
=
python2js_int
(
x
);
if
(
result
==
-
1
)
{
return
pythonexc2js
();
}
return
result
;
}
int
python2js_init
()
{
...
...
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