+/*
+ * This is the unsigned Python Integer -> C integer validation
+ * case. The signed case is below.
+ */
+static inline unsigned long long ndr_PyLong_AsCheckedUnsignedLongLong(PyObject *py_value,
+ size_t target_size)
+{
+ const unsigned long long uint_max = ndr_sizeof2uintmax(target_size);
+ unsigned long long ret_value = 0;
+
+ if (PyLong_Check(py_value)) {
+ unsigned long long test_var;
+
+ test_var = PyLong_AsUnsignedLongLong(py_value);
+ if (PyErr_Occurred() != NULL) {
+ return 0;
+ }
+
+ if (test_var > uint_max) {
+ PyErr_Format(PyExc_OverflowError,
+ \"Expected type %s or %s within range 0 - %llu, got %llu\",
+ PyInt_Type.tp_name, PyLong_Type.tp_name, uint_max, test_var);
+ return 0;
+ }
+
+ ret_value = test_var;
+
+ return ret_value;
+ }
+
+ if (PyInt_Check(py_value)) {
+ long test_var;
+
+ test_var = PyInt_AsLong(py_value);
+ if (PyErr_Occurred() != NULL) {
+ return 0;
+ }
+
+ if (test_var < 0 || (unsigned long long)test_var > uint_max) {
+ PyErr_Format(PyExc_OverflowError,
+ \"Expected type %s or %s within range 0 - %llu, got %ld\",
+ PyInt_Type.tp_name, PyLong_Type.tp_name, uint_max, test_var);
+ return 0;
+ }
+
+ ret_value = test_var;
+
+ return ret_value;
+ }
+
+ PyErr_Format(PyExc_TypeError,
+ \"Expected type %s or %s within range 0 - %llu\",
+ PyInt_Type.tp_name, PyLong_Type.tp_name, uint_max);
+ return 0;
+}
+