/*******************************************************************************
 * Copyright 2013-2017 Aerospike, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

#pragma once

// convert python 2.x calls to python 3.x
#if PY_MAJOR_VERSION >= 3
	#define PyInt_FromLong              PyLong_FromLong
	#define PyInt_AsLong                PyLong_AsLong
	#define PyInt_Check                 PyLong_Check
	#define PyInt_FromLong              PyLong_FromLong
	#define PyInt_Type                  PyLong_Type
	#define PyInt_FromString            PyLong_FromString

	#define PyString_FromString         PyUnicode_FromString
	#define PyString_FromStringAndSize  PyUnicode_FromStringAndSize

	#define PyString_AsString           PyUnicode_AsUTF8

	#define PyString_Size               PyUnicode_GET_SIZE
	#define PyString_GET_SIZE           PyUnicode_GET_SIZE
	#define PyString_Check              PyUnicode_Check
#endif

// define module definition and initialization macros
#if PY_MAJOR_VERSION >= 3
	#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
	#define MOD_DEF(ob, name, doc, methods) \
		static struct PyModuleDef moduledef = { \
			PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
			ob = PyModule_Create(&moduledef);
	#define MOD_SUCCESS_VAL(val) val
#else
	#define MOD_INIT(name) PyMODINIT_FUNC init##name(void)
	#define MOD_DEF(ob, name, doc, methods) \
			ob = Py_InitModule3(name, methods, doc);
	#define MOD_SUCCESS_VAL(val)
#endif
