mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 05:22:45 +00:00
Objects now throw an exception after asserting if initialized with the wrong Python type.
[SVN r8147]
This commit is contained in:
30
objects.cpp
30
objects.cpp
@@ -104,6 +104,11 @@ Tuple::Tuple(Ptr p)
|
||||
: Object(p)
|
||||
{
|
||||
assert(accepts(p));
|
||||
if (!accepts(p))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, p->ob_type->tp_name);
|
||||
throw ErrorAlreadySet();
|
||||
}
|
||||
}
|
||||
|
||||
PyTypeObject* Tuple::type_object()
|
||||
@@ -149,7 +154,15 @@ Tuple& Tuple::operator+=(const Tuple& rhs)
|
||||
// Construct from an owned PyObject*.
|
||||
// Precondition: p must point to a python string.
|
||||
String::String(Ptr p)
|
||||
: Object(p) { assert(accepts(p)); }
|
||||
: Object(p)
|
||||
{
|
||||
assert(accepts(p));
|
||||
if (!accepts(p))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, p->ob_type->tp_name);
|
||||
throw ErrorAlreadySet();
|
||||
}
|
||||
}
|
||||
|
||||
String::String(const char* s)
|
||||
: Object(Ptr(PyString_FromString(s))) {}
|
||||
@@ -196,7 +209,15 @@ void String::intern()
|
||||
}
|
||||
|
||||
Dict::Dict(Ptr p)
|
||||
: Object(p) { assert(accepts(p)); }
|
||||
: Object(p)
|
||||
{
|
||||
assert(accepts(p));
|
||||
if (!accepts(p))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, p->ob_type->tp_name);
|
||||
throw ErrorAlreadySet();
|
||||
}
|
||||
}
|
||||
|
||||
Dict::Dict()
|
||||
: Object(Ptr(PyDict_New())) {}
|
||||
@@ -336,6 +357,11 @@ List::List(Ptr p)
|
||||
: Object(p)
|
||||
{
|
||||
assert(accepts(p));
|
||||
if (!accepts(p))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, p->ob_type->tp_name);
|
||||
throw ErrorAlreadySet();
|
||||
}
|
||||
}
|
||||
|
||||
List::List(std::size_t sz)
|
||||
|
||||
Reference in New Issue
Block a user