Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
4b324243
Commit
4b324243
authored
Sep 25, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
additional error handling
parent
7b270cf9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
7 deletions
+38
-7
from_cpython/Objects/exceptions.c
from_cpython/Objects/exceptions.c
+2
-2
src/gc/gc_alloc.h
src/gc/gc_alloc.h
+7
-0
src/runtime/capi.cpp
src/runtime/capi.cpp
+14
-2
src/runtime/file.cpp
src/runtime/file.cpp
+8
-2
src/runtime/str.cpp
src/runtime/str.cpp
+4
-0
src/runtime/types.cpp
src/runtime/types.cpp
+3
-1
No files found.
from_cpython/Objects/exceptions.c
View file @
4b324243
...
...
@@ -2246,11 +2246,11 @@ _PyExc_Init(void)
POST_INIT
(
UnicodeWarning
)
POST_INIT
(
BytesWarning
)
PyExc_MemoryErrorInst
=
BaseException_new
(
&
_PyExc_MemoryError
,
NULL
,
NULL
);
PyExc_MemoryErrorInst
=
PyGC_AddRoot
(
BaseException_new
(
&
_PyExc_MemoryError
,
NULL
,
NULL
)
);
if
(
!
PyExc_MemoryErrorInst
)
Py_FatalError
(
"Cannot pre-allocate MemoryError instance"
);
PyExc_RecursionErrorInst
=
BaseException_new
(
&
_PyExc_RuntimeError
,
NULL
,
NULL
);
PyExc_RecursionErrorInst
=
PyGC_AddRoot
(
BaseException_new
(
&
_PyExc_RuntimeError
,
NULL
,
NULL
)
);
if
(
!
PyExc_RecursionErrorInst
)
Py_FatalError
(
"Cannot pre-allocate RuntimeError instance for "
"recursion errors"
);
...
...
src/gc/gc_alloc.h
View file @
4b324243
...
...
@@ -51,6 +51,10 @@ extern "C" inline void* gc_alloc(size_t bytes, GCKind kind_id) {
// inline it, which is especially useful for this function.
ScopedStatTimer
gc_alloc_stattimer
(
gc_alloc_stattimer_counter
,
15
);
#endif
if
((
size_t
)(
bytes
)
>
(
size_t
)
PY_SSIZE_T_MAX
)
return
NULL
;
size_t
alloc_bytes
=
bytes
+
sizeof
(
GCAllocation
);
#ifndef NVALGRIND
...
...
@@ -124,6 +128,9 @@ extern "C" inline void* gc_realloc(void* ptr, size_t bytes) {
// Normal realloc() supports receiving a NULL pointer, but we need to know what the GCKind is:
assert
(
ptr
);
if
((
size_t
)(
bytes
)
>
(
size_t
)
PY_SSIZE_T_MAX
)
return
NULL
;
size_t
alloc_bytes
=
bytes
+
sizeof
(
GCAllocation
);
GCAllocation
*
alloc
;
...
...
src/runtime/capi.cpp
View file @
4b324243
...
...
@@ -892,8 +892,20 @@ extern "C" int PyErr_BadArgument() noexcept {
}
extern
"C"
PyObject
*
PyErr_NoMemory
()
noexcept
{
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
return
nullptr
;
if
(
PyErr_ExceptionMatches
(
PyExc_MemoryError
))
/* already current */
return
NULL
;
/* raise the pre-allocated instance if it still exists */
if
(
PyExc_MemoryErrorInst
)
PyErr_SetObject
(
PyExc_MemoryError
,
PyExc_MemoryErrorInst
);
else
/* this will probably fail since there's no memory and hee,
hee, we have to instantiate this class
*/
PyErr_SetNone
(
PyExc_MemoryError
);
return
NULL
;
}
extern
"C"
const
char
*
PyExceptionClass_Name
(
PyObject
*
o
)
noexcept
{
...
...
src/runtime/file.cpp
View file @
4b324243
...
...
@@ -929,11 +929,17 @@ Box* fileNew(BoxedClass* cls, Box* s, Box* m, Box** args) {
assert
(
cls
==
file_cls
);
if
(
s
->
cls
==
unicode_cls
)
if
(
s
->
cls
==
unicode_cls
)
{
s
=
_PyUnicode_AsDefaultEncodedString
(
s
,
NULL
);
if
(
!
s
)
throwCAPIException
();
}
if
(
m
->
cls
==
unicode_cls
)
if
(
m
->
cls
==
unicode_cls
)
{
m
=
_PyUnicode_AsDefaultEncodedString
(
m
,
NULL
);
if
(
!
m
)
throwCAPIException
();
}
if
(
s
->
cls
!=
str_cls
)
{
raiseExcHelper
(
TypeError
,
"coercing to Unicode: need string of buffer, %s found"
,
getTypeName
(
s
));
...
...
src/runtime/str.cpp
View file @
4b324243
...
...
@@ -2477,6 +2477,10 @@ extern "C" int PyString_AsStringAndSize(register PyObject* obj, register char**
}
extern
"C"
PyObject
*
PyString_FromStringAndSize
(
const
char
*
s
,
ssize_t
n
)
noexcept
{
if
(
n
<
0
)
{
PyErr_SetString
(
PyExc_SystemError
,
"Negative size passed to PyString_FromStringAndSize"
);
return
NULL
;
}
if
(
s
==
NULL
)
return
BoxedString
::
createUninitializedString
(
n
);
return
boxString
(
llvm
::
StringRef
(
s
,
n
));
...
...
src/runtime/types.cpp
View file @
4b324243
...
...
@@ -3274,7 +3274,9 @@ extern "C" PyVarObject* PyObject_InitVar(PyVarObject* op, PyTypeObject* tp, Py_s
}
extern
"C"
PyObject
*
PyObject_Init
(
PyObject
*
op
,
PyTypeObject
*
tp
)
noexcept
{
assert
(
op
);
if
(
op
==
NULL
)
return
PyErr_NoMemory
();
assert
(
tp
);
assert
(
gc
::
isValidGCMemory
(
op
));
...
...
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