static int symtab_get_matches(jl_sym_t *tree, const char *str, char **answer) { int x, plen, count=0; ios_t ans; plen = strlen(str); while (tree != NULL) { x = common_prefix(str, tree->name); if (x == plen) { ios_mem(&ans, 0); symtab_search(tree, &count, &ans, str, plen); size_t nb; *answer = ios_takebuf(&ans, &nb); return count; } else { x = strcmp(str, tree->name); if (x < 0) tree = tree->left; else tree = tree->right; } } return 0; }
static int symtab_get_matches(jl_sym_t *tree, const char *str, char **answer) { int x, plen, count=0; ios_t ans; // given str "X.Y.a", set module := X.Y and name := "a" jl_module_t *module = NULL; char *name = NULL, *strcopy = strdup(str); for (char *s=strcopy, *r=NULL;; s=NULL) { char *t = strtok_r(s, ".", &r); if (!t) { if (str[strlen(str)-1] == '.') { // this case is "Module." if (name) { if (!module) module = jl_current_module; module = find_submodule_named(module, name); if (!module) goto symtab_get_matches_exit; } name = ""; } break; } if (name) { if (!module) module = jl_current_module; module = find_submodule_named(module, name); if (!module) goto symtab_get_matches_exit; } name = t; } if (!name) goto symtab_get_matches_exit; plen = strlen(name); while (tree != NULL) { x = common_prefix(name, tree->name); if (x == plen) { ios_mem(&ans, 0); symtab_search(tree, &count, &ans, module, str, name, plen); size_t nb; *answer = ios_takebuf(&ans, &nb); break; } else { x = strcmp(name, tree->name); if (x < 0) tree = tree->left; else tree = tree->right; } } symtab_get_matches_exit: free(strcopy); return count; }
static void *run_io_thr(void *arg) { sigset_t set; sigemptyset(&set); sigaddset(&set, SIGFPE); sigaddset(&set, SIGINT); sigaddset(&set, SIGSEGV); pthread_sigmask(SIG_BLOCK, &set, NULL); while (1) { while (ioq == NULL) { pthread_mutex_lock(&wake_mut); pthread_cond_wait(&wake_cond, &wake_mut); pthread_mutex_unlock(&wake_mut); } assert(ioq != NULL); pthread_mutex_lock(&q_mut); sendreq_t *r = ioq; ioq = ioq->next; pthread_mutex_unlock(&q_mut); if (!r->now) { int64_t now = (int64_t)(clock_now()*1e6); int64_t waittime = r->buf->userdata+200-now; // microseconds if (waittime > 0) { struct timespec wt; wt.tv_sec = 0; wt.tv_nsec = waittime * 1000; nanosleep(&wt, NULL); } } pthread_mutex_lock(&r->buf->mutex); size_t sz; size_t n = r->buf->size; char *buf = ios_takebuf(r->buf, &sz); pthread_mutex_unlock(&r->buf->mutex); size_t nw; _os_write_all(r->fd, buf, n, &nw); julia_free(buf); pthread_mutex_lock(&q_mut); r->next = ioq_freelist; ioq_freelist = r; pthread_mutex_unlock(&q_mut); } return NULL; }
jl_array_t *jl_takebuf_array(ios_t *s) { size_t n; jl_array_t *a; if (s->buf == &s->local[0]) { // small data case. copies, but this can be avoided using the // technique of jl_readuntil below. a = jl_pchar_to_array(s->buf, s->size); ios_trunc(s, 0); } else { char *b = ios_takebuf(s, &n); a = jl_ptr_to_array_1d(jl_array_uint8_type, b, n-1, 1); } return a; }
// the returned buffer must be manually freed. To determine the size, // call position(s) before using this function. void *jl_takebuf_raw(ios_t *s) { size_t sz; void *buf = ios_takebuf(s, &sz); return buf; }