static void emit_tag(list_s *list, unsigned short cv_leaf_type) { if (list->emitted_tag) { return; } /* if */ list->emitted_tag = 1; list->cv_leaf_type = cv_leaf_type; VERBOSE_PUSH_INDENT(TYPE_INDENT); VERBOSE_PRINTF("\n"); VERBOSE_PRINTF("[0x%08x] %sLIST 0x%x tag = ", buffer_total(list->type->buf), cv_leaf_type == LF_ARGLIST ? "ARG" : "FIELD", type_get_index(list->type)); buffer_put_value(list->type->buf, cv_leaf_type, CV_LEAF_TAG_SIZE, NO_VLENGTH); if (cv_leaf_type == LF_ARGLIST) { list->pcount = (unsigned short *)buffer_ptr(list->type->buf); VERBOSE_PRINTF("[0x%08x] ARGLIST 0x%x count dummy = ", buffer_total(list->type->buf), type_get_index(list->type)); buffer_put_value(list->type->buf, 0, CV_ARGLIST_COUNT_SIZE,NO_VLENGTH); } /* if */ VERBOSE_POP_INDENT(); } /* emit tag */
extern data list_member( arg_s *parg, /* arg entry causing call */ callinfo_s *pinfo, /* info we need to pass around */ long *plength) /* for varying length fields */ { long is_arglist; /* set if we're building an arglist */ plength; if (list_stack == 0) { fatal("unexpected list end without list start\n"); } /* if */ is_arglist = pinfo->psym->st == stParam; emit_tag(list_stack, (unsigned short)(is_arglist ? LF_ARGLIST:LF_FIELDLIST)); list_stack->count++; VERBOSE_POP_INDENT(); VERBOSE_PUSH_INDENT(TYPE_INDENT); VERBOSE_PRINTF("LIST 0x%x field %d:\n", type_get_index(list_stack->type), list_stack->count); VERBOSE_POP_INDENT(); VERBOSE_PUSH_INDENT(TYPE_INDENT); pinfo->buf = list_stack->type->buf; /* subversion */ switch (parg->id) { case MEMB: return LF_MEMBER; case ENUM: return LF_ENUMERATE; default: return 0xbadbad; } /* switch */ } /* list_member */
extern data get_field_pad( arg_s *parg, /* arg entry causing call */ callinfo_s *pinfo, /* info we need to pass around */ long *plength) /* for varying length fields */ { /* special LF_PAD things must be put out between field list * members. */ unsigned long bytes; unsigned long pad_size; unsigned char pad; #define PAD_CONSTANT 0xf0 parg; pinfo; plength; if (list_stack == 0) { fatal("tried to emit pad for list stack when it was empty\n"); } /* if */ bytes = buffer_total(list_stack->type->buf); if (CALCULATE_PAD(pad_size, bytes, NATURAL_ALIGNMENT) != 0) { pad = (unsigned char)(PAD_CONSTANT|pad_size); VERBOSE_PRINTF("[0x%08x] LIST pad char = ", buffer_total(list_stack->type->buf)); buffer_put_value(list_stack->type->buf, pad, CV_PAD_LEAF_SIZE, NO_VLENGTH); pad_size -= CV_PAD_LEAF_SIZE; if (pad_size) { VERBOSE_TOTAL(list_stack->type->buf); VERBOSE_PRINTF("LIST pad (%d) = ", pad_size); buffer_put_value(list_stack->type->buf, 0, pad_size, NO_VLENGTH); } /* if */ } /* if */ return 0; } /* get_field_pad */
/* * Set buffer size for socket sock. snd_buf is boolean which if set, send buffer is modified, * otherwise receive buffer is modified. buf_size is size of buffer to allocate. This can be <=0 and * then buffer is left unchanged. new_buf_size is real size provided by OS. new_buf_size also * accepts NULL as pointer, if information about new buffer size is not needed. if force_buf_size is * set and OS will not provide enough buffer, error code is returned and errno is set to ENOBUFS * (this is emulation of *BSD behavior). * On success 0 is returned, otherwise -1. */ int sfset_buf_size(int sock, int snd_buf, int buf_size, int *new_buf_size, int force_buf_size) { const char *opt_name_s; socklen_t optlen; int opt_name; int res; int tmp_buf_size; if (snd_buf) { opt_name = SO_SNDBUF; opt_name_s = "SO_SNDBUF"; } else { opt_name = SO_RCVBUF; opt_name_s = "SO_RCVBUF"; } if (buf_size > 0) { res = setsockopt(sock, SOL_SOCKET, opt_name, &buf_size, sizeof(buf_size)); if (res == -1) { DEBUG_PRINTF("setsockopt %s failed", opt_name_s); return (-1); } } if (new_buf_size == NULL && !force_buf_size) { return (0); } optlen = sizeof(tmp_buf_size); res = getsockopt(sock, SOL_SOCKET, opt_name, &tmp_buf_size, &optlen); if (res == -1) { DEBUG_PRINTF("getsockopt %s failed", opt_name_s); return (-1); } if (force_buf_size && tmp_buf_size < buf_size) { VERBOSE_PRINTF("Buffer size request was %u bytes, but only %u" " bytes was allocated", buf_size, tmp_buf_size); errno = ENOBUFS; return (-1); } if (new_buf_size != NULL) { *new_buf_size = tmp_buf_size; } return (0); }
int end_transaction ( sqlite3 *db, int ret ) { char *zErrMsg = 0; VERBOSE_PRINTF("%s\n", ret ? "ROLLBACK" : "COMMIT"); int ret2 = sqlite3_exec ( db, ret ? "ROLLBACK" : "COMMIT", cb_sql, 0, &zErrMsg ); if ( ret2 != SQLITE_OK ) { printf("end_transaction() SQL: %s", ret ? "ROLLBACK" : "COMMIT"); printf ( "%s error: %s\n", ret ? "ROLLBACK" : "COMMIT", zErrMsg ); sqlite3_free ( zErrMsg ); } return ret; }
int exec_sql ( sqlite3 *db, const char *sql ) { int ret = 0; char *zErrMsg = 0; VERBOSE_PRINTF("%s\n", sql); ret = sqlite3_exec ( db, sql, cb_sql, 0, &zErrMsg ); if ( ret != SQLITE_OK ) { printf("exec_sql() SQL: %s", sql); printf ( "SQL error: ret=%d, msg=%s\n", ret, zErrMsg ); sqlite3_free ( zErrMsg ); return ret; } return ret; }
int start_transaction(sqlite3 *db) { int ret = 0; char *zErrMsg = 0; VERBOSE_PRINTF("BEGIN TRANSACTION\n"); ret = sqlite3_exec(db, "BEGIN TRANSACTION",cb_sql, 0, &zErrMsg); if ( ret != SQLITE_OK ) { printf("start_transaction() SQL: %s", "BEGIN TRANSACTION"); printf ( "SQL error: %s\n", zErrMsg ); sqlite3_free ( zErrMsg ); return ret; } return 0; }
int exec_sql_list_in_transaction ( sqlite3 *db, const char **sqls ) { VERBOSE_PRINTF("exec_sql_list_in_transaction()\n"); int ret = 0; ret = start_transaction(db); if (ret) { return ret; } ret = exec_sql_list(db, sqls); if (ret) { //return ret; } int ret2 = end_transaction(db, ret); if (ret) { return ret; } return ret2; }
PackImgScheme2D<T>::PackImgScheme2D (BrImgVector & imgVec) : PackBase (imgVec), // --> size() & consistency check schemes_ (size()) // allocates vector of `size' NULL schemes { /* Take over the activated images... (relies on some PackBase settings) */ /* The intersection area of all activated images */ const Rectangle & section = imgVec.intersection(); VERBOSE_PRINTF(("Intersection: dim1=%d dim2=%d [x0=%d x1=%d] x [y0=%d y1=%d]\n", section.dim1(), section.dim2(), section.x0(), section.xlast(), section.y0(), section.ylast())); int iact = 0; // counts the active images for (int i=0; i < imgVec.size(); i++) { BrImage & img = imgVec.image(i); if (img.active()) { Vec2_int d = img.active_offset(); int i0 = section.y0() + d.y; // dim1 == height int i1 = section.ylast() + d.y; int k0 = section.x0() + d.x; // dim2 == width int k1 = section.xlast() + d.x; schemes_[iact ++] = ImgScheme2D<T>( img ).subscheme (i0,i1, k0,k1); # if VERBOSE const ImgScheme2D<T> & s = schemes_[iact-1]; printf ("Image: dim1=%d dim2=%d\n", img.dim1(), img.dim2()); printf ("Scheme: dim1=%d dim2=%d stride=%d\n", s.dim1(), s.dim2(), s.stride()); # endif /* Rough test whether active_offset()s are consistent */ assert (i0 >= 0 && i0 < img.dim1()); assert (i1 >= i0 && i1 < img.dim1()); assert (k0 >= 0 && k0 < img.dim2()); assert (k1 >= k0 && k1 < img.dim2()); } } }
int exec_sql_list ( sqlite3 *db, const char **sqls ) { VERBOSE_PRINTF("exec_sql_list()\n"); int ret = 0; char *zErrMsg = 0; for ( int i = 0; sqls[i]; i++ ) { printf("sqls[%d] : %s\n", i, sqls[i]); ret = exec_sql ( db, sqls[i] ); if ( ret != SQLITE_OK ) { printf ( "exec_sql error: ret=%d\n", ret); sqlite3_free ( zErrMsg ); break; } //paf::thread::Sleep(1000); } printf("sqlite3_memory_highwater(): %lld\n", sqlite3_memory_highwater(true)); return ret; }
// arg1: total_sql_num // arg2: max_sql_in_transaction // arg3: new_db: 1: create, 0: use existing. // arg4: sql_template: 1 line sql VA_ARGS: sql_id, mod10, mod10, mod10, sql_id; // arg5: db_name: default "/app0/test.db" // arg6 or follower: option // options: // -v: enable verbose print (default false) // -c SQL: specify table creation SQL. NOTE: that arg3 must be 1. // multiple SQLs can be set with multiple -c options. // -1..9 PARAM_VAL: specify or generate va_args for sql_template // "sql_id", "mod?", "div?" (? can be any number). // "1k?" for ?KB text (e.g. 1k2 => 2KB, 1k10 => 10KB). // -l SIZE: limit heap with sqlite3_soft_heap_limit64(SIZE). int check_args(int argc, char** argv) { if (argc >= 2) { total_sql_num = atoi(argv[1]); } if (argc >= 3) { max_sql_in_trans = atoi(argv[2]); } if (argc >= 4) { new_db = atoi(argv[3]); } if (argc >= 5) { sql_template = argv[4]; } if (argc >= 6) { db_name = argv[5]; } int arg_index = 6; while (argc > arg_index) { if (argv[arg_index][0] != '-') { printf ("error: 6th or following arguments must be a option setting.\n"); return -1; } if (argv[arg_index][1] == 'v' || argv[arg_index][1] == 'V') { option_verbose = true; } else if (argv[arg_index][1] == 'l' || argv[arg_index][1] == 'L') { arg_index++; if (argc <= arg_index) { printf("error: -l option requires a limit size.\n"); return -1; } soft_heap_limit = atoll(argv[arg_index]); VERBOSE_PRINTF("set soft heap limit: %ld\n", soft_heap_limit); } else if (argv[arg_index][1] == 'c' || argv[arg_index][1] == 'C') { arg_index++; if (argc <= arg_index) { printf("error: -c option requires a creation SQL.\n"); return -1; } if (!new_db) { printf("error: 2nd argument (new_db) must be 1 for -c option .\n"); return -1; } if (sql_create_count >= MAX_CREATE_SQL_COUNT) { printf("error: too many creation SQL. count: %d\n", sql_create_count); return -1; } printf("\tcreation SQL: %s\n", argv[arg_index]); sql_create_table[sql_create_count++] = argv[arg_index]; } else if (argv[arg_index][1] >= '1' && argv[arg_index][1] <= '9') { int param_id = argv[arg_index][1] - '1'; arg_index++; if (argc <= arg_index) { printf("error: -1..5 option requires param option (\"sql_id\" or \"modXX\").\n"); return -1; } printf("\tparam option[%d]: %s\n", param_id, argv[arg_index]); if (set_conveted_param(argv[arg_index], param_id)) { // error. return -1; } } else { printf("error: unknown option: %s\n", argv[arg_index]); return -1; } arg_index++; } printf("\n\nMemConsumptionCheck:\n"); printf("start: total_sql_num: %d, max_sql_in_trans: %d, new_db: %d\n", total_sql_num, max_sql_in_trans, new_db); printf("sql_template: %s\n", sql_template); //snprintf(sql_buf, BUF_SIZE, sql_template, 1, 1, 1, 1, 1); fill_sql(1); printf("\tsample: %s\n", sql_buf); printf("db_name: %s\n", db_name); //printf("soft_heap_limit: %ld\n", soft_heap_limit); return 0; }
extern void list_end( arg_s *parg, /* arg entry causing call */ callinfo_s *pinfo, /* info we need to pass around */ long *plength) /* for varying length fields */ { pSYMR psymbegin; list_s *list; unsigned short *pcount; unsigned short *ptype_index; parg; plength; if (list_stack == 0) { fatal("unexpected list end without list start\n"); } /* if */ list = list_stack; VERBOSE_PUSH_INDENT(TYPE_INDENT); /* no entries, emit tag*/ if (pinfo->psym->st != stEnd) emit_tag(list, LF_ARGLIST); else emit_tag(list, LF_FIELDLIST); if (pinfo->psym->st == stEnd) { if (pinfo->psym->index == indexNil) { fatal("list end doesn't point to list begin symbol (%d)\n", pinfo->psym->index); } /* if */ psymbegin = isym_to_psym(pinfo, pinfo->psym->index); if (psymbegin != list->psym) { fatal("list end doesn't point to list begin symbol (%d)\n", pinfo->psym->index); } /* if */ } /* if */ /* stash the count in stEnd iss field, and the type in stEnd value field */ if (pinfo->psym->sc == scForward) { /* referenced the count and type information already and the pointers * to where they go are in the respective fields we intend * to stash them in. */ pcount = (unsigned short *)pinfo->psym->iss; ptype_index = (unsigned short *)pinfo->psym->value; *pcount = (unsigned short)list->count; *ptype_index = (unsigned short)type_get_index(list->type); VERBOSE_PRINTF("Fill forward ref count (%d) & type index (0x%x)\n", *pcount, *ptype_index); } /* if */ pinfo->psym->iss = list->count; pinfo->psym->value = type_get_index(list->type); pinfo->psym->sc = scProcessed; /* mark that we've done it */ if (list->cv_leaf_type == LF_ARGLIST) { /* fix count field */ VERBOSE_PRINTF("Fix ARGLIST count field = %d\n", list->count); *list->pcount = (unsigned short)list->count; if (pinfo->psym->st == stEnd) { /* prottype appears before typedef using prototype, so set * st so we know it was a prototype. */ pinfo->psym->st = stProto; } else if (pinfo->psym->st == stEndParam) { if (list->pproccount) { /* proc definition appears before arglist, so we need to back * fill LF_PROCEDURE arg count */ VERBOSE_PRINTF("Fix LF_PROCEDURE count field = %d\n", list->count); *list->pproccount = (unsigned short)list->count; } /* if */ } /* if */ } /* if */ /* pop the list stack and free list structure, types will dump buffer * later. */ list_stack = list->next; VERBOSE_PRINTF("LIST 0x%x count = %d\n", pinfo->psym->value, list->count); VERBOSE_POP_INDENT(); free(list); } /* list_end */