// get the number of strings stored long string_size(l3obj* obj) { //tmpoff LIVEO(obj); Word_t array_size; JLC(array_size, obj->_judyL, 0, -1); return (long)array_size; }
int dbus_update(struct dbus* dbus) { DBusDispatchStatus status; // handle watches Word_t watch_count = 0; JLC(watch_count, dbus->watches, 0, -1); struct pollfd* pollfds = (struct pollfd*)alloca(sizeof(struct pollfd) * watch_count); int fdcount = get_pollfds(dbus, pollfds); if(poll(pollfds, fdcount, 0) < 0) { return -1; } // process the watches DBusWatch** pwatch; Word_t index = 0; int c = 0; JLF(pwatch, dbus->watches, index); while(pwatch != NULL) { struct pollfd* poll_result = &pollfds[c]; struct DBusWatch* watch = *pwatch; if(dbus_watch_get_enabled(watch)) { assert(poll_result->fd == dbus_watch_get_unix_fd(watch)); int flags = 0; int revents = poll_result->revents; if((revents & POLLIN) != 0) flags |= DBUS_WATCH_READABLE; if((revents & POLLOUT) != 0) flags |= DBUS_WATCH_WRITABLE; if((revents & POLLERR) != 0) flags |= DBUS_WATCH_ERROR; if((revents & POLLHUP) != 0) flags |= DBUS_WATCH_HANGUP; if(flags != 0) dbus_watch_handle(watch, flags); c++; } JLN(pwatch, dbus->watches, index); } // dispatch incoming messages while((status = dbus_connection_get_dispatch_status(dbus->conn)) != DBUS_DISPATCH_COMPLETE) { dbus_connection_dispatch(dbus->conn); } // Send outgoing messages if(dbus_connection_has_messages_to_send(dbus->conn)) { dbus_connection_flush(dbus->conn); } return 0; }
int dogma_remove_charge(dogma_context_t* ctx, dogma_key_t index) { dogma_env_t** module_env; int count; JLG(module_env, ctx->ship->children, index); if(module_env == NULL) return DOGMA_NOT_FOUND; JLC(count, (*module_env)->children, 0, -1); assert(count <= 1); /* If there's more than one charge in this * module, something is wrong */ return dogma_remove_env_generic(ctx, *module_env, 0); }
int pq_overload_number_of_functions(pq_overload *overload) { Word_t num_non_variadic, num_variadic; JLC(num_non_variadic, overload->function_table, 0, -1); JLC(num_variadic, overload->variadic_function_table, 0, -1); return num_non_variadic + num_variadic; }
/* This functions codes all ixeme occurrences in a segment in the correct * order. The catch is that instead of using global ixeme IDs, we use a * minimal local set of IDs, namely integers [1..|S|] for |S| individual * ixemes. Mapping between the IDs is implictely saved in the ascending * order of ixeme IDs, obtainable from the forward index. */ void possect_add(const Pvoid_t tokens) { static uint *offsets; //static uint offsets_len; static char *encode_buf; //static uint buf_len; if (!offsets){ offsets = xmalloc(segment_size * sizeof(uint)); encode_buf = xmalloc(segment_size * 8); memset(encode_buf, 0, segment_size * 8); } memset(offsets, 0, segment_size * sizeof(uint)); //ENSURE_IBLOCK Word_t max = 0; JLC(max, tokens, 0, -1); /* write TOC entry */ toc_e toc; toc.offs = ftello64(data_f); toc.val = max; fwrite(&toc, sizeof(toc_e), 1, toc_f); /* write token list */ uint max_pos = encode_tokens(tokens); /* if (segment_size > offsets_len){ free(offsets); offsets_len = segment_size; offsets = xmalloc(offsets_len * sizeof(uint)); } memset(offsets, 0, offsets_len * sizeof(uint)); */ /* estimate rice_f */ u32 rice_f, offs = 0; if (max) rice_f = estimate_rice_f((u32*)&max, 1); else rice_f = 2; /* allocate bits to positions */ Word_t *ptr; //uint max_pos = 0; int i, j, c = 0; Word_t xid = 0; JLF(ptr, tokens, xid); while (ptr){ offs = 0; rice_write(NULL, &offs, ++c, rice_f); const growing_glist *g = (const growing_glist*)*ptr; for (i = 0; i < g->lst.len; i++){ offsets[g->lst.lst[i] - 1] = offs; if (g->lst.lst[i] > max_pos) max_pos = g->lst.lst[i]; } JLN(ptr, tokens, xid); } /* compute bit offset for each position */ offs = 0; elias_gamma_write(NULL, &offs, max_pos + 1); rice_write(NULL, &offs, rice_f, 2); for (i = 0; i < max_pos; i++){ uint tmp = offsets[i]; if (!tmp) dub_die("A hole in poslist at %u / %u!", i, max_pos); offsets[i] = offs; offs += tmp; } u32 endpos = offs; //u32 total_bits = offs; //elias_gamma_write(NULL, &offs, total_bits); //rice_write(NULL, &offs, 0, rice_f); u32 total_bytes = BITS_TO_BYTES(offs); if (total_bytes > segment_size * 8) dub_die("Pos buffer too small! %u > %u.", total_bytes, segment_size * 8); /* if (total_bytes > buf_len){ free(encode_buf); buf_len = total_bytes; encode_buf = xmalloc(buf_len + 4); memset(encode_buf, 0, buf_len + 4); } */ /* write codes */ offs = 0; elias_gamma_write(encode_buf, &offs, max_pos + 1); rice_write(encode_buf, &offs, rice_f, 2); //elias_gamma_write(encode_buf, &offs, total_bits); xid = c = j = 0; JLF(ptr, tokens, xid); while (ptr){ ++c; growing_glist *g = (growing_glist*)*ptr; for (i = 0; i < g->lst.len; i++){ //u32 d = offsets[g->lst.lst[i] - 1]; //dub_msg("OFFS %u VAL %u", d, c); rice_write(encode_buf, &offsets[g->lst.lst[i] - 1], c, rice_f); //u32 dd = rice_read(encode_buf, &d, rice_f); //if (c != dd) // dub_die("POKS! %u, %u != %u", key, dd, c); ++j; } free(g); JLN(ptr, tokens, xid); } //rice_write(encode_buf, &endpos, 0, rice_f); fwrite(encode_buf, total_bytes, 1, data_f); memset(encode_buf, 0, total_bytes); }
int dogma_free_env(dogma_context_t* ctx, dogma_env_t* env) { int ret; dogma_key_t index = -1, index2, index3; dogma_env_t** child; dogma_array_t* modifiers; dogma_array_t* modifiers2; dogma_modifier_t** modifier; /* Clear our own target */ if(env->target.context != NULL) { assert(dogma_set_target(ctx, env, NULL, NULL) == DOGMA_OK); } /* Clear any targets of things that have what we're about do * delete as a target */ if(env->targeted_by != NULL) { dogma_key_t index = 0; dogma_context_t** targeter; dogma_env_t* source; JLF(targeter, env->targeted_by, index); while(targeter != NULL) { source = (dogma_env_t*)index; assert(dogma_set_target(*targeter, source, NULL, NULL) == DOGMA_OK); JLN(targeter, env->targeted_by, index); } JLC(ret, env->targeted_by, 0, -1); assert(ret == 0); JLFA(ret, env->targeted_by); assert(ret == 0); } /* Clear any chance-based effects */ if(env->chance_effects != NULL) { dogma_key_t effectid = 0; bool* val; JLF(val, env->chance_effects, effectid); while(val != NULL) { DOGMA_ASSUME_OK(dogma_toggle_chance_based_effect_env(ctx, env, effectid, false)); JLN(val, env->chance_effects, effectid); } JLFA(ret, env->chance_effects); } JLL(child, env->children, index); while(child != NULL) { dogma_free_env(ctx, *child); JLP(child, env->children, index); } JLFA(ret, env->children); index = 0; JLF(modifiers, env->modifiers, index); while(modifiers != NULL) { index2 = 0; JLF(modifiers2, *modifiers, index2); while(modifiers2 != NULL) { index3 = 0; JLF(modifier, *modifiers2, index3); while(modifier != NULL) { free(*modifier); JLN(modifier, *modifiers2, index3); } JLFA(ret, *modifiers2); JLN(modifiers2, *modifiers, index2); } JLFA(ret, *modifiers); JLN(modifiers, env->modifiers, index); } JLFA(ret, env->modifiers); free(env); return DOGMA_OK; }