mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
python: Split up large Python extension into smaller C files.
Reduces build time in this directory from 11s to 3s.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
include guestfs-py.h
|
||||
include actions.h
|
||||
include config.h
|
||||
include guestfs-internal-all.h
|
||||
include guestfs-internal-frontend-cleanups.h
|
||||
|
||||
@@ -18,7 +18,16 @@
|
||||
include $(top_srcdir)/subdir-rules.mk
|
||||
|
||||
generator_built = \
|
||||
guestfs-py.c \
|
||||
actions-0.c \
|
||||
actions-1.c \
|
||||
actions-2.c \
|
||||
actions-3.c \
|
||||
actions-4.c \
|
||||
actions-5.c \
|
||||
actions-6.c \
|
||||
actions.h \
|
||||
module.c \
|
||||
structs.c \
|
||||
guestfs.py \
|
||||
bindtests.py
|
||||
|
||||
@@ -42,7 +51,18 @@ python_DATA = guestfs.py
|
||||
|
||||
python_LTLIBRARIES = libguestfsmod.la
|
||||
|
||||
libguestfsmod_la_SOURCES = guestfs-py.c guestfs-py.h guestfs-py-byhand.c
|
||||
libguestfsmod_la_SOURCES = \
|
||||
actions-0.c \
|
||||
actions-1.c \
|
||||
actions-2.c \
|
||||
actions-3.c \
|
||||
actions-4.c \
|
||||
actions-5.c \
|
||||
actions-6.c \
|
||||
actions.h \
|
||||
handle.c \
|
||||
module.c \
|
||||
structs.c
|
||||
|
||||
libguestfsmod_la_CPPFLAGS = \
|
||||
-DGUESTFS_PRIVATE=1 \
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/* libguestfs python bindings
|
||||
* Copyright (C) 2009-2016 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef guestfs_py_h
|
||||
#define guestfs_py_h
|
||||
|
||||
#include "guestfs.h"
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
#if PY_VERSION_HEX < 0x02050000
|
||||
typedef int Py_ssize_t;
|
||||
#define PY_SSIZE_T_MAX INT_MAX
|
||||
#define PY_SSIZE_T_MIN INT_MIN
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_PYCAPSULE_NEW
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
guestfs_h *g;
|
||||
} Pyguestfs_Object;
|
||||
#endif
|
||||
|
||||
static inline guestfs_h *
|
||||
get_handle (PyObject *obj)
|
||||
{
|
||||
assert (obj);
|
||||
assert (obj != Py_None);
|
||||
#ifndef HAVE_PYCAPSULE_NEW
|
||||
return ((Pyguestfs_Object *) obj)->g;
|
||||
#else
|
||||
return (guestfs_h*) PyCapsule_GetPointer(obj, "guestfs_h");
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline PyObject *
|
||||
put_handle (guestfs_h *g)
|
||||
{
|
||||
assert (g);
|
||||
#ifndef HAVE_PYCAPSULE_NEW
|
||||
return
|
||||
PyCObject_FromVoidPtrAndDesc ((void *) g, (char *) "guestfs_h", NULL);
|
||||
#else
|
||||
return PyCapsule_New ((void *) g, "guestfs_h", NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void guestfs_int_py_extend_module (PyObject *module);
|
||||
|
||||
extern PyObject *guestfs_int_py_create (PyObject *self, PyObject *args);
|
||||
extern PyObject *guestfs_int_py_close (PyObject *self, PyObject *args);
|
||||
extern PyObject *guestfs_int_py_set_event_callback (PyObject *self, PyObject *args);
|
||||
extern PyObject *guestfs_int_py_delete_event_callback (PyObject *self, PyObject *args);
|
||||
extern PyObject *guestfs_int_py_event_to_string (PyObject *self, PyObject *args);
|
||||
|
||||
#endif /* guestfs_py_h */
|
||||
@@ -19,7 +19,7 @@
|
||||
/**
|
||||
* This file contains a small number of functions that are written by
|
||||
* hand. The majority of the bindings are generated (see
|
||||
* F<python/guestfs-py.c>).
|
||||
* F<python/actions-*.c>).
|
||||
*/
|
||||
|
||||
/* This has to be included first, else definitions conflict with
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "guestfs-py.h"
|
||||
#include "actions.h"
|
||||
|
||||
static PyObject **get_all_event_callbacks (guestfs_h *g, size_t *len_rtn);
|
||||
|
||||
@@ -279,3 +279,91 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn)
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* This list should be freed (but not the strings) after use. */
|
||||
char **
|
||||
guestfs_int_py_get_string_list (PyObject *obj)
|
||||
{
|
||||
size_t i, len;
|
||||
char **r;
|
||||
#ifndef HAVE_PYSTRING_ASSTRING
|
||||
PyObject *bytes;
|
||||
#endif
|
||||
|
||||
assert (obj);
|
||||
|
||||
if (!PyList_Check (obj)) {
|
||||
PyErr_SetString (PyExc_RuntimeError, "expecting a list parameter");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_ssize_t slen = PyList_Size (obj);
|
||||
if (slen == -1) {
|
||||
PyErr_SetString (PyExc_RuntimeError, "get_string_list: PyList_Size failure");
|
||||
return NULL;
|
||||
}
|
||||
len = (size_t) slen;
|
||||
r = malloc (sizeof (char *) * (len+1));
|
||||
if (r == NULL) {
|
||||
PyErr_SetString (PyExc_RuntimeError, "get_string_list: out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
#ifdef HAVE_PYSTRING_ASSTRING
|
||||
r[i] = PyString_AsString (PyList_GetItem (obj, i));
|
||||
#else
|
||||
bytes = PyUnicode_AsUTF8String (PyList_GetItem (obj, i));
|
||||
r[i] = PyBytes_AS_STRING (bytes);
|
||||
#endif
|
||||
}
|
||||
r[len] = NULL;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
guestfs_int_py_put_string_list (char * const * const argv)
|
||||
{
|
||||
PyObject *list;
|
||||
size_t argc, i;
|
||||
|
||||
for (argc = 0; argv[argc] != NULL; ++argc)
|
||||
;
|
||||
|
||||
list = PyList_New (argc);
|
||||
for (i = 0; i < argc; ++i) {
|
||||
#ifdef HAVE_PYSTRING_ASSTRING
|
||||
PyList_SetItem (list, i, PyString_FromString (argv[i]));
|
||||
#else
|
||||
PyList_SetItem (list, i, PyUnicode_FromString (argv[i]));
|
||||
#endif
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
guestfs_int_py_put_table (char * const * const argv)
|
||||
{
|
||||
PyObject *list, *item;
|
||||
size_t argc, i;
|
||||
|
||||
for (argc = 0; argv[argc] != NULL; ++argc)
|
||||
;
|
||||
|
||||
list = PyList_New (argc >> 1);
|
||||
for (i = 0; i < argc; i += 2) {
|
||||
item = PyTuple_New (2);
|
||||
#ifdef HAVE_PYSTRING_ASSTRING
|
||||
PyTuple_SetItem (item, 0, PyString_FromString (argv[i]));
|
||||
PyTuple_SetItem (item, 1, PyString_FromString (argv[i+1]));
|
||||
#else
|
||||
PyTuple_SetItem (item, 0, PyUnicode_FromString (argv[i]));
|
||||
PyTuple_SetItem (item, 1, PyUnicode_FromString (argv[i+1]));
|
||||
#endif
|
||||
PyList_SetItem (list, i >> 1, item);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -52,7 +52,17 @@ This package contains the Python bindings for libguestfs.
|
||||
ext_modules=[
|
||||
Extension(
|
||||
'libguestfsmod',
|
||||
['guestfs-py-byhand.c', 'guestfs-py.c', 'utils.c'],
|
||||
['actions-0.c',
|
||||
'actions-1.c',
|
||||
'actions-2.c',
|
||||
'actions-3.c',
|
||||
'actions-4.c',
|
||||
'actions-5.c',
|
||||
'actions-6.c',
|
||||
'handle.c',
|
||||
'module.c',
|
||||
'structs.c',
|
||||
'utils.c'],
|
||||
|
||||
include_dirs=['.', '../src'],
|
||||
libraries=['guestfs'],
|
||||
|
||||
Reference in New Issue
Block a user