Esempio n. 1
0
 template <typename U> static PyObject *c2py(U &&x) {
   PyTypeObject *p = get_type_ptr(typeid(T));
   if (p == nullptr) return NULL;
   py_type *self = (py_type *)p->tp_alloc(p, 0);
   if (self != NULL) { self->_c = new T{std::forward<U>(x)}; }
   return (PyObject *)self;
 }
Esempio n. 2
0
File: types.c Progetto: adk9/ohm
inline basetype_t*
get_type_ptr(basetype_t *type)
{
    if ((is_ptr(type->ohm_type) || is_alias(type->ohm_type))
        && type->elems)
        return get_type_ptr(type->elems[0]);
    return type;
}
Esempio n. 3
0
 static bool is_convertible(PyObject *ob, bool raise_exception) {
   PyTypeObject *p = get_type_ptr(typeid(T));
   if (p == nullptr) return false;
   if (PyObject_TypeCheck(ob, p)) {
     if (((py_type *)ob)->_c != NULL) return true;
     if (raise_exception) PyErr_SetString(PyExc_TypeError, "Severe internal error : Python object of ${c.py_type} has a _c NULL pointer !!");
     return false;
   }
   if (raise_exception) PyErr_SetString(PyExc_TypeError, "Python object is not a ${c.py_type}");
   return false;
 }