Skip to content

Commit ddd43f5

Browse files
authored
Merge pull request #732 from izaid/various
Updates to match libdynd
2 parents 5d6d0b7 + 7c51c04 commit ddd43f5

4 files changed

Lines changed: 39 additions & 25 deletions

File tree

dynd/cpp/registry.pxd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ cdef extern from 'dynd/registry.hpp' namespace 'dynd' nogil:
1414

1515
bool is_namespace() const
1616

17-
void observe(void (*)(const char *, registry_entry *))
17+
void observe(void (*)(registry_entry *, const char *, registry_entry *))
1818

1919
registry_entry &get(const string &)
2020

21+
const string &path() const
22+
2123
map[string, registry_entry].iterator begin()
2224
map[string, registry_entry].iterator end()
2325

dynd/nd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
from .registry import publish_callables
1919
from . import functional
2020

21-
publish_callables(sys.modules['dynd'])
21+
publish_callables()

dynd/nd/registry.pxd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
from ..cpp.registry cimport registered, registry_entry
3+
4+
cdef extern _publish_callables(registry_entry &entry)

dynd/nd/registry.pyx

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,34 @@ from .array cimport _registry_assign_init as assign_init
1515

1616
assign_init()
1717

18-
cdef _publish_callables(mod, registry_entry entry = registered()):
19-
for pair in entry:
20-
if (pair.second.is_namespace()):
21-
try:
22-
new_mod = sys.modules[mod.__name__ + '.' + pair.first]
23-
except KeyError:
24-
new_mod = imp.new_module(pair.first)
25-
_publish_callables(new_mod, pair.second)
26-
setattr(mod, pair.first, new_mod)
27-
else:
28-
setattr(mod, pair.first, wrap(pair.second.value()))
29-
30-
def publish_callables(mod):
31-
return _publish_callables(mod, registered())
32-
33-
cdef void observer(const char *name, registry_entry *entry) with gil:
34-
from . import __name__
35-
mod = sys.modules[__name__]
36-
37-
if entry.is_namespace():
38-
_publish_callables(mod, dereference(entry))
39-
40-
registered().observe(&observer)
18+
from libcpp.map cimport map
19+
from libcpp.pair cimport pair
20+
from libcpp.string cimport string
21+
22+
from cython.operator import preincrement
23+
24+
cdef void add_one(registry_entry *parent_entry, const char *name, registry_entry *entry) with gil:
25+
if (entry.is_namespace()):
26+
try:
27+
new_mod = sys.modules[entry.path()]
28+
except KeyError:
29+
new_mod = imp.new_module(entry.path())
30+
sys.modules[entry.path()] = new_mod
31+
_publish_callables(dereference(entry))
32+
if (not parent_entry.path().empty()):
33+
mod = sys.modules[parent_entry.path()]
34+
setattr(mod, name, new_mod)
35+
else:
36+
mod = sys.modules[parent_entry.path()]
37+
setattr(mod, name, wrap(entry.value()))
38+
39+
cdef _publish_callables(registry_entry &entry):
40+
entry.observe(&add_one)
41+
42+
cdef map[string, registry_entry].iterator it = entry.begin()
43+
while (it != entry.end()):
44+
add_one(&entry, dereference(it).first.c_str(), &dereference(it).second)
45+
preincrement(it)
46+
47+
def publish_callables():
48+
return _publish_callables(registered())

0 commit comments

Comments
 (0)