You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2016/02/25 23:40:26 UTC
[11/17] lucy-clownfish git commit: Add classes to Python module
object.
Add classes to Python module object.
For instance, make `clownfish.String` available on the Python
`clownfish` module object.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/49972c1c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/49972c1c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/49972c1c
Branch: refs/heads/master
Commit: 49972c1cbc6b6f9ae4ad55c6d26b69e491e63741
Parents: 67b7630
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Feb 1 17:13:37 2016 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Feb 24 15:20:38 2016 -0800
----------------------------------------------------------------------
compiler/src/CFCPython.c | 10 +++++++++-
runtime/python/test/test_clownfish.py | 2 ++
2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/49972c1c/compiler/src/CFCPython.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPython.c b/compiler/src/CFCPython.c
index 068c9c4..d108b69 100644
--- a/compiler/src/CFCPython.c
+++ b/compiler/src/CFCPython.c
@@ -459,6 +459,7 @@ S_write_module_file(CFCPython *self, CFCParcel *parcel, const char *dest) {
char *class_bindings = S_gen_class_bindings(self, parcel, pymod_name, ordered);
char *parcel_boots = CFCUtil_strdup("");
char *pytype_ready_calls = CFCUtil_strdup("");
+ char *module_adds = CFCUtil_strdup("");
// Add parcel bootstrapping calls.
for (size_t i = 0; parcels[i]; ++i) {
@@ -487,6 +488,10 @@ S_write_module_file(CFCPython *self, CFCParcel *parcel, const char *dest) {
" if (PyType_Ready(&", struct_sym,
"_pytype_struct) < 0) { return NULL; }\n", NULL);
}
+
+ module_adds = CFCUtil_cat(module_adds, " PyModule_AddObject(module, \"",
+ struct_sym, "\", (PyObject*)&", struct_sym,
+ "_pytype_struct);\n", NULL);
}
const char pattern[] =
@@ -522,6 +527,8 @@ S_write_module_file(CFCPython *self, CFCParcel *parcel, const char *dest) {
"%s\n" // parcel boots
"\n"
" PyObject *module = PyModule_Create(&module_def);\n"
+ "%s\n" // Add types to module
+ "\n"
" return module;\n"
"}\n"
"\n"
@@ -532,7 +539,7 @@ S_write_module_file(CFCPython *self, CFCParcel *parcel, const char *dest) {
= CFCUtil_sprintf(pattern, self->header, pound_includes, callbacks,
helper_mod_name, class_bindings, type_linkups,
last_component, pytype_ready_calls, parcel_boots,
- self->footer);
+ module_adds, self->footer);
char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "_%s.c", dest,
last_component);
@@ -540,6 +547,7 @@ S_write_module_file(CFCPython *self, CFCParcel *parcel, const char *dest) {
FREEMEM(filepath);
FREEMEM(content);
+ FREEMEM(module_adds);
FREEMEM(pytype_ready_calls);
FREEMEM(parcel_boots);
FREEMEM(class_bindings);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/49972c1c/runtime/python/test/test_clownfish.py
----------------------------------------------------------------------
diff --git a/runtime/python/test/test_clownfish.py b/runtime/python/test/test_clownfish.py
index fd124d3..d8f2594 100644
--- a/runtime/python/test/test_clownfish.py
+++ b/runtime/python/test/test_clownfish.py
@@ -21,6 +21,8 @@ class MyTest(unittest.TestCase):
def testTrue(self):
self.assertTrue(True, "True should be true")
+ def testClassesPresent(self):
+ self.assertIsInstance(clownfish.Hash, type)
if __name__ == '__main__':
unittest.main()