Patch on top of 7.2.330
Problem: Netbeans keystrings are ignored in unregistered buffers
and not postponed.
An infinite loop occurs while processing postponed keys.
The infinite loop occurs while processing the keyQ_T
circular queue in handle_key_queue() and the current buffer
is not known to netbeans: the key keeps being removed from the
queue and postponed again (added again to the queue) in the
while loop.
Solution: Add keystrings to postponed keys.
Have netbeans_keystring() return FALSE when the key is
postponed and break from the loop in this case.
Files: src/netbeans.c src/proto/netbeans.pro
=====================================================================
Postpone netbeans keystrings and fix infinite loop while processing
postponed keys.
diff --git a/src/netbeans.c b/src/netbeans.c
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -70,7 +70,8 @@
static pos_T *off2pos __ARGS((buf_T *, long));
static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp));
static long get_buf_size __ARGS((buf_T *));
-static void netbeans_keystring __ARGS((int key, char *keystr));
+static int netbeans_keystring __ARGS((int key, char_u *keystr));
+static void postpone_keycommand __ARGS((int key, char_u *keystr));
static void special_keys __ARGS((char_u *args));
static void netbeans_connect __ARGS((void));
@@ -503,6 +504,7 @@
struct keyqueue
{
int key;
+ char_u *keystr;
struct keyqueue *next;
struct keyqueue *prev;
};
@@ -516,7 +518,7 @@
* Queue up key commands sent from netbeans.
*/
static void
-postpone_keycommand(int key)
+postpone_keycommand(int key, char_u *keystr)
{
keyQ_T *node;
@@ -535,6 +537,7 @@
keyHead.prev = node;
node->key = key;
+ node->keystr = (key == 0 ? vim_strsave(keystr) : NULL);
}
/*
@@ -543,7 +546,9 @@
static void
handle_key_queue(void)
{
- while (keyHead.next && keyHead.next != &keyHead)
+ int not_postponed = TRUE;
+
+ while (not_postponed && keyHead.next && keyHead.next != &keyHead)
{
/* first, unlink the node */
keyQ_T *node = keyHead.next;
@@ -551,7 +556,13 @@
node->next->prev = node->prev;
/* now, send the keycommand */
- netbeans_keycommand(node->key);
+ if (node->keystr != NULL)
+ {
+ not_postponed = netbeans_keystring(node->key, node->keystr);
+ vim_free(node->keystr);
+ }
+ else
+ not_postponed = netbeans_keycommand(node->key);
/* Finally, dispose of the node */
vim_free(node);
@@ -2658,7 +2669,7 @@
ex_nbkey(eap)
exarg_T *eap;
{
- netbeans_keystring(0, (char *)eap->arg);
+ netbeans_keystring(0, eap->arg);
}
@@ -3127,23 +3138,26 @@
/*
* Send a keypress event back to netbeans. This usually simulates some
* kind of function key press. This function operates on a key code.
+ * Return FALSE when the command has been postponed.
*/
- void
+ int
netbeans_keycommand(int key)
{
char keyName[60];
netbeans_keyname(key, keyName);
- netbeans_keystring(key, keyName);
+ return netbeans_keystring(key, (char_u *)keyName);
}
/*
* Send a keypress event back to netbeans. This usually simulates some
* kind of function key press. This function operates on a key string.
+ * Return FALSE when the command has been postponed.
*/
- static void
-netbeans_keystring(int key, char *keyName)
+
+ static int
+netbeans_keystring(int key, char_u *keyName)
{
char buf[2*MAXPATHL];
int bufno = nb_getbufno(curbuf);
@@ -3151,7 +3165,7 @@
char_u *q;
if (!haveConnection)
- return;
+ return TRUE;
if (bufno == -1)
@@ -3160,7 +3174,7 @@
q = curbuf->b_ffname == NULL ? (char_u *)""
: nb_quote(curbuf->b_ffname);
if (q == NULL)
- return;
+ return TRUE;
vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0,
q,
"T", /* open in NetBeans */
@@ -3170,9 +3184,8 @@
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
- if (key > 0)
- postpone_keycommand(key);
- return;
+ postpone_keycommand(key, keyName);
+ return FALSE;
}
/* sync the cursor position */
@@ -3198,6 +3211,7 @@
off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
+ return TRUE;
}
diff --git a/src/proto/netbeans.pro b/src/proto/netbeans.pro
--- a/src/proto/netbeans.pro
+++ b/src/proto/netbeans.pro
@@ -16,7 +16,7 @@
void netbeans_removed __ARGS((buf_T *bufp, linenr_T linenr, colnr_T
col, long len));
void netbeans_unmodified __ARGS((buf_T *bufp));
void netbeans_button_release __ARGS((int button));
-void netbeans_keycommand __ARGS((int key));
+int netbeans_keycommand __ARGS((int key));
void netbeans_save_buffer __ARGS((buf_T *bufp));
void netbeans_deleted_all_lines __ARGS((buf_T *bufp));
int netbeans_is_guarded __ARGS((linenr_T top, linenr_T bot));
--
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
Postpone netbeans keystrings and fix infinite loop while processing postponed keys.
diff --git a/src/netbeans.c b/src/netbeans.c
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -70,7 +70,8 @@
static pos_T *off2pos __ARGS((buf_T *, long));
static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp));
static long get_buf_size __ARGS((buf_T *));
-static void netbeans_keystring __ARGS((int key, char *keystr));
+static int netbeans_keystring __ARGS((int key, char_u *keystr));
+static void postpone_keycommand __ARGS((int key, char_u *keystr));
static void special_keys __ARGS((char_u *args));
static void netbeans_connect __ARGS((void));
@@ -503,6 +504,7 @@
struct keyqueue
{
int key;
+ char_u *keystr;
struct keyqueue *next;
struct keyqueue *prev;
};
@@ -516,7 +518,7 @@
* Queue up key commands sent from netbeans.
*/
static void
-postpone_keycommand(int key)
+postpone_keycommand(int key, char_u *keystr)
{
keyQ_T *node;
@@ -535,6 +537,7 @@
keyHead.prev = node;
node->key = key;
+ node->keystr = (key == 0 ? vim_strsave(keystr) : NULL);
}
/*
@@ -543,7 +546,9 @@
static void
handle_key_queue(void)
{
- while (keyHead.next && keyHead.next != &keyHead)
+ int not_postponed = TRUE;
+
+ while (not_postponed && keyHead.next && keyHead.next != &keyHead)
{
/* first, unlink the node */
keyQ_T *node = keyHead.next;
@@ -551,7 +556,13 @@
node->next->prev = node->prev;
/* now, send the keycommand */
- netbeans_keycommand(node->key);
+ if (node->keystr != NULL)
+ {
+ not_postponed = netbeans_keystring(node->key, node->keystr);
+ vim_free(node->keystr);
+ }
+ else
+ not_postponed = netbeans_keycommand(node->key);
/* Finally, dispose of the node */
vim_free(node);
@@ -2658,7 +2669,7 @@
ex_nbkey(eap)
exarg_T *eap;
{
- netbeans_keystring(0, (char *)eap->arg);
+ netbeans_keystring(0, eap->arg);
}
@@ -3127,23 +3138,26 @@
/*
* Send a keypress event back to netbeans. This usually simulates some
* kind of function key press. This function operates on a key code.
+ * Return FALSE when the command has been postponed.
*/
- void
+ int
netbeans_keycommand(int key)
{
char keyName[60];
netbeans_keyname(key, keyName);
- netbeans_keystring(key, keyName);
+ return netbeans_keystring(key, (char_u *)keyName);
}
/*
* Send a keypress event back to netbeans. This usually simulates some
* kind of function key press. This function operates on a key string.
+ * Return FALSE when the command has been postponed.
*/
- static void
-netbeans_keystring(int key, char *keyName)
+
+ static int
+netbeans_keystring(int key, char_u *keyName)
{
char buf[2*MAXPATHL];
int bufno = nb_getbufno(curbuf);
@@ -3151,7 +3165,7 @@
char_u *q;
if (!haveConnection)
- return;
+ return TRUE;
if (bufno == -1)
@@ -3160,7 +3174,7 @@
q = curbuf->b_ffname == NULL ? (char_u *)""
: nb_quote(curbuf->b_ffname);
if (q == NULL)
- return;
+ return TRUE;
vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0,
q,
"T", /* open in NetBeans */
@@ -3170,9 +3184,8 @@
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
- if (key > 0)
- postpone_keycommand(key);
- return;
+ postpone_keycommand(key, keyName);
+ return FALSE;
}
/* sync the cursor position */
@@ -3198,6 +3211,7 @@
off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
+ return TRUE;
}
diff --git a/src/proto/netbeans.pro b/src/proto/netbeans.pro
--- a/src/proto/netbeans.pro
+++ b/src/proto/netbeans.pro
@@ -16,7 +16,7 @@
void netbeans_removed __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, long len));
void netbeans_unmodified __ARGS((buf_T *bufp));
void netbeans_button_release __ARGS((int button));
-void netbeans_keycommand __ARGS((int key));
+int netbeans_keycommand __ARGS((int key));
void netbeans_save_buffer __ARGS((buf_T *bufp));
void netbeans_deleted_all_lines __ARGS((buf_T *bufp));
int netbeans_is_guarded __ARGS((linenr_T top, linenr_T bot));