0
0
mirror of https://github.com/vim/vim.git synced 2025-09-30 04:44:14 -04:00

patch 8.1.2387: using old C style comments

Problem:    Using old C style comments.
Solution:   Use // comments where appropriate.
This commit is contained in:
Bram Moolenaar
2019-12-04 21:24:53 +01:00
parent 9834b96820
commit 2ab2e8608f
12 changed files with 1349 additions and 1335 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -30,18 +30,18 @@
#include "vim.h" #include "vim.h"
#if 0 #if 0
# define HT_DEBUG /* extra checks for table consistency and statistics */ # define HT_DEBUG // extra checks for table consistency and statistics
static long hash_count_lookup = 0; /* count number of hashtab lookups */ static long hash_count_lookup = 0; // count number of hashtab lookups
static long hash_count_perturb = 0; /* count number of "misses" */ static long hash_count_perturb = 0; // count number of "misses"
#endif #endif
/* Magic value for algorithm that walks through the array. */ // Magic value for algorithm that walks through the array.
#define PERTURB_SHIFT 5 #define PERTURB_SHIFT 5
static int hash_may_resize(hashtab_T *ht, int minitems); static int hash_may_resize(hashtab_T *ht, int minitems);
#if 0 /* currently not used */ #if 0 // currently not used
/* /*
* Create an empty hash table. * Create an empty hash table.
* Returns NULL when out of memory. * Returns NULL when out of memory.
@@ -64,7 +64,7 @@ hash_create(void)
void void
hash_init(hashtab_T *ht) hash_init(hashtab_T *ht)
{ {
/* This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". */ // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray".
vim_memset(ht, 0, sizeof(hashtab_T)); vim_memset(ht, 0, sizeof(hashtab_T));
ht->ht_array = ht->ht_smallarray; ht->ht_array = ht->ht_smallarray;
ht->ht_mask = HT_INIT_SIZE - 1; ht->ht_mask = HT_INIT_SIZE - 1;
@@ -165,7 +165,7 @@ hash_lookup(hashtab_T *ht, char_u *key, hash_T hash)
for (perturb = hash; ; perturb >>= PERTURB_SHIFT) for (perturb = hash; ; perturb >>= PERTURB_SHIFT)
{ {
#ifdef HT_DEBUG #ifdef HT_DEBUG
++hash_count_perturb; /* count a "miss" for hashtab lookup */ ++hash_count_perturb; // count a "miss" for hashtab lookup
#endif #endif
idx = (unsigned)((idx << 2U) + idx + perturb + 1U); idx = (unsigned)((idx << 2U) + idx + perturb + 1U);
hi = &ht->ht_array[idx & ht->ht_mask]; hi = &ht->ht_array[idx & ht->ht_mask];
@@ -231,7 +231,7 @@ hash_add_item(
char_u *key, char_u *key,
hash_T hash) hash_T hash)
{ {
/* If resizing failed before and it fails again we can't add an item. */ // If resizing failed before and it fails again we can't add an item.
if (ht->ht_error && hash_may_resize(ht, 0) == FAIL) if (ht->ht_error && hash_may_resize(ht, 0) == FAIL)
return FAIL; return FAIL;
@@ -241,11 +241,11 @@ hash_add_item(
hi->hi_key = key; hi->hi_key = key;
hi->hi_hash = hash; hi->hi_hash = hash;
/* When the space gets low may resize the array. */ // When the space gets low may resize the array.
return hash_may_resize(ht, 0); return hash_may_resize(ht, 0);
} }
#if 0 /* not used */ #if 0 // not used
/* /*
* Overwrite hashtable item "hi" with "key". "hi" must point to the item that * Overwrite hashtable item "hi" with "key". "hi" must point to the item that
* is to be overwritten. Thus the number of items in the hashtable doesn't * is to be overwritten. Thus the number of items in the hashtable doesn't
@@ -318,7 +318,7 @@ hash_unlock(hashtab_T *ht)
static int static int
hash_may_resize( hash_may_resize(
hashtab_T *ht, hashtab_T *ht,
int minitems) /* minimal number of items */ int minitems) // minimal number of items
{ {
hashitem_T temparray[HT_INIT_SIZE]; hashitem_T temparray[HT_INIT_SIZE];
hashitem_T *oldarray, *newarray; hashitem_T *oldarray, *newarray;
@@ -330,7 +330,7 @@ hash_may_resize(
long_u newmask; long_u newmask;
hash_T perturb; hash_T perturb;
/* Don't resize a locked table. */ // Don't resize a locked table.
if (ht->ht_locked > 0) if (ht->ht_locked > 0)
return OK; return OK;
@@ -343,8 +343,8 @@ hash_may_resize(
if (minitems == 0) if (minitems == 0)
{ {
/* Return quickly for small tables with at least two NULL items. NULL // Return quickly for small tables with at least two NULL items. NULL
* items are required for the lookup to decide a key isn't there. */ // items are required for the lookup to decide a key isn't there.
if (ht->ht_filled < HT_INIT_SIZE - 1 if (ht->ht_filled < HT_INIT_SIZE - 1
&& ht->ht_array == ht->ht_smallarray) && ht->ht_array == ht->ht_smallarray)
return OK; return OK;
@@ -360,9 +360,9 @@ hash_may_resize(
return OK; return OK;
if (ht->ht_used > 1000) if (ht->ht_used > 1000)
minsize = ht->ht_used * 2; /* it's big, don't make too much room */ minsize = ht->ht_used * 2; // it's big, don't make too much room
else else
minsize = ht->ht_used * 4; /* make plenty of room */ minsize = ht->ht_used * 4; // make plenty of room
} }
else else
{ {
@@ -375,20 +375,20 @@ hash_may_resize(
newsize = HT_INIT_SIZE; newsize = HT_INIT_SIZE;
while (newsize < minsize) while (newsize < minsize)
{ {
newsize <<= 1; /* make sure it's always a power of 2 */ newsize <<= 1; // make sure it's always a power of 2
if (newsize == 0) if (newsize == 0)
return FAIL; /* overflow */ return FAIL; // overflow
} }
if (newsize == HT_INIT_SIZE) if (newsize == HT_INIT_SIZE)
{ {
/* Use the small array inside the hashdict structure. */ // Use the small array inside the hashdict structure.
newarray = ht->ht_smallarray; newarray = ht->ht_smallarray;
if (ht->ht_array == newarray) if (ht->ht_array == newarray)
{ {
/* Moving from ht_smallarray to ht_smallarray! Happens when there // Moving from ht_smallarray to ht_smallarray! Happens when there
* are many removed items. Copy the items to be able to clean up // are many removed items. Copy the items to be able to clean up
* removed items. */ // removed items.
mch_memmove(temparray, newarray, sizeof(temparray)); mch_memmove(temparray, newarray, sizeof(temparray));
oldarray = temparray; oldarray = temparray;
} }
@@ -397,13 +397,13 @@ hash_may_resize(
} }
else else
{ {
/* Allocate an array. */ // Allocate an array.
newarray = ALLOC_MULT(hashitem_T, newsize); newarray = ALLOC_MULT(hashitem_T, newsize);
if (newarray == NULL) if (newarray == NULL)
{ {
/* Out of memory. When there are NULL items still return OK. // Out of memory. When there are NULL items still return OK.
* Otherwise set ht_error, because lookup may result in a hang if // Otherwise set ht_error, because lookup may result in a hang if
* we add another item. */ // we add another item.
if (ht->ht_filled < ht->ht_mask) if (ht->ht_filled < ht->ht_mask)
return OK; return OK;
ht->ht_error = TRUE; ht->ht_error = TRUE;
@@ -470,8 +470,8 @@ hash_hash(char_u *key)
return (hash_T)0; return (hash_T)0;
p = key + 1; p = key + 1;
/* A simplistic algorithm that appears to do very well. // A simplistic algorithm that appears to do very well.
* Suggested by George Reilly. */ // Suggested by George Reilly.
while (*p != NUL) while (*p != NUL)
hash = hash * 101 + *p++; hash = hash * 101 + *p++;

File diff suppressed because it is too large Load Diff

View File

@@ -15,8 +15,8 @@
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
/* Only do the following when the feature is enabled. Needed for "make // Only do the following when the feature is enabled. Needed for "make
* depend". */ // depend".
#if defined(FEAT_LUA) || defined(PROTO) #if defined(FEAT_LUA) || defined(PROTO)
#define LUAVIM_CHUNKNAME "vim chunk" #define LUAVIM_CHUNKNAME "vim chunk"
@@ -45,9 +45,9 @@ static const char LUAVIM_FREE[] = "luaV_free";
static const char LUAVIM_LUAEVAL[] = "luaV_luaeval"; static const char LUAVIM_LUAEVAL[] = "luaV_luaeval";
static const char LUAVIM_SETREF[] = "luaV_setref"; static const char LUAVIM_SETREF[] = "luaV_setref";
/* most functions are closures with a cache table as first upvalue; // most functions are closures with a cache table as first upvalue;
* get/setudata manage references to vim userdata in cache table through // get/setudata manage references to vim userdata in cache table through
* object pointers (light userdata) */ // object pointers (light userdata)
#define luaV_getudata(L, v) \ #define luaV_getudata(L, v) \
lua_pushlightuserdata((L), (void *) (v)); \ lua_pushlightuserdata((L), (void *) (v)); \
lua_rawget((L), lua_upvalueindex(1)) lua_rawget((L), lua_upvalueindex(1))
@@ -94,7 +94,7 @@ static luaV_Funcref *luaV_pushfuncref(lua_State *L, char_u *name);
# define close_dll FreeLibrary # define close_dll FreeLibrary
#endif #endif
/* lauxlib */ // lauxlib
#if LUA_VERSION_NUM <= 501 #if LUA_VERSION_NUM <= 501
#define luaL_register dll_luaL_register #define luaL_register dll_luaL_register
#define luaL_prepbuffer dll_luaL_prepbuffer #define luaL_prepbuffer dll_luaL_prepbuffer
@@ -119,7 +119,7 @@ static luaV_Funcref *luaV_pushfuncref(lua_State *L, char_u *name);
#define luaL_buffinit dll_luaL_buffinit #define luaL_buffinit dll_luaL_buffinit
#define luaL_addlstring dll_luaL_addlstring #define luaL_addlstring dll_luaL_addlstring
#define luaL_pushresult dll_luaL_pushresult #define luaL_pushresult dll_luaL_pushresult
/* lua */ // lua
#if LUA_VERSION_NUM <= 501 #if LUA_VERSION_NUM <= 501
#define lua_tonumber dll_lua_tonumber #define lua_tonumber dll_lua_tonumber
#define lua_tointeger dll_lua_tointeger #define lua_tointeger dll_lua_tointeger
@@ -177,7 +177,7 @@ static luaV_Funcref *luaV_pushfuncref(lua_State *L, char_u *name);
#define lua_rawseti dll_lua_rawseti #define lua_rawseti dll_lua_rawseti
#define lua_setmetatable dll_lua_setmetatable #define lua_setmetatable dll_lua_setmetatable
#define lua_next dll_lua_next #define lua_next dll_lua_next
/* libs */ // libs
#define luaopen_base dll_luaopen_base #define luaopen_base dll_luaopen_base
#define luaopen_table dll_luaopen_table #define luaopen_table dll_luaopen_table
#define luaopen_string dll_luaopen_string #define luaopen_string dll_luaopen_string
@@ -188,7 +188,7 @@ static luaV_Funcref *luaV_pushfuncref(lua_State *L, char_u *name);
#define luaopen_debug dll_luaopen_debug #define luaopen_debug dll_luaopen_debug
#define luaL_openlibs dll_luaL_openlibs #define luaL_openlibs dll_luaL_openlibs
/* lauxlib */ // lauxlib
#if LUA_VERSION_NUM <= 501 #if LUA_VERSION_NUM <= 501
void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l); void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l);
char *(*dll_luaL_prepbuffer) (luaL_Buffer *B); char *(*dll_luaL_prepbuffer) (luaL_Buffer *B);
@@ -213,7 +213,7 @@ lua_State *(*dll_luaL_newstate) (void);
void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B); void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B);
void (*dll_luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); void (*dll_luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
void (*dll_luaL_pushresult) (luaL_Buffer *B); void (*dll_luaL_pushresult) (luaL_Buffer *B);
/* lua */ // lua
#if LUA_VERSION_NUM <= 501 #if LUA_VERSION_NUM <= 501
lua_Number (*dll_lua_tonumber) (lua_State *L, int idx); lua_Number (*dll_lua_tonumber) (lua_State *L, int idx);
lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx); lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx);
@@ -282,7 +282,7 @@ void (*dll_lua_rawseti) (lua_State *L, int idx, lua_Integer n);
#endif #endif
int (*dll_lua_setmetatable) (lua_State *L, int objindex); int (*dll_lua_setmetatable) (lua_State *L, int objindex);
int (*dll_lua_next) (lua_State *L, int idx); int (*dll_lua_next) (lua_State *L, int idx);
/* libs */ // libs
int (*dll_luaopen_base) (lua_State *L); int (*dll_luaopen_base) (lua_State *L);
int (*dll_luaopen_table) (lua_State *L); int (*dll_luaopen_table) (lua_State *L);
int (*dll_luaopen_string) (lua_State *L); int (*dll_luaopen_string) (lua_State *L);
@@ -300,7 +300,7 @@ typedef struct {
} luaV_Reg; } luaV_Reg;
static const luaV_Reg luaV_dll[] = { static const luaV_Reg luaV_dll[] = {
/* lauxlib */ // lauxlib
#if LUA_VERSION_NUM <= 501 #if LUA_VERSION_NUM <= 501
{"luaL_register", (luaV_function) &dll_luaL_register}, {"luaL_register", (luaV_function) &dll_luaL_register},
{"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer}, {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer},
@@ -325,7 +325,7 @@ static const luaV_Reg luaV_dll[] = {
{"luaL_buffinit", (luaV_function) &dll_luaL_buffinit}, {"luaL_buffinit", (luaV_function) &dll_luaL_buffinit},
{"luaL_addlstring", (luaV_function) &dll_luaL_addlstring}, {"luaL_addlstring", (luaV_function) &dll_luaL_addlstring},
{"luaL_pushresult", (luaV_function) &dll_luaL_pushresult}, {"luaL_pushresult", (luaV_function) &dll_luaL_pushresult},
/* lua */ // lua
#if LUA_VERSION_NUM <= 501 #if LUA_VERSION_NUM <= 501
{"lua_tonumber", (luaV_function) &dll_lua_tonumber}, {"lua_tonumber", (luaV_function) &dll_lua_tonumber},
{"lua_tointeger", (luaV_function) &dll_lua_tointeger}, {"lua_tointeger", (luaV_function) &dll_lua_tointeger},
@@ -383,7 +383,7 @@ static const luaV_Reg luaV_dll[] = {
{"lua_rawseti", (luaV_function) &dll_lua_rawseti}, {"lua_rawseti", (luaV_function) &dll_lua_rawseti},
{"lua_setmetatable", (luaV_function) &dll_lua_setmetatable}, {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
{"lua_next", (luaV_function) &dll_lua_next}, {"lua_next", (luaV_function) &dll_lua_next},
/* libs */ // libs
{"luaopen_base", (luaV_function) &dll_luaopen_base}, {"luaopen_base", (luaV_function) &dll_luaopen_base},
{"luaopen_table", (luaV_function) &dll_luaopen_table}, {"luaopen_table", (luaV_function) &dll_luaopen_table},
{"luaopen_string", (luaV_function) &dll_luaopen_string}, {"luaopen_string", (luaV_function) &dll_luaopen_string},
@@ -433,7 +433,7 @@ lua_link_init(char *libname, int verbose)
} }
return OK; return OK;
} }
#endif /* DYNAMIC_LUA */ #endif // DYNAMIC_LUA
#if defined(DYNAMIC_LUA) || defined(PROTO) #if defined(DYNAMIC_LUA) || defined(PROTO)
int int
@@ -454,7 +454,7 @@ luaL_typeerror(lua_State *L, int narg, const char *tname)
#endif #endif
/* ======= Internal ======= */ // ======= Internal =======
static void static void
luaV_newmetatable(lua_State *L, const char *tname) luaV_newmetatable(lua_State *L, const char *tname)
@@ -470,14 +470,14 @@ luaV_toudata(lua_State *L, int ud, const char *tname)
{ {
void *p = lua_touserdata(L, ud); void *p = lua_touserdata(L, ud);
if (p != NULL) /* value is userdata? */ if (p != NULL) // value is userdata?
{ {
if (lua_getmetatable(L, ud)) /* does it have a metatable? */ if (lua_getmetatable(L, ud)) // does it have a metatable?
{ {
luaV_getfield(L, tname); /* get metatable */ luaV_getfield(L, tname); // get metatable
if (lua_rawequal(L, -1, -2)) /* MTs match? */ if (lua_rawequal(L, -1, -2)) // MTs match?
{ {
lua_pop(L, 2); /* MTs */ lua_pop(L, 2); // MTs
return p; return p;
} }
} }
@@ -643,8 +643,10 @@ luaV_totypval(lua_State *L, int pos, typval_T *tv)
return status; return status;
} }
/* similar to luaL_addlstring, but replaces \0 with \n if toline and /*
* \n with \0 otherwise */ * similar to luaL_addlstring, but replaces \0 with \n if toline and
* \n with \0 otherwise
*/
static void static void
luaV_addlstring(luaL_Buffer *b, const char *s, size_t l, int toline) luaV_addlstring(luaL_Buffer *b, const char *s, size_t l, int toline)
{ {
@@ -683,8 +685,10 @@ luaV_toline(lua_State *L, int pos)
return (char_u *) lua_tostring(L, -1); return (char_u *) lua_tostring(L, -1);
} }
/* pops a string s from the top of the stack and calls mf(t) for pieces t of /*
* s separated by newlines */ * pops a string s from the top of the stack and calls mf(t) for pieces t of
* s separated by newlines
*/
static void static void
luaV_msgfunc(lua_State *L, msgfunc_T mf) luaV_msgfunc(lua_State *L, msgfunc_T mf)
{ {
@@ -694,18 +698,18 @@ luaV_msgfunc(lua_State *L, msgfunc_T mf)
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
luaV_addlstring(&b, s, l, 0); luaV_addlstring(&b, s, l, 0);
luaL_pushresult(&b); luaL_pushresult(&b);
/* break string */ // break string
p = s = lua_tolstring(L, -1, &l); p = s = lua_tolstring(L, -1, &l);
while (l--) while (l--)
{ {
if (*p++ == '\0') /* break? */ if (*p++ == '\0') // break?
{ {
mf((char_u *) s); mf((char_u *) s);
s = p; s = p;
} }
} }
mf((char_u *) s); mf((char_u *) s);
lua_pop(L, 2); /* original and modified strings */ lua_pop(L, 2); // original and modified strings
} }
#define luaV_newtype(typ,tname,luatyp,luatname) \ #define luaV_newtype(typ,tname,luatyp,luatname) \
@@ -748,15 +752,15 @@ luaV_msgfunc(lua_State *L, msgfunc_T mf)
return 1; \ return 1; \
} }
/* ======= List type ======= */ // ======= List type =======
static luaV_List * static luaV_List *
luaV_newlist(lua_State *L, list_T *lis) luaV_newlist(lua_State *L, list_T *lis)
{ {
luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List)); luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List));
*l = lis; *l = lis;
lis->lv_refcount++; /* reference in Lua */ lis->lv_refcount++; // reference in Lua
luaV_setudata(L, lis); /* cache[lis] = udata */ luaV_setudata(L, lis); // cache[lis] = udata
luaV_getfield(L, LUAVIM_LIST); luaV_getfield(L, LUAVIM_LIST);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
return l; return l;
@@ -788,7 +792,7 @@ luaV_list_iter(lua_State *L)
luaV_list_call(lua_State *L) luaV_list_call(lua_State *L)
{ {
list_T *l = luaV_unbox(L, luaV_List, 1); list_T *l = luaV_unbox(L, luaV_List, 1);
lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */ lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along
lua_pushlightuserdata(L, (void *) l->lv_first); lua_pushlightuserdata(L, (void *) l->lv_first);
lua_pushcclosure(L, luaV_list_iter, 2); lua_pushcclosure(L, luaV_list_iter, 2);
return 1; return 1;
@@ -798,7 +802,7 @@ luaV_list_call(lua_State *L)
luaV_list_index(lua_State *L) luaV_list_index(lua_State *L)
{ {
list_T *l = luaV_unbox(L, luaV_List, 1); list_T *l = luaV_unbox(L, luaV_List, 1);
if (lua_isnumber(L, 2)) /* list item? */ if (lua_isnumber(L, 2)) // list item?
{ {
listitem_T *li = list_find(l, (long) luaL_checkinteger(L, 2)); listitem_T *li = list_find(l, (long) luaL_checkinteger(L, 2));
if (li == NULL) if (li == NULL)
@@ -806,7 +810,7 @@ luaV_list_index(lua_State *L)
else else
luaV_pushtypval(L, &li->li_tv); luaV_pushtypval(L, &li->li_tv);
} }
else if (lua_isstring(L, 2)) /* method? */ else if (lua_isstring(L, 2)) // method?
{ {
const char *s = lua_tostring(L, 2); const char *s = lua_tostring(L, 2);
if (strncmp(s, "add", 3) == 0 if (strncmp(s, "add", 3) == 0
@@ -833,7 +837,7 @@ luaV_list_newindex(lua_State *L)
luaL_error(L, "list is locked"); luaL_error(L, "list is locked");
li = list_find(l, n); li = list_find(l, n);
if (li == NULL) return 0; if (li == NULL) return 0;
if (lua_isnil(L, 3)) /* remove? */ if (lua_isnil(L, 3)) // remove?
{ {
vimlist_remove(l, li, li); vimlist_remove(l, li, li);
clear_tv(&li->li_tv); clear_tv(&li->li_tv);
@@ -904,15 +908,15 @@ static const luaL_Reg luaV_List_mt[] = {
}; };
/* ======= Dict type ======= */ // ======= Dict type =======
static luaV_Dict * static luaV_Dict *
luaV_newdict(lua_State *L, dict_T *dic) luaV_newdict(lua_State *L, dict_T *dic)
{ {
luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict)); luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict));
*d = dic; *d = dic;
dic->dv_refcount++; /* reference in Lua */ dic->dv_refcount++; // reference in Lua
luaV_setudata(L, dic); /* cache[dic] = udata */ luaV_setudata(L, dic); // cache[dic] = udata
luaV_getfield(L, LUAVIM_DICT); luaV_getfield(L, LUAVIM_DICT);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
return d; return d;
@@ -956,9 +960,9 @@ luaV_dict_call(lua_State *L)
{ {
dict_T *d = luaV_unbox(L, luaV_Dict, 1); dict_T *d = luaV_unbox(L, luaV_Dict, 1);
hashtab_T *ht = &d->dv_hashtab; hashtab_T *ht = &d->dv_hashtab;
lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */ lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along
lua_pushlightuserdata(L, (void *) ht->ht_array); lua_pushlightuserdata(L, (void *) ht->ht_array);
lua_pushinteger(L, ht->ht_used); /* # remaining items */ lua_pushinteger(L, ht->ht_used); // # remaining items
lua_pushcclosure(L, luaV_dict_iter, 3); lua_pushcclosure(L, luaV_dict_iter, 3);
return 1; return 1;
} }
@@ -975,10 +979,10 @@ luaV_dict_index(lua_State *L)
else else
{ {
luaV_pushtypval(L, &di->di_tv); luaV_pushtypval(L, &di->di_tv);
if (di->di_tv.v_type == VAR_FUNC) /* funcref? */ if (di->di_tv.v_type == VAR_FUNC) // funcref?
{ {
luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1); luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1);
f->self = d; /* keep "self" reference */ f->self = d; // keep "self" reference
d->dv_refcount++; d->dv_refcount++;
} }
} }
@@ -999,14 +1003,14 @@ luaV_dict_newindex(lua_State *L)
return 0; return 0;
if (*key == NUL) if (*key == NUL)
luaL_error(L, "empty key"); luaL_error(L, "empty key");
if (!lua_isnil(L, 3)) /* read value? */ if (!lua_isnil(L, 3)) // read value?
{ {
luaV_checktypval(L, 3, &v, "setting dict item"); luaV_checktypval(L, 3, &v, "setting dict item");
if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC) if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC)
luaL_error(L, "cannot assign funcref to builtin scope"); luaL_error(L, "cannot assign funcref to builtin scope");
} }
di = dict_find(d, key, -1); di = dict_find(d, key, -1);
if (di == NULL) /* non-existing key? */ if (di == NULL) // non-existing key?
{ {
if (lua_isnil(L, 3)) if (lua_isnil(L, 3))
return 0; return 0;
@@ -1021,7 +1025,7 @@ luaV_dict_newindex(lua_State *L)
} }
else else
clear_tv(&di->di_tv); clear_tv(&di->di_tv);
if (lua_isnil(L, 3)) /* remove? */ if (lua_isnil(L, 3)) // remove?
{ {
hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key); hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key);
hash_remove(&d->dv_hashtab, hi); hash_remove(&d->dv_hashtab, hi);
@@ -1045,15 +1049,15 @@ static const luaL_Reg luaV_Dict_mt[] = {
}; };
/* ======= Blob type ======= */ // ======= Blob type =======
static luaV_Blob * static luaV_Blob *
luaV_newblob(lua_State *L, blob_T *blo) luaV_newblob(lua_State *L, blob_T *blo)
{ {
luaV_Blob *b = (luaV_Blob *) lua_newuserdata(L, sizeof(luaV_Blob)); luaV_Blob *b = (luaV_Blob *) lua_newuserdata(L, sizeof(luaV_Blob));
*b = blo; *b = blo;
blo->bv_refcount++; /* reference in Lua */ blo->bv_refcount++; // reference in Lua
luaV_setudata(L, blo); /* cache[blo] = udata */ luaV_setudata(L, blo); // cache[blo] = udata
luaV_getfield(L, LUAVIM_BLOB); luaV_getfield(L, LUAVIM_BLOB);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
return b; return b;
@@ -1163,7 +1167,7 @@ static const luaL_Reg luaV_Blob_mt[] = {
}; };
/* ======= Funcref type ======= */ // ======= Funcref type =======
static luaV_Funcref * static luaV_Funcref *
luaV_newfuncref(lua_State *L, char_u *name) luaV_newfuncref(lua_State *L, char_u *name)
@@ -1202,7 +1206,7 @@ luaV_funcref_gc(lua_State *L)
return 0; return 0;
} }
/* equivalent to string(funcref) */ // equivalent to string(funcref)
static int static int
luaV_funcref_len(lua_State *L) luaV_funcref_len(lua_State *L)
{ {
@@ -1254,7 +1258,7 @@ static const luaL_Reg luaV_Funcref_mt[] = {
}; };
/* ======= Buffer type ======= */ // ======= Buffer type =======
luaV_newtype(buf_T, buffer, luaV_Buffer, LUAVIM_BUFFER) luaV_newtype(buf_T, buffer, luaV_Buffer, LUAVIM_BUFFER)
luaV_pushtype(buf_T, buffer, luaV_Buffer) luaV_pushtype(buf_T, buffer, luaV_Buffer)
@@ -1295,7 +1299,7 @@ luaV_buffer_index(lua_State *L)
? "" : (char *) b->b_ffname); ? "" : (char *) b->b_ffname);
else if (strncmp(s, "number", 6) == 0) else if (strncmp(s, "number", 6) == 0)
lua_pushinteger(L, b->b_fnum); lua_pushinteger(L, b->b_fnum);
/* methods */ // methods
else if (strncmp(s, "insert", 6) == 0 else if (strncmp(s, "insert", 6) == 0
|| strncmp(s, "next", 4) == 0 || strncmp(s, "next", 4) == 0
|| strncmp(s, "previous", 8) == 0 || strncmp(s, "previous", 8) == 0
@@ -1322,7 +1326,7 @@ luaV_buffer_newindex(lua_State *L)
#endif #endif
if (n < 1 || n > b->b_ml.ml_line_count) if (n < 1 || n > b->b_ml.ml_line_count)
luaL_error(L, "invalid line number"); luaL_error(L, "invalid line number");
if (lua_isnil(L, 3)) /* delete line */ if (lua_isnil(L, 3)) // delete line
{ {
buf_T *buf = curbuf; buf_T *buf = curbuf;
curbuf = b; curbuf = b;
@@ -1339,7 +1343,7 @@ luaV_buffer_newindex(lua_State *L)
else else
{ {
deleted_lines_mark(n, 1L); deleted_lines_mark(n, 1L);
if (b == curwin->w_buffer) /* fix cursor in current window? */ if (b == curwin->w_buffer) // fix cursor in current window?
{ {
if (curwin->w_cursor.lnum >= n) if (curwin->w_cursor.lnum >= n)
{ {
@@ -1356,7 +1360,7 @@ luaV_buffer_newindex(lua_State *L)
} }
curbuf = buf; curbuf = buf;
} }
else if (lua_isstring(L, 3)) /* update line */ else if (lua_isstring(L, 3)) // update line
{ {
buf_T *buf = curbuf; buf_T *buf = curbuf;
curbuf = b; curbuf = b;
@@ -1392,10 +1396,10 @@ luaV_buffer_insert(lua_State *L)
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
luaV_checksandbox(L); luaV_checksandbox(L);
#endif #endif
/* fix insertion line */ // fix insertion line
if (n < 0) n = 0; if (n < 0) n = 0;
if (n > last) n = last; if (n > last) n = last;
/* insert */ // insert
buf = curbuf; buf = curbuf;
curbuf = b; curbuf = b;
if (u_save(n, n + 1) == FAIL) if (u_save(n, n + 1) == FAIL)
@@ -1456,7 +1460,7 @@ static const luaL_Reg luaV_Buffer_mt[] = {
}; };
/* ======= Window type ======= */ // ======= Window type =======
luaV_newtype(win_T, window, luaV_Window, LUAVIM_WINDOW) luaV_newtype(win_T, window, luaV_Window, LUAVIM_WINDOW)
luaV_pushtype(win_T, window, luaV_Window) luaV_pushtype(win_T, window, luaV_Window)
@@ -1486,7 +1490,7 @@ luaV_window_index(lua_State *L)
lua_pushinteger(L, w->w_width); lua_pushinteger(L, w->w_width);
else if (strncmp(s, "height", 6) == 0) else if (strncmp(s, "height", 6) == 0)
lua_pushinteger(L, w->w_height); lua_pushinteger(L, w->w_height);
/* methods */ // methods
else if (strncmp(s, "next", 4) == 0 else if (strncmp(s, "next", 4) == 0
|| strncmp(s, "previous", 8) == 0 || strncmp(s, "previous", 8) == 0
|| strncmp(s, "isvalid", 7) == 0) || strncmp(s, "isvalid", 7) == 0)
@@ -1588,12 +1592,12 @@ static const luaL_Reg luaV_Window_mt[] = {
}; };
/* ======= Vim module ======= */ // ======= Vim module =======
static int static int
luaV_print(lua_State *L) luaV_print(lua_State *L)
{ {
int i, n = lua_gettop(L); /* nargs */ int i, n = lua_gettop(L); // nargs
const char *s; const char *s;
size_t l; size_t l;
luaL_Buffer b; luaL_Buffer b;
@@ -1601,13 +1605,13 @@ luaV_print(lua_State *L)
lua_getglobal(L, "tostring"); lua_getglobal(L, "tostring");
for (i = 1; i <= n; i++) for (i = 1; i <= n; i++)
{ {
lua_pushvalue(L, -1); /* tostring */ lua_pushvalue(L, -1); // tostring
lua_pushvalue(L, i); /* arg */ lua_pushvalue(L, i); // arg
lua_call(L, 1, 1); lua_call(L, 1, 1);
s = lua_tolstring(L, -1, &l); s = lua_tolstring(L, -1, &l);
if (s == NULL) if (s == NULL)
return luaL_error(L, "cannot convert to string"); return luaL_error(L, "cannot convert to string");
if (i > 1) luaL_addchar(&b, ' '); /* use space instead of tab */ if (i > 1) luaL_addchar(&b, ' '); // use space instead of tab
luaV_addlstring(&b, s, l, 0); luaV_addlstring(&b, s, l, 0);
lua_pop(L, 1); lua_pop(L, 1);
} }
@@ -1623,22 +1627,22 @@ luaV_debug(lua_State *L)
lua_settop(L, 0); lua_settop(L, 0);
lua_getglobal(L, "vim"); lua_getglobal(L, "vim");
lua_getfield(L, -1, "eval"); lua_getfield(L, -1, "eval");
lua_remove(L, -2); /* vim.eval at position 1 */ lua_remove(L, -2); // vim.eval at position 1
for (;;) for (;;)
{ {
const char *input; const char *input;
size_t l; size_t l;
lua_pushvalue(L, 1); /* vim.eval */ lua_pushvalue(L, 1); // vim.eval
lua_pushliteral(L, "input('lua_debug> ')"); lua_pushliteral(L, "input('lua_debug> ')");
lua_call(L, 1, 1); /* return string */ lua_call(L, 1, 1); // return string
input = lua_tolstring(L, -1, &l); input = lua_tolstring(L, -1, &l);
if (l == 0 || strcmp(input, "cont") == 0) if (l == 0 || strcmp(input, "cont") == 0)
return 0; return 0;
msg_putchar('\n'); /* avoid outputting on input line */ msg_putchar('\n'); // avoid outputting on input line
if (luaL_loadbuffer(L, input, l, "=(debug command)") if (luaL_loadbuffer(L, input, l, "=(debug command)")
|| lua_pcall(L, 0, 0, 0)) || lua_pcall(L, 0, 0, 0))
luaV_emsg(L); luaV_emsg(L);
lua_settop(L, 1); /* remove eventual returns, but keep vim.eval */ lua_settop(L, 1); // remove eventual returns, but keep vim.eval
} }
} }
@@ -1688,7 +1692,7 @@ luaV_list(lua_State *L)
else else
{ {
luaV_newlist(L, l); luaV_newlist(L, l);
if (initarg) /* traverse table to init list */ if (initarg) // traverse table to init list
{ {
int notnil, i = 0; int notnil, i = 0;
typval_T v; typval_T v;
@@ -1702,7 +1706,7 @@ luaV_list(lua_State *L)
list_append_tv(l, &v); list_append_tv(l, &v);
clear_tv(&v); clear_tv(&v);
} }
lua_pop(L, 1); /* value */ lua_pop(L, 1); // value
} while (notnil); } while (notnil);
} }
} }
@@ -1723,7 +1727,7 @@ luaV_dict(lua_State *L)
else else
{ {
luaV_newdict(L, d); luaV_newdict(L, d);
if (initarg) /* traverse table to init dict */ if (initarg) // traverse table to init dict
{ {
lua_pushnil(L); lua_pushnil(L);
while (lua_next(L, 1)) while (lua_next(L, 1))
@@ -1732,7 +1736,7 @@ luaV_dict(lua_State *L)
dictitem_T *di; dictitem_T *di;
typval_T v; typval_T v;
lua_pushvalue(L, -2); /* dup key in case it's a number */ lua_pushvalue(L, -2); // dup key in case it's a number
key = (char_u *) lua_tostring(L, -1); key = (char_u *) lua_tostring(L, -1);
if (key == NULL) if (key == NULL)
{ {
@@ -1741,7 +1745,7 @@ luaV_dict(lua_State *L)
} }
if (*key == NUL) if (*key == NUL)
luaL_error(L, "table has empty key"); luaL_error(L, "table has empty key");
luaV_checktypval(L, -2, &v, "vim.dict"); /* value */ luaV_checktypval(L, -2, &v, "vim.dict"); // value
di = dictitem_alloc(key); di = dictitem_alloc(key);
if (di == NULL || dict_add(d, di) == FAIL) if (di == NULL || dict_add(d, di) == FAIL)
{ {
@@ -1751,7 +1755,7 @@ luaV_dict(lua_State *L)
} }
copy_tv(&v, &di->di_tv); copy_tv(&v, &di->di_tv);
clear_tv(&v); clear_tv(&v);
lua_pop(L, 2); /* key copy and value */ lua_pop(L, 2); // key copy and value
} }
} }
} }
@@ -1789,7 +1793,7 @@ luaV_blob(lua_State *L)
luaV_funcref(lua_State *L) luaV_funcref(lua_State *L)
{ {
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
/* note: not checking if function exists (needs function_exists) */ // note: not checking if function exists (needs function_exists)
if (name == NULL || *name == NUL || VIM_ISDIGIT(*name)) if (name == NULL || *name == NUL || VIM_ISDIGIT(*name))
luaL_error(L, "invalid function name: %s", name); luaL_error(L, "invalid function name: %s", name);
luaV_newfuncref(L, (char_u *) name); luaV_newfuncref(L, (char_u *) name);
@@ -1800,9 +1804,9 @@ luaV_funcref(lua_State *L)
luaV_buffer(lua_State *L) luaV_buffer(lua_State *L)
{ {
buf_T *buf; buf_T *buf;
if (lua_isstring(L, 1)) /* get by number or name? */ if (lua_isstring(L, 1)) // get by number or name?
{ {
if (lua_isnumber(L, 1)) /* by number? */ if (lua_isnumber(L, 1)) // by number?
{ {
int n = lua_tointeger(L, 1); int n = lua_tointeger(L, 1);
FOR_ALL_BUFFERS(buf) FOR_ALL_BUFFERS(buf)
@@ -1825,7 +1829,7 @@ luaV_buffer(lua_State *L)
} }
} }
else else
buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; /* first buffer? */ buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; // first buffer?
luaV_pushbuffer(L, buf); luaV_pushbuffer(L, buf);
return 1; return 1;
} }
@@ -1834,14 +1838,14 @@ luaV_buffer(lua_State *L)
luaV_window(lua_State *L) luaV_window(lua_State *L)
{ {
win_T *win; win_T *win;
if (lua_isnumber(L, 1)) /* get by number? */ if (lua_isnumber(L, 1)) // get by number?
{ {
int n = lua_tointeger(L, 1); int n = lua_tointeger(L, 1);
for (win = firstwin; win != NULL; win = win->w_next, n--) for (win = firstwin; win != NULL; win = win->w_next, n--)
if (n == 1) break; if (n == 1) break;
} }
else else
win = (lua_toboolean(L, 1)) ? firstwin : curwin; /* first window? */ win = (lua_toboolean(L, 1)) ? firstwin : curwin; // first window?
luaV_pushwindow(L, win); luaV_pushwindow(L, win);
return 1; return 1;
} }
@@ -1862,7 +1866,7 @@ luaV_open(lua_State *L)
luaV_type(lua_State *L) luaV_type(lua_State *L)
{ {
luaL_checkany(L, 1); luaL_checkany(L, 1);
if (lua_type(L, 1) == LUA_TUSERDATA) /* check vim udata? */ if (lua_type(L, 1) == LUA_TUSERDATA) // check vim udata?
{ {
lua_settop(L, 1); lua_settop(L, 1);
if (lua_getmetatable(L, 1)) if (lua_getmetatable(L, 1))
@@ -1905,7 +1909,7 @@ luaV_type(lua_State *L)
} }
} }
} }
lua_pushstring(L, luaL_typename(L, 1)); /* fallback */ lua_pushstring(L, luaL_typename(L, 1)); // fallback
return 1; return 1;
} }
@@ -1925,7 +1929,9 @@ static const luaL_Reg luaV_module[] = {
{NULL, NULL} {NULL, NULL}
}; };
/* for freeing list, dict, buffer and window objects; lightuserdata as arg */ /*
* for freeing list, dict, buffer and window objects; lightuserdata as arg
*/
static int static int
luaV_free(lua_State *L) luaV_free(lua_State *L)
{ {
@@ -1947,13 +1953,13 @@ luaV_luaeval(lua_State *L)
luaL_addlstring(&b, str, l); luaL_addlstring(&b, str, l);
luaL_pushresult(&b); luaL_pushresult(&b);
str = lua_tolstring(L, -1, &l); str = lua_tolstring(L, -1, &l);
if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) /* compile error? */ if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) // compile error?
{ {
luaV_emsg(L); luaV_emsg(L);
return 0; return 0;
} }
luaV_pushtypval(L, arg); luaV_pushtypval(L, arg);
if (lua_pcall(L, 1, 1, 0)) /* running error? */ if (lua_pcall(L, 1, 1, 0)) // running error?
{ {
luaV_emsg(L); luaV_emsg(L);
return 0; return 0;
@@ -2004,36 +2010,36 @@ luaV_setref(lua_State *L)
static int static int
luaopen_vim(lua_State *L) luaopen_vim(lua_State *L)
{ {
/* set cache table */ // set cache table
lua_newtable(L); lua_newtable(L);
lua_newtable(L); lua_newtable(L);
lua_pushstring(L, "v"); lua_pushstring(L, "v");
lua_setfield(L, -2, "__mode"); lua_setfield(L, -2, "__mode");
lua_setmetatable(L, -2); /* cache is weak-valued */ lua_setmetatable(L, -2); // cache is weak-valued
/* print */ // print
lua_pushcfunction(L, luaV_print); lua_pushcfunction(L, luaV_print);
lua_setglobal(L, "print"); lua_setglobal(L, "print");
/* debug.debug */ // debug.debug
lua_getglobal(L, "debug"); lua_getglobal(L, "debug");
lua_pushcfunction(L, luaV_debug); lua_pushcfunction(L, luaV_debug);
lua_setfield(L, -2, "debug"); lua_setfield(L, -2, "debug");
lua_pop(L, 1); lua_pop(L, 1);
/* free */ // free
lua_pushlightuserdata(L, (void *) LUAVIM_FREE); lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
lua_pushvalue(L, 1); /* cache table */ lua_pushvalue(L, 1); // cache table
lua_pushcclosure(L, luaV_free, 1); lua_pushcclosure(L, luaV_free, 1);
lua_rawset(L, LUA_REGISTRYINDEX); lua_rawset(L, LUA_REGISTRYINDEX);
/* luaeval */ // luaeval
lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL); lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL);
lua_pushvalue(L, 1); /* cache table */ lua_pushvalue(L, 1); // cache table
lua_pushcclosure(L, luaV_luaeval, 1); lua_pushcclosure(L, luaV_luaeval, 1);
lua_rawset(L, LUA_REGISTRYINDEX); lua_rawset(L, LUA_REGISTRYINDEX);
/* setref */ // setref
lua_pushlightuserdata(L, (void *) LUAVIM_SETREF); lua_pushlightuserdata(L, (void *) LUAVIM_SETREF);
lua_pushvalue(L, 1); /* cache table */ lua_pushvalue(L, 1); // cache table
lua_pushcclosure(L, luaV_setref, 1); lua_pushcclosure(L, luaV_setref, 1);
lua_rawset(L, LUA_REGISTRYINDEX); lua_rawset(L, LUA_REGISTRYINDEX);
/* register */ // register
luaV_newmetatable(L, LUAVIM_LIST); luaV_newmetatable(L, LUAVIM_LIST);
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
luaV_openlib(L, luaV_List_mt, 1); luaV_openlib(L, luaV_List_mt, 1);
@@ -2047,13 +2053,13 @@ luaopen_vim(lua_State *L)
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
luaV_openlib(L, luaV_Funcref_mt, 1); luaV_openlib(L, luaV_Funcref_mt, 1);
luaV_newmetatable(L, LUAVIM_BUFFER); luaV_newmetatable(L, LUAVIM_BUFFER);
lua_pushvalue(L, 1); /* cache table */ lua_pushvalue(L, 1); // cache table
luaV_openlib(L, luaV_Buffer_mt, 1); luaV_openlib(L, luaV_Buffer_mt, 1);
luaV_newmetatable(L, LUAVIM_WINDOW); luaV_newmetatable(L, LUAVIM_WINDOW);
lua_pushvalue(L, 1); /* cache table */ lua_pushvalue(L, 1); // cache table
luaV_openlib(L, luaV_Window_mt, 1); luaV_openlib(L, luaV_Window_mt, 1);
lua_newtable(L); /* vim table */ lua_newtable(L); // vim table
lua_pushvalue(L, 1); /* cache table */ lua_pushvalue(L, 1); // cache table
luaV_openlib(L, luaV_module, 1); luaV_openlib(L, luaV_module, 1);
lua_setglobal(L, LUAVIM_NAME); lua_setglobal(L, LUAVIM_NAME);
return 0; return 0;
@@ -2063,8 +2069,8 @@ luaopen_vim(lua_State *L)
luaV_newstate(void) luaV_newstate(void)
{ {
lua_State *L = luaL_newstate(); lua_State *L = luaL_newstate();
luaL_openlibs(L); /* core libs */ luaL_openlibs(L); // core libs
lua_pushcfunction(L, luaopen_vim); /* vim */ lua_pushcfunction(L, luaopen_vim); // vim
lua_call(L, 0, 0); lua_call(L, 0, 0);
return L; return L;
} }
@@ -2077,11 +2083,11 @@ luaV_setrange(lua_State *L, int line1, int line2)
lua_setfield(L, -2, "firstline"); lua_setfield(L, -2, "firstline");
lua_pushinteger(L, line2); lua_pushinteger(L, line2);
lua_setfield(L, -2, "lastline"); lua_setfield(L, -2, "lastline");
lua_pop(L, 1); /* vim table */ lua_pop(L, 1); // vim table
} }
/* ======= Interface ======= */ // ======= Interface =======
static lua_State *L = NULL; static lua_State *L = NULL;
@@ -2121,7 +2127,9 @@ lua_end(void)
} }
} }
/* ex commands */ /*
* ex commands
*/
void void
ex_lua(exarg_T *eap) ex_lua(exarg_T *eap)
{ {
@@ -2156,48 +2164,48 @@ ex_luado(exarg_T *eap)
} }
luaV_setrange(L, eap->line1, eap->line2); luaV_setrange(L, eap->line1, eap->line2);
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
luaL_addlstring(&b, "return function(line, linenr) ", 30); /* header */ luaL_addlstring(&b, "return function(line, linenr) ", 30); // header
luaL_addlstring(&b, s, strlen(s)); luaL_addlstring(&b, s, strlen(s));
luaL_addlstring(&b, " end", 4); /* footer */ luaL_addlstring(&b, " end", 4); // footer
luaL_pushresult(&b); luaL_pushresult(&b);
s = lua_tolstring(L, -1, &len); s = lua_tolstring(L, -1, &len);
if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME)) if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME))
{ {
luaV_emsg(L); luaV_emsg(L);
lua_pop(L, 1); /* function body */ lua_pop(L, 1); // function body
return; return;
} }
lua_call(L, 0, 1); lua_call(L, 0, 1);
lua_replace(L, -2); /* function -> body */ lua_replace(L, -2); // function -> body
for (l = eap->line1; l <= eap->line2; l++) for (l = eap->line1; l <= eap->line2; l++)
{ {
/* Check the line number, the command my have deleted lines. */ // Check the line number, the command my have deleted lines.
if (l > curbuf->b_ml.ml_line_count) if (l > curbuf->b_ml.ml_line_count)
break; break;
lua_pushvalue(L, -1); /* function */ lua_pushvalue(L, -1); // function
luaV_pushline(L, curbuf, l); /* current line as arg */ luaV_pushline(L, curbuf, l); // current line as arg
lua_pushinteger(L, l); /* current line number as arg */ lua_pushinteger(L, l); // current line number as arg
if (lua_pcall(L, 2, 1, 0)) if (lua_pcall(L, 2, 1, 0))
{ {
luaV_emsg(L); luaV_emsg(L);
break; break;
} }
/* Catch the command switching to another buffer. */ // Catch the command switching to another buffer.
if (curbuf != was_curbuf) if (curbuf != was_curbuf)
break; break;
if (lua_isstring(L, -1)) /* update line? */ if (lua_isstring(L, -1)) // update line?
{ {
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
luaV_checksandbox(L); luaV_checksandbox(L);
#endif #endif
ml_replace(l, luaV_toline(L, -1), TRUE); ml_replace(l, luaV_toline(L, -1), TRUE);
changed_bytes(l, 0); changed_bytes(l, 0);
lua_pop(L, 1); /* result from luaV_toline */ lua_pop(L, 1); // result from luaV_toline
} }
lua_pop(L, 1); /* line */ lua_pop(L, 1); // line
} }
lua_pop(L, 1); /* function */ lua_pop(L, 1); // function
check_cursor(); check_cursor();
update_screen(NOT_VALID); update_screen(NOT_VALID);
} }
@@ -2247,12 +2255,12 @@ set_ref_in_lua(int copyID)
if (lua_isopen()) if (lua_isopen())
{ {
luaV_getfield(L, LUAVIM_SETREF); luaV_getfield(L, LUAVIM_SETREF);
/* call the function with 1 arg, getting 1 result back */ // call the function with 1 arg, getting 1 result back
lua_pushinteger(L, copyID); lua_pushinteger(L, copyID);
lua_call(L, 1, 1); lua_call(L, 1, 1);
/* get the result */ // get the result
aborted = lua_tointeger(L, -1); aborted = lua_tointeger(L, -1);
/* pop result off the stack */ // pop result off the stack
lua_pop(L, 1); lua_pop(L, 1);
} }
return aborted; return aborted;

