Code snippet to work out which RStruct/RStructList structs are used and how
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
Richard W.M. Jones wrote:
Subject: [PATCH] Work out which RStruct/RStructList structs are really used, and how.
Thanks. That was just what I needed. When I apply that along with the following two patches, the four unused functions are no longer emitted.
From 71b6bb79fbae53f1f4f2465e693a2c3e9f1a6faa Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Fri, 14 Aug 2009 19:12:18 +0200 Subject: [PATCH libguestfs 1/2] generator.ml: factor out a function
* src/generator.ml (emit_print_list_function): New function. --- src/generator.ml | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index b76f502..3dc2ae5 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -7445,6 +7445,21 @@ py_guestfs_close (PyObject *self, PyObject *args) "; + let emit_print_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_print_list_function typ ) structs; (* Python wrapper functions. *) -- 1.6.4.357.gfd68c
From bf64b6fa512012e2a15fa5b40037218b5159d659 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Fri, 14 Aug 2009 19:33:35 +0200 Subject: [PATCH libguestfs 2/2] generator.ml: don't emit unused functions
* src/generator.ml: Use "rstructs_used" to emit definitions only for put_TYPE_list functions that are used. --- src/generator.ml | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 3dc2ae5..01a4436 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -7516,9 +7516,17 @@ py_guestfs_close (PyObject *self, PyObject *args) pr "};\n"; pr "\n"; - emit_print_list_function typ ) structs; + (* Emit a put_TYPE_list function definition only if that function is used. *) + List.iter ( + function + | typ, (RStructListOnly | RStructAndList) -> + (* generate the function for typ *) + emit_print_list_function typ + | typ, _ -> () (* empty *) + ) rstructs_used; + (* Python wrapper functions. *) List.iter ( fun (name, style, _, _, _, _, _) -> -- 1.6.4.357.gfd68c
On Fri, Aug 14, 2009 at 07:46:25PM +0200, Jim Meyering wrote:
Richard W.M. Jones wrote:
Subject: [PATCH] Work out which RStruct/RStructList structs are really used, and how.
Thanks. That was just what I needed. When I apply that along with the following two patches, the four unused functions are no longer emitted.
Yup, patch looks good, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
On Fri, Aug 14, 2009 at 07:46:25PM +0200, Jim Meyering wrote:
+ let emit_print_list_function typ = + pr "static PyObject *\n"; + pr "put_%s_list (struct guestfs_%s_list *%ss)\n" typ typ typ;
Actually I guess the OCaml function should be called emit_put_list_function ... Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Richard W.M. Jones wrote:
On Fri, Aug 14, 2009 at 07:46:25PM +0200, Jim Meyering wrote:
+ let emit_print_list_function typ = + pr "static PyObject *\n"; + pr "put_%s_list (struct guestfs_%s_list *%ss)\n" typ typ typ;
Actually I guess the OCaml function should be called emit_put_list_function ...
I chose the more generic name, but that's fine, too. Adjusted. Will push as soon as you've pushed the prereq cset.
participants (2)
-
Jim Meyering -
Richard W.M. Jones