s3/s4 build: Fix Py_RETURN_NONE to work with python versions < 2.4
[tprouty/samba.git] / source4 / param / pyparam.c
index 04bef072314f99d79945656dc87ac98b8e59bc63..1eef02ba39e301611fa86469a8ba9be026d0eea6 100644 (file)
 #include "includes.h"
 #include "param/param.h"
 #include "param/loadparm.h"
+#include "../lib/util/python_util.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
+
 #define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_ptr(obj)
 
 PyAPI_DATA(PyTypeObject) PyLoadparmContext;
@@ -144,7 +151,7 @@ static PyObject *py_lp_ctx_load(py_talloc_Object *self, PyObject *args)
                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)
@@ -156,7 +163,7 @@ static PyObject *py_lp_ctx_load_default(py_talloc_Object *self)
                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)
@@ -169,7 +176,7 @@ 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;
 }
 
@@ -204,7 +211,7 @@ static PyObject *py_lp_ctx_set(py_talloc_Object *self, PyObject *args)
                return NULL;
         }
 
-       return Py_None;
+       Py_RETURN_NONE;
 }
 
 static PyObject *py_lp_ctx_private_path(py_talloc_Object *self, PyObject *args)
@@ -310,13 +317,15 @@ PyTypeObject PyLoadparmService = {
        .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;
@@ -324,10 +333,8 @@ struct loadparm_context *lp_from_py_object(PyObject *py_obj)
 
     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;
     }