-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathException.cpp
More file actions
53 lines (41 loc) · 1.33 KB
/
Copy pathException.cpp
File metadata and controls
53 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Exception.hpp"
#include "PyString.hpp"
#include "types/api.hpp"
#include "types/builtin.hpp"
namespace py {
Exception::Exception(PyType *t) : BaseException(t->underlying_type(), nullptr) {}
Exception::Exception(PyType *t, PyTuple *args) : BaseException(t, args) {}
Exception::Exception(PyTuple *args) : BaseException(types::BuiltinTypes::the().exception(), args) {}
Exception::Exception(const TypePrototype &type, PyTuple *args) : BaseException(type, args) {}
PyResult<PyObject *> Exception::__new__(const PyType *type, PyTuple *args, PyDict *kwargs)
{
ASSERT(type == types::exception());
ASSERT(!kwargs || kwargs->map().empty());
return Ok(Exception::create(args));
}
PyType *Exception::static_type() const
{
ASSERT(types::exception());
return types::exception();
}
PyType *Exception::class_type()
{
ASSERT(types::exception());
return types::exception();
}
namespace {
std::once_flag exception_flag;
std::unique_ptr<TypePrototype> register_exception()
{
return std::move(klass<Exception>("Exception", BaseException::class_type()).type);
}
}// namespace
std::function<std::unique_ptr<TypePrototype>()> Exception::type_factory()
{
return []() {
static std::unique_ptr<TypePrototype> type = nullptr;
std::call_once(exception_flag, []() { type = register_exception(); });
return std::move(type);
};
}
}// namespace py