#include "includes.h"
#include "param/param.h"
#include "param/loadparm.h"
+#include <Python.h>
#include "pytalloc.h"
+/* There's no Py_ssize_t in 2.4, apparently */
+#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
+typedef int Py_ssize_t;
+typedef inquiry lenfunc;
+#endif
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+
#define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_ptr(obj)
-#define PyLoadparmContext_Check(obj) PyObject_TypeCheck(obj, &PyLoadparmContext)
PyAPI_DATA(PyTypeObject) PyLoadparmContext;
PyAPI_DATA(PyTypeObject) PyLoadparmService;
ret = lp_load((struct loadparm_context *)self->ptr, filename);
if (!ret) {
- PyErr_SetString(PyExc_RuntimeError, "Unable to load file");
+ PyErr_Format(PyExc_RuntimeError, "Unable to load file %s", filename);
return NULL;
}
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *py_lp_ctx_load_default(py_talloc_Object *self)
ret = lp_load_default(self->ptr);
if (!ret) {
- PyErr_SetString(PyExc_RuntimeError, "Unable to load file");
+ PyErr_SetString(PyExc_RuntimeError, "Unable to load default file");
return NULL;
}
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *py_lp_ctx_get(py_talloc_Object *self, PyObject *args)
ret = py_lp_ctx_get_helper(self->ptr, section_name, param_name);
if (ret == NULL)
- return Py_None;
+ Py_RETURN_NONE;
return ret;
}
return NULL;
}
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *py_lp_ctx_private_path(py_talloc_Object *self, PyObject *args)
.tp_flags = Py_TPFLAGS_DEFAULT,
};
-struct loadparm_context *lp_from_py_object(PyObject *py_obj)
+_PUBLIC_ struct loadparm_context *lp_from_py_object(PyObject *py_obj)
{
struct loadparm_context *lp_ctx;
if (PyString_Check(py_obj)) {
lp_ctx = loadparm_init(NULL);
if (!lp_load(lp_ctx, PyString_AsString(py_obj))) {
talloc_free(lp_ctx);
+ PyErr_Format(PyExc_RuntimeError,
+ "Unable to load %s", PyString_AsString(py_obj));
return NULL;
}
return lp_ctx;
if (py_obj == Py_None) {
lp_ctx = loadparm_init(NULL);
- if (!lp_load_default(lp_ctx)) {
- talloc_free(lp_ctx);
- return NULL;
- }
+ /* We're not checking that loading the file succeeded *on purpose */
+ lp_load_default(lp_ctx);
return lp_ctx;
}