123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #ifndef __LIBDNS_PYTHON_COMMON_H
- #define __LIBDNS_PYTHON_COMMON_H 1
- #include <Python.h>
- #include <boost/static_assert.hpp>
- #include <climits> // for CHAR_BIT
- #include <stdexcept>
- #include <string>
- namespace isc {
- namespace dns {
- namespace python {
- extern PyObject* po_IscException;
- extern PyObject* po_InvalidParameter;
- extern PyObject* po_DNSMessageBADVERS;
- int readDataFromSequence(uint8_t *data, size_t len, PyObject* sequence);
- int addClassVariable(PyTypeObject& c, const char* name, PyObject* obj);
- #if PY_MINOR_VERSION < 2
- typedef long Py_hash_t;
- #endif
- template <typename HashvalType>
- Py_hash_t
- convertToPyHash(HashvalType val) {
- BOOST_STATIC_ASSERT(sizeof(HashvalType) <= sizeof(Py_hash_t));
-
-
-
-
-
- size_t hash_val_bits = CHAR_BIT * sizeof(HashvalType);
- if (sizeof(HashvalType) < sizeof(Py_hash_t)) {
-
- const Py_hash_t mask = ~(static_cast<Py_hash_t>(-1) << hash_val_bits);
- return (static_cast<Py_hash_t>(val) & mask);
- } else {
-
-
- HashvalType mask = ~(static_cast<HashvalType>(1) <<
- (hash_val_bits - 1));
- return (val & mask);
- }
- }
- }
- }
- }
- #endif // __LIBDNS_PYTHON_COMMON_H
|