File diff suppressed because it is too large Load Diff

View File

@@ -10,14 +10,14 @@
* if_perlsfio.c: Special I/O functions for Perl interface. * if_perlsfio.c: Special I/O functions for Perl interface.
*/ */
#define _memory_h /* avoid memset redeclaration */ #define _memory_h // avoid memset redeclaration
#define IN_PERL_FILE /* don't include if_perl.pro from prot.h */ #define IN_PERL_FILE // don't include if_perl.pro from prot.h
#include "vim.h" #include "vim.h"
#if defined(USE_SFIO) || defined(PROTO) #if defined(USE_SFIO) || defined(PROTO)
#ifndef USE_SFIO /* just generating prototypes */ #ifndef USE_SFIO // just generating prototypes
# define Sfio_t int # define Sfio_t int
# define Sfdisc_t int # define Sfdisc_t int
#endif #endif
@@ -26,10 +26,10 @@
static int static int
sfvimwrite( sfvimwrite(
Sfio_t *f, /* stream involved */ Sfio_t *f, // stream involved
char *buf, /* buffer to read from */ char *buf, // buffer to read from
int n, /* number of bytes to write */ int n, // number of bytes to write
Sfdisc_t *disc) /* discipline */ Sfdisc_t *disc) // discipline
{ {
char_u *str; char_u *str;
@@ -63,4 +63,4 @@ sfdcnewvim(void)
return disc; return disc;
} }
#endif /* USE_SFIO */ #endif // USE_SFIO

