void save_font_list(void) { char *file_name = obs_module_config_path("font_data.bin"); uint32_t font_checksum = get_font_checksum(); int font_count = (int)font_list.num; struct serializer s; bool success = false; if (font_checksum) success = file_output_serializer_init_safe(&s, file_name, "tmp"); bfree(file_name); if (!success) return; success = write_var(&s, font_cache_ver); if (!success) return; success = write_var(&s, font_checksum); if (!success) return; success = write_var(&s, font_count); if (!success) return; #define do_write(var) \ success = write_var(&s, var); \ if (!success) break for (size_t i = 0; i < font_list.num; i++) { struct font_path_info *info = &font_list.array[i]; success = write_str(&s, info->face_and_style); if (!success) break; do_write(info->full_len); do_write(info->face_len); do_write(info->is_bitmap); do_write(info->num_sizes); success = write_data(&s, info->sizes, sizeof(int) * info->num_sizes); if (!success) break; do_write(info->bold); success = write_str(&s, info->path); if (!success) break; do_write(info->italic); do_write(info->index); } #undef do_write file_output_serializer_free(&s); }
static void trigger_tests(void) { int len, local, global, i; char val; int ret; ret = ptrace(PTRACE_TRACEME, 0, NULL, 0); if (ret) { perror("Can't be traced?\n"); return; } kill(getpid(), SIGUSR1); for (local = 0; local < 2; local++) { for (global = 0; global < 2; global++) { if (!local && !global) continue; for (i = 0; i < 4; i++) { dummy_funcs[i](); check_trapped(); } } } for (len = 1; len <= sizeof(long); len <<= 1) { for (local = 0; local < 2; local++) { for (global = 0; global < 2; global++) { if (!local && !global) continue; write_var(len); } } } for (len = 1; len <= sizeof(long); len <<= 1) { for (local = 0; local < 2; local++) { for (global = 0; global < 2; global++) { if (!local && !global) continue; read_var(len); } } } asm(".byte 0xf1\n"); check_trapped(); asm("int $3\n"); check_trapped(); kill(getpid(), SIGUSR1); }
void do_write_tree(FILE *out, struct lacy_env *env, struct tree_node *top) { struct tree_node *t = top; while (t != NULL) { switch (t->token) { case BLOCK: fputs(t->buffer.s, out); break; case INCLUDE: t = write_include(out, t, env); break; case IDENT: t = write_var(out, t, env); break; case FOR: t = write_for(out, t, env); break; case DONE: return; case SH_BLOCK: write_sh_block(out, t, env); break; default: break; } t = t->next; } }
static void write_action(Context* ctx, const WasmAction* action) { write_key(ctx, "action"); wasm_writef(&ctx->json_stream, "{"); write_key(ctx, "type"); if (action->type == WASM_ACTION_TYPE_INVOKE) { write_string(ctx, "invoke"); } else { assert(action->type == WASM_ACTION_TYPE_GET); write_string(ctx, "get"); } write_separator(ctx); if (action->module_var.type != WASM_VAR_TYPE_INDEX) { write_key(ctx, "module"); write_var(ctx, &action->module_var); write_separator(ctx); } if (action->type == WASM_ACTION_TYPE_INVOKE) { write_key(ctx, "field"); write_escaped_string_slice(ctx, action->invoke.name); write_separator(ctx); write_key(ctx, "args"); write_const_vector(ctx, &action->invoke.args); } else { write_key(ctx, "field"); write_escaped_string_slice(ctx, action->get.name); } wasm_writef(&ctx->json_stream, "}"); }
static void makeh(void) {int i, j, l, sz, change, N_var; double t1, t2, *tt, **td, *pd, *time, **ldata; haelem **tab, *hp; source_record *sp; time_list *tp; pcons *pp, *pn; /* order the times for each variable in srctab */ sz = srctab->size; tab = srctab->table; N_var = 0; for (i = 0; i < sz; i++) for (hp = tab[i]; hp != NULL; hp = hp->next) {tp = (time_list *) (hp->def); l = tp->length; /* copy the list into arrays */ tt = time = CMAKE_N(double, l); td = ldata = CMAKE_N(double *, l); for (pp = tp->list; pp != NULL; pp = pn) {sp = (source_record *) pp->car; *(tt++) = sp->time; *(td++) = sp->data; pn = (pcons *) pp->cdr; CFREE(sp); CFREE(pp);}; /* sort the arrays according to the times */ change = TRUE; while (change) {change = FALSE; for (j = 1; j < l; j++) {t1 = time[j-1]; t2 = time[j]; if (t2 < t1) {pd = ldata[j-1]; ldata[j-1] = ldata[j]; ldata[j] = pd; time[j] = t1; time[j-1] = t2; change = TRUE;};};}; /* write the variable and source_record array out */ write_var(pdsf, hp->name, time, ldata, l); N_var++; /* release the temporary storage for this variable */ CFREE(time); CFREE(ldata);}; /* finish up */ PD_write(pdsf, "n_variables", "integer", &N_var); PD_close(pdsf); pdsf = NULL; return;}
//base function void start(){ current_line = 1; var_count = 0; pro_count = 0; advance(); prog(); write_var(); write_pro(); }
static bool write_str(struct serializer *s, const char *str) { uint32_t size = (uint32_t)(str ? strlen(str) : 0); if (!write_var(s, size)) return false; if (size && !write_data(s, str, size)) return false; return true; }
void zero_init() { lcd_clear(); lcd_puts("Memory init"); write_var(0, 0, 0x19); write_var(0, 1, 0x08); write_var(0, 2, 0x1E); //30 block = 0; addr = 3; for(i = 0; i < MAX_PATTERNS; i++) { write_var(block, addr, v1.length); addr++; check_ab(); for(j = 0; j < MAX_ITEMS; j++) { lcd_gotoxy(0, 1); lcd_puts(t_preset); lcd_putchar(' '); LCDWriteInt(i, 0); lcd_putchar(' '); lcd_puts(t_item); lcd_putchar(' '); LCDWriteInt(j, 0); lcd_putchar(' '); write_var(block, addr, v1.out[j]); addr++; check_ab(); } } }
void write_pattern(t_pattern patt, unsigned char num) { #asm("cli") lcd_clear(); lcd_puts("Memory write"); addr = 3 + num * (MAX_ITEMS + 1); block = addr / 256; addr = addr % 256; write_var(block, addr, patt.length); addr++; check_ab(); lcd_gotoxy(0, 1); lcd_puts(t_preset); lcd_putchar(' '); LCDWriteInt(num, 0); lcd_putchar(' '); lcd_puts(t_item); lcd_putchar(' '); for(j = 0; j < MAX_ITEMS; j++) { lcd_gotoxy(14, 1); LCDWriteInt(j, 0); lcd_putchar(' '); write_var(block, addr, patt.out[j]); addr++; check_ab(); } #asm("sei") }
int state2() /* Do what needs to be done in state 2. pre: The global variable 'mu' contains the number of indiviuals you need to read using 'read_sel()'. The global variable 'lambda' contains the number of individuals you need to create by variation of the individuals specified the 'sel' file. post: Optionally call read_arc() in order to delete old uncessary individuals from the global population. read_sel() called 'lambda' children generated from the 'mu' parents Children added to the global population using add_individual(). Information about children written to the 'var' file using write_var(). Return value == 0 if successful, == 1 if unspecified errors happened, == 2 if file reading failed. */ { int *parent_identities, *offspring_identities; /* array of identities */ int result; /* stores return values of called functions */ parent_identities = (int *) malloc(mu * sizeof(int)); if (parent_identities == NULL) { log_to_file(log_file, __FILE__, __LINE__, "variator out of memory"); return (1); } offspring_identities = (int *) malloc(lambda * sizeof(int)); if (offspring_identities == NULL) { log_to_file(log_file, __FILE__, __LINE__, "variator out of memory"); return (1); } result = read_sel(parent_identities); if (result != 0) /* if some file reading error occurs, return 2 */ return (2); result = read_arc(); if (result != 0) /* if some file reading error occurs, return 2 */ return (2); /**********| added for DTLZ |**************/ result = variate(parent_identities, offspring_identities); if (result != 0) return (1); gen++; /**********| addition for DTLZ end |*******/ result = write_var(offspring_identities); if (result != 0) { log_to_file(log_file, __FILE__, __LINE__, "couldn't write var"); free(offspring_identities); free(parent_identities); return (1); } free(offspring_identities); free(parent_identities); return (0); }
void Var::write_to_stream( Stream &os ) const { write_var( os, type_expr(), expr() ); }
// MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vector<ALLOC_INFO*>& dependencies) { ALLOC_INFO_MAP::iterator pos; ALLOC_INFO* alloc_info; char name[256]; int local_anon_var_number; int extern_anon_var_number; // 1) Generate declaration statements for each the allocations that we are managing. out_s << "// Variable Declarations." << std::endl; out_s.flush(); local_anon_var_number = 0; extern_anon_var_number = 0; int n_depends = dependencies.size(); for (int ii = 0 ; ii < n_depends ; ii ++) { alloc_info = dependencies[ii]; /** Generate temporary names for anonymous variables. */ if (alloc_info->name == NULL) { if ( alloc_info->stcl == TRICK_LOCAL) { sprintf( name, "%s%d", local_anon_var_prefix, local_anon_var_number++); alloc_info->name = strdup( name); currentCheckPointAgent->write_decl( out_s, alloc_info); } else if (alloc_info->stcl == TRICK_EXTERN) { sprintf( name, "%s%d", extern_anon_var_prefix, extern_anon_var_number++); alloc_info->name = strdup( name); /** @b NOTE: We should not write declarations for external anonymous variables, because we should not reload them.*/ } else { message_publish(MSG_ERROR, "Memory Manager INTERNAL ERROR: Allocation storage class is messed up.\n") ; } } else { currentCheckPointAgent->write_decl( out_s, alloc_info); } } // Write a "clear_all_vars" command. if (reduced_checkpoint) { out_s << std::endl << std::endl << "// Clear all allocations to 0." << std::endl; out_s << "clear_all_vars();" << std::endl; } // 2) Dump the contents of each of the dynamic and mapped allocations. out_s << std::endl << std::endl << "// Variable Assignments." << std::endl; out_s.flush(); for (int ii = 0 ; ii < n_depends ; ii ++) { alloc_info = dependencies[ii]; write_var( out_s, alloc_info); out_s << std::endl; } // Free all of the temporary names that were created for the checkpoint. for (int ii = 0 ; ii < n_depends ; ii ++) { alloc_info = dependencies[ii]; // If the temporary-variable prefix occurs at the beginning of the name ... if ((alloc_info->name != NULL) && (( strstr( alloc_info->name, local_anon_var_prefix ) == alloc_info->name ) || ( strstr( alloc_info->name, extern_anon_var_prefix) == alloc_info->name ))) { free( alloc_info->name); alloc_info->name = NULL; } } }
internal void push_var(U8Array *buf, u64 var) { u32 len = var_len(var); array_bump(buf, len); write_var(buf->data + buf->size - len, var, len); }
internal void print_type_(Type *type, u32 prec, TypePtrB1Map *seen, TypePtrU64Map *vars, U8Array *buf) { if (IS_VAR(type)) { type = rep(type); if (type->terms == NULL) { TypePtrU64MapGetResult result = type_ptr_u64_map_get(vars, type); if (!result.found) { result.value = vars->size; type_ptr_u64_map_put_bucket(vars, type, result.value, result.bucket); } push_var(buf, result.value); return; } else if (type->terms->next == type->terms) { type = type->terms; } else { array_push(buf, '{'); Type *term = type->terms; do { // TODO consider printing out the full type if (term == type->terms) { array_push(buf, ','); } if (IS_SEALED(term->symbol)) { u8Array_push_cstring(buf, "sealed \" "); u8Array_push_many(buf, term->seal->data, term->seal->size); array_push(buf, '"'); } else { switch (term->symbol) { case SYMBOL_VOID: array_push(buf, '0'); break; case SYMBOL_UNIT: array_push(buf, '1'); break; case SYMBOL_NUMBER: array_push(buf, 'N'); break; case SYMBOL_PRODUCT: array_push(buf, '*'); break; case SYMBOL_SUM: array_push(buf, '+'); break; case SYMBOL_BLOCK: u8Array_push_cstring(buf, "=>"); break; case SYMBOL_BLOCK | POLYMORPHIC_BIT: u8Array_push_cstring(buf, "->"); break; case SYMBOL_BOOL: array_push(buf, 'B'); break; default: array_push(buf, '?'); break; } } term = term->next; } while (term != type->terms); array_push(buf, '}'); return; } } TypePtrB1MapGetResult seen_result = type_ptr_b1_map_get(seen, type); if (seen_result.found) { TypePtrU64MapGetResult vars_result = type_ptr_u64_map_get(vars, type); if (!vars_result.found) { vars_result.value = vars->size; type_ptr_u64_map_put_bucket(vars, type, vars_result.value, vars_result.bucket); } push_var(buf, vars_result.value); return; } type_ptr_b1_map_put_bucket(seen, type, true, seen_result.bucket); TypePtrU64MapGetResult vars_result = type_ptr_u64_map_get(vars, type); if (vars_result.found) { map_delete_bucket(vars, vars_result.bucket); } usize begin = buf->size; if (IS_SEALED(type->symbol)) { if (prec > 8) { array_push(buf, '('); } u8Array_push_cstring(buf, "sealed \""); u8Array_push_many(buf, type->seal->data, type->seal->size); u8Array_push_cstring(buf, "\" "); print_type_(type->child1, 9, seen, vars, buf); if (prec > 8) { array_push(buf, ')'); } } else { u8 sym = 0; b32 children = true; u32 newprec = 100; b32 block = false; switch (type->symbol) { case SYMBOL_VOID: sym = '0'; children = false; break; case SYMBOL_UNIT: sym = '1'; children = false; break; case SYMBOL_NUMBER: sym = 'N'; children = false; break; case SYMBOL_PRODUCT: sym = '*'; newprec = 7; break; case SYMBOL_SUM: sym = '+'; newprec = 6; break; case SYMBOL_BLOCK: case SYMBOL_BLOCK | POLYMORPHIC_BIT: block = true; break; case SYMBOL_BOOL: sym = 'B'; children = false; break; default: sym = '?'; } if (prec > newprec) { array_push(buf, '('); } else if (block) { array_push(buf, '['); } if (children) { print_type_(type->child1, newprec + 1, seen, vars, buf); } if (type->symbol == SYMBOL_BLOCK) { u8Array_push_cstring(buf, " => "); } else if (type->symbol == (SYMBOL_BLOCK | POLYMORPHIC_BIT)) { u8Array_push_cstring(buf, " -> "); } else { if (children) { array_push(buf, ' '); } array_push(buf, sym); if (children) { array_push(buf, ' '); } } if (children) { print_type_(type->child2, newprec, seen, vars, buf); } if (prec > newprec) { array_push(buf, ')'); } else if (block) { array_push(buf, ']'); } } map_delete_bucket(seen, seen_result.bucket); vars_result = type_ptr_u64_map_get(vars, type); if (vars_result.found) { u32 shift = sizeof("μ. ") - 1 + var_len(vars_result.value); if (prec > 0) { shift++; } array_bump(buf, shift); memmove(buf->data + begin + shift, buf->data + begin, buf->size - begin - shift); u8 *hole = buf->data + begin; if (prec > 0) { *hole++ = '('; } hole = mempcpy(hole, "μ", sizeof("μ") - 1); u32 len = var_len(vars_result.value); write_var(hole, vars_result.value, len); hole += len; hole = mempcpy(hole, ". ", sizeof(". ") - 1); if (prec > 0) { array_push(buf, ')'); } } }