pycredentials.h: use import to ensure python type correctness
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sat, 6 Jul 2019 07:09:57 +0000 (19:09 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 22 Jul 2019 22:20:26 +0000 (22:20 +0000)
Because we include pyrpc_util.h, pycredentials doesn't need its own
PyStringFromStringOrNull().

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
auth/credentials/pycredentials.c
auth/credentials/pycredentials.h

index 9e231b04cb30e1d5d2538b4c91759f62c62f1562..5002bb86e1c1b5f03e2aeb44e24a5b9d81911842 100644 (file)
 
 void initcredentials(void);
 
-static PyObject *PyString_FromStringOrNULL(const char *str)
-{
-       if (str == NULL)
-               Py_RETURN_NONE;
-       return PyUnicode_FromString(str);
-}
-
 static PyObject *py_creds_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 {
        return pytalloc_steal(type, cli_credentials_init(NULL));
index a136a210da359b0c92daaec73d5f77a286a63ff5..bf6962c312b30abe610a59ef98b696ba843a5d2c 100644 (file)
 #define _PYCREDENTIALS_H_
 
 #include "auth/credentials/credentials.h"
+#include "librpc/rpc/pyrpc_util.h"
 #include <pytalloc.h>
 
 extern PyTypeObject PyCredentials;
 extern PyTypeObject PyCredentialCacheContainer;
-#define PyCredentials_Check(py_obj) PyObject_TypeCheck(py_obj, &PyCredentials)
-#define PyCredentials_AsCliCredentials(py_obj) pytalloc_get_type(py_obj, struct cli_credentials)
-#define cli_credentials_from_py_object(py_obj) (py_obj == Py_None)?cli_credentials_init_anon(NULL):PyCredentials_AsCliCredentials(py_obj)
+#define PyCredentials_Check(py_obj)                                    \
+       py_check_dcerpc_type(py_obj, "samba.credentials", "Credentials")
+
+#define PyCredentials_AsCliCredentials(py_obj)                         \
+       (PyCredentials_Check(py_obj) ?                                  \
+        pytalloc_get_type(py_obj, struct cli_credentials) : NULL)
+
+#define cli_credentials_from_py_object(py_obj)                  \
+       ((py_obj == Py_None) ?                                   \
+        cli_credentials_init_anon(NULL) :                       \
+        PyCredentials_AsCliCredentials(py_obj))
 
 #endif /*  _PYCREDENTIALS_H_ */