python: Rearrange C files for bindings.
[libguestfs.git] / python / guestfs-py-byhand.c
1 /* libguestfs python bindings
2  * Copyright (C) 2009-2011 Red Hat Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 /* This file contains a small number of functions that are written by
20  * hand.  The majority of the bindings are generated (see
21  * guestfs-py.c).
22  */
23
24 #include <config.h>
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <assert.h>
29
30 #include "guestfs-py.h"
31
32 PyObject *
33 py_guestfs_create (PyObject *self, PyObject *args)
34 {
35   guestfs_h *g;
36
37   g = guestfs_create ();
38   if (g == NULL) {
39     PyErr_SetString (PyExc_RuntimeError,
40                      "guestfs.create: failed to allocate handle");
41     return NULL;
42   }
43   guestfs_set_error_handler (g, NULL, NULL);
44   /* This can return NULL, but in that case put_handle will have
45    * set the Python error string.
46    */
47   return put_handle (g);
48 }
49
50 PyObject *
51 py_guestfs_close (PyObject *self, PyObject *args)
52 {
53   PyThreadState *py_save = NULL;
54   PyObject *py_g;
55   guestfs_h *g;
56
57   if (!PyArg_ParseTuple (args, (char *) "O:guestfs_close", &py_g))
58     return NULL;
59   g = get_handle (py_g);
60
61   if (PyEval_ThreadsInitialized ())
62     py_save = PyEval_SaveThread ();
63   guestfs_close (g);
64   if (PyEval_ThreadsInitialized ())
65     PyEval_RestoreThread (py_save);
66
67   Py_INCREF (Py_None);
68   return Py_None;
69 }