View File

@@ -21,16 +21,15 @@
#include <limits.h> #include <limits.h>
/* uncomment this if used with the debug version of python. // uncomment this if used with the debug version of python.
* Checked on 2.7.4. */ // Checked on 2.7.4.
/* #define Py_DEBUG */ // #define Py_DEBUG
/* Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting // Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting
*/ // uncomment this if used with the debug version of python, but without its
/* uncomment this if used with the debug version of python, but without its // allocator
* allocator */ // #define Py_DEBUG_NO_PYMALLOC
/* #define Py_DEBUG_NO_PYMALLOC */
/* Python.h defines _POSIX_THREADS itself (if needed) */ // Python.h defines _POSIX_THREADS itself (if needed)
#ifdef _POSIX_THREADS #ifdef _POSIX_THREADS
# undef _POSIX_THREADS # undef _POSIX_THREADS
#endif #endif
@@ -53,13 +52,13 @@
# undef HAVE_PUTENV # undef HAVE_PUTENV
#endif #endif
#ifdef HAVE_STDARG_H #ifdef HAVE_STDARG_H
# undef HAVE_STDARG_H /* Python's config.h defines it as well. */ # undef HAVE_STDARG_H // Python's config.h defines it as well.
#endif #endif
#ifdef _POSIX_C_SOURCE #ifdef _POSIX_C_SOURCE
# undef _POSIX_C_SOURCE /* pyconfig.h defines it as well. */ # undef _POSIX_C_SOURCE // pyconfig.h defines it as well.
#endif #endif
#ifdef _XOPEN_SOURCE #ifdef _XOPEN_SOURCE
# undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ # undef _XOPEN_SOURCE // pyconfig.h defines it as well.
#endif #endif
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
@@ -70,8 +69,8 @@
# undef PY_SSIZE_T_CLEAN # undef PY_SSIZE_T_CLEAN
#endif #endif
#undef main /* Defined in python.h - aargh */ #undef main // Defined in python.h - aargh
#undef HAVE_FCNTL_H /* Clash with os_win32.h */ #undef HAVE_FCNTL_H // Clash with os_win32.h
// Perhaps leave this out for Python 2.6, which supports bytes? // Perhaps leave this out for Python 2.6, which supports bytes?
#define PyBytes_FromString PyString_FromString #define PyBytes_FromString PyString_FromString
@@ -80,7 +79,7 @@
#define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_FromStringAndSize PyString_FromStringAndSize
#if !defined(FEAT_PYTHON) && defined(PROTO) #if !defined(FEAT_PYTHON) && defined(PROTO)
/* Use this to be able to generate prototypes without python being used. */ // Use this to be able to generate prototypes without python being used.
# define PyObject Py_ssize_t # define PyObject Py_ssize_t
# define PyThreadState Py_ssize_t # define PyThreadState Py_ssize_t
# define PyTypeObject Py_ssize_t # define PyTypeObject Py_ssize_t
@@ -112,19 +111,19 @@ struct PyMethodDef { Py_ssize_t a; };
#endif #endif
#define Py_bytes_fmt "s" #define Py_bytes_fmt "s"
/* Parser flags */ // Parser flags
#define single_input 256 #define single_input 256
#define file_input 257 #define file_input 257
#define eval_input 258 #define eval_input 258
#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0
/* Python 2.3: can invoke ":python" recursively. */ // Python 2.3: can invoke ":python" recursively.
# define PY_CAN_RECURSE # define PY_CAN_RECURSE
#endif #endif
#if defined(DYNAMIC_PYTHON) || defined(PROTO) #if defined(DYNAMIC_PYTHON) || defined(PROTO)
# ifndef DYNAMIC_PYTHON # ifndef DYNAMIC_PYTHON
# define HINSTANCE long_u /* for generating prototypes */ # define HINSTANCE long_u // for generating prototypes
# endif # endif
# ifndef MSWIN # ifndef MSWIN
@@ -144,8 +143,8 @@ struct PyMethodDef { Py_ssize_t a; };
# define symbol_from_dll GetProcAddress # define symbol_from_dll GetProcAddress
# endif # endif
/* This makes if_python.c compile without warnings against Python 2.5 // This makes if_python.c compile without warnings against Python 2.5
* on Win32 and Win64. */ // on Win32 and Win64.
# undef PyRun_SimpleString # undef PyRun_SimpleString
# undef PyRun_String # undef PyRun_String
# undef PyArg_Parse # undef PyArg_Parse
@@ -456,9 +455,9 @@ static void* (*dll_PyCObject_AsVoidPtr)(PyObject *);
static int* dll_Py_NoSiteFlag; static int* dll_Py_NoSiteFlag;
# endif # endif
static HINSTANCE hinstPython = 0; /* Instance of python.dll */ static HINSTANCE hinstPython = 0; // Instance of python.dll
/* Imported exception objects */ // Imported exception objects
static PyObject *imp_PyExc_AttributeError; static PyObject *imp_PyExc_AttributeError;
static PyObject *imp_PyExc_IndexError; static PyObject *imp_PyExc_IndexError;
static PyObject *imp_PyExc_KeyError; static PyObject *imp_PyExc_KeyError;
@@ -681,9 +680,9 @@ python_runtime_link_init(char *libname, int verbose)
(PYTHON_PROC*)&py_PyUnicode_AsEncodedString; (PYTHON_PROC*)&py_PyUnicode_AsEncodedString;
# if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3) # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3)
/* Can't have Python and Python3 loaded at the same time. // Can't have Python and Python3 loaded at the same time.
* It cause a crash, because RTLD_GLOBAL is needed for // It cause a crash, because RTLD_GLOBAL is needed for
* standard C extension libraries of one or both python versions. */ // standard C extension libraries of one or both python versions.
if (python3_loaded()) if (python3_loaded())
{ {
if (verbose) if (verbose)
@@ -715,8 +714,8 @@ python_runtime_link_init(char *libname, int verbose)
} }
} }
/* Load unicode functions separately as only the ucs2 or the ucs4 functions // Load unicode functions separately as only the ucs2 or the ucs4 functions
* will be present in the library. */ // will be present in the library.
*ucs_as_encoded_string = symbol_from_dll(hinstPython, *ucs_as_encoded_string = symbol_from_dll(hinstPython,
"PyUnicodeUCS2_AsEncodedString"); "PyUnicodeUCS2_AsEncodedString");
if (*ucs_as_encoded_string == NULL) if (*ucs_as_encoded_string == NULL)
@@ -775,7 +774,7 @@ get_exceptions(void)
Py_XINCREF(imp_PyExc_OverflowError); Py_XINCREF(imp_PyExc_OverflowError);
Py_XDECREF(exmod); Py_XDECREF(exmod);
} }
#endif /* DYNAMIC_PYTHON */ #endif // DYNAMIC_PYTHON
static int initialised = 0; static int initialised = 0;
#define PYINITIALISED initialised #define PYINITIALISED initialised
@@ -830,18 +829,16 @@ typedef PySliceObject PySliceObject_T;
#include "if_py_both.h" #include "if_py_both.h"
/****************************************************** ///////////////////////////////////////////////////////
* Internal function prototypes. // Internal function prototypes.
*/
static int PythonMod_Init(void); static int PythonMod_Init(void);
/****************************************************** ///////////////////////////////////////////////////////
* 1. Python interpreter main program. // 1. Python interpreter main program.
*/
#if PYTHON_API_VERSION < 1007 /* Python 1.4 */ #if PYTHON_API_VERSION < 1007 // Python 1.4
typedef PyObject PyThreadState; typedef PyObject PyThreadState;
#endif #endif
@@ -875,7 +872,7 @@ python_end(void)
{ {
static int recurse = 0; static int recurse = 0;
/* If a crash occurs while doing this, don't try again. */ // If a crash occurs while doing this, don't try again.
if (recurse != 0) if (recurse != 0)
return; return;
@@ -888,7 +885,7 @@ python_end(void)
# ifdef PY_CAN_RECURSE # ifdef PY_CAN_RECURSE
PyGILState_Ensure(); PyGILState_Ensure();
# else # else
Python_RestoreThread(); /* enter python */ Python_RestoreThread(); // enter python
# endif # endif
Py_Finalize(); Py_Finalize();
} }
@@ -899,7 +896,7 @@ python_end(void)
# ifdef PY_CAN_RECURSE # ifdef PY_CAN_RECURSE
PyGILState_Ensure(); PyGILState_Ensure();
# else # else
Python_RestoreThread(); /* enter python */ Python_RestoreThread(); // enter python
# endif # endif
Py_Finalize(); Py_Finalize();
} }
@@ -937,7 +934,7 @@ Python_Init(void)
if (*p_pyhome != NUL) if (*p_pyhome != NUL)
{ {
/* The string must not change later, make a copy in static memory. */ // The string must not change later, make a copy in static memory.
py_home_buf = (char *)vim_strsave(p_pyhome); py_home_buf = (char *)vim_strsave(p_pyhome);
if (py_home_buf != NULL) if (py_home_buf != NULL)
Py_SetPythonHome(py_home_buf); Py_SetPythonHome(py_home_buf);
@@ -950,15 +947,15 @@ Python_Init(void)
init_structs(); init_structs();
#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
/* Disable implicit 'import site', because it may cause Vim to exit // Disable implicit 'import site', because it may cause Vim to exit
* when it can't be found. */ // when it can't be found.
Py_NoSiteFlag++; Py_NoSiteFlag++;
#endif #endif
Py_Initialize(); Py_Initialize();
#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
/* 'import site' explicitly. */ // 'import site' explicitly.
site = PyImport_ImportModule("site"); site = PyImport_ImportModule("site");
if (site == NULL) if (site == NULL)
{ {
@@ -968,10 +965,10 @@ Python_Init(void)
Py_DECREF(site); Py_DECREF(site);
#endif #endif
/* Initialise threads, and below save the state using // Initialise threads, and below save the state using
* PyEval_SaveThread. Without the call to PyEval_SaveThread, thread // PyEval_SaveThread. Without the call to PyEval_SaveThread, thread
* specific state (such as the system trace hook), will be lost // specific state (such as the system trace hook), will be lost
* between invocations of Python code. */ // between invocations of Python code.
PyEval_InitThreads(); PyEval_InitThreads();
#ifdef DYNAMIC_PYTHON #ifdef DYNAMIC_PYTHON
get_exceptions(); get_exceptions();
@@ -985,19 +982,18 @@ Python_Init(void)
globals = PyModule_GetDict(PyImport_AddModule("__main__")); globals = PyModule_GetDict(PyImport_AddModule("__main__"));
/* Remove the element from sys.path that was added because of our // Remove the element from sys.path that was added because of our
* argv[0] value in PythonMod_Init(). Previously we used an empty // argv[0] value in PythonMod_Init(). Previously we used an empty
* string, but depending on the OS we then get an empty entry or // string, but depending on the OS we then get an empty entry or
* the current directory in sys.path. */ // the current directory in sys.path.
PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)"); PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");
/* lock is created and acquired in PyEval_InitThreads() and thread // lock is created and acquired in PyEval_InitThreads() and thread
* state is created in Py_Initialize() // state is created in Py_Initialize()
* there _PyGILState_NoteThreadState() also sets gilcounter to 1 // there _PyGILState_NoteThreadState() also sets gilcounter to 1
* (python must have threads enabled!) // (python must have threads enabled!)
* so the following does both: unlock GIL and save thread state in TLS // so the following does both: unlock GIL and save thread state in TLS
* without deleting thread state // without deleting thread state
*/
#ifndef PY_CAN_RECURSE #ifndef PY_CAN_RECURSE
saved_python_thread = saved_python_thread =
#endif #endif
@@ -1009,11 +1005,10 @@ Python_Init(void)
return 0; return 0;
fail: fail:
/* We call PythonIO_Flush() here to print any Python errors. // We call PythonIO_Flush() here to print any Python errors.
* This is OK, as it is possible to call this function even // This is OK, as it is possible to call this function even
* if PythonIO_Init_io() has not completed successfully (it will // if PythonIO_Init_io() has not completed successfully (it will
* not do anything in this case). // not do anything in this case).
*/
PythonIO_Flush(); PythonIO_Flush();
return -1; return -1;
} }
@@ -1050,16 +1045,16 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
init_range(arg); init_range(arg);
Python_Release_Vim(); /* leave vim */ Python_Release_Vim(); // leave Vim
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE) #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
/* Python only works properly when the LC_NUMERIC locale is "C". */ // Python only works properly when the LC_NUMERIC locale is "C".
saved_locale = setlocale(LC_NUMERIC, NULL); saved_locale = setlocale(LC_NUMERIC, NULL);
if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0)
saved_locale = NULL; saved_locale = NULL;
else else
{ {
/* Need to make a copy, value may change when setting new locale. */ // Need to make a copy, value may change when setting new locale.
saved_locale = (char *) PY_STRSAVE(saved_locale); saved_locale = (char *) PY_STRSAVE(saved_locale);
(void)setlocale(LC_NUMERIC, "C"); (void)setlocale(LC_NUMERIC, "C");
} }
@@ -1068,7 +1063,7 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
#ifdef PY_CAN_RECURSE #ifdef PY_CAN_RECURSE
pygilstate = PyGILState_Ensure(); pygilstate = PyGILState_Ensure();
#else #else
Python_RestoreThread(); /* enter python */ Python_RestoreThread(); // enter python
#endif #endif
run((char *) cmd, arg run((char *) cmd, arg
@@ -1080,7 +1075,7 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
#ifdef PY_CAN_RECURSE #ifdef PY_CAN_RECURSE
PyGILState_Release(pygilstate); PyGILState_Release(pygilstate);
#else #else
Python_SaveThread(); /* leave python */ Python_SaveThread(); // leave python
#endif #endif
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE) #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
@@ -1091,7 +1086,7 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
} }
#endif #endif
Python_Lock_Vim(); /* enter vim */ Python_Lock_Vim(); // enter vim
PythonIO_Flush(); PythonIO_Flush();
theend: theend:
@@ -1138,17 +1133,16 @@ ex_pyfile(exarg_T *eap)
if (p_pyx == 0) if (p_pyx == 0)
p_pyx = 2; p_pyx = 2;
/* Have to do it like this. PyRun_SimpleFile requires you to pass a // Have to do it like this. PyRun_SimpleFile requires you to pass a
* stdio file pointer, but Vim and the Python DLL are compiled with // stdio file pointer, but Vim and the Python DLL are compiled with
* different options under Windows, meaning that stdio pointers aren't // different options under Windows, meaning that stdio pointers aren't
* compatible between the two. Yuk. // compatible between the two. Yuk.
* //
* Put the string "execfile('file')" into buffer. But, we need to // Put the string "execfile('file')" into buffer. But, we need to
* escape any backslashes or single quotes in the file name, so that // escape any backslashes or single quotes in the file name, so that
* Python won't mangle the file name. // Python won't mangle the file name.
*/
strcpy(buffer, "execfile('"); strcpy(buffer, "execfile('");
p = buffer + 10; /* size of "execfile('" */ p = buffer + 10; // size of "execfile('"
while (*file && p < buffer + (BUFFER_SIZE - 3)) while (*file && p < buffer + (BUFFER_SIZE - 3))
{ {
@@ -1157,16 +1151,16 @@ ex_pyfile(exarg_T *eap)
*p++ = *file++; *p++ = *file++;
} }
/* If we didn't finish the file name, we hit a buffer overflow */ // If we didn't finish the file name, we hit a buffer overflow
if (*file != '\0') if (*file != '\0')
return; return;
/* Put in the terminating "')" and a null */ // Put in the terminating "')" and a null
*p++ = '\''; *p++ = '\'';
*p++ = ')'; *p++ = ')';
*p++ = '\0'; *p++ = '\0';
/* Execute the file */ // Execute the file
DoPyCommand(buffer, DoPyCommand(buffer,
(rangeinitializer) init_range_cmd, (rangeinitializer) init_range_cmd,
(runner) run_cmd, (runner) run_cmd,
@@ -1185,12 +1179,10 @@ ex_pydo(exarg_T *eap)
(void *)eap); (void *)eap);
} }
/****************************************************** ///////////////////////////////////////////////////////
* 2. Python output stream: writes output via [e]msg(). // 2. Python output stream: writes output via [e]msg().
*/
/* Implementation functions // Implementation functions
*/
static PyObject * static PyObject *
OutputGetattr(PyObject *self, char *name) OutputGetattr(PyObject *self, char *name)
@@ -1206,53 +1198,47 @@ OutputGetattr(PyObject *self, char *name)
return Py_FindMethod(OutputMethods, self, name); return Py_FindMethod(OutputMethods, self, name);
} }
/****************************************************** ///////////////////////////////////////////////////////
* 3. Implementation of the Vim module for Python // 3. Implementation of the Vim module for Python
*/
/* Window type - Implementation functions // Window type - Implementation functions
* -------------------------------------- // --------------------------------------
*/
#define WindowType_Check(obj) ((obj)->ob_type == &WindowType) #define WindowType_Check(obj) ((obj)->ob_type == &WindowType)
/* Buffer type - Implementation functions // Buffer type - Implementation functions
* -------------------------------------- // --------------------------------------
*/
#define BufferType_Check(obj) ((obj)->ob_type == &BufferType) #define BufferType_Check(obj) ((obj)->ob_type == &BufferType)
static PyInt BufferAssItem(PyObject *, PyInt, PyObject *); static PyInt BufferAssItem(PyObject *, PyInt, PyObject *);
static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *); static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *);
/* Line range type - Implementation functions // Line range type - Implementation functions
* -------------------------------------- // --------------------------------------
*/
#define RangeType_Check(obj) ((obj)->ob_type == &RangeType) #define RangeType_Check(obj) ((obj)->ob_type == &RangeType)
static PyInt RangeAssItem(PyObject *, PyInt, PyObject *); static PyInt RangeAssItem(PyObject *, PyInt, PyObject *);
static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *); static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *);
/* Current objects type - Implementation functions // Current objects type - Implementation functions
* ----------------------------------------------- // -----------------------------------------------
*/
static PySequenceMethods BufferAsSeq = { static PySequenceMethods BufferAsSeq = {
(PyInquiry) BufferLength, /* sq_length, len(x) */ (PyInquiry) BufferLength, // sq_length, len(x)
(binaryfunc) 0, /* BufferConcat, sq_concat, x+y */ (binaryfunc) 0, // BufferConcat, sq_concat, x+y
(PyIntArgFunc) 0, /* BufferRepeat, sq_repeat, x*n */ (PyIntArgFunc) 0, // BufferRepeat, sq_repeat, x*n
(PyIntArgFunc) BufferItem, /* sq_item, x[i] */ (PyIntArgFunc) BufferItem, // sq_item, x[i]
(PyIntIntArgFunc) BufferSlice, /* sq_slice, x[i:j] */ (PyIntIntArgFunc) BufferSlice, // sq_slice, x[i:j]
(PyIntObjArgProc) BufferAssItem, /* sq_ass_item, x[i]=v */ (PyIntObjArgProc) BufferAssItem, // sq_ass_item, x[i]=v
(PyIntIntObjArgProc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */ (PyIntIntObjArgProc) BufferAssSlice, // sq_ass_slice, x[i:j]=v
(objobjproc) 0, (objobjproc) 0,
(binaryfunc) 0, (binaryfunc) 0,
0, 0,
}; };
/* Buffer object - Implementation // Buffer object - Implementation
*/
static PyObject * static PyObject *
BufferGetattr(PyObject *self, char *name) BufferGetattr(PyObject *self, char *name)
@@ -1272,7 +1258,7 @@ BufferGetattr(PyObject *self, char *name)
return Py_FindMethod(BufferMethods, self, name); return Py_FindMethod(BufferMethods, self, name);
} }
/******************/ //////////////////
static PyInt static PyInt
BufferAssItem(PyObject *self, PyInt n, PyObject *val) BufferAssItem(PyObject *self, PyInt n, PyObject *val)
@@ -1287,13 +1273,13 @@ BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
} }
static PySequenceMethods RangeAsSeq = { static PySequenceMethods RangeAsSeq = {
(PyInquiry) RangeLength, /* sq_length, len(x) */ (PyInquiry) RangeLength, // sq_length, len(x)
(binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */ (binaryfunc) 0, /* RangeConcat, */ // sq_concat, x+y
(PyIntArgFunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */ (PyIntArgFunc) 0, /* RangeRepeat, */ // sq_repeat, x*n
(PyIntArgFunc) RangeItem, /* sq_item, x[i] */ (PyIntArgFunc) RangeItem, // sq_item, x[i]
(PyIntIntArgFunc) RangeSlice, /* sq_slice, x[i:j] */ (PyIntIntArgFunc) RangeSlice, // sq_slice, x[i:j]
(PyIntObjArgProc) RangeAssItem, /* sq_ass_item, x[i]=v */ (PyIntObjArgProc) RangeAssItem, // sq_ass_item, x[i]=v
(PyIntIntObjArgProc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */ (PyIntIntObjArgProc) RangeAssSlice, // sq_ass_slice, x[i:j]=v
(objobjproc) 0, (objobjproc) 0,
#if PY_MAJOR_VERSION >= 2 #if PY_MAJOR_VERSION >= 2
(binaryfunc) 0, (binaryfunc) 0,
@@ -1301,8 +1287,7 @@ static PySequenceMethods RangeAsSeq = {
#endif #endif
}; };
/* Line range object - Implementation // Line range object - Implementation
*/
static PyObject * static PyObject *
RangeGetattr(PyObject *self, char *name) RangeGetattr(PyObject *self, char *name)
@@ -1317,7 +1302,7 @@ RangeGetattr(PyObject *self, char *name)
return Py_FindMethod(RangeMethods, self, name); return Py_FindMethod(RangeMethods, self, name);
} }
/****************/ ////////////////
static PyInt static PyInt
RangeAssItem(PyObject *self, PyInt n, PyObject *val) RangeAssItem(PyObject *self, PyInt n, PyObject *val)
@@ -1337,8 +1322,7 @@ RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
&((RangeObject *)(self))->end); &((RangeObject *)(self))->end);
} }
/* TabPage object - Implementation // TabPage object - Implementation
*/
static PyObject * static PyObject *
TabPageGetattr(PyObject *self, char *name) TabPageGetattr(PyObject *self, char *name)
@@ -1358,8 +1342,7 @@ TabPageGetattr(PyObject *self, char *name)
return Py_FindMethod(TabPageMethods, self, name); return Py_FindMethod(TabPageMethods, self, name);
} }
/* Window object - Implementation // Window object - Implementation
*/
static PyObject * static PyObject *
WindowGetattr(PyObject *self, char *name) WindowGetattr(PyObject *self, char *name)
@@ -1379,17 +1362,16 @@ WindowGetattr(PyObject *self, char *name)
return Py_FindMethod(WindowMethods, self, name); return Py_FindMethod(WindowMethods, self, name);
} }
/* Tab page list object - Definitions // Tab page list object - Definitions
*/
static PySequenceMethods TabListAsSeq = { static PySequenceMethods TabListAsSeq = {
(PyInquiry) TabListLength, /* sq_length, len(x) */ (PyInquiry) TabListLength, // sq_length, len(x)
(binaryfunc) 0, /* sq_concat, x+y */ (binaryfunc) 0, // sq_concat, x+y
(PyIntArgFunc) 0, /* sq_repeat, x*n */ (PyIntArgFunc) 0, // sq_repeat, x*n
(PyIntArgFunc) TabListItem, /* sq_item, x[i] */ (PyIntArgFunc) TabListItem, // sq_item, x[i]
(PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ (PyIntIntArgFunc) 0, // sq_slice, x[i:j]
(PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ (PyIntObjArgProc) 0, // sq_ass_item, x[i]=v
(PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ (PyIntIntObjArgProc) 0, // sq_ass_slice, x[i:j]=v
(objobjproc) 0, (objobjproc) 0,
#if PY_MAJOR_VERSION >= 2 #if PY_MAJOR_VERSION >= 2
(binaryfunc) 0, (binaryfunc) 0,
@@ -1397,17 +1379,16 @@ static PySequenceMethods TabListAsSeq = {
#endif #endif
}; };
/* Window list object - Definitions // Window list object - Definitions
*/
static PySequenceMethods WinListAsSeq = { static PySequenceMethods WinListAsSeq = {
(PyInquiry) WinListLength, /* sq_length, len(x) */ (PyInquiry) WinListLength, // sq_length, len(x)
(binaryfunc) 0, /* sq_concat, x+y */ (binaryfunc) 0, // sq_concat, x+y
(PyIntArgFunc) 0, /* sq_repeat, x*n */ (PyIntArgFunc) 0, // sq_repeat, x*n
(PyIntArgFunc) WinListItem, /* sq_item, x[i] */ (PyIntArgFunc) WinListItem, // sq_item, x[i]
(PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ (PyIntIntArgFunc) 0, // sq_slice, x[i:j]
(PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ (PyIntObjArgProc) 0, // sq_ass_item, x[i]=v
(PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ (PyIntIntObjArgProc) 0, // sq_ass_slice, x[i:j]=v
(objobjproc) 0, (objobjproc) 0,
#if PY_MAJOR_VERSION >= 2 #if PY_MAJOR_VERSION >= 2
(binaryfunc) 0, (binaryfunc) 0,
@@ -1415,8 +1396,7 @@ static PySequenceMethods WinListAsSeq = {
#endif #endif
}; };
/* External interface // External interface
*/
void void
python_buffer_free(buf_T *buf) python_buffer_free(buf_T *buf)
@@ -1454,13 +1434,13 @@ python_tabpage_free(tabpage_T *tab)
static int static int
PythonMod_Init(void) PythonMod_Init(void)
{ {
/* The special value is removed from sys.path in Python_Init(). */ // The special value is removed from sys.path in Python_Init().
static char *(argv[2]) = {"/must>not&exist/foo", NULL}; static char *(argv[2]) = {"/must>not&exist/foo", NULL};
if (init_types()) if (init_types())
return -1; return -1;
/* Set sys.argv[] to avoid a crash in warn(). */ // Set sys.argv[] to avoid a crash in warn().
PySys_SetArgv(1, argv); PySys_SetArgv(1, argv);
vim_module = Py_InitModule4("vim", VimMethods, (char *)NULL, vim_module = Py_InitModule4("vim", VimMethods, (char *)NULL,
@@ -1475,15 +1455,13 @@ PythonMod_Init(void)
return 0; return 0;
} }
/************************************************************************* //////////////////////////////////////////////////////////////////////////
* 4. Utility functions for handling the interface between Vim and Python. // 4. Utility functions for handling the interface between Vim and Python.
*/
/* Convert a Vim line into a Python string. // Convert a Vim line into a Python string.
* All internal newlines are replaced by null characters. // All internal newlines are replaced by null characters.
* //
* On errors, the Python exception data is set, and NULL is returned. // On errors, the Python exception data is set, and NULL is returned.
*/
static PyObject * static PyObject *
LineToString(const char *str) LineToString(const char *str)
{ {
@@ -1491,10 +1469,9 @@ LineToString(const char *str)
PyInt len = strlen(str); PyInt len = strlen(str);
char *p; char *p;
/* Allocate an Python string object, with uninitialised contents. We // Allocate an Python string object, with uninitialised contents. We
* must do it this way, so that we can modify the string in place // must do it this way, so that we can modify the string in place
* later. See the Python source, Objects/stringobject.c for details. // later. See the Python source, Objects/stringobject.c for details.
*/
result = PyString_FromStringAndSize(NULL, len); result = PyString_FromStringAndSize(NULL, len);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
@@ -1568,8 +1545,8 @@ do_pyeval(char_u *str, typval_T *rettv)
} }
} }
/* Don't generate a prototype for the next function, it generates an error on // Don't generate a prototype for the next function, it generates an error on
* newer Python versions. */ // newer Python versions.
#if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO) #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO)
char * char *
@@ -1577,7 +1554,7 @@ Py_GetProgramName(void)
{ {
return "vim"; return "vim";
} }
#endif /* Python 1.4 */ #endif // Python 1.4
int int
set_ref_in_python(int copyID) set_ref_in_python(int copyID)

View File

@@ -22,13 +22,12 @@
* Adaptations to support both python3.x and python2.x * Adaptations to support both python3.x and python2.x
*/ */
/* uncomment this if used with the debug version of python */ // uncomment this if used with the debug version of python
/* #define Py_DEBUG */ // #define Py_DEBUG
/* Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting // Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting
*/ // uncomment this if used with the debug version of python, but without its
/* uncomment this if used with the debug version of python, but without its // allocator
* allocator */ // #define Py_DEBUG_NO_PYMALLOC
/* #define Py_DEBUG_NO_PYMALLOC */
#include "vim.h" #include "vim.h"
@@ -56,30 +55,30 @@
# undef HAVE_PUTENV # undef HAVE_PUTENV
#endif #endif
#ifdef HAVE_STDARG_H #ifdef HAVE_STDARG_H
# undef HAVE_STDARG_H /* Python's config.h defines it as well. */ # undef HAVE_STDARG_H // Python's config.h defines it as well.
#endif #endif
#ifdef _POSIX_C_SOURCE /* defined in feature.h */ #ifdef _POSIX_C_SOURCE // defined in feature.h
# undef _POSIX_C_SOURCE # undef _POSIX_C_SOURCE
#endif #endif
#ifdef _XOPEN_SOURCE #ifdef _XOPEN_SOURCE
# undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ # undef _XOPEN_SOURCE // pyconfig.h defines it as well.
#endif #endif
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#undef main /* Defined in python.h - aargh */ #undef main // Defined in python.h - aargh
#undef HAVE_FCNTL_H /* Clash with os_win32.h */ #undef HAVE_FCNTL_H // Clash with os_win32.h
/* The "surrogateescape" error handler is new in Python 3.1 */ // The "surrogateescape" error handler is new in Python 3.1
#if PY_VERSION_HEX >= 0x030100f0 #if PY_VERSION_HEX >= 0x030100f0
# define CODEC_ERROR_HANDLER "surrogateescape" # define CODEC_ERROR_HANDLER "surrogateescape"
#else #else
# define CODEC_ERROR_HANDLER NULL # define CODEC_ERROR_HANDLER NULL
#endif #endif
/* Python 3 does not support CObjects, always use Capsules */ // Python 3 does not support CObjects, always use Capsules
#define PY_USE_CAPSULE #define PY_USE_CAPSULE
#define PyInt Py_ssize_t #define PyInt Py_ssize_t
@@ -432,9 +431,9 @@ static void(*py3_PyObject_GC_Del)(void *);
static void(*py3_PyObject_GC_UnTrack)(void *); static void(*py3_PyObject_GC_UnTrack)(void *);
static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *);
static HINSTANCE hinstPy3 = 0; /* Instance of python.dll */ static HINSTANCE hinstPy3 = 0; // Instance of python.dll
/* Imported exception objects */ // Imported exception objects
static PyObject *p3imp_PyExc_AttributeError; static PyObject *p3imp_PyExc_AttributeError;
static PyObject *p3imp_PyExc_IndexError; static PyObject *p3imp_PyExc_IndexError;
static PyObject *p3imp_PyExc_KeyError; static PyObject *p3imp_PyExc_KeyError;
@@ -664,9 +663,9 @@ py3_runtime_link_init(char *libname, int verbose)
(PYTHON_PROC *)&py3_PyUnicode_AsEncodedString; (PYTHON_PROC *)&py3_PyUnicode_AsEncodedString;
# if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON) # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON)
/* Can't have Python and Python3 loaded at the same time. // Can't have Python and Python3 loaded at the same time.
* It cause a crash, because RTLD_GLOBAL is needed for // It cause a crash, because RTLD_GLOBAL is needed for
* standard C extension libraries of one or both python versions. */ // standard C extension libraries of one or both python versions.
if (python_loaded()) if (python_loaded())
{ {
if (verbose) if (verbose)
@@ -699,8 +698,8 @@ py3_runtime_link_init(char *libname, int verbose)
} }
} }
/* Load unicode functions separately as only the ucs2 or the ucs4 functions // Load unicode functions separately as only the ucs2 or the ucs4 functions
* will be present in the library. */ // will be present in the library.
# if PY_VERSION_HEX >= 0x030300f0 # if PY_VERSION_HEX >= 0x030300f0
*ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicode_FromString"); *ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicode_FromString");
*ucs_decode = symbol_from_dll(hinstPy3, "PyUnicode_Decode"); *ucs_decode = symbol_from_dll(hinstPy3, "PyUnicode_Decode");
@@ -746,7 +745,8 @@ python3_enabled(int verbose)
return py3_runtime_link_init((char *)p_py3dll, verbose) == OK; return py3_runtime_link_init((char *)p_py3dll, verbose) == OK;
} }
/* Load the standard Python exceptions - don't import the symbols from the /*
* Load the standard Python exceptions - don't import the symbols from the
* DLL, as this can cause errors (importing data symbols is not reliable). * DLL, as this can cause errors (importing data symbols is not reliable).
*/ */
static void static void
@@ -776,7 +776,7 @@ get_py3_exceptions(void)
Py_XINCREF(p3imp_PyExc_OverflowError); Py_XINCREF(p3imp_PyExc_OverflowError);
Py_XDECREF(exmod); Py_XDECREF(exmod);
} }
#endif /* DYNAMIC_PYTHON3 */ #endif // DYNAMIC_PYTHON3
static int py3initialised = 0; static int py3initialised = 0;
#define PYINITIALISED py3initialised #define PYINITIALISED py3initialised
@@ -843,22 +843,20 @@ static struct PyModuleDef vimmodule;
#define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0) #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
/****************************************************** ///////////////////////////////////////////////////////
* Internal function prototypes. // Internal function prototypes.
*/
static PyObject *Py3Init_vim(void); static PyObject *Py3Init_vim(void);
/****************************************************** ///////////////////////////////////////////////////////
* 1. Python interpreter main program. // 1. Python interpreter main program.
*/
void void
python3_end(void) python3_end(void)
{ {
static int recurse = 0; static int recurse = 0;
/* If a crash occurs while doing this, don't try again. */ // If a crash occurs while doing this, don't try again.
if (recurse != 0) if (recurse != 0)
return; return;
@@ -870,7 +868,7 @@ python3_end(void)
#endif #endif
if (Py_IsInitialized()) if (Py_IsInitialized())
{ {
/* acquire lock before finalizing */ // acquire lock before finalizing
PyGILState_Ensure(); PyGILState_Ensure();
Py_Finalize(); Py_Finalize();
@@ -912,7 +910,7 @@ Python3_Init(void)
{ {
size_t len = mbstowcs(NULL, (char *)p_py3home, 0) + 1; size_t len = mbstowcs(NULL, (char *)p_py3home, 0) + 1;
/* The string must not change later, make a copy in static memory. */ // The string must not change later, make a copy in static memory.
py_home_buf = ALLOC_MULT(wchar_t, len); py_home_buf = ALLOC_MULT(wchar_t, len);
if (py_home_buf != NULL && mbstowcs( if (py_home_buf != NULL && mbstowcs(
py_home_buf, (char *)p_py3home, len) != (size_t)-1) py_home_buf, (char *)p_py3home, len) != (size_t)-1)
@@ -927,10 +925,10 @@ Python3_Init(void)
Py_Initialize(); Py_Initialize();
/* Initialise threads, and below save the state using // Initialise threads, and below save the state using
* PyEval_SaveThread. Without the call to PyEval_SaveThread, thread // PyEval_SaveThread. Without the call to PyEval_SaveThread, thread
* specific state (such as the system trace hook), will be lost // specific state (such as the system trace hook), will be lost
* between invocations of Python code. */ // between invocations of Python code.
PyEval_InitThreads(); PyEval_InitThreads();
#ifdef DYNAMIC_PYTHON3 #ifdef DYNAMIC_PYTHON3
get_py3_exceptions(); get_py3_exceptions();
@@ -941,22 +939,20 @@ Python3_Init(void)
globals = PyModule_GetDict(PyImport_AddModule("__main__")); globals = PyModule_GetDict(PyImport_AddModule("__main__"));
/* Remove the element from sys.path that was added because of our // Remove the element from sys.path that was added because of our
* argv[0] value in Py3Init_vim(). Previously we used an empty // argv[0] value in Py3Init_vim(). Previously we used an empty
* string, but depending on the OS we then get an empty entry or // string, but depending on the OS we then get an empty entry or
* the current directory in sys.path. // the current directory in sys.path.
* Only after vim has been imported, the element does exist in // Only after vim has been imported, the element does exist in
* sys.path. // sys.path.
*/
PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))");
/* lock is created and acquired in PyEval_InitThreads() and thread // lock is created and acquired in PyEval_InitThreads() and thread
* state is created in Py_Initialize() // state is created in Py_Initialize()
* there _PyGILState_NoteThreadState() also sets gilcounter to 1 // there _PyGILState_NoteThreadState() also sets gilcounter to 1
* (python must have threads enabled!) // (python must have threads enabled!)
* so the following does both: unlock GIL and save thread state in TLS // so the following does both: unlock GIL and save thread state in TLS
* without deleting thread state // without deleting thread state
*/
PyEval_SaveThread(); PyEval_SaveThread();
py3initialised = 1; py3initialised = 1;
@@ -965,11 +961,10 @@ Python3_Init(void)
return 0; return 0;
fail: fail:
/* We call PythonIO_Flush() here to print any Python errors. // We call PythonIO_Flush() here to print any Python errors.
* This is OK, as it is possible to call this function even // This is OK, as it is possible to call this function even
* if PythonIO_Init_io() has not completed successfully (it will // if PythonIO_Init_io() has not completed successfully (it will
* not do anything in this case). // not do anything in this case).
*/
PythonIO_Flush(); PythonIO_Flush();
return -1; return -1;
} }
@@ -995,16 +990,16 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
init_range(arg); init_range(arg);
Python_Release_Vim(); /* leave vim */ Python_Release_Vim(); // leave Vim
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE) #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
/* Python only works properly when the LC_NUMERIC locale is "C". */ // Python only works properly when the LC_NUMERIC locale is "C".
saved_locale = setlocale(LC_NUMERIC, NULL); saved_locale = setlocale(LC_NUMERIC, NULL);
if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0)
saved_locale = NULL; saved_locale = NULL;
else else
{ {
/* Need to make a copy, value may change when setting new locale. */ // Need to make a copy, value may change when setting new locale.
saved_locale = (char *)vim_strsave((char_u *)saved_locale); saved_locale = (char *)vim_strsave((char_u *)saved_locale);
(void)setlocale(LC_NUMERIC, "C"); (void)setlocale(LC_NUMERIC, "C");
} }
@@ -1012,8 +1007,8 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
pygilstate = PyGILState_Ensure(); pygilstate = PyGILState_Ensure();
/* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause // PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
* SyntaxError (unicode error). */ // SyntaxError (unicode error).
cmdstr = PyUnicode_Decode(cmd, strlen(cmd), cmdstr = PyUnicode_Decode(cmd, strlen(cmd),
(char *)ENC_OPT, CODEC_ERROR_HANDLER); (char *)ENC_OPT, CODEC_ERROR_HANDLER);
cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER); cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
@@ -1032,11 +1027,11 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
} }
#endif #endif
Python_Lock_Vim(); /* enter vim */ Python_Lock_Vim(); // enter Vim
PythonIO_Flush(); PythonIO_Flush();
theend: theend:
return; /* keeps lint happy */ return; // keeps lint happy
} }
/* /*
@@ -1077,22 +1072,21 @@ ex_py3file(exarg_T *eap)
if (p_pyx == 0) if (p_pyx == 0)
p_pyx = 3; p_pyx = 3;
/* Have to do it like this. PyRun_SimpleFile requires you to pass a // Have to do it like this. PyRun_SimpleFile requires you to pass a
* stdio file pointer, but Vim and the Python DLL are compiled with // stdio file pointer, but Vim and the Python DLL are compiled with
* different options under Windows, meaning that stdio pointers aren't // different options under Windows, meaning that stdio pointers aren't
* compatible between the two. Yuk. // compatible between the two. Yuk.
* //
* construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec')) // construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec'))
* //
* Using bytes so that Python can detect the source encoding as it normally // Using bytes so that Python can detect the source encoding as it normally
* does. The doc does not say "compile" accept bytes, though. // does. The doc does not say "compile" accept bytes, though.
* //
* We need to escape any backslashes or single quotes in the file name, so that // We need to escape any backslashes or single quotes in the file name, so that
* Python won't mangle the file name. // Python won't mangle the file name.
*/
strcpy(buffer, "exec(compile(open('"); strcpy(buffer, "exec(compile(open('");
p = buffer + 19; /* size of "exec(compile(open('" */ p = buffer + 19; // size of "exec(compile(open('"
for (i=0; i<2; ++i) for (i=0; i<2; ++i)
{ {
@@ -1103,7 +1097,7 @@ ex_py3file(exarg_T *eap)
*p++ = '\\'; *p++ = '\\';
*p++ = *file++; *p++ = *file++;
} }
/* If we didn't finish the file name, we hit a buffer overflow */ // If we didn't finish the file name, we hit a buffer overflow
if (*file != '\0') if (*file != '\0')
return; return;
if (i==0) if (i==0)
@@ -1119,7 +1113,7 @@ ex_py3file(exarg_T *eap)
} }
/* Execute the file */ // Execute the file
DoPyCommand(buffer, DoPyCommand(buffer,
(rangeinitializer) init_range_cmd, (rangeinitializer) init_range_cmd,
(runner) run_cmd, (runner) run_cmd,
@@ -1138,12 +1132,10 @@ ex_py3do(exarg_T *eap)
(void *)eap); (void *)eap);
} }
/****************************************************** ///////////////////////////////////////////////////////
* 2. Python output stream: writes output via [e]msg(). // 2. Python output stream: writes output via [e]msg().
*/
/* Implementation functions // Implementation functions
*/
static PyObject * static PyObject *
OutputGetattro(PyObject *self, PyObject *nameobj) OutputGetattro(PyObject *self, PyObject *nameobj)
@@ -1168,28 +1160,24 @@ OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
return OutputSetattr((OutputObject *)(self), name, val); return OutputSetattr((OutputObject *)(self), name, val);
} }
/****************************************************** ///////////////////////////////////////////////////////
* 3. Implementation of the Vim module for Python // 3. Implementation of the Vim module for Python
*/
/* Window type - Implementation functions // Window type - Implementation functions
* -------------------------------------- // --------------------------------------
*/
#define WindowType_Check(obj) ((obj)->ob_base.ob_type == &WindowType) #define WindowType_Check(obj) ((obj)->ob_base.ob_type == &WindowType)
/* Buffer type - Implementation functions // Buffer type - Implementation functions
* -------------------------------------- // --------------------------------------
*/
#define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType) #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType)
static PyObject* BufferSubscript(PyObject *self, PyObject *idx); static PyObject* BufferSubscript(PyObject *self, PyObject *idx);
static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val); static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
/* Line range type - Implementation functions // Line range type - Implementation functions
* -------------------------------------- // --------------------------------------
*/
#define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType) #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType)
@@ -1197,21 +1185,20 @@ static PyObject* RangeSubscript(PyObject *self, PyObject *idx);
static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *); static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val); static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
/* Current objects type - Implementation functions // Current objects type - Implementation functions
* ----------------------------------------------- // -----------------------------------------------
*/
static PySequenceMethods BufferAsSeq = { static PySequenceMethods BufferAsSeq = {
(lenfunc) BufferLength, /* sq_length, len(x) */ (lenfunc) BufferLength, // sq_length, len(x)
(binaryfunc) 0, /* sq_concat, x+y */ (binaryfunc) 0, // sq_concat, x+y
(ssizeargfunc) 0, /* sq_repeat, x*n */ (ssizeargfunc) 0, // sq_repeat, x*n
(ssizeargfunc) BufferItem, /* sq_item, x[i] */ (ssizeargfunc) BufferItem, // sq_item, x[i]
0, /* was_sq_slice, x[i:j] */ 0, // was_sq_slice, x[i:j]
0, /* sq_ass_item, x[i]=v */ 0, // sq_ass_item, x[i]=v
0, /* sq_ass_slice, x[i:j]=v */ 0, // sq_ass_slice, x[i:j]=v
0, /* sq_contains */ 0, // sq_contains
0, /* sq_inplace_concat */ 0, // sq_inplace_concat
0, /* sq_inplace_repeat */ 0, // sq_inplace_repeat
}; };
static PyMappingMethods BufferAsMapping = { static PyMappingMethods BufferAsMapping = {
@@ -1221,8 +1208,7 @@ static PyMappingMethods BufferAsMapping = {
}; };
/* Buffer object // Buffer object
*/
static PyObject * static PyObject *
BufferGetattro(PyObject *self, PyObject *nameobj) BufferGetattro(PyObject *self, PyObject *nameobj)
@@ -1252,7 +1238,7 @@ BufferSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
return BufferSetattr((BufferObject *)(self), name, val); return BufferSetattr((BufferObject *)(self), name, val);
} }
/******************/ //////////////////
static PyObject * static PyObject *
BufferSubscript(PyObject *self, PyObject* idx) BufferSubscript(PyObject *self, PyObject* idx)
@@ -1315,16 +1301,16 @@ BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
} }
static PySequenceMethods RangeAsSeq = { static PySequenceMethods RangeAsSeq = {
(lenfunc) RangeLength, /* sq_length, len(x) */ (lenfunc) RangeLength, // sq_length, len(x)
(binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ (binaryfunc) 0, // RangeConcat, sq_concat, x+y
(ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */ (ssizeargfunc) 0, // RangeRepeat, sq_repeat, x*n
(ssizeargfunc) RangeItem, /* sq_item, x[i] */ (ssizeargfunc) RangeItem, // sq_item, x[i]
0, /* was_sq_slice, x[i:j] */ 0, // was_sq_slice, x[i:j]
(ssizeobjargproc) RangeAsItem, /* sq_as_item, x[i]=v */ (ssizeobjargproc) RangeAsItem, // sq_as_item, x[i]=v
0, /* sq_ass_slice, x[i:j]=v */ 0, // sq_ass_slice, x[i:j]=v
0, /* sq_contains */ 0, // sq_contains
0, /* sq_inplace_concat */ 0, // sq_inplace_concat
0, /* sq_inplace_repeat */ 0, // sq_inplace_repeat
}; };
static PyMappingMethods RangeAsMapping = { static PyMappingMethods RangeAsMapping = {
@@ -1333,8 +1319,7 @@ static PyMappingMethods RangeAsMapping = {
/* mp_ass_subscript */ (objobjargproc)RangeAsSubscript, /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript,
}; };
/* Line range object - Implementation // Line range object - Implementation
*/
static PyObject * static PyObject *
RangeGetattro(PyObject *self, PyObject *nameobj) RangeGetattro(PyObject *self, PyObject *nameobj)
@@ -1349,7 +1334,7 @@ RangeGetattro(PyObject *self, PyObject *nameobj)
return PyObject_GenericGetAttr(self, nameobj); return PyObject_GenericGetAttr(self, nameobj);
} }
/****************/ ////////////////
static Py_ssize_t static Py_ssize_t
RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val) RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val)
@@ -1420,8 +1405,7 @@ RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
} }
} }
/* TabPage object - Implementation // TabPage object - Implementation
*/
static PyObject * static PyObject *
TabPageGetattro(PyObject *self, PyObject *nameobj) TabPageGetattro(PyObject *self, PyObject *nameobj)
@@ -1443,8 +1427,7 @@ TabPageGetattro(PyObject *self, PyObject *nameobj)
return PyObject_GenericGetAttr(self, nameobj); return PyObject_GenericGetAttr(self, nameobj);
} }
/* Window object - Implementation // Window object - Implementation
*/
static PyObject * static PyObject *
WindowGetattro(PyObject *self, PyObject *nameobj) WindowGetattro(PyObject *self, PyObject *nameobj)
@@ -1474,39 +1457,38 @@ WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
return WindowSetattr((WindowObject *)(self), name, val); return WindowSetattr((WindowObject *)(self), name, val);
} }
/* Tab page list object - Definitions // Tab page list object - Definitions
*/
static PySequenceMethods TabListAsSeq = { static PySequenceMethods TabListAsSeq = {
(lenfunc) TabListLength, /* sq_length, len(x) */ (lenfunc) TabListLength, // sq_length, len(x)
(binaryfunc) 0, /* sq_concat, x+y */ (binaryfunc) 0, // sq_concat, x+y
(ssizeargfunc) 0, /* sq_repeat, x*n */ (ssizeargfunc) 0, // sq_repeat, x*n
(ssizeargfunc) TabListItem, /* sq_item, x[i] */ (ssizeargfunc) TabListItem, // sq_item, x[i]
0, /* sq_slice, x[i:j] */ 0, // sq_slice, x[i:j]
(ssizeobjargproc)0, /* sq_as_item, x[i]=v */ (ssizeobjargproc)0, // sq_as_item, x[i]=v
0, /* sq_ass_slice, x[i:j]=v */ 0, // sq_ass_slice, x[i:j]=v
0, /* sq_contains */ 0, // sq_contains
0, /* sq_inplace_concat */ 0, // sq_inplace_concat
0, /* sq_inplace_repeat */ 0, // sq_inplace_repeat
}; };
/* Window list object - Definitions // Window list object - Definitions
*/
static PySequenceMethods WinListAsSeq = { static PySequenceMethods WinListAsSeq = {
(lenfunc) WinListLength, /* sq_length, len(x) */ (lenfunc) WinListLength, // sq_length, len(x)
(binaryfunc) 0, /* sq_concat, x+y */ (binaryfunc) 0, // sq_concat, x+y
(ssizeargfunc) 0, /* sq_repeat, x*n */ (ssizeargfunc) 0, // sq_repeat, x*n
(ssizeargfunc) WinListItem, /* sq_item, x[i] */ (ssizeargfunc) WinListItem, // sq_item, x[i]
0, /* sq_slice, x[i:j] */ 0, // sq_slice, x[i:j]
(ssizeobjargproc)0, /* sq_as_item, x[i]=v */ (ssizeobjargproc)0, // sq_as_item, x[i]=v
0, /* sq_ass_slice, x[i:j]=v */ 0, // sq_ass_slice, x[i:j]=v
0, /* sq_contains */ 0, // sq_contains
0, /* sq_inplace_concat */ 0, // sq_inplace_concat
0, /* sq_inplace_repeat */ 0, // sq_inplace_repeat
}; };
/* Current items object - Implementation /*
* Current items object - Implementation
*/ */
static PyObject * static PyObject *
CurrentGetattro(PyObject *self, PyObject *nameobj) CurrentGetattro(PyObject *self, PyObject *nameobj)
@@ -1525,8 +1507,7 @@ CurrentSetattro(PyObject *self, PyObject *nameobj, PyObject *value)
return CurrentSetattr(self, name, value); return CurrentSetattr(self, name, value);
} }
/* Dictionary object - Definitions // Dictionary object - Definitions
*/
static PyObject * static PyObject *
DictionaryGetattro(PyObject *self, PyObject *nameobj) DictionaryGetattro(PyObject *self, PyObject *nameobj)
@@ -1550,8 +1531,7 @@ DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val)
return DictionarySetattr((DictionaryObject *)(self), name, val); return DictionarySetattr((DictionaryObject *)(self), name, val);
} }
/* List object - Definitions // List object - Definitions
*/
static PyObject * static PyObject *
ListGetattro(PyObject *self, PyObject *nameobj) ListGetattro(PyObject *self, PyObject *nameobj)
@@ -1571,8 +1551,7 @@ ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
return ListSetattr((ListObject *)(self), name, val); return ListSetattr((ListObject *)(self), name, val);
} }
/* Function object - Definitions // Function object - Definitions
*/
static PyObject * static PyObject *
FunctionGetattro(PyObject *self, PyObject *nameobj) FunctionGetattro(PyObject *self, PyObject *nameobj)
@@ -1589,8 +1568,7 @@ FunctionGetattro(PyObject *self, PyObject *nameobj)
return PyObject_GenericGetAttr(self, nameobj); return PyObject_GenericGetAttr(self, nameobj);
} }
/* External interface // External interface
*/
void void
python3_buffer_free(buf_T *buf) python3_buffer_free(buf_T *buf)
@@ -1628,13 +1606,13 @@ python3_tabpage_free(tabpage_T *tab)
static PyObject * static PyObject *
Py3Init_vim(void) Py3Init_vim(void)
{ {
/* The special value is removed from sys.path in Python3_Init(). */ // The special value is removed from sys.path in Python3_Init().
static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL};
if (init_types()) if (init_types())
return NULL; return NULL;
/* Set sys.argv[] to avoid a crash in warn(). */ // Set sys.argv[] to avoid a crash in warn().
PySys_SetArgv(1, argv); PySys_SetArgv(1, argv);
if ((vim_module = PyModule_Create(&vimmodule)) == NULL) if ((vim_module = PyModule_Create(&vimmodule)) == NULL)
@@ -1649,11 +1627,11 @@ Py3Init_vim(void)
return vim_module; return vim_module;
} }
/************************************************************************* //////////////////////////////////////////////////////////////////////////
* 4. Utility functions for handling the interface between Vim and Python. // 4. Utility functions for handling the interface between Vim and Python.
*/
/* Convert a Vim line into a Python string. /*
* Convert a Vim line into a Python string.
* All internal newlines are replaced by null characters. * All internal newlines are replaced by null characters.
* *
* On errors, the Python exception data is set, and NULL is returned. * On errors, the Python exception data is set, and NULL is returned.

View File

@@ -24,7 +24,7 @@
# define NT # define NT
# endif # endif
# ifndef DYNAMIC_RUBY # ifndef DYNAMIC_RUBY
# define IMPORT /* For static dll usage __declspec(dllimport) */ # define IMPORT // For static dll usage __declspec(dllimport)
# define RUBYEXTERN __declspec(dllimport) # define RUBYEXTERN __declspec(dllimport)
# endif # endif
#endif #endif
@@ -87,23 +87,23 @@
#endif #endif
#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19
/* Ruby 1.9 defines a number of static functions which use rb_num2long and // Ruby 1.9 defines a number of static functions which use rb_num2long and
* rb_int2big */ // rb_int2big
# define rb_num2long rb_num2long_stub # define rb_num2long rb_num2long_stub
# define rb_int2big rb_int2big_stub # define rb_int2big rb_int2big_stub
#endif #endif
#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 \ #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 \
&& VIM_SIZEOF_INT < VIM_SIZEOF_LONG && VIM_SIZEOF_INT < VIM_SIZEOF_LONG
/* Ruby 1.9 defines a number of static functions which use rb_fix2int and // Ruby 1.9 defines a number of static functions which use rb_fix2int and
* rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit) */ // rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit)
# define rb_fix2int rb_fix2int_stub # define rb_fix2int rb_fix2int_stub
# define rb_num2int rb_num2int_stub # define rb_num2int rb_num2int_stub
#endif #endif
#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21
/* Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses // Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses
* rb_gc_writebarrier_unprotect_promoted if USE_RGENGC */ // rb_gc_writebarrier_unprotect_promoted if USE_RGENGC
# define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub
#endif #endif
#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22
@@ -126,7 +126,7 @@
#undef EXTERN #undef EXTERN
#undef _ #undef _
/* T_DATA defined both by Ruby and Mac header files, hack around it... */ // T_DATA defined both by Ruby and Mac header files, hack around it...
#if defined(MACOS_X) #if defined(MACOS_X)
# define __OPENTRANSPORT__ # define __OPENTRANSPORT__
# define __OPENTRANSPORTPROTOCOL__ # define __OPENTRANSPORTPROTOCOL__
@@ -189,7 +189,7 @@
#endif #endif
#if defined(PROTO) && !defined(FEAT_RUBY) #if defined(PROTO) && !defined(FEAT_RUBY)
/* Define these to be able to generate the function prototypes. */ // Define these to be able to generate the function prototypes.
# define VALUE int # define VALUE int
# define RUBY_DATA_FUNC int # define RUBY_DATA_FUNC int
#endif #endif
@@ -218,7 +218,7 @@ static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
#if defined(DYNAMIC_RUBY) || defined(PROTO) #if defined(DYNAMIC_RUBY) || defined(PROTO)
# if defined(PROTO) && !defined(HINSTANCE) # if defined(PROTO) && !defined(HINSTANCE)
# define HINSTANCE int /* for generating prototypes */ # define HINSTANCE int // for generating prototypes
# endif # endif
/* /*
@@ -273,7 +273,7 @@ static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
# undef rb_intern # undef rb_intern
# define rb_intern dll_rb_intern # define rb_intern dll_rb_intern
# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 18 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 18
# define rb_fix2int dll_rb_fix2int # define rb_fix2int dll_rb_fix2int
# define rb_num2int dll_rb_num2int # define rb_num2int dll_rb_num2int
@@ -300,10 +300,10 @@ static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
# undef rb_str_new # undef rb_str_new
# define rb_str_new dll_rb_str_new # define rb_str_new dll_rb_str_new
# ifdef rb_str_new2 # ifdef rb_str_new2
/* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */ // Ruby may #define rb_str_new2 to use rb_str_new_cstr.
# define need_rb_str_new_cstr 1 # define need_rb_str_new_cstr 1
/* Ruby's headers #define rb_str_new_cstr to make use of GCC's // Ruby's headers #define rb_str_new_cstr to make use of GCC's
* __builtin_constant_p extension. */ // __builtin_constant_p extension.
# undef rb_str_new_cstr # undef rb_str_new_cstr
# define rb_str_new_cstr dll_rb_str_new_cstr # define rb_str_new_cstr dll_rb_str_new_cstr
# else # else
@@ -420,7 +420,7 @@ static VALUE (*dll_rb_hash_new) (void);
static VALUE (*dll_rb_inspect) (VALUE); static VALUE (*dll_rb_inspect) (VALUE);
static VALUE (*dll_rb_int2inum) (long); static VALUE (*dll_rb_int2inum) (long);
static ID (*dll_rb_intern) (const char*); static ID (*dll_rb_intern) (const char*);
# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only
static long (*dll_rb_fix2int) (VALUE); static long (*dll_rb_fix2int) (VALUE);
static long (*dll_rb_num2int) (VALUE); static long (*dll_rb_num2int) (VALUE);
static unsigned long (*dll_rb_num2uint) (VALUE); static unsigned long (*dll_rb_num2uint) (VALUE);
@@ -445,7 +445,7 @@ static VALUE (*dll_rb_str_cat) (VALUE, const char*, long);
static VALUE (*dll_rb_str_concat) (VALUE, VALUE); static VALUE (*dll_rb_str_concat) (VALUE, VALUE);
static VALUE (*dll_rb_str_new) (const char*, long); static VALUE (*dll_rb_str_new) (const char*, long);
# ifdef need_rb_str_new_cstr # ifdef need_rb_str_new_cstr
/* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */ // Ruby may #define rb_str_new2 to use rb_str_new_cstr.
static VALUE (*dll_rb_str_new_cstr) (const char*); static VALUE (*dll_rb_str_new_cstr) (const char*);
# else # else
static VALUE (*dll_rb_str_new2) (const char*); static VALUE (*dll_rb_str_new2) (const char*);
@@ -560,7 +560,7 @@ rb_num2ulong(VALUE x)
# endif # endif
# endif # endif
/* Do not generate a prototype here, VALUE isn't always defined. */ // Do not generate a prototype here, VALUE isn't always defined.
# if defined(USE_RGENGC) && USE_RGENGC && !defined(PROTO) # if defined(USE_RGENGC) && USE_RGENGC && !defined(PROTO)
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21
void void
@@ -585,7 +585,7 @@ rb_ary_detransient_stub(VALUE x)
} }
# endif # endif
static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */ static HINSTANCE hinstRuby = NULL; // Instance of ruby.dll
/* /*
* Table of name to function pointer of ruby. * Table of name to function pointer of ruby.
@@ -653,7 +653,7 @@ static struct
{"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect},
{"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum}, {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum},
{"rb_intern", (RUBY_PROC*)&dll_rb_intern}, {"rb_intern", (RUBY_PROC*)&dll_rb_intern},
# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only
{"rb_fix2int", (RUBY_PROC*)&dll_rb_fix2int}, {"rb_fix2int", (RUBY_PROC*)&dll_rb_fix2int},
{"rb_num2int", (RUBY_PROC*)&dll_rb_num2int}, {"rb_num2int", (RUBY_PROC*)&dll_rb_num2int},
{"rb_num2uint", (RUBY_PROC*)&dll_rb_num2uint}, {"rb_num2uint", (RUBY_PROC*)&dll_rb_num2uint},
@@ -800,7 +800,7 @@ ruby_enabled(int verbose)
{ {
return ruby_runtime_link_init((char *)p_rubydll, verbose) == OK; return ruby_runtime_link_init((char *)p_rubydll, verbose) == OK;
} }
#endif /* defined(DYNAMIC_RUBY) || defined(PROTO) */ #endif // defined(DYNAMIC_RUBY) || defined(PROTO)
void void
ruby_end(void) ruby_end(void)
@@ -918,7 +918,7 @@ ex_rubydo(exarg_T *eap)
ml_replace(i, (char_u *) StringValuePtr(line), 1); ml_replace(i, (char_u *) StringValuePtr(line), 1);
changed(); changed();
#ifdef SYNTAX_HL #ifdef SYNTAX_HL
syn_changed(i); /* recompute syntax hl. for this line */ syn_changed(i); // recompute syntax hl. for this line
#endif #endif
} }
} }
@@ -978,7 +978,7 @@ ensure_ruby_initialized(void)
{ {
#endif #endif
#ifdef MSWIN #ifdef MSWIN
/* suggested by Ariya Mizutani */ // suggested by Ariya Mizutani
int argc = 1; int argc = 1;
char *argv[] = {"gvim.exe"}; char *argv[] = {"gvim.exe"};
char **argvp = argv; char **argvp = argv;
@@ -1112,7 +1112,7 @@ vim_message(VALUE self UNUSED, VALUE str)
str = rb_obj_as_string(str); str = rb_obj_as_string(str);
if (RSTRING_LEN(str) > 0) if (RSTRING_LEN(str) > 0)
{ {
/* Only do this when the string isn't empty, alloc(0) causes trouble. */ // Only do this when the string isn't empty, alloc(0) causes trouble.
buff = ALLOCA_N(char, RSTRING_LEN(str) + 1); buff = ALLOCA_N(char, RSTRING_LEN(str) + 1);
strcpy(buff, RSTRING_PTR(str)); strcpy(buff, RSTRING_PTR(str));
p = strchr(buff, '\n'); p = strchr(buff, '\n');
@@ -1211,7 +1211,7 @@ vim_to_ruby(typval_T *tv)
result = rb_str_new(tv->vval.v_blob->bv_ga.ga_data, result = rb_str_new(tv->vval.v_blob->bv_ga.ga_data,
tv->vval.v_blob->bv_ga.ga_len); tv->vval.v_blob->bv_ga.ga_len);
} }
/* else return Qnil; */ // else return Qnil;
return result; return result;
} }
@@ -1319,8 +1319,8 @@ buffer_s_count(void)
FOR_ALL_BUFFERS(b) FOR_ALL_BUFFERS(b)
{ {
/* Deleted buffers should not be counted // Deleted buffers should not be counted
* SegPhault - 01/07/05 */ // SegPhault - 01/07/05
if (b->b_p_bl) if (b->b_p_bl)
n++; n++;
} }
@@ -1336,8 +1336,8 @@ buffer_s_aref(VALUE self UNUSED, VALUE num)
FOR_ALL_BUFFERS(b) FOR_ALL_BUFFERS(b)
{ {
/* Deleted buffers should not be counted // Deleted buffers should not be counted
* SegPhault - 01/07/05 */ // SegPhault - 01/07/05
if (!b->b_p_bl) if (!b->b_p_bl)
continue; continue;
@@ -1388,7 +1388,7 @@ buffer_aref(VALUE self, VALUE num)
if (buf != NULL) if (buf != NULL)
return get_buffer_line(buf, (linenr_T)NUM2LONG(num)); return get_buffer_line(buf, (linenr_T)NUM2LONG(num));
return Qnil; /* For stop warning */ return Qnil; // For stop warning
} }
static VALUE static VALUE
@@ -1399,7 +1399,7 @@ set_buffer_line(buf_T *buf, linenr_T n, VALUE str)
if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL)
{ {
/* set curwin/curbuf for "buf" and save some things */ // set curwin/curbuf for "buf" and save some things
aucmd_prepbuf(&aco, buf); aucmd_prepbuf(&aco, buf);
if (u_savesub(n) == OK) if (u_savesub(n) == OK)
@@ -1407,13 +1407,13 @@ set_buffer_line(buf_T *buf, linenr_T n, VALUE str)
ml_replace(n, (char_u *)line, TRUE); ml_replace(n, (char_u *)line, TRUE);
changed(); changed();
#ifdef SYNTAX_HL #ifdef SYNTAX_HL
syn_changed(n); /* recompute syntax hl. for this line */ syn_changed(n); // recompute syntax hl. for this line
#endif #endif
} }
/* restore curwin/curbuf and a few other things */ // restore curwin/curbuf and a few other things
aucmd_restbuf(&aco); aucmd_restbuf(&aco);
/* Careful: autocommands may have made "buf" invalid! */ // Careful: autocommands may have made "buf" invalid!
update_curbuf(NOT_VALID); update_curbuf(NOT_VALID);
} }
@@ -1443,23 +1443,23 @@ buffer_delete(VALUE self, VALUE num)
if (n > 0 && n <= buf->b_ml.ml_line_count) if (n > 0 && n <= buf->b_ml.ml_line_count)
{ {
/* set curwin/curbuf for "buf" and save some things */ // set curwin/curbuf for "buf" and save some things
aucmd_prepbuf(&aco, buf); aucmd_prepbuf(&aco, buf);
if (u_savedel(n, 1) == OK) if (u_savedel(n, 1) == OK)
{ {
ml_delete(n, 0); ml_delete(n, 0);
/* Changes to non-active buffers should properly refresh // Changes to non-active buffers should properly refresh
* SegPhault - 01/09/05 */ // SegPhault - 01/09/05
deleted_lines_mark(n, 1L); deleted_lines_mark(n, 1L);
changed(); changed();
} }
/* restore curwin/curbuf and a few other things */ // restore curwin/curbuf and a few other things
aucmd_restbuf(&aco); aucmd_restbuf(&aco);
/* Careful: autocommands may have made "buf" invalid! */ // Careful: autocommands may have made "buf" invalid!
update_curbuf(NOT_VALID); update_curbuf(NOT_VALID);
} }
@@ -1484,23 +1484,23 @@ buffer_append(VALUE self, VALUE num, VALUE str)
} }
else if (n >= 0 && n <= buf->b_ml.ml_line_count) else if (n >= 0 && n <= buf->b_ml.ml_line_count)
{ {
/* set curwin/curbuf for "buf" and save some things */ // set curwin/curbuf for "buf" and save some things
aucmd_prepbuf(&aco, buf); aucmd_prepbuf(&aco, buf);
if (u_inssub(n + 1) == OK) if (u_inssub(n + 1) == OK)
{ {
ml_append(n, (char_u *) line, (colnr_T) 0, FALSE); ml_append(n, (char_u *) line, (colnr_T) 0, FALSE);
/* Changes to non-active buffers should properly refresh screen // Changes to non-active buffers should properly refresh screen
* SegPhault - 12/20/04 */ // SegPhault - 12/20/04
appended_lines_mark(n, 1L); appended_lines_mark(n, 1L);
changed(); changed();
} }
/* restore curwin/curbuf and a few other things */ // restore curwin/curbuf and a few other things
aucmd_restbuf(&aco); aucmd_restbuf(&aco);
/* Careful: autocommands may have made "buf" invalid! */ // Careful: autocommands may have made "buf" invalid!
update_curbuf(NOT_VALID); update_curbuf(NOT_VALID);
} }
@@ -1684,7 +1684,7 @@ window_set_cursor(VALUE self, VALUE pos)
win->w_cursor.lnum = NUM2LONG(lnum); win->w_cursor.lnum = NUM2LONG(lnum);
win->w_cursor.col = NUM2UINT(col); win->w_cursor.col = NUM2UINT(col);
win->w_set_curswant = TRUE; win->w_set_curswant = TRUE;
check_cursor(); /* put cursor on an existing line */ check_cursor(); // put cursor on an existing line
update_screen(NOT_VALID); update_screen(NOT_VALID);
return Qnil; return Qnil;
} }
@@ -1739,8 +1739,8 @@ ruby_vim_init(void)
objtbl = rb_hash_new(); objtbl = rb_hash_new();
rb_global_variable(&objtbl); rb_global_variable(&objtbl);
/* The Vim module used to be called "VIM", but "Vim" is better. Make an // The Vim module used to be called "VIM", but "Vim" is better. Make an
* alias "VIM" for backwards compatibility. */ // alias "VIM" for backwards compatibility.
mVIM = rb_define_module("Vim"); mVIM = rb_define_module("Vim");
rb_define_const(rb_cObject, "VIM", mVIM); rb_define_const(rb_cObject, "VIM", mVIM);
rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR)); rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR));
@@ -1775,8 +1775,8 @@ ruby_vim_init(void)
rb_define_method(cBuffer, "delete", buffer_delete, 1); rb_define_method(cBuffer, "delete", buffer_delete, 1);
rb_define_method(cBuffer, "append", buffer_append, 2); rb_define_method(cBuffer, "append", buffer_append, 2);
/* Added line manipulation functions // Added line manipulation functions
* SegPhault - 03/07/05 */ // SegPhault - 03/07/05
rb_define_method(cBuffer, "line_number", current_line_number, 0); rb_define_method(cBuffer, "line_number", current_line_number, 0);
rb_define_method(cBuffer, "line", line_s_current, 0); rb_define_method(cBuffer, "line", line_s_current, 0);
rb_define_method(cBuffer, "line=", set_current_line, 1); rb_define_method(cBuffer, "line=", set_current_line, 1);
@@ -1801,7 +1801,7 @@ ruby_vim_init(void)
void void
vim_ruby_init(void *stack_start) vim_ruby_init(void *stack_start)
{ {
/* should get machine stack start address early in main function */ // should get machine stack start address early in main function
ruby_stack_start = stack_start; ruby_stack_start = stack_start;
} }

