diff --git a/src/qli/all.cpp b/src/qli/all.cpp index b8c51d9462..0aafa7e3fd 100644 --- a/src/qli/all.cpp +++ b/src/qli/all.cpp @@ -157,7 +157,7 @@ BLK ALLQ_alloc( PLB pool, UCHAR type, int count) } -BLK ALLQ_extend(BLK * pointer, int size) +BLK ALLQ_extend(BLK* pointer, int size) { /************************************** * @@ -173,8 +173,7 @@ BLK ALLQ_extend(BLK * pointer, int size) BLK new_blk = (BLK) ALLQ_alloc((PLB) global_pools->vec_object[block->blk_pool_id], block->blk_type, size); const int length = MIN(block->blk_length, new_blk->blk_length) - sizeof(blk); - MOVQ_fast((SCHAR*) block + sizeof(blk), - (SCHAR*) new_blk + sizeof(blk), length); + memcpy((SCHAR*) new_blk + sizeof(blk), (SCHAR*) block + sizeof(blk), length); ALLQ_release((FRB) block); if (new_blk->blk_type == (SCHAR) type_vec) @@ -188,7 +187,7 @@ BLK ALLQ_extend(BLK * pointer, int size) } -void ALLQ_fini(void) +void ALLQ_fini() { /************************************** * @@ -217,7 +216,7 @@ void ALLQ_fini(void) } -void ALLQ_free( SCHAR * memory) +void ALLQ_free(void* memory) { /************************************** * @@ -234,7 +233,7 @@ void ALLQ_free( SCHAR * memory) } -void ALLQ_init(void) +void ALLQ_init() { /************************************** * @@ -246,9 +245,10 @@ void ALLQ_init(void) * Initialize the pool system. * **************************************/ - ISC_STATUS_ARRAY temp_vector; + qli_vec temp_vector[2]; + memcpy(temp_vector, 0, sizeof(temp_vector)); - global_pools = (qli_vec*) temp_vector; + global_pools = temp_vector; global_pools->vec_count = 1; global_pools->vec_object[0] = NULL; @@ -286,7 +286,7 @@ SCHAR *ALLQ_malloc(SLONG size) } -PLB ALLQ_pool(void) +PLB ALLQ_pool() { /************************************** * diff --git a/src/qli/all_proto.h b/src/qli/all_proto.h index 7ad517ce01..c3d4a11ade 100644 --- a/src/qli/all_proto.h +++ b/src/qli/all_proto.h @@ -26,11 +26,11 @@ blk* ALLQ_alloc(plb*, UCHAR, int); blk* ALLQ_extend(blk**, int); -void ALLQ_fini(void); -void ALLQ_free(SCHAR*); -void ALLQ_init(void); +void ALLQ_fini(); +void ALLQ_free(void*); +void ALLQ_init(); SCHAR* ALLQ_malloc(SLONG); -plb* ALLQ_pool(void); +plb* ALLQ_pool(); void ALLQ_push(blk*, qli_lls**); blk* ALLQ_pop(qli_lls**); void ALLQ_release(frb*); diff --git a/src/qli/gener.cpp b/src/qli/gener.cpp index ddbac09a13..9b33217231 100644 --- a/src/qli/gener.cpp +++ b/src/qli/gener.cpp @@ -40,8 +40,8 @@ #include "../jrd/gds_proto.h" #ifdef DEV_BUILD -static void explain(const UCHAR*); -static void explain_index_tree(SSHORT, const TEXT*, const SCHAR**, SSHORT*); +static void explain(DBB db, const UCHAR*); +static void explain_index_tree(DBB db, SSHORT, const TEXT*, const UCHAR**, SSHORT*); static void explain_printf(SSHORT, const TEXT*, const TEXT*); #endif @@ -137,19 +137,19 @@ qli_rlb* GEN_rlb_extend(qli_rlb* rlb) if (!rlb) rlb = (qli_rlb*) ALLOCD(type_rlb); - const UCHAR* old_string = rlb->rlb_base; - const ULONG l = rlb->rlb_data - rlb->rlb_base; + UCHAR* const old_string = rlb->rlb_base; + const ULONG len = rlb->rlb_data - rlb->rlb_base; rlb->rlb_length += RLB_BUFFER_SIZE; UCHAR* new_string = (UCHAR*) ALLQ_malloc((SLONG) rlb->rlb_length); if (old_string) { - MOVQ_fast((SCHAR*) old_string, (SCHAR*) new_string, l); - ALLQ_free((SCHAR*) old_string); + memcpy(new_string, old_string, len); + ALLQ_free(old_string); } rlb->rlb_base = new_string; - rlb->rlb_data = new_string + l; + rlb->rlb_data = new_string + len; rlb->rlb_limit = rlb->rlb_data + RLB_BUFFER_SIZE - RLB_SAFETY_MARGIN; - return (rlb); + return rlb; } @@ -173,7 +173,7 @@ void GEN_rlb_release( qli_rlb* rlb) return; if (rlb->rlb_base) { - ALLQ_free((SCHAR*) rlb->rlb_base); + ALLQ_free(rlb->rlb_base); rlb->rlb_base = NULL; rlb->rlb_length = 0; rlb->rlb_data = NULL; @@ -183,7 +183,7 @@ void GEN_rlb_release( qli_rlb* rlb) #ifdef DEV_BUILD -static void explain(const UCHAR* explain_buffer) +static void explain(DBB db, const UCHAR* explain_buffer) { /************************************** * @@ -249,9 +249,7 @@ static void explain(const UCHAR* explain_buffer) case isc_info_rsb_indexed: printf("isc_info_rsb_indexed,\n"); level++; - explain_index_tree(level, relation_name, - reinterpret_cast(&explain_buffer), - &buffer_length); + explain_index_tree(db, level, relation_name, &explain_buffer, &buffer_length); level--; break; @@ -271,9 +269,7 @@ static void explain(const UCHAR* explain_buffer) case isc_info_rsb_navigate: printf("isc_info_rsb_navigate,\n"); level++; - explain_index_tree(level, relation_name, - reinterpret_cast(&explain_buffer), - &buffer_length); + explain_index_tree(db, level, relation_name, &explain_buffer, &buffer_length); level--; break; @@ -354,10 +350,10 @@ static void explain(const UCHAR* explain_buffer) #ifdef DEV_BUILD -static void explain_index_tree( +static void explain_index_tree(DBB db, SSHORT level, const TEXT* relation_name, - const SCHAR** explain_buffer_ptr, + const UCHAR** explain_buffer_ptr, SSHORT* buffer_length) { /************************************** @@ -374,7 +370,7 @@ static void explain_index_tree( SCHAR index_info[256]; SSHORT length; - const SCHAR* explain_buffer = *explain_buffer_ptr; + const UCHAR* explain_buffer = *explain_buffer_ptr; (*buffer_length)--; @@ -382,20 +378,16 @@ static void explain_index_tree( case isc_info_rsb_and: explain_printf(level, "isc_info_rsb_and,\n", 0); level++; - explain_index_tree(level, relation_name, &explain_buffer, - buffer_length); - explain_index_tree(level, relation_name, &explain_buffer, - buffer_length); + explain_index_tree(db, level, relation_name, &explain_buffer, buffer_length); + explain_index_tree(db, level, relation_name, &explain_buffer, buffer_length); level--; break; case isc_info_rsb_or: explain_printf(level, "isc_info_rsb_or,\n", 0); level++; - explain_index_tree(level, relation_name, &explain_buffer, - buffer_length); - explain_index_tree(level, relation_name, &explain_buffer, - buffer_length); + explain_index_tree(db, level, relation_name, &explain_buffer, buffer_length); + explain_index_tree(db, level, relation_name, &explain_buffer, buffer_length); level--; break; @@ -408,13 +400,13 @@ static void explain_index_tree( (*buffer_length)--; length = (SSHORT) *explain_buffer++; - strncpy(index_name, explain_buffer, length); + memcpy(index_name, explain_buffer, length); index_name[length] = 0; *buffer_length -= length; explain_buffer += length; - MET_index_info(relation_name, index_name, index_info); + MET_index_info(db, relation_name, index_name, index_info, sizeof(index_info)); printf("%s\n", index_info); break; } @@ -602,7 +594,7 @@ static void gen_compile( qli_req* request) if (QLI_blr) gds__print_blr(rlb->rlb_base, 0, 0, 0); - const USHORT length = (UCHAR *) rlb->rlb_data - (UCHAR *) rlb->rlb_base; + const USHORT length = rlb->rlb_data - rlb->rlb_base; DBB dbb = request->req_database; @@ -622,7 +614,7 @@ static void gen_compile( qli_req* request) sizeof(explain_info), explain_info, sizeof(explain_buffer), explain_buffer)) { - explain((UCHAR*) explain_buffer); + explain(dbb, (UCHAR*) explain_buffer); } #endif diff --git a/src/qli/meta.epp b/src/qli/meta.epp index c70afa6968..048c6c524e 100644 --- a/src/qli/meta.epp +++ b/src/qli/meta.epp @@ -78,6 +78,7 @@ static qli_syntax* parse_blr(UCHAR **, qli_symbol*); static qli_syntax* parse_blr_blob(ISC_QUAD&, qli_symbol*); static void purge_relation(qli_rel*); static void put_dyn_string(qli_rlb*, const TEXT*); +static void release_request(DBB db, FB_API_HANDLE& request_handle); static void rollback_update(DBB); static void set_capabilities(DBB); static DBB setup_update(DBB); @@ -965,9 +966,11 @@ int MET_get_datatype( USHORT blr_datatype) #ifdef DEV_BUILD -void MET_index_info(const SCHAR* relation_name, +void MET_index_info(DBB db, + const SCHAR* relation_name, const SCHAR* index_name, - SCHAR* buffer) + SCHAR* const buffer, + size_t bufsize) { /************************************** * @@ -992,15 +995,18 @@ void MET_index_info(const SCHAR* relation_name, const SCHAR* p; if (b == buffer) { - // CVC: warning: not dialect 3 aware. - for (p = IDX.RDB$INDEX_NAME; *p && *p != ' ';) { + for (p = fb_utils::exact_name(IDX.RDB$INDEX_NAME); *p;) { *b++ = *p++; } *b++ = ' '; *b++ = '('; } - // CVC: warning: not dialect 3 aware. - for (p = SEG.RDB$FIELD_NAME; *p && *p != ' ';) { + + p = fb_utils::exact_name(SEG.RDB$FIELD_NAME); + if (p + strlen(p) + 2 > buffer + bufsize) + break; + + while (*p) { *b++ = *p++; } @@ -1011,11 +1017,9 @@ void MET_index_info(const SCHAR* relation_name, ERRQ_database_error(NULL, gds_status); END_ERROR; - if (request_handle) - if (isc_release_request(gds_status, &request_handle)) - ERRQ_database_error(NULL, gds_status); + release_request(db, request_handle); -// back up over the last space and finish off + // back up over the last space and finish off b--; *b++ = ')'; @@ -2249,13 +2253,8 @@ static void clone_fields( qli_rel* target, qli_rel* source) execute_dynamic_ddl(target->rel_database, rlb); - if (req1) - if (isc_release_request(gds_status, &req1)) - ERRQ_database_error(source->rel_database, gds_status); - if (req2) - if (isc_release_request(gds_status, &req2)) - ERRQ_database_error(source->rel_database, gds_status); - //return TRUE; + release_request(source->rel_database, req1); + release_request(source->rel_database, req2); } @@ -2323,7 +2322,7 @@ static void clone_global_fields( qli_rel* target, qli_rel* source) && (A.RDB$FIELD_SUB_TYPE != Y.RDB$FIELD_SUB_TYPE))) { - TEXT* name = (TEXT*) ALLQ_malloc((SLONG) sizeof(Y.RDB$FIELD_NAME)); + TEXT* name = ALLQ_malloc((SLONG) sizeof(Y.RDB$FIELD_NAME)); strcpy(name, Y.RDB$FIELD_NAME); rollback_update(target->rel_database); // CVC: When is this memory deallocated? @@ -2477,16 +2476,9 @@ static void clone_global_fields( qli_rel* target, qli_rel* source) execute_dynamic_ddl(target->rel_database, rlb); } - if (req1) - if (isc_release_request(gds_status, &req1)) - ERRQ_database_error(source->rel_database, gds_status); - if (req2) - if (isc_release_request(gds_status, &req2)) - ERRQ_database_error(target->rel_database, gds_status); - if (req3) - if (isc_release_request(gds_status, &req3)) - ERRQ_database_error(source->rel_database, gds_status); - //return TRUE; + release_request(source->rel_database, req1); + release_request(target->rel_database, req2); + release_request(source->rel_database, req3); } @@ -2617,7 +2609,7 @@ static void execute_dynamic_ddl( DBB database, qli_rlb* rlb) * Execute a ddl command, for better or for worse. * **************************************/ - const USHORT length = (UCHAR *) rlb->rlb_data - (UCHAR *) rlb->rlb_base; + const USHORT length = rlb->rlb_data - rlb->rlb_base; if (QLI_blr) PRETTY_print_dyn(rlb->rlb_base, NULL, NULL, 0); @@ -2863,13 +2855,12 @@ static void install( dbb* old_dbb) ERRQ_database_error(new_dbb, gds_status); END_ERROR; - if (request) - if (isc_release_request(gds_status, &request)) - ERRQ_database_error(new_dbb, gds_status); + release_request(new_dbb, request); -// Pick up functions, if appropriate + // Pick up functions, if appropriate - if (new_dbb->dbb_capabilities & DBB_cap_functions) { + if (new_dbb->dbb_capabilities & DBB_cap_functions) + { FB_API_HANDLE request2 = 0; FOR(REQUEST_HANDLE request) X IN DB.RDB$FUNCTIONS qli_symbol* fsymbol = make_symbol(X.RDB$FUNCTION_NAME, sizeof(X.RDB$FUNCTION_NAME)); @@ -2913,12 +2904,8 @@ static void install( dbb* old_dbb) ON_ERROR ERRQ_database_error(new_dbb, gds_status); END_ERROR; - if (request) - if (isc_release_request(gds_status, &request)) - ERRQ_database_error(new_dbb, gds_status); - if (request2) - if (isc_release_request(gds_status, &request2)) - ERRQ_database_error(new_dbb, gds_status); + release_request(new_dbb, request); + release_request(new_dbb, request2); } } @@ -3413,6 +3400,16 @@ static void put_dyn_string( qli_rlb* rlb, const TEXT* string) } +static void release_request(DBB db, FB_API_HANDLE& request_handle) +{ + if (request_handle) + { + if (isc_release_request(gds_status, &request_handle)) + ERRQ_database_error(db, gds_status); + } +} + + static void rollback_update( DBB database) { /************************************** @@ -3472,11 +3469,7 @@ static void set_capabilities( DBB database) END_ERROR; } - if (req) - { - if (isc_release_request(gds_status, &req)) - ERRQ_database_error(database, gds_status); - } + release_request(database, req); } diff --git a/src/qli/meta_proto.h b/src/qli/meta_proto.h index 984e00f531..d5310c90a7 100644 --- a/src/qli/meta_proto.h +++ b/src/qli/meta_proto.h @@ -37,7 +37,7 @@ int MET_dimensions(dbb*, const TEXT*); void MET_fields(qli_rel*); void MET_finish(dbb*); int MET_get_datatype (USHORT); -void MET_index_info(const TEXT*, const TEXT*, SCHAR*); +void MET_index_info(DBB db, const TEXT*, const TEXT*, SCHAR* const, size_t bufsize); void MET_meta_commit(dbb*); void MET_meta_rollback(dbb*); FB_API_HANDLE MET_meta_transaction(dbb*, bool); diff --git a/src/qli/mov.cpp b/src/qli/mov.cpp index 9431c57070..23dc69daf4 100644 --- a/src/qli/mov.cpp +++ b/src/qli/mov.cpp @@ -439,26 +439,6 @@ void MOVQ_double_to_date( double real, SLONG fixed[2]) } -void MOVQ_fast(const SCHAR* from, - SCHAR* to, - ULONG length) -{ -/************************************** - * - * M O V Q _ f a s t - * - ************************************** - * - * Functional description - * Move a byte string as fast as possible. - * - **************************************/ - - if (length) - memcpy(to, from, length); -} - - double MOVQ_get_double(const dsc* desc) { /************************************** diff --git a/src/qli/mov_proto.h b/src/qli/mov_proto.h index e778f89a48..96a6c274c7 100644 --- a/src/qli/mov_proto.h +++ b/src/qli/mov_proto.h @@ -28,7 +28,6 @@ int MOVQ_compare(const dsc*, const dsc*); double MOVQ_date_to_double(const dsc*); int MOVQ_decompose (const TEXT*, USHORT, SLONG *); void MOVQ_double_to_date (double, SLONG [2]); -void MOVQ_fast (const SCHAR*, SCHAR*, ULONG); double MOVQ_get_double(const dsc*); SLONG MOVQ_get_long(const dsc*, SSHORT); int MOVQ_get_string(const dsc*, const TEXT**, vary*, USHORT); diff --git a/src/qli/report.cpp b/src/qli/report.cpp index afb44af90b..ae9574bfec 100644 --- a/src/qli/report.cpp +++ b/src/qli/report.cpp @@ -103,8 +103,7 @@ void RPT_report( qli_nod* loop) report->rpt_buffer = (UCHAR *) string->str_data; } - MOVQ_fast((SCHAR*) message->msg_buffer, (SCHAR*) report->rpt_buffer, - (SLONG) message->msg_length); + memcpy(report->rpt_buffer, message->msg_buffer, (SLONG) message->msg_length); qli_brk* control; if (control = report->rpt_top_rpt)