Skip to content

Commit 9132c8f

Browse files
Fix build failures from upstream removal of constructor for ndt::type
that constructs a type from its type id.
1 parent ea4a43a commit 9132c8f

5 files changed

Lines changed: 30 additions & 9 deletions

File tree

dynd/cpp/type.pxd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil:
3636
type_id_t get_base_id() const
3737

3838
type make_type[T]() except +translate_exception
39+
40+
cppclass reg_info_t:
41+
type tp
42+
43+
# Ideally we wouldn't use the detail namespace, but this is currently
44+
# needed to map a type id back to the corresponding type.
45+
cdef extern from "<dynd/type.hpp>" nogil:
46+
# Function doesn't really exist.
47+
# Use this to avoid Cython's odd handling of lvalue references
48+
reg_info_t _get_reg_info "dynd::ndt::detail::infos().operator[]"(type_id_t) except +translate_exception

dynd/ndt/type.pyx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ from ..cpp.types.callable_type cimport callable_type as _callable_type
3333
from ..cpp.types.string_type cimport string_type
3434
from ..cpp.types.bytes_type cimport bytes_type
3535
from ..cpp.types.fixed_bytes_type cimport fixed_bytes_type
36-
from ..cpp.type cimport make_type
36+
from ..cpp.type cimport make_type, _get_reg_info
3737
from ..cpp.complex cimport complex as dynd_complex
3838

3939
from ..config cimport translate_exception
@@ -399,8 +399,6 @@ cdef _type as_cpp_type(object o) except *:
399399
elif _builtin_type(o) is str or PyUnicode_Check(<PyObject*>o):
400400
# Use Cython's automatic conversion to c++ strings.
401401
return _type(<string>o)
402-
elif _builtin_type(o) is int or _builtin_type(o) is long:
403-
return _type(<type_id_t>(<int>o))
404402
elif is_numpy_dtype(<PyObject*>o):
405403
return _type_from_numpy_dtype(<PyArray_Descr*>o)
406404
elif issubclass(o, _ctypes_base_type):
@@ -718,7 +716,8 @@ cdef as_numba_type(_type tp):
718716
return _to_numba_type[tp.get_id()]
719717

720718
cdef _type from_numba_type(tp):
721-
return _type(<type_id_t> _from_numba_type[tp])
719+
720+
return _get_reg_info((<type_id_t> _from_numba_type[tp])).tp
722721

723722
cdef _type cpp_type_for(object obj) except *:
724723
cdef _type tp = xtype_for_prefix(obj)

dynd/src/array_from_py.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static dynd::nd::array array_from_pylist(PyObject *obj)
235235
// TODO: Add ability to specify access flags (e.g. immutable)
236236
// Do a pass through all the data to deduce its type and shape
237237
vector<intptr_t> shape;
238-
ndt::type tp(void_id);
238+
ndt::type tp = ndt::make_type<void>();
239239
Py_ssize_t size = PyList_GET_SIZE(obj);
240240
shape.push_back(size);
241241
for (Py_ssize_t i = 0; i < size; ++i) {

dynd/src/assign.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <dynd/functional.hpp>
1010
#include <dynd/kernels/tuple_assignment_kernels.hpp>
11+
#include <dynd/type.hpp>
1112

1213
#include "assign.hpp"
1314
#include "callables/assign_from_pyobject_callable.hpp"
@@ -26,12 +27,19 @@ PYDYND_API void assign_init()
2627
types;
2728

2829
PyDateTime_IMPORT;
30+
// TODO: There should be an interface that allows adding overloads
31+
// based on type id rather than on actual type. The current interface
32+
// makes for a lot of mapping back and forth between types and their
33+
// corresponding type ids.
34+
// For now, just use the infos vector from the type registry to map
35+
// ids back to their corresponding types.
36+
auto infos = ndt::detail::infos();
2937

3038
for (const auto &pair : nd::callable::make_all<pydynd::nd::assign_from_pyobject_callable, types>()) {
31-
nd::assign.overload(pair.first[0], {ndt::make_type<pyobject_type>()}, pair.second);
39+
nd::assign.overload(infos[pair.first[0]].tp, {ndt::make_type<pyobject_type>()}, pair.second);
3240
}
3341
for (const auto &pair : nd::callable::make_all<pydynd::nd::assign_to_pyobject_callable, types>()) {
34-
nd::assign.overload(ndt::make_type<pyobject_type>(), {ndt::type(pair.first[0])}, pair.second);
42+
nd::assign.overload(ndt::make_type<pyobject_type>(), {infos[pair.first[0]].tp}, pair.second);
3543
}
3644
}
3745

dynd/src/type_conversions.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
#include <cstdint>
2+
13
#include "type_functions.hpp"
4+
25
#include "type_deduction.hpp"
6+
37
#include "type_api.h"
48

59
dynd::ndt::type &pydynd::type_to_cpp_ref(PyObject *o)
@@ -70,15 +74,15 @@ dynd::ndt::type pydynd::ndt_type_from_pylist(PyObject *obj)
7074
// TODO: Add ability to specify access flags (e.g. immutable)
7175
// Do a pass through all the data to deduce its type and shape
7276
std::vector<intptr_t> shape;
73-
dynd::ndt::type tp(dynd::void_id);
77+
dynd::ndt::type tp = dynd::ndt::make_type<void>();
7478
Py_ssize_t size = PyList_GET_SIZE(obj);
7579
shape.push_back(size);
7680
for (Py_ssize_t i = 0; i < size; ++i) {
7781
deduce_pylist_shape_and_dtype(PyList_GET_ITEM(obj, i), shape, tp, 1);
7882
}
7983

8084
if (tp.get_id() == dynd::void_id) {
81-
tp = dynd::ndt::type(dynd::int32_id);
85+
tp = dynd::ndt::make_type<int32_t>();
8286
}
8387

8488
return dynd::ndt::make_type(shape.size(), shape.data(), tp);

0 commit comments

Comments
 (0)