aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/cyson/cyson/unsigned_long.h
blob: 8f8c8c1da775f4eee4e1ca47073285a133447e77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once

#include <Python.h>

#include <stdint.h>

namespace NCYson {
    extern PyTypeObject PyUnsignedLong_Type;

    PyObject* PreparePyUIntType(PyObject* repr = nullptr);
    PyObject* ConstructPyUIntFromPyLong(PyLongObject*);
    PyObject* ConstructPyUIntFromUint(uint64_t);

    inline int IsExactPyUInt(PyObject* obj) {
        return Py_TYPE(obj) == &PyUnsignedLong_Type;
    }

#if PY_MAJOR_VERSION >= 3
    inline PyObject* ConstructPyNumberFromUint(uint64_t n) {
        return ConstructPyUIntFromUint(n);
    }
#else
    inline PyObject* ConstructPyNumberFromUint(uint64_t n) {
        return PyLong_FromUnsignedLong(n);
    }
#endif
}