/* vi:set ts=8 sts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar * * Do ":help uganda" in Vim to read copying and usage conditions. * Do ":help credits" in Vim to see a list of people who contributed. * See README.txt for an overview of the Vim source code. *//* * Python extensions by Paul Moore. * Changes for Unix by David Leonard. * * This consists of four parts: * 1. Python interpreter main program * 2. Python output stream: writes output via [e]msg(). * 3. Implementation of the Vim module for Python * 4. Utility functions for handling the interface between Vim and Python. *//* * Roland Puntaier 2009/sept/16: * Adaptations to support both python3.x and python2.x */// uncomment this if used with the debug version of python// #define Py_DEBUG#include"vim.h"#include<limits.h>/* Python.h defines _POSIX_THREADS itself (if needed) */#ifdef _POSIX_THREADS# undef _POSIX_THREADS#endif#if defined(_WIN32) && defined(HAVE_FCNTL_H)# undef HAVE_FCNTL_H#endif#ifdef _DEBUG# undef _DEBUG#endif#define PY_SSIZE_T_CLEAN#ifdef F_BLANK# undef F_BLANK#endif#ifdef HAVE_STDARG_H# undef HAVE_STDARG_H /* Python's config.h defines it as well. */#endif#ifdef _POSIX_C_SOURCE /* defined in feature.h */# undef _POSIX_C_SOURCE#endif#ifdef _XOPEN_SOURCE# undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */#endif#include<Python.h>#if defined(MACOS) && !defined(MACOS_X_UNIX)#include"macglue.h"#include<CodeFragments.h>#endif#undef main /* Defined in python.h - aargh */#undef HAVE_FCNTL_H /* Clash with os_win32.h */staticvoidinit_structs(void);#define PyInt Py_ssize_t#define PyString_Check(obj) PyUnicode_Check(obj)#define PyString_AsString(obj) _PyUnicode_AsString(obj)#define PyString_Size(obj) PyUnicode_GET_SIZE(obj)#define PyString_FromString(repr) PyUnicode_FromString(repr)#if defined(DYNAMIC_PYTHON3)#ifndef WIN3264#include<dlfcn.h>#define FARPROC void*#define HINSTANCE void*#define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)#define close_dll dlclose#define symbol_from_dll dlsym#else#define load_dll LoadLibrary#define close_dll FreeLibrary#define symbol_from_dll GetProcAddress#endif/* * Wrapper defines */#undef PyArg_Parse# define PyArg_Parse py3_PyArg_Parse#undef PyArg_ParseTuple# define PyArg_ParseTuple py3_PyArg_ParseTuple# define PyDict_SetItemString py3_PyDict_Se