View File

@@ -67,10 +67,10 @@ TODO:
*/ */
#include "vim.h" #include "vim.h"
#undef EXTERN /* tcl.h defines it too */ #undef EXTERN // tcl.h defines it too
#ifdef DYNAMIC_TCL #ifdef DYNAMIC_TCL
# define USE_TCL_STUBS /* use tcl's stubs mechanism */ # define USE_TCL_STUBS // use tcl's stubs mechanism
#endif #endif
#include <tcl.h> #include <tcl.h>
@@ -106,7 +106,7 @@ static tcl_info tclinfo = { NULL, 0, 0, 0, 0, NULL, NULL };
#define VIMOUT ((ClientData)1) #define VIMOUT ((ClientData)1)
#define VIMERR ((ClientData)2) #define VIMERR ((ClientData)2)
/* This appears to be new in Tcl 8.4. */ // This appears to be new in Tcl 8.4.
#ifndef CONST84 #ifndef CONST84
# define CONST84 # define CONST84
#endif #endif
@@ -123,9 +123,9 @@ struct ref
struct ref *next; struct ref *next;
Tcl_Interp *interp; Tcl_Interp *interp;
Tcl_Command cmd; /* Tcl command that represents this object */ Tcl_Command cmd; // Tcl command that represents this object
Tcl_Obj *delcmd; /* Tcl command to call when object is being del. */ Tcl_Obj *delcmd; // Tcl command to call when object is being del.
void *vimobj; /* Vim window or buffer (win_T* or buf_T*) */ void *vimobj; // Vim window or buffer (win_T* or buf_T*)
}; };
static char * tclgetbuffer _ANSI_ARGS_((Tcl_Interp *interp, buf_T *buf)); static char * tclgetbuffer _ANSI_ARGS_((Tcl_Interp *interp, buf_T *buf));
static char * tclgetwindow _ANSI_ARGS_((Tcl_Interp *interp, win_T *win)); static char * tclgetwindow _ANSI_ARGS_((Tcl_Interp *interp, win_T *win));
@@ -142,11 +142,11 @@ static void tclmsg _ANSI_ARGS_((char *text));
static void tclerrmsg _ANSI_ARGS_((char *text)); static void tclerrmsg _ANSI_ARGS_((char *text));
static void tclupdatevars _ANSI_ARGS_((void)); static void tclupdatevars _ANSI_ARGS_((void));
static struct ref refsdeleted; /* dummy object for deleted ref list */ static struct ref refsdeleted; // dummy object for deleted ref list
/***************************************************************************** //////////////////////////////////////////////////////////////////////////////
* TCL interface manager // TCL interface manager
****************************************************************************/ ////////////////////////////////////////////////////////////////////////////
#if defined(DYNAMIC_TCL) || defined(PROTO) #if defined(DYNAMIC_TCL) || defined(PROTO)
# ifndef DYNAMIC_TCL_DLL # ifndef DYNAMIC_TCL_DLL
@@ -156,7 +156,7 @@ static struct ref refsdeleted; /* dummy object for deleted ref list */
# define DYNAMIC_TCL_VER "8.3" # define DYNAMIC_TCL_VER "8.3"
# endif # endif
# ifndef DYNAMIC_TCL /* Just generating prototypes */ # ifndef DYNAMIC_TCL // Just generating prototypes
typedef int HANDLE; typedef int HANDLE;
# endif # endif
@@ -230,7 +230,7 @@ tcl_runtime_link_init(char *libname, int verbose)
} }
return OK; return OK;
} }
#endif /* defined(DYNAMIC_TCL) || defined(PROTO) */ #endif // defined(DYNAMIC_TCL) || defined(PROTO)
#ifdef DYNAMIC_TCL #ifdef DYNAMIC_TCL
static char *find_executable_arg = NULL; static char *find_executable_arg = NULL;
@@ -270,7 +270,7 @@ tcl_enabled(int verbose)
Tcl_DeleteInterp(interp); Tcl_DeleteInterp(interp);
stubs_initialized = TRUE; stubs_initialized = TRUE;
} }
/* FIXME: When Tcl_InitStubs() was failed, how delete interp? */ // FIXME: When Tcl_InitStubs() was failed, how delete interp?
} }
} }
return stubs_initialized; return stubs_initialized;
@@ -289,9 +289,9 @@ tcl_end(void)
#endif #endif
} }
/**************************************************************************** /////////////////////////////////////////////////////////////////////////////
Tcl commands // Tcl commands
****************************************************************************/ ////////////////////////////////////////////////////////////////////////////
/* /*
* Replace standard "exit" command. * Replace standard "exit" command.
@@ -321,7 +321,7 @@ exitcmd(
case 2: case 2:
if (Tcl_GetIntFromObj(interp, objv[1], &value) != TCL_OK) if (Tcl_GetIntFromObj(interp, objv[1], &value) != TCL_OK)
break; break;
/* FALLTHROUGH */ // FALLTHROUGH
case 1: case 1:
tclinfo.exitvalue = value; tclinfo.exitvalue = value;
@@ -402,7 +402,7 @@ buffercmd(
Tcl_SetResult(interp, _("invalid buffer number"), TCL_STATIC); Tcl_SetResult(interp, _("invalid buffer number"), TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
Tcl_ResetResult(interp); /* clear error from Tcl_GetIntFromObj */ Tcl_ResetResult(interp); // clear error from Tcl_GetIntFromObj
err = Tcl_GetIndexFromObj(interp, objv[1], bcmdoptions, "option", 0, &idx); err = Tcl_GetIndexFromObj(interp, objv[1], bcmdoptions, "option", 0, &idx);
if (err != TCL_OK) if (err != TCL_OK)
@@ -576,7 +576,7 @@ bufselfcmd(
* Get line number of last line. * Get line number of last line.
*/ */
opt = 1; opt = 1;
/* fallthrough */ // fallthrough
case BUF_COUNT: case BUF_COUNT:
/* /*
* Get number of lines in buffer. * Get number of lines in buffer.
@@ -639,7 +639,7 @@ bufselfcmd(
err = TCL_ERROR; err = TCL_ERROR;
} }
} }
else { /* objc == 3 */ else { // objc == 3
line = (char *)ml_get_buf(buf, (linenr_T)val1, FALSE); line = (char *)ml_get_buf(buf, (linenr_T)val1, FALSE);
Tcl_SetResult(interp, line, TCL_VOLATILE); Tcl_SetResult(interp, line, TCL_VOLATILE);
} }
@@ -725,7 +725,7 @@ bufselfcmd(
} }
if (i < lc) if (i < lc)
{ {
/* append lines */ // append lines
do do
{ {
line = Tcl_GetStringFromObj(lv[i], NULL); line = Tcl_GetStringFromObj(lv[i], NULL);
@@ -738,7 +738,7 @@ bufselfcmd(
} }
else if (n <= val2) else if (n <= val2)
{ {
/* did not replace all lines, delete */ // did not replace all lines, delete
i = n; i = n;
do do
{ {
@@ -747,13 +747,13 @@ bufselfcmd(
++n; ++n;
} while (n <= val2); } while (n <= val2);
} }
lc -= val2 - val1 + 1; /* number of lines to be replaced */ lc -= val2 - val1 + 1; // number of lines to be replaced
mark_adjust((linenr_T)val1, (linenr_T)val2, (long)MAXLNUM, mark_adjust((linenr_T)val1, (linenr_T)val2, (long)MAXLNUM,
(long)lc); (long)lc);
changed_lines((linenr_T)val1, 0, (linenr_T)val2 + 1, (long)lc); changed_lines((linenr_T)val1, 0, (linenr_T)val2 + 1, (long)lc);
break; break;
setListError: setListError:
u_undo(1); /* ??? */ u_undo(1); // ???
Tcl_SetResult(interp, _("cannot set line(s)"), TCL_STATIC); Tcl_SetResult(interp, _("cannot set line(s)"), TCL_STATIC);
err = TCL_ERROR; err = TCL_ERROR;
} }
@@ -838,7 +838,7 @@ bufselfcmd(
case BUF_INSERT: case BUF_INSERT:
opt = 1; opt = 1;
/* fallthrough */ // fallthrough
case BUF_APPEND: case BUF_APPEND:
if (objc != 4) if (objc != 4)
{ {
@@ -1078,7 +1078,7 @@ winselfcmd(
if (err != TCL_OK) if (err != TCL_OK)
break; break;
} }
else { /* objc == 4 */ else { // objc == 4
err = tclgetlinenum(interp, objv[2], &val1, win->w_buffer); err = tclgetlinenum(interp, objv[2], &val1, win->w_buffer);
if (err != TCL_OK) if (err != TCL_OK)
break; break;
@@ -1086,7 +1086,7 @@ winselfcmd(
if (err != TCL_OK) if (err != TCL_OK)
break; break;
} }
/* TODO: should check column */ // TODO: should check column
win->w_cursor.lnum = val1; win->w_cursor.lnum = val1;
win->w_cursor.col = col2vim(val2); win->w_cursor.col = col2vim(val2);
win->w_set_curswant = TRUE; win->w_set_curswant = TRUE;
@@ -1145,9 +1145,9 @@ exprcmd(
return tclvimexpr(interp, objc, objv, 1); return tclvimexpr(interp, objc, objv, 1);
} }
/**************************************************************************** /////////////////////////////////////////////////////////////////////////////
Support functions for Tcl commands // Support functions for Tcl commands
****************************************************************************/ ////////////////////////////////////////////////////////////////////////////
/* /*
* Get a line number from 'obj' and convert it to vim's range. * Get a line number from 'obj' and convert it to vim's range.
@@ -1215,7 +1215,7 @@ tclfindwin(buf_T *buf)
if (win->w_buffer == buf) if (win->w_buffer == buf)
return win; return win;
} }
return curwin; /* keep current window context */ return curwin; // keep current window context
} }
/* /*
@@ -1267,7 +1267,7 @@ tcldoexcommand(
--emsg_off; --emsg_off;
err = vimerror(interp); err = vimerror(interp);
/* If the ex command created a new Tcl interpreter, remove it */ // If the ex command created a new Tcl interpreter, remove it
if (tclinfo.interp) if (tclinfo.interp)
tcldelthisinterp(); tcldelthisinterp();
memcpy(&tclinfo, &saveinfo, sizeof(tcl_info)); memcpy(&tclinfo, &saveinfo, sizeof(tcl_info));
@@ -1325,7 +1325,7 @@ tclsetoption(
{ {
if (isnum) if (isnum)
{ {
sval = NULL; /* avoid compiler warning */ sval = NULL; // avoid compiler warning
err = Tcl_GetIndexFromObj(interp, objv[objn], optkw, "", 0, &idx); err = Tcl_GetIndexFromObj(interp, objv[objn], optkw, "", 0, &idx);
if (err != TCL_OK) if (err != TCL_OK)
{ {
@@ -1440,11 +1440,11 @@ delref(ClientData cref)
static char * static char *
tclgetref( tclgetref(
Tcl_Interp *interp, Tcl_Interp *interp,
void **refstartP, /* ptr to w_tcl_ref/b_tcl-ref member of void **refstartP, // ptr to w_tcl_ref/b_tcl-ref member of
win_T/buf_T struct */ // win_T/buf_T struct
char *prefix, /* "win" or "buf" */ char *prefix, // "win" or "buf"
void *vimobj, /* win_T* or buf_T* */ void *vimobj, // win_T* or buf_T*
Tcl_ObjCmdProc *proc) /* winselfcmd or bufselfcmd */ Tcl_ObjCmdProc *proc) // winselfcmd or bufselfcmd
{ {
struct ref *ref, *unused = NULL; struct ref *ref, *unused = NULL;
static char name[VARNAME_SIZE]; static char name[VARNAME_SIZE];
@@ -1481,7 +1481,7 @@ tclgetref(
(*refstartP) = (void *)ref; (*refstartP) = (void *)ref;
} }
/* This might break on some exotic systems... */ // This might break on some exotic systems...
vim_snprintf(name, sizeof(name), "::vim::%s_%lx", vim_snprintf(name, sizeof(name), "::vim::%s_%lx",
prefix, (unsigned long)vimobj); prefix, (unsigned long)vimobj);
cmd = Tcl_CreateObjCommand(interp, name, proc, cmd = Tcl_CreateObjCommand(interp, name, proc,
@@ -1534,23 +1534,23 @@ tclsetdelcmd(
} }
reflist = reflist->next; reflist = reflist->next;
} }
/* This should never happen. Famous last word? */ // This should never happen. Famous last word?
emsg(_("E280: TCL FATAL ERROR: reflist corrupt!? Please report this to vim-dev@vim.org")); emsg(_("E280: TCL FATAL ERROR: reflist corrupt!? Please report this to vim-dev@vim.org"));
Tcl_SetResult(interp, _("cannot register callback command: buffer/window reference not found"), TCL_STATIC); Tcl_SetResult(interp, _("cannot register callback command: buffer/window reference not found"), TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
/******************************************* ////////////////////////////////////////////
I/O Channel // I/O Channel
********************************************/ ////////////////////////////////////////////
static int static int
tcl_channel_close(ClientData instance, Tcl_Interp *interp UNUSED) tcl_channel_close(ClientData instance, Tcl_Interp *interp UNUSED)
{ {
int err = 0; int err = 0;
/* currently does nothing */ // currently does nothing
if (instance != VIMOUT && instance != VIMERR) if (instance != VIMOUT && instance != VIMERR)
{ {
@@ -1568,7 +1568,7 @@ tcl_channel_input(
int *errptr) int *errptr)
{ {
/* input is currently not supported */ // input is currently not supported
Tcl_SetErrno(EINVAL); Tcl_SetErrno(EINVAL);
if (errptr) if (errptr)
@@ -1586,10 +1586,9 @@ tcl_channel_output(
char_u *str; char_u *str;
int result; int result;
/* The buffer is not guaranteed to be 0-terminated, and we don't if // The buffer is not guaranteed to be 0-terminated, and we don't if
* there is enough room to add a '\0'. So we have to create a copy // there is enough room to add a '\0'. So we have to create a copy
* of the buffer... // of the buffer...
*/
str = vim_strnsave((char_u *)buf, bufsiz); str = vim_strnsave((char_u *)buf, bufsiz);
if (!str) if (!str)
{ {
@@ -1635,43 +1634,43 @@ tcl_channel_gethandle(
static Tcl_ChannelType tcl_channel_type = static Tcl_ChannelType tcl_channel_type =
{ {
"vimmessage", /* typeName */ "vimmessage", // typeName
TCL_CHANNEL_VERSION_2, /* version */ TCL_CHANNEL_VERSION_2, // version
tcl_channel_close, /* closeProc */ tcl_channel_close, // closeProc
tcl_channel_input, /* inputProc */ tcl_channel_input, // inputProc
tcl_channel_output, /* outputProc */ tcl_channel_output, // outputProc
NULL, /* seekProc */ NULL, // seekProc
NULL, /* setOptionProc */ NULL, // setOptionProc
NULL, /* getOptionProc */ NULL, // getOptionProc
tcl_channel_watch, /* watchProc */ tcl_channel_watch, // watchProc
tcl_channel_gethandle, /* getHandleProc */ tcl_channel_gethandle, // getHandleProc
NULL, /* close2Proc */ NULL, // close2Proc
NULL, /* blockModeProc */ NULL, // blockModeProc
#ifdef TCL_CHANNEL_VERSION_2 #ifdef TCL_CHANNEL_VERSION_2
NULL, /* flushProc */ NULL, // flushProc
NULL, /* handlerProc */ NULL, // handlerProc
#endif #endif
/* The following should not be necessary since TCL_CHANNEL_VERSION_2 was // The following should not be necessary since TCL_CHANNEL_VERSION_2 was
* set above */ // set above
#ifdef TCL_CHANNEL_VERSION_3 #ifdef TCL_CHANNEL_VERSION_3
NULL, /* wideSeekProc */ NULL, // wideSeekProc
#endif #endif
#ifdef TCL_CHANNEL_VERSION_4 #ifdef TCL_CHANNEL_VERSION_4
NULL, /* threadActionProc */ NULL, // threadActionProc
#endif #endif
#ifdef TCL_CHANNEL_VERSION_5 #ifdef TCL_CHANNEL_VERSION_5
NULL /* truncateProc */ NULL // truncateProc
#endif #endif
}; };
/********************************** ///////////////////////////////////
Interface to vim // Interface to vim
**********************************/ //////////////////////////////////
static void static void
tclupdatevars(void) tclupdatevars(void)
{ {
char varname[VARNAME_SIZE]; /* must be writeable */ char varname[VARNAME_SIZE]; // must be writeable
char *name; char *name;
strcpy(varname, VAR_RANGE1); strcpy(varname, VAR_RANGE1);
@@ -1699,7 +1698,7 @@ tclupdatevars(void)
static int static int
tclinit(exarg_T *eap) tclinit(exarg_T *eap)
{ {
char varname[VARNAME_SIZE]; /* Tcl_LinkVar requires writeable varname */ char varname[VARNAME_SIZE]; // Tcl_LinkVar requires writeable varname
char *name; char *name;
#ifdef DYNAMIC_TCL #ifdef DYNAMIC_TCL
@@ -1715,9 +1714,9 @@ tclinit(exarg_T *eap)
Tcl_Interp *interp; Tcl_Interp *interp;
static Tcl_Channel ch1, ch2; static Tcl_Channel ch1, ch2;
/* Create replacement channels for stdout and stderr; this has to be // Create replacement channels for stdout and stderr; this has to be
* done each time an interpreter is created since the channels are closed // done each time an interpreter is created since the channels are closed
* when the interpreter is deleted */ // when the interpreter is deleted
ch1 = Tcl_CreateChannel(&tcl_channel_type, "vimout", VIMOUT, TCL_WRITABLE); ch1 = Tcl_CreateChannel(&tcl_channel_type, "vimout", VIMOUT, TCL_WRITABLE);
ch2 = Tcl_CreateChannel(&tcl_channel_type, "vimerr", VIMERR, TCL_WRITABLE); ch2 = Tcl_CreateChannel(&tcl_channel_type, "vimerr", VIMERR, TCL_WRITABLE);
Tcl_SetStdChannel(ch1, TCL_STDOUT); Tcl_SetStdChannel(ch1, TCL_STDOUT);
@@ -1732,7 +1731,7 @@ tclinit(exarg_T *eap)
return FAIL; return FAIL;
} }
#if 0 #if 0
/* VIM sure is interactive */ // VIM sure is interactive
Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
#endif #endif
@@ -1745,12 +1744,12 @@ tclinit(exarg_T *eap)
Tcl_SetChannelOption(interp, ch2, "-translation", "lf"); Tcl_SetChannelOption(interp, ch2, "-translation", "lf");
#endif #endif
/* replace standard Tcl exit command */ // replace standard Tcl exit command
Tcl_DeleteCommand(interp, "exit"); Tcl_DeleteCommand(interp, "exit");
Tcl_CreateObjCommand(interp, "exit", exitcmd, Tcl_CreateObjCommand(interp, "exit", exitcmd,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
/* new commands, in ::vim namespace */ // new commands, in ::vim namespace
Tcl_CreateObjCommand(interp, "::vim::buffer", buffercmd, Tcl_CreateObjCommand(interp, "::vim::buffer", buffercmd,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "::vim::window", windowcmd, Tcl_CreateObjCommand(interp, "::vim::window", windowcmd,
@@ -1764,12 +1763,12 @@ tclinit(exarg_T *eap)
Tcl_CreateObjCommand(interp, "::vim::expr", exprcmd, Tcl_CreateObjCommand(interp, "::vim::expr", exprcmd,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
/* "lbase" variable */ // "lbase" variable
tclinfo.lbase = 1; tclinfo.lbase = 1;
strcpy(varname, VAR_LBASE); strcpy(varname, VAR_LBASE);
Tcl_LinkVar(interp, varname, (char *)&tclinfo.lbase, TCL_LINK_INT); Tcl_LinkVar(interp, varname, (char *)&tclinfo.lbase, TCL_LINK_INT);
/* "range" variable */ // "range" variable
tclinfo.range_start = eap->line1; tclinfo.range_start = eap->line1;
strcpy(varname, VAR_RANGE1); strcpy(varname, VAR_RANGE1);
Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_start, TCL_LINK_INT|TCL_LINK_READ_ONLY); Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_start, TCL_LINK_INT|TCL_LINK_READ_ONLY);
@@ -1779,7 +1778,7 @@ tclinit(exarg_T *eap)
strcpy(varname, VAR_RANGE3); strcpy(varname, VAR_RANGE3);
Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_end, TCL_LINK_INT|TCL_LINK_READ_ONLY); Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_end, TCL_LINK_INT|TCL_LINK_READ_ONLY);
/* "current" variable */ // "current" variable
tclinfo.curbuf = Tcl_Alloc(VARNAME_SIZE); tclinfo.curbuf = Tcl_Alloc(VARNAME_SIZE);
tclinfo.curwin = Tcl_Alloc(VARNAME_SIZE); tclinfo.curwin = Tcl_Alloc(VARNAME_SIZE);
name = tclgetbuffer(interp, curbuf); name = tclgetbuffer(interp, curbuf);
@@ -1795,7 +1794,7 @@ tclinit(exarg_T *eap)
} }
else else
{ {
/* Interpreter already exists, just update variables */ // Interpreter already exists, just update variables
tclinfo.range_start = row2tcl(eap->line1); tclinfo.range_start = row2tcl(eap->line1);
tclinfo.range_end = row2tcl(eap->line2); tclinfo.range_end = row2tcl(eap->line2);
tclupdatevars(); tclupdatevars();
@@ -1841,15 +1840,14 @@ tcldelthisinterp(void)
if (!Tcl_InterpDeleted(tclinfo.interp)) if (!Tcl_InterpDeleted(tclinfo.interp))
Tcl_DeleteInterp(tclinfo.interp); Tcl_DeleteInterp(tclinfo.interp);
Tcl_Release(tclinfo.interp); Tcl_Release(tclinfo.interp);
/* The interpreter is now gets deleted. All registered commands (esp. // The interpreter is now gets deleted. All registered commands (esp.
* window and buffer commands) are deleted, triggering their deletion // window and buffer commands) are deleted, triggering their deletion
* callback, which deletes all refs pointing to this interpreter. // callback, which deletes all refs pointing to this interpreter.
* We could garbage-collect the unused ref structs in all windows and // We could garbage-collect the unused ref structs in all windows and
* buffers, but unless the user creates hundreds of sub-interpreters // buffers, but unless the user creates hundreds of sub-interpreters
* all referring to lots of windows and buffers, this is hardly worth // all referring to lots of windows and buffers, this is hardly worth
* the effort. Unused refs are recycled by other interpreters, and // the effort. Unused refs are recycled by other interpreters, and
* all refs are free'd when the window/buffer gets closed by vim. // all refs are free'd when the window/buffer gets closed by vim.
*/
tclinfo.interp = NULL; tclinfo.interp = NULL;
Tcl_Free(tclinfo.curbuf); Tcl_Free(tclinfo.curbuf);
@@ -1862,9 +1860,9 @@ tclexit(int error)
{ {
int newerr = OK; int newerr = OK;
if (Tcl_InterpDeleted(tclinfo.interp) /* True if we intercepted Tcl's exit command */ if (Tcl_InterpDeleted(tclinfo.interp) // True if we intercepted Tcl's exit command
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8 #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8
|| Tcl_LimitExceeded(tclinfo.interp) /* True if the interpreter cannot continue */ || Tcl_LimitExceeded(tclinfo.interp) // True if the interpreter cannot continue
#endif #endif
) )
{ {
@@ -1954,7 +1952,7 @@ ex_tcldo(exarg_T *eap)
{ {
char *script, *line; char *script, *line;
int err, rs, re, lnum; int err, rs, re, lnum;
char var_lnum[VARNAME_SIZE]; /* must be writeable memory */ char var_lnum[VARNAME_SIZE]; // must be writeable memory
char var_line[VARNAME_SIZE]; char var_line[VARNAME_SIZE];
linenr_T first_line = 0; linenr_T first_line = 0;
linenr_T last_line = 0; linenr_T last_line = 0;
@@ -2035,7 +2033,7 @@ tcldelallrefs(struct ref *ref)
char *result; char *result;
#ifdef DYNAMIC_TCL #ifdef DYNAMIC_TCL
/* TODO: this code currently crashes Vim on exit */ // TODO: this code currently crashes Vim on exit
if (exiting) if (exiting)
return; return;
#endif #endif
@@ -2070,7 +2068,7 @@ tcl_buffer_free(buf_T *buf)
struct ref *reflist; struct ref *reflist;
#ifdef DYNAMIC_TCL #ifdef DYNAMIC_TCL
if (!stubs_initialized) /* Not using Tcl, nothing to do. */ if (!stubs_initialized) // Not using Tcl, nothing to do.
return; return;
#endif #endif
@@ -2089,7 +2087,7 @@ tcl_window_free(win_T *win)
struct ref *reflist; struct ref *reflist;
#ifdef DYNAMIC_TCL #ifdef DYNAMIC_TCL
if (!stubs_initialized) /* Not using Tcl, nothing to do. */ if (!stubs_initialized) // Not using Tcl, nothing to do.
return; return;
#endif #endif
@@ -2102,4 +2100,4 @@ tcl_window_free(win_T *win)
} }
} }
/* The End */ // The End

View File

@@ -64,18 +64,18 @@
typedef struct PendingCommand typedef struct PendingCommand
{ {
int serial; /* Serial number expected in result. */ int serial; // Serial number expected in result.
int code; /* Result Code. 0 is OK */ int code; // Result Code. 0 is OK
char_u *result; /* String result for command (malloc'ed). char_u *result; // String result for command (malloc'ed).
* NULL means command still pending. */ // NULL means command still pending.
struct PendingCommand *nextPtr; struct PendingCommand *nextPtr;
/* Next in list of all outstanding commands. // Next in list of all outstanding commands.
* NULL means end of list. */ // NULL means end of list.
} PendingCommand; } PendingCommand;
static PendingCommand *pendingCommands = NULL; static PendingCommand *pendingCommands = NULL;
/* List of all commands currently // List of all commands currently
* being waited for. */ // being waited for.
/* /*
* The information below is used for communication between processes * The information below is used for communication between processes
@@ -179,7 +179,7 @@ struct x_cmdqueue
typedef struct x_cmdqueue x_queue_T; typedef struct x_cmdqueue x_queue_T;
/* dummy node, header for circular queue */ // dummy node, header for circular queue
static x_queue_T head = {NULL, 0, NULL, NULL}; static x_queue_T head = {NULL, 0, NULL, NULL};
/* /*
@@ -200,12 +200,12 @@ static int IsSerialName(char_u *name);
static void save_in_queue(char_u *buf, long_u len); static void save_in_queue(char_u *buf, long_u len);
static void server_parse_message(Display *dpy, char_u *propInfo, long_u numItems); static void server_parse_message(Display *dpy, char_u *propInfo, long_u numItems);
/* Private variables for the "server" functionality */ // Private variables for the "server" functionality
static Atom registryProperty = None; static Atom registryProperty = None;
static Atom vimProperty = None; static Atom vimProperty = None;
static int got_x_error = FALSE; static int got_x_error = FALSE;
static char_u *empty_prop = (char_u *)""; /* empty GetRegProp() result */ static char_u *empty_prop = (char_u *)""; // empty GetRegProp() result
/* /*
* Associate an ASCII name with Vim. Try real hard to get a unique one. * Associate an ASCII name with Vim. Try real hard to get a unique one.
@@ -213,8 +213,8 @@ static char_u *empty_prop = (char_u *)""; /* empty GetRegProp() result */
*/ */
int int
serverRegisterName( serverRegisterName(
Display *dpy, /* display to register with */ Display *dpy, // display to register with
char_u *name) /* the name that will be used as a base */ char_u *name) // the name that will be used as a base
{ {
int i; int i;
int res; int res;
@@ -329,25 +329,25 @@ DoRegisterName(Display *dpy, char_u *name)
*/ */
void void
serverChangeRegisteredWindow( serverChangeRegisteredWindow(
Display *dpy, /* Display to register with */ Display *dpy, // Display to register with
Window newwin) /* Re-register to this ID */ Window newwin) // Re-register to this ID
{ {
char_u propInfo[MAX_NAME_LENGTH + 20]; char_u propInfo[MAX_NAME_LENGTH + 20];
commWindow = newwin; commWindow = newwin;
/* Always call SendInit() here, to make sure commWindow is marked as a Vim // Always call SendInit() here, to make sure commWindow is marked as a Vim
* window. */ // window.
if (SendInit(dpy) < 0) if (SendInit(dpy) < 0)
return; return;
/* WARNING: Do not step through this while debugging, it will hangup the X // WARNING: Do not step through this while debugging, it will hangup the X
* server! */ // server!
XGrabServer(dpy); XGrabServer(dpy);
DeleteAnyLingerer(dpy, newwin); DeleteAnyLingerer(dpy, newwin);
if (serverName != NULL) if (serverName != NULL)
{ {
/* Reinsert name if we was already registered */ // Reinsert name if we was already registered
(void)LookupName(dpy, serverName, /*delete=*/TRUE, NULL); (void)LookupName(dpy, serverName, /*delete=*/TRUE, NULL);
sprintf((char *)propInfo, "%x %.*s", sprintf((char *)propInfo, "%x %.*s",
(int_u)newwin, MAX_NAME_LENGTH, serverName); (int_u)newwin, MAX_NAME_LENGTH, serverName);
@@ -365,30 +365,30 @@ serverChangeRegisteredWindow(
*/ */
int int
serverSendToVim( serverSendToVim(
Display *dpy, /* Where to send. */ Display *dpy, // Where to send.
char_u *name, /* Where to send. */ char_u *name, // Where to send.
char_u *cmd, /* What to send. */ char_u *cmd, // What to send.
char_u **result, /* Result of eval'ed expression */ char_u **result, // Result of eval'ed expression
Window *server, /* Actual ID of receiving app */ Window *server, // Actual ID of receiving app
Bool asExpr, /* Interpret as keystrokes or expr ? */ Bool asExpr, // Interpret as keystrokes or expr ?
int timeout, /* seconds to wait or zero */ int timeout, // seconds to wait or zero
Bool localLoop, /* Throw away everything but result */ Bool localLoop, // Throw away everything but result
int silent) /* don't complain about no server */ int silent) // don't complain about no server
{ {
Window w; Window w;
char_u *property; char_u *property;
int length; int length;
int res; int res;
static int serial = 0; /* Running count of sent commands. static int serial = 0; // Running count of sent commands.
* Used to give each command a // Used to give each command a
* different serial number. */ // different serial number.
PendingCommand pending; PendingCommand pending;
char_u *loosename = NULL; char_u *loosename = NULL;
if (result != NULL) if (result != NULL)
*result = NULL; *result = NULL;
if (name == NULL || *name == NUL) if (name == NULL || *name == NUL)
name = (char_u *)"GVIM"; /* use a default name */ name = (char_u *)"GVIM"; // use a default name
if (commProperty == None && dpy != NULL) if (commProperty == None && dpy != NULL)
{ {
@@ -396,7 +396,7 @@ serverSendToVim(
return -1; return -1;
} }
/* Execute locally if no display or target is ourselves */ // Execute locally if no display or target is ourselves
if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0)) if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0))
return sendToLocalVim(cmd, asExpr, result); return sendToLocalVim(cmd, asExpr, result);
@@ -411,7 +411,7 @@ serverSendToVim(
while (TRUE) while (TRUE)
{ {
w = LookupName(dpy, name, FALSE, &loosename); w = LookupName(dpy, name, FALSE, &loosename);
/* Check that the window is hot */ // Check that the window is hot
if (w != None) if (w != None)
{ {
if (!WindowValid(dpy, w)) if (!WindowValid(dpy, w))
@@ -447,11 +447,11 @@ serverSendToVim(
0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd); 0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd);
if (name == loosename) if (name == loosename)
vim_free(loosename); vim_free(loosename);
/* Add a back reference to our comm window */ // Add a back reference to our comm window
serial++; serial++;
sprintf((char *)property + length, "%c-r %x %d", sprintf((char *)property + length, "%c-r %x %d",
0, (int_u)commWindow, serial); 0, (int_u)commWindow, serial);
/* Add length of what "-r %x %d" resulted in, skipping the NUL. */ // Add length of what "-r %x %d" resulted in, skipping the NUL.
length += STRLEN(property + length + 1) + 1; length += STRLEN(property + length + 1) + 1;
res = AppendPropCarefully(dpy, w, commProperty, property, length + 1); res = AppendPropCarefully(dpy, w, commProperty, property, length + 1);
@@ -462,7 +462,7 @@ serverSendToVim(
return -1; return -1;
} }
if (!asExpr) /* There is no answer for this - Keys are sent async */ if (!asExpr) // There is no answer for this - Keys are sent async
return 0; return 0;
/* /*
@@ -592,7 +592,7 @@ ServerWait(
check_due_timer(); check_due_timer();
#endif #endif
/* Just look out for the answer without calling back into Vim */ // Just look out for the answer without calling back into Vim
if (localLoop) if (localLoop)
{ {
#ifndef HAVE_SELECT #ifndef HAVE_SELECT
@@ -670,9 +670,8 @@ serverGetVimNames(Display *dpy)
return ga.ga_data; return ga.ga_data;
} }
/* ---------------------------------------------------------- /////////////////////////////////////////////////////////////
* Reply stuff // Reply stuff
*/
static struct ServerReply * static struct ServerReply *
ServerReplyFind(Window w, enum ServerReplyOp op) ServerReplyFind(Window w, enum ServerReplyOp op)
@@ -754,7 +753,7 @@ serverSendReply(char_u *name, char_u *str)
{ {
sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x", sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x",
0, 0, p_enc, 0, str, 0, (unsigned int)commWindow); 0, 0, p_enc, 0, str, 0, (unsigned int)commWindow);
/* Add length of what "%x" resulted in. */ // Add length of what "%x" resulted in.
length += STRLEN(property + length); length += STRLEN(property + length);
res = AppendPropCarefully(dpy, win, commProperty, property, length + 1); res = AppendPropCarefully(dpy, win, commProperty, property, length + 1);
vim_free(property); vim_free(property);
@@ -804,7 +803,7 @@ serverReadReply(
} }
else else
{ {
/* Last string read. Remove from list */ // Last string read. Remove from list
ga_clear(&p->strings); ga_clear(&p->strings);
ServerReplyFind(win, SROP_Delete); ServerReplyFind(win, SROP_Delete);
} }
@@ -864,14 +863,14 @@ SendInit(Display *dpy)
WhitePixel(dpy, DefaultScreen(dpy)), WhitePixel(dpy, DefaultScreen(dpy)),
WhitePixel(dpy, DefaultScreen(dpy))); WhitePixel(dpy, DefaultScreen(dpy)));
XSelectInput(dpy, commWindow, PropertyChangeMask); XSelectInput(dpy, commWindow, PropertyChangeMask);
/* WARNING: Do not step through this while debugging, it will hangup // WARNING: Do not step through this while debugging, it will hangup
* the X server! */ // the X server!
XGrabServer(dpy); XGrabServer(dpy);
DeleteAnyLingerer(dpy, commWindow); DeleteAnyLingerer(dpy, commWindow);
XUngrabServer(dpy); XUngrabServer(dpy);
} }
/* Make window recognizable as a vim window */ // Make window recognizable as a vim window
XChangeProperty(dpy, commWindow, vimProperty, XA_STRING, XChangeProperty(dpy, commWindow, vimProperty, XA_STRING,
8, PropModeReplace, (char_u *)VIM_VERSION_SHORT, 8, PropModeReplace, (char_u *)VIM_VERSION_SHORT,
(int)STRLEN(VIM_VERSION_SHORT) + 1); (int)STRLEN(VIM_VERSION_SHORT) + 1);
@@ -896,11 +895,11 @@ SendInit(Display *dpy)
*/ */
static Window static Window
LookupName( LookupName(
Display *dpy, /* Display whose registry to check. */ Display *dpy, // Display whose registry to check.
char_u *name, /* Name of a server. */ char_u *name, // Name of a server.
int delete, /* If non-zero, delete info about name. */ int delete, // If non-zero, delete info about name.
char_u **loose) /* Do another search matching -999 if not found char_u **loose) // Do another search matching -999 if not found
Return result here if a match is found */ // Return result here if a match is found
{ {
char_u *regProp, *entry; char_u *regProp, *entry;
char_u *p; char_u *p;
@@ -917,7 +916,7 @@ LookupName(
* Scan the property for the desired name. * Scan the property for the desired name.
*/ */
returnValue = (int_u)None; returnValue = (int_u)None;
entry = NULL; /* Not needed, but eliminates compiler warning. */ entry = NULL; // Not needed, but eliminates compiler warning.
for (p = regProp; (long_u)(p - regProp) < numItems; ) for (p = regProp; (long_u)(p - regProp) < numItems; )
{ {
entry = p; entry = p;
@@ -990,8 +989,8 @@ LookupName(
*/ */
static void static void
DeleteAnyLingerer( DeleteAnyLingerer(
Display *dpy, /* Display whose registry to check. */ Display *dpy, // Display whose registry to check.
Window win) /* Window to remove */ Window win) // Window to remove
{ {
char_u *regProp, *entry = NULL; char_u *regProp, *entry = NULL;
char_u *p; char_u *p;
@@ -1004,7 +1003,7 @@ DeleteAnyLingerer(
if (GetRegProp(dpy, &regProp, &numItems, FALSE) == FAIL) if (GetRegProp(dpy, &regProp, &numItems, FALSE) == FAIL)
return; return;
/* Scan the property for the window id. */ // Scan the property for the window id.
for (p = regProp; (long_u)(p - regProp) < numItems; ) for (p = regProp; (long_u)(p - regProp) < numItems; )
{ {
if (*p != 0) if (*p != 0)
@@ -1014,7 +1013,7 @@ DeleteAnyLingerer(
{ {
int lastHalf; int lastHalf;
/* Copy down the remainder to delete entry */ // Copy down the remainder to delete entry
entry = p; entry = p;
while (*p != 0) while (*p != 0)
p++; p++;
@@ -1055,7 +1054,7 @@ GetRegProp(
Display *dpy, Display *dpy,
char_u **regPropp, char_u **regPropp,
long_u *numItemsp, long_u *numItemsp,
int domsg) /* When TRUE give error message. */ int domsg) // When TRUE give error message.
{ {
int result, actualFormat; int result, actualFormat;
long_u bytesAfter; long_u bytesAfter;
@@ -1079,13 +1078,13 @@ GetRegProp(
if (actualType == None) if (actualType == None)
{ {
/* No prop yet. Logically equal to the empty list */ // No prop yet. Logically equal to the empty list
*numItemsp = 0; *numItemsp = 0;
*regPropp = empty_prop; *regPropp = empty_prop;
return OK; return OK;
} }
/* If the property is improperly formed, then delete it. */ // If the property is improperly formed, then delete it.
if (result != Success || actualFormat != 8 || actualType != XA_STRING) if (result != Success || actualFormat != 8 || actualType != XA_STRING)
{ {
if (*regPropp != NULL) if (*regPropp != NULL)
@@ -1110,8 +1109,8 @@ GetRegProp(
void void
serverEventProc( serverEventProc(
Display *dpy, Display *dpy,
XEvent *eventPtr, /* Information about event. */ XEvent *eventPtr, // Information about event.
int immediate) /* Run event immediately. Should mostly be 0. */ int immediate) // Run event immediately. Should mostly be 0.
{ {
char_u *propInfo; char_u *propInfo;
int result, actualFormat; int result, actualFormat;
@@ -1135,7 +1134,7 @@ serverEventProc(
&actualFormat, &numItems, &bytesAfter, &actualFormat, &numItems, &bytesAfter,
&propInfo); &propInfo);
/* If the property doesn't exist or is improperly formed then ignore it. */ // If the property doesn't exist or is improperly formed then ignore it.
if (result != Success || actualType != XA_STRING || actualFormat != 8) if (result != Success || actualType != XA_STRING || actualFormat != 8)
{ {
if (propInfo != NULL) if (propInfo != NULL)
@@ -1159,17 +1158,17 @@ save_in_queue(char_u *propInfo, long_u len)
node = ALLOC_ONE(x_queue_T); node = ALLOC_ONE(x_queue_T);
if (node == NULL) if (node == NULL)
return; /* out of memory */ return; // out of memory
node->propInfo = propInfo; node->propInfo = propInfo;
node->len = len; node->len = len;
if (head.next == NULL) /* initialize circular queue */ if (head.next == NULL) // initialize circular queue
{ {
head.next = &head; head.next = &head;
head.prev = &head; head.prev = &head;
} }
/* insert node at tail of queue */ // insert node at tail of queue
node->next = &head; node->next = &head;
node->prev = head.prev; node->prev = head.prev;
head.prev->next = node; head.prev->next = node;
@@ -1185,7 +1184,7 @@ server_parse_messages(void)
x_queue_T *node; x_queue_T *node;
if (!X_DISPLAY) if (!X_DISPLAY)
return; /* cannot happen? */ return; // cannot happen?
while (head.next != NULL && head.next != &head) while (head.next != NULL && head.next != &head)
{ {
node = head.next; node = head.next;
@@ -1214,8 +1213,8 @@ server_waiting(void)
static void static void
server_parse_message( server_parse_message(
Display *dpy, Display *dpy,
char_u *propInfo, /* A string containing 0 or more X commands */ char_u *propInfo, // A string containing 0 or more X commands
long_u numItems) /* The size of propInfo in bytes. */ long_u numItems) // The size of propInfo in bytes.
{ {
char_u *p; char_u *p;
int code; int code;
@@ -1276,7 +1275,7 @@ server_parse_message(
else else
{ {
p = serial = end + 1; p = serial = end + 1;
clientWindow = resWindow; /* Remember in global */ clientWindow = resWindow; // Remember in global
} }
break; break;
case 'n': case 'n':
@@ -1314,14 +1313,14 @@ server_parse_message(
{ {
garray_T reply; garray_T reply;
/* Initialize the result property. */ // Initialize the result property.
ga_init2(&reply, 1, 100); ga_init2(&reply, 1, 100);
(void)ga_grow(&reply, 50 + STRLEN(p_enc)); (void)ga_grow(&reply, 50 + STRLEN(p_enc));
sprintf(reply.ga_data, "%cr%c-E %s%c-s %s%c-r ", sprintf(reply.ga_data, "%cr%c-E %s%c-s %s%c-r ",
0, 0, p_enc, 0, serial, 0); 0, 0, p_enc, 0, serial, 0);
reply.ga_len = 14 + STRLEN(p_enc) + STRLEN(serial); reply.ga_len = 14 + STRLEN(p_enc) + STRLEN(serial);
/* Evaluate the expression and return the result. */ // Evaluate the expression and return the result.
if (res != NULL) if (res != NULL)
ga_concat(&reply, res); ga_concat(&reply, res);
else else
@@ -1485,11 +1484,11 @@ server_parse_message(
*/ */
static int static int
AppendPropCarefully( AppendPropCarefully(
Display *dpy, /* Display on which to operate. */ Display *dpy, // Display on which to operate.
Window window, /* Window whose property is to be modified. */ Window window, // Window whose property is to be modified.
Atom property, /* Name of property. */ Atom property, // Name of property.
char_u *value, /* Characters to append to property. */ char_u *value, // Characters to append to property.
int length) /* How much to append */ int length) // How much to append
{ {
XErrorHandler old_handler; XErrorHandler old_handler;
@@ -1524,4 +1523,4 @@ IsSerialName(char_u *str)
return (len > 1 && vim_isdigit(str[len - 1])); return (len > 1 && vim_isdigit(str[len - 1]));
} }
#endif /* FEAT_CLIENTSERVER */ #endif // FEAT_CLIENTSERVER

View File

@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2387,
/**/ /**/
2386, 2386,
/**/ /**/