Skip to content

Commit bbdb24d

Browse files
committed
Merge pull request libdynd#452 from izaid/gfunc
Update to match libdynd
2 parents bb2ebfa + de0ab8d commit bbdb24d

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

dynd/src/gfunc_callable_functions.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,20 @@ void pydynd::init_w__type_callable_typeobject(PyObject *type)
2727
void pydynd::add__type_names_to_dir_dict(const ndt::type &dt, PyObject *dict)
2828
{
2929
if (!dt.is_builtin()) {
30-
const std::pair<std::string, nd::callable> *properties;
31-
size_t count;
3230
// Add the type properties
33-
dt.extended()->get_dynamic_type_properties(&properties, &count);
34-
for (size_t i = 0; i < count; ++i) {
35-
if (PyDict_SetItemString(dict, properties[i].first.c_str(), Py_None) <
36-
0) {
31+
std::map<std::string, nd::callable> properties;
32+
dt.extended()->get_dynamic_type_properties(properties);
33+
for (const auto &pair : properties) {
34+
if (PyDict_SetItemString(dict, pair.first.c_str(), Py_None) < 0) {
3735
throw runtime_error("");
3836
}
3937
}
4038
// Add the type functions
41-
dt.extended()->get_dynamic_type_functions(&properties, &count);
39+
const std::pair<std::string, nd::callable> *functions;
40+
size_t count;
41+
dt.extended()->get_dynamic_type_functions(&functions, &count);
4242
for (size_t i = 0; i < count; ++i) {
43-
if (PyDict_SetItemString(dict, properties[i].first.c_str(), Py_None) <
44-
0) {
43+
if (PyDict_SetItemString(dict, functions[i].first.c_str(), Py_None) < 0) {
4544
throw runtime_error("");
4645
}
4746
}
@@ -52,30 +51,25 @@ PyObject *pydynd::get__type_dynamic_property(const dynd::ndt::type &dt,
5251
PyObject *name)
5352
{
5453
if (!dt.is_builtin()) {
55-
const std::pair<std::string, nd::callable> *properties;
56-
size_t count;
5754
// Search for a property
58-
dt.extended()->get_dynamic_type_properties(&properties, &count);
55+
std::map<std::string, nd::callable> properties;
56+
dt.extended()->get_dynamic_type_properties(properties);
5957
// TODO: We probably want to make some kind of acceleration structure for
6058
// the name lookup
61-
if (count > 0) {
62-
std::string nstr = pystring_as_string(name);
63-
for (size_t i = 0; i < count; ++i) {
64-
if (properties[i].first == nstr) {
65-
return DyND_PyWrapper_New(const_cast<dynd::nd::callable &>(
66-
properties[i].second)(dynd::kwds("self", dt)));
67-
// return call_gfunc_callable(nstr, properties[i].second,
68-
// dt);
69-
}
70-
}
59+
std::string nstr = pystring_as_string(name);
60+
nd::callable p = properties[nstr];
61+
if (!p.is_null()) {
62+
return DyND_PyWrapper_New(p(dt));
7163
}
7264
// Search for a function
73-
dt.extended()->get_dynamic_type_functions(&properties, &count);
65+
const std::pair<std::string, nd::callable> *functions;
66+
size_t count;
67+
dt.extended()->get_dynamic_type_functions(&functions, &count);
7468
if (count > 0) {
7569
std::string nstr = pystring_as_string(name);
7670
for (size_t i = 0; i < count; ++i) {
77-
if (properties[i].first == nstr) {
78-
return wrap__type_callable(nstr, properties[i].second, dt);
71+
if (functions[i].first == nstr) {
72+
return wrap__type_callable(nstr, functions[i].second, dt);
7973
}
8074
}
8175
}

0 commit comments

Comments
 (0)