diff options
author | Jim Meyering <meyering@redhat.com> | 2009-08-14 19:12:18 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2009-08-14 20:40:17 +0200 |
commit | 4b940d1e349e382cb077be97af43a4893de9ea55 (patch) | |
tree | abdaf989909dc2c4925d5396a18a18a089d6330b | |
parent | 8300b097ecbd66a1c9e2595e92bf4caca18768e4 (diff) | |
download | libguestfs-4b940d1e349e382cb077be97af43a4893de9ea55.tar.gz libguestfs-4b940d1e349e382cb077be97af43a4893de9ea55.tar.xz libguestfs-4b940d1e349e382cb077be97af43a4893de9ea55.zip |
generator.ml: factor out a function
* src/generator.ml (emit_put_list_function): New function.
-rwxr-xr-x | src/generator.ml | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/generator.ml b/src/generator.ml index b76f502c..4fb9e4f2 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -7445,6 +7445,21 @@ py_guestfs_close (PyObject *self, PyObject *args) "; + let emit_put_list_function typ = + pr "static PyObject *\n"; + pr "put_%s_list (struct guestfs_%s_list *%ss)\n" typ typ typ; + pr "{\n"; + pr " PyObject *list;\n"; + pr " int i;\n"; + pr "\n"; + pr " list = PyList_New (%ss->len);\n" typ; + pr " for (i = 0; i < %ss->len; ++i)\n" typ; + pr " PyList_SetItem (list, i, put_%s (&%ss->val[i]));\n" typ typ; + pr " return list;\n"; + pr "};\n"; + pr "\n" + in + (* Structures, turned into Python dictionaries. *) List.iter ( fun (typ, cols) -> @@ -7501,18 +7516,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr "};\n"; pr "\n"; - pr "static PyObject *\n"; - pr "put_%s_list (struct guestfs_%s_list *%ss)\n" typ typ typ; - pr "{\n"; - pr " PyObject *list;\n"; - pr " int i;\n"; - pr "\n"; - pr " list = PyList_New (%ss->len);\n" typ; - pr " for (i = 0; i < %ss->len; ++i)\n" typ; - pr " PyList_SetItem (list, i, put_%s (&%ss->val[i]));\n" typ typ; - pr " return list;\n"; - pr "};\n"; - pr "\n" + emit_put_list_function typ ) structs; (* Python wrapper functions. *) |