[INTERPRETER]
* BUG: ARRAY_add_void() function now correctly adds a void element in the array after an element has been previously removed. That bug made the event loop mad in some cases! git-svn-id: svn://localhost/gambas/trunk@3131 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
9307500dcb
commit
85b08d28ba
3 changed files with 56 additions and 18 deletions
|
@ -36,9 +36,8 @@
|
||||||
#include "gbx_c_timer.h"
|
#include "gbx_c_timer.h"
|
||||||
#include "gbx_watch.h"
|
#include "gbx_watch.h"
|
||||||
|
|
||||||
|
//#define DEBUG_TIMER 1
|
||||||
//#define DEBUG_TIMER
|
//#define DEBUG_WATCH 1
|
||||||
//#define DEBUG_WATCH
|
|
||||||
|
|
||||||
static fd_set read_fd;
|
static fd_set read_fd;
|
||||||
static fd_set write_fd;
|
static fd_set write_fd;
|
||||||
|
@ -208,6 +207,9 @@ static bool get_timeout(const struct timeval *wait, struct timeval *tv)
|
||||||
|
|
||||||
if (timeout.tv_sec == 0 && timeout.tv_usec < (1000000 / 100))
|
if (timeout.tv_sec == 0 && timeout.tv_usec < (1000000 / 100))
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_TIMER
|
||||||
|
fprintf(stderr, "busy loop\n");
|
||||||
|
#endif
|
||||||
// busy loop!
|
// busy loop!
|
||||||
time_add(&timeout, now);
|
time_add(&timeout, now);
|
||||||
for(;;)
|
for(;;)
|
||||||
|
@ -261,7 +263,7 @@ void WATCH_exit(void)
|
||||||
static void watch_fd(int fd, int flag, bool watch)
|
static void watch_fd(int fd, int flag, bool watch)
|
||||||
{
|
{
|
||||||
#if DEBUG_WATCH
|
#if DEBUG_WATCH
|
||||||
fprintf(stderr, "watch_fd: %d / %d: %d\n", fd, flag, watch);
|
fprintf(stderr, "watch_fd: %d for %s: %s\n", fd, flag == WATCH_READ ? "read" : "write", watch ? "set" : "clear");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (flag == WATCH_READ)
|
if (flag == WATCH_READ)
|
||||||
|
@ -331,19 +333,29 @@ static WATCH_CALLBACK *watch_create_callback(int fd)
|
||||||
if (fd > max_fd)
|
if (fd > max_fd)
|
||||||
max_fd = fd;
|
max_fd = fd;
|
||||||
|
|
||||||
|
#if DEBUG_WATCH
|
||||||
|
fprintf(stderr, "watch_create_callback: %d -> %d read = %p (%p) write = %p (%p)\n", fd, pos, wcb->callback_read, (void *)wcb->param_read, wcb->callback_write, (void *)wcb->param_write);
|
||||||
|
#endif
|
||||||
|
|
||||||
return wcb;
|
return wcb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void watch_delete_callback(int fd)
|
static void watch_delete_callback(int fd)
|
||||||
{
|
{
|
||||||
|
WATCH_CALLBACK *wcb;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
|
#if DEBUG_WATCH
|
||||||
|
fprintf(stderr, "watch_delete_callback: %d (%d)\n", fd, _do_not_really_delete_callback);
|
||||||
|
#endif
|
||||||
|
|
||||||
pos = watch_find_callback(fd);
|
pos = watch_find_callback(fd);
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
watch_callback[pos].fd = -1;
|
wcb = &watch_callback[pos];
|
||||||
|
wcb->fd = -1;
|
||||||
watch_fd(fd, WATCH_READ, FALSE);
|
watch_fd(fd, WATCH_READ, FALSE);
|
||||||
watch_fd(fd, WATCH_WRITE, FALSE);
|
watch_fd(fd, WATCH_WRITE, FALSE);
|
||||||
max_fd = find_max_fd();
|
max_fd = find_max_fd();
|
||||||
|
@ -383,6 +395,11 @@ void WATCH_watch(int fd, int type, void *callback, intptr_t param)
|
||||||
wcb->callback_write = callback;
|
wcb->callback_write = callback;
|
||||||
wcb->param_write = param;
|
wcb->param_write = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG_WATCH
|
||||||
|
fprintf(stderr, "add watch: %d -> %d read = %p (%p) write = %p (%p)\n", fd, watch_find_callback(fd), wcb->callback_read, (void *)wcb->param_read, wcb->callback_write, (void *)wcb->param_write);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!wcb->callback_read && !wcb->callback_write)
|
if (!wcb->callback_read && !wcb->callback_write)
|
||||||
watch_delete_callback(fd);
|
watch_delete_callback(fd);
|
||||||
else
|
else
|
||||||
|
@ -390,10 +407,6 @@ void WATCH_watch(int fd, int type, void *callback, intptr_t param)
|
||||||
watch_fd(fd, WATCH_READ, wcb->callback_read != NULL);
|
watch_fd(fd, WATCH_READ, wcb->callback_read != NULL);
|
||||||
watch_fd(fd, WATCH_WRITE, wcb->callback_write != NULL);
|
watch_fd(fd, WATCH_WRITE, wcb->callback_write != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_WATCH
|
|
||||||
fprintf(stderr, "add watch: %d\n", watch_find_callback(fd));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +419,7 @@ static void raise_callback(fd_set *rfd, fd_set *wfd)
|
||||||
_do_not_really_delete_callback++;
|
_do_not_really_delete_callback++;
|
||||||
|
|
||||||
#if DEBUG_WATCH
|
#if DEBUG_WATCH
|
||||||
fprintf(stderr, "\nmax_fd = %d\n", max_fd);
|
fprintf(stderr, "raise_callback: max_fd = %d\n", max_fd);
|
||||||
#endif
|
#endif
|
||||||
for (i = 0; i < ARRAY_count(watch_callback); i++)
|
for (i = 0; i < ARRAY_count(watch_callback); i++)
|
||||||
{
|
{
|
||||||
|
@ -414,19 +427,34 @@ static void raise_callback(fd_set *rfd, fd_set *wfd)
|
||||||
// execution of the callbacks.
|
// execution of the callbacks.
|
||||||
|
|
||||||
wcb = watch_callback[i];
|
wcb = watch_callback[i];
|
||||||
|
|
||||||
|
#if DEBUG_WATCH
|
||||||
|
fprintf(stderr, "raise_callback: [%d] fd = %d read = %p (%p) write = %p (%p)\n", i, wcb.fd, wcb.callback_read, (void *)wcb.param_read, wcb.callback_write, (void *)wcb.param_write);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (wcb.fd < 0)
|
if (wcb.fd < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (FD_ISSET(wcb.fd, rfd))
|
if (FD_ISSET(wcb.fd, rfd))
|
||||||
{
|
{
|
||||||
if (wcb.callback_read)
|
if (wcb.callback_read)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_WATCH
|
||||||
|
fprintf(stderr, "call read callback on fd %d\n", wcb.fd);
|
||||||
|
#endif
|
||||||
(*(wcb.callback_read))(wcb.fd, WATCH_READ, wcb.param_read);
|
(*(wcb.callback_read))(wcb.fd, WATCH_READ, wcb.param_read);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(wcb.fd, wfd))
|
if (FD_ISSET(wcb.fd, wfd))
|
||||||
{
|
{
|
||||||
if (wcb.callback_write)
|
if (wcb.callback_write)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_WATCH
|
||||||
|
fprintf(stderr, "call write callback on fd %d\n", wcb.fd);
|
||||||
|
#endif
|
||||||
(*(wcb.callback_write))(wcb.fd, WATCH_WRITE, wcb.param_write);
|
(*(wcb.callback_write))(wcb.fd, WATCH_WRITE, wcb.param_write);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,6 +508,10 @@ static bool do_loop(struct timeval *wait)
|
||||||
if (EVENT_check_post())
|
if (EVENT_check_post())
|
||||||
something_done = TRUE;
|
something_done = TRUE;
|
||||||
|
|
||||||
|
#ifdef DEBUG_TIMER
|
||||||
|
fprintf(stderr, "\ndo_loop: now = %.7g: select (%d)\n", time_to_double(time_now()), something_done);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (get_timeout(wait, &tv))
|
if (get_timeout(wait, &tv))
|
||||||
ret = do_select(&rfd, &wfd, NULL);
|
ret = do_select(&rfd, &wfd, NULL);
|
||||||
else
|
else
|
||||||
|
@ -489,11 +521,15 @@ static bool do_loop(struct timeval *wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_TIMER
|
#ifdef DEBUG_TIMER
|
||||||
fprintf(stderr, "do_loop: now = %.7g\n", time_to_double(time_now()));
|
fprintf(stderr, "do_loop: now = %.7g: timers (%d)\n", time_to_double(time_now()), something_done);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
raise_timers();
|
raise_timers();
|
||||||
|
|
||||||
|
#ifdef DEBUG_TIMER
|
||||||
|
fprintf(stderr, "do_loop: now = %.7g: callbacks\n", time_to_double(time_now()));
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
raise_callback(&rfd, &wfd);
|
raise_callback(&rfd, &wfd);
|
||||||
|
@ -608,3 +644,4 @@ void WATCH_timer(void *t, int on)
|
||||||
timer->id = 0;
|
timer->id = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ void ARRAY_delete(void *p_data);
|
||||||
#define ARRAY_size(_data) (DATA_TO_ARRAY(_data)->size)
|
#define ARRAY_size(_data) (DATA_TO_ARRAY(_data)->size)
|
||||||
#define ARRAY_count(_data) ((_data) ? DATA_TO_ARRAY(_data)->count : 0)
|
#define ARRAY_count(_data) ((_data) ? DATA_TO_ARRAY(_data)->count : 0)
|
||||||
|
|
||||||
void ARRAY_realloc(void *p_data, bool zero);
|
void ARRAY_realloc(void *p_data);
|
||||||
|
|
||||||
void *ARRAY_add_data(void *p_data, int num, bool zero);
|
void *ARRAY_add_data(void *p_data, int num, bool zero);
|
||||||
void *ARRAY_add_data_one(void *p_data, bool zero);
|
void *ARRAY_add_data_one(void *p_data, bool zero);
|
||||||
|
@ -66,9 +66,10 @@ void *ARRAY_add_data_one(void *p_data, bool zero);
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
ARRAY_realloc(_pdata, (_zero)); \
|
ARRAY_realloc(_pdata); \
|
||||||
ptr = *(_pdata) + old_count; \
|
ptr = *(_pdata) + old_count; \
|
||||||
} \
|
} \
|
||||||
|
if (_zero) memset(ptr, 0, sizeof(*ptr)); \
|
||||||
ptr; \
|
ptr; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -82,12 +82,12 @@ void *ARRAY_add_data(void *p_data, int num, bool zero)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARRAY_realloc(void *p_data, bool zero)
|
void ARRAY_realloc(void *p_data) //, bool zero)
|
||||||
{
|
{
|
||||||
void **data = (void **)p_data;
|
void **data = (void **)p_data;
|
||||||
ARRAY *array = DATA_TO_ARRAY(*data);
|
ARRAY *array = DATA_TO_ARRAY(*data);
|
||||||
ARRAY *new_array;
|
ARRAY *new_array;
|
||||||
int old_max = array->max;
|
//int old_max = array->max;
|
||||||
int size = array->size;
|
int size = array->size;
|
||||||
|
|
||||||
array->max = array->inc + ((array->count + array->inc) / array->inc) * array->inc;
|
array->max = array->inc + ((array->count + array->inc) / array->inc) * array->inc;
|
||||||
|
@ -95,11 +95,11 @@ void ARRAY_realloc(void *p_data, bool zero)
|
||||||
REALLOC(&new_array, sizeof(ARRAY) + array->max * size, "ARRAY_realloc");
|
REALLOC(&new_array, sizeof(ARRAY) + array->max * size, "ARRAY_realloc");
|
||||||
*data = ARRAY_TO_DATA(new_array);
|
*data = ARRAY_TO_DATA(new_array);
|
||||||
//fprintf(stderr, "ARRAY_realloc: %p (%d) -> %p (%d) [%d]\n", array, old_max, new_array, new_array->max, size);
|
//fprintf(stderr, "ARRAY_realloc: %p (%d) -> %p (%d) [%d]\n", array, old_max, new_array, new_array->max, size);
|
||||||
if (zero)
|
/*if (zero)
|
||||||
{
|
{
|
||||||
//fprintf(stderr, "ARRAY_realloc: memset(%p, 0, %d)\n", ARRAY_TO_DATA(new_array) + old_max * size, (new_array->max - old_max) * size);
|
//fprintf(stderr, "ARRAY_realloc: memset(%p, 0, %d)\n", ARRAY_TO_DATA(new_array) + old_max * size, (new_array->max - old_max) * size);
|
||||||
memset(ARRAY_TO_DATA(new_array) + old_max * size, 0, (new_array->max - old_max) * size);
|
memset(ARRAY_TO_DATA(new_array) + old_max * size, 0, (new_array->max - old_max) * size);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue