Fix issue with some variables named 'this' which conflicts with the Intel C compiler.

pull/15/merge
Robert G. Jakabosky 15 years ago
parent 1bd721fb02
commit ba5f08b586

@ -40,32 +40,32 @@ typedef struct ZMQ_Poller ZMQ_Poller;
#define ITEM_TO_INDEX(items, item) (item - (items)) #define ITEM_TO_INDEX(items, item) (item - (items))
static int poller_resize_items(ZMQ_Poller *this, int len) { static int poller_resize_items(ZMQ_Poller *poller, int len) {
int old_len = this->len; int old_len = poller->len;
/* make sure new length is atleast as large as items count. */ /* make sure new length is atleast as large as items count. */
len = (this->count <= len) ? len : this->count; len = (poller->count <= len) ? len : poller->count;
/* if the new length is the same as the old length, then don't try to resize. */ /* if the new length is the same as the old length, then don't try to resize. */
if(old_len == len) return len; if(old_len == len) return len;
this->items = (zmq_pollitem_t *)realloc(this->items, len * sizeof(zmq_pollitem_t)); poller->items = (zmq_pollitem_t *)realloc(poller->items, len * sizeof(zmq_pollitem_t));
this->len = len; poller->len = len;
if(len > old_len) { if(len > old_len) {
/* clear new space. */ /* clear new space. */
memset(&(this->items[old_len]), 0, (len - old_len) * sizeof(zmq_pollitem_t)); memset(&(poller->items[old_len]), 0, (len - old_len) * sizeof(zmq_pollitem_t));
} }
return len; return len;
} }
static int poller_find_sock_item(ZMQ_Poller *this, ZMQ_Socket *sock) { static int poller_find_sock_item(ZMQ_Poller *poller, ZMQ_Socket *sock) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int count; int count;
int n; int n;
/* find ZMQ_Socket */ /* find ZMQ_Socket */
items = this->items; items = poller->items;
count = this->count; count = poller->count;
for(n=0; n < count; n++) { for(n=0; n < count; n++) {
if(items[n].socket == sock) return n; if(items[n].socket == sock) return n;
} }
@ -73,14 +73,14 @@ static int poller_find_sock_item(ZMQ_Poller *this, ZMQ_Socket *sock) {
return -1; return -1;
} }
static int poller_find_fd_item(ZMQ_Poller *this, socket_t fd) { static int poller_find_fd_item(ZMQ_Poller *poller, socket_t fd) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int count; int count;
int n; int n;
/* find fd */ /* find fd */
items = this->items; items = poller->items;
count = this->count; count = poller->count;
for(n=0; n < count; n++) { for(n=0; n < count; n++) {
if(items[n].fd == fd) return n; if(items[n].fd == fd) return n;
} }
@ -88,55 +88,55 @@ static int poller_find_fd_item(ZMQ_Poller *this, socket_t fd) {
return -1; return -1;
} }
static void poller_remove_item(ZMQ_Poller *this, int idx) { static void poller_remove_item(ZMQ_Poller *poller, int idx) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int free_list; int free_list;
int count; int count;
count = this->count; count = poller->count;
/* no item to remove. */ /* no item to remove. */
if(idx >= count || count == 0) return; if(idx >= count || count == 0) return;
items = this->items; items = poller->items;
free_list = this->free_list; free_list = poller->free_list;
/* link new free slot to head of free list. */ /* link new free slot to head of free list. */
if(free_list >= 0 && free_list < count) { if(free_list >= 0 && free_list < count) {
/* use socket pointer for free list's 'next' field. */ /* use socket pointer for free list's 'next' field. */
items[idx].socket = &(items[free_list]); items[idx].socket = &(items[free_list]);
} else { } else {
/* free list is empty mark this slot as the end. */ /* free list is empty mark poller slot as the end. */
items[idx].socket = NULL; items[idx].socket = NULL;
} }
this->free_list = idx; poller->free_list = idx;
/* mark this slot as a free slot. */ /* mark poller slot as a free slot. */
items[idx].events = FREE_ITEM_EVENTS_TAG; items[idx].events = FREE_ITEM_EVENTS_TAG;
/* clear old revents. */ /* clear old revents. */
items[idx].revents = 0; items[idx].revents = 0;
} }
static int poller_get_free_item(ZMQ_Poller *this) { static int poller_get_free_item(ZMQ_Poller *poller) {
zmq_pollitem_t *curr; zmq_pollitem_t *curr;
zmq_pollitem_t *next; zmq_pollitem_t *next;
int count; int count;
int idx; int idx;
count = this->count; count = poller->count;
idx = this->free_list; idx = poller->free_list;
/* check for a free slot in the free list. */ /* check for a free slot in the free list. */
if(idx >= 0 && idx < count) { if(idx >= 0 && idx < count) {
/* remove free slot from free list. */ /* remove free slot from free list. */
curr = &(this->items[idx]); curr = &(poller->items[idx]);
/* valid free slot. */ /* valid free slot. */
assert(curr->events == FREE_ITEM_EVENTS_TAG); assert(curr->events == FREE_ITEM_EVENTS_TAG);
/* is this the last free slot? */ /* is poller the last free slot? */
next = ((zmq_pollitem_t *)curr->socket); next = ((zmq_pollitem_t *)curr->socket);
if(next != NULL) { if(next != NULL) {
/* set next free slot as head of free list. */ /* set next free slot as head of free list. */
this->free_list = ITEM_TO_INDEX(this->items, next); poller->free_list = ITEM_TO_INDEX(poller->items, next);
} else { } else {
/* free list is empty now. */ /* free list is empty now. */
this->free_list = -1; poller->free_list = -1;
} }
/* clear slot */ /* clear slot */
memset(curr, 0, sizeof(zmq_pollitem_t)); memset(curr, 0, sizeof(zmq_pollitem_t));
@ -144,26 +144,26 @@ static int poller_get_free_item(ZMQ_Poller *this) {
} }
idx = count; idx = count;
this->count = ++count; poller->count = ++count;
/* make room for new item. */ /* make room for new item. */
if(count >= this->len) { if(count >= poller->len) {
poller_resize_items(this, this->len + 10); poller_resize_items(poller, poller->len + 10);
} }
return idx; return idx;
} }
static int poller_compact_items(ZMQ_Poller *this) { static int poller_compact_items(ZMQ_Poller *poller) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int count; int count;
int old_count; int old_count;
int next; int next;
count = this->count; count = poller->count;
/* if no free slot, then return. */ /* if no free slot, then return. */
if(this->free_list < 0) return count; if(poller->free_list < 0) return count;
old_count = count; old_count = count;
items = this->items; items = poller->items;
next = 0; next = 0;
/* find first free slot. */ /* find first free slot. */
while(next < count && items[next].events != FREE_ITEM_EVENTS_TAG) { while(next < count && items[next].events != FREE_ITEM_EVENTS_TAG) {
@ -184,19 +184,19 @@ static int poller_compact_items(ZMQ_Poller *this) {
/* clear old used-space */ /* clear old used-space */
memset(&(items[count]), 0, ((old_count - count) * sizeof(zmq_pollitem_t))); memset(&(items[count]), 0, ((old_count - count) * sizeof(zmq_pollitem_t)));
this->count = count; poller->count = count;
this->free_list = -1; /* free list is now empty. */ poller->free_list = -1; /* free list is now empty. */
assert(count <= this->len); assert(count <= poller->len);
return count; return count;
} }
static int poller_poll(ZMQ_Poller *this, long timeout) { static int poller_poll(ZMQ_Poller *poller, long timeout) {
int count; int count;
/* remove free slots from items list. */ /* remove free slots from items list. */
count = poller_compact_items(this); count = poller_compact_items(poller);
/* poll for events. */ /* poll for events. */
return zmq_poll(this->items, count, timeout); return zmq_poll(poller->items, count, timeout);
} }
]], ]],
@ -215,11 +215,11 @@ typedef struct zmq_pollitem_t {
int zmq_poll(zmq_pollitem_t *items, int nitems, long timeout); int zmq_poll(zmq_pollitem_t *items, int nitems, long timeout);
]], ]],
ffi_cdef(ZMQ_Poller_type), ffi_cdef(ZMQ_Poller_type),
ffi_export_function "int" "poller_find_sock_item" "(ZMQ_Poller *this, ZMQ_Socket *sock)", ffi_export_function "int" "poller_find_sock_item" "(ZMQ_Poller *poller, ZMQ_Socket *sock)",
ffi_export_function "int" "poller_find_fd_item" "(ZMQ_Poller *this, socket_t fd)", ffi_export_function "int" "poller_find_fd_item" "(ZMQ_Poller *poller, socket_t fd)",
ffi_export_function "int" "poller_get_free_item" "(ZMQ_Poller *this)", ffi_export_function "int" "poller_get_free_item" "(ZMQ_Poller *poller)",
ffi_export_function "int" "poller_poll" "(ZMQ_Poller *this, long timeout)", ffi_export_function "int" "poller_poll" "(ZMQ_Poller *poller, long timeout)",
ffi_export_function "void" "poller_remove_item" "(ZMQ_Poller *this, int idx)", ffi_export_function "void" "poller_remove_item" "(ZMQ_Poller *poller, int idx)",
constructor "new" { constructor "new" {
var_in{ "unsigned int", "length", is_optional = true, default = 10 }, var_in{ "unsigned int", "length", is_optional = true, default = 10 },

File diff suppressed because it is too large Load Diff

@ -19,7 +19,7 @@
-- THE SOFTWARE. -- THE SOFTWARE.
-- make generated variable nicer. -- make generated variable nicer.
set_variable_format "%s" set_variable_format "%s%d"
c_module "zmq" { c_module "zmq" {
-- module settings. -- module settings.

Loading…
Cancel
Save