diff --git a/src/alice/alice.cpp b/src/alice/alice.cpp index 73cbf596ef..3f4578df31 100644 --- a/src/alice/alice.cpp +++ b/src/alice/alice.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: alice.cpp,v 1.4 2001-07-29 23:43:20 skywalker Exp $ +// $Id: alice.cpp,v 1.5 2001-12-24 02:50:47 tamlin Exp $ // // 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" // conditionals, as the engine now fully supports @@ -72,10 +72,6 @@ #endif -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - static USHORT val_err_table[] = { 0, 55, /* msg 55: \n\tNumber of record level errors\t: %ld */ @@ -232,38 +228,8 @@ int DLL_EXPORT ALICE_gfix( tdgbl->output_data = output_data; tdgbl->ALICE_permanent_pool = NULL; tdgbl->ALICE_default_pool = NULL; - tdgbl->pools = NULL; - - if (SETJMP(env)) { - int exit_code; - - /* All calls to EXIT(), normal and error exits, wind up here */ - - SVC_STARTED(tdgbl->service_blk); - tdgbl->alice_env = NULL; - exit_code = tdgbl->exit_code; - - /* Close the status output file */ - if (tdgbl->sw_redirect == TRUE && tdgbl->output_file != NULL) { - ib_fclose(tdgbl->output_file); - tdgbl->output_file = NULL; - } - - /* Free all unfreed memory used by Gfix itself */ - ALLA_fini(); - - RESTORE_THREAD_DATA; - if (tdgbl != NULL) { - gds__free((SLONG *) tdgbl); - } -#if defined(DEBUG_GDS_ALLOC) && !defined(SUPERSERVER) - gds_alloc_report(0, __FILE__, __LINE__); -#endif - - /* All returns occur from this point - even normal returns */ - return exit_code; - } + try { #ifdef VMS argc = VMS_parse(&argv, argc); @@ -333,10 +299,13 @@ int DLL_EXPORT ALICE_gfix( database = NULL; argv++; - while (--argc > 0) { - if ((*argv)[0] != '-') { - if (database) + while (--argc > 0) + { + if ((*argv)[0] != '-') + { + if (database) { ALICE_error(1, database, 0, 0, 0, 0); /* msg 1: "data base file name (%s) already given", */ + } database = *argv++; #if defined (WIN95) && !defined (GUI_TOOLS) @@ -577,6 +546,38 @@ int DLL_EXPORT ALICE_gfix( EXIT(FINI_OK); + } // try + catch (...) + { + int exit_code; + + /* All calls to EXIT(), normal and error exits, wind up here */ + + SVC_STARTED(tdgbl->service_blk); + tdgbl->alice_env = NULL; + exit_code = tdgbl->exit_code; + + /* Close the status output file */ + if (tdgbl->sw_redirect == TRUE && tdgbl->output_file != NULL) { + ib_fclose(tdgbl->output_file); + tdgbl->output_file = NULL; + } + + /* Free all unfreed memory used by Gfix itself */ + ALLA_fini(); + + RESTORE_THREAD_DATA; + if (tdgbl != NULL) { + gds__free((SLONG *) tdgbl); + } +#if defined(DEBUG_GDS_ALLOC) && !defined(SUPERSERVER) + gds_alloc_report(0, __FILE__, __LINE__); +#endif + + /* All returns occur from this point - even normal returns */ + return exit_code; + } // catch + return 0; // compiler silencer } diff --git a/src/alice/alice.h b/src/alice/alice.h index b3ef89f921..0f553edb29 100644 --- a/src/alice/alice.h +++ b/src/alice/alice.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _ALICE_ALICE_H_ -#define _ALICE_ALICE_H_ +#ifndef ALICE_ALICE_H +#define ALICE_ALICE_H #include "../jrd/ib_stdio.h" @@ -31,22 +31,22 @@ #include "../jrd/thd.h" #include "../alice/all.h" #include "../alice/alice_proto.h" +#include "../include/fb_blk.h" +#include "../common/memory/allocators.h" - -#ifdef __cplusplus -//extern "C" { -#endif +#include #ifndef MAXPATHLEN #define MAXPATHLEN 1024 #endif #define BLKDEF(type, root, tail) type, -enum blk_t { - type_MIN = 0, +enum alice_blk_t + { + alice_type_MIN = 0, #include "../alice/blk.h" - type_MAX -}; + alice_type_MAX + }; #undef BLKDEF #define VAL_INVALID_DB_VERSION 0 @@ -82,18 +82,18 @@ typedef struct user_action /* String block: used to store a string of constant length. */ -typedef struct str { - struct blk str_header; +class str : public pool_alloc_rpt +{ +public: USHORT str_length; UCHAR str_data[2]; -} *STR; - +}; +typedef str *STR; /* Transaction block: used to store info about a multidatabase transaction. */ typedef struct tdr { - struct blk tdr_header; struct tdr *tdr_next; /* next subtransaction */ SLONG tdr_id; /* database-specific transaction id */ struct str *tdr_fullpath; /* full (possibly) remote pathname */ @@ -131,32 +131,38 @@ typedef struct tdr /* a couple of obscure blocks used only in data allocator routines */ -typedef struct vec +class vec : public pool_alloc_rpt { - struct blk vec_header; +public: ULONG vec_count; struct blk *vec_object[1]; -} *VEC; +}; +typedef vec *VEC; -typedef struct vcl +class vcl : public pool_alloc_rpt { - struct blk vcl_header; ULONG vcl_count; SLONG vcl_long[1]; -} *VCL; +}; +typedef vcl *VCL; /* Global switches and data */ #include "../jrd/svc.h" -typedef struct tgbl +class tgbl { +public: + tgbl(AliceMemoryPool *p) : pools(0, (AliceMemoryPool*)0, + pool_vec_t::allocator_type(*p)) {} + struct thdd tgbl_thd_data; struct user_action ALICE_data; - PLB ALICE_permanent_pool; - PLB ALICE_default_pool; + AliceMemoryPool *ALICE_permanent_pool; + AliceMemoryPool *ALICE_default_pool; STATUS status_vector[ISC_STATUS_LENGTH]; - VEC pools; + typedef std::vector > pool_vec_t; + pool_vec_t pools; UCHAR* alice_env; int exit_code; OUTPUTPROC output_proc; @@ -169,10 +175,8 @@ typedef struct tgbl USHORT sw_redirect; USHORT sw_service; USHORT sw_service_thd; - - -} *TGBL; - +}; +typedef tgbl *TGBL; #ifdef GET_THREAD_DATA #undef GET_THREAD_DATA @@ -212,17 +216,11 @@ extern struct tgbl *gdgbl; #if defined(__cplusplus) #define EXIT(code) { tdgbl->exit_code = (code); \ if (tdgbl->alice_env != NULL) \ - LONGJMP((jmp_buf)(tdgbl->alice_env), 1); } + Firebird::status_longjmp_error::raise(1); } #else -#define EXIT(code) { tdgbl->exit_code = (code); \ - if (tdgbl->alice_env != NULL) \ - LONGJMP(tdgbl->alice_env, 1); } -#endif /* __cplusplus */ +#error Dont do this, it hurts! +#endif // __cplusplus #define NOOUTPUT 2 -#ifdef __cplusplus -//} /* extern "C" */ -#endif - -#endif /* _ALICE_ALICE_H_ */ +#endif // ALICE_ALICE_H diff --git a/src/alice/alice_meta.epp b/src/alice/alice_meta.epp index 20f77b9181..c4538dff4a 100644 --- a/src/alice/alice_meta.epp +++ b/src/alice/alice_meta.epp @@ -27,7 +27,7 @@ * *____________________________________________________________ * - * $Id: alice_meta.epp,v 1.2 2001-07-29 23:43:20 skywalker Exp $ + * $Id: alice_meta.epp,v 1.3 2001-12-24 02:50:47 tamlin Exp $ */ #include "firebird.h" @@ -38,11 +38,11 @@ #include "../jrd/license.h" #include "../alice/alice.h" #include "../alice/all.h" -#include "../alice/alloc.h" -#include "../alice/all_proto.h" #include "../alice/alice_meta.h" #include "../jrd/gds_proto.h" #include "../jrd/thd_proto.h" +#include "../include/fb_exception.h" +#include "../common/memory/allocators.h" #include @@ -90,12 +90,14 @@ static struct rfr_tab_t rfr_table[] = { #ifdef GUI_TOOLS #define RETURN_ERROR(user_status) \ - { memcpy (user_status, gds_status, sizeof (gds_status)); \ - LONGJMP ((JMP_BUF)tdgbl->alice_env, 1); } + { memcpy (user_status, gds_status, sizeof (gds_status)); \ + Firebird::status_longjmp_error::raise(0); } +// LONGJMP ((JMP_BUF)tdgbl->alice_env, 1); } #else #define RETURN_ERROR(user_status) \ - { ALICE_print_status (gds_status); \ - LONGJMP ((JMP_BUF)tdgbl->alice_env, 1); } + { ALICE_print_status (gds_status); \ + Firebird::status_longjmp_error::raise(0); } +// LONGJMP ((JMP_BUF)tdgbl->alice_env, 1); } #endif @@ -245,7 +247,7 @@ static STR alloc_string(TEXT ** ptr) p = *ptr; length = (USHORT) * p++; - string = (STR) ALLOCDV(type_str, length + 1); + string = new(*tdgbl->ALICE_default_pool, length + 1) str; q = (TEXT *) string->str_data; while (length--) @@ -342,9 +344,9 @@ static TDR get_description(SLONG blob_id[2]) id = gds__vax_integer((UCHAR*) p, id_length); p += id_length; if (!trans) - trans = ptr = (TDR) ALLOCD(type_tdr); + trans = ptr = new(*tdgbl->ALICE_default_pool) tdr; else { - ptr->tdr_next = (TDR) ALLOCD(type_tdr); + ptr->tdr_next = new(*tdgbl->ALICE_default_pool) tdr; ptr = ptr->tdr_next; } ptr->tdr_host_site = host_site; @@ -405,7 +407,7 @@ static void parse_fullpath(TDR trans) if (*q) { trans->tdr_filename = q + 1; - trans->tdr_remote_site = (STR) ALLOCDV(type_str, q - p + 1); + trans->tdr_remote_site = new(*tdgbl->ALICE_default_pool, q - p + 1) str; strncpy((char*) trans->tdr_remote_site->str_data, (char*) p, q - p); trans->tdr_remote_site->str_data[q - p] = '\0'; } @@ -431,7 +433,7 @@ static void parse_fullpath(TDR trans) p++; if (length) { - trans->tdr_remote_site = (STR) ALLOCDV(type_str, length + 1); + trans->tdr_remote_site = new(*tdgbl->ALICE_default_pool, length + 1) str; q = (TEXT *) trans->tdr_remote_site->str_data; while (length--) *q++ = *p++; diff --git a/src/alice/all.cpp b/src/alice/all.cpp index ec703a0b13..c61218f1ee 100644 --- a/src/alice/all.cpp +++ b/src/alice/all.cpp @@ -24,173 +24,22 @@ // //____________________________________________________________ // -// $Id: all.cpp,v 1.2 2001-07-29 23:43:20 skywalker Exp $ +// $Id: all.cpp,v 1.3 2001-12-24 02:50:47 tamlin Exp $ // -#include "firebird.h" -#include "../jrd/ib_stdio.h" -#include "../jrd/common.h" -#include "../jrd/ibsetjmp.h" -#include "../alice/alice.h" #include "../alice/all.h" -#include "../alice/alloc.h" -#include "../alice/lls.h" -#include "../alice/all_proto.h" -#include "../jrd/gds_proto.h" +//#include "firebird.h" +//#include "../jrd/ib_stdio.h" +//#include "../jrd/common.h" +//#include "../jrd/ibsetjmp.h" +#include "../alice/alice.h" +//#include "../alice/all.h" +//#include "../alice/alloc.h" +//#include "../alice/lls.h" +//#include "../alice/all_proto.h" +//#include "../jrd/gds_proto.h" #include "../jrd/thd_proto.h" - -#define BLKDEF(type, root, tail) sizeof (struct root), tail, -static struct { - SSHORT typ_root_length; - SSHORT typ_tail_length; -} block_sizes[] = { - 0, 0, -#include "../alice/blk.h" -0}; - -#undef BLKDEF - -static void extend_pool(PLB, SLONG); -static PLB find_pool(BLK); -static void release(FRB, PLB); - - - -//____________________________________________________________ -// -// Allocate a block from a given pool and initialize the block. -// This is the primary block allocation routine. -// - -BLK ALLA_alloc(PLB pool, UCHAR type, int count) -{ - register BLK block; - FRB free, *best, *ptr; - SLONG best_tail, tail; - USHORT units; - register SLONG size; - register USHORT *p; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; - - if (type <= (UCHAR) type_MIN || type >= (SCHAR) type_MAX) - ALICE_error(62, 0, 0, 0, 0, 0); /* msg 62: bad block type */ - -// Compute block length - - size = block_sizes[type].typ_root_length; - - if ((tail = block_sizes[type].typ_tail_length) && count >= FUDGE) - size += (count - FUDGE) * tail; - - size = (size + MIN_ALLOC - 1) & ~((ULONG) MIN_ALLOC - 1); -// TMN: Here we should probably have the following assert -// assert((size >> SHIFT) <= MAX_USHORT); - units = (USHORT) (size >> SHIFT); - - if (size >= MAX_BLOCK) - ALICE_error(63, 0, 0, 0, 0, 0); /* msg 63:internal block exceeds maximum size */ - -// Find best fit. Best fit is defined to be the free block of shortest -// tail. If there isn't a fit, extend the pool and try, try again. - - while (TRUE) { - best = NULL; - best_tail = MAX_BLOCK; - for (ptr = &pool->plb_free; (free = *ptr); ptr = &free->frb_next) { - if (free == free->frb_next) - ALICE_error(64, 0, 0, 0, 0, 0); /* msg 64: corrupt pool */ - if ((tail = (int) free->frb_header.blk_length - (int) units) >= 0 - && tail < best_tail) { - best = ptr; - best_tail = tail; - if (tail == 0) - break; - } - } - if (best) - break; - extend_pool(pool, size); - } - -// We've got our free block. If there's enough left of the free block -// after taking out our block, chop out out block. If not, allocate -// the entire free block as our block (a little extra won't hurt). - - best_tail <<= SHIFT; - free = *best; - - if (best_tail > sizeof(struct frb)) { - block = - (BLK) ((SCHAR *) free + (free->frb_header.blk_length << SHIFT)); - block = (BLK) ((SCHAR *) block - size); - free->frb_header.blk_length -= units; - } - else { - *best = free->frb_next; - units = free->frb_header.blk_length; - size = units << SHIFT; - block = (BLK) free; - } - -// zero out the allocated memory - - size >>= 1; - p = (USHORT *) block; - do - *p++ = 0; - while (--size); - - block->blk_type = type; -// TMN: Here we should probably have the following assert -// assert(pool->plb_pool_id <= MAX_UCHAR); - block->blk_pool_id = (UCHAR) pool->plb_pool_id; - block->blk_length = units; - - return block; -} - - -//____________________________________________________________ -// -// Extend a repeating block, copying the constant part. -// - -BLK ALLA_extend(BLK * pointer, int size) -{ - BLK block; - PLB pool; - SLONG old_length, new_length; - register SCHAR *from, *to; - register SSHORT length; - - block = *pointer; - pool = find_pool(block); - BLK new_ = ALLA_alloc(pool, block->blk_type, size); - - old_length = block->blk_length << SHIFT; - new_length = new_->blk_length << SHIFT; - - from = (SCHAR *) block + sizeof(struct blk); - to = (SCHAR *) new_ + sizeof(struct blk); - length = MIN(old_length, new_length) - sizeof(struct blk); - if (length) - do - *to++ = *from++; - while (--length); - - release(reinterpret_cast < frb * >(block), pool); - - if (new_->blk_type == (UCHAR) type_vec) - ((VEC) new_)->vec_count = size; - else if (new_->blk_type == (UCHAR) type_vcl) - ((VCL) new_)->vcl_count = size; - - *pointer = new_; - - return new_; -} +#include "../common/memory/allocators.h" //____________________________________________________________ @@ -200,36 +49,17 @@ BLK ALLA_extend(BLK * pointer, int size) void ALLA_fini(void) { - register PLB pool, *vector, *until; - register HNK hunks, hunk; - TGBL tdgbl; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - - if (tdgbl->pools) { - for (vector = - (PLB *) tdgbl->pools->vec_object + tdgbl->pools->vec_count, - until = (PLB *) tdgbl->pools->vec_object; --vector >= until;) - if (pool = *vector) - for (hunks = pool->plb_hunks; hunk = hunks;) { - hunks = hunk->hnk_next; - ALLA_free(hunk->hnk_address); - } + for(tgbl::pool_vec_t::iterator curr = tdgbl->pools.begin(); + curr != tdgbl->pools.end(); ++curr) + { + delete *curr; + *curr = 0; } + tdgbl->pools.clear(); - tdgbl->pools = NULL; -} - - -//____________________________________________________________ -// -// Give space back to system. -// - -void ALLA_free(SCHAR * memory) -{ - - gds__free(memory); + tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = NULL; } @@ -240,310 +70,130 @@ void ALLA_free(SCHAR * memory) void ALLA_init(void) { - SLONG temp_vector[20]; - VEC vector; - PLB pool; TGBL tdgbl; tdgbl = GET_THREAD_DATA; - tdgbl->pools = vector = (VEC) temp_vector; - vector->vec_count = 1; - vector->vec_object[0] = NULL; - - tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = pool = - ALLA_pool(); - tdgbl->pools = vector = (VEC) ALLA_alloc(pool, type_vec, 10); - vector->vec_count = 10; - vector->vec_object[0] = (BLK) pool; +#if 0 + tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = + AliceMemoryPool::create_new_pool(); +#else + tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = + new(*FB_MemoryPool) AliceMemoryPool; +#endif } -//____________________________________________________________ -// -// Get memory from system. -// -SCHAR *ALLA_malloc(SLONG size) +void AliceMemoryPool::ALLA_push(class blk *object, class lls** stack) { - register SCHAR *memory; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; - - if (memory = (SCHAR *) gds__alloc(size)) - return memory; - - ALICE_error(65, 0, 0, 0, 0, 0); /* msg 65: virtual memory exhausted */ - return (SCHAR *) 0; /* Keep compilers happy. ALICE_error() never returns. */ -} - - -//____________________________________________________________ -// -// Allocate a new pool. This is done by creating a tempory -// pool block on the stack, then allocating a real pool block. -// In USHORT, by mirrors. -// - -PLB ALLA_pool(void) -{ - struct plb temp_pool; - register VEC vector; - register PLB pool; - register int pool_id; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; - - -// Start by assigning a pool id - - vector = tdgbl->pools; - - for (pool_id = 0; pool_id < (int) vector->vec_count; pool_id++) - if (!(vector->vec_object[pool_id])) - break; - - if (pool_id >= (int) vector->vec_count) - vector = - (VEC) ALLA_extend(reinterpret_cast < blk ** >(&(tdgbl->pools)), - pool_id + 10); - - vector->vec_object[pool_id] = (BLK) & temp_pool; - temp_pool.plb_free = NULL; - temp_pool.plb_hunks = NULL; - temp_pool.plb_pool_id = pool_id; - if (pool_id == 0) - tdgbl->ALICE_permanent_pool = &temp_pool; - - pool = (PLB) ALLA_alloc(&temp_pool, type_plb, 0); - pool->plb_pool_id = pool_id; - pool->plb_free = temp_pool.plb_free; - pool->plb_hunks = temp_pool.plb_hunks; - vector->vec_object[pool_id] = (BLK) pool; - - if (pool_id == 0) - tdgbl->ALICE_permanent_pool = pool; - - return pool; -} - - -//____________________________________________________________ -// -// Push an object on an LLS stack. -// - -void ALLA_push(BLK object, register LLS * stack) -{ - register LLS node; - PLB pool; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; +/************************************** + * + * A L L _ p u s h + * + ************************************** + * + * Functional description + * Push an object on an LLS stack. + * + **************************************/ + class lls* node; + AliceMemoryPool* pool; + TGBL tdgbl = GET_THREAD_DATA; pool = tdgbl->ALICE_default_pool; - if (node = pool->plb_lls) - pool->plb_lls = node->lls_next; - else - node = (LLS) ALLA_alloc(pool, type_lls, 0); - + node = pool->lls_cache.newBlock(); node->lls_object = object; node->lls_next = *stack; *stack = node; } -//____________________________________________________________ -// -// Pop an object off a linked list stack. Save the node for -// further use. -// - -BLK ALLA_pop(register LLS * stack) +BLK AliceMemoryPool::ALLA_pop(register LLS *stack) { +/************************************** + * + * A L L _ p o p + * + ************************************** + * + * Functional description + * Pop an object off a linked list stack. Save the node for + * further use. + * + **************************************/ register LLS node; - register PLB pool; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; - + AliceMemoryPool* pool; + BLK object; node = *stack; - pool = (PLB) tdgbl->pools->vec_object[node->lls_header.blk_pool_id]; *stack = node->lls_next; - node->lls_next = pool->plb_lls; - pool->plb_lls = node; + object = node->lls_object; - return node->lls_object; + pool = (AliceMemoryPool*)MemoryPool::blk_pool(node); + pool->lls_cache.returnBlock(node); + + return object; } - -//____________________________________________________________ -// -// Release a block to its pool. If it is contiguous to -// another free block, combine them. Otherwise link it -// into the free block linked list (kept in ascending order -// of addresses). -// - -void ALLA_release(register FRB block) +#if 0 +AliceMemoryPool* AliceMemoryPool::create_new_pool(MemoryPool* parent) { +/************************************** + * + * A L L _ p o o l + * + ************************************** + * + * Functional description + * Allocate a new pool. + * + **************************************/ - release(block, find_pool(block ? &block->frb_header : (BLK) 0)); + TGBL tdgbl = GET_THREAD_DATA; + + // TMN: John, is this correct? + AliceMemoryPool* pool = new(0, parent) AliceMemoryPool(parent); + tgbl::pool_vec_t::iterator curr; + + for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) + { + if (!*curr) + { + *curr = pool; + return pool; + } + } + + tdgbl->pools.resize(tdgbl->pools.size() + 10); + for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) + { + if (!*curr) + { + *curr = pool; + return pool; + } + } + + //assert(0); + //BUGCHECK ("ALLA_fini - finishing before starting"); + return 0;//pool; // Never reached, but makes the compiler happy. } +#endif - -//____________________________________________________________ -// -// Release a storage pool. This involves nothing more than returning -// hunks to the free hunk list. -// - -void ALLA_rlpool(PLB pool) +AliceMemoryPool::~AliceMemoryPool() { - register HNK hunk, hunks; - TGBL tdgbl; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - - - tdgbl->pools->vec_object[pool->plb_pool_id] = NULL; - - for (hunks = pool->plb_hunks; hunk = hunks;) { - hunks = hunk->hnk_next; - ALLA_free(hunk->hnk_address); + tgbl::pool_vec_t::iterator curr; + for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) + { + if (*curr == this) + { + *curr = 0; + return; + } } } - -//____________________________________________________________ -// -// Allocate, extend, or no-op a vector making sure it is "long enough". -// - -VEC ALLA_vector(PLB pool, VEC * ptr, USHORT count) -{ - VEC vector; - - ++count; - - if (!(vector = *ptr)) { - vector = *ptr = (VEC) ALLA_alloc(pool, type_vec, count); - vector->vec_count = count; - return vector; - } - - if (vector->vec_count >= count) - return vector; - - return (VEC) ALLA_extend(reinterpret_cast < blk ** >(ptr), count); -} - - -//____________________________________________________________ -// -// Extend a pool by at least enough to accomodate a block -// of given size. -// - -static void extend_pool(PLB pool, SLONG size) -{ - register HNK hunk; - register BLK block; - - size = - (size + sizeof(struct hnk) + MIN_ALLOCATION - - 1) & ~((ULONG) MIN_ALLOCATION - 1); - block = (BLK) ALLA_malloc((SLONG) size); -// TMN: Here we should probably have the following assert -// assert((size >> SHIFT) <= MAX_USHORT); - block->blk_length = (USHORT) size >> SHIFT; - block->blk_type = (UCHAR) type_frb; -// TMN: Here we should probably have the following assert -// assert(pool->plb_pool_id <= MAX_UCHAR); - block->blk_pool_id = (UCHAR) pool->plb_pool_id; - release(reinterpret_cast < frb * >(block), pool); - - hunk = (HNK) ALLA_alloc(pool, type_hnk, 0); - hunk->hnk_address = (SCHAR *) block; - hunk->hnk_length = size; - hunk->hnk_next = pool->plb_hunks; - pool->plb_hunks = hunk; -} - - -//____________________________________________________________ -// -// Find pool associate with block. -// - -static PLB find_pool(BLK block) -{ - PLB pool; - HNK hunk; - USHORT pool_id; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; - - - for (pool_id = block->blk_pool_id; - pool_id < tdgbl->pools->vec_count - && (pool = (PLB) tdgbl->pools->vec_object[pool_id]); pool_id += 256) - for (hunk = pool->plb_hunks; hunk; hunk = hunk->hnk_next) - if ((SCHAR *) block >= hunk->hnk_address - && (SCHAR *) block < hunk->hnk_address + hunk->hnk_length) - return pool; - - ALICE_error(66, 0, 0, 0, 0, 0); /* msg 66: bad pool id */ - return (PLB) 0; /* Keep compilers happy. ALICE_error() never returns. */ -} - - -//____________________________________________________________ -// -// Release a block to its pool. If it is contiguous to -// another free block, combine them. Otherwise link it -// into the free block linked list (kept in ascending order -// of addresses). -// - -static void release(FRB block, PLB pool) -{ - register FRB prior, free; - FRB *ptr; - SLONG length; - - block->frb_header.blk_type = (UCHAR) type_frb; - prior = NULL; - - for (ptr = &pool->plb_free; free = *ptr; - prior = free, ptr = &free->frb_next) if (block < free) - break; - -// Merge block into list first, then try to combine blocks - - block->frb_next = free; - *ptr = block; - -// Try to merge the free block with the next one down. - - length = block->frb_header.blk_length << SHIFT; - - if (free && (SCHAR *) block + length == (SCHAR *) free) { - block->frb_header.blk_length += free->frb_header.blk_length; - block->frb_next = free->frb_next; - } - -// Try and merge the block with the prior free block - - if (prior && - (length = prior->frb_header.blk_length << SHIFT) && - (SCHAR *) prior + length == (SCHAR *) block) { - prior->frb_header.blk_length += block->frb_header.blk_length; - prior->frb_next = block->frb_next; - } -} diff --git a/src/alice/all.h b/src/alice/all.h index 1299de30e2..45732a847e 100644 --- a/src/alice/all.h +++ b/src/alice/all.h @@ -24,53 +24,35 @@ #ifndef _ALICE_ALL_H_ #define _ALICE_ALL_H_ -#if ALIGNMENT == 8 -#define MIN_ALLOC 8 -#else -#define MIN_ALLOC 4 -#endif +#include "../common/memory/memory_pool.h" +#include "../jrd/block_cache.h" +#include "../alice/lls.h" -#define MAX_BLOCK 256000 -#define FUDGE 1 -#define SHIFT 2 +void ALLA_init(); /* initialize pool system */ +void ALLA_fini(); /* get rid of everything */ -#define MIN_ALLOCATION 1024 /* Minimin allocation from operating system */ - -/* This is the header to be used by all blocks to - specify the type of block, the pool in which it has - been allocated, and the length of its tail. */ - -#ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" -#endif - -/* Free block */ - -typedef struct frb +class AliceMemoryPool : public MemoryPool { - struct blk frb_header; - struct frb *frb_next; /* Next free block in pool */ -} *FRB; +public: +// static AliceMemoryPool *create_new_pool(MemoryPool* = 0); +// AliceMemoryPool(MemoryPool* p = 0) +// : MemoryPool(0, p), +// lls_cache(*this) +// {} + AliceMemoryPool(int extSize = 0, MemoryPool* p = FB_MemoryPool) + : MemoryPool(extSize, p), + lls_cache(*this) + { + } -/* Pool block */ -typedef struct plb -{ - struct blk plb_header; - USHORT plb_pool_id; /* pool id */ - struct frb *plb_free; /* first free block */ - struct hnk *plb_hunks; /* first hunk block */ - struct lls *plb_lls; /* avaiable linked list stack nodes */ -} *PLB; + ~AliceMemoryPool(); -/* Hunk blocks */ + static class blk* ALLA_pop(class lls**); + static void ALLA_push(class blk*, class lls**); -typedef struct hnk -{ - struct blk hnk_header; - SCHAR *hnk_address; /* start of memory hunk */ - SLONG hnk_length; /* length of memory hunk */ - struct hnk *hnk_next; /* next memory hunk in structure */ -} *HNK; +private: + BlockCache lls_cache; /* Was plb_lls */ +}; -#endif /* _ALICE_ALL_H_ */ +#endif /* _ALICE_ALL_H_ */ \ No newline at end of file diff --git a/src/alice/all_proto.h b/src/alice/all_proto.h index f608f0c1ad..eacd208a23 100644 --- a/src/alice/all_proto.h +++ b/src/alice/all_proto.h @@ -21,30 +21,9 @@ * Contributor(s): ______________________________________. */ -#ifndef _ALICE_ALL_PROTO_H_ -#define _ALICE_ALL_PROTO_H_ +#ifndef ALICE_ALL_PROTO_H +#define ALICE_ALL_PROTO_H -#include "../alice/lls.h" +#include "../alice/all.h" -#ifdef __cplusplus -extern "C" { -#endif - -BLK ALLA_alloc(PLB, UCHAR, int); -BLK ALLA_extend(BLK *, int); -void ALLA_fini(void); -void ALLA_free(SCHAR *); -void ALLA_init(void); -SCHAR* ALLA_malloc(SLONG); -PLB ALLA_pool(void); -void ALLA_push(BLK, register LLS *); -BLK ALLA_pop(register LLS *); -void ALLA_release(register FRB); -void ALLA_rlpool(PLB); -VEC ALLA_vector(PLB, VEC *, USHORT); - -#ifdef __cplusplus -}; -#endif - -#endif /* _ALICE_ALL_PROTO_H_ */ +#endif /* ALICE_ALL_PROTO_H */ diff --git a/src/alice/alloc.h b/src/alice/alloc.h index ca74671a4c..8434ca230f 100644 --- a/src/alice/alloc.h +++ b/src/alice/alloc.h @@ -24,6 +24,7 @@ #ifndef _ALICE_ALLOC_H_ #define _ALICE_ALLOC_H_ +/* #define ALL_release(blk) ALLA_release (blk) #define ALLOCD(type) ALLA_alloc (tdgbl->ALICE_default_pool, type, 0) #define ALLOCDV(type,repeat) ALLA_alloc (tdgbl->ALICE_default_pool, type, repeat) @@ -31,5 +32,6 @@ #define ALLOCPV(type,repeat) ALLA_alloc (tdgbl->ALICE_permanent_pool, type, repeat) #define ALLOC(type,pool) ALLA_alloc (pool, type, 0) #define ALLOCV(type,pool,repeat) ALLA_alloc (pool, type, repeat) +*/ #endif /* _ALICE_ALLOC_H_ */ diff --git a/src/alice/blk.h b/src/alice/blk.h index 5999594c17..37d2319161 100644 --- a/src/alice/blk.h +++ b/src/alice/blk.h @@ -21,11 +21,11 @@ * Contributor(s): ______________________________________. */ -BLKDEF(type_frb, frb, 0) -BLKDEF(type_hnk, hnk, 0) -BLKDEF(type_plb, plb, 0) -BLKDEF(type_vec, vec, sizeof(((VEC) 0)->vec_object[0])) -BLKDEF(type_vcl, vcl, sizeof(((VCL) 0)->vcl_long[0])) -BLKDEF(type_tdr, tdr, 0) /* transaction description */ -BLKDEF(type_str, str, 1) /* general string block */ -BLKDEF(type_lls, lls, 0) +BLKDEF(alice_type_frb, frb, 0) +BLKDEF(alice_type_hnk, hnk, 0) +BLKDEF(alice_type_plb, plb, 0) +BLKDEF(alice_type_vec, vec, sizeof(((VEC) 0)->vec_object[0])) +BLKDEF(alice_type_vcl, vcl, sizeof(((VCL) 0)->vcl_long[0])) +BLKDEF(alice_type_tdr, tdr, 0) /* transaction description */ +BLKDEF(alice_type_str, str, 1) /* general string block */ +BLKDEF(alice_type_lls, lls, 0) diff --git a/src/alice/exe.cpp b/src/alice/exe.cpp index fa2479d572..83932cf900 100644 --- a/src/alice/exe.cpp +++ b/src/alice/exe.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: exe.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ +// $Id: exe.cpp,v 1.4 2001-12-24 02:50:47 tamlin Exp $ // // 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" // conditionals, as the engine now fully supports diff --git a/src/alice/lls.h b/src/alice/lls.h index bcb6face13..0d71ba8f61 100644 --- a/src/alice/lls.h +++ b/src/alice/lls.h @@ -21,16 +21,15 @@ * Contributor(s): ______________________________________. */ -#ifndef _ALICE_LLS_H_ -#define _ALICE_LLS_H_ +#ifndef ALICE_LLS_H +#define ALICE_LLS_H -#define LLS_PUSH(object, stack) ALL_push (object, stack) -#define LLS_POP(stack) ALL_pop (stack) +#define LLS_PUSH(object, stack) AliceMemoryPool::ALLA_push(object, stack) +#define LLS_POP(stack) AliceMemoryPool::ALLA_pop(stack) typedef struct lls { - struct blk lls_header; struct blk *lls_object; struct lls *lls_next; } *LLS; -#endif /* _ALICE_LLS_H_ */ +#endif // ALICE_LLS_H diff --git a/src/alice/tdr.cpp b/src/alice/tdr.cpp index ffc30d5eb5..cf72bd0038 100644 --- a/src/alice/tdr.cpp +++ b/src/alice/tdr.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: tdr.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ +// $Id: tdr.cpp,v 1.4 2001-12-24 02:50:47 tamlin Exp $ // #include "firebird.h" @@ -923,15 +923,15 @@ static void reattach_database(TDR trans) p = buffer; while (*p == ' ') *p++; - if (TDR_attach_database - (status_vector, trans, reinterpret_cast < char *>(p))) { - string = - (STR) ALLOCDV(type_str, - strlen(reinterpret_cast < - const char *>(p)) + 1); - strcpy(reinterpret_cast < char *>(string->str_data), - reinterpret_cast < const char *>(p)); - string->str_length = strlen(reinterpret_cast < const char *>(p)); + if (TDR_attach_database(status_vector, + trans, + reinterpret_cast(p))) + { + string = new(*tdgbl->ALICE_default_pool, + strlen(reinterpret_cast(p)) + 1) str; + strcpy(reinterpret_cast(string->str_data), + reinterpret_cast(p)); + string->str_length = strlen(reinterpret_cast(p)); trans->tdr_fullpath = string; trans->tdr_filename = (TEXT *) string->str_data; return; diff --git a/src/burp/backup.epp b/src/burp/backup.epp index 220de6233b..e4d6ceaa86 100644 --- a/src/burp/backup.epp +++ b/src/burp/backup.epp @@ -22,7 +22,7 @@ * Toni Martir: Added verbose backup records as BACKUP_VERBOSE_INTERVAL */ /* -$Id: backup.epp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +$Id: backup.epp,v 1.3 2001-12-24 02:50:47 tamlin Exp $ */ #include "firebird.h" @@ -33,6 +33,7 @@ $Id: backup.epp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ #include "../jrd/ods.h" #include "../jrd/align.h" #include "../jrd/gdsassert.h" +#include "../jrd/thd_proto.h" #include "../burp/backu_proto.h" #include "../burp/burp_proto.h" #include "../burp/canon_proto.h" diff --git a/src/burp/burp.cpp b/src/burp/burp.cpp index 8ec0b96b7d..554acfc284 100644 --- a/src/burp/burp.cpp +++ b/src/burp/burp.cpp @@ -134,9 +134,6 @@ struct tgbl *gdgbl; #endif -extern "C" { - - #define OUTPUT_SUPPRESS "SUPPRESS" #define BURP_MSG_FAC 12 @@ -439,6 +436,8 @@ static int output_svc( SLONG output_data, UCHAR * output_buf) return 0; } +extern "C" { + int DLL_EXPORT BURP_gbak(int argc, char* argv[], OUTPUTPROC output_proc, @@ -503,67 +502,12 @@ int DLL_EXPORT BURP_gbak(int argc, tdgbl->output_data = output_data; /* Initialize static data. */ - for (in_sw_tab = burp_in_sw_table; in_sw_tab->in_sw_name; in_sw_tab++) + for (in_sw_tab = burp_in_sw_table; in_sw_tab->in_sw_name; in_sw_tab++) { in_sw_tab->in_sw_state = FALSE; - - if (SETJMP(env)) { - int exit_code; - UCHAR *mem; - - /* All calls to EXIT(), normal and error exits, wind up here */ - - tdgbl->burp_env = NULL; - exit_code = tdgbl->exit_code; - - /* Close the gbak file handles if they still open */ - for (file = tdgbl->gbl_sw_backup_files; file; file = file->fil_next) { - if (file->fil_fd != INVALID_HANDLE_VALUE) - CLOSE(file->fil_fd); - if (exit_code != 0 - && (tdgbl->action->act_action == ACT_backup_split - || tdgbl->action->act_action == ACT_backup)) - UNLINK(file->fil_name); - } - - /* Detach from database to release system resources */ - if (tdgbl->db_handle != 0) { - close_out_transaction(action, - const_cast(&tdgbl->tr_handle)); - close_out_transaction(action, - const_cast(&tdgbl->global_trans)); - if (isc_detach_database(const_cast(tdgbl->status_vector), - const_cast(&tdgbl->db_handle))) - { - BURP_print_status(const_cast(tdgbl->status_vector)); - } - } - - /* Close the status output file */ - if (tdgbl->sw_redirect == TRUE && tdgbl->output_file != NULL) { - ib_fclose(tdgbl->output_file); - tdgbl->output_file = NULL; - } - - /* Free all unfreed memory used by Gbak itself */ - while (tdgbl->head_of_mem_list != NULL) { - mem = tdgbl->head_of_mem_list; - tdgbl->head_of_mem_list = *((UCHAR **) tdgbl->head_of_mem_list); - gds__free(mem); - } - - RESTORE_THREAD_DATA; - if (tdgbl != NULL) { - gds__free((SLONG *) tdgbl); - } - -#if defined(DEBUG_GDS_ALLOC) && !defined(SUPERSERVER) - gds_alloc_report(0, __FILE__, __LINE__); -#endif - - /* All returns occur from this point - even normal returns */ - return exit_code; } + try { + #ifdef VMS argc = VMS_parse(&argv, argc); #endif @@ -1101,9 +1045,70 @@ int DLL_EXPORT BURP_gbak(int argc, EXIT(result); return result; + } // try + + catch (...) + { + int exit_code; + UCHAR *mem; + + /* All calls to EXIT(), normal and error exits, wind up here */ + + tdgbl->burp_env = NULL; + exit_code = tdgbl->exit_code; + + /* Close the gbak file handles if they still open */ + for (file = tdgbl->gbl_sw_backup_files; file; file = file->fil_next) { + if (file->fil_fd != INVALID_HANDLE_VALUE) + CLOSE(file->fil_fd); + if (exit_code != 0 + && (tdgbl->action->act_action == ACT_backup_split + || tdgbl->action->act_action == ACT_backup)) + UNLINK(file->fil_name); + } + + /* Detach from database to release system resources */ + if (tdgbl->db_handle != 0) { + close_out_transaction(action, + const_cast(&tdgbl->tr_handle)); + close_out_transaction(action, + const_cast(&tdgbl->global_trans)); + if (isc_detach_database(const_cast(tdgbl->status_vector), + const_cast(&tdgbl->db_handle))) + { + BURP_print_status(const_cast(tdgbl->status_vector)); + } + } + + /* Close the status output file */ + if (tdgbl->sw_redirect == TRUE && tdgbl->output_file != NULL) { + ib_fclose(tdgbl->output_file); + tdgbl->output_file = NULL; + } + + /* Free all unfreed memory used by Gbak itself */ + while (tdgbl->head_of_mem_list != NULL) { + mem = tdgbl->head_of_mem_list; + tdgbl->head_of_mem_list = *((UCHAR **) tdgbl->head_of_mem_list); + gds__free(mem); + } + + RESTORE_THREAD_DATA; + if (tdgbl != NULL) { + gds__free((SLONG *) tdgbl); + } + +#if defined(DEBUG_GDS_ALLOC) && !defined(SUPERSERVER) + gds_alloc_report(0, __FILE__, __LINE__); +#endif + + /* All returns occur from this point - even normal returns */ + return exit_code; + } } + void BURP_abort(void) { /************************************** @@ -1440,6 +1445,8 @@ void BURP_verbose(USHORT number, burp_output(""); } +} // extern "C" + static void close_out_transaction(VOLATILE SSHORT action, isc_tr_handle* handle) @@ -2256,5 +2263,3 @@ static int api_gbak(int argc, #endif // !SUPERSERVER - -} // extern "C" diff --git a/src/burp/burp.h b/src/burp/burp.h index 92cbdb4ade..61c2c1e8eb 100644 --- a/src/burp/burp.h +++ b/src/burp/burp.h @@ -603,6 +603,10 @@ typedef struct gfld { #define MAX_FILE_NAME_LENGTH 256 +#ifdef __cplusplus +} /* extern "C" */ +#endif + /* Note that this typedef is also defined in JRD.H and REMOTE.H */ /* but for some reason we are avoiding including JRD.H */ /* and this typedef is needed to include SVC.H */ @@ -613,10 +617,6 @@ typedef struct gfld { #endif -#ifdef __cplusplus -} /* extern "C" */ -#endif - #include "../jrd/svc.h" #include "../jrd/svc_proto.h" @@ -865,11 +865,11 @@ extern struct tgbl *gdgbl; // I had funnies with this cast #define EXIT(code) { tdgbl->exit_code = ((volatile int)code); \ if (tdgbl->burp_env != NULL) \ - LONGJMP((jmp_buf)(const_cast(tdgbl->burp_env)), 1); } + Firebird::status_longjmp_error::raise(1); } #else -#define EXIT(code) { tdgbl->exit_code = ((volatile int)code); \ - if (tdgbl->burp_env != NULL) \ - LONGJMP(tdgbl->burp_env, 1); } + +#error Dont do this, it hurts! + #endif /* __cplusplus */ #define FINI_DB_NOT_ONLINE 2 /* database is not on-line due to diff --git a/src/burp/canonical.cpp b/src/burp/canonical.cpp index 1b307cbe7c..79f95c3186 100644 --- a/src/burp/canonical.cpp +++ b/src/burp/canonical.cpp @@ -21,13 +21,12 @@ * Contributor(s): ______________________________________. */ /* -$Id: canonical.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +$Id: canonical.cpp,v 1.3 2001-12-24 02:50:48 tamlin Exp $ */ #include "firebird.h" #include "../jrd/ib_stdio.h" #include -#include "../remote/remote.h" #include "../burp/burp.h" #include "../jrd/align.h" #include "../jrd/sdl.h" @@ -35,6 +34,16 @@ $Id: canonical.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ #include "../jrd/sdl_proto.h" #include "../remote/xdr_proto.h" #include "../jrd/gdsassert.h" +#include "../include/fb_types.h" + +// TMN: Currently we can't include remote/remote.h because we'd get +// conflicting blk_t definitions (we are gonna fix this, in due time). +// Because this file needs the remote definition of VARY, which +// coincidentally is different from _all_ other modules in the code, +// we have to make the type definition here. + +typedef vary* VARY; + #ifdef PC_PLATFORM #ifndef NETWARE_386 diff --git a/src/burp/restore.epp b/src/burp/restore.epp index 45500915ab..fef38b6f5e 100644 --- a/src/burp/restore.epp +++ b/src/burp/restore.epp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Backup and Restore Program - * MODULE: restore.e + * MODULE: restore.epp * DESCRIPTION: Restore routine * * The contents of this file are subject to the Interbase Public @@ -21,9 +21,10 @@ * Contributor(s): ______________________________________. * Toni Martir: Verbose records restored as RESTORE_VERBOSE_INTERVAL, * also verbose restoring indexes as DEFERRED when verbose + * */ /* -$Id: restore.epp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +$Id: restore.epp,v 1.3 2001-12-24 02:50:48 tamlin Exp $ */ #include "firebird.h" @@ -37,6 +38,7 @@ $Id: restore.epp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ #include "../jrd/license.h" #include "../jrd/obj.h" #include "../jrd/ods.h" +#include "../jrd/thd_proto.h" #include "../burp/burp_proto.h" #include "../burp/canon_proto.h" #include "../burp/misc_proto.h" @@ -44,18 +46,6 @@ $Id: restore.epp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ #include "../burp/resto_proto.h" #include "../intl/charsets.h" #include "../jrd/gdsassert.h" - -/* this typedef is required to avoid compilation warnings in - * protocol.h. - * - * REMOVED 6/26 JMB. Not needed anymore with C++ - * -typedef struct bid { - ULONG bid_relation_id; // Relation id (or null) - ULONG bid_number; // Record number -} *BID; -*/ - #include "../remote/protocol.h" /* For netware the follow DB handle is #defined to be a value stored */ @@ -73,7 +63,7 @@ DATABASE #define DEBUG 1 ***/ -#define STUFF(byte) {*blr++ = (UCHAR) (byte);} +#define STUFF(byte) {*blr++ = (UCHAR) (byte);} #define STUFF_WORD(word) {STUFF (word); STUFF ((word) >> 8);} #define STUFF_LONG(lword) {STUFF_WORD (lword); STUFF_WORD ((lword) >> 16);} #define STUFF_INT64(i64) {STUFF_LONG (i64); STUFF_LONG ((i64) >> 32);} @@ -82,15 +72,15 @@ DATABASE #define DB_VERSION_DDL5 5 /* ods5 db */ #define DB_VERSION_DDL8 8 /* ods8 db */ #define DB_VERSION_CURRENT DB_VERSION_DDL8 /* v4.0 is ods8 */ -#define FOREIGN_KEY "FOREIGN KEY" +#define FOREIGN_KEY "FOREIGN KEY" -#define DEFERRED_ACTIVE 3 /* RDB$INDEX_INACTIVE setting for Foreign Keys +#define DEFERRED_ACTIVE 3 /* RDB$INDEX_INACTIVE setting for Foreign Keys * This setting is used temporarily while * restoring a database. This was required * in order to differentiate a partial * "inactive" state of SOME indices from * "inactive" state of ALL indices (gbak -i) - * -bsriram, 11-May-1999 BUG: 10016 + * -bsriram, 11-May-1999 BUG: 10016 */ #define RESTORE_VERBOSE_INTERVAL 10000 @@ -206,6 +196,7 @@ static CONST SSHORT old_sparcs[] = #define GET_BLOCK(p,n) MVOL_read_block (tdgbl, (p), (n)) #define GET_ATTRIBUTE(att) ((att) = (ATT_TYPE) GET()) #define GET_RECORD(att) ((att) = (REC_TYPE) GET()) +#define GET_TEXT(text) get_text((text), sizeof(text)) /* When skipping started, scan_next_attr will be changed from NO_SKIP */ /* to BEFORE_SKIP. When scanning for next valid attribute after skipping, */ @@ -257,7 +248,7 @@ long db_handle; UCHAR dpb[128], *d, *q; SSHORT l; isc_req_handle req_handle3 = NULL; -TEXT index_name[32]; +BASED_ON RDB$INDICES.RDB$INDEX_NAME index_name; long error_code; tdgbl = GET_THREAD_DATA; @@ -1254,8 +1245,9 @@ while ((item = *p++) != gds_info_end) ** in one big segment ** */ - if (num_segments > 1) + if (num_segments > 1) { assert (num_segments > 1); + } break; default: @@ -2103,13 +2095,13 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_character_sets_req_handle1) case att_charset_name: X.RDB$CHARACTER_SET_NAME.NULL = FALSE; - get_text (X.RDB$CHARACTER_SET_NAME, sizeof (X.RDB$CHARACTER_SET_NAME)); + GET_TEXT(X.RDB$CHARACTER_SET_NAME); BURP_verbose (msgVerbose_restore_charset, X.RDB$CHARACTER_SET_NAME, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); break; case att_charset_form: X.RDB$FORM_OF_USE.NULL = FALSE; - get_text (X.RDB$FORM_OF_USE, sizeof (X.RDB$FORM_OF_USE)); + GET_TEXT(X.RDB$FORM_OF_USE); break; case att_charset_numchar: @@ -2119,7 +2111,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_character_sets_req_handle1) case att_charset_coll: X.RDB$DEFAULT_COLLATE_NAME.NULL = FALSE; - get_text (X.RDB$DEFAULT_COLLATE_NAME, sizeof (X.RDB$DEFAULT_COLLATE_NAME)); + GET_TEXT(X.RDB$DEFAULT_COLLATE_NAME); break; case att_charset_id: @@ -2139,7 +2131,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_character_sets_req_handle1) case att_charset_funct: X.RDB$FUNCTION_NAME.NULL = FALSE; - get_text (X.RDB$FUNCTION_NAME, sizeof (X.RDB$FUNCTION_NAME)); + GET_TEXT(X.RDB$FUNCTION_NAME); break; case att_charset_bytes_char: @@ -2188,12 +2180,12 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_chk_constraint_req_handle1) { case att_chk_constraint_name: X.RDB$CONSTRAINT_NAME.NULL = FALSE; - get_text (X.RDB$CONSTRAINT_NAME, sizeof (X.RDB$CONSTRAINT_NAME)); + GET_TEXT(X.RDB$CONSTRAINT_NAME); break; case att_chk_trigger_name: X.RDB$TRIGGER_NAME.NULL = FALSE; - get_text (X.RDB$TRIGGER_NAME, sizeof (X.RDB$TRIGGER_NAME)); + GET_TEXT(X.RDB$TRIGGER_NAME); break; default: @@ -2244,7 +2236,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_collation_req_handle1) case att_coll_name: X.RDB$COLLATION_NAME.NULL = FALSE; - get_text (X.RDB$COLLATION_NAME, sizeof (X.RDB$COLLATION_NAME)); + GET_TEXT(X.RDB$COLLATION_NAME); BURP_verbose (msgVerbose_restore_collation, X.RDB$COLLATION_NAME, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); break; @@ -2281,7 +2273,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_collation_req_handle1) case att_coll_funct: X.RDB$FUNCTION_NAME.NULL = FALSE; - get_text (X.RDB$FUNCTION_NAME, sizeof (X.RDB$FUNCTION_NAME)); + GET_TEXT(X.RDB$FUNCTION_NAME); break; default: @@ -2325,7 +2317,7 @@ SLONG *blob_id; REC_TYPE record; TGBL tdgbl; isc_req_handle req_handle = NULL; -TEXT index_name[32]; +BASED_ON RDB$INDICES.RDB$INDEX_NAME index_name; long error_code; tdgbl = GET_THREAD_DATA; @@ -2421,7 +2413,7 @@ for (field = relation->rel_fields; field; field = field->fld_next) default: #ifdef SUPERSERVER - BURP_svc_error (26, isc_arg_number, field->fld_type, + BURP_svc_error (26, isc_arg_number, (void*)field->fld_type, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (26, (void*) field->fld_type, 0, 0, 0, 0); @@ -2533,8 +2525,9 @@ while (TRUE) old_length = recompute_length (relation); if (l != old_length) #ifdef SUPERSERVER - BURP_svc_error (40, isc_arg_number, length, isc_arg_number, l, - 0, NULL, 0, NULL, 0, NULL); + BURP_svc_error(40, isc_arg_number, (void*)length, + isc_arg_number, (void*)l, + 0, NULL, 0, NULL, 0, NULL); #else BURP_error (40, (void*) length, (void*) l, 0, 0, 0); /* msg 40 wrong length record, expected %ld encountered %ld */ @@ -2742,7 +2735,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_exception_req_handle1) switch (attribute) { case att_exception_name: - l = get_text (X.RDB$EXCEPTION_NAME, sizeof (X.RDB$EXCEPTION_NAME)); + l = GET_TEXT(X.RDB$EXCEPTION_NAME); MISC_terminate ((UCHAR*) X.RDB$EXCEPTION_NAME, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (199, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 199 restoring exception %s */ @@ -2759,7 +2752,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_exception_req_handle1) break; case att_exception_msg: - get_text (X.RDB$MESSAGE, sizeof (X.RDB$MESSAGE)); + GET_TEXT(X.RDB$MESSAGE); X.RDB$MESSAGE.NULL = FALSE; break; @@ -2939,23 +2932,23 @@ STORE (TRANSACTION_HANDLE local_trans { case att_field_name: field->fld_name_length = - get_text (field->fld_name, sizeof (field->fld_name)); + GET_TEXT(field->fld_name); BURP_verbose (115, field->fld_name, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 115 restoring field %s */ strcpy (X.RDB$FIELD_NAME, field->fld_name); break; case att_field_source: - get_text (X.RDB$FIELD_SOURCE, sizeof (X.RDB$FIELD_SOURCE)); + GET_TEXT(X.RDB$FIELD_SOURCE); break; case att_field_security_class: - get_text (X.RDB$SECURITY_CLASS, sizeof (X.RDB$SECURITY_CLASS)); + GET_TEXT(X.RDB$SECURITY_CLASS); X.RDB$SECURITY_CLASS.NULL = FALSE; break; case att_field_query_name: - get_text (X.RDB$QUERY_NAME, sizeof (X.RDB$QUERY_NAME)); + GET_TEXT(X.RDB$QUERY_NAME); X.RDB$QUERY_NAME.NULL = FALSE; break; @@ -2965,7 +2958,7 @@ STORE (TRANSACTION_HANDLE local_trans break; case att_field_edit_string: - get_text (X.RDB$EDIT_STRING, sizeof (X.RDB$EDIT_STRING)); + GET_TEXT(X.RDB$EDIT_STRING); X.RDB$EDIT_STRING.NULL = FALSE; break; @@ -3010,7 +3003,7 @@ STORE (TRANSACTION_HANDLE local_trans break; case att_base_field: - get_text (X.RDB$BASE_FIELD, sizeof (X.RDB$BASE_FIELD)); + GET_TEXT(X.RDB$BASE_FIELD); X.RDB$BASE_FIELD.NULL = FALSE; break; @@ -3025,7 +3018,7 @@ STORE (TRANSACTION_HANDLE local_trans break; case att_field_complex_name: - get_text (X.RDB$COMPLEX_NAME, sizeof (X.RDB$COMPLEX_NAME)); + GET_TEXT(X.RDB$COMPLEX_NAME); X.RDB$COMPLEX_NAME.NULL = FALSE; break; @@ -3140,7 +3133,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_field_dimensions_req_handle1) switch (attribute) { case att_field_name: - get_text (X.RDB$FIELD_NAME, sizeof (X.RDB$FIELD_NAME)); + GET_TEXT(X.RDB$FIELD_NAME); break; case att_field_dimensions: @@ -3196,7 +3189,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_files_req_handle1) switch (attribute) { case att_file_filename: - get_text (X.RDB$FILE_NAME, sizeof (X.RDB$FILE_NAME)); + GET_TEXT(X.RDB$FILE_NAME); BURP_verbose (116, /* msg 116 restoring file %s */ X.RDB$FILE_NAME, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); @@ -3264,7 +3257,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_filter_req_handle1) switch (attribute) { case att_filter_name: - get_text (X.RDB$FUNCTION_NAME, sizeof (X.RDB$FUNCTION_NAME)); + GET_TEXT(X.RDB$FUNCTION_NAME); BURP_verbose (117, X.RDB$FUNCTION_NAME, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 117 restoring filter %s */ break; @@ -3280,11 +3273,11 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_filter_req_handle1) break; case att_filter_module_name: - get_text (X.RDB$MODULE_NAME, sizeof (X.RDB$MODULE_NAME)); + GET_TEXT(X.RDB$MODULE_NAME); break; case att_filter_entrypoint: - get_text (X.RDB$ENTRYPOINT, sizeof (X.RDB$ENTRYPOINT)); + GET_TEXT(X.RDB$ENTRYPOINT); break; case att_filter_input_sub_type: @@ -3337,7 +3330,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_function_req_handle1) switch (attribute) { case att_function_name: - l = get_text (X.RDB$FUNCTION_NAME, sizeof (X.RDB$FUNCTION_NAME)); + l = GET_TEXT(X.RDB$FUNCTION_NAME); MISC_terminate ((UCHAR*) X.RDB$FUNCTION_NAME, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (118, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 118 restoring function %s */ @@ -3352,11 +3345,11 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_function_req_handle1) break; case att_function_module_name: - get_text (X.RDB$MODULE_NAME, sizeof (X.RDB$MODULE_NAME)); + GET_TEXT(X.RDB$MODULE_NAME); break; case att_function_entrypoint: - get_text (X.RDB$ENTRYPOINT, sizeof (X.RDB$ENTRYPOINT)); + GET_TEXT(X.RDB$ENTRYPOINT); break; case att_function_return_arg: @@ -3364,7 +3357,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_function_req_handle1) break; case att_function_query_name: - get_text (X.RDB$QUERY_NAME, sizeof (X.RDB$QUERY_NAME)); + GET_TEXT(X.RDB$QUERY_NAME); break; case att_function_type: @@ -3424,7 +3417,7 @@ if (tdgbl->RESTORE_format >= 6) switch (attribute) { case att_functionarg_name: - l = get_text (X.RDB$FUNCTION_NAME, sizeof (X.RDB$FUNCTION_NAME)); + l = GET_TEXT(X.RDB$FUNCTION_NAME); MISC_terminate ((UCHAR*) X.RDB$FUNCTION_NAME, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (119, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 119 restoring argument for function %s */ @@ -3488,7 +3481,7 @@ else switch (attribute) { case att_functionarg_name: - l = get_text (X.RDB$FUNCTION_NAME, sizeof (X.RDB$FUNCTION_NAME)); + l = GET_TEXT(X.RDB$FUNCTION_NAME); MISC_terminate ((UCHAR*) X.RDB$FUNCTION_NAME, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (119, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 119 restoring argument for function %s */ @@ -3552,7 +3545,7 @@ static BOOLEAN get_generator (void) * **************************************/ SINT64 value; -TEXT name [32]; +BASED_ON RDB$GENERATORS.RDB$GENERATOR_NAME name; ATT_TYPE attribute; UCHAR scan_next_attr; TGBL tdgbl; @@ -3564,7 +3557,7 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) switch (attribute) { case att_gen_generator: - get_text (name, sizeof (name)); + GET_TEXT(name); break; case att_gen_value: @@ -3652,19 +3645,19 @@ if (tdgbl->RESTORE_format >= 6) switch (attribute) { case att_field_name: - l = get_text (X.RDB$FIELD_NAME, sizeof (X.RDB$FIELD_NAME)); + l = GET_TEXT(X.RDB$FIELD_NAME); MISC_terminate ((UCHAR*) X.RDB$FIELD_NAME, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (121, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 121 restoring global field %s */ break; case att_field_query_name: - get_text (X.RDB$QUERY_NAME, sizeof (X.RDB$QUERY_NAME)); + GET_TEXT(X.RDB$QUERY_NAME); X.RDB$QUERY_NAME.NULL = FALSE; break; case att_field_edit_string: - get_text (X.RDB$EDIT_STRING, sizeof (X.RDB$EDIT_STRING)); + GET_TEXT(X.RDB$EDIT_STRING); X.RDB$EDIT_STRING.NULL = FALSE; break; @@ -3963,19 +3956,19 @@ else /* RESTORE_format < 6 */ switch (attribute) { case att_field_name: - l = get_text (X.RDB$FIELD_NAME, sizeof (X.RDB$FIELD_NAME)); + l = GET_TEXT(X.RDB$FIELD_NAME); MISC_terminate ((UCHAR*) X.RDB$FIELD_NAME, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (121, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 121 restoring global field %s */ break; case att_field_query_name: - get_text (X.RDB$QUERY_NAME, sizeof (X.RDB$QUERY_NAME)); + GET_TEXT(X.RDB$QUERY_NAME); X.RDB$QUERY_NAME.NULL = FALSE; break; case att_field_edit_string: - get_text (X.RDB$EDIT_STRING, sizeof (X.RDB$EDIT_STRING)); + GET_TEXT(X.RDB$EDIT_STRING); X.RDB$EDIT_STRING.NULL = FALSE; break; @@ -4255,7 +4248,7 @@ static BOOLEAN get_index ( * **************************************/ SSHORT count, segments; -TEXT index_name [32]; +BASED_ON RDB$INDICES.RDB$INDEX_NAME index_name; ATT_TYPE attribute; BOOLEAN foreign_index = FALSE; UCHAR scan_next_attr; @@ -4283,7 +4276,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_index_req_handle1) switch (attribute) { case att_index_name: - (void) get_text (X.RDB$INDEX_NAME, sizeof (X.RDB$INDEX_NAME)); + GET_TEXT(X.RDB$INDEX_NAME); strcpy (index_name, X.RDB$INDEX_NAME); BURP_verbose (122, X.RDB$INDEX_NAME, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); break; @@ -4322,7 +4315,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_index_req_handle1) case att_index_field_name: STORE (REQUEST_HANDLE tdgbl->handles_get_index_req_handle2) Y IN RDB$INDEX_SEGMENTS - get_text (Y.RDB$FIELD_NAME, sizeof (Y.RDB$FIELD_NAME)); + GET_TEXT(Y.RDB$FIELD_NAME); strcpy (Y.RDB$INDEX_NAME, X.RDB$INDEX_NAME); Y.RDB$FIELD_POSITION = count++; END_STORE; @@ -4370,7 +4363,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_index_req_handle1) if (tdgbl->gbl_sw_deactivate_indexes) X.RDB$INDEX_INACTIVE = TRUE; X.RDB$FOREIGN_KEY.NULL = FALSE; - get_text (X.RDB$FOREIGN_KEY, sizeof (X.RDB$FOREIGN_KEY)); + GET_TEXT(X.RDB$FOREIGN_KEY); } break; @@ -4502,12 +4495,15 @@ static SLONG get_numeric (void) * Get a numeric value from the input stream. * **************************************/ -SLONG value [2]; -SSHORT length; + SLONG value[2]; -length = get_text ((TEXT *) value, sizeof (value)); + // get_text needs additional space for the terminator, + // because it treats everything as strings. + assert(sizeof(value) > sizeof(SLONG)); -return isc_vax_integer ((SCHAR *) value, length); + SSHORT length = get_text((TEXT*) value, sizeof (value)); + + return isc_vax_integer ((SCHAR *) value, length); } static SINT64 get_int64 (void) @@ -4522,12 +4518,15 @@ static SINT64 get_int64 (void) * Get a possibly-64-bit numeric value from the input stream. * **************************************/ -SLONG value [4]; -SSHORT length; + SLONG value [4]; -length = get_text ((TEXT *) value, sizeof (value)); + // get_text needs additional space for the terminator, + // because it treats everything as strings. + assert (sizeof(value) > sizeof(SINT64)); -return isc_portable_integer ((UCHAR *) value, length); + SSHORT length = get_text ((TEXT *) value, sizeof (value)); + + return isc_portable_integer ((UCHAR *) value, length); } static BOOLEAN get_procedure (void) @@ -4574,7 +4573,7 @@ STORE (TRANSACTION_HANDLE local_trans switch (attribute) { case att_procedure_name: - l = get_text (X.RDB$PROCEDURE_NAME, sizeof (X.RDB$PROCEDURE_NAME)); + l = GET_TEXT(X.RDB$PROCEDURE_NAME); procedure->prc_name_length = l; strcpy (procedure->prc_name, X.RDB$PROCEDURE_NAME); MISC_terminate ((UCHAR*) X.RDB$PROCEDURE_NAME, (UCHAR*) temp, l, sizeof (temp)); @@ -4607,12 +4606,12 @@ STORE (TRANSACTION_HANDLE local_trans break; case att_procedure_security_class: - get_text (X.RDB$SECURITY_CLASS, sizeof (X.RDB$SECURITY_CLASS)); + GET_TEXT(X.RDB$SECURITY_CLASS); X.RDB$SECURITY_CLASS.NULL = FALSE; break; case att_procedure_owner_name: - get_text (procedure->prc_owner, sizeof (procedure->prc_owner)); + GET_TEXT(procedure->prc_owner); break; case att_procedure_inputs: @@ -4683,7 +4682,7 @@ STORE (TRANSACTION_HANDLE local_trans switch (attribute) { case att_procedureprm_name: - l = get_text (X.RDB$PARAMETER_NAME, sizeof (X.RDB$PARAMETER_NAME)); + l = GET_TEXT(X.RDB$PARAMETER_NAME); MISC_terminate ((UCHAR*) X.RDB$PARAMETER_NAME, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (196, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 196 restoring parameter %s for stored procedure */ @@ -4698,7 +4697,7 @@ STORE (TRANSACTION_HANDLE local_trans break; case att_procedureprm_field_source: - get_text (X.RDB$FIELD_SOURCE, sizeof (X.RDB$FIELD_SOURCE)); + GET_TEXT(X.RDB$FIELD_SOURCE); break; case att_procedureprm_description: @@ -4755,27 +4754,27 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_ref_constraint_req_handle1) { case att_ref_constraint_name: X.RDB$CONSTRAINT_NAME.NULL = FALSE; - get_text (X.RDB$CONSTRAINT_NAME, sizeof (X.RDB$CONSTRAINT_NAME)); + GET_TEXT(X.RDB$CONSTRAINT_NAME); break; case att_ref_unique_const_name: X.RDB$CONST_NAME_UQ.NULL = FALSE; - get_text (X.RDB$CONST_NAME_UQ, sizeof (X.RDB$CONST_NAME_UQ)); + GET_TEXT(X.RDB$CONST_NAME_UQ); break; case att_ref_match_option: X.RDB$MATCH_OPTION.NULL = FALSE; - get_text (X.RDB$MATCH_OPTION, sizeof (X.RDB$MATCH_OPTION)); + GET_TEXT(X.RDB$MATCH_OPTION); break; case att_ref_update_rule: X.RDB$UPDATE_RULE.NULL = FALSE; - get_text (X.RDB$UPDATE_RULE, sizeof (X.RDB$UPDATE_RULE)); + GET_TEXT(X.RDB$UPDATE_RULE); break; case att_ref_delete_rule: X.RDB$DELETE_RULE.NULL = FALSE; - get_text (X.RDB$DELETE_RULE, sizeof (X.RDB$DELETE_RULE)); + GET_TEXT(X.RDB$DELETE_RULE); break; default: @@ -4823,9 +4822,11 @@ SLONG rel_flags, sys_flag; short rel_flags_null, sys_flag_null; GDS_QUAD view_blr, view_src, rel_desc, ext_desc; USHORT view_blr_null, view_src_null, rel_desc_null, ext_desc_null; -char sec_class[32]; + +BASED_ON RDB$RELATIONS.RDB$SECURITY_CLASS sec_class; short sec_class_null; -TEXT ext_file_name [253]; + +BASED_ON RDB$RELATIONS.RDB$EXTERNAL_FILE ext_file_name; short ext_file_name_null; isc_tr_handle local_trans; @@ -4872,7 +4873,7 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) switch (attribute) { case att_relation_name: - l = get_text (relation->rel_name, 31); + l = GET_TEXT(relation->rel_name); relation->rel_name_length = l; MISC_terminate ((UCHAR*) relation->rel_name, (UCHAR*) temp, l, sizeof (temp)); BURP_verbose (167, temp, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); @@ -4881,7 +4882,7 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) case att_relation_security_class: sec_class_null = FALSE; - get_text (sec_class, sizeof (sec_class)); + GET_TEXT(sec_class); break; case att_relation_view_blr: @@ -4932,12 +4933,12 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) break; case att_relation_owner_name: - get_text (relation->rel_owner, sizeof (relation->rel_owner)); + GET_TEXT(relation->rel_owner); break; case att_relation_ext_file_name: ext_file_name_null = FALSE; - get_text (ext_file_name, sizeof (ext_file_name)); + GET_TEXT(ext_file_name); break; default: @@ -5024,7 +5025,7 @@ while (GET_RECORD (record) != rec_data) default: #ifdef SUPERSERVER - BURP_svc_error (43, isc_arg_number, (void *) record, + BURP_svc_error (43, isc_arg_number, (void*) record, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (43, (void*) record, 0, 0, 0, 0); @@ -5087,32 +5088,32 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_rel_constraint_req_handle1) { case att_rel_constraint_name: X.RDB$CONSTRAINT_NAME.NULL = FALSE; - get_text (X.RDB$CONSTRAINT_NAME, sizeof (X.RDB$CONSTRAINT_NAME)); + GET_TEXT(X.RDB$CONSTRAINT_NAME); break; case att_rel_constraint_type: X.RDB$CONSTRAINT_TYPE.NULL = FALSE; - get_text (X.RDB$CONSTRAINT_TYPE, sizeof (X.RDB$CONSTRAINT_TYPE)); + GET_TEXT(X.RDB$CONSTRAINT_TYPE); break; case att_rel_constraint_rel_name: X.RDB$RELATION_NAME.NULL = FALSE; - get_text (X.RDB$RELATION_NAME, sizeof (X.RDB$RELATION_NAME)); + GET_TEXT(X.RDB$RELATION_NAME); break; case att_rel_constraint_defer: X.RDB$DEFERRABLE.NULL = FALSE; - get_text (X.RDB$DEFERRABLE, sizeof (X.RDB$DEFERRABLE)); + GET_TEXT(X.RDB$DEFERRABLE); break; case att_rel_constraint_init: X.RDB$INITIALLY_DEFERRED.NULL = FALSE; - get_text (X.RDB$INITIALLY_DEFERRED, sizeof (X.RDB$INITIALLY_DEFERRED)); + GET_TEXT(X.RDB$INITIALLY_DEFERRED); break; case att_rel_constraint_index: X.RDB$INDEX_NAME.NULL = FALSE; - get_text (X.RDB$INDEX_NAME, sizeof (X.RDB$INDEX_NAME)); + GET_TEXT(X.RDB$INDEX_NAME); break; default: @@ -5143,7 +5144,7 @@ static BOOLEAN get_relation_data (void) * **************************************/ REL relation; -TEXT name [32]; +BASED_ON RDB$RELATIONS.RDB$RELATION_NAME name; SLONG gen_id; ATT_TYPE attribute; REC_TYPE record; @@ -5159,7 +5160,7 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) switch (attribute) { case att_relation_name: - get_text (name, sizeof (name)); + GET_TEXT(name); relation = find_relation (name); break; @@ -5245,7 +5246,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_sql_roles_req_handle1) { case att_role_name: X.RDB$ROLE_NAME.NULL = FALSE; - l = get_text (X.RDB$ROLE_NAME, sizeof (X.RDB$ROLE_NAME)); + l = GET_TEXT(X.RDB$ROLE_NAME); MISC_terminate ((UCHAR*) X.RDB$ROLE_NAME, (UCHAR*) temp, l, sizeof (temp)); /************************************************ ** @@ -5258,7 +5259,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_sql_roles_req_handle1) case att_role_owner_name: X.RDB$OWNER_NAME.NULL = FALSE; - get_text (X.RDB$OWNER_NAME, sizeof (X.RDB$OWNER_NAME)); + GET_TEXT(X.RDB$OWNER_NAME); break; default: @@ -5334,8 +5335,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_security_class_req_handle1) switch (attribute) { case att_class_security_class: - l = get_text (X.RDB$SECURITY_CLASS, - sizeof (X.RDB$SECURITY_CLASS)); + l = GET_TEXT(X.RDB$SECURITY_CLASS); /* Bug fix for bug_no 7299: There was a V3 bug that inserted garbage security class entry when doing GBAK. In order to @@ -5636,7 +5636,7 @@ static BOOLEAN get_trigger (void) * **************************************/ ATT_TYPE attribute; -TEXT name [32]; +BASED_ON RDB$TRIGGERS.RDB$TRIGGER_NAME name; UCHAR scan_next_attr; isc_tr_handle local_trans; TGBL tdgbl; @@ -5683,14 +5683,14 @@ STORE (TRANSACTION_HANDLE local_trans break; case att_trig_name: - get_text (X.RDB$TRIGGER_NAME, sizeof (X.RDB$TRIGGER_NAME)); + GET_TEXT(X.RDB$TRIGGER_NAME); strcpy (name, X.RDB$TRIGGER_NAME); BURP_verbose (126, X.RDB$TRIGGER_NAME, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 126 restoring trigger %s */ break; case att_trig_relation_name: - get_text (X.RDB$RELATION_NAME, sizeof (X.RDB$RELATION_NAME)); + GET_TEXT(X.RDB$RELATION_NAME); break; case att_trig_sequence: @@ -5779,7 +5779,7 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) switch (attribute) { case att_trigmsg_name: - get_text (name, sizeof (name)); + GET_TEXT(name); flag = FALSE; FOR (REQUEST_HANDLE tdgbl->handles_get_trigger_message_req_handle1) FIRST 1 X IN RDB$TRIGGERS WITH @@ -5798,7 +5798,7 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) break; case att_trigmsg_text: - get_text (message, sizeof (message)); + GET_TEXT(message); break; default: @@ -5875,7 +5875,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_type_req_handle1) switch (attribute) { case att_type_name: - l = get_text (X.RDB$TYPE_NAME, sizeof (X.RDB$TYPE_NAME)); + l = GET_TEXT(X.RDB$TYPE_NAME); break; case att_type_type: @@ -5883,7 +5883,7 @@ STORE (REQUEST_HANDLE tdgbl->handles_get_type_req_handle1) break; case att_type_field_name: - get_text (X.RDB$FIELD_NAME, sizeof (X.RDB$FIELD_NAME)); + GET_TEXT(X.RDB$FIELD_NAME); break; case att_type_description: @@ -5961,19 +5961,19 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) case att_priv_user: /* default USER_TYPE to USER */ flags |= USER_PRIV_USER; - get_text (user, sizeof (user)); + GET_TEXT(user); BURP_verbose (123, user, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR); /* msg 123 restoring privilege for user %s */ break; case att_priv_grantor: flags |= USER_PRIV_GRANTOR; - get_text (grantor, sizeof (grantor)); + GET_TEXT(grantor); break; case att_priv_privilege: flags |= USER_PRIV_PRIVILEGE; - get_text (privilege, sizeof (privilege)); + GET_TEXT(privilege); break; case att_priv_grant_option: @@ -5984,12 +5984,12 @@ while (SKIP_SCAN, GET_ATTRIBUTE (attribute) != att_end) case att_priv_object_name: flags |= USER_PRIV_OBJECT_NAME; /* default OBJECT_TYPE to RELATION */ - get_text (relation_name, sizeof (relation_name)); + GET_TEXT(relation_name); break; case att_priv_field_name: flags |= USER_PRIV_FIELD_NAME; - get_text (field_name, sizeof (field_name)); + GET_TEXT(field_name); break; case att_priv_user_type: @@ -6163,11 +6163,11 @@ STORE (TRANSACTION_HANDLE local_trans switch (attribute) { case att_view_relation_name: - get_text (X.RDB$RELATION_NAME, sizeof (X.RDB$RELATION_NAME)); + GET_TEXT(X.RDB$RELATION_NAME); break; case att_view_context_name: - get_text (X.RDB$CONTEXT_NAME, sizeof (X.RDB$CONTEXT_NAME)); + GET_TEXT(X.RDB$CONTEXT_NAME); break; case att_view_context_id: @@ -6581,7 +6581,7 @@ flag = FALSE; if (tdgbl->RESTORE_format < 1 || tdgbl->RESTORE_format > ATT_BACKUP_FORMAT) #ifdef SUPERSERVER - BURP_svc_error (44, isc_arg_number, tdgbl->RESTORE_format, + BURP_svc_error (44, isc_arg_number, (void*)tdgbl->RESTORE_format, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (44, (void*) tdgbl->RESTORE_format, 0, 0, 0, 0); @@ -6604,7 +6604,7 @@ EXEC SQL SET TRANSACTION NAME tdgbl->global_trans ISOLATION LEVEL READ COMMITTED db_version = check_db_version(); if (db_version < DB_VERSION_CURRENT) #ifdef SUPERSERVER - BURP_svc_error (51, isc_arg_number, db_version, + BURP_svc_error (51, isc_arg_number, (void*)db_version, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (51, (void*) db_version, 0, 0, 0, 0); @@ -6622,7 +6622,7 @@ while (GET_ATTRIBUTE (attribute) != att_end) just store the value in tdgbl. It will be updated at the very end to prevent security class validation failures during change table ownership operation */ - get_text(tdgbl->database_security_class, sizeof(tdgbl->database_security_class)); + GET_TEXT(tdgbl->database_security_class); break; case att_database_description: @@ -6648,7 +6648,7 @@ while (GET_ATTRIBUTE (attribute) != att_end) FOR (REQUEST_HANDLE req_handle3) X IN RDB$DATABASE MODIFY X USING - get_text (X.RDB$CHARACTER_SET_NAME, sizeof (X.RDB$CHARACTER_SET_NAME)); + GET_TEXT(X.RDB$CHARACTER_SET_NAME); END_MODIFY; ON_ERROR general_on_error (); @@ -6823,7 +6823,7 @@ while (GET_RECORD (record) != rec_end) default: #ifdef SUPERSERVER - BURP_svc_error (43, isc_arg_number, (void *) record, + BURP_svc_error (43, isc_arg_number, (void*) record, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (43, (void*) record, 0, 0, 0, 0); diff --git a/src/burp/spit.cpp b/src/burp/spit.cpp index 6973e0a628..c0c0bf7b85 100644 --- a/src/burp/spit.cpp +++ b/src/burp/spit.cpp @@ -46,7 +46,8 @@ #endif #ifdef WIN_NT -#include /* usage of non-ANSI open/read/write/close functions */ +// usage of non-ANSI open/read/write/close functions +#include #endif #define MODE_READ O_RDONLY @@ -1088,7 +1089,7 @@ SLONG cnt, SLONG * total_int) break; default: - assert(write_cnt == read_cnt); + gds_assert(write_cnt == read_cnt); break; } diff --git a/src/csv/csi.h b/src/csv/csi.h index 2344f0097c..a70f6baccf 100644 --- a/src/csv/csi.h +++ b/src/csv/csi.h @@ -434,7 +434,7 @@ typedef SLONG HANDLE; /* Block types */ #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #define type_rdb 10 diff --git a/src/csv/csu.cpp b/src/csv/csu.cpp index a2f60d6aa5..62ce9a7dc1 100644 --- a/src/csv/csu.cpp +++ b/src/csv/csu.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: csu.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +$Id: csu.cpp,v 1.3 2001-12-24 02:50:48 tamlin Exp $ */ #include "firebird.h" diff --git a/src/csv/csv.cpp b/src/csv/csv.cpp index 71cfec2b98..a99b00256d 100644 --- a/src/csv/csv.cpp +++ b/src/csv/csv.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: csv.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +$Id: csv.cpp,v 1.3 2001-12-24 02:50:48 tamlin Exp $ */ #include "firebird.h" diff --git a/src/dsql/all.h b/src/dsql/all.h index 00849262ab..defe5ec6e3 100644 --- a/src/dsql/all.h +++ b/src/dsql/all.h @@ -21,20 +21,29 @@ * Contributor(s): ______________________________________. */ -#include "../dsql/dsql.h" +#ifndef DSQL_ALL_H +#define DSQL_ALL_H -/* alloc and init a block from a pool */ -BLK ALLD_alloc(PLB pool, UCHAR type, int count); +#include "../common/memory/memory_pool.h" +#include "../common/memory/allocators.h" +#include "../jrd/block_cache.h" -/* extend a block by given size */ -BLK ALLD_extend(BLK* pointer, int size); +void ALLD_init(); /* initialize pool system */ +void ALLD_fini(); /* get rid of everything */ -int ALLD_fini(); /* get rid of everything */ -int ALLD_free(void* memory); /* give space back to system */ -int ALLD_init(); /* initialize pool system */ -void* ALLD_malloc(int size); /* get memory from system */ -PLB ALLD_pool(); /* allocate a new pool */ -int ALLD_push(BLK object, LLS * stack); /* push object on LLS stack */ -BLK ALLD_pop(LLS* stack); /* pop object off LLS stack */ -int ALLD_release(FRB block); /* release a block to its pool */ -int ALLD_rlpool(PLB pool); /* release a pool */ +class DsqlMemoryPool : public MemoryPool +{ +public: + DsqlMemoryPool(int extSize = 0, MemoryPool& p = *FB_MemoryPool); + ~DsqlMemoryPool(); + + static class blk* ALLD_pop(class dsql_lls**); + static void ALLD_push(class blk*, class dsql_lls**); + +private: + BlockCache lls_cache; /* Was plb_lls */ +}; + +extern DsqlMemoryPool *DSQL_permanent_pool; + +#endif // DSQL_ALL_H diff --git a/src/dsql/alld.cpp b/src/dsql/alld.cpp index d87363a5dd..0fa7108f65 100644 --- a/src/dsql/alld.cpp +++ b/src/dsql/alld.cpp @@ -22,25 +22,6 @@ * 02 Nov 2001: Mike Nordell - Synch with FB1 changes. */ - -/*************************************************** - THIS MODULE HAS SEVERAL KISSING COUSINS; IF YOU - SHOULD CHANGE ONE OF THE MODULES IN THE FOLLOWING - LIST, PLEASE BE SURE TO CHECK THE OTHERS FOR - SIMILAR CHANGES: - - /gds/maint/pyxis/all.c - /dsql/all.c - /jrd/all.c - /pipe/allp.c - /qli/all.c - /remote/allr.c - /gpre/msc.c - - - THANK YOU -***************************************************/ - - /************************************************************** V4 Multi-threading changes. @@ -69,6 +50,7 @@ nested FOR loops are added. THREAD_ENTER; // First statment after FOR loop ***************************************************************/ +#include "../dsql/all.h" #include "firebird.h" #include #include "../jrd/ib_stdio.h" @@ -81,918 +63,127 @@ nested FOR loops are added. #include "../jrd/gds_proto.h" #include "../jrd/thd_proto.h" -ASSERT_FILENAME /* Define things dsql/assert needed */ +ASSERT_FILENAME //Define things dsql/assert needed +#include "../include/fb_vector.h" + +#ifdef SUPERSERVER extern "C" { -#define MIN_ALLOCATION 1024 -#if (defined PC_PLATFORM && !defined NETWARE_386) -#define MAX_BLOCK 65520 -#else -#define MAX_BLOCK (262144 - MIN_ALLOCATION - sizeof (struct hnk) - 8) -#endif -#define SHIFT SHIFTLONG -#define BLOCK_FACTOR (1 << SHIFT) -#define BLOCKS_TO_SIZE(blocks) ((blocks) << SHIFT) -#define SIZE_TO_BLOCKS(size) ((size) >> SHIFT) -#define BLOCK_ROUNDUP(size) ROUNDUP (size, MAX(BLOCK_FACTOR,ALIGNMENT)) -#define EXPAND_BLOCKSIZE(b) (BLOCKS_TO_SIZE ((b)->blk_length)) - -#define BLKDEF(type, root, tail) { sizeof (struct root), tail }, - static CONST struct { - USHORT typ_root_length; - USHORT typ_tail_length; -} block_sizes[] = { - 0, 0, -#include "../dsql/blk.h" -0}; - - -#undef BLKDEF - -#ifdef SUPERSERVER extern SLONG trace_pools; +} SLONG alld_delta_alloc = 0; - -#define BLKDEF(type, root, tail) 0, - -SLONG alld_block_type_count[] = { -#include "../dsql/blk.h" - 0 -}; -#undef BLKDEF -#define BLKDEF(type, root, tail) #type, -char ALLD_types[][24] = { - "type_MIN", -#include "../dsql/blk.h" - "type_MAX" -}; -#undef BLKDEF -int alld_type_MAX = type_MAX; #endif -static void extend_pool(PLB, ULONG); -static PLB find_pool(BLK); -static void release(FRB, PLB); +DsqlMemoryPool *DSQL_permanent_pool = 0; +typedef Firebird::vector pool_vec_t; +static bool init_flag = false; +static Firebird::vector *pools = 0; -static USHORT init_flag = FALSE; -static VEC pools = NULL; - - -BLK ALLD_alloc( PLB pool, UCHAR type, ULONG count) -{ -/************************************** - * - * A L L D _ a l l o c - * - ************************************** - * - * Functional description - * Allocate a block from a given pool and initialize the block. - * This is the primary block allocation routine. - * - **************************************/ - register BLK block; - FRB free, *best, *ptr; - register ULONG size; - ULONG l; - SLONG best_tail, tail; - ULONG needed_blocks; - - if (!pool) { - BUGCHECK ("Bad pool, ALLD_alloc"); - } - - DEV_BLKCHK(pool, type_plb); - - if (type <= (SCHAR) type_MIN || type >= (SCHAR) type_MAX) - BUGCHECK("bad block type"); - -/* Compute block length */ - - size = block_sizes[type].typ_root_length; - - if ((tail = block_sizes[type].typ_tail_length) && count >= 1) { - size += (count - 1) * tail; - } - - if (size <= sizeof(struct blk) || size >= MAX_BLOCK) { - BUGCHECK("bad block size"); - } - - needed_blocks = SIZE_TO_BLOCKS(BLOCK_ROUNDUP(size)); - - if (BLOCKS_TO_SIZE (needed_blocks) < size) { - BUGCHECK ("ALLD_alloc rounded down when it should round up"); - } - -/* Find best fit. Best fit is defined to be the free block of shortest - tail. If there isn't a fit, extend the pool and try, try again. */ - - while (TRUE) - { - best = NULL; - best_tail = MAX_BLOCK; - for (ptr = &pool->plb_free; ((free = *ptr) != NULL); ptr = &free->frb_next) - { - if ((SCHAR HUGE_PTR *) free == (SCHAR HUGE_PTR *) free->frb_next) - { - BUGCHECK("corrupt pool"); - } - /* Is this block big enough? - * And have less leftover than the best one found? */ - else if ( - ((tail = - ((ULONG) free->frb_header.blk_length - - needed_blocks)) >= 0) && (tail < best_tail)) - { - best = ptr; - best_tail = tail; - if (tail == 0) { - break; - } - } - } - if (best) { - break; - } - - extend_pool(pool, size); - } - -/* We've got our free block. If there's enough left of the free block - after taking out our block, chop out out block. If not, allocate - the entire free block as our block (a little extra won't hurt). */ - - free = *best; - if (best_tail > SIZE_TO_BLOCKS(BLOCK_ROUNDUP(sizeof(struct frb)))) - { - /* Carve off the needed size from the bottom of the free block */ - l = free->frb_header.blk_length - needed_blocks; - - block = (BLK) ((UCHAR *) free + BLOCKS_TO_SIZE(l)); - - /* Reset the length of the free block */ - if (needed_blocks < 0) { - BUGCHECK ("ALLD_alloc: asking for less than nothing"); - } - free->frb_header.blk_length = (USHORT) l; - } - else - { - /* There isn't left over in the free block to save in the free list */ - /* So give the client the whole free block */ - - /* Unhook the free block from the free chain */ - *best = free->frb_next; - - /* Client gets the whole block */ - needed_blocks = free->frb_header.blk_length; - block = (BLK) free; - } - -/* Zero the whole allocated structure */ - memset(block, 0, BLOCKS_TO_SIZE(needed_blocks)); - -/* Note that only the last 8 bits of the pool id are - stored in the block header. find_pool does the - necessary expansion */ - - block->blk_type = type; - block->blk_pool_id = (UCHAR)pool->plb_pool_id; - - if (needed_blocks > (ULONG) MAX_USHORT) { - BUGCHECK ("ALLD_alloc: too greedy"); - } - - block->blk_length = (USHORT) needed_blocks; - -#ifdef SUPERSERVER - if (trace_pools) { - ++alld_block_type_count[type]; - ++pool->plb_blk_type_count[type]; - } +// Microsoft MSVC bug workaround +#ifdef _MSC_VER +#define for if(0) {} else for #endif - return block; -} - -BLK ALLD_extend(BLK * pointer, ULONG size) +void ALLD_fini() { -/************************************** - * - * A L L D _ e x t e n d - * - ************************************** - * - * Functional description - * Extend a repeating block, copying the constant part. - * - **************************************/ - BLK block, new_; - PLB pool; - register ULONG length, l; - register SLONG *p1, *p2; - register SCHAR *c1, *c2; - - if (!pointer || !(*pointer)) { - BUGCHECK ("bad pointer in ALLD_extend"); - } - - block = *pointer; - pool = find_pool(block); - new_ = ALLD_alloc(pool, block->blk_type, size); - length = MIN(EXPAND_BLOCKSIZE(block), EXPAND_BLOCKSIZE(new_)) - - sizeof(struct blk); - p1 = (SLONG *) ((UCHAR *) new_ + sizeof(struct blk)); - p2 = (SLONG *) ((UCHAR *) block + sizeof(struct blk)); - -/* Copy the bytes a longword at a time */ - if ((l = length >> SHIFTLONG) != 0) - { - do { - *p1++ = *p2++; - } while (--l); - } - -/* Copy any remaining bytes */ - if (length &= 3) - { - c1 = (SCHAR *) p1; - c2 = (SCHAR *) p2; - do { - *c1++ = *c2++; - } while (--length); - } - - release(reinterpret_cast(block), pool); - - if (new_->blk_type == (SCHAR) type_vec) { - ((VEC) new_)->vec_count = size; - } else if (new_->blk_type == (SCHAR) type_vcl) { - ((VCL) new_)->vcl_count = size; - } - - *pointer = new_; - - return new_; -} - - -void ALLD_fini(void) -{ -/************************************** - * - * A L L D _ f i n i - * - ************************************** - * - * Functional description - * Get rid of everything. - * - **************************************/ - BLK *vector, *until; - PLB pool; - - if (!init_flag) { // Must _init before _fini + if (!init_flag) { BUGCHECK ("ALLD_fini - finishing before starting"); } -/* if there are no pools, we've already finished. */ - - if (!pools) - return; - -/* vec_object [0] is the memory pool which contains pools, so release - * objects in reverse order, and be careful not to refer to pools - * during the process. - */ - for (vector = pools->vec_object + pools->vec_count, - until = pools->vec_object; --vector >= until;) + for (pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr) { - if ((pool = (PLB) * vector) != NULL) { - ALLD_rlpool(pool); + if (*curr) { + delete *curr; } } - pools = NULL; - init_flag = FALSE; + delete pools; + pools = 0; + delete DSQL_permanent_pool; + DSQL_permanent_pool = 0; + init_flag = false; } -void ALLD_free(void* memory) +void ALLD_init() { -/************************************** - * - * A L L D _ f r e e - * - ************************************** - * - * Functional description - * Give space back to system. - * - **************************************/ - -#ifdef SUPERSERVER - alld_delta_alloc -= gds__free(memory); -#else - gds__free(memory); -#endif -} - - -USHORT ALLD_init(void) -{ -/************************************** - * - * A L L D _ i n i t - * - ************************************** - * - * Functional description - * Initialize the pool system. Return - * TRUE if initialization took place, FALSE if - * we had been previous initialized. - * - **************************************/ - SLONG temp_vector[20]; - PLB pool; - USHORT init; - TSQL tdsql; - - tdsql = GET_THREAD_DATA; - - init = (init_flag == FALSE); - if (!init_flag) - { - init_flag = TRUE; - - pools = (VEC) temp_vector; - pools->vec_count = 1; - pools->vec_object[0] = NULL; - - tdsql->tsql_default = DSQL_permanent_pool = pool = ALLD_pool(); - pools = (VEC) ALLD_alloc(pool, type_vec, 10); - pools->vec_count = 10; - - /* Note: ALLD_fini() assumes the this master pool is in vec_object [0] */ - pools->vec_object[0] = (BLK) pool; - } - - return init; -} - - -void* ALLD_malloc(ULONG size) -{ -/************************************** - * - * A L L D _ m a l l o c - * - ************************************** - * - * Functional description - * Get memory from system. - * - **************************************/ - TSQL tdsql = GET_THREAD_DATA; - UCHAR* memory = (UCHAR*)gds__alloc((SLONG) size); - - if (memory) + if (!init_flag) { -#ifdef SUPERSERVER - alld_delta_alloc += size; -#endif - return memory; + init_flag = true; + DSQL_permanent_pool = new(*FB_MemoryPool) DsqlMemoryPool; + pools = new(*DSQL_permanent_pool) Firebird::vector + (10, *DSQL_permanent_pool, dsql_type_vec); + tdsql->tsql_default = DSQL_permanent_pool; } - -/* FREE: by ALLD_free, called during DSQL cleanup */ -/* NOMEM: post a user level error - if we can */ - - if (tdsql && tdsql->tsql_setjmp) - { - ERRD_post(gds_sys_request, gds_arg_string, "gds__alloc", gds_arg_gds, - gds_virmemexh, gds_arg_end); - } - -/* Commentary: This expands out to a call to ERRD_error - which - * promply depends on tdsql being non-NULL. Knock, knock, anyone home? - */ - IBERROR(-1, "out of memory"); - return 0; // Not reached } - -PLB ALLD_pool(void) +void DsqlMemoryPool::ALLD_push(BLK object, register DLLS * stack) { -/************************************** - * - * A L L D _ p o o l - * - ************************************** - * - * Functional description - * Allocate a new pool. This is done by creating a tempory - * pool block on the stack, then allocating a real pool block. - * In short, by mirrors. - * - **************************************/ - struct plb temp_pool; - register PLB pool; - register USHORT pool_id; - -/* Start by assigning a pool id */ - - for (pool_id = 0; pool_id < pools->vec_count; pool_id++) - if (!(pools->vec_object[pool_id])) - break; - - if (pool_id >= pools->vec_count) - ALLD_extend((BLK *) & pools, (ULONG) (pool_id + 10)); - - memset((UCHAR *) & temp_pool, 0, sizeof(temp_pool)); - temp_pool.plb_header.blk_type = type_plb; - pools->vec_object[pool_id] = (BLK) & temp_pool; - temp_pool.plb_free = NULL; - temp_pool.plb_hunks = NULL; - temp_pool.plb_pool_id = pool_id; - temp_pool.plb_blk_type_count = NULL; -#ifdef SUPERSERVER - if (trace_pools) - { - temp_pool.plb_blk_type_count = - reinterpret_cast (gds__alloc(sizeof(alld_block_type_count))); - if (!temp_pool.plb_blk_type_count) { - trace_pools = 0; /* No memory!! stop tracing pool info */ - } else { - memset(temp_pool.plb_blk_type_count, 0, sizeof(alld_block_type_count)); - } - } -#endif - - if (pool_id == 0) { - DSQL_permanent_pool = &temp_pool; - } - - pool = (PLB) ALLD_alloc(&temp_pool, type_plb, 0); - pool->plb_pool_id = pool_id; - pool->plb_free = temp_pool.plb_free; - pool->plb_hunks = temp_pool.plb_hunks; -#ifdef SUPERSERVER - pool->plb_blk_type_count = temp_pool.plb_blk_type_count; -#endif - pools->vec_object[pool_id] = (BLK) pool; - - if (pool_id == 0) { - DSQL_permanent_pool = pool; - } - - return pool; -} - - -#ifdef SUPERSERVER -void ALLD_print_memory_pool_info( IB_FILE * fptr) -{ -/************************************************************* - * - * A L L D _ p r i n t _ m e m o r y _ p o o l _ i n f o - * - ************************************************************* - * - * Functional description - * Print the various block types allocated with in the pools - * - *************************************************************/ - VEC vector; - PLB myPool; - HNK hnk; - int i, j, col; - - if (!trace_pools) { - return; - } - - ib_fprintf(fptr, "\n\tALLD_xx block types\n"); - ib_fprintf(fptr, "\t--------------------"); - for (i = 0, col = 0; i < type_MAX; i++) - { - if (alld_block_type_count[i]) - { - if (col % 5 == 0) { - ib_fprintf(fptr, "\n\t"); - } - ib_fprintf(fptr, "%s = %d ", ALLD_types[i], - alld_block_type_count[i]); - ++col; - } - } - ib_fprintf(fptr, "\n"); - - if (!pools) { - ib_fprintf(fptr, "\t No pools allocated"); - return; - } - vector = pools; - for (j = 0, i = 0; i < (int) vector->vec_count; i++) - { - myPool = (PLB) vector->vec_object[i]; - if (myPool) { - ++j; - } - } - ib_fprintf(fptr, "\t There are %d pools", j); - for (i = 0; i < (int) vector->vec_count; i++) - { - myPool = (PLB) vector->vec_object[i]; - if (!myPool) { - continue; - } - ib_fprintf(fptr, "\n\t Pool %d", myPool->plb_pool_id); - for (j = 0, hnk = myPool->plb_hunks; hnk; hnk = hnk->hnk_next) { - j++; - } - if (j) { - ib_fprintf(fptr, " has %d hunks", j); - } - for (j = 0, col = 0; j < type_MAX; j++) - { - if (myPool->plb_blk_type_count[j]) { - if (col % 5 == 0) { - ib_fprintf(fptr, "\n\t "); - } - ib_fprintf(fptr, "%s = %d ", ALLD_types[j], - myPool->plb_blk_type_count[j]); - ++col; - } - } - } -} -#endif - - -void ALLD_push( BLK object, register LLS * stack) -{ -/************************************** - * - * A L L D _ p u s h - * - ************************************** - * - * Functional description - * Push an object on an LLS stack. - * - **************************************/ - register LLS node; - PLB pool; - TSQL tdsql; - - tdsql = GET_THREAD_DATA; - - pool = tdsql->tsql_default; - - if ((node = pool->plb_lls) != NULL) { - /* Pull a stack block off the list of free stack blocks */ - pool->plb_lls = node->lls_next; - } - else { - /* No free stack blocks - allocate a new one */ - node = (LLS) ALLD_alloc(pool, type_lls, 0); - } - - DEV_BLKCHK(node, type_lls); - DEV_BLKCHK(*stack, type_lls); + TSQL tdsql = GET_THREAD_DATA; + DsqlMemoryPool* pool = tdsql->tsql_default; + DLLS node = pool->lls_cache.newBlock(); node->lls_object = object; node->lls_next = *stack; *stack = node; } -BLK ALLD_pop(register LLS * stack) +BLK DsqlMemoryPool::ALLD_pop(register DLLS *stack) { -/************************************** - * - * A L L D _ p o p - * - ************************************** - * - * Functional description - * Pop an object off a linked list stack. Save the node for - * further use. - * - **************************************/ - register LLS node; - register PLB pool; - BLK block; - - DEV_BLKCHK(*stack, type_lls); - - node = *stack; - - DEV_BLKCHK(node, type_lls); - - - -/* what we are doing below is .... block = &(node->lls_header) */ - block = (BLK) node; - pool = find_pool(block); - -/* Pop item off the stack */ + DLLS node = *stack; *stack = node->lls_next; + BLK object = node->lls_object; -/* Add the popped stack lls block to the list of free stack blocks */ - node->lls_next = pool->plb_lls; - pool->plb_lls = node; + DsqlMemoryPool* pool = (DsqlMemoryPool*)MemoryPool::blk_pool(node); + pool->lls_cache.returnBlock(node); - return node->lls_object; + return object; } - -void ALLD_release( register FRB block) +DsqlMemoryPool::DsqlMemoryPool(int extSize, MemoryPool& p) + : MemoryPool(0, &p), + lls_cache(*this) { -/************************************** - * - * A L L D _ r e l e a s e - * - ************************************** - * - * Functional description - * Release a block to its pool. If it is contiguous to - * another free block, combine them. Otherwise link it - * into the free block linked list (kept in ascending order - * of addresses). - * - **************************************/ - - release(block, find_pool(&block->frb_header)); -} - - -void ALLD_rlpool( PLB pool) -{ -/************************************** - * - * A L L D _ r l p o o l - * - ************************************** - * - * Functional description - * Release a storage pool. This involves nothing more than returning - * hunks to the free hunk list. - * - **************************************/ - register HNK hunk, hunks; - -/* if there are no pools, there's no point in releasing anything... */ - - if (!pools) + if (!DSQL_permanent_pool) return; - - DEV_BLKCHK(pool, type_plb); - - pools->vec_object[pool->plb_pool_id] = NULL; - -/* Have to release hunks carefully, as one of the hunks being released - * contains pool itself - */ -#ifdef SUPERSERVER - if (trace_pools && pool->plb_blk_type_count) + + for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr) { - int i; - for (i = 0; i < type_MAX; i++) + if (!*curr) { - alld_block_type_count[i] -= pool->plb_blk_type_count[i]; + *curr = this; + return; } - gds__free(pool->plb_blk_type_count); } -#endif - for (hunks = pool->plb_hunks; hunk = hunks;) + pools->resize(pools->size() + 10); + for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr) { - hunks = hunk->hnk_next; - ALLD_free(hunk->hnk_address); + if (!*curr) + { + *curr = this; + return; + } } + + BUGCHECK ("ALLD_fini - finishing before starting"); } - -static void extend_pool( PLB pool, ULONG size) +DsqlMemoryPool::~DsqlMemoryPool() { -/************************************** - * - * e x t e n d _ p o o l - * - ************************************** - * - * Functional description - * Extend a pool by at least enough to accomodate a block - * of given size. - * - **************************************/ - register HNK hunk; - register BLK block; - - DEV_BLKCHK(pool, type_plb); - - size = (size + sizeof(struct hnk) + MIN_ALLOCATION - 1) - & ~((ULONG) MIN_ALLOCATION - 1); - block = (BLK) ALLD_malloc(size); - - if (SIZE_TO_BLOCKS (size) > MAX_USHORT) { - BUGCHECK ("too greedy in extend pool of alld.c"); + if (this == DSQL_permanent_pool) + return; + + for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr) + { + if (*curr == this) + { + *curr = 0; + return; + } } - - block->blk_length = (USHORT) SIZE_TO_BLOCKS(size); - block->blk_type = (SCHAR) type_frb; - - block->blk_pool_id = (UCHAR) pool->plb_pool_id; -#ifdef SUPERSERVER - if (trace_pools) { - ++alld_block_type_count[block->blk_type]; - ++pool->plb_blk_type_count[block->blk_type]; - } -#endif - release(reinterpret_cast(block), pool); - - hunk = (HNK) ALLD_alloc(pool, type_hnk, 0); - hunk->hnk_address = (UCHAR *) block; - hunk->hnk_length = size; - hunk->hnk_next = pool->plb_hunks; - pool->plb_hunks = hunk; } - - -static PLB find_pool( BLK block) -{ -/************************************** - * - * f i n d _ p o o l - * - ************************************** - * - * Functional description - * Find pool associate with block. - * - **************************************/ - PLB pool; - HNK hunk; - USHORT pool_id; - - if (pools->vec_count < 256) - { - if ((pool_id = block->blk_pool_id) < pools->vec_count && - (pool = (PLB) pools->vec_object[pool_id])) - { - return pool; - } - else - { - BUGCHECK("bad pool id"); - } - } - - for (pool_id = block->blk_pool_id; pool_id < pools->vec_count; pool_id += 256) - { - if (pool = (PLB) pools->vec_object[pool_id]) - { - hunk = pool->plb_hunks; - for (; hunk; hunk = hunk->hnk_next) - { - if ((SCHAR HUGE_PTR *) block >= (SCHAR HUGE_PTR *) hunk->hnk_address - && (SCHAR HUGE_PTR *) block < - (SCHAR HUGE_PTR *) hunk->hnk_address + hunk->hnk_length) - { - return pool; - } - } - } - } - BUGCHECK("bad pool id"); - return (PLB) NULL; /* Added to remove warnings */ -} - - -static void release( FRB block, PLB pool) -{ -/************************************** - * - * r e l e a s e - * - ************************************** - * - * Functional description - * Release a block to its pool. If it is contiguous to - * another free block, combine them. Otherwise link it - * into the free block linked list (kept in ascending order - * of addresses). - * - **************************************/ - register FRB prior, free; - FRB* ptr; - - DEV_BLKCHK(pool, type_plb); - -#ifdef SUPERSERVER - UCHAR blk_header_type = block->frb_header.blk_type; -#endif - block->frb_header.blk_type = (SCHAR) type_frb; - prior = NULL; - - for (ptr = &pool->plb_free; (free = *ptr) != NULL; - prior = free, ptr = &free->frb_next) - { - if ((SCHAR HUGE_PTR *) block <= (SCHAR HUGE_PTR *) free) - { - break; - } - } - -#ifdef DEBUG_GDS_ALLOC -/* Debugging code to erase memory locations after a release - - * this will assist in catching dangling memory references to - * freed locations. - * Note that the header parts of the freed block may still be used, - * for the free chain, so we don't zap those locations. - */ - -#define ALLD_RELEASED_PATTERN 0xEE - { - ULONG size; - size = BLOCKS_TO_SIZE(block->frb_header.blk_length); - if (size < sizeof (struct blk)) - { - BUGCHECK ("Releasing less that 4 bytes: alld.c/release"); - } - size -= sizeof(struct blk); - if (size) - { - memset((SCHAR *) block + sizeof(struct blk), - ALLD_RELEASED_PATTERN, size); - } - }; -#endif /* DEBUG_GDS_ALLOC */ - - if ((SCHAR HUGE_PTR *) block == (SCHAR HUGE_PTR *) free) { - BUGCHECK("block released twice"); - } - -/* Merge block into list first, then try to combine blocks */ - - block->frb_next = free; - *ptr = block; - -/* Try to merge the free block with the next one down. */ - - if (free) - { - if ((SCHAR HUGE_PTR *) block + EXPAND_BLOCKSIZE(&block->frb_header) == - (SCHAR HUGE_PTR *) free) - { - block->frb_header.blk_length += free->frb_header.blk_length; - block->frb_next = free->frb_next; -#ifdef DEBUG_GDS_ALLOC - /* Paint the freed header of the merged-away block */ - memset((UCHAR *) free, ALLD_RELEASED_PATTERN, sizeof(*free)); -#endif /* DEBUG_GDS_ALLOC */ - } - else if ((SCHAR HUGE_PTR *) block + - EXPAND_BLOCKSIZE(&block->frb_header) > - (SCHAR HUGE_PTR *) free) - { - BUGCHECK("released block overlaps following free block"); - } - } - -/* Try and merge the block with the prior free block */ - - if (prior) - { - if ((SCHAR HUGE_PTR *) prior + EXPAND_BLOCKSIZE(&prior->frb_header) == - (SCHAR HUGE_PTR *) block) - { - prior->frb_header.blk_length += block->frb_header.blk_length; - prior->frb_next = block->frb_next; -#ifdef DEBUG_GDS_ALLOC - /* Paint the freed header of the merged-away block */ - memset((UCHAR *) block, ALLD_RELEASED_PATTERN, sizeof(*block)); -#endif /* DEBUG_GDS_ALLOC */ - } - else if ((SCHAR HUGE_PTR *) prior + - EXPAND_BLOCKSIZE(&prior->frb_header) > - (SCHAR HUGE_PTR *) block) - { - BUGCHECK("released block overlaps prior free block"); - } - } -#ifdef SUPERSERVER - if (trace_pools) { - --alld_block_type_count[blk_header_type]; - --pool->plb_blk_type_count[blk_header_type]; - } -#endif -} - - -} // extern "C" diff --git a/src/dsql/alld_proto.h b/src/dsql/alld_proto.h index f69087c0f8..99dc80f570 100644 --- a/src/dsql/alld_proto.h +++ b/src/dsql/alld_proto.h @@ -24,24 +24,6 @@ #ifndef _DSQL_ALLD_PROTO_H_ #define _DSQL_ALLD_PROTO_H_ -#ifdef __cplusplus -extern "C" { -#endif - -BLK ALLD_alloc(struct plb*, UCHAR, ULONG); -BLK ALLD_extend(struct blk**, ULONG); -void ALLD_fini(void); -void ALLD_free(void*); -USHORT ALLD_init(void); -void* ALLD_malloc(ULONG); -PLB ALLD_pool(void); -BLK ALLD_pop(register struct lls**); -void ALLD_push(struct blk*, register struct lls**); -void ALLD_release(register struct frb*); -void ALLD_rlpool(struct plb*); - -#ifdef __cplusplus -} /* extern "C" */ -#endif +#include "../dsql/all.h" #endif /* _DSQL_ALLD_PROTO_H_ */ diff --git a/src/dsql/array.epp b/src/dsql/array.epp index 0e8e7097d0..b2b5b0fce8 100644 --- a/src/dsql/array.epp +++ b/src/dsql/array.epp @@ -1,6 +1,6 @@ /* * PROGRAM: Interbase layered support library - * MODULE: array.e + * MODULE: array.epp * DESCRIPTION: Dynamic array support * * The contents of this file are subject to the Interbase Public @@ -152,7 +152,7 @@ STATUS API_ROUTINE isc_array_lookup_bounds(STATUS * status, ++tail; END_FOR ON_ERROR - return copy_status(gds__status, status); + return copy_status(gds_status, status); END_ERROR; return status[1]; @@ -490,7 +490,7 @@ SCHAR * relation_name, ISC_ARRAY_DESC * desc, SCHAR * global) RELEASE_REQUESTS; DB = *db_handle; - gds__trans = *trans_handle; + gds_trans = *trans_handle; get_name(field_name, desc->array_desc_field_name); get_name(relation_name, desc->array_desc_relation_name); desc->array_desc_flags = 0; @@ -511,7 +511,7 @@ SCHAR * relation_name, ISC_ARRAY_DESC * desc, SCHAR * global) get_name(Y.RDB$FIELD_NAME, global); END_FOR ON_ERROR - return copy_status(gds__status, status); + return copy_status(gds_status, status); END_ERROR; if (!flag) diff --git a/src/dsql/blk.h b/src/dsql/blk.h index 5618f43cf2..1856fc1c7c 100644 --- a/src/dsql/blk.h +++ b/src/dsql/blk.h @@ -21,29 +21,25 @@ * Contributor(s): ______________________________________. */ -BLKDEF(type_ctx, ctx, 0) - BLKDEF(type_par, par, 0) - BLKDEF(type_map, map, 0) - BLKDEF(type_req, req, 0) - BLKDEF(type_dbb, dbb, 0) - BLKDEF(type_dsql_rel, dsql_rel, 1) - BLKDEF(type_fld, fld, 1) - BLKDEF(type_fil, fil, 0) - BLKDEF(type_nod, nod, sizeof(((NOD) 0)->nod_arg[0])) - BLKDEF(type_msg, msg, 0) - BLKDEF(type_frb, frb, 0) - BLKDEF(type_hnk, hnk, 0) - BLKDEF(type_plb, plb, 0) - BLKDEF(type_vec, vec, sizeof(((VEC) 0)->vec_object[0])) - BLKDEF(type_vcl, vcl, sizeof(((VCL) 0)->vcl_long[0])) - BLKDEF(type_lls, lls, 0) /* linked list stack */ - BLKDEF(type_str, str, 1) /* random string block */ - BLKDEF(type_sym, sym, 1) /* symbol block */ - BLKDEF(type_err, err, 0) - BLKDEF(type_opn, opn, 0) - BLKDEF(type_tra, tra, 0) - BLKDEF(type_udf, udf, 1) - BLKDEF(type_var, var, 1) - BLKDEF(type_blb, blb, 0) - BLKDEF(type_prc, prc, 1) - BLKDEF(type_intlsym, intlsym, 1) +BLKDEF(dsql_type_ctx, ctx, 0) +BLKDEF(dsql_type_par, par, 0) +BLKDEF(dsql_type_map, map, 0) /* Unique */ +BLKDEF(dsql_type_req, req, 0) +BLKDEF(dsql_type_dbb, dbb, 0) +BLKDEF(dsql_type_dsql_rel, dsql_rel, 1) +BLKDEF(dsql_type_fld, fld, 1) +BLKDEF(dsql_type_fil, fil, 0) +BLKDEF(dsql_type_nod, nod, sizeof(((NOD) 0)->nod_arg[0])) +BLKDEF(dsql_type_msg, msg, 0) +BLKDEF(dsql_type_lls, dsql_lls, 0) /* linked list stack */ +BLKDEF(dsql_type_str, str, 1) /* random string block */ +BLKDEF(dsql_type_sym, sym, 1) /* symbol block */ +BLKDEF(dsql_type_err, err, 0) +BLKDEF(dsql_type_opn, opn, 0) +BLKDEF(dsql_type_tra, tra, 0) +BLKDEF(dsql_type_udf, udf, 1) +BLKDEF(dsql_type_var, var, 1) +BLKDEF(dsql_type_blb, blb, 0) +BLKDEF(dsql_type_prc, prc, 1) +BLKDEF(dsql_type_intlsym, intlsym, 1) +BLKDEF(dsql_type_vec, vec, 0) diff --git a/src/dsql/blob.epp b/src/dsql/blob.epp index c072bc0dd6..3cc676c92e 100644 --- a/src/dsql/blob.epp +++ b/src/dsql/blob.epp @@ -1,6 +1,6 @@ /* * PROGRAM: InterBase layered support library - * MODULE: blob.e + * MODULE: blob.epp * DESCRIPTION: Dynamic blob support * * The contents of this file are subject to the Interbase Public @@ -142,7 +142,7 @@ STATUS API_ROUTINE isc_blob_lookup_desc(STATUS * status, RELEASE_REQUESTS; DB = *db_handle; - gds__trans = *trans_handle; + gds_trans = *trans_handle; get_name(field_name, desc->blob_desc_field_name); get_name(relation_name, desc->blob_desc_relation_name); @@ -159,7 +159,7 @@ STATUS API_ROUTINE isc_blob_lookup_desc(STATUS * status, if (global) get_name((UCHAR *) Y.RDB$FIELD_NAME, global); - END_FOR ON_ERROR return copy_status(gds__status, status); + END_FOR ON_ERROR return copy_status(gds_status, status); END_ERROR; if (!flag) diff --git a/src/dsql/ddl.cpp b/src/dsql/ddl.cpp index 7d59443b67..21fd8c46d4 100644 --- a/src/dsql/ddl.cpp +++ b/src/dsql/ddl.cpp @@ -20,13 +20,14 @@ * All Rights Reserved. * Contributor(s): ______________________________________. * - * $Id: ddl.cpp,v 1.4 2001-07-29 23:43:21 skywalker Exp $ + * $Id: ddl.cpp,v 1.5 2001-12-24 02:50:48 tamlin Exp $ * 2001.5.20 Claudio Valderrama: Stop null pointer that leads to a crash, * caused by incomplete yacc syntax that allows ALTER DOMAIN dom SET; * * 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" * conditionals, as the engine now fully supports * readonly databases. + * December 2001 Mike Nordell - Attempt to make it C++ */ #include "firebird.h" @@ -57,10 +58,10 @@ extern "C" { +} // extern "C" #define BLOB_BUFFER_SIZE 4096 /* to read in blr blob for default values */ -static void begin_blr(REQ, UCHAR); static USHORT check_array_or_blob(NOD); static void check_constraint(REQ, NOD, SSHORT); static void create_view_triggers(REQ, NOD, NOD); @@ -68,7 +69,7 @@ static void define_computed(REQ, NOD, FLD, NOD); static void define_constraint_trigger(REQ, NOD); static void define_database(REQ); static void define_del_cascade_trg(REQ, NOD, NOD, NOD, TEXT *, TEXT *); -static void define_del_default_trg(REQ, NOD, NOD, NOD, TEXT *, TEXT *); +//static void define_del_default_trg(REQ, NOD, NOD, NOD, TEXT *, TEXT *); static void define_dimensions(REQ, FLD); static void define_domain(REQ); static void define_exception(REQ, NOD_TYPE); @@ -81,7 +82,8 @@ static NOD define_insert_action(REQ); static void define_procedure(REQ, NOD_TYPE); static void define_rel_constraint(REQ, NOD); static void define_relation(REQ); -static void define_set_null_trg(REQ, NOD, NOD, NOD, TEXT *, TEXT *, BOOLEAN); +static void define_set_null_trg(REQ, NOD, NOD, NOD, TEXT*, TEXT*, bool); +static void define_set_default_trg(REQ, NOD, NOD, NOD, TEXT*, TEXT*, bool); static void define_shadow(REQ); static void define_trigger(REQ, NOD); static void define_udf(REQ); @@ -89,7 +91,6 @@ static void define_update_action(REQ, NOD *, NOD *); static void define_upd_cascade_trg(REQ, NOD, NOD, NOD, TEXT *, TEXT *); static void define_view(REQ); static void define_view_trigger(REQ, NOD, NOD, NOD); -static void end_blr(REQ); static void foreign_key(REQ, NOD); static void generate_dyn(REQ, NOD); static void grant_revoke(REQ); @@ -103,15 +104,12 @@ static void modify_privilege(REQ, NOD_TYPE, SSHORT, UCHAR *, NOD, NOD, STR); static void process_role_nm_list(REQ, SSHORT, NOD, NOD, NOD_TYPE); static SCHAR modify_privileges(REQ, NOD_TYPE, SSHORT, NOD, NOD, NOD); static void modify_relation(REQ); -static void put_cstring(REQ, UCHAR, char *); static void put_descriptor(REQ, DSC *); static void put_dtype(REQ, FLD, USHORT); static void put_field(REQ, FLD, BOOLEAN); static void put_local_variable(REQ, VAR); static SSHORT put_local_variables(REQ, NOD, SSHORT); static void put_msg_field(REQ, FLD); -static void put_number(REQ, UCHAR, SSHORT); -static void put_string(REQ, UCHAR, UCHAR *, USHORT); static NOD replace_field_names(NOD, NOD, NOD, SSHORT); static void reset_context_stack(REQ); static void save_field(REQ, SCHAR *); @@ -127,21 +125,17 @@ static void set_nod_value_attributes(NOD, FLD); #endif #ifdef DEV_BUILD -#define BLKCHK(blk, typ) \ - { \ - if ((blk) && (((BLK) (blk))->blk_type != (typ))) \ - ERRD_bugcheck ("Invalid block type"); /* NTX: dev build */ \ +static inline void BLKCHK(const void* p, USHORT type) +{ + if (p && MemoryPool::blk_type(p) != type) { + ERRD_bugcheck("Invalid block type"); } +} #else #define BLKCHK(blk, typ) #endif -/* STUFF is defined in dsql.h for use in common with gen.c */ - -#define STUFF_WORD(n) {STUFF (n); STUFF ((n) >> 8);} -#define STUFF_DWORD(n) {STUFF (n); STUFF ((n) >> 8);\ - STUFF ((n) >> 16); STUFF ((n) >> 24);} #define PRE_STORE_TRIGGER 1 #define POST_STORE_TRIGGER 2 @@ -190,7 +184,9 @@ static CONST UCHAR nonnull_validation_blr[] = { blr_eoc }; -ASSERT_FILENAME void DDL_execute( REQ request) +ASSERT_FILENAME + +void DDL_execute(REQ request) { /************************************** * @@ -204,64 +200,67 @@ ASSERT_FILENAME void DDL_execute( REQ request) * metadata updates. * **************************************/ - USHORT length; + STR string; STATUS s; - NOD relation_node; - TSQL tdsql; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; #ifdef DEBUG #if !(defined REQUESTER && defined SUPERCLIENT) if (DSQL_debug > 0) - PRETTY_print_dyn(reinterpret_cast < - char *>(request->req_blr_string->str_data), NULL, - "%4d %s\n", NULL); + PRETTY_print_dyn(reinterpret_cast( + request->req_blr_string->str_data), + NULL, + "%4d %s\n", + NULL); #endif #endif - length = request->req_blr - request->req_blr_string->str_data; + USHORT length = request->req_blr - request->req_blr_string->str_data; THREAD_EXIT; s = isc_ddl(GDS_VAL(tdsql->tsql_status), - reinterpret_cast < - void **>(GDS_REF(request->req_dbb->dbb_database_handle)), - reinterpret_cast < void **>(GDS_REF(request->req_trans)), + reinterpret_cast(GDS_REF(request->req_dbb->dbb_database_handle)), + reinterpret_cast(GDS_REF(request->req_trans)), length, - reinterpret_cast < - char *>(GDS_VAL(request->req_blr_string->str_data))); + reinterpret_cast(GDS_VAL(request->req_blr_string->str_data))); THREAD_ENTER; -/* for delete & modify, get rid of the cached relation metadata */ + // for delete & modify, get rid of the cached relation metadata if ((request->req_ddl_node->nod_type == nod_mod_relation) || - (request->req_ddl_node->nod_type == nod_del_relation)) { - if (request->req_ddl_node->nod_type == nod_mod_relation) { - relation_node = request->req_ddl_node->nod_arg[e_alt_name]; + (request->req_ddl_node->nod_type == nod_del_relation)) + { + if (request->req_ddl_node->nod_type == nod_mod_relation) + { + NOD relation_node = request->req_ddl_node->nod_arg[e_alt_name]; string = (STR) relation_node->nod_arg[e_rln_name]; } - else + else { string = (STR) request->req_ddl_node->nod_arg[e_alt_name]; + } METD_drop_relation(request, string); } -/* for delete & modify, get rid of the cached procedure metadata */ + // for delete & modify, get rid of the cached procedure metadata if ((request->req_ddl_node->nod_type == nod_mod_procedure) || - (request->req_ddl_node->nod_type == nod_del_procedure)) { + (request->req_ddl_node->nod_type == nod_del_procedure)) + { string = (STR) request->req_ddl_node->nod_arg[e_prc_name]; METD_drop_procedure(request, string); } - if (s) - LONGJMP(*tdsql->tsql_setjmp, (int) tdsql->tsql_status[1]); + if (s) { + Firebird::status_longjmp_error::raise(tdsql->tsql_status[1]); + } } -void DDL_generate( REQ request, NOD node) +void DDL_generate(REQ request, NOD node) { /************************************** * @@ -280,14 +279,14 @@ void DDL_generate( REQ request, NOD node) ERRD_post(isc_read_only_database, 0); return; } - - STUFF(gds_dyn_version_1); + + request->append_uchar(gds_dyn_version_1); generate_dyn(request, node); - STUFF(gds_dyn_eoc); + request->append_uchar(gds_dyn_eoc); } -int DDL_ids( REQ request) +int DDL_ids(REQ request) { /************************************** * @@ -301,10 +300,12 @@ int DDL_ids( REQ request) * and relations. * **************************************/ - NOD ddl_node; - if (!(ddl_node = request->req_ddl_node)) + NOD ddl_node = request->req_ddl_node; + + if (!ddl_node) { return TRUE; + } if (ddl_node->nod_type == nod_def_view || ddl_node->nod_type == nod_def_constraint || @@ -312,13 +313,16 @@ int DDL_ids( REQ request) ddl_node->nod_type == nod_mod_trigger || ddl_node->nod_type == nod_def_procedure || ddl_node->nod_type == nod_def_computed || - ddl_node->nod_type == nod_mod_procedure) return FALSE; + ddl_node->nod_type == nod_mod_procedure) + { + return FALSE; + } return TRUE; } -void DDL_put_field_dtype( REQ request, FLD field, USHORT use_subtype) +void DDL_put_field_dtype(REQ request, FLD field, USHORT use_subtype) { /************************************** * @@ -356,21 +360,19 @@ void DDL_resolve_intl_type( REQ request, FLD field, STR collation_name) * lengths of CHARACTERs, not BYTES. * **************************************/ - UCHAR *charset_name; + INTLSYM resolved_type; - INTLSYM resolved_charset; - INTLSYM resolved_collation; - STR dfl_charset; - SSHORT blob_sub_type; ULONG field_length; - if ((field->fld_dtype > dtype_any_text) && field->fld_dtype != dtype_blob) { + if ((field->fld_dtype > dtype_any_text) && field->fld_dtype != dtype_blob) + { if (field->fld_character_set || collation_name || field->fld_flags & FLD_national) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_datatype_err, gds_arg_gds, gds_collation_requires_text, 0); - + } return; } @@ -378,6 +380,7 @@ void DDL_resolve_intl_type( REQ request, FLD field, STR collation_name) { if (field->fld_sub_type_name) { + SSHORT blob_sub_type; if (!METD_get_type(request, reinterpret_cast(field->fld_sub_type_name), (UCHAR *)("RDB$FIELD_SUB_TYPE"), @@ -428,146 +431,156 @@ void DDL_resolve_intl_type( REQ request, FLD field, STR collation_name) } if (field->fld_character_set_id != 0 && !collation_name) { - /* This field has already been resolved once, and the collation hasn't - * changed. Therefore, no need to do it again. - */ + // This field has already been resolved once, and the collation + // hasn't changed. Therefore, no need to do it again. return; } if (!(field->fld_character_set || field->fld_character_set_id || /* set if a domain */ - (field->fld_flags & FLD_national))) { + (field->fld_flags & FLD_national))) + { - /* Attach the database default character set, if not otherwise specified */ + // Attach the database default character set, if not otherwise specified - if (dfl_charset = METD_get_default_charset(request)) { + STR dfl_charset = METD_get_default_charset(request); + if (dfl_charset) + { field->fld_character_set = (NOD) dfl_charset; } - else { + else + { /* If field is not specified with NATIONAL, or CHARACTER SET * treat it as a single-byte-per-character field of character set NONE. */ - if (field->fld_character_length) { + if (field->fld_character_length) + { field_length = field->fld_character_length; - if (field->fld_dtype == dtype_varying) + if (field->fld_dtype == dtype_varying) { field_length += sizeof(USHORT); + } if (field_length > (ULONG) MAX_COLUMN_SIZE) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_datatype_err, gds_arg_gds, gds_imp_exc, gds_arg_gds, gds_field_name, gds_arg_string, field->fld_name, 0); + } field->fld_length = (USHORT) field_length; }; field->fld_ttype = 0; - if (!collation_name) + if (!collation_name) { return; + } } } - if (field->fld_flags & FLD_national) + UCHAR* charset_name; + + if (field->fld_flags & FLD_national) { charset_name = (UCHAR *) NATIONAL_CHARACTER_SET; - else if (field->fld_character_set) + } else if (field->fld_character_set) { charset_name = (UCHAR *) ((STR) field->fld_character_set)->str_data; - else + } else { charset_name = (UCHAR *) NULL; + } -/* Find an intlsym for any specified character set name & collation name */ +// Find an intlsym for any specified character set name & collation name - resolved_charset = NULL; - if (charset_name) { - resolved_charset = + if (charset_name) + { + INTLSYM resolved_charset = METD_get_charset(request, - (USHORT) strlen(reinterpret_cast < - char *>(charset_name)), - charset_name); + (USHORT) strlen(reinterpret_cast(charset_name)), + charset_name); - /* Error code -204 (IBM's DB2 manual) is close enough */ + // Error code -204 (IBM's DB2 manual) is close enough if (!resolved_charset) - /* specified character set not found */ + { + // specified character set not found ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_datatype_err, gds_arg_gds, gds_charset_not_found, gds_arg_string, charset_name, 0); + } field->fld_character_set_id = resolved_charset->intlsym_charset_id; resolved_type = resolved_charset; } - resolved_collation = NULL; - if (collation_name) { - resolved_collation = METD_get_collation(request, collation_name); + if (collation_name) + { + INTLSYM resolved_collation = + METD_get_collation(request, collation_name); + if (!resolved_collation) - /* Specified collation not found */ + { + // Specified collation not found ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_datatype_err, gds_arg_gds, gds_collation_not_found, gds_arg_string, collation_name->str_data, 0); + } - /* If both specified, must be for same character set */ - /* A "literal constant" must be handled (charset as ttype_dynamic) */ + // If both specified, must be for same character set + // A "literal constant" must be handled (charset as ttype_dynamic) resolved_type = resolved_collation; if ((field->fld_character_set_id != resolved_type->intlsym_charset_id) && (field->fld_character_set_id != ttype_dynamic)) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_datatype_err, gds_arg_gds, gds_collation_not_for_charset, gds_arg_string, collation_name->str_data, 0); + } } - if (field->fld_character_length) { + if (field->fld_character_length) + { field_length = (ULONG) resolved_type->intlsym_bytes_per_char * field->fld_character_length; - if (field->fld_dtype == dtype_varying) + if (field->fld_dtype == dtype_varying) { field_length += sizeof(USHORT); + } if (field_length > (ULONG) MAX_COLUMN_SIZE) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_datatype_err, gds_arg_gds, gds_imp_exc, gds_arg_gds, gds_field_name, gds_arg_string, field->fld_name, 0); + } field->fld_length = (USHORT) field_length; }; - field->fld_ttype = resolved_type->intlsym_ttype; + field->fld_ttype = resolved_type->intlsym_ttype; field->fld_character_set_id = resolved_type->intlsym_charset_id; - field->fld_collation_id = resolved_type->intlsym_collate_id; + field->fld_collation_id = resolved_type->intlsym_collate_id; } -static void begin_blr( REQ request, UCHAR verb) +// +// Write out a string of blr as part of a ddl string, +// as in a view or computed field definition. +// +void req::begin_blr(UCHAR verb) { -/************************************** - * - * b e g i n _ b l r - * - ************************************** - * - * Function - * Write out a string of blr as part of a ddl string, - * as in a view or computed field definition. - * - **************************************/ + if (verb) { + append_uchar(verb); + } - if (verb) - STUFF(verb); + req_base_offset = req_blr - req_blr_string->str_data; - request->req_base_offset = - request->req_blr - request->req_blr_string->str_data; - -/* put in a place marker for the size of the blr, since it is unknown */ - - STUFF_WORD(0); - if (request->req_flags & REQ_blr_version4) - STUFF(blr_version4); - else - STUFF(blr_version5); + // put in a place marker for the size of the blr, since it is unknown + append_ushort(0); + append_uchar((req_flags & REQ_blr_version4) ? blr_version4 : blr_version5); } -static USHORT check_array_or_blob( NOD node) +static USHORT check_array_or_blob(NOD node) { /************************************** * @@ -582,12 +595,8 @@ static USHORT check_array_or_blob( NOD node) * definition time, rather than a runtime error at execution. * **************************************/ - MAP map; - UDF udf; - FLD fld; - NOD *ptr, *end; - BLKCHK(node, type_nod); + BLKCHK(node, dsql_type_nod); switch (node->nod_type) { case nod_agg_count: @@ -603,8 +612,10 @@ static USHORT check_array_or_blob( NOD node) return FALSE; case nod_map: - map = (MAP) node->nod_arg[e_map_map]; + { + MAP map = (MAP) node->nod_arg[e_map_map]; return check_array_or_blob(map->map_node); + } case nod_agg_max: case nod_agg_min: @@ -617,11 +628,13 @@ static USHORT check_array_or_blob( NOD node) return check_array_or_blob(node->nod_arg[0]); case nod_cast: - fld = (FLD) node->nod_arg[e_cast_target]; - if ((fld->fld_dtype == dtype_blob) || (fld->fld_dtype == dtype_array)) + { + FLD fld = (FLD) node->nod_arg[e_cast_target]; + if ((fld->fld_dtype == dtype_blob) || (fld->fld_dtype == dtype_array)) { return TRUE; - + } return check_array_or_blob(node->nod_arg[e_cast_source]); + } case nod_add: case nod_subtract: @@ -633,35 +646,45 @@ static USHORT check_array_or_blob( NOD node) case nod_multiply2: case nod_divide2: - if (check_array_or_blob(node->nod_arg[0])) + if (check_array_or_blob(node->nod_arg[0])) { return TRUE; + } return check_array_or_blob(node->nod_arg[1]); case nod_alias: return check_array_or_blob(node->nod_arg[e_alias_value]); case nod_udf: - udf = (UDF) node->nod_arg[0]; - if ((udf->udf_dtype == dtype_blob) || (udf->udf_dtype == dtype_array)) + { + UDF udf = (UDF) node->nod_arg[0]; + if ((udf->udf_dtype == dtype_blob) || (udf->udf_dtype == dtype_array)) { return TRUE; - - /* parameters to UDF don't need checking, an blob or array can be passed */ + } + // parameters to UDF don't need checking, + // an blob or array can be passed return FALSE; + } case nod_extract: case nod_list: - for (ptr = node->nod_arg, end = ptr + node->nod_count; - ptr < end; ptr++) - if (check_array_or_blob(*ptr)) + { + const NOD* end = node->nod_arg + node->nod_count; + for (NOD* ptr = node->nod_arg; ptr < end; ++ptr) + { + if (check_array_or_blob(*ptr)) { return TRUE; + } + } + } return FALSE; case nod_field: if ((node->nod_desc.dsc_dtype == dtype_blob) || (node->nod_desc.dsc_dtype == dtype_array)) + { return TRUE; - + } return FALSE; default: @@ -671,9 +694,9 @@ static USHORT check_array_or_blob( NOD node) } -static void check_constraint( - REQ request, - NOD element, SSHORT delete_trigger_required) +static void check_constraint( REQ request, + NOD element, + SSHORT delete_trigger_required) { /* ************************************* * @@ -686,57 +709,58 @@ static void check_constraint( * clause, either at the field or table level. * **************************************/ - NOD ddl_node, list_node; - NOD *errorcode_node; - ddl_node = request->req_ddl_node; - if (!(element->nod_arg[e_cnstr_table])) + NOD ddl_node = request->req_ddl_node; + + if (!(element->nod_arg[e_cnstr_table])) { element->nod_arg[e_cnstr_table] = ddl_node->nod_arg[e_drl_name]; + } -/* specify that the trigger should abort if the condition is not met */ + // specify that the trigger should abort if the condition is not met - element->nod_arg[e_cnstr_actions] = list_node = - MAKE_node(nod_list, (int) 1); + NOD list_node = MAKE_node(nod_list, (int) 1); + element->nod_arg[e_cnstr_actions] = list_node; list_node->nod_arg[0] = MAKE_node(nod_gdscode, (int) 1); - errorcode_node = &list_node->nod_arg[0]->nod_arg[0]; + + NOD* errorcode_node = &list_node->nod_arg[0]->nod_arg[0]; *errorcode_node = (NOD) MAKE_cstring("check_constraint"); element->nod_arg[e_cnstr_message] = NULL; -/* create the INSERT trigger */ + // create the INSERT trigger + +// element->nod_arg [e_cnstr_message] = +// (NOD) MAKE_cstring ("insert violates CHECK constraint on table"); -/* element->nod_arg [e_cnstr_message] = - * (NOD) MAKE_cstring ("insert violates CHECK constraint on table"); - */ element->nod_arg[e_cnstr_type] = MAKE_constant((STR) PRE_STORE_TRIGGER, 1); define_constraint_trigger(request, element); -/* create the UPDATE trigger */ + // create the UPDATE trigger + +// element->nod_arg [e_cnstr_message] = +// (NOD) MAKE_cstring ("update violates CHECK constraint on table"); -/* element->nod_arg [e_cnstr_message] = - * (NOD) MAKE_cstring ("update violates CHECK constraint on table"); - */ element->nod_arg[e_cnstr_type] = MAKE_constant((STR) PRE_MODIFY_TRIGGER, 1); define_constraint_trigger(request, element); -/* create the DELETE trigger, if required */ - - if (delete_trigger_required) { -/* - * element->nod_arg [e_cnstr_message] = - * (NOD) MAKE_cstring ("delete violates CHECK constraint on table"); - */ + // create the DELETE trigger, if required + if (delete_trigger_required) + { +// +// element->nod_arg [e_cnstr_message] = +// (NOD) MAKE_cstring ("delete violates CHECK constraint on table"); +// element->nod_arg[e_cnstr_type] = MAKE_constant((STR) PRE_ERASE_TRIGGER, 1); define_constraint_trigger(request, element); } - STUFF(gds_dyn_end); /* For CHECK constraint definition */ + request->append_uchar(gds_dyn_end); // For CHECK constraint definition } -static void create_view_triggers( REQ request, NOD element, NOD items) +static void create_view_triggers(REQ request, NOD element, NOD items) { /* Fields in the VIEW actually */ /* ************************************* * @@ -749,54 +773,57 @@ static void create_view_triggers( REQ request, NOD element, NOD items) * clause for a VIEW * **************************************/ - NOD temp, rse, base_relation, base_and_node, ddl_node, list_node; - NOD *errorcode_node; - ddl_node = request->req_ddl_node; + NOD temp, base_relation, base_and_node; - if (!(element->nod_arg[e_cnstr_table])) + NOD ddl_node = request->req_ddl_node; + + if (!(element->nod_arg[e_cnstr_table])) { element->nod_arg[e_cnstr_table] = ddl_node->nod_arg[e_drl_name]; + } -/* specify that the trigger should abort if the condition is not met */ + // specify that the trigger should abort if the condition is not met - element->nod_arg[e_cnstr_actions] = list_node = - MAKE_node(nod_list, (int) 1); + NOD list_node = MAKE_node(nod_list, (int) 1); + element->nod_arg[e_cnstr_actions] = list_node; list_node->nod_arg[0] = MAKE_node(nod_gdscode, (int) 1); - errorcode_node = &list_node->nod_arg[0]->nod_arg[0]; + + NOD* errorcode_node = &list_node->nod_arg[0]->nod_arg[0]; *errorcode_node = (NOD) MAKE_cstring("check_constraint"); element->nod_arg[e_cnstr_message] = NULL; -/* create the UPDATE trigger */ + // create the UPDATE trigger + +// element->nod_arg [e_cnstr_message] = +// (NOD) MAKE_cstring ("update violates CHECK constraint on view"); -/* element->nod_arg [e_cnstr_message] = - * (NOD) MAKE_cstring ("update violates CHECK constraint on view"); - */ element->nod_arg[e_cnstr_type] = MAKE_constant((STR) PRE_MODIFY_TRIGGER, 1); define_update_action(request, &base_and_node, &base_relation); - rse = MAKE_node(nod_rse, e_rse_count); + NOD rse = MAKE_node(nod_rse, e_rse_count); rse->nod_arg[e_rse_boolean] = base_and_node; rse->nod_arg[e_rse_streams] = temp = MAKE_node(nod_list, 1); temp->nod_arg[0] = base_relation; define_view_trigger(request, element, rse, items); -/* create the INSERT trigger */ + // create the INSERT trigger + +// element->nod_arg [e_cnstr_message] = +// (NOD) MAKE_cstring ("insert violates CHECK constraint on view"); -/* element->nod_arg [e_cnstr_message] = - * (NOD) MAKE_cstring ("insert violates CHECK constraint on view"); - */ element->nod_arg[e_cnstr_type] = MAKE_constant((STR) PRE_STORE_TRIGGER, 1); define_view_trigger(request, element, NULL, items); - STUFF(gds_dyn_end); /* For triggers definition */ + request->append_uchar(gds_dyn_end); // For triggers definition } -static void define_computed( - REQ request, - NOD relation_node, FLD field, NOD node) +static void define_computed(REQ request, + NOD relation_node, + FLD field, + NOD node) { /************************************** * @@ -809,23 +836,23 @@ static void define_computed( * or an expression index. * **************************************/ - NOD input, ddl_node; - STR source; - DSC save_desc, desc; - ddl_node = request->req_ddl_node; + NOD ddl_node = request->req_ddl_node; request->req_ddl_node = node; -/* Get the table node & set up correct context */ + // Get the table node & set up correct context - if (request->req_context_number) + if (request->req_context_number) { reset_context_stack(request); + } -/* Save the size of the field if it is specified */ + DSC save_desc; + // Save the size of the field if it is specified save_desc.dsc_dtype = 0; - if (field && field->fld_dtype) { + if (field && field->fld_dtype) + { assert(field->fld_dtype <= MAX_UCHAR); save_desc.dsc_dtype = (UCHAR) field->fld_dtype; save_desc.dsc_length = field->fld_length; @@ -839,51 +866,52 @@ static void define_computed( PASS1_make_context(request, relation_node); - input = PASS1_node(request, node->nod_arg[e_cmp_expr], 0); + NOD input = PASS1_node(request, node->nod_arg[e_cmp_expr], 0); -/* check if array or blobs are used in expression */ + // check if array or blobs are used in expression if (check_array_or_blob(input)) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_no_blob_array, 0); + } -/* generate the blr expression */ - STUFF(gds_dyn_fld_computed_blr); - begin_blr(request, 0); + // generate the blr expression + + request->append_uchar(gds_dyn_fld_computed_blr); + request->begin_blr(0); GEN_expr(request, input); - end_blr(request); - -/* try to calculate size of the computed field. The calculated size - may be ignored, but it will catch self references */ + request->end_blr(); + // try to calculate size of the computed field. The calculated size + // may be ignored, but it will catch self references + DSC desc; MAKE_desc(&desc, input); if (save_desc.dsc_dtype) { - /* restore the field size/type overrides */ - - field->fld_dtype = save_desc.dsc_dtype; + // restore the field size/type overrides + field->fld_dtype = save_desc.dsc_dtype; field->fld_length = save_desc.dsc_length; - field->fld_scale = save_desc.dsc_scale; + field->fld_scale = save_desc.dsc_scale; } else if (field) { - /* use size calculated */ - - field->fld_dtype = desc.dsc_dtype; + // use size calculated + field->fld_dtype = desc.dsc_dtype; field->fld_length = desc.dsc_length; - field->fld_scale = desc.dsc_scale; + field->fld_scale = desc.dsc_scale; } request->req_type = REQ_DDL; request->req_ddl_node = ddl_node; reset_context_stack(request); -/* generate the source text */ - - source = (STR) node->nod_arg[e_cmp_text]; + // generate the source text + STR source = (STR) node->nod_arg[e_cmp_text]; assert(source->str_length <= MAX_USHORT); - put_string(request, gds_dyn_fld_computed_source, source->str_data, - (USHORT) source->str_length); + request->append_string( gds_dyn_fld_computed_source, + reinterpret_cast(source->str_data), + (USHORT) source->str_length); } @@ -899,7 +927,6 @@ static void define_constraint_trigger(REQ request, NOD node) * Create the ddl to define or alter a constraint trigger. * **************************************/ - NOD actions, *ptr, *end, constant; /* make the "define trigger" node the current request ddl node so that generating of BLR will be appropriate for trigger */ @@ -917,59 +944,60 @@ static void define_constraint_trigger(REQ request, NOD node) assert(trigger_name->str_length <= MAX_USHORT); - put_string(request, - gds_dyn_def_trigger, - trigger_name->str_data, - (USHORT) trigger_name->str_length); + request->append_string( gds_dyn_def_trigger, + reinterpret_cast(trigger_name->str_data), + (USHORT) trigger_name->str_length); NOD relation_node = node->nod_arg[e_cnstr_table]; STR relation_name = (STR) relation_node->nod_arg[e_rln_name]; assert(trigger_name->str_length <= MAX_USHORT); - put_string(request, - gds_dyn_rel_name, - relation_name->str_data, - (USHORT) relation_name->str_length); + request->append_string( gds_dyn_rel_name, + reinterpret_cast(relation_name->str_data), + (USHORT) relation_name->str_length); STR source = (STR) node->nod_arg[e_cnstr_source]; if (source) { assert(source->str_length <= MAX_USHORT); - put_string(request, gds_dyn_trg_source, source->str_data, - (USHORT) source->str_length); + request->append_string( gds_dyn_trg_source, + reinterpret_cast(source->str_data), + (USHORT) source->str_length); } - if ((constant = node->nod_arg[e_cnstr_position]) != NULL) + NOD constant = node->nod_arg[e_cnstr_position]; + if (constant) { - put_number(request, gds_dyn_trg_sequence, + request->append_number(gds_dyn_trg_sequence, (SSHORT) (constant ? constant->nod_arg[0] : 0)); } if ((constant = node->nod_arg[e_cnstr_type]) != NULL) { const SSHORT type = (SSHORT) constant->nod_arg[0]; - put_number(request, gds_dyn_trg_type, type); + request->append_number(gds_dyn_trg_type, type); } - STUFF(gds_dyn_sql_object); + request->append_uchar(gds_dyn_sql_object); STR message = (STR) node->nod_arg[e_cnstr_message]; if (message) { - put_number(request, gds_dyn_def_trigger_msg, 0); + request->append_number(gds_dyn_def_trigger_msg, 0); assert(message->str_length <= MAX_USHORT); - put_string(request, gds_dyn_trg_msg, message->str_data, - (USHORT) message->str_length); - STUFF(gds_dyn_end); + request->append_string( gds_dyn_trg_msg, + reinterpret_cast(message->str_data), + (USHORT) message->str_length); + request->append_uchar(gds_dyn_end); } -/* generate the trigger blr */ + // generate the trigger blr if (node->nod_arg[e_cnstr_condition] && node->nod_arg[e_cnstr_actions]) { - begin_blr(request, gds_dyn_trg_blr); - STUFF(blr_begin); + request->begin_blr(gds_dyn_trg_blr); + request->append_uchar(blr_begin); /* create the "OLD" and "NEW" contexts for the trigger -- the new one could be a dummy place holder to avoid resolving @@ -985,17 +1013,19 @@ static void define_constraint_trigger(REQ request, NOD node) relation_node->nod_arg[e_rln_alias] = (NOD) MAKE_cstring(NEW_CONTEXT); PASS1_make_context(request, relation_node); - /* generate the condition for firing the trigger */ + // generate the condition for firing the trigger - STUFF(blr_if); + request->append_uchar(blr_if); GEN_expr(request, PASS1_node(request, node->nod_arg[e_cnstr_condition], 0)); - STUFF(blr_begin); - STUFF(blr_end); /* of begin */ + request->append_uchar(blr_begin); + request->append_uchar(blr_end); // of begin - /* generate the action statements for the trigger */ - actions = node->nod_arg[e_cnstr_actions]; + // generate the action statements for the trigger + NOD actions = node->nod_arg[e_cnstr_actions]; + NOD* ptr; + NOD* end; for (ptr = actions->nod_arg, end = ptr + actions->nod_count; ptr < end; ptr++) { @@ -1006,23 +1036,23 @@ static void define_constraint_trigger(REQ request, NOD node) if ((actions = node->nod_arg[e_cnstr_else]) != NULL) { - STUFF(blr_begin); + request->append_uchar(blr_begin); for (ptr = actions->nod_arg, end = ptr + actions->nod_count; ptr < end; ptr++) { GEN_statement(request, PASS1_statement(request, *ptr, 0)); } - STUFF(blr_end); /* of begin */ + request->append_uchar(blr_end); // of begin } else { - STUFF(blr_end); /* of if */ + request->append_uchar(blr_end); // of if } - end_blr(request); + request->end_blr(); } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); /* the request type may have been set incorrectly when parsing the trigger actions, so reset it to reflect the fact that this @@ -1060,9 +1090,9 @@ static void define_database( REQ request) ddl_node = request->req_ddl_node; - STUFF(gds_dyn_mod_database); + request->append_uchar(gds_dyn_mod_database); /* -put_number (request, gds_dyn_rel_sql_protection, 1); +request->append_number(gds_dyn_rel_sql_protection, 1); */ elements = ddl_node->nod_arg[e_database_initial_desc]; @@ -1084,26 +1114,22 @@ put_number (request, gds_dyn_rel_sql_protection, 1); elements = ddl_node->nod_arg[e_database_rem_desc]; if (elements) + { for (ptr = elements->nod_arg, end = ptr + elements->nod_count; - ptr < end; ptr++) { + ptr < end; ptr++) + { element = *ptr; switch (element->nod_type) { case nod_file_desc: file = (FIL) element->nod_arg[0]; - put_cstring(request, gds_dyn_def_file, - reinterpret_cast < - char *>(file->fil_name->str_data)); - STUFF(gds_dyn_file_start); - STUFF_WORD(4); + request->append_cstring(gds_dyn_def_file, + reinterpret_cast(file->fil_name->str_data)); + start = MAX(start, file->fil_start); - - STUFF_DWORD(start); - - STUFF(gds_dyn_file_length); - STUFF_WORD(4); - STUFF_DWORD(file->fil_length); - STUFF(gds_dyn_end); + request->append_file_start(start); + request->append_file_length(file->fil_length); + request->append_uchar(gds_dyn_end); start += file->fil_length; break; @@ -1111,73 +1137,65 @@ put_number (request, gds_dyn_rel_sql_protection, 1); file = (FIL) element->nod_arg[0]; if (file->fil_flags & LOG_default) { - STUFF(gds_dyn_def_default_log); + request->append_uchar(gds_dyn_def_default_log); break; } - put_cstring(request, gds_dyn_def_log_file, + request->append_cstring(gds_dyn_def_log_file, reinterpret_cast < char *>(file->fil_name->str_data)); - STUFF(gds_dyn_file_length); - STUFF_WORD(4); - STUFF_DWORD(file->fil_length); - STUFF(gds_dyn_log_file_sequence); - STUFF_WORD(2); - STUFF_WORD(number); - number++; - STUFF(gds_dyn_log_file_partitions); - STUFF_WORD(2); - STUFF_WORD(file->fil_partitions); - if (file->fil_flags & LOG_serial) - STUFF(gds_dyn_log_file_serial); - if (file->fil_flags & LOG_overflow) - STUFF(gds_dyn_log_file_overflow); - if (file->fil_flags & LOG_raw) - STUFF(gds_dyn_log_file_raw); - STUFF(gds_dyn_end); + request->append_file_length(file->fil_length); + request->append_uchar(gds_dyn_log_file_sequence); + request->append_ushort_with_length(number); + ++number; + request->append_uchar(gds_dyn_log_file_partitions); + request->append_ushort_with_length(file->fil_partitions); + if (file->fil_flags & LOG_serial) { + request->append_uchar(gds_dyn_log_file_serial); + } + if (file->fil_flags & LOG_overflow) { + request->append_uchar(gds_dyn_log_file_overflow); + } + if (file->fil_flags & LOG_raw) { + request->append_uchar(gds_dyn_log_file_raw); + } + request->append_uchar(gds_dyn_end); break; case nod_cache_file_desc: file = (FIL) element->nod_arg[0]; - put_cstring(request, gds_dyn_def_cache_file, - reinterpret_cast < - char *>(file->fil_name->str_data)); - STUFF(gds_dyn_file_length); - STUFF_WORD(4); - STUFF_DWORD(file->fil_length); - STUFF(gds_dyn_end); + request->append_cstring(gds_dyn_def_cache_file, + reinterpret_cast(file->fil_name->str_data)); + request->append_file_length(file->fil_length); + request->append_uchar(gds_dyn_end); break; case nod_group_commit_wait: - STUFF(gds_dyn_log_group_commit_wait); + request->append_uchar(gds_dyn_log_group_commit_wait); temp_long = (SLONG) (element->nod_arg[0]); - STUFF_WORD(4); - STUFF_DWORD(temp_long); + request->append_ulong_with_length(temp_long); break; case nod_check_point_len: - STUFF(gds_dyn_log_check_point_length); + request->append_uchar(gds_dyn_log_check_point_length); temp_long = (SLONG) (element->nod_arg[0]); - STUFF_WORD(4); - STUFF_DWORD(temp_long); + request->append_ulong_with_length(temp_long); break; case nod_num_log_buffers: - STUFF(gds_dyn_log_num_of_buffers); + request->append_uchar(gds_dyn_log_num_of_buffers); temp_short = (SSHORT) (element->nod_arg[0]); - STUFF_WORD(2); - STUFF_WORD(temp_short); + request->append_ushort_with_length(temp_short); break; case nod_log_buffer_size: - STUFF(gds_dyn_log_buffer_size); + request->append_uchar(gds_dyn_log_buffer_size); temp_short = (SSHORT) (element->nod_arg[0]); - STUFF_WORD(2); - STUFF_WORD(temp_short); + request->append_ushort_with_length(temp_short); break; case nod_dfl_charset: name = (STR) element->nod_arg[0]; - put_cstring(request, gds_dyn_fld_character_set_name, + request->append_cstring(gds_dyn_fld_character_set_name, reinterpret_cast(name->str_data)); break; @@ -1185,17 +1203,18 @@ put_number (request, gds_dyn_rel_sql_protection, 1); break; } } + } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void define_del_cascade_trg( - REQ request, - NOD element, - NOD for_columns, - NOD prim_columns, -TEXT * prim_rel_name, TEXT * for_rel_name) +static void define_del_cascade_trg( REQ request, + NOD element, + NOD for_columns, + NOD prim_columns, + TEXT* prim_rel_name, + TEXT* for_rel_name) { /***************************************************** * @@ -1208,54 +1227,54 @@ TEXT * prim_rel_name, TEXT * for_rel_name) * along with its blr * *****************************************************/ - USHORT num_fields = 0; - if (element->nod_type != nod_foreign) + if (element->nod_type != nod_foreign) { return; + } -/* stuff a trigger_name of size 0. So the dyn-parser will make one up. */ - put_string(request, gds_dyn_def_trigger, (UCHAR *)(""), - (USHORT) 0); + // stuff a trigger_name of size 0. So the dyn-parser will make one up. + request->append_string( gds_dyn_def_trigger, "", 0); - put_number(request, gds_dyn_trg_type, (SSHORT) POST_ERASE_TRIGGER); + request->append_number(gds_dyn_trg_type, (SSHORT) POST_ERASE_TRIGGER); - STUFF(gds_dyn_sql_object); - put_number(request, gds_dyn_trg_sequence, (SSHORT) 1); - put_number(request, gds_dyn_trg_inactive, (SSHORT) 0); - put_cstring(request, gds_dyn_rel_name, prim_rel_name); + request->append_uchar(gds_dyn_sql_object); + request->append_number(gds_dyn_trg_sequence, (SSHORT) 1); + request->append_number(gds_dyn_trg_inactive, (SSHORT) 0); + request->append_cstring(gds_dyn_rel_name, prim_rel_name); -/* the trigger blr */ - begin_blr(request, gds_dyn_trg_blr); - STUFF(blr_for); - STUFF(blr_rse); + // the trigger blr + request->begin_blr(gds_dyn_trg_blr); + request->append_uchar(blr_for); + request->append_uchar(blr_rse); -/* the context for the prim. key relation */ - STUFF(1); + // the context for the prim. key relation + request->append_uchar(1); - STUFF(blr_relation); - put_cstring(request, 0, for_rel_name); -/* the context for the foreign key relation */ - STUFF(2); + request->append_uchar(blr_relation); + request->append_cstring(0, for_rel_name); + // the context for the foreign key relation + request->append_uchar(2); stuff_matching_blr(request, for_columns, prim_columns); - STUFF(blr_erase); - STUFF((SSHORT) 2); - end_blr(request); -/* end of the blr */ + request->append_uchar(blr_erase); + request->append_uchar(2); + request->end_blr(); + // end of the blr -/* no trg_source and no trg_description */ - STUFF(gds_dyn_end); + // no trg_source and no trg_description + request->append_uchar(gds_dyn_end); } -static void define_set_default_trg( - REQ request, - NOD element, - NOD for_columns, - NOD prim_columns, -TEXT * prim_rel_name, TEXT * for_rel_name, BOOLEAN on_upd_trg) +static void define_set_default_trg( REQ request, + NOD element, + NOD for_columns, + NOD prim_columns, + TEXT* prim_rel_name, + TEXT* for_rel_name, + bool on_upd_trg) { /***************************************************** * @@ -1268,74 +1287,28 @@ TEXT * prim_rel_name, TEXT * for_rel_name, BOOLEAN on_upd_trg) * referential integrity) along with its blr * *****************************************************/ - NOD *for_key_flds; - USHORT num_fields = 0; - STR for_key_fld_name_str; + UCHAR default_val[BLOB_BUFFER_SIZE]; - BOOLEAN found_default, search_for_default; - NOD ddl_node, elem, *ptr, *end, default_node; - NOD domain_node, tmp_node; - FLD field; - STR domain_name_str; - TEXT *domain_name; - - if (element->nod_type != nod_foreign) + if (element->nod_type != nod_foreign) { return; - -/* stuff a trigger_name of size 0. So the dyn-parser will make one up. */ - put_string(request, gds_dyn_def_trigger, (UCHAR *)(""), - (USHORT) 0); - - put_number(request, gds_dyn_trg_type, - (SSHORT) (on_upd_trg ? POST_MODIFY_TRIGGER : - POST_ERASE_TRIGGER)); - - STUFF(gds_dyn_sql_object); - put_number(request, gds_dyn_trg_sequence, (SSHORT) 1); - put_number(request, gds_dyn_trg_inactive, (SSHORT) 0); - put_cstring(request, gds_dyn_rel_name, prim_rel_name); - -/* the trigger blr */ - begin_blr(request, gds_dyn_trg_blr); - -/* for ON UPDATE TRIGGER only: generate the trigger firing condition: - if prim_key.old_value != prim_key.new value. - Note that the key could consist of multiple columns */ - - if (on_upd_trg) { - stuff_trg_firing_cond(request, prim_columns); - STUFF(blr_begin); - STUFF(blr_begin); } - STUFF(blr_for); - STUFF(blr_rse); + request->generate_unnamed_trigger_beginning(on_upd_trg, + prim_rel_name, + prim_columns, + for_rel_name, + for_columns); -/* the context for the prim. key relation */ - STUFF(1); - STUFF(blr_relation); - put_cstring(request, 0, for_rel_name); -/* the context for the foreign key relation */ - STUFF(2); - - stuff_matching_blr(request, for_columns, prim_columns); - - STUFF(blr_modify); - STUFF((SSHORT) 2); - STUFF((SSHORT) 2); - STUFF(blr_begin); - - num_fields = 0; - for_key_flds = for_columns->nod_arg; - - ddl_node = request->req_ddl_node; + USHORT num_fields = 0; + NOD* for_key_flds = for_columns->nod_arg; + NOD ddl_node = request->req_ddl_node; do { /* for every column in the foreign key .... */ - for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; + STR for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; - STUFF(blr_assignment); + request->append_uchar(blr_assignment); /* here stuff the default value as blr_literal .... or blr_null if this col. does not have an applicable default */ @@ -1355,99 +1328,116 @@ TEXT * prim_rel_name, TEXT * for_rel_name, BOOLEAN on_upd_trg) default value from the system tables by calling: METD_get_col_default(). */ - found_default = FALSE; - search_for_default = TRUE; + BOOLEAN found_default = FALSE; + bool search_for_default = true; /* search the parse tree to find the column */ - elem = ddl_node->nod_arg[e_drl_elements]; - for (ptr = elem->nod_arg, end = ptr + elem->nod_count; ptr < end; - ptr++) { + NOD elem = ddl_node->nod_arg[e_drl_elements]; + NOD* end = elem->nod_arg + elem->nod_count; + for (NOD* ptr = elem->nod_arg; ptr < end; ++ptr) + { elem = *ptr; - if (elem->nod_type != nod_def_field) + if (elem->nod_type != nod_def_field) { continue; - field = (FLD) elem->nod_arg[e_dfl_field]; - if (strcmp - (field->fld_name, - reinterpret_cast < - char *>(for_key_fld_name_str->str_data))) continue; + } + + FLD field = (FLD) elem->nod_arg[e_dfl_field]; + if (strcmp(field->fld_name, + reinterpret_cast(for_key_fld_name_str->str_data))) + { + continue; + } /* Now, we have the right column in the parse tree. case (1) above */ - if ((default_node = elem->nod_arg[e_dfl_default]) != NULL) { + NOD default_node = elem->nod_arg[e_dfl_default]; + if (default_node) + { /* case (1-a) above: there is a col. level default */ GEN_expr(request, default_node); found_default = TRUE; - search_for_default = FALSE; + search_for_default = false; } - else { + else + { + TEXT* domain_name; + STR domain_name_str; + NOD domain_node; + NOD tmp_node; + if (!(domain_node = elem->nod_arg[e_dfl_domain]) || !(tmp_node = domain_node->nod_arg[e_dom_name]) || !(domain_name_str = (STR) tmp_node->nod_arg[e_fln_name]) || !(domain_name = - reinterpret_cast < - char *>(domain_name_str->str_data))) break; + reinterpret_cast(domain_name_str->str_data))) + { + break; + } /* case: (1-b): domain name is available. Column level default is not declared. so get the domain default */ METD_get_domain_default(request, domain_name, &found_default, - reinterpret_cast < - char *>(default_val), + reinterpret_cast(default_val), sizeof(default_val)); - search_for_default = FALSE; + search_for_default = false; if (found_default) + { stuff_default_blr(request, reinterpret_cast(default_val), sizeof(default_val)); + } else - /* neither col level nor domain level default exists */ - STUFF(blr_null); + { + // neither col level nor domain level default exists + request->append_uchar(blr_null); + } } break; } - if (search_for_default) { + if (search_for_default) + { /* case 2: see if the column/domain has already been created */ METD_get_col_default(request, for_rel_name, - reinterpret_cast < - char *>(for_key_fld_name_str->str_data), + reinterpret_cast(for_key_fld_name_str->str_data), &found_default, reinterpret_cast(default_val), sizeof(default_val)); - if (found_default) + if (found_default) { stuff_default_blr(request, reinterpret_cast(default_val), sizeof(default_val)); - else - STUFF(blr_null); + } else { + request->append_uchar(blr_null); + } } - /* the context for the foreign key relation */ - STUFF(blr_field); - STUFF((SSHORT) 2); - put_cstring(request, 0, - reinterpret_cast < - char *>(for_key_fld_name_str->str_data)); + // the context for the foreign key relation + request->append_uchar(blr_field); + request->append_uchar(2); + request->append_cstring(0, + reinterpret_cast(for_key_fld_name_str->str_data)); num_fields++; for_key_flds++; - } - while (num_fields < for_columns->nod_count); - STUFF(blr_end); + + } while (num_fields < for_columns->nod_count); + + request->append_uchar(blr_end); if (on_upd_trg) { - STUFF(blr_end); - STUFF(blr_end); - STUFF(blr_end); + request->append_uchars(blr_end, 3); } - end_blr(request); -/* no trg_source and no trg_description */ - STUFF(gds_dyn_end); + request->end_blr(); + + // no trg_source and no trg_description + request->append_uchar(gds_dyn_end); } @@ -1463,12 +1453,9 @@ static void define_dimensions( REQ request, FLD field) * Define dimensions of an array * **************************************/ - NOD elements, element; - USHORT dims; - SLONG lrange, hrange; - elements = field->fld_ranges; - dims = elements->nod_count / 2; + NOD elements = field->fld_ranges; + USHORT dims = elements->nod_count / 2; if (dims > MAX_ARRAY_DIMENSIONS) { @@ -1476,25 +1463,23 @@ static void define_dimensions( REQ request, FLD field) gds_arg_gds, gds_dsql_max_arr_dim_exceeded, 0); } - put_number(request, gds_dyn_fld_dimensions, (SSHORT) dims); + request->append_number(gds_dyn_fld_dimensions, (SSHORT) dims); SSHORT position = 0; NOD* ptr = elements->nod_arg; NOD* end = ptr + elements->nod_count; for (; ptr < end; ++ptr, ++position) { - put_number(request, gds_dyn_def_dimension, position); - element = *ptr++; - STUFF(gds_dyn_dim_lower); - lrange = (SLONG) (element->nod_arg[0]); - STUFF_WORD(4); - STUFF_DWORD(lrange); + request->append_number(gds_dyn_def_dimension, position); + NOD element = *ptr++; + request->append_uchar(gds_dyn_dim_lower); + SLONG lrange = (SLONG) (element->nod_arg[0]); + request->append_ulong_with_length(lrange); element = *ptr; - STUFF(gds_dyn_dim_upper); - hrange = (SLONG) (element->nod_arg[0]); - STUFF_WORD(4); - STUFF_DWORD(hrange); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_dim_upper); + SLONG hrange = (SLONG) (element->nod_arg[0]); + request->append_ulong_with_length(hrange); + request->append_uchar(gds_dyn_end); if (lrange >= hrange) { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 604, @@ -1504,7 +1489,7 @@ static void define_dimensions( REQ request, FLD field) } -static void define_domain( REQ request) +static void define_domain(REQ request) { /************************************** * @@ -1516,38 +1501,36 @@ static void define_domain( REQ request) * Define a domain (global field) * **************************************/ - NOD node; - STR string; - BOOLEAN null_flag = FALSE; - BOOLEAN check_flag = FALSE; + + bool null_flag = false; + bool check_flag = false; NOD element = request->req_ddl_node; FLD field = (FLD) element->nod_arg[e_dom_name]; - put_cstring(request, gds_dyn_def_global_fld, field->fld_name); + request->append_cstring(gds_dyn_def_global_fld, field->fld_name); DDL_resolve_intl_type(request, field, (STR) element->nod_arg[e_dom_collate]); put_field(request, field, FALSE); -/* check for a default value */ + // check for a default value - node = element->nod_arg[e_dom_default]; + NOD node = element->nod_arg[e_dom_default]; if (node) { node = PASS1_node(request, node, 0); - begin_blr(request, gds_dyn_fld_default_value); + request->begin_blr(gds_dyn_fld_default_value); GEN_expr(request, node); - end_blr(request); + request->end_blr(); - string = (STR) element->nod_arg[e_dom_default_source]; + STR string = (STR) element->nod_arg[e_dom_default_source]; if (string) { assert(string->str_length <= MAX_USHORT); - put_string(request, - gds_dyn_fld_default_source, - string->str_data, - (USHORT) string->str_length); + request->append_string( gds_dyn_fld_default_source, + reinterpret_cast(string->str_data), + (USHORT) string->str_length); } } @@ -1556,7 +1539,7 @@ static void define_domain( REQ request) define_dimensions(request, field); } -/* check for constraints */ + // check for constraints node = element->nod_arg[e_dom_constraint]; if (node) { @@ -1569,10 +1552,10 @@ static void define_domain( REQ request) NOD node1 = (*ptr)->nod_arg[e_rct_type]; if (node1->nod_type == nod_null) { - if (!(null_flag)) + if (!null_flag) { - STUFF(gds_dyn_fld_not_null); - null_flag = TRUE; + request->append_uchar(gds_dyn_fld_not_null); + null_flag = true; } else { @@ -1590,18 +1573,17 @@ static void define_domain( REQ request) gds_arg_string, "DOMAIN CHECK CONSTRAINT", 0); } - check_flag = TRUE; + check_flag = true; - string = (STR) node1->nod_arg[e_cnstr_source]; + STR string = (STR) node1->nod_arg[e_cnstr_source]; if (string) { assert(string->str_length <= MAX_USHORT); - put_string(request, - gds_dyn_fld_validation_source, - string->str_data, - (USHORT) string->str_length); + request->append_string( gds_dyn_fld_validation_source, + reinterpret_cast(string->str_data), + (USHORT) string->str_length); } - begin_blr(request, gds_dyn_fld_validation_blr); + request->begin_blr(gds_dyn_fld_validation_blr); /* Set any VALUE nodes to the type of the domain being defined. */ if (node1->nod_arg[e_cnstr_condition]) @@ -1627,13 +1609,13 @@ static void define_domain( REQ request) node1->nod_arg[e_cnstr_condition], 0)); - end_blr(request); + request->end_blr(); } } } } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -1657,20 +1639,21 @@ static void define_exception( REQ request, NOD_TYPE op) text = (STR) ddl_node->nod_arg[e_xcp_text]; if (op == nod_def_exception) - put_cstring(request, gds_dyn_def_exception, + request->append_cstring(gds_dyn_def_exception, reinterpret_cast(name->str_data)); else if (op == nod_mod_exception) - put_cstring(request, gds_dyn_mod_exception, + request->append_cstring(gds_dyn_mod_exception, reinterpret_cast(name->str_data)); else - put_cstring(request, gds_dyn_del_exception, + request->append_cstring(gds_dyn_del_exception, reinterpret_cast(name->str_data)); if (op != nod_del_exception) { assert(text->str_length <= MAX_USHORT); - put_string(request, gds_dyn_xcp_msg, text->str_data, - (USHORT) text->str_length); - STUFF(gds_dyn_end); + request->append_string( gds_dyn_xcp_msg, + reinterpret_cast(text->str_data), + (USHORT) text->str_length); + request->append_uchar(gds_dyn_end); } } @@ -1690,13 +1673,13 @@ static void define_field( * table or an alter table statement. * **************************************/ - NOD domain_node, node, node1, *ptr, *end_ptr; + NOD domain_node, node, node1, *ptr; FLD field; DSQL_REL relation; STR string, domain_name; USHORT cnstrt_flag = FALSE; NOD computed_node; - BOOLEAN default_null_flag = FALSE; + bool default_null_flag = false; field = (FLD) element->nod_arg[e_dfl_field]; @@ -1708,10 +1691,10 @@ static void define_field( } if (domain_node = element->nod_arg[e_dfl_domain]) { - put_cstring(request, gds_dyn_def_local_fld, field->fld_name); + request->append_cstring(gds_dyn_def_local_fld, field->fld_name); node1 = domain_node->nod_arg[e_dom_name]; domain_name = (STR) node1->nod_arg[e_fln_name]; - put_cstring(request, gds_dyn_fld_source, + request->append_cstring(gds_dyn_fld_source, reinterpret_cast(domain_name->str_data)); /* Get the domain information */ @@ -1727,17 +1710,20 @@ static void define_field( field, reinterpret_cast(element->nod_arg[e_dfl_collate])); if (element->nod_arg[e_dfl_collate]) { - put_number(request, gds_dyn_fld_collation, + request->append_number(gds_dyn_fld_collation, field->fld_collation_id); } } - else { - put_cstring(request, gds_dyn_def_sql_fld, field->fld_name); - if (relation_name) - put_cstring(request, gds_dyn_rel_name, + else + { + request->append_cstring(gds_dyn_def_sql_fld, field->fld_name); + if (relation_name) { + request->append_cstring(gds_dyn_rel_name, reinterpret_cast(relation_name->str_data)); + } - if (element->nod_arg[e_dfl_computed]) { + if (element->nod_arg[e_dfl_computed]) + { field->fld_flags |= FLD_computed; computed_node = element->nod_arg[e_dfl_computed]; define_computed(request, @@ -1751,90 +1737,102 @@ static void define_field( } if (position != -1) - put_number(request, gds_dyn_fld_position, position); + request->append_number(gds_dyn_fld_position, position); -/* check for a default value */ + // check for a default value - if ((node = element->nod_arg[e_dfl_default]) != NULL) { + node = element->nod_arg[e_dfl_default]; + if (node) + { node = PASS1_node(request, node, 0); - begin_blr(request, gds_dyn_fld_default_value); - if (node->nod_type == nod_null) - default_null_flag = TRUE; + request->begin_blr(gds_dyn_fld_default_value); + if (node->nod_type == nod_null) { + default_null_flag = true; + } GEN_expr(request, node); - end_blr(request); - if ((string = (STR) element->nod_arg[e_dfl_default_source]) != NULL) { + request->end_blr(); + string = (STR) element->nod_arg[e_dfl_default_source]; + if (string) + { assert(string->str_length <= MAX_USHORT); - put_string(request, gds_dyn_fld_default_source, string->str_data, - (USHORT) string->str_length); + request->append_string( gds_dyn_fld_default_source, + reinterpret_cast(string->str_data), + (USHORT) string->str_length); } } - if (field->fld_ranges) + if (field->fld_ranges) { define_dimensions(request, field); + } /* check for constraints */ - if (node = element->nod_arg[e_dfl_constraint]) { - for (ptr = node->nod_arg, end_ptr = ptr + node->nod_count; - ptr < end_ptr; ptr++) { - if ((*ptr)->nod_type == nod_rel_constraint) { + if (node = element->nod_arg[e_dfl_constraint]) + { + NOD* end_ptr = node->nod_arg + node->nod_count; + for (ptr = node->nod_arg; ptr < end_ptr; ++ptr) + { + if ((*ptr)->nod_type == nod_rel_constraint) + { string = (STR) (*ptr)->nod_arg[e_rct_name]; node1 = (*ptr)->nod_arg[e_rct_type]; - if (node1->nod_type == nod_null) { - if (default_null_flag == TRUE) + if (node1->nod_type == nod_null) + { + if (default_null_flag) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, isc_bad_default_value, gds_arg_gds, isc_invalid_clause, gds_arg_string, "default null not null", 0); - STUFF(gds_dyn_fld_not_null); + } + request->append_uchar(gds_dyn_fld_not_null); if (cnstrt_flag == FALSE) { - STUFF(gds_dyn_end); /* For field definition */ + request->append_uchar(gds_dyn_end); /* For field definition */ cnstrt_flag = TRUE; } - put_cstring(request, gds_dyn_rel_constraint, - reinterpret_cast < - char *>((string) ? string->str_data : NULL)); - STUFF(gds_dyn_fld_not_null); - STUFF(gds_dyn_end); /* For NOT NULL Constraint definition */ + request->append_cstring(gds_dyn_rel_constraint, + reinterpret_cast((string) ? + string->str_data : NULL)); + request->append_uchar(gds_dyn_fld_not_null); + request->append_uchar(gds_dyn_end); /* For NOT NULL Constraint definition */ } else if (node1->nod_type == nod_primary - || node1->nod_type == nod_unique) { - if (cnstrt_flag == FALSE) { - STUFF(gds_dyn_end); /* For field definition */ + || node1->nod_type == nod_unique) + { + if (cnstrt_flag == FALSE) + { + request->append_uchar(gds_dyn_end); /* For field definition */ cnstrt_flag = TRUE; } - put_cstring(request, gds_dyn_rel_constraint, - reinterpret_cast < - char *>((string) ? string->str_data : NULL)); - if (node1->nod_type == nod_primary) - STUFF(gds_dyn_def_primary_key); - else if (node1->nod_type == nod_unique) - STUFF(gds_dyn_def_unique); - - STUFF_WORD(0); /* So index name is generated */ - put_number(request, gds_dyn_idx_unique, 1); - put_cstring(request, gds_dyn_fld_name, field->fld_name); - STUFF(gds_dyn_end); + request->append_cstring(gds_dyn_rel_constraint, + reinterpret_cast((string) ? string->str_data : NULL)); + if (node1->nod_type == nod_primary) { + request->append_uchar(gds_dyn_def_primary_key); + } else if (node1->nod_type == nod_unique) { + request->append_uchar(gds_dyn_def_unique); + } + request->append_ushort(0); /* So index name is generated */ + request->append_number(gds_dyn_idx_unique, 1); + request->append_cstring(gds_dyn_fld_name, field->fld_name); + request->append_uchar(gds_dyn_end); } else if (node1->nod_type == nod_foreign) { if (cnstrt_flag == FALSE) { - STUFF(gds_dyn_end); /* For field definition */ + request->append_uchar(gds_dyn_end); /* For field definition */ cnstrt_flag = TRUE; } - put_cstring(request, gds_dyn_rel_constraint, - reinterpret_cast < - char *>((string) ? string->str_data : NULL)); + request->append_cstring(gds_dyn_rel_constraint, + reinterpret_cast((string) ? string->str_data : NULL)); foreign_key(request, node1); } else if (node1->nod_type == nod_def_constraint) { if (cnstrt_flag == FALSE) { - STUFF(gds_dyn_end); /* For field definition */ + request->append_uchar(gds_dyn_end); /* For field definition */ cnstrt_flag = TRUE; } - put_cstring(request, gds_dyn_rel_constraint, - reinterpret_cast < - char *>((string) ? string->str_data : NULL)); + request->append_cstring(gds_dyn_rel_constraint, + reinterpret_cast((string) ? string->str_data : NULL)); check_constraint(request, node1, FALSE /* No delete trigger */ ); } @@ -1842,8 +1840,9 @@ static void define_field( } } - if (cnstrt_flag == FALSE) - STUFF(gds_dyn_end); + if (cnstrt_flag == FALSE) { + request->append_uchar(gds_dyn_end); + } } @@ -1863,21 +1862,18 @@ static void define_filter( REQ request) filter_node = request->req_ddl_node; ptr = filter_node->nod_arg; - put_cstring(request, gds_dyn_def_filter, - reinterpret_cast < - char *>(((STR) (ptr[e_filter_name]))->str_data)); - put_number(request, gds_dyn_filter_in_subtype, + request->append_cstring(gds_dyn_def_filter, + reinterpret_cast(((STR) (ptr[e_filter_name]))->str_data)); + request->append_number(gds_dyn_filter_in_subtype, (SSHORT) ((ptr[e_filter_in_type])->nod_arg[0])); - put_number(request, gds_dyn_filter_out_subtype, + request->append_number(gds_dyn_filter_out_subtype, (SSHORT) ((ptr[e_filter_out_type])->nod_arg[0])); - put_cstring(request, gds_dyn_func_entry_point, - reinterpret_cast < - char *>(((STR) (ptr[e_filter_entry_pt]))->str_data)); - put_cstring(request, gds_dyn_func_module_name, - reinterpret_cast < - char *>(((STR) (ptr[e_filter_module]))->str_data)); + request->append_cstring(gds_dyn_func_entry_point, + reinterpret_cast(((STR) (ptr[e_filter_entry_pt]))->str_data)); + request->append_cstring(gds_dyn_func_module_name, + reinterpret_cast(((STR) (ptr[e_filter_module]))->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -1893,16 +1889,15 @@ static void define_generator( REQ request) * create a generator. * **************************************/ - STR gen_name; - gen_name = (STR) request->req_ddl_node->nod_arg[e_gen_name]; - put_cstring(request, gds_dyn_def_generator, + STR gen_name = (STR) request->req_ddl_node->nod_arg[e_gen_name]; + request->append_cstring(gds_dyn_def_generator, reinterpret_cast(gen_name->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void define_index( REQ request) +static void define_index(REQ request) { /************************************** * @@ -1917,7 +1912,7 @@ static void define_index( REQ request) NOD ddl_node, relation_node, field_list, *ptr, *end; STR relation_name, index_name; - STUFF(gds_dyn_begin); + request->append_uchar(gds_dyn_begin); ddl_node = request->req_ddl_node; relation_node = (NOD) ddl_node->nod_arg[e_idx_table]; @@ -1925,9 +1920,9 @@ static void define_index( REQ request) field_list = ddl_node->nod_arg[e_idx_fields]; index_name = (STR) ddl_node->nod_arg[e_idx_name]; - put_cstring(request, gds_dyn_def_idx, + request->append_cstring(gds_dyn_def_idx, reinterpret_cast(index_name->str_data)); - put_cstring(request, gds_dyn_rel_name, + request->append_cstring(gds_dyn_rel_name, reinterpret_cast(relation_name->str_data)); /* go through the fields list, making an index segment for each field, @@ -1936,9 +1931,8 @@ static void define_index( REQ request) if (field_list->nod_type == nod_list) for (ptr = field_list->nod_arg, end = ptr + field_list->nod_count; ptr < end; ptr++) - put_cstring(request, gds_dyn_fld_name, - reinterpret_cast < - char *>(((STR) (*ptr)->nod_arg[1])->str_data)); + request->append_cstring(gds_dyn_fld_name, + reinterpret_cast(((STR) (*ptr)->nod_arg[1])->str_data)); #ifdef EXPRESSION_INDICES else if (field_list->nod_type == nod_def_computed) define_computed(request, relation_node, NULL, field_list); @@ -1946,14 +1940,16 @@ static void define_index( REQ request) /* check for a unique index */ - if (ddl_node->nod_arg[e_idx_unique]) - put_number(request, gds_dyn_idx_unique, 1); + if (ddl_node->nod_arg[e_idx_unique]) { + request->append_number(gds_dyn_idx_unique, 1); + } - if (ddl_node->nod_arg[e_idx_asc_dsc]) - put_number(request, gds_dyn_idx_type, 1); + if (ddl_node->nod_arg[e_idx_asc_dsc]) { + request->append_number(gds_dyn_idx_type, 1); + } - STUFF(gds_dyn_end); /* of define index */ - STUFF(gds_dyn_end); /* of begin */ + request->append_uchar(gds_dyn_end); /* of define index */ + request->append_uchar(gds_dyn_end); /* of begin */ } @@ -1976,7 +1972,7 @@ static NOD define_insert_action( REQ request) NOD select_node, select_expr, from_list, relation_node; NOD fields_node, values_node, field_node, value_node; NOD *ptr, *end, *ptr2, *end2; - LLS field_stack, value_stack; + DLLS field_stack, value_stack; DSQL_REL relation; FLD field; @@ -2081,53 +2077,62 @@ static void define_procedure( REQ request, NOD_TYPE op) * Create DYN to store a procedure * **************************************/ - NOD parameters, parameter, *ptr, *end, procedure_node; - STR procedure_name, source; + NOD parameters, parameter, *ptr, *end; PRC procedure; FLD field, *field_ptr; - SSHORT position, inputs, outputs, locals; + SSHORT position; VAR variable; - TSQL tdsql; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; - inputs = outputs = locals = 0; - procedure_node = request->req_ddl_node; - procedure_name = (STR) procedure_node->nod_arg[e_prc_name]; - if (op == nod_def_procedure) { - put_cstring(request, gds_dyn_def_procedure, + SSHORT inputs = 0; + SSHORT outputs = 0; + SSHORT locals = 0; + NOD procedure_node = request->req_ddl_node; + STR procedure_name = (STR) procedure_node->nod_arg[e_prc_name]; + + if (op == nod_def_procedure) + { + request->append_cstring(gds_dyn_def_procedure, reinterpret_cast(procedure_name->str_data)); - put_number(request, gds_dyn_rel_sql_protection, 1); + request->append_number(gds_dyn_rel_sql_protection, 1); } - else { - put_cstring(request, gds_dyn_mod_procedure, + else + { + request->append_cstring(gds_dyn_mod_procedure, reinterpret_cast(procedure_name->str_data)); - if (procedure = METD_get_procedure(request, procedure_name)) { + procedure = METD_get_procedure(request, procedure_name); + if (procedure) + { for (field = procedure->prc_inputs; field; - field = field->fld_next) { - put_cstring(request, gds_dyn_delete_parameter, + field = field->fld_next) + { + request->append_cstring(gds_dyn_delete_parameter, field->fld_name); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } for (field = procedure->prc_outputs; field; - field = field->fld_next) { - put_cstring(request, gds_dyn_delete_parameter, + field = field->fld_next) + { + request->append_cstring(gds_dyn_delete_parameter, field->fld_name); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } } } - if ((source = (STR) procedure_node->nod_arg[e_prc_source]) != NULL) { + + STR source = (STR) procedure_node->nod_arg[e_prc_source]; + if (source) + { assert(source->str_length <= MAX_USHORT); - put_string(request, gds_dyn_prc_source, source->str_data, - (USHORT) source->str_length); + request->append_string( gds_dyn_prc_source, + reinterpret_cast(source->str_data), + (USHORT) source->str_length); } /* Fill req_procedure to allow procedure to self reference */ - procedure = - (PRC) ALLOCDV(type_prc, - strlen(reinterpret_cast < - char *>(procedure_name->str_data)) + 1); + procedure = new(*tdsql->tsql_default, + strlen(reinterpret_cast(procedure_name->str_data))) prc; procedure->prc_name = procedure->prc_data; procedure->prc_owner = procedure->prc_data + procedure_name->str_length + 1; @@ -2140,16 +2145,18 @@ static void define_procedure( REQ request, NOD_TYPE op) field_ptr = &procedure->prc_inputs; - if (parameters = procedure_node->nod_arg[e_prc_inputs]) { + if (parameters = procedure_node->nod_arg[e_prc_inputs]) + { position = 0; for (ptr = parameters->nod_arg, end = ptr + parameters->nod_count; - ptr < end; ptr++) { + ptr < end; ptr++) + { parameter = *ptr; field = (FLD) parameter->nod_arg[e_dfl_field]; - put_cstring(request, gds_dyn_def_parameter, field->fld_name); - put_number(request, gds_dyn_prm_number, position); - put_number(request, gds_dyn_prm_type, 0); + request->append_cstring(gds_dyn_def_parameter, field->fld_name); + request->append_number(gds_dyn_prm_number, position); + request->append_number(gds_dyn_prm_type, 0); DDL_resolve_intl_type(request, field, NULL); put_field(request, field, FALSE); @@ -2162,8 +2169,8 @@ static void define_procedure( REQ request, NOD_TYPE op) field_ptr = &field->fld_next; position++; - STUFF(gds_dyn_end); - put_number(request, gds_dyn_prc_inputs, position); + request->append_uchar(gds_dyn_end); + request->append_number(gds_dyn_prc_inputs, position); } inputs = position; } @@ -2175,15 +2182,17 @@ static void define_procedure( REQ request, NOD_TYPE op) /* now do the output parameters */ field_ptr = &procedure->prc_outputs; - if (parameters = procedure_node->nod_arg[e_prc_outputs]) { + if (parameters = procedure_node->nod_arg[e_prc_outputs]) + { position = 0; - for (ptr = parameters->nod_arg, end = ptr + parameters->nod_count; - ptr < end; ptr++) { + end = parameters->nod_arg + parameters->nod_count; + for (ptr = parameters->nod_arg; ptr < end; ++ptr) + { parameter = *ptr; field = (FLD) parameter->nod_arg[e_dfl_field]; - put_cstring(request, gds_dyn_def_parameter, field->fld_name); - put_number(request, gds_dyn_prm_number, position); - put_number(request, gds_dyn_prm_type, 1); + request->append_cstring(gds_dyn_def_parameter, field->fld_name); + request->append_number(gds_dyn_prm_number, position); + request->append_number(gds_dyn_prm_type, 1); DDL_resolve_intl_type(request, field, NULL); put_field(request, field, FALSE); @@ -2195,8 +2204,8 @@ static void define_procedure( REQ request, NOD_TYPE op) position++; locals++; - STUFF(gds_dyn_end); - put_number(request, gds_dyn_prc_outputs, position); + request->append_uchar(gds_dyn_end); + request->append_number(gds_dyn_prc_outputs, position); } outputs = position; } @@ -2205,28 +2214,32 @@ static void define_procedure( REQ request, NOD_TYPE op) procedure->prc_out_count = outputs; procedure->prc_in_count = inputs; - begin_blr(request, gds_dyn_prc_blr); - STUFF(blr_begin); - if (inputs) { - STUFF(blr_message); - STUFF(0); - STUFF_WORD(2 * inputs); + request->begin_blr(gds_dyn_prc_blr); + request->append_uchar(blr_begin); + if (inputs) + { + request->append_uchar(blr_message); + request->append_uchar(0); + request->append_ushort(2 * inputs); parameters = procedure_node->nod_arg[e_prc_inputs]; for (ptr = parameters->nod_arg, end = ptr + parameters->nod_count; - ptr < end; ptr++) { + ptr < end; ptr++) + { parameter = *ptr; variable = (VAR) parameter->nod_arg[e_var_variable]; field = variable->var_field; put_msg_field(request, field); } } - STUFF(blr_message); - STUFF(1); - STUFF_WORD(2 * outputs + 1); - if (outputs) { + request->append_uchar(blr_message); + request->append_uchar(1); + request->append_ushort(2 * outputs + 1); + if (outputs) + { parameters = procedure_node->nod_arg[e_prc_outputs]; for (ptr = parameters->nod_arg, end = ptr + parameters->nod_count; - ptr < end; ptr++) { + ptr < end; ptr++) + { parameter = *ptr; variable = (VAR) parameter->nod_arg[e_var_variable]; field = variable->var_field; @@ -2236,18 +2249,20 @@ static void define_procedure( REQ request, NOD_TYPE op) /* add slot for EOS */ - STUFF(blr_short); - STUFF(0); + request->append_uchar(blr_short); + request->append_uchar(0); if (inputs) { - STUFF(blr_receive); - STUFF(0); + request->append_uchar(blr_receive); + request->append_uchar(0); } - STUFF(blr_begin); - if (outputs) { + request->append_uchar(blr_begin); + if (outputs) + { parameters = procedure_node->nod_arg[e_prc_outputs]; for (ptr = parameters->nod_arg, end = ptr + parameters->nod_count; - ptr < end; ptr++) { + ptr < end; ptr++) + { parameter = *ptr; variable = (VAR) parameter->nod_arg[e_var_variable]; put_local_variable(request, variable); @@ -2257,22 +2272,22 @@ static void define_procedure( REQ request, NOD_TYPE op) locals = put_local_variables(request, procedure_node->nod_arg[e_prc_dcls], locals); - STUFF(blr_stall); + request->append_uchar(blr_stall); /* Put a label before body of procedure, so that any exit statement can get out */ - STUFF(blr_label); - STUFF(0); + request->append_uchar(blr_label); + request->append_uchar(0); request->req_loop_number = 1; GEN_statement(request, PASS1_statement(request, procedure_node->nod_arg[e_prc_body], 1)); request->req_type = REQ_DDL; - STUFF(blr_end); + request->append_uchar(blr_end); GEN_return(request, procedure_node, TRUE); - STUFF(blr_end); - end_blr(request); + request->append_uchar(blr_end); + request->end_blr(); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -2293,7 +2308,7 @@ static void define_rel_constraint( REQ request, NOD element) STR string; string = (STR) element->nod_arg[e_rct_name]; - put_cstring(request, gds_dyn_rel_constraint, + request->append_cstring(gds_dyn_rel_constraint, reinterpret_cast < char *>((string) ? string->str_data : NULL)); node = element->nod_arg[e_rct_type]; @@ -2328,13 +2343,15 @@ static void define_relation( REQ request) relation_node = ddl_node->nod_arg[e_drl_name]; relation_name = (STR) relation_node->nod_arg[e_rln_name]; - put_cstring(request, gds_dyn_def_rel, + request->append_cstring(gds_dyn_def_rel, reinterpret_cast(relation_name->str_data)); if (external_file = (STR) ddl_node->nod_arg[e_drl_ext_file]) - put_cstring(request, gds_dyn_rel_ext_file, + { + request->append_cstring(gds_dyn_rel_ext_file, reinterpret_cast(external_file->str_data)); + } save_relation(request, relation_name); - put_number(request, gds_dyn_rel_sql_protection, 1); + request->append_number(gds_dyn_rel_sql_protection, 1); /* now do the actual metadata definition */ @@ -2357,37 +2374,29 @@ static void define_relation( REQ request) } } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void define_role( REQ request) +// +// Create a SQL role. +// +static void define_role(REQ request) { -/************************************** - * - * d e f i n e _ r o l e - * - ************************************** - * - * Function - * create a SQL role. - * - **************************************/ - STR gen_name; - - gen_name = (STR) request->req_ddl_node->nod_arg[e_gen_name]; - put_cstring(request, isc_dyn_def_sql_role, - reinterpret_cast(gen_name->str_data)); - STUFF(gds_dyn_end); + STR gen_name = (STR) request->req_ddl_node->nod_arg[e_gen_name]; + request->append_cstring(isc_dyn_def_sql_role, + reinterpret_cast(gen_name->str_data)); + request->append_uchar(gds_dyn_end); } -static void define_set_null_trg( - REQ request, - NOD element, - NOD for_columns, - NOD prim_columns, -TEXT * prim_rel_name, TEXT * for_rel_name, BOOLEAN on_upd_trg) +static void define_set_null_trg(REQ request, + NOD element, + NOD for_columns, + NOD prim_columns, + TEXT* prim_rel_name, + TEXT* for_rel_name, + bool on_upd_trg) { /***************************************************** * @@ -2402,228 +2411,172 @@ TEXT * prim_rel_name, TEXT * for_rel_name, BOOLEAN on_upd_trg) * The on_upd_trg parameter == TRUE is an update trigger. * *****************************************************/ - NOD *for_key_flds; - USHORT num_fields = 0; - STR for_key_fld_name_str; - - if (element->nod_type != nod_foreign) + if (element->nod_type != nod_foreign) { return; + } -/* count of foreign key columns */ + // count of foreign key columns assert(prim_columns->nod_count == for_columns->nod_count); assert(prim_columns->nod_count != 0); -/* no trigger name. It is generated by the engine */ - put_string(request, gds_dyn_def_trigger, (UCHAR *)(""), - (USHORT) 0); + request->generate_unnamed_trigger_beginning(on_upd_trg, + prim_rel_name, + prim_columns, + for_rel_name, + for_columns); - put_number(request, gds_dyn_trg_type, - (SSHORT) (on_upd_trg ? POST_MODIFY_TRIGGER : - POST_ERASE_TRIGGER)); - - STUFF(gds_dyn_sql_object); - put_number(request, gds_dyn_trg_sequence, (SSHORT) 1); - put_number(request, gds_dyn_trg_inactive, (SSHORT) 0); - put_cstring(request, gds_dyn_rel_name, prim_rel_name); - -/* the trigger blr */ - begin_blr(request, gds_dyn_trg_blr); - -/* for ON UPDATE TRIGGER only: generate the trigger firing condition: - if prim_key.old_value != prim_key.new value. - Note that the key could consist of multiple columns */ - - if (on_upd_trg) { - stuff_trg_firing_cond(request, prim_columns); - STUFF(blr_begin); - STUFF(blr_begin); - } - - STUFF(blr_for); - STUFF(blr_rse); - -/* the context for the prim. key relation */ - STUFF(1); - - STUFF(blr_relation); - put_cstring(request, 0, for_rel_name); -/* the context for the foreign key relation */ - STUFF(2); - - stuff_matching_blr(request, for_columns, prim_columns); - - STUFF(blr_modify); - STUFF((SSHORT) 2); - STUFF((SSHORT) 2); - STUFF(blr_begin); - - num_fields = 0; - for_key_flds = for_columns->nod_arg; + USHORT num_fields = 0; + NOD* for_key_flds = for_columns->nod_arg; do { - for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; + STR for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; - STUFF(blr_assignment); - STUFF(blr_null); - STUFF(blr_field); - STUFF((SSHORT) 2); - put_cstring(request, 0, - reinterpret_cast < - char *>(for_key_fld_name_str->str_data)); + request->append_uchar(blr_assignment); + request->append_uchar(blr_null); + request->append_uchar(blr_field); + request->append_uchar(2); + request->append_cstring(0, + reinterpret_cast(for_key_fld_name_str->str_data)); num_fields++; for_key_flds++; - } - while (num_fields < for_columns->nod_count); - STUFF(blr_end); + + } while (num_fields < for_columns->nod_count); + + request->append_uchar(blr_end); if (on_upd_trg) { - STUFF(blr_end); - STUFF(blr_end); - STUFF(blr_end); + request->append_uchars(blr_end, 3); } - end_blr(request); -/* end of the blr */ + request->end_blr(); + // end of the blr -/* no trg_source and no trg_description */ - STUFF(gds_dyn_end); + // no trg_source and no trg_description + request->append_uchar(gds_dyn_end); } -static void define_shadow( REQ request) +// +// create a shadow for the database +// +static void define_shadow(REQ request) { -/************************************** - * - * d e f i n e _ s h a d o w - * - ************************************** - * - * Function - * create a shadow for the database - * - **************************************/ - NOD shadow_node, elements, element, *ptr, *end; - SLONG start; - FIL file; - SLONG length; + NOD shadow_node = request->req_ddl_node; + NOD* ptr = shadow_node->nod_arg; - shadow_node = request->req_ddl_node; - ptr = shadow_node->nod_arg; if (!ptr[e_shadow_number]) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_dsql_shadow_number_err, 0); + } - put_number(request, gds_dyn_def_shadow, (SSHORT) (ptr[e_shadow_number])); - put_cstring(request, gds_dyn_def_file, - reinterpret_cast < - char *>(((STR) (ptr[e_shadow_name]))->str_data)); - put_number(request, gds_dyn_shadow_man_auto, + request->append_number(gds_dyn_def_shadow, (SSHORT) (ptr[e_shadow_number])); + request->append_cstring(gds_dyn_def_file, + reinterpret_cast(((STR) (ptr[e_shadow_name]))->str_data)); + request->append_number(gds_dyn_shadow_man_auto, (SSHORT) ((ptr[e_shadow_man_auto])->nod_arg[0])); - put_number(request, gds_dyn_shadow_conditional, + request->append_number(gds_dyn_shadow_conditional, (SSHORT) ((ptr[e_shadow_conditional])->nod_arg[0])); - STUFF(gds_dyn_file_start); - STUFF_WORD(4); - STUFF_DWORD(0); + request->append_file_start(0); - length = (SLONG) ptr[e_shadow_length]; - STUFF(gds_dyn_file_length); - STUFF_WORD(4); - STUFF_DWORD(length); + SLONG length = (SLONG) ptr[e_shadow_length]; + request->append_file_length(length); - STUFF(gds_dyn_end); - elements = ptr[e_shadow_sec_files]; + request->append_uchar(gds_dyn_end); + NOD elements = ptr[e_shadow_sec_files]; if (elements) - for (ptr = elements->nod_arg, end = ptr + elements->nod_count; - ptr < end; ptr++) { - element = *ptr; - file = (FIL) element->nod_arg[0]; - put_cstring(request, gds_dyn_def_file, + { + NOD* end = elements->nod_arg + elements->nod_count; + for (ptr = elements->nod_arg; ptr < end; ++ptr) + { + NOD element = *ptr; + FIL file = (FIL) element->nod_arg[0]; + request->append_cstring(gds_dyn_def_file, reinterpret_cast(file->fil_name->str_data)); if (!length && !file->fil_start) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_dsql_file_length_err, gds_arg_number, (SLONG) file->fil_name->str_data, /* Preceding file did not specify length, so %s must include starting page number */ 0); + } - STUFF(gds_dyn_file_start); - STUFF_WORD(4); - start = file->fil_start; - STUFF_DWORD(start); - STUFF(gds_dyn_file_length); - STUFF_WORD(4); + SLONG start = file->fil_start; + request->append_file_start(start); length = file->fil_length; - STUFF_DWORD(length); - STUFF(gds_dyn_end); + request->append_file_length(length); + request->append_uchar(gds_dyn_end); } + } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } +// +// Create the ddl to define or alter a trigger. +// static void define_trigger( REQ request, NOD node) { -/************************************** - * - * d e f i n e _ t r i g g e r - * - ************************************** - * - * Function - * Create the ddl to define or alter a trigger. - * - **************************************/ - STR trigger_name, relation_name, source, message_text; - NOD temp, actions, *ptr, *end, constant, relation_node, message; - SSHORT number; + STR relation_name; + NOD temp, constant, relation_node; USHORT trig_type; - TSQL tdsql; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; -/* make the "define trigger" node the current request ddl node so - that generating of BLR will be appropriate for trigger */ + // make the "define trigger" node the current request ddl node so + // that generating of BLR will be appropriate for trigger request->req_ddl_node = node; - trigger_name = (STR) node->nod_arg[e_trg_name]; + STR trigger_name = (STR) node->nod_arg[e_trg_name]; - if (node->nod_type == nod_def_trigger) { + if (node->nod_type == nod_def_trigger) + { assert(trigger_name->str_length <= MAX_USHORT); - put_string(request, gds_dyn_def_trigger, trigger_name->str_data, - (USHORT) trigger_name->str_length); + request->append_string( gds_dyn_def_trigger, + reinterpret_cast(trigger_name->str_data), + (USHORT) trigger_name->str_length); relation_node = node->nod_arg[e_trg_table]; relation_name = (STR) relation_node->nod_arg[e_rln_name]; assert(relation_name->str_length <= MAX_USHORT); - put_string(request, gds_dyn_rel_name, relation_name->str_data, - (USHORT) relation_name->str_length); - STUFF(gds_dyn_sql_object); + request->append_string( gds_dyn_rel_name, + reinterpret_cast(relation_name->str_data), + (USHORT) relation_name->str_length); + request->append_uchar(gds_dyn_sql_object); } - else { /* if (node->nod_type == nod_mod_trigger) */ + else + { /* if (node->nod_type == nod_mod_trigger) */ assert(node->nod_type == nod_mod_trigger); assert(trigger_name->str_length <= MAX_USHORT); - put_string(request, gds_dyn_mod_trigger, trigger_name->str_data, - (USHORT) trigger_name->str_length); - if (node->nod_arg[e_trg_actions]) { + request->append_string( gds_dyn_mod_trigger, + reinterpret_cast(trigger_name->str_data), + (USHORT) trigger_name->str_length); + if (node->nod_arg[e_trg_actions]) + { /* Since we will be updating the body of the trigger, we need to know what relation the trigger relates to. */ - if (! - (relation_name = - METD_get_trigger_relation(request, trigger_name, - &trig_type))) + relation_name = + METD_get_trigger_relation( request, + trigger_name, + &trig_type); + if (!relation_name) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_trigger_err, gds_arg_gds, gds_random, gds_arg_string, trigger_name->str_data, 0); - relation_node = (NOD) ALLOCDV(type_nod, e_rln_count); + } + relation_node = new(*tdsql->tsql_default, e_rln_count) nod; node->nod_arg[e_trg_table] = relation_node; relation_node->nod_type = nod_relation_name; relation_node->nod_count = e_rln_count; @@ -2631,40 +2584,43 @@ static void define_trigger( REQ request, NOD node) } } - source = (STR) node->nod_arg[e_trg_source]; - actions = (node->nod_arg[e_trg_actions]) ? + STR source = (STR) node->nod_arg[e_trg_source]; + NOD actions = (node->nod_arg[e_trg_actions]) ? node->nod_arg[e_trg_actions]->nod_arg[1] : NULL; if (source && actions) { assert(source->str_length <= MAX_USHORT); - put_string(request, gds_dyn_trg_source, source->str_data, - (USHORT) source->str_length); + request->append_string( gds_dyn_trg_source, + reinterpret_cast(source->str_data), + (USHORT) source->str_length); } if (constant = node->nod_arg[e_trg_active]) - put_number(request, gds_dyn_trg_inactive, + request->append_number(gds_dyn_trg_inactive, (SSHORT) constant->nod_arg[0]); if (constant = node->nod_arg[e_trg_position]) - put_number(request, gds_dyn_trg_sequence, + request->append_number(gds_dyn_trg_sequence, (SSHORT) constant->nod_arg[0]); if (constant = node->nod_arg[e_trg_type]) { - put_number(request, gds_dyn_trg_type, (SSHORT) constant->nod_arg[0]); + request->append_number(gds_dyn_trg_type, (SSHORT) constant->nod_arg[0]); trig_type = (USHORT) constant->nod_arg[0]; } else { assert(node->nod_type == nod_mod_trigger); } - if (actions) { + if (actions) + { /* create the "OLD" and "NEW" contexts for the trigger -- the new one could be a dummy place holder to avoid resolving fields to that context but prevent relations referenced in the trigger actions from referencing the predefined "1" context */ - if (request->req_context_number) + if (request->req_context_number) { reset_context_stack(request); + } temp = relation_node->nod_arg[e_rln_alias]; if ((trig_type != PRE_STORE_TRIGGER) @@ -2676,21 +2632,23 @@ static void define_trigger( REQ request, NOD node) else request->req_context_number++; - if ((trig_type != PRE_ERASE_TRIGGER) - && (trig_type != POST_ERASE_TRIGGER)) { + if (trig_type != PRE_ERASE_TRIGGER && trig_type != POST_ERASE_TRIGGER) + { relation_node->nod_arg[e_rln_alias] = (NOD) MAKE_cstring(NEW_CONTEXT); PASS1_make_context(request, relation_node); } else + { request->req_context_number++; + } relation_node->nod_arg[e_rln_alias] = temp; - /* generate the trigger blr */ + // generate the trigger blr - begin_blr(request, gds_dyn_trg_blr); - STUFF(blr_begin); + request->begin_blr(gds_dyn_trg_blr); + request->append_uchar(blr_begin); put_local_variables(request, node->nod_arg[e_trg_actions]->nod_arg[0], 0); @@ -2698,8 +2656,8 @@ static void define_trigger( REQ request, NOD node) request->req_scope_level++; GEN_statement(request, PASS1_statement(request, actions, 1)); request->req_scope_level--; - STUFF(blr_end); - end_blr(request); + request->append_uchar(blr_end); + request->end_blr(); /* the request type may have been set incorrectly when parsing the trigger actions, so reset it to reflect the fact that this @@ -2709,28 +2667,35 @@ static void define_trigger( REQ request, NOD node) } if (temp = node->nod_arg[e_trg_messages]) - for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; - ptr++) { - message = *ptr; - number = (SSHORT) message->nod_arg[e_msg_number]; - if (message->nod_type == nod_del_trigger_msg) { - put_number(request, gds_dyn_delete_trigger_msg, number); - STUFF(gds_dyn_end); + { + NOD* end = temp->nod_arg + temp->nod_count; + for (NOD* ptr = temp->nod_arg; ptr < end; ++ptr) + { + NOD message = *ptr; + SSHORT number = (SSHORT) message->nod_arg[e_msg_number]; + if (message->nod_type == nod_del_trigger_msg) + { + request->append_number(gds_dyn_delete_trigger_msg, number); + request->append_uchar(gds_dyn_end); } - else { - message_text = (STR) message->nod_arg[e_msg_text]; - if (message->nod_type == nod_def_trigger_msg) - put_number(request, gds_dyn_def_trigger_msg, number); - else - put_number(request, gds_dyn_mod_trigger_msg, number); + else + { + STR message_text = (STR) message->nod_arg[e_msg_text]; + if (message->nod_type == nod_def_trigger_msg) { + request->append_number(gds_dyn_def_trigger_msg, number); + } else { + request->append_number(gds_dyn_mod_trigger_msg, number); + } assert(message_text->str_length <= MAX_USHORT); - put_string(request, gds_dyn_trg_msg, message_text->str_data, - (USHORT) message_text->str_length); - STUFF(gds_dyn_end); + request->append_string( gds_dyn_trg_msg, + reinterpret_cast(message_text->str_data), + (USHORT) message_text->str_length); + request->append_uchar(gds_dyn_end); } } + } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -2755,12 +2720,12 @@ static void define_udf( REQ request) arguments = udf_node->nod_arg[e_udf_args]; ptr = udf_node->nod_arg; udf_name = ((STR) (ptr[e_udf_name]))->str_data; - put_cstring(request, gds_dyn_def_function, + request->append_cstring(gds_dyn_def_function, reinterpret_cast(udf_name)); - put_cstring(request, gds_dyn_func_entry_point, + request->append_cstring(gds_dyn_func_entry_point, reinterpret_cast < char *>(((STR) (ptr[e_udf_entry_pt]))->str_data)); - put_cstring(request, gds_dyn_func_module_name, + request->append_cstring(gds_dyn_func_module_name, reinterpret_cast < char *>(((STR) (ptr[e_udf_module]))->str_data)); @@ -2777,29 +2742,36 @@ static void define_udf( REQ request) field->fld_dtype == dtype_cstring || field->fld_dtype == dtype_blob || field->fld_dtype == dtype_timestamp)) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_return_mode_err, /* Return mode by value not allowed for this data type */ 0); + } /* For functions returning a blob, coerce return argument position to be the last parameter. */ - if (field->fld_dtype == dtype_blob) { + if (field->fld_dtype == dtype_blob) + { blob_position = (arguments) ? arguments->nod_count + 1 : 1; if (blob_position > MAX_UDF_ARGUMENTS) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_extern_func_err, /* External functions can not have more than 10 parameters */ /* Or 9 if the function returns a BLOB */ 0); + } - put_number(request, gds_dyn_func_return_argument, blob_position); + request->append_number(gds_dyn_func_return_argument, blob_position); } else - put_number(request, gds_dyn_func_return_argument, (SSHORT) 0); + { + request->append_number(gds_dyn_func_return_argument, (SSHORT) 0); + } position = 0; } @@ -2808,70 +2780,84 @@ static void define_udf( REQ request) /* Function modifies an argument whose value is the function return value */ if (!arguments || position > arguments->nod_count || position < 1) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_extern_func_err, /* External functions can not have more than 10 parameters */ /* Not strictly correct -- return position error */ 0); + } - put_number(request, gds_dyn_func_return_argument, position); + request->append_number(gds_dyn_func_return_argument, position); position = 1; } /* Now define all the arguments */ - if (!position) { - if (field->fld_dtype == dtype_blob) { + if (!position) + { + if (field->fld_dtype == dtype_blob) + { BOOLEAN free_it = ((SSHORT) ret_val_ptr[1]->nod_arg[0] < 0); - put_number(request, gds_dyn_def_function_arg, blob_position); - put_number(request, gds_dyn_func_mechanism, + request->append_number(gds_dyn_def_function_arg, blob_position); + request->append_number(gds_dyn_func_mechanism, (SSHORT) ((free_it ? -1 : 1) * FUN_blob_struct)); /* if we have the free_it set then the blob has to be freed on return */ } - else { - put_number(request, gds_dyn_def_function_arg, (SSHORT) 0); - put_number(request, gds_dyn_func_mechanism, + else + { + request->append_number(gds_dyn_def_function_arg, (SSHORT) 0); + request->append_number(gds_dyn_func_mechanism, (SSHORT) (ret_val_ptr[1]->nod_arg[0])); } - put_cstring(request, gds_dyn_function_name, + request->append_cstring(gds_dyn_function_name, reinterpret_cast(udf_name)); DDL_resolve_intl_type(request, field, NULL); put_field(request, field, TRUE); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); position = 1; } assert(position == 1); if (arguments) + { for (ptr = arguments->nod_arg, end = ptr + arguments->nod_count; - ptr < end; ptr++, position++) { + ptr < end; ptr++, position++) + { if (position > MAX_UDF_ARGUMENTS) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_extern_func_err, /* External functions can not have more than 10 parameters */ 0); + } field = (FLD) * ptr; - put_number(request, gds_dyn_def_function_arg, (SSHORT) position); + request->append_number(gds_dyn_def_function_arg, (SSHORT) position); if (field->fld_dtype == dtype_blob) - put_number(request, gds_dyn_func_mechanism, + { + request->append_number(gds_dyn_func_mechanism, (SSHORT) FUN_blob_struct); + } else - put_number(request, gds_dyn_func_mechanism, + { + request->append_number(gds_dyn_func_mechanism, (SSHORT) FUN_reference); + } - put_cstring(request, gds_dyn_function_name, + request->append_cstring(gds_dyn_function_name, reinterpret_cast(udf_name)); DDL_resolve_intl_type(request, field, NULL); put_field(request, field, TRUE); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } + } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -2898,7 +2884,7 @@ static void define_update_action( NOD fields_node, values_node, field_node, value_node, old_value_node; NOD *ptr, *end, *ptr2, *end2; NOD iand_node, or_node, anull_node, bnull_node; - LLS field_stack; + DLLS field_stack; DSQL_REL relation; FLD field; SSHORT and_arg = 0; @@ -3021,12 +3007,12 @@ static void define_update_action( } -static void define_upd_cascade_trg( - REQ request, - NOD element, - NOD for_columns, - NOD prim_columns, -TEXT * prim_rel_name, TEXT * for_rel_name) +static void define_upd_cascade_trg( REQ request, + NOD element, + NOD for_columns, + NOD prim_columns, + TEXT* prim_rel_name, + TEXT* for_rel_name) { /***************************************************** * @@ -3039,91 +3025,51 @@ TEXT * prim_rel_name, TEXT * for_rel_name) * along with the trigger blr. * *****************************************************/ - NOD *for_key_flds, *prim_key_flds; - USHORT num_fields = 0; - STR for_key_fld_name_str, prim_key_fld_name_str; - if (element->nod_type != nod_foreign) + if (element->nod_type != nod_foreign) { return; + } -/* count of foreign key columns */ + // count of foreign key columns assert(prim_columns->nod_count == for_columns->nod_count); assert(prim_columns->nod_count != 0); -/* no trigger name is generated here. Let the engine make one up */ - put_string(request, gds_dyn_def_trigger, (UCHAR *)(""), - (USHORT) 0); + request->generate_unnamed_trigger_beginning(true, + prim_rel_name, + prim_columns, + for_rel_name, + for_columns); - put_number(request, gds_dyn_trg_type, (SSHORT) POST_MODIFY_TRIGGER); - - STUFF(gds_dyn_sql_object); - put_number(request, gds_dyn_trg_sequence, (SSHORT) 1); - put_number(request, gds_dyn_trg_inactive, (SSHORT) 0); - put_cstring(request, gds_dyn_rel_name, prim_rel_name); - -/* the trigger blr */ - begin_blr(request, gds_dyn_trg_blr); - -/* generate the trigger firing condition: foreign_key == primary_key */ - stuff_trg_firing_cond(request, prim_columns); - - STUFF(blr_begin); - STUFF(blr_begin); - - STUFF(blr_for); - STUFF(blr_rse); - -/* the new context for the prim. key relation */ - STUFF(1); - - STUFF(blr_relation); - put_cstring(request, 0, for_rel_name); -/* the context for the foreign key relation */ - STUFF(2); - -/* generate the blr for: foreign_key == primary_key */ - stuff_matching_blr(request, for_columns, prim_columns); - - STUFF(blr_modify); - STUFF((SSHORT) 2); - STUFF((SSHORT) 2); - STUFF(blr_begin); - - num_fields = 0; - for_key_flds = for_columns->nod_arg; - prim_key_flds = prim_columns->nod_arg; + USHORT num_fields = 0; + NOD* for_key_flds = for_columns->nod_arg; + NOD* prim_key_flds = prim_columns->nod_arg; do { - for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; - prim_key_fld_name_str = (STR) (*prim_key_flds)->nod_arg[1]; + STR for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; + STR prim_key_fld_name_str = (STR) (*prim_key_flds)->nod_arg[1]; - STUFF(blr_assignment); - STUFF(blr_field); - STUFF((SSHORT) 1); - put_cstring(request, 0, - reinterpret_cast < - char *>(prim_key_fld_name_str->str_data)); - STUFF(blr_field); - STUFF((SSHORT) 2); - put_cstring(request, 0, - reinterpret_cast < - char *>(for_key_fld_name_str->str_data)); + request->append_uchar(blr_assignment); + request->append_uchar(blr_field); + request->append_uchar(1); + request->append_cstring(0, + reinterpret_cast(prim_key_fld_name_str->str_data)); + request->append_uchar(blr_field); + request->append_uchar(2); + request->append_cstring(0, + reinterpret_cast(for_key_fld_name_str->str_data)); num_fields++; prim_key_flds++; for_key_flds++; - } - while (num_fields < for_columns->nod_count); - STUFF(blr_end); - STUFF(blr_end); - STUFF(blr_end); - STUFF(blr_end); - end_blr(request); -/* end of the blr */ + } while (num_fields < for_columns->nod_count); -/* no trg_source and no trg_description */ - STUFF(gds_dyn_end); + request->append_uchars(blr_end, 4); + request->end_blr(); + // end of the blr + + // no trg_source and no trg_description + request->append_uchar(gds_dyn_end); } @@ -3151,14 +3097,14 @@ static void define_view( REQ request) STR view_name, field_name, source; SSHORT position, updatable = TRUE; TEXT *field_string; - LLS temp; + DLLS temp; node = request->req_ddl_node; view_name = (STR) node->nod_arg[e_view_name]; - put_cstring(request, gds_dyn_def_view, + request->append_cstring(gds_dyn_def_view, reinterpret_cast(view_name->str_data)); save_relation(request, view_name); - put_number(request, gds_dyn_rel_sql_protection, 1); + request->append_number(gds_dyn_rel_sql_protection, 1); /* compile the SELECT statement into a record selection expression, making sure to bump the context number since view contexts start @@ -3172,11 +3118,11 @@ static void define_view( REQ request) select_expr = select->nod_arg[0]; rse = PASS1_rse(request, select_expr, select->nod_arg[1]); -/* store the blr and source string for the view definition */ + // store the blr and source string for the view definition - begin_blr(request, gds_dyn_view_blr); + request->begin_blr(gds_dyn_view_blr); GEN_expr(request, rse); - end_blr(request); + request->end_blr(); /* Store source for view. gdef -e cannot cope with it. We need to add something to rdb$views to indicate source type. @@ -3184,20 +3130,23 @@ static void define_view( REQ request) source = (STR) node->nod_arg[e_view_source]; assert(source->str_length <= MAX_USHORT); - put_string(request, gds_dyn_view_source, source->str_data, - (USHORT) source->str_length); + request->append_string( gds_dyn_view_source, + reinterpret_cast(source->str_data), + (USHORT) source->str_length); /* define the view source relations from the request contexts */ - for (temp = request->req_context; temp; temp = temp->lls_next) { + for (temp = request->req_context; temp; temp = temp->lls_next) + { context = (CTX) temp->lls_object; - if (relation = context->ctx_relation) { - put_cstring(request, gds_dyn_view_relation, relation->rel_name); - put_number(request, gds_dyn_view_context, context->ctx_context); - put_cstring(request, gds_dyn_view_context_name, + if (relation = context->ctx_relation) + { + request->append_cstring(gds_dyn_view_relation, relation->rel_name); + request->append_number(gds_dyn_view_context, context->ctx_context); + request->append_cstring(gds_dyn_view_context_name, context->ctx_alias ? context->ctx_alias : relation-> rel_name); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } } @@ -3236,17 +3185,21 @@ static void define_view( REQ request) /* if this is an expression, check to make sure there is a name specified */ if (!ptr && !field) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_specify_field_err, /* must specify field name for view select expression */ 0); + } /* determine the proper field name, replacing the default if necessary */ - if (field) + if (field) { field_string = field->fld_name; - if (ptr && ptr < end) { + } + if (ptr && ptr < end) + { field_name = (STR) (*ptr)->nod_arg[1]; field_string = (TEXT *) field_name->str_data; ptr++; @@ -3255,60 +3208,73 @@ static void define_view( REQ request) /* if not an expression, point to the proper base relation field, else make up an SQL field with generated global field for calculations */ - if (field) { - put_cstring(request, gds_dyn_def_local_fld, field_string); - put_cstring(request, gds_dyn_fld_base_fld, field->fld_name); - put_number(request, gds_dyn_view_context, context->ctx_context); + if (field) + { + request->append_cstring(gds_dyn_def_local_fld, field_string); + request->append_cstring(gds_dyn_fld_base_fld, field->fld_name); + request->append_number(gds_dyn_view_context, context->ctx_context); } - else { - put_cstring(request, gds_dyn_def_sql_fld, field_string); + else + { + request->append_cstring(gds_dyn_def_sql_fld, field_string); MAKE_desc(&field_node->nod_desc, field_node); put_descriptor(request, &field_node->nod_desc); - begin_blr(request, gds_dyn_fld_computed_blr); + request->begin_blr(gds_dyn_fld_computed_blr); GEN_expr(request, field_node); - end_blr(request); - put_number(request, gds_dyn_view_context, (SSHORT) 0); + request->end_blr(); + request->append_number(gds_dyn_view_context, (SSHORT) 0); } save_field(request, field_string); - put_number(request, gds_dyn_fld_position, position); - STUFF(gds_dyn_end); + request->append_number(gds_dyn_fld_position, position); + request->append_uchar(gds_dyn_end); } if (ptr != end) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_num_field_err, /* number of fields does not match select list */ 0); + } -/* setup to define triggers for WITH CHECK OPTION */ + // setup to define triggers for WITH CHECK OPTION - if ((check = node->nod_arg[e_view_check]) != NULL) { + check = node->nod_arg[e_view_check]; + + if (check) + { if (!updatable) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_col_name_err, /* Only simple column names permitted for VIEW WITH CHECK OPTION */ 0); + } if (select_expr->nod_count != 1) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_table_view_err, /* Only one table allowed for VIEW WITH CHECK OPTION */ 0); + } /* Handle VIEWS with UNION : nod_select now points to nod_list which in turn points to nod_select_expr */ else if (select_expr->nod_arg[0]->nod_arg[e_sel_from]->nod_count != 1) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_table_view_err, /* Only one table allowed for VIEW WITH CHECK OPTION */ 0); + } /* Handle VIEWS with UNION : nod_select now points to nod_list @@ -3316,21 +3282,25 @@ static void define_view( REQ request) */ select_expr = select_expr->nod_arg[0]; if (!(select_expr->nod_arg[e_sel_where])) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_where_err, /* No where clause for VIEW WITH CHECK OPTION */ 0); + } if (select_expr->nod_arg[e_sel_distinct] || select_expr->nod_arg[e_sel_group] || select_expr->nod_arg[e_sel_having]) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_distinct_err, /* DISTINCT, GROUP or HAVING not permitted for VIEW WITH CHECK OPTION */ 0); + } relation_node = MAKE_node(nod_relation_name, e_rln_count); relation_node->nod_arg[e_rln_name] = (NOD) view_name; @@ -3349,7 +3319,7 @@ static void define_view( REQ request) create_view_triggers(request, check, rse->nod_arg[e_rse_items]); } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); reset_context_stack(request); } @@ -3366,13 +3336,13 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) * Create the ddl to define a trigger for a VIEW WITH CHECK OPTION. * **************************************/ - STR trigger_name, relation_name, message; + STR trigger_name, relation_name; NOD temp_rse, temp, ddl_node, actions, *ptr, *end, constant; NOD relation_node; USHORT trig_type; NOD action_node, condition, select, select_expr, view_fields; CTX context, sav_context = 0; - LLS stack; + DLLS stack; TSQL tdsql; tdsql = GET_THREAD_DATA; @@ -3394,49 +3364,64 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) trigger_name = (STR) node->nod_arg[e_cnstr_name]; - if (node->nod_type == nod_def_constraint) { + if (node->nod_type == nod_def_constraint) + { assert(trigger_name->str_length <= MAX_USHORT); - put_string(request, gds_dyn_def_trigger, trigger_name->str_data, - (USHORT) trigger_name->str_length); + request->append_string( gds_dyn_def_trigger, + reinterpret_cast(trigger_name->str_data), + (USHORT) trigger_name->str_length); relation_node = node->nod_arg[e_cnstr_table]; relation_name = (STR) relation_node->nod_arg[e_rln_name]; assert(relation_name->str_length <= MAX_USHORT); - put_string(request, gds_dyn_rel_name, relation_name->str_data, - (USHORT) relation_name->str_length); + request->append_string( gds_dyn_rel_name, + reinterpret_cast(relation_name->str_data), + (USHORT) relation_name->str_length); } else + { return; - - if ((constant = node->nod_arg[e_cnstr_position]) != NULL) - put_number(request, gds_dyn_trg_sequence, - (SSHORT) (constant ? constant->nod_arg[0] : 0)); - - if ((constant = node->nod_arg[e_cnstr_type]) != NULL) { - trig_type = (USHORT) constant->nod_arg[0]; - put_number(request, gds_dyn_trg_type, trig_type); } - else { + + constant = node->nod_arg[e_cnstr_position]; + if (constant) + { + request->append_number(gds_dyn_trg_sequence, + (SSHORT) (constant ? constant->nod_arg[0] : 0)); + } + + constant = node->nod_arg[e_cnstr_type]; + if (constant) + { + trig_type = (USHORT) constant->nod_arg[0]; + request->append_number(gds_dyn_trg_type, trig_type); + } + else + { /* If we don't have a trigger type assigned, then this is just a template definition for use with domains. The real triggers are defined when the domain is used. */ trig_type = 0; } - STUFF(gds_dyn_sql_object); + request->append_uchar(gds_dyn_sql_object); - if ((message = (STR) node->nod_arg[e_cnstr_message]) != NULL) { - put_number(request, gds_dyn_def_trigger_msg, 0); + STR message = (STR) node->nod_arg[e_cnstr_message]; + if (message) + { + request->append_number(gds_dyn_def_trigger_msg, 0); assert(message->str_length <= MAX_USHORT); - put_string(request, gds_dyn_trg_msg, message->str_data, - (USHORT) message->str_length); - STUFF(gds_dyn_end); + request->append_string( gds_dyn_trg_msg, + reinterpret_cast(message->str_data), + (USHORT) message->str_length); + request->append_uchar(gds_dyn_end); } -/* generate the trigger blr */ + // generate the trigger blr - if (node->nod_arg[e_cnstr_condition] && node->nod_arg[e_cnstr_actions]) { - begin_blr(request, gds_dyn_trg_blr); - STUFF(blr_begin); + if (node->nod_arg[e_cnstr_condition] && node->nod_arg[e_cnstr_actions]) + { + request->begin_blr(gds_dyn_trg_blr); + request->append_uchar(blr_begin); /* create the "OLD" and "NEW" contexts for the trigger -- the new one could be a dummy place holder to avoid resolving @@ -3450,7 +3435,7 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) stack = request->req_context; context = (CTX) stack->lls_object; if (context->ctx_alias) { - sav_context = (CTX) ALLOCD(type_ctx); + sav_context = new(*tdsql->tsql_default) ctx; *sav_context = *context; } } @@ -3469,7 +3454,7 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) } if (trig_type == PRE_MODIFY_TRIGGER) { - STUFF(blr_for); + request->append_uchar(blr_for); temp = rse->nod_arg[e_rse_streams]; temp->nod_arg[0] = PASS1_node(request, temp->nod_arg[0], 0); temp = rse->nod_arg[e_rse_boolean]; @@ -3480,11 +3465,11 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) condition->nod_arg[0] = replace_field_names(select_expr->nod_arg[e_sel_where], items, view_fields, FALSE); - STUFF(blr_begin); - STUFF(blr_if); + request->append_uchar(blr_begin); + request->append_uchar(blr_if); GEN_expr(request, PASS1_node(request, condition->nod_arg[0], 0)); - STUFF(blr_begin); - STUFF(blr_end); + request->append_uchar(blr_begin); + request->append_uchar(blr_end); } if (trig_type == PRE_STORE_TRIGGER) { @@ -3492,10 +3477,10 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) condition->nod_arg[0] = replace_field_names(select_expr->nod_arg[e_sel_where], items, view_fields, TRUE); - STUFF(blr_if); + request->append_uchar(blr_if); GEN_expr(request, PASS1_node(request, condition->nod_arg[0], 0)); - STUFF(blr_begin); - STUFF(blr_end); + request->append_uchar(blr_begin); + request->append_uchar(blr_end); } /* generate the action statements for the trigger */ @@ -3503,32 +3488,39 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) actions = node->nod_arg[e_cnstr_actions]; for (ptr = actions->nod_arg, end = ptr + actions->nod_count; ptr < end; ptr++) + { GEN_statement(request, PASS1_statement(request, *ptr, 0)); + } - /* generate the action statements for the trigger */ + // generate the action statements for the trigger - if ((actions = node->nod_arg[e_cnstr_else]) != NULL) { - STUFF(blr_begin); + actions = node->nod_arg[e_cnstr_else]; + if (actions) + { + request->append_uchar(blr_begin); for (ptr = actions->nod_arg, end = ptr + actions->nod_count; - ptr < end; ptr++) { + ptr < end; ptr++) + { action_node = PASS1_statement(request, *ptr, 0); - if (action_node->nod_type == nod_modify) { + if (action_node->nod_type == nod_modify) + { temp_rse = action_node->nod_arg[e_mod_rse]; temp_rse->nod_arg[e_rse_first] = MAKE_constant((STR) 1, 1); } GEN_statement(request, action_node); } - STUFF(blr_end); /* of begin */ + request->append_uchar(blr_end); /* of begin */ } - STUFF(blr_end); /* of if */ - if (trig_type == PRE_MODIFY_TRIGGER) - STUFF(blr_end); /* of for */ - end_blr(request); + request->append_uchar(blr_end); /* of if */ + if (trig_type == PRE_MODIFY_TRIGGER) { + request->append_uchar(blr_end); /* of for */ + } + request->end_blr(); } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); /* the request type may have been set incorrectly when parsing the trigger actions, so reset it to reflect the fact that this @@ -3540,28 +3532,18 @@ static void define_view_trigger( REQ request, NOD node, NOD rse, NOD items) } -static void end_blr( REQ request) +// +// Complete the stuffing of a piece of +// blr by going back and inserting the length. +// +void req::end_blr() { -/************************************** - * - * e n d _ b l r - * - ************************************** - * - * Function - * Complete the stuffing of a piece of - * blr by going back and inserting the length. - * - **************************************/ - UCHAR *blr_base; - USHORT length; + append_uchar(blr_eoc); - STUFF(blr_eoc); + // go back and stuff in the proper length -/* go back and stuff in the proper length */ - - blr_base = request->req_blr_string->str_data + request->req_base_offset; - length = (SSHORT) (request->req_blr - blr_base) - 2; + UCHAR* blr_base = req_blr_string->str_data + req_base_offset; + USHORT length = (SSHORT) (req_blr - blr_base) - 2; *blr_base++ = (UCHAR) length; *blr_base = (UCHAR) (length >> 8); } @@ -3591,7 +3573,8 @@ static void foreign_key( REQ request, NOD element) /* If there is a referenced table name but no referenced field names, the primary key of the referenced table designates the referenced fields. */ - if (!(columns2 = element->nod_arg[e_for_refcolumns])) { + if (!(columns2 = element->nod_arg[e_for_refcolumns])) + { element->nod_arg[e_for_refcolumns] = columns2 = METD_get_primary_key(request, relation2); @@ -3599,20 +3582,24 @@ static void foreign_key( REQ request, NOD element) the referenced table have a primary key to serve as the implicitly referenced field, fail. */ if (!columns2) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_reftable_requires_pk, /* "REFERENCES table" without "(column)" requires PRIMARY KEY on referenced table */ 0); + } } if (columns2 && (columns1->nod_count != columns2->nod_count)) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_key_field_count_err, /* foreign key field count does not match primary key */ 0); + } /* define the foreign key index and the triggers that may be needed for referential integrity action. */ @@ -3687,44 +3674,44 @@ static void generate_dyn( REQ request, NOD node) case nod_del_domain: string = (STR) node->nod_arg[0]; - put_cstring(request, gds_dyn_delete_global_fld, + request->append_cstring(gds_dyn_delete_global_fld, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_del_index: string = (STR) node->nod_arg[0]; - put_cstring(request, gds_dyn_delete_idx, + request->append_cstring(gds_dyn_delete_idx, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_del_relation: string = (STR) node->nod_arg[0]; - put_cstring(request, gds_dyn_delete_rel, + request->append_cstring(gds_dyn_delete_rel, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_del_procedure: string = (STR) node->nod_arg[0]; - put_cstring(request, gds_dyn_delete_procedure, + request->append_cstring(gds_dyn_delete_procedure, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_del_trigger: string = (STR) node->nod_arg[0]; - put_cstring(request, gds_dyn_delete_trigger, + request->append_cstring(gds_dyn_delete_trigger, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_del_role: string = (STR) node->nod_arg[0]; - put_cstring(request, isc_dyn_del_sql_role, + request->append_cstring(isc_dyn_del_sql_role, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_grant: @@ -3747,15 +3734,15 @@ static void generate_dyn( REQ request, NOD node) case nod_del_generator: string = (STR) node->nod_arg[0]; /**********FIX -- nothing like delete_generator exists as yet - put_cstring (request, gds_dyn_def_generator, string->str_data); + request->append_cstring(gds_dyn_def_generator, string->str_data); STUFF (gds_dyn_end); */ break; case nod_del_filter: string = (STR) node->nod_arg[0]; - put_cstring(request, gds_dyn_delete_filter, + request->append_cstring(gds_dyn_delete_filter, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_def_udf: @@ -3764,9 +3751,9 @@ static void generate_dyn( REQ request, NOD node) case nod_del_udf: string = (STR) node->nod_arg[0]; - put_cstring(request, gds_dyn_delete_function, + request->append_cstring(gds_dyn_delete_function, reinterpret_cast(string->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_def_shadow: @@ -3774,9 +3761,9 @@ static void generate_dyn( REQ request, NOD node) break; case nod_del_shadow: - put_number(request, gds_dyn_delete_shadow, + request->append_number(gds_dyn_delete_shadow, (SSHORT) (node->nod_arg[0])); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_mod_database: @@ -3813,20 +3800,21 @@ static void grant_revoke( REQ request) * Build DYN string for GRANT/REVOKE statements * **************************************/ - NOD ddl_node, privs, table; - NOD users, *uptr, *uend; - SSHORT option; - NOD role_list, *role_ptr, *role_end; - BOOLEAN process_grant_role = FALSE; - option = FALSE; - ddl_node = request->req_ddl_node; + NOD table; + NOD users; + NOD* uptr; + NOD* uend; + bool process_grant_role = false; - privs = ddl_node->nod_arg[e_grant_privs]; + SSHORT option = FALSE; + NOD ddl_node = request->req_ddl_node; + NOD privs = ddl_node->nod_arg[e_grant_privs]; if (privs->nod_arg[0] != NULL) { - if (privs->nod_arg[0]->nod_type == nod_role_name) - process_grant_role = TRUE; + if (privs->nod_arg[0]->nod_type == nod_role_name) { + process_grant_role = true; + } } if (!process_grant_role) @@ -3837,11 +3825,10 @@ static void grant_revoke( REQ request) option = TRUE; } - STUFF(gds_dyn_begin); + request->append_uchar(gds_dyn_begin); - for (uptr = users->nod_arg, uend = uptr + users->nod_count; - uptr < uend; - uptr++) + uend = users->nod_arg + users->nod_count; + for (uptr = users->nod_arg; uptr < uend; ++uptr) { modify_privileges( request, ddl_node->nod_type, @@ -3853,32 +3840,37 @@ static void grant_revoke( REQ request) } else { - role_list = ddl_node->nod_arg[0]; + NOD role_list = ddl_node->nod_arg[0]; users = ddl_node->nod_arg[1]; - if (ddl_node->nod_arg[3]) + if (ddl_node->nod_arg[3]) { option = 2; - STUFF(isc_dyn_begin); + } + request->append_uchar(isc_dyn_begin); - for (role_ptr = role_list->nod_arg, - role_end = role_ptr + role_list->nod_count; - role_ptr < role_end; role_ptr++) { - for (uptr = users->nod_arg, uend = uptr + users->nod_count; - uptr < uend; uptr++) { - process_role_nm_list(request, option, *uptr, *role_ptr, - ddl_node->nod_type); + NOD* role_end = role_list->nod_arg + role_list->nod_count; + for (NOD* role_ptr = role_list->nod_arg; role_ptr < role_end; ++role_ptr) + { + uend = users->nod_arg + users->nod_count; + for (uptr = users->nod_arg; uptr < uend; ++uptr) + { + process_role_nm_list( request, + option, + *uptr, + *role_ptr, + ddl_node->nod_type); } } } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void make_index( - REQ request, - NOD element, - NOD columns, - NOD referenced_columns, TEXT * relation_name) +static void make_index( REQ request, + NOD element, + NOD columns, + NOD referenced_columns, + TEXT* relation_name) { /* ************************************* * @@ -3893,39 +3885,38 @@ static void make_index( * The func. make_index_trf_ref_int handles foreign key constraint * **************************************/ - NOD *ptr, *end; - STR field_name; -/* stuff a zero-length name, indicating that an index - name should be generated */ + // stuff a zero-length name, indicating that an index + // name should be generated - assert(element->nod_type != nod_foreign) + assert(element->nod_type != nod_foreign); - if (element->nod_type == nod_primary) - STUFF(gds_dyn_def_primary_key); - else if (element->nod_type == nod_unique) - STUFF(gds_dyn_def_unique); - STUFF_WORD(0); + if (element->nod_type == nod_primary) { + request->append_uchar(gds_dyn_def_primary_key); + } else if (element->nod_type == nod_unique) { + request->append_uchar(gds_dyn_def_unique); + } + request->append_ushort(0); - put_number(request, gds_dyn_idx_unique, 1); + request->append_number(gds_dyn_idx_unique, 1); - for (ptr = columns->nod_arg, end = ptr + columns->nod_count; ptr < end; - ptr++) { - field_name = (STR) (*ptr)->nod_arg[1]; - put_cstring(request, gds_dyn_fld_name, + const NOD* end = columns->nod_arg + columns->nod_count; + for (NOD* ptr = columns->nod_arg; ptr < end; ++ptr) + { + STR field_name = (STR) (*ptr)->nod_arg[1]; + request->append_cstring(gds_dyn_fld_name, reinterpret_cast(field_name->str_data)); } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void make_index_trg_ref_int( - REQ request, - NOD element, - NOD columns, - NOD referenced_columns, - TEXT * relation_name) +static void make_index_trg_ref_int( REQ request, + NOD element, + NOD columns, + NOD referenced_columns, + TEXT* relation_name) { /****************************************************** * @@ -3944,7 +3935,7 @@ static void make_index_trg_ref_int( * * *****************************************************/ - NOD *ptr, *end; + STR field_name; NOD for_rel_node, ddl_node; STR for_rel_name_str; @@ -3962,88 +3953,87 @@ static void make_index_trg_ref_int( /* stuff a zero-length name, indicating that an index name should be generated */ - STUFF(gds_dyn_def_foreign_key); - STUFF_WORD(0); + request->append_uchar(gds_dyn_def_foreign_key); + request->append_ushort(0); - if (element->nod_arg[e_for_action]) { + if (element->nod_arg[e_for_action]) + { nod_for_action = element->nod_arg[e_for_action]; assert(nod_for_action->nod_type == nod_ref_upd_del); nod_ref_upd_action = nod_for_action->nod_arg[e_ref_upd]; - if (nod_ref_upd_action) { + if (nod_ref_upd_action) + { assert(nod_ref_upd_action->nod_type == nod_ref_trig_action); - STUFF(gds_dyn_foreign_key_update); - switch (nod_ref_upd_action->nod_flags) { + request->append_uchar(gds_dyn_foreign_key_update); + switch (nod_ref_upd_action->nod_flags) + { case REF_ACTION_CASCADE: - STUFF(gds_dyn_foreign_key_cascade); + request->append_uchar(gds_dyn_foreign_key_cascade); define_upd_cascade_trg(request, element, columns, referenced_columns, relation_name, - reinterpret_cast < - char *>(for_rel_name_str->str_data)); + reinterpret_cast(for_rel_name_str->str_data)); break; case REF_ACTION_SET_DEFAULT: - STUFF(gds_dyn_foreign_key_default); + request->append_uchar(gds_dyn_foreign_key_default); define_set_default_trg(request, element, columns, referenced_columns, relation_name, - reinterpret_cast < - char *>(for_rel_name_str->str_data), - TRUE); + reinterpret_cast(for_rel_name_str->str_data), + true); break; case REF_ACTION_SET_NULL: - STUFF(gds_dyn_foreign_key_null); + request->append_uchar(gds_dyn_foreign_key_null); define_set_null_trg(request, element, columns, referenced_columns, relation_name, - reinterpret_cast < - char *>(for_rel_name_str->str_data), - TRUE); + reinterpret_cast(for_rel_name_str->str_data), + true); break; case REF_ACTION_NONE: - STUFF(gds_dyn_foreign_key_none); + request->append_uchar(gds_dyn_foreign_key_none); break; default: assert(0); - STUFF(gds_dyn_foreign_key_none); /* just in case */ + request->append_uchar(gds_dyn_foreign_key_none); /* just in case */ break; } } nod_ref_del_action = nod_for_action->nod_arg[e_ref_del]; - if (nod_ref_del_action) { + if (nod_ref_del_action) + { assert(nod_ref_del_action->nod_type == nod_ref_trig_action); - STUFF(gds_dyn_foreign_key_delete); + request->append_uchar(gds_dyn_foreign_key_delete); switch (nod_ref_del_action->nod_flags) { case REF_ACTION_CASCADE: - STUFF(gds_dyn_foreign_key_cascade); + request->append_uchar(gds_dyn_foreign_key_cascade); define_del_cascade_trg(request, element, columns, referenced_columns, relation_name, reinterpret_cast < char *>(for_rel_name_str->str_data)); break; case REF_ACTION_SET_DEFAULT: - STUFF(gds_dyn_foreign_key_default); + request->append_uchar(gds_dyn_foreign_key_default); define_set_default_trg(request, element, columns, referenced_columns, relation_name, - reinterpret_cast < - char *>(for_rel_name_str->str_data), - FALSE); + reinterpret_cast(for_rel_name_str->str_data), + false); break; case REF_ACTION_SET_NULL: - STUFF(gds_dyn_foreign_key_null); + request->append_uchar(gds_dyn_foreign_key_null); define_set_null_trg(request, element, columns, referenced_columns, relation_name, - reinterpret_cast < - char *>(for_rel_name_str->str_data), - FALSE); + reinterpret_cast(for_rel_name_str->str_data), + false); break; case REF_ACTION_NONE: - STUFF(gds_dyn_foreign_key_none); + request->append_uchar(gds_dyn_foreign_key_none); break; default: assert(0); - STUFF(gds_dyn_foreign_key_none); /* just in case */ + request->append_uchar(gds_dyn_foreign_key_none); /* just in case */ break; /* Error */ } @@ -4051,23 +4041,28 @@ static void make_index_trg_ref_int( } - for (ptr = columns->nod_arg, end = ptr + columns->nod_count; ptr < end; - ptr++) { + NOD* ptr; + NOD* end = columns->nod_arg + columns->nod_count; + for (ptr = columns->nod_arg; ptr < end; ++ptr) + { field_name = (STR) (*ptr)->nod_arg[1]; - put_cstring(request, gds_dyn_fld_name, + request->append_cstring(gds_dyn_fld_name, reinterpret_cast(field_name->str_data)); } - put_cstring(request, gds_dyn_idx_foreign_key, relation_name); + request->append_cstring(gds_dyn_idx_foreign_key, relation_name); if (referenced_columns) - for (ptr = referenced_columns->nod_arg, end = - ptr + referenced_columns->nod_count; ptr < end; ptr++) { + { + end = referenced_columns->nod_arg + referenced_columns->nod_count; + for (ptr = referenced_columns->nod_arg; ptr < end; ++ptr) + { field_name = (STR) (*ptr)->nod_arg[1]; - put_cstring(request, gds_dyn_idx_ref_column, + request->append_cstring(gds_dyn_idx_ref_column, reinterpret_cast(field_name->str_data)); } + } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -4083,7 +4078,7 @@ static void modify_database( REQ request) * Modify a database. * **************************************/ - NOD ddl_node, elements, element, *ptr, *end; + NOD ddl_node, element, *ptr; SLONG start = 0; FIL file; SSHORT number = 0; @@ -4094,13 +4089,14 @@ static void modify_database( REQ request) ddl_node = request->req_ddl_node; - STUFF(gds_dyn_mod_database); + request->append_uchar(gds_dyn_mod_database); /* -put_number (request, gds_dyn_rel_sql_protection, 1); +request->append_number(gds_dyn_rel_sql_protection, 1); */ - elements = ddl_node->nod_arg[e_adb_all]; - for (ptr = elements->nod_arg, end = ptr + elements->nod_count; - ptr < end; ptr++) { + NOD elements = ddl_node->nod_arg[e_adb_all]; + NOD* end = elements->nod_arg + elements->nod_count; + for (ptr = elements->nod_arg; ptr < end; ptr++) + { element = *ptr; switch (element->nod_type) { case nod_drop_log: @@ -4115,31 +4111,30 @@ put_number (request, gds_dyn_rel_sql_protection, 1); } } - if (drop_log) - STUFF(gds_dyn_drop_log); - if (drop_cache) - STUFF(gds_dyn_drop_cache); + if (drop_log) { + request->append_uchar(gds_dyn_drop_log); + } + if (drop_cache) { + request->append_uchar(gds_dyn_drop_cache); + } elements = ddl_node->nod_arg[e_adb_all]; - for (ptr = elements->nod_arg, end = ptr + elements->nod_count; - ptr < end; ptr++) { + end = elements->nod_arg + elements->nod_count; + for (ptr = elements->nod_arg; ptr < end; ptr++) + { element = *ptr; switch (element->nod_type) { case nod_file_desc: file = (FIL) element->nod_arg[0]; - put_cstring(request, gds_dyn_def_file, + request->append_cstring(gds_dyn_def_file, reinterpret_cast(file->fil_name->str_data)); - STUFF(gds_dyn_file_start); - STUFF_WORD(4); + start = MAX(start, file->fil_start); + request->append_file_start(start); - STUFF_DWORD(start); - - STUFF(gds_dyn_file_length); - STUFF_WORD(4); - STUFF_DWORD(file->fil_length); - STUFF(gds_dyn_end); + request->append_file_length(file->fil_length); + request->append_uchar(gds_dyn_end); start += file->fil_length; break; @@ -4147,66 +4142,59 @@ put_number (request, gds_dyn_rel_sql_protection, 1); file = (FIL) element->nod_arg[0]; if (file->fil_flags & LOG_default) { - STUFF(gds_dyn_def_default_log); + request->append_uchar(gds_dyn_def_default_log); break; } - put_cstring(request, gds_dyn_def_log_file, + request->append_cstring(gds_dyn_def_log_file, reinterpret_cast(file->fil_name->str_data)); - STUFF(gds_dyn_file_length); - STUFF_WORD(4); - STUFF_DWORD(file->fil_length); - STUFF(gds_dyn_log_file_sequence); - STUFF_WORD(2); - STUFF_WORD(number); + request->append_file_length(file->fil_length); + request->append_uchar(gds_dyn_log_file_sequence); + request->append_ushort_with_length(number); number++; - STUFF(gds_dyn_log_file_partitions); - STUFF_WORD(2); - STUFF_WORD(file->fil_partitions); - if (file->fil_flags & LOG_serial) - STUFF(gds_dyn_log_file_serial); - if (file->fil_flags & LOG_overflow) - STUFF(gds_dyn_log_file_overflow); - if (file->fil_flags & LOG_raw) - STUFF(gds_dyn_log_file_raw); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_log_file_partitions); + request->append_ushort_with_length(file->fil_partitions); + if (file->fil_flags & LOG_serial) { + request->append_uchar(gds_dyn_log_file_serial); + } + if (file->fil_flags & LOG_overflow) { + request->append_uchar(gds_dyn_log_file_overflow); + } + if (file->fil_flags & LOG_raw) { + request->append_uchar(gds_dyn_log_file_raw); + } + request->append_uchar(gds_dyn_end); break; case nod_cache_file_desc: file = (FIL) element->nod_arg[0]; - put_cstring(request, gds_dyn_def_cache_file, + request->append_cstring(gds_dyn_def_cache_file, reinterpret_cast(file->fil_name->str_data)); - STUFF(gds_dyn_file_length); - STUFF_WORD(4); - STUFF_DWORD(file->fil_length); - STUFF(gds_dyn_end); + request->append_file_length(file->fil_length); + request->append_uchar(gds_dyn_end); break; case nod_group_commit_wait: - STUFF(gds_dyn_log_group_commit_wait); + request->append_uchar(gds_dyn_log_group_commit_wait); temp_long = (SLONG) (element->nod_arg[0]); - STUFF_WORD(4); - STUFF_DWORD(temp_long); + request->append_ulong_with_length(temp_long); break; case nod_check_point_len: - STUFF(gds_dyn_log_check_point_length); + request->append_uchar(gds_dyn_log_check_point_length); temp_long = (SLONG) (element->nod_arg[0]); - STUFF_WORD(4); - STUFF_DWORD(temp_long); + request->append_ulong_with_length(temp_long); break; case nod_num_log_buffers: - STUFF(gds_dyn_log_num_of_buffers); + request->append_uchar(gds_dyn_log_num_of_buffers); temp_short = (SSHORT) (element->nod_arg[0]); - STUFF_WORD(2); - STUFF_WORD(temp_short); + request->append_ushort_with_length(temp_short); break; case nod_log_buffer_size: - STUFF(gds_dyn_log_buffer_size); + request->append_uchar(gds_dyn_log_buffer_size); temp_short = (SSHORT) (element->nod_arg[0]); - STUFF_WORD(2); - STUFF_WORD(temp_short); + request->append_ushort_with_length(temp_short); break; case nod_drop_log: case nod_drop_cache: @@ -4217,7 +4205,7 @@ put_number (request, gds_dyn_rel_sql_protection, 1); } } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -4236,14 +4224,14 @@ static void modify_domain( REQ request) NOD ddl_node, domain_node, ops, element, *ptr, *end; STR string, domain_name; FLD field; - struct fld local_field; + fld local_field; ddl_node = request->req_ddl_node; domain_node = ddl_node->nod_arg[e_alt_dom_name]; domain_name = (STR) domain_node->nod_arg[e_fln_name]; - put_cstring(request, gds_dyn_mod_global_fld, + request->append_cstring(gds_dyn_mod_global_fld, reinterpret_cast(domain_name->str_data)); ops = ddl_node->nod_arg[e_alt_dom_ops]; @@ -4256,41 +4244,48 @@ static void modify_domain( REQ request) /* CVC: So do you want to crash me with ALTER DOMAIN dom SET; ??? */ if (!element->nod_arg[e_dft_default]) { - ERRD_post (gds_sqlerr, gds_arg_number, (SLONG) -104, - gds_arg_gds, gds_command_end_err, /* Unexpected end of command */ - 0); + ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) -104, + gds_arg_gds, gds_command_end_err, /* Unexpected end of command */ + 0); } /* CVC End modification. */ element->nod_arg[e_dft_default] = PASS1_node(request, element->nod_arg[e_dft_default], 0); - begin_blr(request, gds_dyn_fld_default_value); + + request->begin_blr(gds_dyn_fld_default_value); GEN_expr(request, element->nod_arg[e_dft_default]); - end_blr(request); - if ((string = (STR) element->nod_arg[e_dft_default_source]) != - NULL) { + request->end_blr(); + + string = (STR) element->nod_arg[e_dft_default_source]; + if (string) + { assert(string->str_length <= MAX_USHORT); - put_string(request, gds_dyn_fld_default_source, - string->str_data, (USHORT) string->str_length); + request->append_string( gds_dyn_fld_default_source, + reinterpret_cast(string->str_data), + (USHORT) string->str_length); } break; case nod_def_constraint: - STUFF(gds_dyn_single_validation); - begin_blr(request, gds_dyn_fld_validation_blr); + request->append_uchar(gds_dyn_single_validation); + request->begin_blr(gds_dyn_fld_validation_blr); /* Get the attributes of the domain, and set any occurances of nod_dom_value (corresponding to the keyword VALUE) to the correct type, length, scale, etc. */ - if (!METD_get_domain(request, &local_field, - domain_name->str_data)) + if (!METD_get_domain(request, &local_field, domain_name->str_data)) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_dsql_domain_not_found, /* Specified domain or source field does not exist */ 0); + } if (element->nod_arg[e_cnstr_condition]) + { set_nod_value_attributes(element->nod_arg[e_cnstr_condition], &local_field); + } /* Increment the context level for this request, so that the context number for any RSE generated for a SELECT @@ -4307,11 +4302,12 @@ static void modify_domain( REQ request) PASS1_node(request, element->nod_arg[e_cnstr_condition], 0)); - end_blr(request); + request->end_blr(); if ((string = (STR) element->nod_arg[e_cnstr_source]) != NULL) { assert(string->str_length <= MAX_USHORT); - put_string(request, gds_dyn_fld_validation_source, - string->str_data, (USHORT) string->str_length); + request->append_string( gds_dyn_fld_validation_source, + reinterpret_cast(string->str_data), + (USHORT) string->str_length); } break; @@ -4326,18 +4322,18 @@ static void modify_domain( REQ request) STR new_dom_name; new_dom_name = (STR) element->nod_arg[e_fln_name]; - put_cstring(request, gds_dyn_fld_name, + request->append_cstring(gds_dyn_fld_name, reinterpret_cast < char *>(new_dom_name->str_data)); break; } case nod_delete_rel_constraint: - STUFF(gds_dyn_del_validation); + request->append_uchar(gds_dyn_del_validation); break; case nod_del_default: - STUFF(gds_dyn_del_default); + request->append_uchar(gds_dyn_del_default); break; default: @@ -4345,7 +4341,7 @@ static void modify_domain( REQ request) } } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -4369,24 +4365,26 @@ static void modify_index( REQ request) index_node = ddl_node->nod_arg[e_alt_index]; index_name = (STR) index_node->nod_arg[e_alt_idx_name]; - put_cstring(request, gds_dyn_mod_idx, + request->append_cstring(gds_dyn_mod_idx, reinterpret_cast(index_name->str_data)); - if (index_node->nod_type == nod_idx_active) - put_number(request, gds_dyn_idx_inactive, 0); - else if (index_node->nod_type == nod_idx_inactive) - put_number(request, gds_dyn_idx_inactive, 1); + if (index_node->nod_type == nod_idx_active) { + request->append_number(gds_dyn_idx_inactive, 0); + } else if (index_node->nod_type == nod_idx_inactive) { + request->append_number(gds_dyn_idx_inactive, 1); + } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void modify_privilege( - REQ request, - NOD_TYPE type, - SSHORT option, - UCHAR * privs, -NOD table, NOD user, STR field_name) +static void modify_privilege( REQ request, + NOD_TYPE type, + SSHORT option, + UCHAR* privs, + NOD table, + NOD user, + STR field_name) { /************************************** * @@ -4402,18 +4400,19 @@ NOD table, NOD user, STR field_name) UCHAR *dynsave; STR name; - if (type == nod_grant) - STUFF(gds_dyn_grant); - else - STUFF(gds_dyn_revoke); + if (type == nod_grant) { + request->append_uchar(gds_dyn_grant); + } else { + request->append_uchar(gds_dyn_revoke); + } /* stuff the privileges string */ priv_count = 0; - STUFF_WORD(0); + request->append_ushort(0); for (; *privs; privs++) { priv_count++; - STUFF(*privs); + request->append_uchar(*privs); } dynsave = request->req_blr; @@ -4425,35 +4424,35 @@ NOD table, NOD user, STR field_name) name = (STR) table->nod_arg[0]; if (table->nod_type == nod_procedure_name) - put_cstring(request, gds_dyn_prc_name, + request->append_cstring(gds_dyn_prc_name, reinterpret_cast(name->str_data)); else - put_cstring(request, gds_dyn_rel_name, + request->append_cstring(gds_dyn_rel_name, reinterpret_cast(name->str_data)); name = (STR) user->nod_arg[0]; switch (user->nod_type) { case nod_user_group: /* GRANT priv ON tbl TO GROUP unix_group */ - put_cstring(request, isc_dyn_grant_user_group, + request->append_cstring(isc_dyn_grant_user_group, reinterpret_cast(name->str_data)); break; case nod_user_name: - put_cstring(request, gds_dyn_grant_user, + request->append_cstring(gds_dyn_grant_user, reinterpret_cast(name->str_data)); break; case nod_proc_obj: - put_cstring(request, gds_dyn_grant_proc, + request->append_cstring(gds_dyn_grant_proc, reinterpret_cast(name->str_data)); break; case nod_trig_obj: - put_cstring(request, gds_dyn_grant_trig, + request->append_cstring(gds_dyn_grant_trig, reinterpret_cast(name->str_data)); break; case nod_view_obj: - put_cstring(request, gds_dyn_grant_view, + request->append_cstring(gds_dyn_grant_view, reinterpret_cast(name->str_data)); break; @@ -4462,19 +4461,18 @@ NOD table, NOD user, STR field_name) } if (field_name) { - put_cstring(request, - gds_dyn_fld_name, - reinterpret_cast(field_name->str_data)); + request->append_cstring(gds_dyn_fld_name, + reinterpret_cast(field_name->str_data)); } if ((option) && ((type == nod_grant) || (!(request->req_dbb->dbb_flags & DBB_v3)))) { - put_number(request, gds_dyn_grant_options, option); + request->append_number(gds_dyn_grant_options, option); } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -4584,7 +4582,7 @@ static void modify_relation( REQ request) relation_node = ddl_node->nod_arg[e_alt_name]; relation_name = (STR) relation_node->nod_arg[e_rln_name]; - put_cstring(request, gds_dyn_mod_rel, + request->append_cstring(gds_dyn_mod_rel, reinterpret_cast(relation_name->str_data)); save_relation(request, relation_name); @@ -4595,12 +4593,7 @@ static void modify_relation( REQ request) old_env = tdsql->tsql_setjmp; tdsql->tsql_setjmp = &env; - if (SETJMP(*tdsql->tsql_setjmp)) { - METD_drop_relation(request, relation_name); - request->req_relation = 0; - tdsql->tsql_setjmp = old_env; - LONGJMP(*tdsql->tsql_setjmp, (int) tdsql->tsql_status[1]); - } + try { ops = ddl_node->nod_arg[e_alt_ops]; for (ptr = ops->nod_arg, end = ptr + ops->nod_count; ptr < end; ptr++) { @@ -4613,19 +4606,19 @@ static void modify_relation( REQ request) old_field = element->nod_arg[e_mod_fld_name_orig_name]; old_field_name = (STR) old_field->nod_arg[e_fln_name]; - put_cstring(request, gds_dyn_mod_local_fld, + request->append_cstring(gds_dyn_mod_local_fld, reinterpret_cast < char *>(old_field_name->str_data)); new_field = element->nod_arg[e_mod_fld_name_new_name]; new_field_name = (STR) new_field->nod_arg[e_fln_name]; - put_cstring(request, gds_dyn_rel_name, + request->append_cstring(gds_dyn_rel_name, reinterpret_cast < char *>(relation_name->str_data)); - put_cstring(request, isc_dyn_new_fld_name, + request->append_cstring(isc_dyn_new_fld_name, reinterpret_cast < char *>(new_field_name->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; } @@ -4636,16 +4629,16 @@ static void modify_relation( REQ request) field_node = element->nod_arg[e_mod_fld_pos_orig_name]; field_name = (STR) field_node->nod_arg[e_fln_name]; - put_cstring(request, gds_dyn_mod_local_fld, + request->append_cstring(gds_dyn_mod_local_fld, reinterpret_cast(field_name->str_data)); const_node = element->nod_arg[e_mod_fld_pos_new_position]; constant = (SSHORT) const_node->nod_arg[0]; - put_cstring(request, gds_dyn_rel_name, + request->append_cstring(gds_dyn_rel_name, reinterpret_cast < char *>(relation_name->str_data)); - put_number(request, gds_dyn_fld_position, constant); - STUFF(gds_dyn_end); + request->append_number(gds_dyn_fld_position, constant); + request->append_uchar(gds_dyn_end); break; } @@ -4675,20 +4668,22 @@ static void modify_relation( REQ request) field_name = (STR) field_node->nod_arg[e_fln_name]; if ((element->nod_arg[1])->nod_type == nod_cascade) + { /* Unsupported DSQL construct */ ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 901, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_dsql_construct_err, 0); + } assert((element->nod_arg[1])->nod_type == nod_restrict); - put_cstring(request, gds_dyn_delete_local_fld, + request->append_cstring(gds_dyn_delete_local_fld, reinterpret_cast(field_name->str_data)); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); break; case nod_delete_rel_constraint: field_name = (STR) element->nod_arg[0]; - put_cstring(request, gds_dyn_delete_rel_constraint, + request->append_cstring(gds_dyn_delete_rel_constraint, reinterpret_cast(field_name->str_data)); break; @@ -4701,18 +4696,28 @@ static void modify_relation( REQ request) } } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); /* restore the setjmp pointer */ tdsql->tsql_setjmp = old_env; + + } // try + catch (...) + { + METD_drop_relation(request, relation_name); + request->req_relation = 0; + tdsql->tsql_setjmp = old_env; + Firebird::status_longjmp_error::raise(tdsql->tsql_status[1]); + } } -static void process_role_nm_list( - REQ request, - SSHORT option, - NOD user_ptr, NOD role_ptr, NOD_TYPE type) +static void process_role_nm_list( REQ request, + SSHORT option, + NOD user_ptr, + NOD role_ptr, + NOD_TYPE type) { /************************************** * @@ -4726,30 +4731,32 @@ static void process_role_nm_list( **************************************/ STR role_nm, user_nm; - if (type == nod_grant) - STUFF(isc_dyn_grant); - else - STUFF(isc_dyn_revoke); + if (type == nod_grant) { + request->append_uchar(isc_dyn_grant); + } else { + request->append_uchar(isc_dyn_revoke); + } - STUFF_WORD(1); - STUFF('M'); + request->append_ushort(1); + request->append_uchar('M'); role_nm = (STR) role_ptr->nod_arg[0]; - put_cstring(request, isc_dyn_sql_role_name, + request->append_cstring(isc_dyn_sql_role_name, reinterpret_cast(role_nm->str_data)); user_nm = (STR) user_ptr->nod_arg[0]; - put_cstring(request, isc_dyn_grant_user, + request->append_cstring(isc_dyn_grant_user, reinterpret_cast(user_nm->str_data)); - if (option) - put_number(request, isc_dyn_grant_admin_options, option); + if (option) { + request->append_number(isc_dyn_grant_admin_options, option); + } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void put_descriptor( REQ request, DSC * desc) +static void put_descriptor(REQ request, DSC * desc) { /************************************** * @@ -4763,17 +4770,18 @@ static void put_descriptor( REQ request, DSC * desc) * **************************************/ - put_number(request, gds_dyn_fld_type, blr_dtypes[desc->dsc_dtype]); - if (desc->dsc_dtype == dtype_varying) - put_number(request, gds_dyn_fld_length, + request->append_number(gds_dyn_fld_type, blr_dtypes[desc->dsc_dtype]); + if (desc->dsc_dtype == dtype_varying) { + request->append_number(gds_dyn_fld_length, (SSHORT) (desc->dsc_length - sizeof(USHORT))); - else - put_number(request, gds_dyn_fld_length, desc->dsc_length); - put_number(request, gds_dyn_fld_scale, desc->dsc_scale); + } else { + request->append_number(gds_dyn_fld_length, desc->dsc_length); + } + request->append_number(gds_dyn_fld_scale, desc->dsc_scale); } -static void put_dtype( REQ request, FLD field, USHORT use_subtype) +static void put_dtype(REQ request, FLD field, USHORT use_subtype) { /************************************** * @@ -4800,33 +4808,37 @@ static void put_dtype( REQ request, FLD field, USHORT use_subtype) #endif if (field->fld_dtype == dtype_cstring || - field->fld_dtype == dtype_text || field->fld_dtype == dtype_varying) { + field->fld_dtype == dtype_text || field->fld_dtype == dtype_varying) + { if (!use_subtype || (request->req_dbb->dbb_flags & DBB_v3)) { - STUFF(blr_dtypes[field->fld_dtype]); + request->append_uchar(blr_dtypes[field->fld_dtype]); } else if (field->fld_dtype == dtype_varying) { - STUFF(blr_varying2); - STUFF_WORD(field->fld_ttype); + request->append_uchar(blr_varying2); + request->append_ushort(field->fld_ttype); } else if (field->fld_dtype == dtype_cstring) { - STUFF(blr_cstring2); - STUFF_WORD(field->fld_ttype); + request->append_uchar(blr_cstring2); + request->append_ushort(field->fld_ttype); } else { - STUFF(blr_text2); - STUFF_WORD(field->fld_ttype); + request->append_uchar(blr_text2); + request->append_ushort(field->fld_ttype); } - if (field->fld_dtype == dtype_varying) - STUFF_WORD(field->fld_length - sizeof(USHORT)) - else - STUFF_WORD(field->fld_length); + if (field->fld_dtype == dtype_varying) { + request->append_ushort(field->fld_length - sizeof(USHORT)); + } else { + request->append_ushort(field->fld_length); + } } - else { - STUFF(blr_dtypes[field->fld_dtype]); + else + { + request->append_uchar(blr_dtypes[field->fld_dtype]); if (DTYPE_IS_EXACT(field->fld_dtype) || - (dtype_quad == field->fld_dtype)) { - STUFF(field->fld_scale); + (dtype_quad == field->fld_dtype)) + { + request->append_uchar(field->fld_scale); } } } @@ -4847,50 +4859,65 @@ static void put_field( REQ request, FLD field, BOOLEAN udf_flag) * **************************************/ - put_number(request, gds_dyn_fld_type, blr_dtypes[field->fld_dtype]); - if (field->fld_dtype == dtype_blob) { - put_number(request, gds_dyn_fld_sub_type, field->fld_sub_type); - put_number(request, gds_dyn_fld_scale, 0); - if (!udf_flag) { - if (!field->fld_seg_length) + request->append_number(gds_dyn_fld_type, blr_dtypes[field->fld_dtype]); + if (field->fld_dtype == dtype_blob) + { + request->append_number(gds_dyn_fld_sub_type, field->fld_sub_type); + request->append_number(gds_dyn_fld_scale, 0); + if (!udf_flag) + { + if (!field->fld_seg_length) { field->fld_seg_length = DEFAULT_BLOB_SEGMENT_SIZE; - put_number(request, gds_dyn_fld_segment_length, + } + request->append_number(gds_dyn_fld_segment_length, field->fld_seg_length); } if (!(request->req_dbb->dbb_flags & DBB_v3)) - if (field->fld_sub_type == BLOB_text) - put_number(request, gds_dyn_fld_character_set, + { + if (field->fld_sub_type == BLOB_text) { + request->append_number(gds_dyn_fld_character_set, field->fld_character_set_id); + } + } } - else if (field->fld_dtype <= dtype_any_text) { - if (field->fld_sub_type) - put_number(request, gds_dyn_fld_sub_type, field->fld_sub_type); - put_number(request, gds_dyn_fld_scale, 0); - if (field->fld_dtype == dtype_varying) { + else if (field->fld_dtype <= dtype_any_text) + { + if (field->fld_sub_type) { + request->append_number(gds_dyn_fld_sub_type, field->fld_sub_type); + } + request->append_number(gds_dyn_fld_scale, 0); + if (field->fld_dtype == dtype_varying) + { assert((field->fld_length - sizeof(USHORT)) <= MAX_SSHORT); - put_number(request, gds_dyn_fld_length, + request->append_number(gds_dyn_fld_length, (SSHORT) (field->fld_length - sizeof(USHORT))); } else - put_number(request, gds_dyn_fld_length, field->fld_length); - if (!(request->req_dbb->dbb_flags & DBB_v3)) { - put_number(request, gds_dyn_fld_char_length, + { + request->append_number(gds_dyn_fld_length, field->fld_length); + } + if (!(request->req_dbb->dbb_flags & DBB_v3)) + { + request->append_number(gds_dyn_fld_char_length, field->fld_character_length); - put_number(request, gds_dyn_fld_character_set, + request->append_number(gds_dyn_fld_character_set, field->fld_character_set_id); if (!udf_flag) - put_number(request, gds_dyn_fld_collation, + request->append_number(gds_dyn_fld_collation, field->fld_collation_id); } } else { - put_number(request, gds_dyn_fld_scale, field->fld_scale); - put_number(request, gds_dyn_fld_length, field->fld_length); - if (DTYPE_IS_EXACT(field->fld_dtype)) { - put_number(request, isc_dyn_fld_precision, field->fld_precision); + request->append_number(gds_dyn_fld_scale, field->fld_scale); + request->append_number(gds_dyn_fld_length, field->fld_length); + if (DTYPE_IS_EXACT(field->fld_dtype)) + { + request->append_number(isc_dyn_fld_precision, field->fld_precision); if (field->fld_sub_type) - put_number(request, isc_dyn_fld_sub_type, + { + request->append_number(isc_dyn_fld_sub_type, field->fld_sub_type); + } } } } @@ -4908,28 +4935,32 @@ static void put_local_variable( REQ request, VAR variable) * Write out local variable field data type * **************************************/ - FLD field; - USHORT dtype; - field = variable->var_field; - STUFF(blr_dcl_variable); - STUFF_WORD(variable->var_variable_number); + FLD field = variable->var_field; + + request->append_uchar(blr_dcl_variable); + request->append_ushort(variable->var_variable_number); DDL_resolve_intl_type(request, field, NULL); - if ((dtype = field->fld_dtype) == dtype_blob) + + const USHORT dtype = field->fld_dtype; + + if (dtype == dtype_blob) { field->fld_dtype = dtype_quad; + } + put_dtype(request, field, TRUE); field->fld_dtype = dtype; -/* Initialize variable to NULL */ + // Initialize variable to NULL - STUFF(blr_assignment); - STUFF(blr_null); - STUFF(blr_variable); - STUFF_WORD(variable->var_variable_number); + request->append_uchar(blr_assignment); + request->append_uchar(blr_null); + request->append_uchar(blr_variable); + request->append_ushort(variable->var_variable_number); } -static SSHORT put_local_variables( REQ request, NOD parameters, SSHORT locals) +static SSHORT put_local_variables(REQ request, NOD parameters, SSHORT locals) { /************************************** * @@ -4942,27 +4973,30 @@ static SSHORT put_local_variables( REQ request, NOD parameters, SSHORT locals) * in a procedure or trigger. * **************************************/ - NOD *rest, parameter, *ptr, *end, var_node; - FLD field, rest_field; - VAR variable; - if (parameters) { - ptr = parameters->nod_arg; - for (end = ptr + parameters->nod_count; ptr < end; ptr++) { - parameter = *ptr; - field = (FLD) parameter->nod_arg[e_dfl_field]; - rest = ptr; - while ((++rest) != end) { - rest_field = (FLD) (*rest)->nod_arg[e_dfl_field]; + if (parameters) + { + NOD* ptr = parameters->nod_arg; + for (NOD* end = ptr + parameters->nod_count; ptr < end; ptr++) + { + NOD parameter = *ptr; + FLD field = (FLD) parameter->nod_arg[e_dfl_field]; + NOD* rest = ptr; + while ((++rest) != end) + { + FLD rest_field = (FLD) (*rest)->nod_arg[e_dfl_field]; if (!strcmp(field->fld_name, rest_field->fld_name)) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 637, gds_arg_gds, gds_dsql_duplicate_spec, gds_arg_string, field->fld_name, 0); + } } - *ptr = var_node = + NOD var_node = MAKE_variable(field, field->fld_name, VAR_output, 0, 0, locals); - variable = (VAR) var_node->nod_arg[e_var_variable]; + *ptr = var_node; + VAR variable = (VAR) var_node->nod_arg[e_var_variable]; put_local_variable(request, variable); locals++; } @@ -4984,27 +5018,25 @@ static void put_msg_field( REQ request, FLD field) * Write out message field data type * **************************************/ - USHORT dtype; - if ((dtype = field->fld_dtype) == dtype_blob) + const USHORT dtype = field->fld_dtype; + + if (dtype == dtype_blob) { field->fld_dtype = dtype_quad; + } + put_dtype(request, field, TRUE); field->fld_dtype = dtype; -/* add slot for null flag (parameter2) */ - - STUFF(blr_short); - STUFF(0); + // add slot for null flag (parameter2) + request->append_uchar(blr_short); + request->append_uchar(0); } -static void put_number( REQ request, UCHAR verb, SSHORT number) +void req::append_number(UCHAR verb, SSHORT number) { /************************************** - * - * p u t _ n u m b e r - * - ************************************** * * Input * blr_ptr: current position of blr being generated @@ -5013,70 +5045,53 @@ static void put_number( REQ request, UCHAR verb, SSHORT number) * Function * Write out a numeric valued attribute. * - **************************************/ - - if (verb) - STUFF(verb); - - STUFF_WORD(2); - STUFF_WORD(number); -} - - -static void put_cstring( REQ request, UCHAR verb, char *string) -{ -/************************************** - * - * p u t _ c s t r i n g - * - ************************************** - * - * Function - * Write out a string valued attribute. - * - **************************************/ - USHORT length; - - if (string) - length = strlen(string); - else - length = 0; - - put_string(request, verb, reinterpret_cast < UCHAR * >(string), length); -} - - -static void put_string( - REQ request, UCHAR verb, UCHAR * string, USHORT length) -{ -/************************************** - * - * p u t _ s t r i n g - * - ************************************** - * - * Function - * Write out a string valued attribute. - * **************************************/ if (verb) { - STUFF(verb); - STUFF_WORD(length); + append_uchar(verb); } - else - STUFF(length); - if (string) - for (; *string && length--; string++) - STUFF(*string); + append_ushort_with_length(number); } -static NOD replace_field_names( - NOD input, - NOD search_fields, - NOD replace_fields, SSHORT null_them) +// +// Write out a string valued attribute. +// +void req::append_cstring(UCHAR verb, char* string) +{ + const USHORT length = string ? strlen(string) : 0; + append_string(verb, string, length); +} + + +// +// Write out a string valued attribute. +// +void req::append_string(UCHAR verb, char* string, USHORT length) +{ + // TMN: Doesn't this look pretty awkward? If we are given + // a verb, the length is a ushort, else it's uchar. + if (verb) { + append_uchar(verb); + append_ushort(length); + } + else { + append_uchar(length); + } + + if (string) { + for (; *string && length--; string++) { + append_uchar(*string); + } + } +} + + +static NOD replace_field_names(NOD input, + NOD search_fields, + NOD replace_fields, + SSHORT null_them) { /* ************************************* * @@ -5090,67 +5105,75 @@ static NOD replace_field_names( * Used to create view WITH CHECK OPTION. * **************************************/ - NOD *endo, field_node, *ptr, *end, *search, *replace; - STR field_name, replace_name; - TEXT *search_name; - FLD field; - SSHORT found; - if (!input) + if (!input || MemoryPool::blk_type(input) != dsql_type_nod) { return input; + } - if (input->nod_header.blk_type != type_nod) - return input; + const NOD* endo = input->nod_arg + input->nod_count; - for (ptr = input->nod_arg, endo = ptr + input->nod_count; ptr < endo; - ptr++) { + for (NOD* ptr = input->nod_arg; ptr < endo; ++ptr) + { if ((*ptr)->nod_type == nod_select_expr) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_subquery_err, /* No subqueries permitted for VIEW WITH CHECK OPTION */ 0); + } - if ((*ptr)->nod_type == nod_field_name) { - /* found a field node, check if it needs to be replaced */ + if ((*ptr)->nod_type == nod_field_name) + { + // found a field node, check if it needs to be replaced - field_name = (STR) (*ptr)->nod_arg[e_fln_name]; - - search = search_fields->nod_arg; - end = search + search_fields->nod_count; - if (replace_fields) + STR field_name = (STR) (*ptr)->nod_arg[e_fln_name]; + NOD* search = search_fields->nod_arg; + NOD* end = search + search_fields->nod_count; + NOD* replace; + if (replace_fields) { replace = replace_fields->nod_arg; - found = FALSE; - for (; search < end; - search++, (replace_fields) ? replace++ : NULL) { + } + bool found = false; + for (; search < end; search++, (replace_fields) ? replace++ : NULL) + { + STR replace_name; if (replace_fields) { replace_name = (STR) (*replace)->nod_arg[e_fln_name]; } - field_node = *search; - field = (FLD) field_node->nod_arg[e_fld_field]; - search_name = field->fld_name; - if (!strcmp - ((SCHAR *) field_name->str_data, (SCHAR *) search_name)) { - found = TRUE; - if (replace_fields) + NOD field_node = *search; + FLD field = (FLD) field_node->nod_arg[e_fld_field]; + TEXT* search_name = field->fld_name; + if (!strcmp((SCHAR *) field_name->str_data, + (SCHAR *) search_name)) + { + found = true; + if (replace_fields) { (*ptr)->nod_arg[e_fln_name] = (*replace)->nod_arg[e_fln_name]; + } (*ptr)->nod_arg[e_fln_context] = (NOD) MAKE_cstring(NEW_CONTEXT); } if (null_them && replace_fields && !strcmp((SCHAR *) field_name->str_data, - (SCHAR *) replace_name->str_data)) found = TRUE; + (SCHAR *) replace_name->str_data)) + { + found = true; + } } if (null_them && !found) { (*ptr) = MAKE_node(nod_null, (int) 0); } } else - /* recursively go through the input tree looking for field name nodes */ + { + // recursively go through the input tree + // looking for field name nodes replace_field_names(*ptr, search_fields, replace_fields, null_them); + } } return input; @@ -5171,13 +5194,14 @@ static void reset_context_stack( REQ request) * **************************************/ - while (request->req_context) + while (request->req_context) { LLS_POP(&request->req_context); + } request->req_context_number = 0; } -static void save_field( REQ request, TEXT * field_name) +static void save_field(REQ request, TEXT* field_name) { /************************************** * @@ -5192,16 +5216,15 @@ static void save_field( REQ request, TEXT * field_name) * in this request. * **************************************/ - DSQL_REL relation; - FLD field; - TSQL tdsql; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; - if (!(relation = request->req_relation)) + DSQL_REL relation = request->req_relation; + if (!relation) { return; + } - field = (FLD) ALLOCDV(type_fld, strlen(field_name) + 1); + FLD field = new(*tdsql->tsql_default, strlen(field_name) + 1) fld; strcpy(field->fld_name, field_name); field->fld_next = relation->rel_fields; relation->rel_fields = field; @@ -5223,17 +5246,17 @@ static void save_relation( REQ request, STR relation_name) * in this request. * **************************************/ - DSQL_REL relation; - NOD ddl_node; - TSQL tdsql; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; - if (request->req_flags & REQ_save_metadata) + if (request->req_flags & REQ_save_metadata) { return; + } request->req_flags |= REQ_save_metadata; - ddl_node = request->req_ddl_node; + + NOD ddl_node = request->req_ddl_node; + DSQL_REL relation; if (ddl_node->nod_type == nod_mod_relation) { @@ -5241,8 +5264,7 @@ static void save_relation( REQ request, STR relation_name) } else { - relation = - (DSQL_REL) ALLOCDV(type_dsql_rel, relation_name->str_length); + relation = new(*tdsql->tsql_default, relation_name->str_length) dsql_rel; relation->rel_name = relation->rel_data; relation->rel_owner = relation->rel_data + relation_name->str_length + 1; @@ -5272,18 +5294,18 @@ static void set_statistics( REQ request) index_name = (STR) ddl_node->nod_arg[e_stat_name]; - put_cstring(request, gds_dyn_mod_idx, + request->append_cstring(gds_dyn_mod_idx, reinterpret_cast(index_name->str_data)); - STUFF(gds_dyn_idx_statistic); + request->append_uchar(gds_dyn_idx_statistic); - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } -static void stuff_default_blr( - REQ request, - TEXT * default_buff, USHORT buff_size) +static void stuff_default_blr( REQ request, + TEXT* default_buff, + USHORT buff_size) { /******************************************** * @@ -5301,15 +5323,15 @@ static void stuff_default_blr( assert((*default_buff == blr_version4) || (*default_buff == blr_version5)); - for (i = 1; ((i < buff_size) && (default_buff[i] != blr_eoc)); i++) - STUFF(default_buff[i]); + for (i = 1; ((i < buff_size) && (default_buff[i] != blr_eoc)); i++) { + request->append_uchar(default_buff[i]); + } assert(default_buff[i] == blr_eoc); } -static void stuff_matching_blr( - REQ request, NOD for_columns, NOD prim_columns) +static void stuff_matching_blr(REQ request, NOD for_columns, NOD prim_columns) { /******************************************** * @@ -5323,55 +5345,51 @@ static void stuff_matching_blr( * for_key.column_2 = prim_key.column_2 and .... so on.. * **************************************/ - NOD *for_key_flds, *prim_key_flds; - USHORT num_fields = 0; - STR for_key_fld_name_str, prim_key_fld_name_str; /* count of foreign key columns */ assert(prim_columns->nod_count == for_columns->nod_count); assert(prim_columns->nod_count != 0); - STUFF(blr_boolean); - if (prim_columns->nod_count > 1) - STUFF(blr_and); + request->append_uchar(blr_boolean); + if (prim_columns->nod_count > 1) { + request->append_uchar(blr_and); + } - num_fields = 0; - for_key_flds = for_columns->nod_arg; - prim_key_flds = prim_columns->nod_arg; + USHORT num_fields = 0; + NOD* for_key_flds = for_columns->nod_arg; + NOD* prim_key_flds = prim_columns->nod_arg; do { - STUFF(blr_eql); + request->append_uchar(blr_eql); - for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; - prim_key_fld_name_str = (STR) (*prim_key_flds)->nod_arg[1]; + STR for_key_fld_name_str = (STR) (*for_key_flds)->nod_arg[1]; + STR prim_key_fld_name_str = (STR) (*prim_key_flds)->nod_arg[1]; - STUFF(blr_field); - STUFF((SSHORT) 2); - put_cstring(request, 0, - reinterpret_cast < - char *>(for_key_fld_name_str->str_data)); - STUFF(blr_field); - STUFF((SSHORT) 0); - put_cstring(request, 0, - reinterpret_cast < - char *>(prim_key_fld_name_str->str_data)); + request->append_uchar(blr_field); + request->append_uchar(2); + request->append_cstring(0, + reinterpret_cast(for_key_fld_name_str->str_data)); + request->append_uchar(blr_field); + request->append_uchar(0); + request->append_cstring(0, + reinterpret_cast(prim_key_fld_name_str->str_data)); num_fields++; - if (prim_columns->nod_count - num_fields >= (unsigned) 2) - STUFF(blr_and); + if (prim_columns->nod_count - num_fields >= (unsigned) 2) { + request->append_uchar(blr_and); + } for_key_flds++; prim_key_flds++; - } - while (num_fields < for_columns->nod_count); + } while (num_fields < for_columns->nod_count); - STUFF(blr_end); + request->append_uchar(blr_end); } -static void stuff_trg_firing_cond( REQ request, NOD prim_columns) +static void stuff_trg_firing_cond(REQ request, NOD prim_columns) { /******************************************** * @@ -5384,47 +5402,46 @@ static void stuff_trg_firing_cond( REQ request, NOD prim_columns) * do a column by column comparison. * **************************************/ - NOD *prim_key_flds; + + + request->append_uchar(blr_if); + + if (prim_columns->nod_count > 1) { + request->append_uchar(blr_or); + } + USHORT num_fields = 0; - STR prim_key_fld_name_str; + NOD* prim_key_flds = prim_columns->nod_arg; - STUFF(blr_if); - if (prim_columns->nod_count > 1) - STUFF(blr_or); - - num_fields = 0; - prim_key_flds = prim_columns->nod_arg; do { - STUFF(blr_neq); + request->append_uchar(blr_neq); - prim_key_fld_name_str = (STR) (*prim_key_flds)->nod_arg[1]; + STR prim_key_fld_name_str = (STR) (*prim_key_flds)->nod_arg[1]; - STUFF(blr_field); - STUFF((SSHORT) 0); - put_cstring(request, 0, - reinterpret_cast < - char *>(prim_key_fld_name_str->str_data)); - STUFF(blr_field); - STUFF((SSHORT) 1); - put_cstring(request, 0, - reinterpret_cast < - char *>(prim_key_fld_name_str->str_data)); + request->append_uchar(blr_field); + request->append_uchar(0); + request->append_cstring(0, + reinterpret_cast(prim_key_fld_name_str->str_data)); + request->append_uchar(blr_field); + request->append_uchar(1); + request->append_cstring(0, + reinterpret_cast(prim_key_fld_name_str->str_data)); num_fields++; if (prim_columns->nod_count - num_fields >= (unsigned) 2) - STUFF(blr_or); + request->append_uchar(blr_or); prim_key_flds++; - } - while (num_fields < prim_columns->nod_count); + } while (num_fields < prim_columns->nod_count); } -static void modify_field( - REQ request, - NOD element, SSHORT position, STR relation_name) +static void modify_field(REQ request, + NOD element, + SSHORT position, + STR relation_name) { /************************************** * @@ -5442,43 +5459,49 @@ static void modify_field( DSQL_REL relation; field = (FLD) element->nod_arg[e_dfl_field]; - put_cstring(request, isc_dyn_mod_sql_fld, + request->append_cstring(isc_dyn_mod_sql_fld, reinterpret_cast(field->fld_name)); -/* add the field to the relation being defined for parsing purposes */ - if ((relation = request->req_relation) != NULL) { +// add the field to the relation being defined for parsing purposes + if ((relation = request->req_relation) != NULL) + { field->fld_next = relation->rel_fields; relation->rel_fields = field; } - if (domain_node = element->nod_arg[e_mod_fld_type_dom_name]) { + if (domain_node = element->nod_arg[e_mod_fld_type_dom_name]) + { NOD node1; STR domain_name; node1 = domain_node->nod_arg[e_dom_name]; domain_name = (STR) node1->nod_arg[e_fln_name]; - put_cstring(request, gds_dyn_fld_source, + request->append_cstring(gds_dyn_fld_source, reinterpret_cast(domain_name->str_data)); - /* Get the domain information */ + // Get the domain information - if (!(METD_get_domain(request, field, domain_name->str_data))) + if (!METD_get_domain(request, field, domain_name->str_data)) + { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 607, gds_arg_gds, gds_dsql_command_err, gds_arg_gds, gds_dsql_domain_not_found, /* Specified domain or source field does not exist */ 0); + } DDL_resolve_intl_type(request, field, NULL); } - else { - if (relation_name) - put_cstring(request, gds_dyn_rel_name, + else + { + if (relation_name) { + request->append_cstring(gds_dyn_rel_name, reinterpret_cast(relation_name->str_data)); + } DDL_resolve_intl_type(request, field, NULL); put_field(request, field, FALSE); } - STUFF(gds_dyn_end); + request->append_uchar(gds_dyn_end); } @@ -5497,12 +5520,14 @@ static void set_nod_value_attributes( NOD node, FLD field) * **************************************/ ULONG child_number; - NOD child; - for (child_number = 0; child_number < node->nod_count; ++child_number) { - child = node->nod_arg[child_number]; - if (child && (type_nod == child->nod_header.blk_type)) { - if (nod_dom_value == child->nod_type) { + for (child_number = 0; child_number < node->nod_count; ++child_number) + { + NOD child = node->nod_arg[child_number]; + if (child && MemoryPool::blk_type(child) == dsql_type_nod) + { + if (nod_dom_value == child->nod_type) + { assert(field->fld_dtype <= MAX_UCHAR); child->nod_desc.dsc_dtype = (UCHAR) field->fld_dtype; child->nod_desc.dsc_length = field->fld_length; @@ -5510,7 +5535,8 @@ static void set_nod_value_attributes( NOD node, FLD field) child->nod_desc.dsc_scale = (SCHAR) field->fld_scale; } else if ((nod_constant != child->nod_type) && - (child->nod_count > 0)) { + (child->nod_count > 0)) + { /* A nod_constant can have nod_arg entries which are not really pointers to other nodes, but rather integer values, so it is not safe to scan through its children. Fortunately, @@ -5526,4 +5552,109 @@ static void set_nod_value_attributes( NOD node, FLD field) } -} // extern "C" +void req::append_uchar(UCHAR byte) +{ + if (req_blr < req_blr_yellow) { + *req_blr++ = byte; + } else { + GEN_expand_buffer(this, byte); + } +} + +void req::append_uchars(UCHAR byte, UCHAR count) +{ + for (int i=0; i< count ; ++i) { + append_uchar(byte); + } +} + +void req::append_ushort(USHORT val) +{ + append_uchar(val); + append_uchar(val >> 8); +} + +void req::append_ulong(ULONG val) +{ + append_ushort(val); + append_ushort(val >> 16); +} + +void req::append_ushort_with_length(USHORT val) +{ + // append an USHORT value, prepended with the USHORT length of an USHORT + append_ushort(2); + append_ushort(val); +} + +void req::append_ulong_with_length(ULONG val) +{ + // append an ULONG value, prepended with the USHORT length of an ULONG + append_ushort(4); + append_ulong(val); +} + +void req::append_file_length(ULONG length) +{ + append_uchar(gds_dyn_file_length); + append_ulong_with_length(length); +} + +void req::append_file_start(ULONG start) +{ + append_uchar(gds_dyn_file_start); + append_ulong_with_length(start); +} + +// +// common code factored out +// +void req::generate_unnamed_trigger_beginning( bool on_update_trigger, + TEXT* prim_rel_name, + struct nod* prim_columns, + TEXT* for_rel_name, + struct nod* for_columns) +{ + // no trigger name. It is generated by the engine + append_string(gds_dyn_def_trigger, "", 0); + + append_number(gds_dyn_trg_type, + (SSHORT) (on_update_trigger ? POST_MODIFY_TRIGGER : + POST_ERASE_TRIGGER)); + + append_uchar(gds_dyn_sql_object); + append_number(gds_dyn_trg_sequence, 1); + append_number(gds_dyn_trg_inactive, 0); + append_cstring(gds_dyn_rel_name, prim_rel_name); + + // the trigger blr + begin_blr(gds_dyn_trg_blr); + +/* for ON UPDATE TRIGGER only: generate the trigger firing condition: + if prim_key.old_value != prim_key.new value. + Note that the key could consist of multiple columns */ + + if (on_update_trigger) { + stuff_trg_firing_cond(this, prim_columns); + append_uchars(blr_begin, 2); + } + + append_uchar(blr_for); + append_uchar(blr_rse); + + // the context for the prim. key relation + append_uchar(1); + append_uchar(blr_relation); + append_cstring(0, for_rel_name); + // the context for the foreign key relation + append_uchar(2); + + // generate the blr for: foreign_key == primary_key + stuff_matching_blr(this, for_columns, prim_columns); + + append_uchar(blr_modify); + append_uchar(2); + append_uchar(2); + append_uchar(blr_begin); +} + diff --git a/src/dsql/ddl_proto.h b/src/dsql/ddl_proto.h index 57adfca0e6..d52bc10a4c 100644 --- a/src/dsql/ddl_proto.h +++ b/src/dsql/ddl_proto.h @@ -24,18 +24,11 @@ #ifndef _DSQL_DDL_PROTO_H_ #define _DSQL_DDL_PROTO_H_ -#ifdef __cplusplus -extern "C" { -#endif +void DDL_execute(class req*); +void DDL_generate(class req*, struct nod*); +int DDL_ids(class req*); +void DDL_put_field_dtype(class req*, class fld*, USHORT); +void DDL_resolve_intl_type(class req*, class fld*, class str*); -void DDL_execute(struct req *); -void DDL_generate(struct req *, struct nod *); -int DDL_ids(struct req *); -void DDL_put_field_dtype(struct req *, struct fld *, USHORT); -void DDL_resolve_intl_type(struct req *, struct fld *, struct str *); - -#ifdef __cplusplus -} /* extern "C" */ -#endif #endif /* _DSQL_DDL_PROTO_H_ */ diff --git a/src/dsql/dsql.cpp b/src/dsql/dsql.cpp index 08aa473a31..15b824fd29 100644 --- a/src/dsql/dsql.cpp +++ b/src/dsql/dsql.cpp @@ -22,9 +22,10 @@ * 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" * conditionals, as the engine now fully supports * readonly databases. + * December 2001 Mike Nordell: Major overhaul to (try to) make it C++ */ /* -$Id: dsql.cpp,v 1.6 2001-07-29 23:43:21 skywalker Exp $ +$Id: dsql.cpp,v 1.7 2001-12-24 02:50:48 tamlin Exp $ */ /************************************************************** V4 Multi-threading changes. @@ -89,7 +90,9 @@ ASSERT_FILENAME #ifdef VMS #include #endif + extern "C" { + #ifdef NETWARE_386 #define PRINTF ConsolePrintf #endif @@ -106,13 +109,14 @@ extern "C" { return tdsql->tsql_status [1];\ };\ } -#define RETURN_SUCCESS return return_success() + #define SET_THREAD_DATA {\ tdsql = &thd_context;\ THD_put_specific ((THDD) tdsql);\ tdsql->tsql_thd_data.thdd_type = THDD_TYPE_TSQL;\ } #define RESTORE_THREAD_DATA THD_restore_specific() + #ifdef STACK_REDUCTION #define FREE_MEM_RETURN {\ if (buffer)\ @@ -125,32 +129,33 @@ extern "C" { #else #define FREE_MEM_RETURN return #endif -static void cleanup(void *); -static void cleanup_database(SLONG **, SLONG); -static void cleanup_transaction(SLONG *, SLONG); -static void close_cursor(REQ); -static USHORT convert(SLONG, SCHAR *); -static STATUS error(void); -static void execute_blob(REQ, USHORT, UCHAR *, USHORT, UCHAR *, - USHORT, UCHAR *, USHORT, UCHAR *); -static STATUS execute_request(REQ, isc_tr_handle*, USHORT, UCHAR *, USHORT, UCHAR *, - USHORT, UCHAR *, USHORT, UCHAR *, USHORT); -static SSHORT filter_sub_type(REQ, NOD); -static BOOLEAN get_indices(SSHORT *, SCHAR **, SSHORT *, SCHAR **); -static USHORT get_plan_info(REQ, SSHORT, SCHAR **); -static USHORT get_request_info(REQ, SSHORT, SCHAR *); -static BOOLEAN get_rsb_item(SSHORT *, SCHAR **, SSHORT *, SCHAR **, USHORT *, - USHORT *); -static DBB init(SLONG **); -static void map_in_out(REQ, MSG, USHORT, UCHAR *, USHORT, UCHAR *); -static USHORT name_length(TEXT *); -static USHORT parse_blr(USHORT, UCHAR *, USHORT, PAR); -static REQ prepare(REQ, USHORT, TEXT *, USHORT, USHORT); -static void punt(void); -static SCHAR *put_item(SCHAR, USHORT, SCHAR *, SCHAR *, SCHAR *); -static void release_request(REQ, USHORT); -static STATUS return_success(void); -static SCHAR *var_info(MSG, SCHAR *, SCHAR *, SCHAR *, SCHAR *, USHORT); + +static void cleanup(void*); +static void cleanup_database(SLONG**, SLONG); +static void cleanup_transaction(SLONG*, SLONG); +static void close_cursor(REQ); +static USHORT convert(SLONG, SCHAR*); +static STATUS error(); +static void execute_blob(REQ, USHORT, UCHAR*, USHORT, UCHAR*, + USHORT, UCHAR*, USHORT, UCHAR*); +static STATUS execute_request(REQ, isc_tr_handle*, USHORT, UCHAR*, USHORT, UCHAR*, + USHORT, UCHAR*, USHORT, UCHAR*, USHORT); +static SSHORT filter_sub_type(REQ, NOD); +static BOOLEAN get_indices(SSHORT*, SCHAR**, SSHORT*, SCHAR**); +static USHORT get_plan_info(REQ, SSHORT, SCHAR**); +static USHORT get_request_info(REQ, SSHORT, SCHAR*); +static BOOLEAN get_rsb_item(SSHORT*, SCHAR**, SSHORT*, SCHAR**, USHORT*, + USHORT*); +static DBB init(SLONG**); +static void map_in_out(REQ, MSG, USHORT, UCHAR*, USHORT, UCHAR*); +static USHORT name_length(TEXT*); +static USHORT parse_blr(USHORT, UCHAR*, USHORT, PAR); +static REQ prepare(REQ, USHORT, TEXT*, USHORT, USHORT); +static void punt(void); +static SCHAR* put_item(SCHAR, USHORT, SCHAR*, SCHAR*, SCHAR*); +static void release_request(REQ, USHORT); +static STATUS return_success(void); +static SCHAR* var_info(MSG, SCHAR*, SCHAR*, SCHAR*, SCHAR*, USHORT); extern NOD DSQL_parse; @@ -182,26 +187,284 @@ static MUTX_T cursors_mutex; static USHORT mutex_inited = 0; #endif -/* STUFF_INFO used in place of STUFF to avoid confusion with BLR STUFF - macro defined in dsql.h */ -#define STUFF_INFO_WORD(p,value) {*p++ = (UCHAR)value; *p++ = value >> 8;} -#define STUFF_INFO(p,value) *p++ = value; +////////////////////////////////////////////////////////////////// +// declarations of the C++ implementations of the C API functions +// with the matching name. +////////////////////////////////////////////////////////////////// -#define GDS_DSQL_ALLOCATE dsql8_allocate_statement -#define GDS_DSQL_EXECUTE dsql8_execute +static +STATUS GDS_DSQL_ALLOCATE_CPP( STATUS* user_status, + int** db_handle, + req** req_handle); + +static +STATUS GDS_DSQL_EXECUTE_CPP( STATUS* user_status, + isc_tr_handle* trans_handle, + req** req_handle, + USHORT in_blr_length, + UCHAR* in_blr, + USHORT in_msg_type, + USHORT in_msg_length, + UCHAR* in_msg, + USHORT out_blr_length, + UCHAR* out_blr, + USHORT out_msg_type, + USHORT out_msg_length, + UCHAR* out_msg); + +static +STATUS GDS_DSQL_FETCH_CPP( STATUS* user_status, + req** req_handle, + USHORT blr_length, + UCHAR* blr, + USHORT msg_type, + USHORT msg_length, + UCHAR* msg +#ifdef SCROLLABLE_CURSORS + , USHORT direction, SLONG offset) +#else + ); +#endif + +static +STATUS GDS_DSQL_FREE_CPP(STATUS* user_status, + req** req_handle, + USHORT option); + +static +STATUS GDS_DSQL_INSERT_CPP( STATUS* user_status, + req** req_handle, + USHORT blr_length, + UCHAR* blr, + USHORT msg_type, + USHORT msg_length, + UCHAR* msg); + +static +STATUS GDS_DSQL_PREPARE_CPP(STATUS* user_status, + isc_tr_handle* trans_handle, + req** req_handle, + USHORT length, + TEXT* string, + USHORT dialect, + USHORT item_length, + UCHAR* items, + USHORT buffer_length, + UCHAR* buffer); + +static +STATUS GDS_DSQL_SQL_INFO_CPP( STATUS* user_status, + req** req_handle, + USHORT item_length, + SCHAR* items, + USHORT info_length, + SCHAR* info); + +STATUS GDS_DSQL_SET_CURSOR_CPP( STATUS* user_status, + req** req_handle, + TEXT* input_cursor, + USHORT type); + +#define GDS_DSQL_ALLOCATE dsql8_allocate_statement +#define GDS_DSQL_EXECUTE dsql8_execute #define GDS_DSQL_EXECUTE_IMMED dsql8_execute_immediate -#define GDS_DSQL_FETCH dsql8_fetch -#define GDS_DSQL_FREE dsql8_free_statement -#define GDS_DSQL_INSERT dsql8_insert -#define GDS_DSQL_PREPARE dsql8_prepare -#define GDS_DSQL_SET_CURSOR dsql8_set_cursor -#define GDS_DSQL_SQL_INFO dsql8_sql_info +#define GDS_DSQL_FETCH dsql8_fetch +#define GDS_DSQL_FREE dsql8_free_statement +#define GDS_DSQL_INSERT dsql8_insert +#define GDS_DSQL_PREPARE dsql8_prepare +#define GDS_DSQL_SET_CURSOR dsql8_set_cursor +#define GDS_DSQL_SQL_INFO dsql8_sql_info + +} // extern "C" + +extern "C" { + +////////////////////////////////////////////////////////////////// +// Begin : C API -> C++ wrapper functions +// Note that we don't wrap GDS_DSQL_EXECUTE_IMMED since it +// contains no req in its parameter list. +////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_ALLOCATE( STATUS* user_status, + int** db_handle, + struct dsql_req** req_handle) +{ + return GDS_DSQL_ALLOCATE_CPP(user_status, + db_handle, + reinterpret_cast(req_handle)); +} + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_EXECUTE( STATUS* user_status, + isc_tr_handle* trans_handle, + struct dsql_req** req_handle, + USHORT in_blr_length, + UCHAR* in_blr, + USHORT in_msg_type, + USHORT in_msg_length, + UCHAR* in_msg, + USHORT out_blr_length, + UCHAR* out_blr, + USHORT out_msg_type, + USHORT out_msg_length, + UCHAR* out_msg) +{ + return GDS_DSQL_EXECUTE_CPP(user_status, + trans_handle, + reinterpret_cast(req_handle), + in_blr_length, + in_blr, + in_msg_type, + in_msg_length, + in_msg, + out_blr_length, + out_blr, + out_msg_type, + out_msg_length, + out_msg); +} + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_FETCH( STATUS* user_status, + struct dsql_req** req_handle, + USHORT blr_length, + UCHAR* blr, + USHORT msg_type, + USHORT msg_length, + UCHAR* msg +#ifdef SCROLLABLE_CURSORS + , USHORT direction, SLONG offset +#endif + ) +{ + return GDS_DSQL_FETCH_CPP( user_status, + reinterpret_cast(req_handle), + blr_length, + blr, + msg_type, + msg_length, + msg +#ifdef SCROLLABLE_CURSORS + , direction, offset +#endif + ); +} + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_FREE( STATUS* user_status, + struct dsql_req** req_handle, + USHORT option) +{ + return GDS_DSQL_FREE_CPP(user_status, + reinterpret_cast(req_handle), + option); +} + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_INSERT(STATUS* user_status, + struct dsql_req** req_handle, + USHORT blr_length, + UCHAR* blr, + USHORT msg_type, + USHORT msg_length, + UCHAR* msg) +{ + return GDS_DSQL_INSERT_CPP( user_status, + reinterpret_cast(req_handle), + blr_length, + blr, + msg_type, + msg_length, + msg); +} + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_PREPARE( STATUS* user_status, + isc_tr_handle* trans_handle, + struct dsql_req** req_handle, + USHORT length, + TEXT* string, + USHORT dialect, + USHORT item_length, + UCHAR* items, + USHORT buffer_length, + UCHAR* buffer) +{ + return GDS_DSQL_PREPARE_CPP(user_status, + trans_handle, + reinterpret_cast(req_handle), + length, + string, + dialect, + item_length, + items, + buffer_length, + buffer); + +} + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_SQL_INFO( STATUS* user_status, + struct dsql_req** req_handle, + USHORT item_length, + SCHAR* items, + USHORT info_length, + SCHAR* info) +{ + return GDS_DSQL_SQL_INFO_CPP( user_status, + reinterpret_cast(req_handle), + item_length, + items, + info_length, + info); +} + +////////////////////////////////////////////////////////////////// + +STATUS DLL_EXPORT +GDS_DSQL_SET_CURSOR(STATUS* user_status, + dsql_req** req_handle, + TEXT* input_cursor, + USHORT type) +{ + return GDS_DSQL_SET_CURSOR_CPP(user_status, + reinterpret_cast(req_handle), + input_cursor, + type); +} + +////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////// +// End : C API -> C++ wrapper functions +////////////////////////////////////////////////////////////////// -STATUS DLL_EXPORT GDS_DSQL_ALLOCATE(STATUS* user_status, - int** db_handle, - REQ* req_handle) +} // extern "C" + +extern "C" { + + +static STATUS +GDS_DSQL_ALLOCATE_CPP( STATUS* user_status, + int** db_handle, + req** req_handle) { /************************************** * @@ -227,32 +490,33 @@ STATUS DLL_EXPORT GDS_DSQL_ALLOCATE(STATUS* user_status, database = init((SLONG **) db_handle); - tdsql->tsql_default = ALLD_pool(); + tdsql->tsql_default = new(*DSQL_permanent_pool) DsqlMemoryPool; /* allocate the request block */ - request = (REQ) ALLOCD(type_req); + request = new(*tdsql->tsql_default) req; request->req_dbb = database; request->req_pool = tdsql->tsql_default; *req_handle = request; - RETURN_SUCCESS; + return return_success(); } -STATUS DLL_EXPORT GDS_DSQL_EXECUTE(STATUS * user_status, - isc_tr_handle * trans_handle, - REQ * req_handle, - USHORT in_blr_length, - UCHAR * in_blr, - USHORT in_msg_type, - USHORT in_msg_length, - UCHAR * in_msg, - USHORT out_blr_length, - UCHAR * out_blr, - USHORT out_msg_type, - USHORT out_msg_length, UCHAR * out_msg) +STATUS DLL_EXPORT GDS_DSQL_EXECUTE_CPP(STATUS* user_status, + isc_tr_handle* trans_handle, + req** req_handle, + USHORT in_blr_length, + UCHAR* in_blr, + USHORT in_msg_type, + USHORT in_msg_length, + UCHAR* in_msg, + USHORT out_blr_length, + UCHAR* out_blr, + USHORT out_msg_type, + USHORT out_msg_length, + UCHAR* out_msg) { /************************************** * @@ -339,7 +603,7 @@ STATUS DLL_EXPORT GDS_DSQL_EXECUTE(STATUS * user_status, ((request-> req_type == REQ_EMBED_SELECT) ? REQ_embedded_sql_cursor : 0); - request->req_open_cursor = open_cursor = (OPN) ALLOCP(type_opn); + request->req_open_cursor = open_cursor = new(*DSQL_permanent_pool) opn; open_cursor->opn_request = request; open_cursor->opn_transaction = (SLONG *) * trans_handle; THD_MUTEX_LOCK(&cursors_mutex); @@ -353,31 +617,31 @@ STATUS DLL_EXPORT GDS_DSQL_EXECUTE(STATUS * user_status, THREAD_ENTER; } - if (!sing_status) - RETURN_SUCCESS; - else { - RESTORE_THREAD_DATA; - return sing_status; + if (!sing_status) { + return return_success(); } + + RESTORE_THREAD_DATA; + return sing_status; } -STATUS DLL_EXPORT GDS_DSQL_EXECUTE_IMMED(STATUS * user_status, - int **db_handle, - int **trans_handle, - USHORT length, - TEXT * string, - USHORT dialect, - USHORT in_blr_length, - UCHAR * in_blr, - USHORT in_msg_type, - USHORT in_msg_length, - UCHAR * in_msg, - USHORT out_blr_length, - UCHAR * out_blr, - USHORT out_msg_type, - USHORT out_msg_length, - UCHAR * out_msg) +STATUS DLL_EXPORT GDS_DSQL_EXECUTE_IMMED(STATUS* user_status, + int** db_handle, + int** trans_handle, + USHORT length, + TEXT* string, + USHORT dialect, + USHORT in_blr_length, + UCHAR* in_blr, + USHORT in_msg_type, + USHORT in_msg_length, + UCHAR* in_msg, + USHORT out_blr_length, + UCHAR* out_blr, + USHORT out_msg_type, + USHORT out_msg_length, + UCHAR* out_msg) { /************************************** * @@ -401,24 +665,20 @@ STATUS DLL_EXPORT GDS_DSQL_EXECUTE_IMMED(STATUS * user_status, ERROR_INIT(env); database = init(reinterpret_cast < long **>(db_handle)); - tdsql->tsql_default = ALLD_pool(); + tdsql->tsql_default = new(*DSQL_permanent_pool) DsqlMemoryPool; /* allocate the request block, then prepare the request */ - request = (REQ) ALLOCD(type_req); + request = new(*tdsql->tsql_default) req; request->req_dbb = database; request->req_pool = tdsql->tsql_default; request->req_trans = (int *) *trans_handle; - if (SETJMP(*tdsql->tsql_setjmp)) { - status = error(); - release_request(request, TRUE); - RESTORE_THREAD_DATA; - return status; - } + try { - if (!length) + if (!length) { length = strlen(string); + } /* Figure out which parser version to use */ /* Since the API to GDS_DSQL_EXECUTE_IMMED is public and can not be changed, there needs to @@ -468,21 +728,29 @@ STATUS DLL_EXPORT GDS_DSQL_EXECUTE_IMMED(STATUS * user_status, release_request(request, TRUE); - RETURN_SUCCESS; + return return_success(); + + } // try + catch (...) { + status = error(); + release_request(request, TRUE); + RESTORE_THREAD_DATA; + return status; + } } -STATUS DLL_EXPORT GDS_DSQL_FETCH(STATUS * user_status, - REQ * req_handle, - USHORT blr_length, - UCHAR * blr, - USHORT msg_type, - USHORT msg_length, UCHAR * msg +STATUS GDS_DSQL_FETCH_CPP( STATUS* user_status, + req** req_handle, + USHORT blr_length, + UCHAR* blr, + USHORT msg_type, + USHORT msg_length, + UCHAR* msg #ifdef SCROLLABLE_CURSORS - , USHORT direction, SLONG offset) -#else - ) + , USHORT direction, SLONG offset #endif + ) { /************************************** * @@ -682,12 +950,13 @@ STATUS DLL_EXPORT GDS_DSQL_FETCH(STATUS * user_status, map_in_out(NULL, message, 0, blr, msg_length, msg); - RETURN_SUCCESS; + return return_success(); } -STATUS DLL_EXPORT GDS_DSQL_FREE(STATUS * user_status, - REQ * req_handle, USHORT option) +STATUS GDS_DSQL_FREE_CPP(STATUS* user_status, + req** req_handle, + USHORT option) { /************************************** * @@ -727,16 +996,17 @@ STATUS DLL_EXPORT GDS_DSQL_FREE(STATUS * user_status, close_cursor(request); } - RETURN_SUCCESS; + return return_success(); } -STATUS DLL_EXPORT GDS_DSQL_INSERT(STATUS * user_status, - REQ * req_handle, - USHORT blr_length, - UCHAR * blr, - USHORT msg_type, - USHORT msg_length, UCHAR * msg) +STATUS GDS_DSQL_INSERT_CPP( STATUS* user_status, + req** req_handle, + USHORT blr_length, + UCHAR* blr, + USHORT msg_type, + USHORT msg_length, + UCHAR* msg) { /************************************** * @@ -797,19 +1067,20 @@ STATUS DLL_EXPORT GDS_DSQL_INSERT(STATUS * user_status, punt(); } - RETURN_SUCCESS; + return return_success(); } -STATUS DLL_EXPORT GDS_DSQL_PREPARE(STATUS * user_status, - isc_tr_handle * trans_handle, - REQ * req_handle, - USHORT length, - TEXT * string, - USHORT dialect, - USHORT item_length, - UCHAR * items, - USHORT buffer_length, UCHAR * buffer) +STATUS GDS_DSQL_PREPARE_CPP(STATUS* user_status, + isc_tr_handle* trans_handle, + req** req_handle, + USHORT length, + TEXT* string, + USHORT dialect, + USHORT item_length, + UCHAR* items, + USHORT buffer_length, + UCHAR* buffer) { /************************************** * @@ -849,19 +1120,14 @@ STATUS DLL_EXPORT GDS_DSQL_PREPARE(STATUS * user_status, /* It would be really *nice* to know *why* we want to keep the old request around -- 1994-October-27 David Schnepper */ - tdsql->tsql_default = ALLD_pool(); + tdsql->tsql_default = new(*DSQL_permanent_pool) DsqlMemoryPool; - request = (REQ) ALLOCD(type_req); + request = new(*tdsql->tsql_default) req; request->req_dbb = database; request->req_pool = tdsql->tsql_default; request->req_trans = (int *) *trans_handle; - if (SETJMP(*tdsql->tsql_setjmp)) { - status = error(); - release_request(request, TRUE); - RESTORE_THREAD_DATA; - return status; - } + try { if (!length) length = strlen(string); @@ -923,15 +1189,27 @@ STATUS DLL_EXPORT GDS_DSQL_PREPARE(STATUS * user_status, RESTORE_THREAD_DATA; - return GDS_DSQL_SQL_INFO(user_status, req_handle, item_length, - reinterpret_cast < char *>(items), buffer_length, - reinterpret_cast < char *>(buffer)); + return GDS_DSQL_SQL_INFO_CPP( user_status, + req_handle, + item_length, + reinterpret_cast(items), + buffer_length, + reinterpret_cast(buffer)); + + } // try + catch(...) { + status = error(); + release_request(request, TRUE); + RESTORE_THREAD_DATA; + return status; + } } -STATUS DLL_EXPORT GDS_DSQL_SET_CURSOR(STATUS * user_status, - REQ * req_handle, - TEXT * input_cursor, USHORT type) +STATUS GDS_DSQL_SET_CURSOR_CPP( STATUS* user_status, + req** req_handle, + TEXT* input_cursor, + USHORT type) { /***************************************** * @@ -958,63 +1236,71 @@ STATUS DLL_EXPORT GDS_DSQL_SET_CURSOR(STATUS * user_status, request = *req_handle; tdsql->tsql_default = request->req_pool; - if (input_cursor[0] == '\"') { - /** Quoted cursor names eh? Strip'em. - Note that "" will be replaced with ". - **/ - int ij; - for (ij = 0; *input_cursor; input_cursor++) { - if (*input_cursor == '\"') + if (input_cursor[0] == '\"') + { + // Quoted cursor names eh? Strip'em. + // Note that "" will be replaced with ". + // + int index; + for (index = 0; *input_cursor; input_cursor++) { + if (*input_cursor == '\"') { input_cursor++; - cursor[ij++] = *input_cursor; + } + cursor[index++] = *input_cursor; } - cursor[ij] = 0; + cursor[index] = 0; } - else { + else // not quoted name + { USHORT i; for (i = 0; i < sizeof(cursor) - 1 /* PJPG 20001013 */ && input_cursor[i] /* PJPG 20001013 */ - &&input_cursor[i] != ' '; i++) /* PJPG 20001013 */ + && input_cursor[i] != ' '; ++i) /* PJPG 20001013 */ + { cursor[i] = UPPER7(input_cursor[i]); + } cursor[i] = '\0'; } length = name_length(cursor); - if (length == 0) + if (length == 0) { ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 502, gds_arg_gds, gds_dsql_decl_err, 0); + } /* If there already is a different cursor by the same name, bitch */ if (symbol = HSHD_lookup(request->req_dbb, cursor, length, SYM_cursor, 0)) { - if (request->req_cursor == symbol) - RETURN_SUCCESS; - else - ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 502, - gds_arg_gds, gds_dsql_decl_err, 0); + if (request->req_cursor == symbol) { + return return_success(); + } + + ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 502, + gds_arg_gds, gds_dsql_decl_err, 0); } /* If there already is a cursor and its name isn't the same, ditto. We already know there is no cursor by this name in the hash table */ - if (!request->req_cursor) + if (!request->req_cursor) { request->req_cursor = MAKE_symbol(request->req_dbb, cursor, length, SYM_cursor, request); - else { + } else { assert(request->req_cursor != symbol); ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 502, gds_arg_gds, gds_dsql_decl_err, 0); - }; + } - RETURN_SUCCESS; + return return_success(); } -STATUS DLL_EXPORT GDS_DSQL_SQL_INFO(STATUS * user_status, - REQ * req_handle, - USHORT item_length, - SCHAR * items, - USHORT info_length, SCHAR * info) +STATUS GDS_DSQL_SQL_INFO_CPP( STATUS* user_status, + req** req_handle, + USHORT item_length, + SCHAR* items, + USHORT info_length, + SCHAR* info) { /************************************** * @@ -1048,18 +1334,21 @@ STATUS DLL_EXPORT GDS_DSQL_SQL_INFO(STATUS * user_status, message = NULL; first_index = 0; - while (items < end_items && *items != gds_info_end) { + while (items < end_items && *items != gds_info_end) + { item = *items++; - if (item == gds_info_sql_select || item == gds_info_sql_bind) { + if (item == gds_info_sql_select || item == gds_info_sql_bind) + { message = (item == gds_info_sql_select) ? &request->req_receive : &request->req_send; if (info + 1 >= end_info) { *info = gds_info_truncated; - RETURN_SUCCESS; + return return_success(); } *info++ = item; } - else if (item == gds_info_sql_stmt_type) { + else if (item == gds_info_sql_stmt_type) + { switch (request->req_type) { case REQ_SELECT: case REQ_EMBED_SELECT: @@ -1109,16 +1398,17 @@ STATUS DLL_EXPORT GDS_DSQL_SQL_INFO(STATUS * user_status, break; } length = convert((SLONG) number, buffer); - if (!(info = put_item(item, length, buffer, info, end_info))) { - RETURN_SUCCESS; + info = put_item(item, length, buffer, info, end_info); + if (!info) { + return return_success(); } } else if (item == gds_info_sql_sqlda_start) { length = *items++; first_index = - static_cast < USHORT > + static_cast (gds__vax_integer - (reinterpret_cast < UCHAR * >(items), length)); + (reinterpret_cast(items), length)); items += length; } else if (item == isc_info_sql_batch_fetch) { @@ -1128,7 +1418,7 @@ STATUS DLL_EXPORT GDS_DSQL_SQL_INFO(STATUS * user_status, number = TRUE; length = convert((SLONG) number, buffer); if (!(info = put_item(item, length, buffer, info, end_info))) { - RETURN_SUCCESS; + return return_success(); } } else if (item == gds_info_sql_records) { @@ -1136,7 +1426,7 @@ STATUS DLL_EXPORT GDS_DSQL_SQL_INFO(STATUS * user_status, get_request_info(request, (SSHORT) sizeof(buffer), buffer); if (length && !(info = put_item(item, length, buffer, info, end_info))) { - RETURN_SUCCESS; + return return_success(); } } else if (item == gds_info_sql_get_plan) { @@ -1154,53 +1444,60 @@ STATUS DLL_EXPORT GDS_DSQL_SQL_INFO(STATUS * user_status, gds__free(buffer_ptr); if (!info) - RETURN_SUCCESS; + return return_success(); } else if (!message || (item != gds_info_sql_num_variables - && item != gds_info_sql_describe_vars)) { + && item != gds_info_sql_describe_vars)) + { buffer[0] = item; item = gds_info_error; length = 1 + convert((SLONG) gds_infunk, buffer + 1); if (!(info = put_item(item, length, buffer, info, end_info))) { - RETURN_SUCCESS; + return return_success(); } } - else { + else + { number = (*message) ? (*message)->msg_index : 0; length = convert((SLONG) number, buffer); if (!(info = put_item(item, length, buffer, info, end_info))) { - RETURN_SUCCESS; + return return_success(); } - if (item == gds_info_sql_num_variables) + if (item == gds_info_sql_num_variables) { continue; + } end_describe = items; while (end_describe < end_items && *end_describe != gds_info_end && *end_describe != gds_info_sql_describe_end) end_describe++; - if (! - (info = - var_info(*message, items, end_describe, info, end_info, - first_index))) { - RETURN_SUCCESS; + info = var_info(*message, + items, + end_describe, + info, + end_info, + first_index); + if (!info) { + return return_success(); } items = end_describe; - if (*items == gds_info_sql_describe_end) + if (*items == gds_info_sql_describe_end) { items++; + } } } *info++ = gds_info_end; - RETURN_SUCCESS; + return return_success(); } #ifdef DEV_BUILD -void DSQL_pretty( NOD node, int column) +void DSQL_pretty(NOD node, int column) { /************************************** * @@ -1213,32 +1510,34 @@ void DSQL_pretty( NOD node, int column) * **************************************/ MAP map; - NOD *ptr, *end; DSQL_REL relation; CTX context; FLD field; STR string; VAR variable; + #ifdef STACK_REDUCTION - TEXT *buffer, *p, *verb, s[64]; + TEXT* buffer; #else - TEXT buffer[1024], *p, *verb, s[64]; + TEXT buffer[1024]; #endif - USHORT l; + + TEXT* verb; + TEXT s[64]; #ifdef STACK_REDUCTION buffer = (TEXT *) gds__alloc(BUFFER_LARGE); #endif - p = buffer; - sprintf(p, "%.7X ", node); - while (*p) - p++; + TEXT* p = buffer; + p += sprintf(p, "%.7X ", node); - if ((l = column * 3) != NULL) - do + if (column) { + USHORT l = column * 3; + do { *p++ = ' '; - while (--l); + } while (--l); + } *p = 0; @@ -1247,20 +1546,20 @@ void DSQL_pretty( NOD node, int column) FREE_MEM_RETURN; } - switch (node->nod_header.blk_type) { - case (TEXT) type_str: + switch (MemoryPool::blk_type(node)) { + case (TEXT) dsql_type_str: PRINTF("%sSTRING: \"%s\"\n", buffer, ((STR) node)->str_data); FREE_MEM_RETURN; - case (TEXT) type_fld: + case (TEXT) dsql_type_fld: PRINTF("%sFIELD: %s\n", buffer, ((FLD) node)->fld_name); FREE_MEM_RETURN; - case (TEXT) type_sym: + case (TEXT) dsql_type_sym: PRINTF("%sSYMBOL: %s\n", buffer, ((SYM) node)->sym_string); FREE_MEM_RETURN; - case (TEXT) type_nod: + case (TEXT) dsql_type_nod: break; default: @@ -1268,8 +1567,8 @@ void DSQL_pretty( NOD node, int column) FREE_MEM_RETURN; } - ptr = node->nod_arg; - end = ptr + node->nod_count; + NOD* ptr = node->nod_arg; + NOD* end = ptr + node->nod_count; switch (node->nod_type) { case nod_abort: @@ -1731,17 +2030,19 @@ void DSQL_pretty( NOD node, int column) verb = s; } - if (node->nod_desc.dsc_dtype) + if (node->nod_desc.dsc_dtype) { PRINTF("%s%s (%d,%d,%x)\n", buffer, verb, node->nod_desc.dsc_dtype, node->nod_desc.dsc_length, node->nod_desc.dsc_address); - else + } else { PRINTF("%s%s\n", buffer, verb); + } ++column; - while (ptr < end) + while (ptr < end) { DSQL_pretty(*ptr++, column); + } FREE_MEM_RETURN; } @@ -1815,7 +2116,7 @@ static void cleanup_database( SLONG ** db_handle, SLONG flag) THREAD_ENTER; } HSHD_finish(dbb); - ALLD_rlpool(dbb->dbb_pool); + delete dbb->dbb_pool; } if (!databases) { @@ -1862,8 +2163,9 @@ static void cleanup_transaction( SLONG * tra_handle, SLONG arg) * call in why.c below the cleanup handlers. smistry 9-27-98 */ THREAD_ENTER; - GDS_DSQL_FREE(local_status, &open_cursor->opn_request, - DSQL_close); + GDS_DSQL_FREE_CPP( local_status, + &open_cursor->opn_request, + DSQL_close); THREAD_EXIT; THD_MUTEX_LOCK(&cursors_mutex); open_cursor_ptr = &open_cursors; @@ -1921,7 +2223,7 @@ static void close_cursor( REQ request) THD_MUTEX_UNLOCK(&cursors_mutex); if (open_cursor) { - ALLD_release(reinterpret_cast(open_cursor)); + delete open_cursor; request->req_open_cursor = NULL; } } @@ -1965,7 +2267,7 @@ static USHORT convert( SLONG number, SCHAR * buffer) } -static STATUS error(void) +static STATUS error() { /************************************** * @@ -1977,9 +2279,8 @@ static STATUS error(void) * An error returned has been trapped. * **************************************/ - TSQL tdsql; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; return tdsql->tsql_status[1]; } @@ -2035,47 +2336,49 @@ static void execute_blob( REQ request, *p++ = filter >> 8; } bpb_length = p - bpb; - if (bpb_length == 1) + if (bpb_length == 1) { bpb_length = 0; + } parameter = blob->blb_blob_id; null = parameter->par_null; - if (request->req_type == REQ_GET_SEGMENT) { + if (request->req_type == REQ_GET_SEGMENT) + { blob_id = (GDS__QUAD *) parameter->par_desc.dsc_address; - if (null && *((SSHORT *) null->par_desc.dsc_address) < 0) + if (null && *((SSHORT *) null->par_desc.dsc_address) < 0) { memset(blob_id, 0, sizeof(GDS__QUAD)); + } THREAD_EXIT; s = isc_open_blob2(tdsql->tsql_status, reinterpret_cast(GDS_REF(request->req_dbb->dbb_database_handle)), reinterpret_cast(GDS_REF(request->req_trans)), - reinterpret_cast(GDS_REF(request->req_handle)), + reinterpret_cast(GDS_REF(request->req_handle)), GDS_VAL(blob_id), bpb_length, reinterpret_cast(bpb)); THREAD_ENTER; - if (s) + if (s) { punt(); + } } - else { + else + { request->req_handle = NULL; blob_id = (GDS__QUAD *) parameter->par_desc.dsc_address; memset(blob_id, 0, sizeof(GDS__QUAD)); THREAD_EXIT; s = isc_create_blob2(tdsql->tsql_status, - reinterpret_cast < - void - **>(GDS_REF - (request->req_dbb->dbb_database_handle)), - reinterpret_cast < - void **>(GDS_REF(request->req_trans)), - reinterpret_cast < - void **>(GDS_REF(request->req_handle)), + reinterpret_cast( + GDS_REF(request->req_dbb->dbb_database_handle)), + reinterpret_cast(GDS_REF(request->req_trans)), + reinterpret_cast(GDS_REF(request->req_handle)), GDS_VAL(blob_id), bpb_length, - reinterpret_cast < char *>(bpb)); + reinterpret_cast(bpb)); THREAD_ENTER; - if (s) + if (s) { punt(); + } map_in_out(NULL, blob->blb_open_out_msg, out_blr_length, out_blr, out_msg_length, out_msg); } @@ -2135,8 +2438,7 @@ static STATUS execute_request(REQ request, case REQ_COMMIT: THREAD_EXIT; s = isc_commit_transaction(tdsql->tsql_status, - reinterpret_cast < - void **>(&request->req_trans)); + reinterpret_cast(&request->req_trans)); THREAD_ENTER; if (s) punt(); @@ -2146,8 +2448,7 @@ static STATUS execute_request(REQ request, case REQ_COMMIT_RETAIN: THREAD_EXIT; s = isc_commit_retaining(tdsql->tsql_status, - reinterpret_cast < - void **>(&request->req_trans)); + reinterpret_cast(&request->req_trans)); THREAD_ENTER; if (s) punt(); @@ -2156,8 +2457,7 @@ static STATUS execute_request(REQ request, case REQ_ROLLBACK: THREAD_EXIT; s = isc_rollback_transaction(tdsql->tsql_status, - reinterpret_cast < - void **>(&request->req_trans)); + reinterpret_cast(&request->req_trans)); THREAD_ENTER; if (s) punt(); @@ -2204,9 +2504,10 @@ static STATUS execute_request(REQ request, in_msg = NULL; } if (out_msg_length && (message = (MSG) request->req_receive)) { - if (out_blr_length) + if (out_blr_length) { parse_blr(out_blr_length, out_blr, out_msg_length, message->msg_parameters); + } use_msg_length = message->msg_length; use_msg = message->msg_buffer; } @@ -2296,9 +2597,10 @@ static STATUS execute_request(REQ request, /* Insure that the blr for the message is parsed, regardless of whether anything is found by the call to receive. */ - if (out_blr_length) + if (out_blr_length) { parse_blr(out_blr_length, out_blr, out_msg_length, message->msg_parameters); + } THREAD_EXIT; s = isc_receive(tdsql->tsql_status, @@ -2308,8 +2610,9 @@ static STATUS execute_request(REQ request, message->msg_buffer, 0); THREAD_ENTER; - if (s) + if (s) { punt(); + } map_in_out(NULL, message, 0, out_blr, out_msg_length, out_msg); @@ -2325,7 +2628,7 @@ static STATUS execute_request(REQ request, In either case, there's more than one record. */ UCHAR* message_buffer = - (UCHAR*)ALLD_malloc((ULONG) message->msg_length); + (UCHAR*)MemoryPool::malloc_from_system((ULONG) message->msg_length); s = 0; THREAD_EXIT; @@ -2339,7 +2642,7 @@ static STATUS execute_request(REQ request, 0); } THREAD_ENTER; - ALLD_free(message_buffer); + MemoryPool::free_from_system(message_buffer); /* two successful receives means more than one record a req_sync error on the first pass above means no records @@ -2370,10 +2673,12 @@ static STATUS execute_request(REQ request, { if (request->req_type == REQ_UPDATE_CURSOR) { - GDS_DSQL_SQL_INFO(local_status, &request, - sizeof(sql_records_info), - const_cast < char *>(sql_records_info), - sizeof(buffer), buffer); + GDS_DSQL_SQL_INFO_CPP( local_status, + &request, + sizeof(sql_records_info), + const_cast(sql_records_info), + sizeof(buffer), + buffer); if (!request->req_updates) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 913, @@ -2383,10 +2688,12 @@ static STATUS execute_request(REQ request, } else if (request->req_type == REQ_DELETE_CURSOR) { - GDS_DSQL_SQL_INFO(local_status, &request, - sizeof(sql_records_info), - const_cast < char *>(sql_records_info), - sizeof(buffer), buffer); + GDS_DSQL_SQL_INFO_CPP( local_status, + &request, + sizeof(sql_records_info), + const_cast(sql_records_info), + sizeof(buffer), + buffer); if (!request->req_deletes) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 913, @@ -2680,11 +2987,12 @@ static USHORT get_request_info( } -static BOOLEAN get_rsb_item( - SSHORT * explain_length_ptr, - SCHAR ** explain_ptr, - SSHORT * plan_length_ptr, -SCHAR ** plan_ptr, USHORT * parent_join_count, USHORT * level_ptr) +static BOOLEAN get_rsb_item(SSHORT* explain_length_ptr, + SCHAR ** explain_ptr, + SSHORT* plan_length_ptr, + SCHAR** plan_ptr, + USHORT* parent_join_count, + USHORT* level_ptr) { /************************************** * @@ -2968,9 +3276,9 @@ static DBB init( SLONG ** db_handle) * Initialize dynamic SQL. This is called only once. * **************************************/ - DBB database; + STATUS user_status[ISC_STATUS_LENGTH]; - PLB pool; + DsqlMemoryPool *pool; SCHAR buffer[128], *data; UCHAR p; SSHORT l; @@ -3005,16 +3313,19 @@ static DBB init( SLONG ** db_handle) return NULL; } -/* Look for database block. If we don't find one, allocate one. */ + // Look for database block. If we don't find one, allocate one. + DBB database; for (database = databases; database; database = database->dbb_next) + { if (database->dbb_database_handle == *db_handle) { THD_MUTEX_UNLOCK(&databases_mutex); return database; } + } - pool = ALLD_pool(); - database = (DBB) ALLOC(type_dbb, pool); + pool = new(*DSQL_permanent_pool) DsqlMemoryPool; + database = new(*pool) dbb; database->dbb_pool = pool; database->dbb_next = databases; databases = database; @@ -3466,8 +3777,8 @@ static REQ prepare( /* allocate the send and receive messages */ - request->req_send = (MSG) ALLOCD(type_msg); - request->req_receive = message = (MSG) ALLOCD(type_msg); + request->req_send = new(*tdsql->tsql_default) msg; + request->req_receive = message = new(*tdsql->tsql_default) msg; message->msg_number = 1; #ifdef SCROLLABLE_CURSORS @@ -3475,7 +3786,7 @@ static REQ prepare( /* allocate a message in which to send scrolling information outside of the normal send/receive protocol */ - request->req_async = message = (MSG) ALLOCD(type_msg); + request->req_async = message = new(*tdsql->tsql_default) msg; message->msg_number = 2; } #endif @@ -3524,13 +3835,13 @@ static REQ prepare( request->req_type == REQ_EXEC_PROCEDURE) { /* Allocate persistent blr string from request's pool. */ - request->req_blr_string = (STR) ALLOCDV(type_str, 980); + request->req_blr_string = new(*tdsql->tsql_default, 980) str; } else { /* Allocate transient blr string from permanent pool so as not to unnecessarily bloat the request's pool. */ - request->req_blr_string = (STR) ALLOCPV(type_str, 980); + request->req_blr_string = new(*DSQL_permanent_pool, 980) str; } request->req_blr_string->str_length = 980; request->req_blr = request->req_blr_string->str_data; @@ -3607,7 +3918,7 @@ static REQ prepare( sizeof(STATUS) * len); } - ALLD_release(reinterpret_cast(request->req_blr_string)); + delete request->req_blr_string; request->req_blr_string = NULL; if (status) @@ -3633,14 +3944,15 @@ static void punt(void) tdsql = GET_THREAD_DATA; - LONGJMP(*tdsql->tsql_setjmp, (int) tdsql->tsql_status[1]); + Firebird::status_longjmp_error::raise(tdsql->tsql_status[1]); } -static SCHAR *put_item( - SCHAR item, - USHORT length, - SCHAR * string, SCHAR * ptr, SCHAR * end) +static SCHAR* put_item( SCHAR item, + USHORT length, + SCHAR* string, + SCHAR* ptr, + SCHAR* end) { /************************************** * @@ -3661,18 +3973,21 @@ static SCHAR *put_item( } *ptr++ = item; - STUFF_INFO_WORD(ptr, length); - if (length) - do + *ptr++ = (UCHAR)length; + *ptr++ = length >> 8; + + if (length) { + do { *ptr++ = *string++; - while (--length); + } while (--length); + } return ptr; } -static void release_request( REQ request, USHORT top_level) +static void release_request(REQ request, USHORT top_level) { /************************************** * @@ -3684,40 +3999,46 @@ static void release_request( REQ request, USHORT top_level) * Release a dynamic request. * **************************************/ - REQ *ptr, child, parent; + STATUS status_vector[ISC_STATUS_LENGTH]; - PLB save_default; - struct tsql *tdsql; - tdsql = GET_THREAD_DATA; + tsql* tdsql = GET_THREAD_DATA; -/* If request is parent, orphan the children and release a portion - of their requests */ + // If request is parent, orphan the children and + // release a portion of their requests - for (child = request->req_offspring; child; child = child->req_sibling) { + for (REQ child = request->req_offspring; child; child = child->req_sibling) { child->req_flags |= REQ_orphan; child->req_parent = NULL; - save_default = tdsql->tsql_default; + DsqlMemoryPool *save_default = tdsql->tsql_default; tdsql->tsql_default = child->req_pool; release_request(child, FALSE); tdsql->tsql_default = save_default; } -/* For top level requests that are linked to a parent, unlink it */ +// For top level requests that are linked to a parent, unlink it - if (top_level && (parent = request->req_parent) != NULL) - for (ptr = &parent->req_offspring; *ptr; ptr = &(*ptr)->req_sibling) + if (top_level && request->req_parent) + { + REQ parent = request->req_parent; + for (REQ* ptr = &parent->req_offspring; + *ptr; + ptr = &(*ptr)->req_sibling) + { if (*ptr == request) { *ptr = request->req_sibling; break; } + } + } -/* If the request had an open cursor, close it */ +// If the request had an open cursor, close it - if (request->req_open_cursor) + if (request->req_open_cursor) { close_cursor(request); + } -/* If request is named, clear it from the hash table */ +// If request is named, clear it from the hash table if (request->req_name) { HSHD_remove(request->req_name); @@ -3730,11 +4051,11 @@ static void release_request( REQ request, USHORT top_level) } if (request->req_blr_string) { - ALLD_release(reinterpret_cast(request->req_blr_string)); + delete request->req_blr_string; request->req_blr_string = NULL; } -/* If a request has been compiled, release it now */ +// If a request has been compiled, release it now if (request->req_handle) { THREAD_EXIT; @@ -3747,7 +4068,7 @@ static void release_request( REQ request, USHORT top_level) /* Only release the entire request for top level requests */ if (top_level) - ALLD_rlpool(request->req_pool); + delete request->req_pool; } @@ -3763,17 +4084,17 @@ static STATUS return_success(void) * Set up status vector to reflect successful execution. * **************************************/ - TSQL tdsql; - STATUS *p; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; - p = tdsql->tsql_status; + STATUS*p = tdsql->tsql_status; *p++ = gds_arg_gds; *p++ = SUCCESS; -/* do not overwrite warnings */ - if (*p != isc_arg_warning) + + // do not overwrite warnings + if (*p != isc_arg_warning) { *p = gds_arg_end; + } RESTORE_THREAD_DATA; diff --git a/src/dsql/dsql.h b/src/dsql/dsql.h index 5a90f7cb8f..1bec7bb2f3 100644 --- a/src/dsql/dsql.h +++ b/src/dsql/dsql.h @@ -27,144 +27,98 @@ #include "../jrd/ibsetjmp.h" #include "../jrd/common.h" +#include "../dsql/all.h" +#include -/* Dynamic SQL Error Status Block */ +// Dynamic SQL Error Status Block -typedef struct err { - STATUS *dsql_status; - STATUS *dsql_user_status; - JMP_BUF dsql_env; /* Error return environment */ -} *ERR; +struct err +{ + STATUS* dsql_status; + STATUS* dsql_user_status; + JMP_BUF dsql_env; // Error return environment +}; +typedef err* ERR; -/* macros for block allocation */ -#define ALL_release(blk) ALLD_release (blk) -#define ALLOCD(type) ALLD_alloc (tdsql->tsql_default, type, 0) -#define ALLOCDV(type,repeat) ALLD_alloc (tdsql->tsql_default, type, repeat) -#define ALLOCP(type) ALLD_alloc (DSQL_permanent_pool, type, 0) -#define ALLOCPV(type,repeat) ALLD_alloc (DSQL_permanent_pool, type, repeat) -#define ALLOC(type,pool) ALLD_alloc (pool, type, 0) -#define ALLOCV(type,pool,repeat) ALLD_alloc (pool, type, repeat) - -/* this table is used in data allocation to determine - whether a block has a variable length tail */ +// this table is used in data allocation to determine +// whether a block has a variable length tail #define BLKDEF(type, root, tail) type, ENUM blk_t { - type_MIN = 0, + dsql_type_MIN = 0, #include "../dsql/blk.h" -type_MAX}; +dsql_type_MAX}; #undef BLKDEF -/* generic block used as header to all allocated structures */ +// generic block used as header to all allocated structures #ifndef INCLUDE_FB_BLK #include "../include/fb_blk.h" #endif -/* aggregate blocks to store vectors of objects */ +// generic data type used to store strings -typedef struct vec { - struct blk vec_header; - ULONG vec_count; - struct blk *vec_object[1]; -} *VEC; - -typedef struct vcl { - struct blk vcl_header; - ULONG vcl_count; - SLONG vcl_long[1]; -} *VCL; - -/* generic structure used to store strings */ - -typedef struct str +class str : public pool_alloc_rpt { - struct blk str_header; - TEXT* str_charset; /* ASCIIZ Character set identifier for string */ +public: + TEXT* str_charset; // ASCIIZ Character set identifier for string USHORT str_flags; - USHORT str_length; /* length of string in BYTES */ - UCHAR str_data[2]; /* one for ALLOC and one for the NULL */ -} *STR; + USHORT str_length; // length of string in BYTES + UCHAR str_data[2]; // one for ALLOC and one for the NULL +}; +typedef str* STR; -/* values used in str_flags */ +// values used in str_flags #define STR_delimited_id 0x1L -/* macros and block used to implement a generic stack mechanism */ +// macros and block used to implement a generic stack mechanism -#define LLS_PUSH(object,stack) ALLD_push ((BLK) object, stack) -#define LLS_POP(stack) ALLD_pop (stack) +class dsql_lls : public pool_alloc +{ +public: + blk* lls_object; + dsql_lls* lls_next; +}; +typedef dsql_lls* DLLS; -typedef struct lls { - struct blk lls_header; - struct blk *lls_object; - struct lls *lls_next; -} *LLS; - - -/* blocks used internally to the data allocator */ - -/* free block used to point to an unused block */ - -typedef struct frb { - struct blk frb_header; - struct frb *frb_next; /* Next free block in pool */ -} *FRB; - -/* Pool block used to store a set of blocks to be treated as an aggregate */ - -typedef struct plb { - struct blk plb_header; - USHORT plb_pool_id; /* pool id */ - struct frb *plb_free; /* first free block */ - struct hnk *plb_hunks; /* first hunk block */ - struct lls *plb_lls; /* available linked list stack nodes */ - SLONG *plb_blk_type_count; /* array to keep track of block types */ -} *PLB; - -/* Hunk blocks, used to allow dynamic expansion of an allocated pool */ - -typedef struct hnk { - struct blk hnk_header; - UCHAR *hnk_address; /* start of memory hunk */ - int hnk_length; /* length of memory hunk */ - struct hnk *hnk_next; /* next memory hunk in structure */ -} *HNK; +#define LLS_PUSH(object,stack) DsqlMemoryPool::ALLD_push ((BLK) object, stack) +#define LLS_POP(stack) DsqlMemoryPool::ALLD_pop (stack) -/*====================================================================== - remaining node definitions for local processing -*/ +//====================================================================== +// remaining node definitions for local processing +// -/* Include definition of descriptor */ +/// Include definition of descriptor #include "../jrd/dsc.h" -/* internal DSQL requests */ +// internal DSQL requests #if 0 -#define irq_relation 0 /* lookup a relation */ -#define irq_fields 1 /* lookup a relation's fields */ -#define irq_dimensions 2 /* lookup a field's dimensions */ -#define irq_primary_key 3 /* lookup a primary key */ -#define irq_view 4 /* lookup a view's base relations */ -#define irq_function 5 /* lookup a user defined function */ -#define irq_func_return 6 /* lookup a function's return argument */ -#define irq_procedure 7 /* lookup a stored procedure */ -#define irq_parameters 8 /* lookup a procedure's parameters */ -#define irq_collation 9 /* lookup a collation name */ -#define irq_charset 10 /* lookup a character set name */ -#define irq_trigger 11 /* lookup a trigger */ -#define irq_domain 12 /* lookup a domain */ -#define irq_type 13 /* lookup a symbolic name in RDB$TYPES */ -#define irq_col_default 14 /* lookup default for a column */ -#define irq_domain_2 15 /* lookup a domain */ +#define irq_relation 0 // lookup a relation +#define irq_fields 1 // lookup a relation's fields +#define irq_dimensions 2 // lookup a field's dimensions +#define irq_primary_key 3 // lookup a primary key +#define irq_view 4 // lookup a view's base relations +#define irq_function 5 // lookup a user defined function +#define irq_func_return 6 // lookup a function's return argument +#define irq_procedure 7 // lookup a stored procedure +#define irq_parameters 8 // lookup a procedure's parameters +#define irq_collation 9 // lookup a collation name +#define irq_charset 10 // lookup a character set name +#define irq_trigger 11 // lookup a trigger +#define irq_domain 12 // lookup a domain +#define irq_type 13 // lookup a symbolic name in RDB$TYPES +#define irq_col_default 14 // lookup default for a column +#define irq_domain_2 15 // lookup a domain #define irq_MAX 16 @@ -194,249 +148,299 @@ enum irq_type_t { #endif -/* blocks used to cache metadata */ +// blocks used to cache metadata -typedef struct dbb { /* Database Block */ - struct blk dbb_header; - struct dbb *dbb_next; - struct dsql_rel *dbb_relations; /* known relations in database */ - struct prc *dbb_procedures; /* known procedures in database */ - struct udf *dbb_functions; /* known functions in database */ - struct plb *dbb_pool; - SLONG *dbb_database_handle; - SLONG *dbb_requests[irq_MAX]; - struct str *dbb_dfl_charset; - USHORT dbb_base_level; /* indicates the version of the engine code itself */ - USHORT dbb_flags; - USHORT dbb_db_SQL_dialect; - SSHORT dbb_att_charset; /* characterset at time of attachment */ -} *DBB; +// Database Block +class dbb : public pool_alloc +{ +public: + dbb* dbb_next; + class dsql_rel* dbb_relations; // known relations in database + class prc* dbb_procedures; // known procedures in database + class udf* dbb_functions; // known functions in database + DsqlMemoryPool* dbb_pool; // The current pool for the dbb + SLONG* dbb_database_handle; + SLONG* dbb_requests[irq_MAX]; + str* dbb_dfl_charset; + USHORT dbb_base_level; // indicates the version of the engine code itself + USHORT dbb_flags; + USHORT dbb_db_SQL_dialect; + SSHORT dbb_att_charset; // characterset at time of attachment +}; +typedef dbb* DBB; -/* values used in dbb_flags */ +// values used in dbb_flags #define DBB_no_arrays 0x1 -#define DBB_v3 0x2 +#define DBB_v3 0x2 #define DBB_no_charset 0x4 #define DBB_read_only 0x8 -typedef struct dsql_rel /* Relation block */ +// Relation block + +class dsql_rel : public pool_alloc_rpt { - struct blk rel_header; - struct dsql_rel* rel_next; /* Next relation in database */ - struct sym* rel_symbol; /* Hash symbol for relation */ - struct fld* rel_fields; /* Field block */ - struct dsql_rel* rel_base_relation; /* base relation for an updatable view */ - TEXT* rel_name; /* Name of relation */ - TEXT* rel_owner; /* Owner of relation */ - USHORT rel_id; /* Relation id */ - USHORT rel_dbkey_length; - USHORT rel_flags; - TEXT rel_data[3]; -} *DSQL_REL; +public: + dsql_rel* rel_next; // Next relation in database + struct sym* rel_symbol; // Hash symbol for relation + class fld* rel_fields; // Field block + dsql_rel* rel_base_relation; // base relation for an updatable view + TEXT* rel_name; // Name of relation + TEXT* rel_owner; // Owner of relation + USHORT rel_id; // Relation id + USHORT rel_dbkey_length; + USHORT rel_flags; + TEXT rel_data[3]; +}; +typedef dsql_rel* DSQL_REL; -/* rel_flags bits */ +// rel_flags bits -#define REL_new_relation 1 /* relation is newly defined, not committed yet */ -#define REL_dropped 2 /* relation has been dropped */ +#define REL_new_relation 1 // relation is newly defined, not committed yet +#define REL_dropped 2 // relation has been dropped -typedef struct fld /* Field block */ +class fld : public pool_alloc_rpt { - struct blk fld_header; - struct fld* fld_next; /* Next field in relation */ - struct dsql_rel* fld_relation; /* Parent relation */ - struct prc* fld_procedure; /* Parent procedure */ - struct nod* fld_ranges; /* ranges for multi dimension array */ - struct nod* fld_character_set; /* null means not specified */ - struct nod* fld_sub_type_name; /* Subtype name for later resolution */ - USHORT fld_flags; - USHORT fld_id; /* Field in in database */ - USHORT fld_dtype; /* Data type of field */ - FLD_LENGTH fld_length; /* Length of field */ - USHORT fld_element_dtype; /* Data type of array element */ - USHORT fld_element_length; /* Length of array element */ - SSHORT fld_scale; /* Scale factor of field */ - SSHORT fld_sub_type; /* Subtype for text & blob fields */ - USHORT fld_precision; /* Precision for exact numeric types */ - USHORT fld_character_length; /* length of field in characters */ - USHORT fld_seg_length; /* Segment length for blobs */ - SSHORT fld_dimensions; /* Non-zero means array */ - SSHORT fld_character_set_id; /* ID of field's character set */ - SSHORT fld_collation_id; /* ID of field's collation */ - SSHORT fld_ttype; /* ID of field's language_driver */ - TEXT fld_name[2]; -} *FLD; +public: + fld* fld_next; // Next field in relation + dsql_rel* fld_relation; // Parent relation + class prc* fld_procedure; // Parent procedure + struct nod* fld_ranges; // ranges for multi dimension array + struct nod* fld_character_set; // null means not specified + struct nod* fld_sub_type_name; // Subtype name for later resolution + USHORT fld_flags; + USHORT fld_id; // Field in in database + USHORT fld_dtype; // Data type of field + FLD_LENGTH fld_length; // Length of field + USHORT fld_element_dtype; // Data type of array element + USHORT fld_element_length; // Length of array element + SSHORT fld_scale; // Scale factor of field + SSHORT fld_sub_type; // Subtype for text & blob fields + USHORT fld_precision; // Precision for exact numeric types + USHORT fld_character_length; // length of field in characters + USHORT fld_seg_length; // Segment length for blobs + SSHORT fld_dimensions; // Non-zero means array + SSHORT fld_character_set_id; // ID of field's character set + SSHORT fld_collation_id; // ID of field's collation + SSHORT fld_ttype; // ID of field's language_driver + TEXT fld_name[2]; +}; +typedef fld* FLD; -/* values used in fld_flags */ +// values used in fld_flags #define FLD_computed 1 #define FLD_drop 2 #define FLD_dbkey 4 -#define FLD_national 8 /* field uses NATIONAL character set */ +#define FLD_national 8 // field uses NATIONAL character set #define FLD_nullable 16 -#define MAX_ARRAY_DIMENSIONS 16 /* max array dimensions */ +#define MAX_ARRAY_DIMENSIONS 16 // max array dimensions -/* database/log/cache file block */ +// database/log/cache file block -typedef struct fil { - struct blk fil_header; - SLONG fil_length; /* File length in pages */ - SLONG fil_start; /* Starting page */ - struct str *fil_name; /* File name */ - struct fil *fil_next; /* next file */ - SSHORT fil_shadow_number; /* shadow number if part of shadow */ - SSHORT fil_manual; /* flag to indicate manual shadow */ - SSHORT fil_partitions; /* number of log file partitions */ - USHORT fil_flags; -} *FIL; +class fil : public pool_alloc +{ +public: + SLONG fil_length; // File length in pages + SLONG fil_start; // Starting page + str* fil_name; // File name + fil* fil_next; // next file + SSHORT fil_shadow_number; // shadow number if part of shadow + SSHORT fil_manual; // flag to indicate manual shadow + SSHORT fil_partitions; // number of log file partitions + USHORT fil_flags; +}; +typedef fil* FIL; -/* Stored Procedure block */ +// Stored Procedure block -typedef struct prc { /* Relation block */ - struct blk prc_header; - struct prc *prc_next; /* Next relation in database */ - struct sym *prc_symbol; /* Hash symbol for procedure */ - struct fld *prc_inputs; /* Input parameters */ - struct fld *prc_outputs; /* Output parameters */ - TEXT *prc_name; /* Name of procedure */ - TEXT *prc_owner; /* Owner of procedure */ - SSHORT prc_in_count; - SSHORT prc_out_count; - USHORT prc_id; /* Procedure id */ - USHORT prc_flags; - TEXT prc_data[3]; -} *PRC; +// Relation block +class prc : public pool_alloc_rpt +{ +public: + prc* prc_next; // Next relation in database + struct sym* prc_symbol; // Hash symbol for procedure + fld* prc_inputs; // Input parameters + fld* prc_outputs; // Output parameters + TEXT* prc_name; // Name of procedure + TEXT* prc_owner; // Owner of procedure + SSHORT prc_in_count; + SSHORT prc_out_count; + USHORT prc_id; // Procedure id + USHORT prc_flags; + TEXT prc_data[3]; +}; +typedef prc* PRC; -/* prc_flags bits */ +// prc_flags bits -#define PRC_new_procedure 1 /* procedure is newly defined, not committed yet */ -#define PRC_dropped 2 /* procedure has been dropped */ +#define PRC_new_procedure 1 // procedure is newly defined, not committed yet +#define PRC_dropped 2 // procedure has been dropped -/* User defined function block */ +// User defined function block -typedef struct udf { - struct blk udf_header; - struct udf *udf_next; - struct sym *udf_symbol; /* Hash symbol for udf */ - USHORT udf_dtype; - SSHORT udf_scale; - SSHORT udf_sub_type; - USHORT udf_length; - SSHORT udf_character_set_id; - USHORT udf_character_length; - TEXT udf_name[2]; -} *UDF; +class udf : public pool_alloc_rpt +{ +public: + udf* udf_next; + struct sym* udf_symbol; // Hash symbol for udf + USHORT udf_dtype; + SSHORT udf_scale; + SSHORT udf_sub_type; + USHORT udf_length; + SSHORT udf_character_set_id; + USHORT udf_character_length; + TEXT udf_name[2]; +}; +typedef udf* UDF; -/* these values are multiplied by -1 to indicate that server frees them - on return from the udf */ -typedef ENUM { - FUN_value, - FUN_reference, - FUN_descriptor, FUN_blob_struct, FUN_scalar_array} FUN_T; +// these values are multiplied by -1 to indicate that server frees them +// on return from the udf +enum FUN_T +{ + FUN_value, + FUN_reference, + FUN_descriptor, + FUN_blob_struct, + FUN_scalar_array +}; -/* Variables - input, output & local */ +// Variables - input, output & local -typedef struct var { /* Variable block */ - struct blk var_header; - struct fld *var_field; /* Field on which variable is based */ - USHORT var_flags; - USHORT var_msg_number; /* Message number containing variable */ - USHORT var_msg_item; /* Item number in message */ - USHORT var_variable_number; /* Local variable number */ - TEXT var_name[2]; -} *VAR; +// Variable block +class var : public pool_alloc_rpt +{ +public: + fld* var_field; // Field on which variable is based + USHORT var_flags; + USHORT var_msg_number; // Message number containing variable + USHORT var_msg_item; // Item number in message + USHORT var_variable_number; // Local variable number + TEXT var_name[2]; +}; +typedef var* VAR; -/* values used in var_flags */ +// values used in var_flags #define VAR_input 1 #define VAR_output 2 #define VAR_local 4 -/* Symbolic names for international text types */ -/* (either collation or character set name) */ +// Symbolic names for international text types +// (either collation or character set name) -typedef struct intlsym { /* International symbol */ - struct blk intlsym_header; - struct sym *intlsym_symbol; /* Hash symbol for intlsym */ - USHORT intlsym_type; /* what type of name */ - USHORT intlsym_flags; - SSHORT intlsym_ttype; /* id of implementation */ - SSHORT intlsym_charset_id; - SSHORT intlsym_collate_id; - USHORT intlsym_bytes_per_char; - TEXT intlsym_name[2]; -} *INTLSYM; +// International symbol +class intlsym : public pool_alloc_rpt +{ +public: + struct sym* intlsym_symbol; // Hash symbol for intlsym + USHORT intlsym_type; // what type of name + USHORT intlsym_flags; + SSHORT intlsym_ttype; // id of implementation + SSHORT intlsym_charset_id; + SSHORT intlsym_collate_id; + USHORT intlsym_bytes_per_char; + TEXT intlsym_name[2]; +}; +typedef intlsym* INTLSYM; -/* values used in intlsym_type */ +// values used in intlsym_type #define INTLSYM_collation 1 #define INTLSYM_charset 2 -/* values used in intlsym_flags */ +// values used in intlsym_flags -/* Request information */ +// Request information -typedef enum { +enum REQ_TYPE +{ REQ_SELECT, REQ_SELECT_UPD, REQ_INSERT, REQ_DELETE, REQ_UPDATE, REQ_UPDATE_CURSOR, REQ_DELETE_CURSOR, REQ_COMMIT, REQ_ROLLBACK, REQ_DDL, REQ_EMBED_SELECT, REQ_START_TRANS, REQ_GET_SEGMENT, REQ_PUT_SEGMENT, REQ_EXEC_PROCEDURE, REQ_COMMIT_RETAIN, REQ_SET_GENERATOR -} REQ_TYPE; +}; -typedef struct req { - struct blk req_header; - struct req *req_parent; /* Source request, if cursor update */ - struct req *req_sibling; /* Next sibling request, if cursor update */ - struct req *req_offspring; /* Cursor update requests */ - struct plb *req_pool; - struct lls *req_context; - struct sym *req_name; /* Name of request */ - struct sym *req_cursor; /* Cursor symbol. if any */ - struct dbb *req_dbb; /* Database handle */ - int *req_trans; /* Database transaction handle */ - struct opn *req_open_cursor; - struct nod *req_ddl_node; /* Store metadata request */ - struct blb *req_blob; /* Blob info for blob requests */ - int *req_handle; /* OSRI request handle */ - struct str *req_blr_string; /* String block during BLR generation */ - struct msg *req_send; /* Message to be sent to start request */ - struct msg *req_receive; /* Per record message to be received */ - struct msg *req_async; /* Message for sending scrolling information */ - struct par *req_eof; /* End of file parameter */ - struct par *req_dbkey; /* Database key for current of */ - struct par *req_rec_version; /* Record Version for current of */ - struct par *req_parent_rec_version; /* parent record version */ - struct par *req_parent_dbkey; /* Parent database key for current of */ - struct dsql_rel *req_relation; /* relation created by this request (for DDL) */ - struct prc *req_procedure; /* procedure created by this request (for DDL) */ - struct ctx *req_outer_agg_context; /* agg context for outer ref */ - BLOB_PTR *req_blr; /* Running blr address */ - BLOB_PTR *req_blr_yellow; /* Threshold for upping blr buffer size */ - ULONG req_inserts; /* records processed in request */ - ULONG req_deletes; - ULONG req_updates; - ULONG req_selects; - REQ_TYPE req_type; /* Type of request */ - USHORT req_base_offset; /* place to go back and stuff in blr length */ - USHORT req_context_number; /* Next available context number */ - USHORT req_scope_level; /* Scope level for parsing aliases in subqueries */ - USHORT req_message_number; /* Next available message number */ - USHORT req_loop_number; /* Next available loop number */ - SSHORT req_inhibit_map; /* Map inhibit count */ - USHORT req_in_select_list; /* now processing "select list" */ - USHORT req_in_where_clause; /* processing "where clause" */ - USHORT req_in_having_clause; /* processing "having clause" */ - USHORT req_in_order_by_clause; /* processing "order by clause" */ - USHORT req_error_handlers; /* count of active error handlers */ - USHORT req_flags; /* generic flag */ - USHORT req_client_dialect; /* dialect passed into the API call */ -} *REQ; -/* values used in req_flags */ +class req : public pool_alloc +{ +public: + // begin - member functions that should be private + inline void append_uchar(UCHAR byte); + inline void append_ushort(USHORT val); + inline void append_ulong(ULONG val); + void append_cstring(UCHAR verb, char* string); + void append_string(UCHAR verb, char* string, USHORT len); + void append_number(UCHAR verb, SSHORT number); + void begin_blr(UCHAR verb); + void end_blr(); + void append_uchars(UCHAR byte, UCHAR count); + void append_ushort_with_length(USHORT val); + void append_ulong_with_length(ULONG val); + void append_file_length(ULONG length); + void append_file_start(ULONG start); + void generate_unnamed_trigger_beginning( bool on_update_trigger, + TEXT* prim_rel_name, + struct nod* prim_columns, + TEXT* for_rel_name, + struct nod* for_columns); + // end - member functions that should be private + + req* req_parent; // Source request, if cursor update + req* req_sibling; // Next sibling request, if cursor update + req* req_offspring; // Cursor update requests + DsqlMemoryPool* req_pool; + DLLS req_context; + struct sym* req_name; // Name of request + struct sym* req_cursor; // Cursor symbol. if any + dbb* req_dbb; // Database handle + int* req_trans; // Database transaction handle + class opn* req_open_cursor; + struct nod* req_ddl_node; // Store metadata request + class blb* req_blob; // Blob info for blob requests + int* req_handle; // OSRI request handle + str* req_blr_string; // String block during BLR generation + class msg* req_send; // Message to be sent to start request + class msg* req_receive; // Per record message to be received + class msg* req_async; // Message for sending scrolling information + class par* req_eof; // End of file parameter + class par* req_dbkey; // Database key for current of + class par* req_rec_version; // Record Version for current of + class par* req_parent_rec_version; // parent record version + class par* req_parent_dbkey; // Parent database key for current of + dsql_rel* req_relation; // relation created by this request (for DDL) + prc* req_procedure; // procedure created by this request (for DDL) + class ctx* req_outer_agg_context; // agg context for outer ref + BLOB_PTR* req_blr; // Running blr address + BLOB_PTR* req_blr_yellow; // Threshold for upping blr buffer size + ULONG req_inserts; // records processed in request + ULONG req_deletes; + ULONG req_updates; + ULONG req_selects; + REQ_TYPE req_type; // Type of request + USHORT req_base_offset; // place to go back and stuff in blr length + USHORT req_context_number; // Next available context number + USHORT req_scope_level; // Scope level for parsing aliases in subqueries + USHORT req_message_number; // Next available message number + USHORT req_loop_number; // Next available loop number + SSHORT req_inhibit_map; // Map inhibit count + USHORT req_in_select_list; // now processing "select list" + USHORT req_in_where_clause; // processing "where clause" + USHORT req_in_having_clause; // processing "having clause" + USHORT req_in_order_by_clause; // processing "order by clause" + USHORT req_error_handlers; // count of active error handlers + USHORT req_flags; // generic flag + USHORT req_client_dialect; // dialect passed into the API call +}; +typedef req* REQ; + + +// values used in req_flags #define REQ_cursor_open 1 #define REQ_save_metadata 2 @@ -451,117 +455,135 @@ typedef struct req { #define REQ_blr_version4 1024 #define REQ_blr_version5 2048 -/* Blob */ +// Blob -typedef struct blb { - struct blk blb_header; - struct nod *blb_field; /* Related blob field */ - struct par *blb_blob_id; /* Parameter to hold blob id */ - struct par *blb_segment; /* Parameter for segments */ - struct nod *blb_from; - struct nod *blb_to; - struct msg *blb_open_in_msg; /* Input message to open cursor */ - struct msg *blb_open_out_msg; /* Output message from open cursor */ - struct msg *blb_segment_msg; /* Segment message */ -} *BLB; +class blb : public pool_alloc +{ +public: + struct nod* blb_field; // Related blob field + class par* blb_blob_id; // Parameter to hold blob id + class par* blb_segment; // Parameter for segments + struct nod* blb_from; + struct nod* blb_to; + class msg* blb_open_in_msg; // Input message to open cursor + class msg* blb_open_out_msg; // Output message from open cursor + class msg* blb_segment_msg; // Segment message +}; +typedef blb* BLB; -/* List of open cursors */ +// List of open cursors -typedef struct opn { - struct blk opn_header; - struct opn *opn_next; /* Next open cursor */ - struct req *opn_request; /* Request owning the cursor */ - SLONG *opn_transaction; /* Transaction executing request */ -} *OPN; +class opn : public pool_alloc +{ +public: + opn* opn_next; // Next open cursor + req* opn_request; // Request owning the cursor + SLONG* opn_transaction; // Transaction executing request +}; +typedef opn* OPN; -/* Transaction block */ +// Transaction block -typedef struct tra { - struct blk tra_header; - struct tra *tra_next; /* Next open transaction */ -} *TRA; +class tra : public pool_alloc +{ +public: + tra* tra_next; // Next open transaction +}; +typedef tra* TRA; -/* Context block used to create an instance of a relation reference */ +// Context block used to create an instance of a relation reference -typedef struct ctx { - struct blk ctx_header; - struct req *ctx_request; /* Parent request */ - struct dsql_rel *ctx_relation; /* Relation for context */ - struct prc *ctx_procedure; /* Procedure for context */ - struct nod *ctx_proc_inputs; /* Procedure input parameters */ - struct map *ctx_map; /* Map for aggregates */ - struct nod *ctx_rse; /* Sub-rse for aggregates */ - struct ctx *ctx_parent; /* Parent context for aggregates */ - TEXT *ctx_alias; /* Context alias */ - USHORT ctx_context; /* Context id */ - USHORT ctx_scope_level; /* Subquery level within this request */ - USHORT ctx_flags; /* Various flag values */ -} *CTX; +class ctx : public pool_alloc +{ +public: + req* ctx_request; // Parent request + dsql_rel* ctx_relation; // Relation for context + prc* ctx_procedure; // Procedure for context + struct nod* ctx_proc_inputs; // Procedure input parameters + class map* ctx_map; // Map for aggregates + struct nod* ctx_rse; // Sub-rse for aggregates + ctx* ctx_parent; // Parent context for aggregates + TEXT* ctx_alias; // Context alias + USHORT ctx_context; // Context id + USHORT ctx_scope_level; // Subquery level within this request + USHORT ctx_flags; // Various flag values +}; +typedef ctx* CTX; -/* Flag values for ctx_flags */ +// Flag values for ctx_flags -#define CTX_outer_join (1<<0) /* reference is part of an outer join */ +#define CTX_outer_join (1<<0) // reference is part of an outer join -/* Aggregate/union map block to map virtual fields to their base */ +// Aggregate/union map block to map virtual fields to their base -typedef struct map { - struct blk map_header; - struct map *map_next; /* Next map in item */ - struct nod *map_node; /* Value for map item */ - USHORT map_position; /* Position in map */ -} *MAP; +// TMN: NOTE! This datatype should definitely be renamed! +class map : public pool_alloc +{ +public: + map* map_next; // Next map in item + struct nod* map_node; // Value for map item + USHORT map_position; // Position in map +}; +typedef map* MAP; -/* Message block used in communicating with a running request */ +// Message block used in communicating with a running request #ifndef GUI_TOOLS -typedef struct msg { - struct blk msg_header; - struct par *msg_parameters; /* Parameter list */ - struct par *msg_par_ordered; /* Ordered parameter list */ - UCHAR *msg_buffer; /* Message buffer */ - USHORT msg_number; /* Message number */ - USHORT msg_length; /* Message length */ - USHORT msg_parameter; /* Next parameter number */ - USHORT msg_index; /* Next index into SQLDA */ -} *MSG; + +class msg : public pool_alloc +{ +public: + class par* msg_parameters; // Parameter list + class par* msg_par_ordered; // Ordered parameter list + UCHAR* msg_buffer; // Message buffer + USHORT msg_number; // Message number + USHORT msg_length; // Message length + USHORT msg_parameter; // Next parameter number + USHORT msg_index; // Next index into SQLDA +}; +typedef msg* MSG; #endif -/* Parameter block used to describe a parameter of a message */ +// Parameter block used to describe a parameter of a message -typedef struct par { - struct blk par_header; - struct msg *par_message; /* Parent message */ - struct par *par_next; /* Next parameter in linked list */ - struct par *par_ordered; /* Next parameter in order of index */ - struct par *par_null; /* Null parameter, if used */ - struct nod *par_node; /* Associated value node, if any */ - struct ctx *par_dbkey_ctx; /* Context of internally requested dbkey */ - struct ctx *par_rec_version_ctx; /* Context of internally requested record version */ - TEXT *par_name; /* Parameter name, if any */ - TEXT *par_rel_name; /* Relation name, if any */ - TEXT *par_owner_name; /* Owner name, if any */ - TEXT *par_alias; /* Alias, if any */ - DSC par_desc; /* Field data type */ - DSC par_user_desc; /* SQLDA data type */ - USHORT par_parameter; /* BLR parameter number */ - USHORT par_index; /* Index into SQLDA, if appropriate */ -} *PAR; +class par : public pool_alloc +{ +public: + msg* par_message; // Parent message + class par* par_next; // Next parameter in linked list + class par* par_ordered; // Next parameter in order of index + class par* par_null; // Null parameter, if used + struct nod* par_node; // Associated value node, if any + ctx* par_dbkey_ctx; // Context of internally requested dbkey + ctx* par_rec_version_ctx; // Context of internally requested record version + TEXT* par_name; // Parameter name, if any + TEXT* par_rel_name; // Relation name, if any + TEXT* par_owner_name; // Owner name, if any + TEXT* par_alias; // Alias, if any + DSC par_desc; // Field data type + DSC par_user_desc; // SQLDA data type + USHORT par_parameter; // BLR parameter number + USHORT par_index; // Index into SQLDA, if appropriate +}; +typedef par* PAR; #include "../jrd/thd.h" -/* DSQL threading declarations */ +// DSQL threading declarations -typedef struct tsql +struct tsql { - struct thdd tsql_thd_data; - struct plb* tsql_default; + thdd tsql_thd_data; + DsqlMemoryPool* tsql_default; STATUS* tsql_status; STATUS* tsql_user_status; jmp_buf* tsql_setjmp; -} *TSQL; +}; +typedef tsql* TSQL; + #ifdef GET_THREAD_DATA #undef GET_THREAD_DATA @@ -572,56 +594,64 @@ typedef struct tsql #ifndef SHLIB_DEFS #ifdef DSQL_MAIN -PLB DSQL_permanent_pool; int DSQL_debug; #else -extern PLB DSQL_permanent_pool; extern int DSQL_debug; #endif #else -extern PLB DSQL_permanent_pool; extern int DSQL_debug; #endif -/* macros for error generation */ +// macros for error generation #define BUGCHECK(string) ERRD_bugcheck(string) #define IBERROR(code, string) ERRD_error(code, string) -#define BLKCHK(blk, type) if (blk->blk_type != (SCHAR) type) BUGCHECK ("expected type") +//#define BLKCHK(blk, type) if (blk->blk_type != (SCHAR) type) BUGCHECK ("expected type") +#define BLKCHK(blk, type) if (MemoryPool::blk_type(blk) != (SSHORT) type) BUGCHECK ("expected type") -/* macro to stuff blr */ -/* this is used in both ddl.cpp and gen.cpp, and is put here for commonality */ +// macro to stuff blr +// this is used in both ddl.cpp and gen.cpp, and is put here for commonality #define STUFF(byte) ((BLOB_PTR*)request->req_blr < (BLOB_PTR*)request->req_blr_yellow) ?\ (*request->req_blr++ = (UCHAR)(byte)) : GEN_expand_buffer (request, (UCHAR)(byte)) -/* Macros for DEV_BUILD internal consistancy checking */ +// Macros for DEV_BUILD internal consistancy checking #ifdef DEV_BUILD /* Verifies that a pointed to block matches the expected type. - * Useful to find coding errors & memory globbers. - */ + Useful to find coding errors & memory globbers. + #define DEV_BLKCHK(blk, typ) \ { \ if ((blk) && (((BLK) (blk))->blk_type != (typ))) \ ERRD_assert_msg (assert_blkchk_msg, assert_filename, (ULONG) __LINE__); \ } +*/ -#define _assert(ex) {if (!(ex)){(void) ERRD_assert_msg (NULL, assert_filename, __LINE__);}} +#define DEV_BLKCHK(blk, typ) { \ + if ((blk) && MemoryPool::blk_type(blk) != (SSHORT)typ) { \ + ERRD_assert_msg((char*)assert_blkchk_msg, \ + (char*)assert_filename, \ + (ULONG) __LINE__); \ + } \ + } + + +#define _assert(ex) {if (!(ex)){(void) ERRD_assert_msg (NULL, (char*)assert_filename, __LINE__);}} #define assert(ex) _assert(ex) -#define ASSERT_FAIL ERRD_assert_msg (NULL, assert_filename, __LINE__) +#define ASSERT_FAIL ERRD_assert_msg (NULL, (char*)assert_filename, __LINE__) -/* Define the assert_filename as a static variable to save on codespace */ +// Define the assert_filename as a static variable to save on codespace #define ASSERT_FILENAME \ static UCHAR assert_filename[] = __FILE__; \ - static UCHAR assert_blkchk_msg[] = "Unexpected memory block type"; /* NTX: dev */ + static UCHAR assert_blkchk_msg[] = "Unexpected memory block type"; // NTX: dev -#else /* PROD_BUILD */ +#else // PROD_BUILD #define DEV_BLKCHK(blk, typ) #define _assert(ex) @@ -629,6 +659,6 @@ extern int DSQL_debug; #define ASSERT_FAIL #define ASSERT_FILENAME -#endif /* DEV_BUILD */ +#endif // DEV_BUILD -#endif /* _DSQL_DSQL_H_ */ +#endif // _DSQL_DSQL_H_ diff --git a/src/dsql/dsql_proto.h b/src/dsql/dsql_proto.h index 04def92b89..51ead512dd 100644 --- a/src/dsql/dsql_proto.h +++ b/src/dsql/dsql_proto.h @@ -30,8 +30,8 @@ extern "C" { extern STATUS DLL_EXPORT dsql8_allocate_statement( STATUS*, int**, - struct req**); -extern STATUS DLL_EXPORT dsql8_execute(STATUS *, void **, struct req**, + struct dsql_req**); +extern STATUS DLL_EXPORT dsql8_execute(STATUS *, void **, struct dsql_req**, USHORT, UCHAR *, USHORT, USHORT, UCHAR *, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); @@ -42,22 +42,22 @@ extern STATUS DLL_EXPORT dsql8_execute_immediate(STATUS *, int **, int **, UCHAR *, USHORT, USHORT, UCHAR *); #ifdef SCROLLABLE_CURSORS -extern STATUS DLL_EXPORT dsql8_fetch(STATUS *, struct req **, USHORT, UCHAR *, +extern STATUS DLL_EXPORT dsql8_fetch(STATUS *, struct dsql_req**, USHORT, UCHAR *, USHORT, USHORT, UCHAR *, USHORT, SLONG); #else -extern STATUS DLL_EXPORT dsql8_fetch(STATUS *, struct req **, USHORT, UCHAR *, +extern STATUS DLL_EXPORT dsql8_fetch(STATUS *, struct dsql_req**, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); #endif /* SCROLLABLE_CURSORS */ -extern STATUS DLL_EXPORT dsql8_free_statement(STATUS *, struct req **, +extern STATUS DLL_EXPORT dsql8_free_statement(STATUS *, struct dsql_req**, USHORT); -extern STATUS DLL_EXPORT dsql8_insert(STATUS *, struct req **, USHORT, +extern STATUS DLL_EXPORT dsql8_insert(STATUS *, struct dsql_req**, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); -extern STATUS DLL_EXPORT dsql8_prepare(STATUS *, void **, struct req **, +extern STATUS DLL_EXPORT dsql8_prepare(STATUS *, void **, struct dsql_req**, USHORT, TEXT *, USHORT, USHORT, UCHAR *, USHORT, UCHAR *); -extern STATUS DLL_EXPORT dsql8_set_cursor(STATUS *, struct req **, TEXT *, +extern STATUS DLL_EXPORT dsql8_set_cursor(STATUS *, struct dsql_req**, TEXT *, USHORT); -extern STATUS DLL_EXPORT dsql8_sql_info(STATUS *, struct req **, USHORT, +extern STATUS DLL_EXPORT dsql8_sql_info(STATUS *, struct dsql_req**, USHORT, SCHAR *, USHORT, SCHAR *); extern void DSQL_pretty(struct nod *, int); diff --git a/src/dsql/errd.cpp b/src/dsql/errd.cpp index 2bb251b8d3..6bc742f457 100644 --- a/src/dsql/errd.cpp +++ b/src/dsql/errd.cpp @@ -44,7 +44,7 @@ extern "C" { ASSERT_FILENAME /* Define things assert() needs */ #ifdef DEV_BUILD -void ERRD_assert_msg( CONST UCHAR * msg, CONST UCHAR * file, ULONG lineno) +void ERRD_assert_msg(const char* msg, const char* file, ULONG lineno) { /************************************** * @@ -60,13 +60,13 @@ void ERRD_assert_msg( CONST UCHAR * msg, CONST UCHAR * file, ULONG lineno) char buffer[100]; sprintf(buffer, "Assertion failure: %s File: %s Line: %ld\n", /* NTX: dev build */ - (msg ? msg : (UCHAR *) ""), (file ? file : (UCHAR *) ""), lineno); + (msg ? msg : ""), (file ? file : ""), lineno); ERRD_bugcheck(buffer); } #endif /* DEV_BUILD */ -void ERRD_bugcheck( CONST TEXT * text) +void ERRD_bugcheck(const char* text) { /************************************** * @@ -85,7 +85,7 @@ void ERRD_bugcheck( CONST TEXT * text) } -void ERRD_error( int code, CONST TEXT * text) +void ERRD_error( int code, const char* text) { /************************************** * @@ -110,7 +110,7 @@ void ERRD_error( int code, CONST TEXT * text) sprintf(s, "** DSQL error: %s **\n", text); TRACE(s); - LONGJMP(*tdsql->tsql_setjmp, code); + Firebird::status_longjmp_error::raise(code); } @@ -323,7 +323,7 @@ void ERRD_punt(void) /* Give up whatever we were doing and return to the user. */ - LONGJMP(*tdsql->tsql_setjmp, (int) tdsql->tsql_status[1]); + Firebird::status_longjmp_error::raise(tdsql->tsql_status[1]); } diff --git a/src/dsql/errd_proto.h b/src/dsql/errd_proto.h index a606294be8..d764967cbe 100644 --- a/src/dsql/errd_proto.h +++ b/src/dsql/errd_proto.h @@ -29,11 +29,11 @@ extern "C" { #endif #ifdef DEV_BUILD -void ERRD_assert_msg(CONST UCHAR *, CONST UCHAR *, ULONG); +void ERRD_assert_msg(const char*, const char*, ULONG); #endif -void ERRD_bugcheck(CONST TEXT *); -void ERRD_error(int, CONST TEXT *); +void ERRD_bugcheck(const char*); +void ERRD_error(int, const char*); void ERRD_post(STATUS, ...); BOOLEAN ERRD_post_warning(STATUS, ...); void ERRD_punt(void); diff --git a/src/dsql/gen.cpp b/src/dsql/gen.cpp index f02295fe9d..2968aa07e8 100644 --- a/src/dsql/gen.cpp +++ b/src/dsql/gen.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: gen.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +$Id: gen.cpp,v 1.3 2001-12-24 02:50:48 tamlin Exp $ */ #include "firebird.h" @@ -90,31 +90,26 @@ UCHAR GEN_expand_buffer( REQ request, UCHAR byte) * The blr buffer needs to be expanded. * **************************************/ - ULONG length; - ULONG copy_length; - PLB pool; - STR new_buffer; + BLOB_PTR *p; /* one huge pointer per line for LIBS */ BLOB_PTR *q; /* one huge pointer per line for LIBS */ BLOB_PTR *end; /* one huge pointer per line for LIBS */ - TSQL tdsql; - tdsql = GET_THREAD_DATA; + TSQL tdsql = GET_THREAD_DATA; - length = request->req_blr_string->str_length + 2048; - pool = (request->req_blr_string->str_header.blk_pool_id == - DSQL_permanent_pool->plb_pool_id) ? + ULONG length = request->req_blr_string->str_length + 2048; + DsqlMemoryPool *pool = (MemoryPool::blk_pool(request->req_blr_string) == DSQL_permanent_pool) ? DSQL_permanent_pool : tdsql->tsql_default; - new_buffer = (STR) ALLOCV(type_str, pool, length); + STR new_buffer = new(*pool, length) str; new_buffer->str_length = length; p = new_buffer->str_data; q = request->req_blr_string->str_data; end = request->req_blr; - copy_length = (ULONG) (end - q); + ULONG copy_length = (ULONG) (end - q); memcpy(p, q, copy_length); - ALLD_release(reinterpret_cast(request->req_blr_string)); + delete request->req_blr_string; request->req_blr_string = new_buffer; request->req_blr = p + copy_length; request->req_blr_yellow = new_buffer->str_data + length; @@ -636,7 +631,7 @@ void GEN_port( REQ request, MSG message) /* Allocate buffer for message */ - buffer = (STR) ALLOCDV(type_str, message->msg_length + DOUBLE_ALIGN - 1); + buffer = new(*tdsql->tsql_default, message->msg_length + DOUBLE_ALIGN - 1) str; message->msg_buffer = (UCHAR *) FB_ALIGN((U_IPTR) buffer->str_data, DOUBLE_ALIGN); diff --git a/src/dsql/hsh.cpp b/src/dsql/hsh.cpp index 84beccef8f..8a50dd151a 100644 --- a/src/dsql/hsh.cpp +++ b/src/dsql/hsh.cpp @@ -86,7 +86,7 @@ void HSHD_init(void) } #endif - p = (UCHAR *) ALLD_malloc(sizeof(SYM) * HASH_SIZE); + p = (UCHAR *) MemoryPool::malloc_from_system(sizeof(SYM) * HASH_SIZE); memset(p, 0, sizeof(SYM) * HASH_SIZE); hash_table = (SYM *) p; @@ -156,7 +156,7 @@ void HSHD_fini(void) hash_table[i] = NULL; } - ALLD_free(hash_table); + MemoryPool::free_from_system(hash_table); hash_table = NULL; } diff --git a/src/dsql/make.cpp b/src/dsql/make.cpp index 4485828809..a6717f0d05 100644 --- a/src/dsql/make.cpp +++ b/src/dsql/make.cpp @@ -20,6 +20,11 @@ * All Rights Reserved. * Contributor(s): ______________________________________. */ + +//This MUST be before any other includes +#ifdef DARWIN +#define _STLP_CCTYPE +#endif #include "firebird.h" #include @@ -40,9 +45,6 @@ #include "../jrd/cvt_proto.h" -extern "C" { - - ASSERT_FILENAME /* declare things assert() needs */ /* InterBase provides transparent conversion from string to date in * contexts where it makes sense. This macro checks a descriptor to @@ -53,7 +55,9 @@ ASSERT_FILENAME /* declare things assert() needs */ #define IS_DATE_AND_TIME(d1,d2) \ ((((d1).dsc_dtype==dtype_sql_time)&&((d2).dsc_dtype==dtype_sql_date)) || \ (((d2).dsc_dtype==dtype_sql_time)&&((d1).dsc_dtype==dtype_sql_date))) - NOD MAKE_constant(STR constant, int numeric_flag) + + +NOD MAKE_constant(STR constant, int numeric_flag) { /************************************** * @@ -70,9 +74,9 @@ ASSERT_FILENAME /* declare things assert() needs */ tdsql = GET_THREAD_DATA; - node = (NOD) ALLOCDV(type_nod, - (numeric_flag == CONSTANT_TIMESTAMP || - numeric_flag == CONSTANT_SINT64) ? 2 : 1); + node = new(*tdsql->tsql_default, + (numeric_flag == CONSTANT_TIMESTAMP || + numeric_flag == CONSTANT_SINT64) ? 2 : 1) nod; node->nod_type = nod_constant; if (numeric_flag == CONSTANT_SLONG) { @@ -84,7 +88,7 @@ ASSERT_FILENAME /* declare things assert() needs */ node->nod_arg[0] = (NOD) constant; } else if (numeric_flag == CONSTANT_DOUBLE) { - DEV_BLKCHK(constant, type_str); + DEV_BLKCHK(constant, dsql_type_str); /* This is a numeric value which is transported to the engine as * a string. The engine will convert it. Use dtype_double so that @@ -166,23 +170,23 @@ ASSERT_FILENAME /* declare things assert() needs */ tmp.dsc_scale = 0; tmp.dsc_flags = 0; tmp.dsc_ttype = ttype_ascii; - tmp.dsc_length = static_cast < USHORT > (constant->str_length); + tmp.dsc_length = static_cast(constant->str_length); tmp.dsc_address = constant->str_data; /* Now invoke the string_to_date/time/timestamp routines */ CVT_move(&tmp, &node->nod_desc, - reinterpret_cast < void (*)() > (ERRD_post)); + reinterpret_cast (ERRD_post)); } else { assert(numeric_flag == CONSTANT_STRING); - DEV_BLKCHK(constant, type_str); + DEV_BLKCHK(constant, dsql_type_str); node->nod_desc.dsc_dtype = dtype_text; node->nod_desc.dsc_sub_type = 0; node->nod_desc.dsc_scale = 0; node->nod_desc.dsc_length = - static_cast < USHORT > (constant->str_length); + static_cast(constant->str_length); node->nod_desc.dsc_address = constant->str_data; node->nod_desc.dsc_ttype = ttype_dynamic; /* carry a pointer to the constant to resolve character set in pass1 */ @@ -211,15 +215,15 @@ NOD MAKE_str_constant(STR constant, SSHORT character_set) tdsql = GET_THREAD_DATA; - node = (NOD) ALLOCDV(type_nod, 1); + node = new(*tdsql->tsql_default, 1) nod; node->nod_type = nod_constant; - DEV_BLKCHK(constant, type_str); + DEV_BLKCHK(constant, dsql_type_str); node->nod_desc.dsc_dtype = dtype_text; node->nod_desc.dsc_sub_type = 0; node->nod_desc.dsc_scale = 0; - node->nod_desc.dsc_length = static_cast < USHORT > (constant->str_length); + node->nod_desc.dsc_length = static_cast(constant->str_length); node->nod_desc.dsc_address = constant->str_data; node->nod_desc.dsc_ttype = character_set; /* carry a pointer to the constant to resolve character set in pass1 */ @@ -267,7 +271,7 @@ void MAKE_desc( DSC * desc, NOD node) UDF udf; FLD field; - DEV_BLKCHK(node, type_nod); + DEV_BLKCHK(node, dsql_type_nod); /* If we already know the datatype, don't worry about anything */ @@ -766,7 +770,7 @@ void MAKE_desc( DSC * desc, NOD node) MAKE_desc(&desc1, node->nod_arg[0]); MAKE_desc(&desc2, node->nod_arg[1]); dtype = DSC_multiply_result[desc1.dsc_dtype][desc2.dsc_dtype]; - desc->dsc_dtype = static_cast < UCHAR > (dtype); + desc->dsc_dtype = static_cast(dtype); desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable; switch (dtype) { @@ -817,9 +821,9 @@ void MAKE_desc( DSC * desc, NOD node) case nod_udf: udf = (UDF) node->nod_arg[0]; - desc->dsc_dtype = static_cast < UCHAR > (udf->udf_dtype); + desc->dsc_dtype = static_cast(udf->udf_dtype); desc->dsc_length = udf->udf_length; - desc->dsc_scale = static_cast < SCHAR > (udf->udf_scale); + desc->dsc_scale = static_cast(udf->udf_scale); desc->dsc_flags = 0; desc->dsc_ttype = udf->udf_sub_type; return; @@ -966,10 +970,10 @@ void MAKE_desc_from_field( DSC * desc, FLD field) * **************************************/ - DEV_BLKCHK(field, type_fld); + DEV_BLKCHK(field, dsql_type_fld); - desc->dsc_dtype = static_cast < UCHAR > (field->fld_dtype); - desc->dsc_scale = static_cast < SCHAR > (field->fld_scale); + desc->dsc_dtype = static_cast(field->fld_dtype); + desc->dsc_scale = static_cast(field->fld_scale); desc->dsc_sub_type = field->fld_sub_type; desc->dsc_length = field->fld_length; desc->dsc_flags = (field->fld_flags & FLD_nullable) ? DSC_nullable : 0; @@ -978,7 +982,7 @@ void MAKE_desc_from_field( DSC * desc, FLD field) field->fld_collation_id); } else if (desc->dsc_dtype == dtype_blob) - desc->dsc_scale = static_cast < SCHAR > (field->fld_character_set_id); + desc->dsc_scale = static_cast(field->fld_character_set_id); } @@ -996,9 +1000,9 @@ NOD MAKE_field(CTX context, FLD field, NOD indices) **************************************/ NOD node; - DEV_BLKCHK(context, type_ctx); - DEV_BLKCHK(field, type_fld); - DEV_BLKCHK(indices, type_nod); + DEV_BLKCHK(context, dsql_type_ctx); + DEV_BLKCHK(field, dsql_type_fld); + DEV_BLKCHK(indices, dsql_type_nod); node = MAKE_node(nod_field, e_fld_count); node->nod_arg[e_fld_context] = (NOD) context; @@ -1008,7 +1012,7 @@ NOD MAKE_field(CTX context, FLD field, NOD indices) node->nod_arg[e_fld_indices] = indices; MAKE_desc_from_field(&node->nod_desc, field); node->nod_desc.dsc_dtype = - static_cast < UCHAR > (field->fld_element_dtype); + static_cast(field->fld_element_dtype); node->nod_desc.dsc_length = field->fld_element_length; /* node->nod_desc.dsc_scale = field->fld_scale; @@ -1019,7 +1023,7 @@ NOD MAKE_field(CTX context, FLD field, NOD indices) node->nod_desc.dsc_dtype = dtype_array; node->nod_desc.dsc_length = sizeof(GDS__QUAD); node->nod_desc.dsc_scale = - static_cast < SCHAR > (field->fld_scale); + static_cast(field->fld_scale); node->nod_desc.dsc_sub_type = field->fld_sub_type; } } @@ -1036,7 +1040,7 @@ NOD MAKE_field(CTX context, FLD field, NOD indices) } -NOD MAKE_list(LLS stack) +NOD MAKE_list(DLLS stack) { /************************************** * @@ -1048,11 +1052,11 @@ NOD MAKE_list(LLS stack) * Make a list node from a linked list stack of things. * **************************************/ - LLS temp; + DLLS temp; USHORT count; NOD node, *ptr; - DEV_BLKCHK(stack, type_lls); + DEV_BLKCHK(stack, dsql_type_lls); for (temp = stack, count = 0; temp; temp = temp->lls_next) ++count; @@ -1084,7 +1088,7 @@ NOD MAKE_node(NOD_TYPE type, int count) tdsql = GET_THREAD_DATA; - node = (NOD) ALLOCDV(type_nod, count); + node = new(*tdsql->tsql_default, count) nod; node->nod_type = type; node->nod_count = count; @@ -1108,11 +1112,11 @@ PAR MAKE_parameter(MSG message, USHORT sqlda_flag, USHORT null_flag) PAR parameter, null; TSQL tdsql; - DEV_BLKCHK(message, type_msg); + DEV_BLKCHK(message, dsql_type_msg); tdsql = GET_THREAD_DATA; - parameter = (PAR) ALLOCD(type_par); + parameter = new(*tdsql->tsql_default) par; parameter->par_message = message; if (parameter->par_next = message->msg_parameters) parameter->par_next->par_ordered = parameter; @@ -1174,14 +1178,14 @@ SYM MAKE_symbol(DBB database, TEXT *p; TSQL tdsql; - DEV_BLKCHK(database, type_dbb); - DEV_BLKCHK(object, type_req); + DEV_BLKCHK(database, dsql_type_dbb); + DEV_BLKCHK(object, dsql_type_req); assert(name); assert(length > 0); tdsql = GET_THREAD_DATA; - symbol = (SYM) ALLOCDV(type_sym, length); + symbol = new(*tdsql->tsql_default, length) sym; symbol->sym_type = type; symbol->sym_object = (BLK) object; symbol->sym_dbb = database; @@ -1197,7 +1201,7 @@ SYM MAKE_symbol(DBB database, } -STR MAKE_tagged_string(CONST UCHAR * str, int length, CONST TEXT * charset) +STR MAKE_tagged_string(CONST UCHAR * str_, int length, CONST TEXT * charset) { /************************************** * @@ -1216,11 +1220,11 @@ STR MAKE_tagged_string(CONST UCHAR * str, int length, CONST TEXT * charset) tdsql = GET_THREAD_DATA; - string = (STR) ALLOCDV(type_str, length); + string = new(*tdsql->tsql_default, length) str; string->str_charset = const_cast < char *>(charset); string->str_length = length; for (p = string->str_data; length; --length) - *p++ = *str++; + *p++ = *str_++; return string; } @@ -1242,26 +1246,24 @@ NOD MAKE_variable(FLD field, * **************************************/ NOD node; - VAR var; + VAR var_; TSQL tdsql; - DEV_BLKCHK(field, type_fld); + DEV_BLKCHK(field, dsql_type_fld); tdsql = GET_THREAD_DATA; - var = (VAR) ALLOCDV(type_var, strlen(name)); + var_ = new(*tdsql->tsql_default, strlen(name)) var; node = MAKE_node(nod_variable, e_var_count); - node->nod_arg[e_var_variable] = (NOD) var; - var->var_msg_number = msg_number; - var->var_msg_item = item_number; - var->var_variable_number = local_number; - var->var_field = field; - strcpy(var->var_name, name); - var->var_flags = type; + node->nod_arg[e_var_variable] = (NOD) var_; + var_->var_msg_number = msg_number; + var_->var_msg_item = item_number; + var_->var_variable_number = local_number; + var_->var_field = field; + strcpy(var_->var_name, name); + var_->var_flags = type; MAKE_desc_from_field(&node->nod_desc, field); return node; } - -} // extern "C" diff --git a/src/dsql/make_proto.h b/src/dsql/make_proto.h index 9722c41db0..670ff4f277 100644 --- a/src/dsql/make_proto.h +++ b/src/dsql/make_proto.h @@ -26,28 +26,21 @@ #include "../dsql/sym.h" -#ifdef __cplusplus -extern "C" { -#endif - -struct nod *MAKE_constant(struct str *, int); -struct nod *MAKE_str_constant(struct str *, SSHORT); -struct str *MAKE_cstring(CONST SCHAR *); -void MAKE_desc(struct dsc *, struct nod *); -void MAKE_desc_from_field(struct dsc *, struct fld *); -struct nod *MAKE_field(struct ctx *, struct fld *, struct nod *); -struct nod *MAKE_list(struct lls *); -struct nod *MAKE_node(ENUM nod_t, int); -struct par *MAKE_parameter(struct msg *, USHORT, USHORT); -struct str *MAKE_string(CONST UCHAR *, int); -struct sym *MAKE_symbol(struct dbb *, CONST TEXT *, USHORT, - ENUM sym_type, struct req *); -struct str *MAKE_tagged_string(CONST UCHAR *, int, CONST TEXT *); -struct nod *MAKE_variable(struct fld *, CONST TEXT *, USHORT, USHORT, +struct nod* MAKE_constant(class str* , int); +struct nod* MAKE_str_constant(class str* , SSHORT); +class str* MAKE_cstring(CONST SCHAR*); +void MAKE_desc(struct dsc* , struct nod*); +void MAKE_desc_from_field(struct dsc* , class fld*); +struct nod* MAKE_field(class ctx* , class fld* , struct nod*); +struct nod* MAKE_list(class dsql_lls*); +struct nod* MAKE_node(ENUM nod_t, int); +class par* MAKE_parameter(class msg* , USHORT, USHORT); +class str* MAKE_string(CONST UCHAR* , int); +struct sym* MAKE_symbol(class dbb* , CONST TEXT* , USHORT, + ENUM sym_type, class req*); +class str* MAKE_tagged_string(CONST UCHAR* , int, CONST TEXT*); +struct nod* MAKE_variable(class fld* , CONST TEXT* , USHORT, USHORT, USHORT, USHORT); -#ifdef __cplusplus -} /* extern "C" */ -#endif #endif /* _DSQL_MAKE_PROTO_H_ */ diff --git a/src/dsql/metd.epp b/src/dsql/metd.epp index 4ca6228724..3fd694d35f 100644 --- a/src/dsql/metd.epp +++ b/src/dsql/metd.epp @@ -1,6 +1,6 @@ /* * PROGRAM: Dynamic SQL runtime support - * MODULE: met.e + * MODULE: met.epp * DESCRIPTION: Meta-data interface * * The contents of this file are subject to the Interbase Public @@ -41,7 +41,7 @@ #include "../jrd/thd_proto.h" #include "../jrd/constants.h" -/* NOTE: The static definition of DB and gds__trans by gpre will not +/* NOTE: The static definition of DB and gds_trans by gpre will not be used by the meta data routines. Each of those routines has its own local definition of these variables. */ @@ -213,7 +213,7 @@ INTLSYM METD_get_collation(REQ request, STR name) * If it doesn't exist, return NULL. * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; INTLSYM iname; SYM symbol; @@ -232,7 +232,7 @@ INTLSYM METD_get_collation(REQ request, STR name) dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; iname = NULL; THREAD_EXIT; @@ -244,7 +244,7 @@ INTLSYM METD_get_collation(REQ request, STR name) THREAD_ENTER; - iname = (INTLSYM) ALLOCV(type_intlsym, dbb->dbb_pool, name->str_length); + iname = new(*dbb->dbb_pool, name->str_length) intlsym; strcpy(iname->intlsym_name, (TEXT *) name->str_data); iname->intlsym_type = INTLSYM_collation; iname->intlsym_flags = 0; @@ -268,7 +268,7 @@ INTLSYM METD_get_collation(REQ request, STR name) /* Store in the symbol table */ - symbol = iname->intlsym_symbol = (SYM) ALLOCV(type_sym, dbb->dbb_pool, 0); + symbol = iname->intlsym_symbol = new(*dbb->dbb_pool, 0) sym; symbol->sym_object = (BLK) iname; symbol->sym_string = iname->intlsym_name; symbol->sym_length = name->str_length; @@ -303,7 +303,7 @@ TEXT * buffer, USHORT buff_length) * Reads the system tables RDB$FIELDS and RDB$RELATION_FIELDS. * **************************************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; long status_vect[20]; @@ -318,7 +318,7 @@ TEXT * buffer, USHORT buff_length) dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; /* V4.x multi threading requirements */ THREAD_EXIT; @@ -346,7 +346,7 @@ TEXT * buffer, USHORT buff_length) if (*has_default) { /* open the blob */ THREAD_EXIT; - stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds__trans, + stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds_trans, (void**) &blob_handle, blob_id, sizeof(blr_bpb), (UCHAR*)blr_bpb); THREAD_ENTER; @@ -413,7 +413,7 @@ INTLSYM METD_get_charset(REQ request, USHORT length, UCHAR * name) * If it doesn't exist, return NULL. * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; INTLSYM iname; SYM symbol; @@ -431,7 +431,7 @@ INTLSYM METD_get_charset(REQ request, USHORT length, UCHAR * name) dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; iname = NULL; THREAD_EXIT; @@ -447,7 +447,7 @@ INTLSYM METD_get_charset(REQ request, USHORT length, UCHAR * name) THREAD_ENTER; - iname = (INTLSYM) ALLOCV(type_intlsym, dbb->dbb_pool, length); + iname = new(*dbb->dbb_pool, length) intlsym; strcpy(iname->intlsym_name, (char*) name); iname->intlsym_type = INTLSYM_charset; iname->intlsym_flags = 0; @@ -473,7 +473,7 @@ INTLSYM METD_get_charset(REQ request, USHORT length, UCHAR * name) /* Store in the symbol table */ - symbol = iname->intlsym_symbol = (SYM) ALLOCV(type_sym, dbb->dbb_pool, 0); + symbol = iname->intlsym_symbol = new(*dbb->dbb_pool, 0) sym; symbol->sym_object = (BLK) iname; symbol->sym_string = iname->intlsym_name; symbol->sym_length = length; @@ -497,11 +497,11 @@ STR METD_get_default_charset(REQ request) * Find the default character set for a database * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; isc_req_handle handle; UCHAR *p; - UCHAR *str; + UCHAR *str_; USHORT length; dbb = request->req_dbb; @@ -514,7 +514,7 @@ STR METD_get_default_charset(REQ request) /* Now see if it is in the database */ DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; handle = NULL_PTR; @@ -529,12 +529,12 @@ STR METD_get_default_charset(REQ request) /* Terminate ASCIIZ string on first blank */ metd_exact_name(DBB.RDB$CHARACTER_SET_NAME); length = strlen(DBB.RDB$CHARACTER_SET_NAME); - dbb->dbb_dfl_charset = (STR) ALLOCV(type_str, dbb->dbb_pool, length); + dbb->dbb_dfl_charset = new(*dbb->dbb_pool, length) str; dbb->dbb_dfl_charset->str_length = length; dbb->dbb_dfl_charset->str_charset = NULL; - str = (UCHAR*) DBB.RDB$CHARACTER_SET_NAME; + str_ = (UCHAR*) DBB.RDB$CHARACTER_SET_NAME; for (p = dbb->dbb_dfl_charset->str_data; length; --length) - *p++ = *str++; + *p++ = *str_++; THREAD_EXIT; END_FOR @@ -551,7 +551,7 @@ gds__release request () THREAD_EXIT; *************/ - isc_release_request(gds__status, GDS_REF(handle)); + isc_release_request(gds_status, GDS_REF(handle)); THREAD_ENTER; if (dbb->dbb_dfl_charset == NULL) @@ -573,13 +573,13 @@ USHORT METD_get_domain(REQ request, FLD field, UCHAR * name) * Fetch domain information for field defined as 'name' * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; USHORT found = FALSE; dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; THREAD_EXIT; @@ -639,7 +639,7 @@ void METD_get_domain_default(REQ request, * Gets the default value for a domain of an existing table. * **************************************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; ISC_STATUS status_vect[20]; @@ -654,7 +654,7 @@ void METD_get_domain_default(REQ request, dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; /* V4.x multi threading requirements */ THREAD_EXIT; @@ -672,7 +672,7 @@ void METD_get_domain_default(REQ request, if (*has_default) { /* open the blob */ THREAD_EXIT; - stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds__trans, + stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds_trans, (void**) &blob_handle, blob_id, sizeof(blr_bpb), (UCHAR*)blr_bpb); THREAD_ENTER; @@ -744,9 +744,9 @@ UDF METD_get_function(REQ request, STR name) * return NULL. * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; - UDF udf; + UDF udf_; USHORT return_arg; SYM symbol; @@ -761,8 +761,8 @@ UDF METD_get_function(REQ request, STR name) dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; - udf = NULL; + gds_trans = (SLONG*) request->req_trans; + udf_ = NULL; THREAD_EXIT; @@ -772,10 +772,10 @@ UDF METD_get_function(REQ request, STR name) THREAD_ENTER; - udf = (UDF) ALLOCV(type_udf, dbb->dbb_pool, name->str_length); - udf->udf_next = dbb->dbb_functions; - dbb->dbb_functions = udf; - strcpy((char*) udf->udf_name, (char*) name->str_data); + udf_ = new(*dbb->dbb_pool, name->str_length) udf; + udf_->udf_next = dbb->dbb_functions; + dbb->dbb_functions = udf_; + strcpy((char*) udf_->udf_name, (char*) name->str_data); return_arg = X.RDB$RETURN_ARGUMENT; THREAD_EXIT; @@ -786,7 +786,7 @@ UDF METD_get_function(REQ request, STR name) THREAD_ENTER; - if (!udf) + if (!udf_) return NULL; /* Note: The following two requests differ in the fields which are @@ -805,11 +805,11 @@ UDF METD_get_function(REQ request, STR name) THREAD_ENTER; - udf->udf_dtype = (X.RDB$FIELD_TYPE != blr_blob) ? + udf_->udf_dtype = (X.RDB$FIELD_TYPE != blr_blob) ? gds_cvt_blr_dtype[X.RDB$FIELD_TYPE] : dtype_blob; - udf->udf_scale = X.RDB$FIELD_SCALE; - udf->udf_sub_type = X.RDB$FIELD_SUB_TYPE; - udf->udf_length = X.RDB$FIELD_LENGTH; + udf_->udf_scale = X.RDB$FIELD_SCALE; + udf_->udf_sub_type = X.RDB$FIELD_SUB_TYPE; + udf_->udf_length = X.RDB$FIELD_LENGTH; THREAD_EXIT; @@ -826,14 +826,14 @@ UDF METD_get_function(REQ request, STR name) THREAD_ENTER; - udf->udf_dtype = (X.RDB$FIELD_TYPE != blr_blob) ? + udf_->udf_dtype = (X.RDB$FIELD_TYPE != blr_blob) ? gds_cvt_blr_dtype[X.RDB$FIELD_TYPE] : dtype_blob; - udf->udf_scale = X.RDB$FIELD_SCALE; - udf->udf_sub_type = X.RDB$FIELD_SUB_TYPE; - udf->udf_length = X.RDB$FIELD_LENGTH; + udf_->udf_scale = X.RDB$FIELD_SCALE; + udf_->udf_sub_type = X.RDB$FIELD_SUB_TYPE; + udf_->udf_length = X.RDB$FIELD_LENGTH; if (!X.RDB$CHARACTER_SET_ID.NULL) - udf->udf_character_set_id = X.RDB$CHARACTER_SET_ID; + udf_->udf_character_set_id = X.RDB$CHARACTER_SET_ID; THREAD_EXIT; @@ -850,23 +850,23 @@ UDF METD_get_function(REQ request, STR name) * (Q: why not use varying?) */ - if (udf->udf_dtype == dtype_cstring) { - udf->udf_dtype = dtype_text; + if (udf_->udf_dtype == dtype_cstring) { + udf_->udf_dtype = dtype_text; } - else if (udf->udf_dtype == dtype_varying) - udf->udf_length += sizeof(USHORT); + else if (udf_->udf_dtype == dtype_varying) + udf_->udf_length += sizeof(USHORT); /* Store in the symbol table */ - symbol = udf->udf_symbol = (SYM) ALLOCV(type_sym, dbb->dbb_pool, 0); - symbol->sym_object = (BLK) udf; - symbol->sym_string = udf->udf_name; + symbol = udf_->udf_symbol = new(*dbb->dbb_pool, 0) sym; + symbol->sym_object = (BLK) udf_; + symbol->sym_string = udf_->udf_name; symbol->sym_length = name->str_length; symbol->sym_type = SYM_udf; symbol->sym_dbb = dbb; HSHD_insert(symbol); - return udf; + return udf_; } @@ -884,7 +884,7 @@ NOD METD_get_primary_key(REQ request, STR relation_name) * node of the fields. * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; NOD list, field_node; STR field_name; @@ -892,7 +892,7 @@ NOD METD_get_primary_key(REQ request, STR relation_name) dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; list = NULL; count = 0; @@ -943,7 +943,7 @@ PRC METD_get_procedure(REQ request, STR name) * If it is marked dropped, try to read from system tables * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; FLD parameter, *ptr; PRC procedure, temp; @@ -977,7 +977,7 @@ PRC METD_get_procedure(REQ request, STR name) dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; procedure = NULL; THREAD_EXIT; @@ -990,8 +990,8 @@ PRC METD_get_procedure(REQ request, STR name) metd_exact_name(X.RDB$OWNER_NAME); - procedure = (PRC) ALLOCV(type_prc, dbb->dbb_pool, - name->str_length + strlen(X.RDB$OWNER_NAME)); + procedure = new(*dbb->dbb_pool, + name->str_length + strlen(X.RDB$OWNER_NAME)) prc; procedure->prc_id = X.RDB$PROCEDURE_ID; procedure->prc_name = procedure->prc_data; @@ -1037,8 +1037,8 @@ PRC METD_get_procedure(REQ request, STR name) /* allocate the field block */ metd_exact_name(PR.RDB$PARAMETER_NAME); - parameter = (FLD) ALLOCV(type_fld, dbb->dbb_pool, - strlen(PR.RDB$PARAMETER_NAME)); + parameter = new(*dbb->dbb_pool, + strlen(PR.RDB$PARAMETER_NAME)) fld; parameter->fld_next = *ptr; *ptr = parameter; @@ -1107,8 +1107,7 @@ PRC METD_get_procedure(REQ request, STR name) procedure->prc_next = dbb->dbb_procedures; dbb->dbb_procedures = procedure; - symbol = procedure->prc_symbol = - (SYM) ALLOCV(type_sym, dbb->dbb_pool, 0); + symbol = procedure->prc_symbol = new(*dbb->dbb_pool, 0) sym; symbol->sym_object = (BLK) procedure; symbol->sym_string = procedure->prc_name; symbol->sym_length = name->str_length; @@ -1135,7 +1134,7 @@ DSQL_REL METD_get_relation(REQ request, STR name) * If it does, fetch field information as well. * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; FLD field, *ptr; DSQL_REL relation, temp; @@ -1170,7 +1169,7 @@ DSQL_REL METD_get_relation(REQ request, STR name) dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; relation = NULL; THREAD_EXIT; @@ -1186,15 +1185,14 @@ DSQL_REL METD_get_relation(REQ request, STR name) metd_exact_name(X.RDB$OWNER_NAME); if (!X.RDB$RELATION_ID.NULL) { - relation = - (DSQL_REL) ALLOCV(type_dsql_rel, dbb->dbb_pool, - name->str_length + strlen(X.RDB$OWNER_NAME)); + relation = new(*dbb->dbb_pool, + name->str_length + strlen(X.RDB$OWNER_NAME)) dsql_rel; relation->rel_id = X.RDB$RELATION_ID; } else if (!DDL_ids(request)) { relation = - (DSQL_REL) ALLOCDV(type_dsql_rel, - name->str_length + strlen(X.RDB$OWNER_NAME)); + new(*tdsql->tsql_default, + name->str_length + strlen(X.RDB$OWNER_NAME)) dsql_rel; relation->rel_flags |= REL_new_relation; } @@ -1245,11 +1243,11 @@ DSQL_REL METD_get_relation(REQ request, STR name) /* Allocate from default or permanent pool as appropriate */ if (relation->rel_flags & REL_new_relation) - *ptr = field = (FLD) ALLOCDV(type_fld, - strlen(RFR.RDB$FIELD_NAME)); + *ptr = field = new(*tdsql->tsql_default, + strlen(RFR.RDB$FIELD_NAME)) fld; else - *ptr = field = (FLD) ALLOCV(type_fld, dbb->dbb_pool, - strlen(RFR.RDB$FIELD_NAME)); + *ptr = field = new(*dbb->dbb_pool, + strlen(RFR.RDB$FIELD_NAME)) fld; ptr = &field->fld_next; /* get field information */ @@ -1296,11 +1294,11 @@ DSQL_REL METD_get_relation(REQ request, STR name) /* Allocate from default or permanent pool as appropriate */ if (relation->rel_flags & REL_new_relation) - *ptr = field = (FLD) ALLOCDV(type_fld, - strlen(RFR.RDB$FIELD_NAME)); + *ptr = field = new(*tdsql->tsql_default, + strlen(RFR.RDB$FIELD_NAME)) fld; else - *ptr = field = (FLD) ALLOCV(type_fld, dbb->dbb_pool, - strlen(RFR.RDB$FIELD_NAME)); + *ptr = field = new(*dbb->dbb_pool, + strlen(RFR.RDB$FIELD_NAME)) fld; ptr = &field->fld_next; @@ -1373,8 +1371,7 @@ DSQL_REL METD_get_relation(REQ request, STR name) /* store in the symbol table unless the relation is not yet committed */ - symbol = relation->rel_symbol = - (SYM) ALLOCV(type_sym, dbb->dbb_pool, 0); + symbol = relation->rel_symbol = new(*dbb->dbb_pool, 0) sym; symbol->sym_object = (BLK) relation; symbol->sym_string = relation->rel_name; symbol->sym_length = name->str_length; @@ -1399,13 +1396,13 @@ STR METD_get_trigger_relation(REQ request, STR name, USHORT * trig_type) * Look up a trigger's relation and return it's current type * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; STR relation; dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; relation = NULL; @@ -1444,13 +1441,13 @@ USHORT METD_get_type(REQ request, STR name, UCHAR * field, SSHORT * value) * Look up a symbolic name in RDB$TYPES * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; USHORT found; dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; found = FALSE; @@ -1494,13 +1491,13 @@ DSQL_REL METD_get_view_relation(REQ request, * **************************************/ DBB dbb; - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; STR relation_name; DSQL_REL relation; dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; relation = NULL; @@ -1519,7 +1516,7 @@ DSQL_REL METD_get_view_relation(REQ request, relation_name = MAKE_string((UCHAR*) X.RDB$RELATION_NAME, strlen(X.RDB$RELATION_NAME)); relation = METD_get_relation(request, relation_name); - ALLD_release((FRB)relation_name); + delete relation_name; return relation; } @@ -1554,12 +1551,12 @@ static void check_array( REQ request, TEXT * field_name, FLD field) * so in the database block to avoid wasting further effort. * **************************************/ - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; DBB dbb; dbb = request->req_dbb; DB = dbb->dbb_database_handle; - gds__trans = (SLONG*) request->req_trans; + gds_trans = (SLONG*) request->req_trans; THREAD_EXIT; @@ -1643,18 +1640,18 @@ static void free_procedure( PRC procedure) for (param = procedure->prc_inputs; param;) { temp = param; param = param->fld_next; - ALLD_release((FRB) temp); + delete temp; } for (param = procedure->prc_outputs; param;) { temp = param; param = param->fld_next; - ALLD_release((FRB) temp); + delete temp; } /* release the procedure & symbol blocks */ - ALLD_release((FRB) procedure); + delete procedure; } @@ -1677,12 +1674,12 @@ static void free_relation( DSQL_REL relation) for (field = relation->rel_fields; field;) { temp = field; field = field->fld_next; - ALLD_release((FRB) temp); + delete temp; } /* release the relation & symbol blocks */ - ALLD_release((FRB) relation); + delete relation; } diff --git a/src/dsql/metd_proto.h b/src/dsql/metd_proto.h index add5c7268d..944030d944 100644 --- a/src/dsql/metd_proto.h +++ b/src/dsql/metd_proto.h @@ -24,28 +24,21 @@ #ifndef _DSQL_METD_PROTO_H #define _DSQL_METD_PROTO_H -#ifdef __cplusplus -extern "C" { -#endif - -void METD_drop_procedure(struct req*, struct str *); -void METD_drop_relation(struct req*, struct str *); -INTLSYM METD_get_charset(struct req*, USHORT, UCHAR *); -INTLSYM METD_get_collation(struct req*, struct str *); +void METD_drop_procedure(class req*, class str*); +void METD_drop_relation(class req*, class str*); +INTLSYM METD_get_charset(class req*, USHORT, UCHAR *); +INTLSYM METD_get_collation(class req*, class str*); void METD_get_col_default(REQ, TEXT*, TEXT*, BOOLEAN*, TEXT*, USHORT); -STR METD_get_default_charset(struct req*); -USHORT METD_get_domain(struct req*, struct fld*, UCHAR*); -void METD_get_domain_default(REQ, TEXT*, BOOLEAN*, TEXT*, USHORT); -UDF METD_get_function(struct req*, struct str*); -NOD METD_get_primary_key(struct req*, struct str*); -PRC METD_get_procedure(struct req*, struct str*); -DSQL_REL METD_get_relation(struct req*, struct str*); -STR METD_get_trigger_relation(struct req*, struct str*, USHORT*); -USHORT METD_get_type(struct req*, struct str*, UCHAR*, SSHORT*); -DSQL_REL METD_get_view_relation(struct req*, UCHAR*, UCHAR*, USHORT); +STR METD_get_default_charset(class req*); +USHORT METD_get_domain(class req*, class fld*, UCHAR*); +void METD_get_domain_default(class req*, TEXT*, BOOLEAN*, TEXT*, USHORT); +UDF METD_get_function(class req*, class str*); +NOD METD_get_primary_key(class req*, class str*); +PRC METD_get_procedure(class req*, class str*); +DSQL_REL METD_get_relation(class req*, class str*); +STR METD_get_trigger_relation(class req*, class str*, USHORT*); +USHORT METD_get_type(class req*, class str*, UCHAR*, SSHORT*); +DSQL_REL METD_get_view_relation(class req*, UCHAR*, UCHAR*, USHORT); -#ifdef __cplusplus -} /* extern "C" */ -#endif #endif /*_DSQL_METD_PROTO_H */ diff --git a/src/dsql/node.h b/src/dsql/node.h index 3e434cf8c4..bc9a21eb1c 100644 --- a/src/dsql/node.h +++ b/src/dsql/node.h @@ -30,6 +30,7 @@ typedef ENUM nod_t { + nod_unknown_type = 0, nod_commit = 1, /* Commands, not executed. */ nod_rollback, nod_trans, @@ -301,14 +302,18 @@ typedef ENUM nod_t /* definition of a syntax node created both in parsing and in context recognition */ -typedef struct nod { - struct blk nod_header; +class nod : public pool_alloc_rpt +{ +public: NOD_TYPE nod_type; /* Type of node */ DSC nod_desc; /* Descriptor */ USHORT nod_count; /* Number of arguments */ USHORT nod_flags; struct nod *nod_arg[1]; -} *NOD; + + nod() : nod_type(nod_unknown_type), nod_count(0), nod_flags(0) {} +}; +typedef nod *NOD; /* values of flags */ diff --git a/src/dsql/parse.cpp b/src/dsql/parse.cpp index 0381acc41c..ea2ae62106 100644 --- a/src/dsql/parse.cpp +++ b/src/dsql/parse.cpp @@ -93,12 +93,16 @@ static CONST UCHAR static CONST UCHAR NULL_STRING [] = ""; +extern "C" { + #ifndef SHLIB_DEFS NOD DSQL_parse; #else extern NOD DSQL_parse; #endif +} // extern "C" + static FLD field; static FIL file; static NOD field_name; @@ -147,6 +151,9 @@ static SSHORT log_defined, cache_defined; #define DATABASE 295 #define DATE 296 #define DB_KEY 297 +#ifdef DEBUG +#undef DEBUG +#endif #define DEBUG 298 #define DECIMAL 299 #define DECLARE 300 @@ -3392,9 +3399,9 @@ static NOD make_list (NOD); static NOD make_node (NOD_TYPE, int, ...); static NOD make_flag_node (NOD_TYPE, SSHORT, int, ...); static BOOLEAN short_int (NOD, SLONG *, SSHORT); -static void stack_nodes (NOD, LLS *); +static void stack_nodes (NOD, DLLS*); static int yylex (USHORT, USHORT, USHORT, BOOLEAN *); -static void yyerror (TEXT *); +static void yyerror (TEXT*); static void yyabandon (SSHORT, STATUS); #ifndef WINDOWS_ONLY static void check_log_file_attrs (void); @@ -3403,6 +3410,12 @@ static void check_log_file_attrs (void); static TEXT *ptr, *end, *last_token, *line_start; static SSHORT lines, att_charset; +// TMN: Temp hack +#if defined(_MSC_VER) && defined(CONST) +#undef CONST +#define CONST +#endif + typedef struct tok { USHORT tok_ident; CONST SCHAR *tok_string; @@ -3433,18 +3446,18 @@ CONST TOK *token; for (token = tokens; token->tok_string; ++token) { SYM symbol; - STR str; + STR str_; - symbol = (SYM) ALLOCPV (type_sym, 0); + symbol = new(*DSQL_permanent_pool, 0) sym; symbol->sym_string = (TEXT *) token->tok_string; symbol->sym_length = strlen (token->tok_string); symbol->sym_type = SYM_keyword; symbol->sym_keyword = token->tok_ident; symbol->sym_version = token->tok_version; - str = (STR) ALLOCPV (type_str, symbol->sym_length); - str->str_length = symbol->sym_length; - strncpy ((char*)str->str_data, (char*)symbol->sym_string, symbol->sym_length); - symbol->sym_object = (void *) str; + str_ = new(*DSQL_permanent_pool, symbol->sym_length) str; + str_->str_length = symbol->sym_length; + strncpy ((char*)str_->str_data, (char*)symbol->sym_string, symbol->sym_length); + symbol->sym_object = (void *) str_; HSHD_insert (symbol); } @@ -3580,12 +3593,12 @@ tdsql = GET_THREAD_DATA; if (field_name == NULL) { - field = (FLD) ALLOCDV (type_fld, sizeof (INTERNAL_FIELD_NAME)); + field = new(*tdsql->tsql_default, sizeof (INTERNAL_FIELD_NAME)) fld; strcpy (field->fld_name, (TEXT*) INTERNAL_FIELD_NAME); return field; } string = (STR) field_name->nod_arg [1]; -field = (FLD) ALLOCDV (type_fld, strlen ((SCHAR*) string->str_data)); +field = new(*tdsql->tsql_default, strlen ((SCHAR*) string->str_data)) fld; strcpy (field->fld_name, (TEXT*) string->str_data); return field; @@ -3609,7 +3622,7 @@ TSQL tdsql; tdsql = GET_THREAD_DATA; -temp_file = (FIL) ALLOCD (type_fil); +temp_file = new(*tdsql->tsql_default) fil; return temp_file; } @@ -3628,8 +3641,8 @@ static NOD make_list ( * Collapse nested list nodes into single list. * **************************************/ -NOD *ptr; -LLS stack, temp; +NOD* ptr; +DLLS stack, temp; USHORT l; NOD old; TSQL tdsql; @@ -3645,7 +3658,7 @@ for (l = 0, temp = stack; temp; temp = temp->lls_next) l++; old = node; -node = (NOD) ALLOCDV (type_nod, l); +node = new(*tdsql->tsql_default, l) nod; node->nod_count = l; node->nod_type = nod_list; node->nod_flags = old->nod_flags; @@ -3680,7 +3693,7 @@ TSQL tdsql; tdsql = GET_THREAD_DATA; -node = (NOD) ALLOCDV (type_nod, count); +node = new (*tdsql->tsql_default, count) nod; node->nod_type = type; node->nod_count = count; p = node->nod_arg; @@ -3715,7 +3728,7 @@ TSQL tdsql; tdsql = GET_THREAD_DATA; -node = (NOD) ALLOCDV (type_nod, count); +node = new(*tdsql->tsql_default, count) nod; node->nod_type = type; node->nod_flags = flag; node->nod_count = count; @@ -3786,7 +3799,7 @@ return !return_value; static void stack_nodes ( NOD node, - LLS *stack) + DLLS *stack) { /************************************** * @@ -4357,7 +4370,6 @@ dsql_yyparse(USHORT client_dialect, USHORT db_dialect, USHORT parser_version, BO register int yym, yyn, yystate; #if YYDEBUG register char *yys; - extern char *getenv(); if (yys = getenv("YYDEBUG")) { @@ -4418,13 +4430,13 @@ yyloop: if (DSQL_yyerrflag) goto yyinrecovery; #ifdef lint goto yynewerror; -#endif yynewerror: +#endif yyerror("syntax error"); #ifdef lint goto yyerrlab; -#endif yyerrlab: +#endif ++yynerrs; yyinrecovery: if (DSQL_yyerrflag < 3) diff --git a/src/dsql/parse.y b/src/dsql/parse.y index 0938a9a0d2..50e0f3e42e 100644 --- a/src/dsql/parse.y +++ b/src/dsql/parse.y @@ -3352,7 +3352,7 @@ static NOD make_list (NOD); static NOD make_node (NOD_TYPE, int, ...); static NOD make_flag_node (NOD_TYPE, SSHORT, int, ...); static BOOLEAN short_int (NOD, SLONG *, SSHORT); -static void stack_nodes (NOD, LLS *); +static void stack_nodes (NOD, DLLS *); static int yylex (USHORT, USHORT, USHORT, BOOLEAN *); static void yyerror (TEXT *); static void yyabandon (SSHORT, STATUS); @@ -3393,18 +3393,18 @@ CONST TOK *token; for (token = tokens; token->tok_string; ++token) { SYM symbol; - STR str; + STR str_; - symbol = (SYM) ALLOCPV (type_sym, 0); + symbol = new(*DSQL_permanent_pool, 0) sym; symbol->sym_string = (TEXT *) token->tok_string; symbol->sym_length = strlen (token->tok_string); symbol->sym_type = SYM_keyword; symbol->sym_keyword = token->tok_ident; symbol->sym_version = token->tok_version; - str = (STR) ALLOCPV (type_str, symbol->sym_length); - str->str_length = symbol->sym_length; - strncpy ((char*)str->str_data, (char*)symbol->sym_string, symbol->sym_length); - symbol->sym_object = (void *) str; + str_ = new(*DSQL_permanent_pool, symbol->sym_length) str; + str_->str_length = symbol->sym_length; + strncpy ((char*)str_->str_data, (char*)symbol->sym_string, symbol->sym_length); + symbol->sym_object = (void *) str_; HSHD_insert (symbol); } @@ -3540,12 +3540,12 @@ tdsql = GET_THREAD_DATA; if (field_name == NULL) { - field = (FLD) ALLOCDV (type_fld, sizeof (INTERNAL_FIELD_NAME)); + field = new (*tdsql->tsql_default, sizeof (INTERNAL_FIELD_NAME)) fld; strcpy (field->fld_name, (TEXT*) INTERNAL_FIELD_NAME); return field; } string = (STR) field_name->nod_arg [1]; -field = (FLD) ALLOCDV (type_fld, strlen ((SCHAR*) string->str_data)); +field = new(*tdsql->tsql_default, strlen ((SCHAR*) string->str_data)) fld; strcpy (field->fld_name, (TEXT*) string->str_data); return field; @@ -3569,7 +3569,7 @@ TSQL tdsql; tdsql = GET_THREAD_DATA; -temp_file = (FIL) ALLOCD (type_fil); +temp_file = new(*tdsql->tsql_default) fil; return temp_file; } @@ -3589,7 +3589,7 @@ static NOD make_list ( * **************************************/ NOD *ptr; -LLS stack, temp; +DLLS stack, temp; USHORT l; NOD old; TSQL tdsql; @@ -3605,7 +3605,7 @@ for (l = 0, temp = stack; temp; temp = temp->lls_next) l++; old = node; -node = (NOD) ALLOCDV (type_nod, l); +node = new(*tdsql->tsql_default, l) nod; node->nod_count = l; node->nod_type = nod_list; node->nod_flags = old->nod_flags; @@ -3640,7 +3640,7 @@ TSQL tdsql; tdsql = GET_THREAD_DATA; -node = (NOD) ALLOCDV (type_nod, count); +node = new(*tdsql->tsql_default, count) nod; node->nod_type = type; node->nod_count = count; p = node->nod_arg; @@ -3675,7 +3675,7 @@ TSQL tdsql; tdsql = GET_THREAD_DATA; -node = (NOD) ALLOCDV (type_nod, count); +node = new(*tdsql->tsql_default, count) nod; node->nod_type = type; node->nod_flags = flag; node->nod_count = count; @@ -3746,7 +3746,7 @@ return !return_value; static void stack_nodes ( NOD node, - LLS *stack) + DLLS *stack) { /************************************** * diff --git a/src/dsql/pass1.cpp b/src/dsql/pass1.cpp index 570dc4a5c4..9f1339315b 100644 --- a/src/dsql/pass1.cpp +++ b/src/dsql/pass1.cpp @@ -53,7 +53,7 @@ static void assign_fld_dtype_from_dsc(FLD, DSC *); static NOD compose(NOD, NOD, NOD_TYPE); static NOD copy_field(NOD, CTX); static NOD copy_fields(NOD, CTX); -static void explode_asterisk(NOD, NOD, LLS *); +static void explode_asterisk(NOD, NOD, DLLS *); static NOD explode_outputs(REQ, PRC); static void field_error(TEXT *, TEXT *); static PAR find_dbkey(REQ, NOD); @@ -79,7 +79,7 @@ static NOD pass1_rse(REQ, NOD, NOD); static NOD pass1_sel_list(REQ, NOD); static NOD pass1_sort(REQ, NOD, NOD); static NOD pass1_udf(REQ, NOD, USHORT); -static void pass1_udf_args(REQ, NOD, LLS *, USHORT); +static void pass1_udf_args(REQ, NOD, DLLS *, USHORT); static NOD pass1_union(REQ, NOD, NOD); static NOD pass1_update(REQ, NOD); static NOD pass1_variable(REQ, NOD); @@ -120,15 +120,14 @@ CTX PASS1_make_context( REQ request, NOD relation_node) PRC procedure; FLD field; NOD *input; - LLS stack; + DLLS stack; TEXT *conflict_name; STATUS error_code; - struct nod desc_node; TSQL tdsql; USHORT count; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(relation_node, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(relation_node, dsql_type_nod); tdsql = GET_THREAD_DATA; @@ -143,7 +142,7 @@ CTX PASS1_make_context( REQ request, NOD relation_node) else relation_name = (STR) relation_node->nod_arg[e_rln_name]; - DEV_BLKCHK(relation_name, type_str); + DEV_BLKCHK(relation_name, dsql_type_str); if ((relation_node->nod_type == nod_rel_proc_name) && relation_node->nod_arg[e_rpn_inputs]) @@ -191,7 +190,7 @@ CTX PASS1_make_context( REQ request, NOD relation_node) /* Set up context block */ - context = (CTX) ALLOCD(type_ctx); + context = new(*tdsql->tsql_default) ctx; context->ctx_relation = relation; context->ctx_procedure = procedure; context->ctx_request = request; @@ -205,7 +204,7 @@ CTX PASS1_make_context( REQ request, NOD relation_node) else string = (STR) relation_node->nod_arg[e_rln_alias]; - DEV_BLKCHK(string, type_str); + DEV_BLKCHK(string, dsql_type_str); if (string) { context->ctx_alias = (TEXT *) string->str_data; @@ -244,33 +243,42 @@ CTX PASS1_make_context( REQ request, NOD relation_node) } } - if (procedure) { - if (request->req_scope_level == 1) + if (procedure) + { + if (request->req_scope_level == 1) { request->req_flags |= REQ_no_batch; + } - if (relation_node->nod_arg[e_rpn_inputs]) { + if (relation_node->nod_arg[e_rpn_inputs]) + { context->ctx_proc_inputs = PASS1_node(request, relation_node-> nod_arg[e_rpn_inputs], 0); count = context->ctx_proc_inputs->nod_count; } else + { count = 0; + } - if (!(request->req_type & REQ_procedure)) { + if (!(request->req_type & REQ_procedure)) + { if (count != procedure->prc_in_count) + { ERRD_post(gds_prcmismat, gds_arg_string, relation_name->str_data, 0); + } - if (count) { - /* Initialize this stack variable, and make it look like a node */ - memset((SCHAR *) & desc_node, 0, sizeof(desc_node)); - desc_node.nod_header.blk_type = type_nod; + if (count) + { + // Initialize this stack variable, and make it look like a node + nod desc_node; for (input = context->ctx_proc_inputs->nod_arg, field = procedure->prc_inputs; - field; input++, field = field->fld_next) { - DEV_BLKCHK(field, type_fld); - DEV_BLKCHK(*input, type_nod); + field; input++, field = field->fld_next) + { + DEV_BLKCHK(field, dsql_type_fld); + DEV_BLKCHK(*input, dsql_type_nod); MAKE_desc_from_field(&desc_node.nod_desc, field); set_parameter_type(*input, &desc_node, FALSE); } @@ -300,12 +308,12 @@ NOD PASS1_node(REQ request, NOD input, USHORT proc_flag) * **************************************/ NOD node, temp, *ptr, *end, *ptr2, rse, sub1, sub2, sub3; - LLS base; + DLLS base; FLD field; CTX agg_context; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); if (input == NULL) return NULL; @@ -327,7 +335,7 @@ NOD PASS1_node(REQ request, NOD input, USHORT proc_flag) PASS1_node(request, input->nod_arg[e_cast_source], proc_flag); node->nod_arg[e_cast_target] = input->nod_arg[e_cast_target]; field = (FLD) node->nod_arg[e_cast_target]; - DEV_BLKCHK(field, type_fld); + DEV_BLKCHK(field, dsql_type_fld); DDL_resolve_intl_type(request, field, NULL); MAKE_desc_from_field(&node->nod_desc, field); /* If the source is nullable, so is the target */ @@ -498,7 +506,7 @@ NOD PASS1_node(REQ request, NOD input, USHORT proc_flag) for (ptr = sub2->nod_arg, end = ptr + sub2->nod_count; ptr < end && list_item_count < MAX_MEMBER_LIST; list_item_count++, ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); temp = MAKE_node(input->nod_type, 2); temp->nod_arg[0] = input->nod_arg[0]; temp->nod_arg[1] = *ptr; @@ -560,6 +568,8 @@ NOD PASS1_node(REQ request, NOD input, USHORT proc_flag) case nod_lss_all: case nod_leq_all: return pass1_any(request, input, nod_ansi_all); + default: // make compiler happy + break; } } } @@ -634,9 +644,9 @@ NOD PASS1_node(REQ request, NOD input, USHORT proc_flag) ptr2 = node->nod_arg; for (ptr = input->nod_arg, end = ptr + input->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); *ptr2++ = PASS1_node(request, *ptr, proc_flag); - DEV_BLKCHK(*(ptr2 - 1), type_nod); + DEV_BLKCHK(*(ptr2 - 1), dsql_type_nod); } /* Mark relations as "possibly NULL" if they are in outer joins */ @@ -752,9 +762,9 @@ NOD PASS1_rse(REQ request, NOD input, NOD order) **************************************/ NOD node; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); - DEV_BLKCHK(order, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); + DEV_BLKCHK(order, dsql_type_nod); request->req_scope_level++; node = pass1_rse(request, input, order); @@ -778,14 +788,14 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag) **************************************/ NOD node, *ptr, *end, *ptr2, *end2, into_in, into_out, procedure, cursor, temp, parameters, variables; - LLS base; + DLLS base; FLD field, field2; STR name; struct nod desc_node; USHORT count; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); #ifdef DEV_BUILD if (DSQL_debug > 2) @@ -854,12 +864,12 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag) for (ptr = variables->nod_arg, end = ptr + variables->nod_count; ptr < end; ptr++) { field = (FLD) (*ptr)->nod_arg[e_dfl_field]; - DEV_BLKCHK(field, type_fld); + DEV_BLKCHK(field, dsql_type_fld); if (parameters = input->nod_arg[e_prc_inputs]) for (ptr2 = parameters->nod_arg, end2 = ptr2 + parameters->nod_count; ptr2 < end2; ptr2++) { field2 = (FLD) (*ptr2)->nod_arg[e_dfl_field]; - DEV_BLKCHK(field2, type_fld); + DEV_BLKCHK(field2, dsql_type_fld); if (!strcmp(field->fld_name, field2->fld_name)) ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 901, gds_arg_gds, @@ -870,7 +880,7 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag) for (ptr2 = parameters->nod_arg, end2 = ptr2 + parameters->nod_count; ptr2 < end2; ptr2++) { field2 = (FLD) (*ptr2)->nod_arg[e_dfl_field]; - DEV_BLKCHK(field2, type_fld); + DEV_BLKCHK(field2, dsql_type_fld); if (!strcmp(field->fld_name, field2->fld_name)) ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 901, gds_arg_gds, @@ -909,7 +919,7 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag) case nod_exec_procedure: if (!proc_flag) { name = (STR) input->nod_arg[e_exe_procedure]; - DEV_BLKCHK(name, type_str); + DEV_BLKCHK(name, dsql_type_str); if (!(request->req_procedure = METD_get_procedure(request, name))) ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 204, gds_arg_gds, gds_dsql_procedure_err, @@ -938,12 +948,12 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag) if (count) { /* Initialize this stack variable, and make it look like a node */ memset((SCHAR *) & desc_node, 0, sizeof(desc_node)); - desc_node.nod_header.blk_type = type_nod; + //desc_node.nod_header.blk_type = type_nod; for (ptr = node->nod_arg[e_exe_inputs]->nod_arg, field = request->req_procedure->prc_inputs; field; ptr++, field = field->fld_next) { - DEV_BLKCHK(field, type_fld); - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(field, dsql_type_fld); + DEV_BLKCHK(*ptr, dsql_type_nod); MAKE_desc_from_field(&desc_node.nod_desc, field); set_parameter_type(*ptr, &desc_node, FALSE); } @@ -972,9 +982,9 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag) ptr2 = into_out->nod_arg; for (ptr = into_in->nod_arg, end = ptr + into_in->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); *ptr2++ = PASS1_node(request, *ptr, proc_flag); - DEV_BLKCHK(*(ptr2 - 1), type_nod); + DEV_BLKCHK(*(ptr2 - 1), dsql_type_nod); } if (input->nod_arg[e_flp_action]) node->nod_arg[e_flp_action] = PASS1_statement(request, @@ -1053,12 +1063,12 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag) ptr2 = node->nod_arg; for (ptr = input->nod_arg, end = ptr + input->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); if ((*ptr)->nod_type == nod_assign) *ptr2++ = PASS1_node(request, *ptr, proc_flag); else *ptr2++ = PASS1_statement(request, *ptr, proc_flag); - DEV_BLKCHK(*(ptr2 - 1), type_nod); + DEV_BLKCHK(*(ptr2 - 1), dsql_type_nod); } if (input->nod_type == nod_block && input->nod_arg[e_blk_errs]) request->req_error_handlers--; @@ -1213,8 +1223,8 @@ static BOOLEAN aggregate_found( REQ request, NOD sub, NOD * proj) **************************************/ BOOLEAN aggregate, field; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(sub, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(sub, dsql_type_nod); field = FALSE; @@ -1249,8 +1259,8 @@ static BOOLEAN aggregate_found2( BOOLEAN aggregate; NOD *ptr, *end; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(sub, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(sub, dsql_type_nod); switch (sub->nod_type) { @@ -1300,7 +1310,7 @@ static BOOLEAN aggregate_found2( case nod_list: aggregate = FALSE; for (ptr = sub->nod_arg, end = ptr + sub->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); aggregate |= aggregate_found2(request, *ptr, proj, field); } return aggregate; @@ -1334,7 +1344,7 @@ static void assign_fld_dtype_from_dsc( FLD field, DSC * nod_desc) * **************************************/ - DEV_BLKCHK(field, type_fld); + DEV_BLKCHK(field, dsql_type_fld); field->fld_dtype = nod_desc->dsc_dtype; field->fld_scale = nod_desc->dsc_scale; @@ -1363,8 +1373,8 @@ static NOD compose( NOD expr1, NOD expr2, NOD_TYPE operator_) **************************************/ NOD node; - DEV_BLKCHK(expr1, type_nod); - DEV_BLKCHK(expr2, type_nod); + DEV_BLKCHK(expr1, dsql_type_nod); + DEV_BLKCHK(expr2, dsql_type_nod); if (!expr1) return expr2; @@ -1396,20 +1406,20 @@ static NOD copy_field( NOD field, CTX context) MAP map; STR alias; - DEV_BLKCHK(field, type_nod); - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(field, dsql_type_nod); + DEV_BLKCHK(context, dsql_type_ctx); switch (field->nod_type) { case nod_map: map = (MAP) field->nod_arg[e_map_map]; - DEV_BLKCHK(map, type_map); + DEV_BLKCHK(map, dsql_type_map); temp = map->map_node; return post_map(temp, context); case nod_alias: actual = field->nod_arg[e_alias_value]; alias = (STR) field->nod_arg[e_alias_alias]; - DEV_BLKCHK(alias, type_str); + DEV_BLKCHK(alias, dsql_type_str); temp = MAKE_node(nod_alias, e_alias_count); temp->nod_arg[e_alias_value] = copy_field(actual, context); temp->nod_arg[e_alias_alias] = (NOD) alias; @@ -1467,8 +1477,8 @@ static NOD copy_fields( NOD fields, CTX context) NOD list; USHORT i; - DEV_BLKCHK(fields, type_nod); - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(fields, dsql_type_nod); + DEV_BLKCHK(context, dsql_type_ctx); list = MAKE_node(nod_list, fields->nod_count); @@ -1479,7 +1489,7 @@ static NOD copy_fields( NOD fields, CTX context) } -static void explode_asterisk( NOD node, NOD aggregate, LLS * stack) +static void explode_asterisk( NOD node, NOD aggregate, DLLS * stack) { /************************************** * @@ -1496,8 +1506,8 @@ static void explode_asterisk( NOD node, NOD aggregate, LLS * stack) PRC procedure; FLD field; - DEV_BLKCHK(node, type_nod); - DEV_BLKCHK(aggregate, type_nod); + DEV_BLKCHK(node, dsql_type_nod); + DEV_BLKCHK(aggregate, dsql_type_nod); if (node->nod_type == nod_join) { explode_asterisk(node->nod_arg[e_join_left_rel], aggregate, stack); @@ -1505,10 +1515,10 @@ static void explode_asterisk( NOD node, NOD aggregate, LLS * stack) } else { context = (CTX) node->nod_arg[e_rel_context]; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); if (relation = context->ctx_relation) for (field = relation->rel_fields; field; field = field->fld_next) { - DEV_BLKCHK(field, type_fld); + DEV_BLKCHK(field, dsql_type_fld); node = MAKE_field(context, field, 0); if (aggregate) { if (invalid_reference @@ -1526,7 +1536,7 @@ static void explode_asterisk( NOD node, NOD aggregate, LLS * stack) } else if (procedure = context->ctx_procedure) for (field = procedure->prc_outputs; field; - field = field->fld_next) {DEV_BLKCHK(field, type_fld); + field = field->fld_next) {DEV_BLKCHK(field, dsql_type_fld); node = MAKE_field(context, field, 0); if (aggregate) { if (invalid_reference @@ -1563,15 +1573,15 @@ static NOD explode_outputs( REQ request, PRC procedure) PAR parameter; SSHORT count; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(procedure, type_prc); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(procedure, dsql_type_prc); count = procedure->prc_out_count; node = MAKE_node(nod_list, count); for (field = procedure->prc_outputs, ptr = node->nod_arg; field; field = field->fld_next, ptr++) { - DEV_BLKCHK(field, type_fld); - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(field, dsql_type_fld); + DEV_BLKCHK(*ptr, dsql_type_nod); *ptr = p_node = MAKE_node(nod_parameter, e_par_count); p_node->nod_count = 0; parameter = MAKE_parameter(request->req_receive, TRUE, TRUE); @@ -1635,18 +1645,18 @@ static PAR find_dbkey( REQ request, NOD relation_name) DSQL_REL relation; STR rel_name; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(relation_name, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(relation_name, dsql_type_nod); message = request->req_receive; candidate = NULL; rel_name = (STR) relation_name->nod_arg[e_rln_name]; - DEV_BLKCHK(rel_name, type_str); + DEV_BLKCHK(rel_name, dsql_type_str); for (parameter = message->msg_parameters; parameter; parameter = parameter->par_next) { - DEV_BLKCHK(parameter, type_par); + DEV_BLKCHK(parameter, dsql_type_par); if (context = parameter->par_dbkey_ctx) { - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); relation = context->ctx_relation; if (!strcmp (reinterpret_cast < char *>(rel_name->str_data), @@ -1680,18 +1690,18 @@ static PAR find_record_version( REQ request, NOD relation_name) DSQL_REL relation; STR rel_name; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(relation_name, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(relation_name, dsql_type_nod); message = request->req_receive; candidate = NULL; rel_name = (STR) relation_name->nod_arg[e_rln_name]; - DEV_BLKCHK(rel_name, type_str); + DEV_BLKCHK(rel_name, dsql_type_str); for (parameter = message->msg_parameters; parameter; parameter = parameter->par_next) { - DEV_BLKCHK(parameter, type_par); + DEV_BLKCHK(parameter, dsql_type_par); if (context = parameter->par_rec_version_ctx) { - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); relation = context->ctx_relation; if (!strcmp (reinterpret_cast < char *>(rel_name->str_data), @@ -1732,8 +1742,8 @@ static BOOLEAN invalid_reference( NOD node, NOD list) NOD *ptr, *end; BOOLEAN invalid; - DEV_BLKCHK(node, type_nod); - DEV_BLKCHK(list, type_nod); + DEV_BLKCHK(node, dsql_type_nod); + DEV_BLKCHK(list, dsql_type_nod); if (node == NULL) { @@ -1753,19 +1763,19 @@ static BOOLEAN invalid_reference( NOD node, NOD list) field = (FLD) node->nod_arg[e_fld_field]; context = (CTX) node->nod_arg[e_fld_context]; - DEV_BLKCHK(field, type_fld); - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(field, dsql_type_fld); + DEV_BLKCHK(context, dsql_type_ctx); for (ptr = list->nod_arg, end = ptr + list->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); reference = *ptr; if ((*ptr)->nod_type == nod_cast) { reference = (*ptr)->nod_arg[e_cast_source]; } - DEV_BLKCHK(reference, type_nod); + DEV_BLKCHK(reference, dsql_type_nod); if (reference->nod_type == nod_field && field == (FLD) reference->nod_arg[e_fld_field] && context == (CTX) reference->nod_arg[e_fld_context]) @@ -1792,18 +1802,18 @@ static BOOLEAN invalid_reference( NOD node, NOD list) rel_node = (NOD) node->nod_arg[0]; context = (CTX) rel_node->nod_arg[0]; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); for (ptr = list->nod_arg, end = ptr + list->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); reference = *ptr; if ((*ptr)->nod_type == nod_cast) { reference = (*ptr)->nod_arg[e_cast_source]; } - DEV_BLKCHK(reference, type_nod); + DEV_BLKCHK(reference, dsql_type_nod); if (reference->nod_type == nod_dbkey && rel_node == (NOD) reference->nod_arg[0] && context == (CTX) rel_node->nod_arg[0]) @@ -1834,7 +1844,7 @@ static BOOLEAN invalid_reference( NOD node, NOD list) { MAP map; map = (MAP) node->nod_arg[e_map_map]; - DEV_BLKCHK(map, type_map); + DEV_BLKCHK(map, dsql_type_map); invalid |= invalid_reference(map->map_node, list); } #endif @@ -1952,12 +1962,12 @@ static void mark_ctx_outer_join( NOD node) **************************************/ CTX context; - DEV_BLKCHK(node, type_nod); + DEV_BLKCHK(node, dsql_type_nod); switch (node->nod_type) { case nod_relation: context = (CTX) node->nod_arg[e_rel_context]; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); assert(context); context->ctx_flags |= CTX_outer_join; break; @@ -1991,8 +2001,8 @@ static BOOLEAN node_match( NOD node1, NOD node2) USHORT l; UCHAR *p1, *p2; - DEV_BLKCHK(node1, type_nod); - DEV_BLKCHK(node2, type_nod); + DEV_BLKCHK(node1, dsql_type_nod); + DEV_BLKCHK(node2, dsql_type_nod); if ((!node1) && (!node2)) return TRUE; @@ -2070,8 +2080,8 @@ static BOOLEAN node_match( NOD node1, NOD node2) { map1 = (MAP)node1->nod_arg[e_map_map]; map2 = (MAP)node2->nod_arg[e_map_map]; - DEV_BLKCHK(map1, type_map); - DEV_BLKCHK(map2, type_map); + DEV_BLKCHK(map1, dsql_type_map); + DEV_BLKCHK(map2, dsql_type_map); return node_match(map1->map_node, map2->map_node); } @@ -2110,8 +2120,8 @@ static BOOLEAN node_match( NOD node1, NOD node2) } VAR var1 = reinterpret_cast(node1->nod_arg[e_var_variable]); VAR var2 = reinterpret_cast(node2->nod_arg[e_var_variable]); - DEV_BLKCHK(var1, type_var); - DEV_BLKCHK(var2, type_var); + DEV_BLKCHK(var1, dsql_type_var); + DEV_BLKCHK(var2, dsql_type_var); if ((strcmp(var1->var_name, var2->var_name)) || (var1->var_field != var2->var_field) || (var1->var_variable_number != var2->var_variable_number) || @@ -2147,10 +2157,10 @@ static NOD pass1_any( REQ request, NOD input, NOD_TYPE ntype) * **************************************/ NOD node, temp, rse, select; - LLS base; + DLLS base; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); select = input->nod_arg[1]; base = request->req_context; @@ -2197,8 +2207,8 @@ static void pass1_blob( REQ request, NOD input) PAR parameter; TSQL tdsql; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); tdsql = GET_THREAD_DATA; @@ -2212,10 +2222,10 @@ static void pass1_blob( REQ request, NOD input) request->req_type = (input->nod_type == nod_get_segment) ? REQ_GET_SEGMENT : REQ_PUT_SEGMENT; - request->req_blob = blob = (BLB) ALLOCDV(type_blb, 0); + request->req_blob = blob = new(*tdsql->tsql_default) blb; blob->blb_field = field; blob->blb_open_in_msg = request->req_send; - blob->blb_open_out_msg = (MSG) ALLOCD(type_msg); + blob->blb_open_out_msg = new(*tdsql->tsql_default) msg; blob->blb_segment_msg = request->req_receive; /* Create a parameter for the blob segment */ @@ -2226,7 +2236,7 @@ static void pass1_blob( REQ request, NOD input) parameter->par_desc.dsc_ttype = ttype_binary; parameter->par_desc.dsc_length = ((FLD) field->nod_arg[e_fld_field])->fld_seg_length; - DEV_BLKCHK(field->nod_arg[e_fld_field], type_fld); + DEV_BLKCHK(field->nod_arg[e_fld_field], dsql_type_fld); /* The Null indicator is used to pass back the segment length, * set DSC_nullable so that the SQL_type is set to SQL_TEXT+1 instead @@ -2287,15 +2297,15 @@ static NOD pass1_collate( REQ request, NOD sub1, STR collation) FLD field; TSQL tdsql; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(sub1, type_nod); - DEV_BLKCHK(collation, type_str); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(sub1, dsql_type_nod); + DEV_BLKCHK(collation, dsql_type_str); tdsql = GET_THREAD_DATA; node = MAKE_node(nod_cast, e_cast_count); - field = (FLD) ALLOCDV(type_fld, 1); + field = new(*tdsql->tsql_default, 1) fld; field->fld_name[0] = 0; node->nod_arg[e_cast_target] = (NOD) field; node->nod_arg[e_cast_source] = sub1; @@ -2334,13 +2344,13 @@ static NOD pass1_constant( REQ request, NOD constant) INTLSYM resolved; INTLSYM resolved_collation = NULL; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(constant, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(constant, dsql_type_nod); if (constant->nod_desc.dsc_dtype > dtype_any_text) return constant; string = (STR) constant->nod_arg[0]; - DEV_BLKCHK(string, type_str); + DEV_BLKCHK(string, dsql_type_str); if (!string || !string->str_charset) return constant; resolved = @@ -2390,14 +2400,14 @@ static NOD pass1_cursor( REQ request, NOD cursor, NOD relation_name) STR string; PAR parameter, source, rv_source; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(cursor, type_nod); - DEV_BLKCHK(relation_name, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(cursor, dsql_type_nod); + DEV_BLKCHK(relation_name, dsql_type_nod); /* Lookup parent request */ string = (STR) cursor->nod_arg[e_cur_name]; - DEV_BLKCHK(string, type_str); + DEV_BLKCHK(string, dsql_type_str); symbol = HSHD_lookup(request->req_dbb, @@ -2482,20 +2492,20 @@ static CTX pass1_cursor_context( REQ request, NOD cursor, NOD relation_name) STR string, cname, rname; DSQL_REL relation; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(cursor, type_nod); - DEV_BLKCHK(relation_name, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(cursor, dsql_type_nod); + DEV_BLKCHK(relation_name, dsql_type_nod); string = (STR) cursor->nod_arg[e_cur_name]; - DEV_BLKCHK(string, type_str); + DEV_BLKCHK(string, dsql_type_str); procedure = request->req_ddl_node; context = NULL; for (node = procedure->nod_arg[e_prc_cursors]; node; node = node->nod_arg[e_cur_next]) { - DEV_BLKCHK(node, type_nod); + DEV_BLKCHK(node, dsql_type_nod); cname = (STR) node->nod_arg[e_cur_name]; - DEV_BLKCHK(cname, type_str); + DEV_BLKCHK(cname, dsql_type_str); if (!strcmp (reinterpret_cast < const char *>(string->str_data), reinterpret_cast < const char *>(cname->str_data))) { @@ -2504,14 +2514,14 @@ static CTX pass1_cursor_context( REQ request, NOD cursor, NOD relation_name) temp = temp->nod_arg[e_rse_streams]; for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); r_node = *ptr; if (r_node->nod_type == nod_relation) { candidate = (CTX) r_node->nod_arg[e_rel_context]; - DEV_BLKCHK(candidate, type_ctx); + DEV_BLKCHK(candidate, dsql_type_ctx); relation = candidate->ctx_relation; rname = (STR) relation_name->nod_arg[e_rln_name]; - DEV_BLKCHK(rname, type_str); + DEV_BLKCHK(rname, dsql_type_str); if (!strcmp (reinterpret_cast < const char *>(rname->str_data), relation->rel_name)) { @@ -2551,20 +2561,20 @@ static NOD pass1_dbkey( REQ request, NOD input) **************************************/ NOD node, rel_node; STR qualifier; - LLS stack; + DLLS stack; CTX context; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); if (!(qualifier = (STR) input->nod_arg[0])) { - DEV_BLKCHK(qualifier, type_str); + DEV_BLKCHK(qualifier, dsql_type_str); /* No qualifier, if only one context then use, else error */ if ((stack = request->req_context) && !stack->lls_next) { context = (CTX) stack->lls_object; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); node = MAKE_node(nod_dbkey, 1); rel_node = MAKE_node(nod_relation, e_rel_count); rel_node->nod_arg[0] = (NOD) context; @@ -2576,7 +2586,7 @@ static NOD pass1_dbkey( REQ request, NOD input) for (stack = request->req_context; stack; stack = stack->lls_next) { context = (CTX) stack->lls_object; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); if ((!(context->ctx_relation) || strcmp(reinterpret_cast < const char *>(qualifier->str_data), context->ctx_relation->rel_name)) && @@ -2617,8 +2627,8 @@ static NOD pass1_delete( REQ request, NOD input) **************************************/ NOD rse, node, temp, cursor, relation; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); cursor = input->nod_arg[e_del_cursor]; relation = input->nod_arg[e_del_relation]; @@ -2671,11 +2681,11 @@ static NOD pass1_field( REQ request, NOD input, USHORT list) NOD node, indices; STR name, qualifier; FLD field; - LLS stack; + DLLS stack; CTX context; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); /* handle an array element */ @@ -2694,8 +2704,8 @@ static NOD pass1_field( REQ request, NOD input, USHORT list) name = (STR) input->nod_arg[1]; qualifier = (STR) input->nod_arg[0]; } - DEV_BLKCHK(name, type_str); - DEV_BLKCHK(qualifier, type_str); + DEV_BLKCHK(name, dsql_type_str); + DEV_BLKCHK(qualifier, dsql_type_str); /* Try to resolve field against various contexts; if there is an alias, check only against the first matching */ @@ -2790,10 +2800,10 @@ static NOD pass1_insert( REQ request, NOD input) FLD field; DSQL_REL relation; CTX context; - LLS stack; + DLLS stack; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); request->req_type = REQ_INSERT; node = MAKE_node(nod_store, e_sto_count); @@ -2812,7 +2822,7 @@ static NOD pass1_insert( REQ request, NOD input) node->nod_arg[e_sto_relation] = temp = pass1_relation(request, input->nod_arg[e_ins_relation]); context = (CTX) temp->nod_arg[0]; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); relation = context->ctx_relation; /* If there isn't a field list, generate one */ @@ -2837,8 +2847,8 @@ static NOD pass1_insert( REQ request, NOD input) for (ptr = fields->nod_arg, end = ptr + fields->nod_count, ptr2 = values->nod_arg; ptr < end; ptr++, ptr2++) { - DEV_BLKCHK(*ptr, type_nod); - DEV_BLKCHK(*ptr2, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); + DEV_BLKCHK(*ptr2, dsql_type_nod); temp = MAKE_node(nod_assign, 2); temp->nod_arg[0] = *ptr2; temp->nod_arg[1] = *ptr; @@ -2871,8 +2881,8 @@ static NOD pass1_relation( REQ request, NOD input) **************************************/ NOD node; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); node = MAKE_node(nod_relation, e_rel_count); @@ -2905,12 +2915,12 @@ static NOD pass1_alias_list( REQ request, NOD alias_list) NOD *arg, *end; USHORT alias_length; TEXT *p, *q; - LLS stack; + DLLS stack; STR alias; TSQL tdsql; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(alias_list, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(alias_list, dsql_type_nod); tdsql = GET_THREAD_DATA; @@ -2965,7 +2975,7 @@ static NOD pass1_alias_list( REQ request, NOD alias_list) /* make up a dummy context to hold the resultant relation */ - new_context = (CTX) ALLOCD(type_ctx); + new_context = new(*tdsql->tsql_default) ctx; new_context->ctx_context = context->ctx_context; new_context->ctx_relation = relation; @@ -2974,16 +2984,16 @@ static NOD pass1_alias_list( REQ request, NOD alias_list) alias_length = alias_list->nod_count; for (arg = alias_list->nod_arg; arg < end; arg++) { - DEV_BLKCHK(*arg, type_str); + DEV_BLKCHK(*arg, dsql_type_str); alias_length += static_cast < USHORT > (((STR) * arg)->str_length); } - alias = (STR) ALLOCDV(type_str, alias_length); + alias = new(*tdsql->tsql_default, alias_length) str; alias->str_length = alias_length; p = new_context->ctx_alias = (TEXT *) alias->str_data; for (arg = alias_list->nod_arg; arg < end; arg++) { - DEV_BLKCHK(*arg, type_str); + DEV_BLKCHK(*arg, dsql_type_str); for (q = (TEXT *) ((STR) * arg)->str_data; *q;) *p++ = *q++; *p++ = ' '; @@ -3010,11 +3020,11 @@ static CTX pass1_alias( REQ request, STR alias) * proper context. * **************************************/ - LLS stack; + DLLS stack; CTX context, relation_context = NULL; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(alias, type_str); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(alias, dsql_type_str); /* look through all contexts at this scope level to find one that has a relation name or alias @@ -3068,9 +3078,9 @@ static DSQL_REL pass1_base_table( REQ request, DSQL_REL relation, STR alias) * **************************************/ - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(relation, type_dsql_rel); - DEV_BLKCHK(alias, type_str); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(relation, dsql_type_dsql_rel); + DEV_BLKCHK(alias, dsql_type_str); return METD_get_view_relation(request, reinterpret_cast < @@ -3095,13 +3105,13 @@ static NOD pass1_rse( REQ request, NOD input, NOD order) **************************************/ NOD rse, parent_rse, target_rse, aggregate, node, list, sub, *ptr, *end, proj; - LLS stack; + DLLS stack; CTX parent_context; TSQL tdsql; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); - DEV_BLKCHK(order, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); + DEV_BLKCHK(order, dsql_type_nod); tdsql = GET_THREAD_DATA; @@ -3135,14 +3145,14 @@ static NOD pass1_rse( REQ request, NOD input, NOD order) sub = sub->nod_arg[e_alias_value]; if (aggregate_found(request, sub, &proj)) { - parent_context = (CTX) ALLOCD(type_ctx); + parent_context = new(*tdsql->tsql_default) ctx; break; } } if (!parent_context && (input->nod_arg[e_sel_group] || input->nod_arg[e_sel_having])) - parent_context = (CTX) ALLOCD(type_ctx); + parent_context = new(*tdsql->tsql_default) ctx; if (parent_context) { parent_context->ctx_context = request->req_context_number++; @@ -3282,10 +3292,10 @@ static NOD pass1_sel_list( REQ request, NOD input) * **************************************/ NOD node, *ptr, *end, frnode; - LLS stack; + DLLS stack; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); /* For each node in the list, if it's a field node, see if it's of @@ -3295,7 +3305,7 @@ static NOD pass1_sel_list( REQ request, NOD input) stack = NULL; for (ptr = input->nod_arg, end = ptr + input->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); if ((*ptr)->nod_type == nod_field_name) { /* check for field or relation node */ @@ -3330,9 +3340,9 @@ static NOD pass1_sort( REQ request, NOD input, NOD s_list) NOD node, *ptr, *end, *ptr2, node1, node2; ULONG position; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); - DEV_BLKCHK(s_list, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); + DEV_BLKCHK(s_list, dsql_type_nod); if (input->nod_type != nod_list) ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 104, @@ -3345,7 +3355,7 @@ static NOD pass1_sort( REQ request, NOD input, NOD s_list) ptr2 = node->nod_arg; for (ptr = input->nod_arg, end = ptr + input->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); node1 = *ptr; if (node1->nod_type != nod_order) ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 104, @@ -3375,7 +3385,7 @@ static NOD pass1_sort( REQ request, NOD input, NOD s_list) 0); if ((*ptr)->nod_arg[e_order_collate]) { - DEV_BLKCHK((*ptr)->nod_arg[e_order_collate], type_str); + DEV_BLKCHK((*ptr)->nod_arg[e_order_collate], dsql_type_str); node2->nod_arg[0] = pass1_collate(request, node2->nod_arg[0], (STR) (*ptr)->nod_arg[e_order_collate]); @@ -3402,13 +3412,13 @@ static NOD pass1_udf( REQ request, NOD input, USHORT proc_flag) STR name; UDF udf; NOD node; - LLS stack; + DLLS stack; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); name = (STR) input->nod_arg[0]; - DEV_BLKCHK(name, type_str); + DEV_BLKCHK(name, dsql_type_str); udf = METD_get_function(request, name); if (!udf) ERRD_post(gds_sqlerr, gds_arg_number, (SLONG) - 804, @@ -3430,7 +3440,7 @@ static NOD pass1_udf( REQ request, NOD input, USHORT proc_flag) static void pass1_udf_args( REQ request, - NOD input, LLS * stack, USHORT proc_flag) + NOD input, DLLS * stack, USHORT proc_flag) { /************************************** * @@ -3444,8 +3454,8 @@ static void pass1_udf_args( **************************************/ NOD *ptr, *end; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); if (input->nod_type != nod_list) { LLS_PUSH(PASS1_node(request, input, proc_flag), stack); @@ -3475,16 +3485,16 @@ static NOD pass1_union( REQ request, NOD input, NOD order_list) NOD map_node, *ptr, *end, items, union_node, *uptr, nod1; NOD union_rse, union_items, order1, order2, sort, position; CTX union_context; - MAP map; + MAP map_; SSHORT count = 0; ULONG number; SSHORT i, j; /* for-loop counters */ TSQL tdsql; - LLS base; + DLLS base; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); - DEV_BLKCHK(order_list, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); + DEV_BLKCHK(order_list, dsql_type_nod); tdsql = GET_THREAD_DATA; @@ -3516,7 +3526,7 @@ static NOD pass1_union( REQ request, NOD input, NOD order_list) /* generate a context for the union itself */ - union_context = (CTX) ALLOCDV(type_ctx, 0); + union_context = new(*tdsql->tsql_default) ctx; union_context->ctx_context = request->req_context_number++; /* generate the list of fields to select */ @@ -3573,15 +3583,15 @@ static NOD pass1_union( REQ request, NOD input, NOD order_list) ptr < end; ptr++) { *ptr = map_node = MAKE_node(nod_map, e_map_count); map_node->nod_arg[e_map_context] = (NOD) union_context; - map = (MAP) ALLOCD(type_map); - map_node->nod_arg[e_map_map] = (NOD) map; + map_ = new(*tdsql->tsql_default) map; + map_node->nod_arg[e_map_map] = (NOD) map_; /* set up the MAP between the sub-rses and the union context */ - map->map_position = count++; - map->map_node = *uptr++; - map->map_next = union_context->ctx_map; - union_context->ctx_map = map; + map_->map_position = count++; + map_->map_node = *uptr++; + map_->map_next = union_context->ctx_map; + union_context->ctx_map = map_; } union_rse->nod_arg[e_rse_items] = union_items; @@ -3637,8 +3647,8 @@ static NOD pass1_update( REQ request, NOD input) **************************************/ NOD rse, node, temp, relation, cursor; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); cursor = input->nod_arg[e_upd_cursor]; relation = input->nod_arg[e_upd_relation]; @@ -3700,8 +3710,8 @@ static NOD pass1_variable( REQ request, NOD input) VAR var; SSHORT position; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(input, type_nod); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(input, dsql_type_nod); if (input->nod_type == nod_field_name) { if (input->nod_arg[e_fln_context]) { @@ -3714,7 +3724,7 @@ static NOD pass1_variable( REQ request, NOD input) } else var_name = (STR) input->nod_arg[e_vrn_name]; - DEV_BLKCHK(var_name, type_str); + DEV_BLKCHK(var_name, dsql_type_str); if ((procedure_node = request->req_ddl_node) && (procedure_node->nod_type == nod_def_procedure || @@ -3731,7 +3741,7 @@ static NOD pass1_variable( REQ request, NOD input) ptr + var_nodes->nod_count; ptr < end; ptr++, position++) { var_node = *ptr; var = (VAR) var_node->nod_arg[e_var_variable]; - DEV_BLKCHK(var, type_var); + DEV_BLKCHK(var, dsql_type_var); if (!strcmp (reinterpret_cast < const char *>(var_name->str_data), var->var_name)) return var_node; @@ -3741,7 +3751,7 @@ static NOD pass1_variable( REQ request, NOD input) ptr + var_nodes->nod_count; ptr < end; ptr++, position++) { var_node = *ptr; var = (VAR) var_node->nod_arg[e_var_variable]; - DEV_BLKCHK(var, type_var); + DEV_BLKCHK(var, dsql_type_var); if (!strcmp (reinterpret_cast < const char *>(var_name->str_data), var->var_name)) return var_node; @@ -3756,7 +3766,7 @@ static NOD pass1_variable( REQ request, NOD input) ptr + var_nodes->nod_count; ptr < end; ptr++, position++) { var_node = *ptr; var = (VAR) var_node->nod_arg[e_var_variable]; - DEV_BLKCHK(var, type_var); + DEV_BLKCHK(var, dsql_type_var); if (!strcmp (reinterpret_cast < const char *>(var_name->str_data), var->var_name)) return var_node; @@ -3784,33 +3794,33 @@ static NOD post_map( NOD node, CTX context) * **************************************/ NOD new_node; - MAP map; + MAP map_; USHORT count; TSQL tdsql; - DEV_BLKCHK(node, type_nod); - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(node, dsql_type_nod); + DEV_BLKCHK(context, dsql_type_ctx); tdsql = GET_THREAD_DATA; /* Check to see if the item has already been posted */ - for (map = context->ctx_map, count = 0; map; map = map->map_next, count++) - if (node_match(node, map->map_node)) + for (map_ = context->ctx_map, count = 0; map_; map_ = map_->map_next, count++) + if (node_match(node, map_->map_node)) break; - if (!map) { - map = (MAP) ALLOCD(type_map); - map->map_position = count; - map->map_next = context->ctx_map; - context->ctx_map = map; - map->map_node = node; + if (!map_) { + map_ = new(*tdsql->tsql_default) map; + map_->map_position = count; + map_->map_next = context->ctx_map; + context->ctx_map = map_; + map_->map_node = node; } new_node = MAKE_node(nod_map, e_map_count); new_node->nod_count = 0; new_node->nod_arg[e_map_context] = (NOD) context; - new_node->nod_arg[e_map_map] = (NOD) map; + new_node->nod_arg[e_map_map] = (NOD) map_; new_node->nod_desc = node->nod_desc; return new_node; @@ -3834,8 +3844,8 @@ static void remap_streams_to_parent_context( NOD input, CTX parent_context) CTX context; NOD *ptr, *end; - DEV_BLKCHK(input, type_nod); - DEV_BLKCHK(parent_context, type_ctx); + DEV_BLKCHK(input, dsql_type_nod); + DEV_BLKCHK(parent_context, dsql_type_ctx); switch (input->nod_type) { case nod_list: @@ -3846,7 +3856,7 @@ static void remap_streams_to_parent_context( NOD input, CTX parent_context) case nod_relation: context = (CTX) input->nod_arg[e_rel_context]; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); context->ctx_parent = parent_context; break; @@ -3883,10 +3893,10 @@ static FLD resolve_context( REQ request, STR name, STR qualifier, CTX context) FLD field; TEXT *table_name; - DEV_BLKCHK(request, type_req); - DEV_BLKCHK(name, type_str); - DEV_BLKCHK(qualifier, type_str); - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(name, dsql_type_str); + DEV_BLKCHK(qualifier, dsql_type_str); + DEV_BLKCHK(context, dsql_type_ctx); relation = context->ctx_relation; procedure = context->ctx_procedure; @@ -3943,8 +3953,8 @@ static BOOLEAN set_parameter_type( PAR parameter; BOOLEAN result = 0; - DEV_BLKCHK(in_node, type_nod); - DEV_BLKCHK(node, type_nod); + DEV_BLKCHK(in_node, dsql_type_nod); + DEV_BLKCHK(node, dsql_type_nod); if (in_node == NULL) return FALSE; @@ -3953,7 +3963,7 @@ static BOOLEAN set_parameter_type( case nod_parameter: MAKE_desc(&in_node->nod_desc, node); parameter = (PAR) in_node->nod_arg[e_par_parameter]; - DEV_BLKCHK(parameter, type_par); + DEV_BLKCHK(parameter, dsql_type_par); parameter->par_desc = in_node->nod_desc; parameter->par_node = in_node; @@ -4032,16 +4042,16 @@ static void set_parameters_name( NOD list_node, NOD rel_node) CTX context; DSQL_REL relation; - DEV_BLKCHK(list_node, type_nod); - DEV_BLKCHK(rel_node, type_nod); + DEV_BLKCHK(list_node, dsql_type_nod); + DEV_BLKCHK(rel_node, dsql_type_nod); context = (CTX) rel_node->nod_arg[0]; - DEV_BLKCHK(context, type_ctx); + DEV_BLKCHK(context, dsql_type_ctx); relation = context->ctx_relation; for (ptr = list_node->nod_arg, end = ptr + list_node->nod_count; ptr < end; ptr++) { - DEV_BLKCHK(*ptr, type_nod); + DEV_BLKCHK(*ptr, dsql_type_nod); if ((*ptr)->nod_type == nod_assign) set_parameter_name((*ptr)->nod_arg[0], (*ptr)->nod_arg[1], relation); @@ -4075,9 +4085,9 @@ static void set_parameter_name( NOD par_node, NOD fld_node, DSQL_REL relation) PAR parameter; FLD field; - DEV_BLKCHK(par_node, type_nod); - DEV_BLKCHK(fld_node, type_nod); - DEV_BLKCHK(relation, type_dsql_rel); + DEV_BLKCHK(par_node, dsql_type_nod); + DEV_BLKCHK(fld_node, dsql_type_nod); + DEV_BLKCHK(relation, dsql_type_dsql_rel); /* Could it be something else ??? */ assert(fld_node->nod_type == nod_field); @@ -4088,9 +4098,9 @@ static void set_parameter_name( NOD par_node, NOD fld_node, DSQL_REL relation) switch (par_node->nod_type) { case nod_parameter: parameter = (PAR) par_node->nod_arg[e_par_parameter]; - DEV_BLKCHK(parameter, type_par); + DEV_BLKCHK(parameter, dsql_type_par); field = (FLD) fld_node->nod_arg[e_fld_field]; - DEV_BLKCHK(field, type_fld); + DEV_BLKCHK(field, dsql_type_fld); parameter->par_name = field->fld_name; parameter->par_rel_name = relation->rel_name; return; diff --git a/src/dsql/sqlda.h b/src/dsql/sqlda.h index 7df9877478..eb40ca481c 100644 --- a/src/dsql/sqlda.h +++ b/src/dsql/sqlda.h @@ -42,7 +42,6 @@ #include "../include/fb_types.h" #endif - typedef struct { SSHORT sqltype; diff --git a/src/dsql/sym.h b/src/dsql/sym.h index 5cf25f2dec..f2b3f19346 100644 --- a/src/dsql/sym.h +++ b/src/dsql/sym.h @@ -39,8 +39,8 @@ typedef ENUM sym_type { /* symbol block */ -typedef struct sym { - struct blk sym_header; +class sym : public pool_alloc_rpt { +public: void *sym_dbb; /* generic DB structure handle */ TEXT *sym_string; /* address of asciz string */ USHORT sym_length; /* length of string (exc. term.) */ @@ -51,6 +51,7 @@ typedef struct sym { struct sym *sym_homonym; /* homonym pointer */ TEXT sym_name[2]; /* space for name, if necessary */ USHORT sym_version; /* dialect version the symbol was introduced */ -} *SYM; +}; +typedef sym *SYM; #endif /* _DSQL_SYM_H_ */ diff --git a/src/dsql/user_dsql.cpp b/src/dsql/user_dsql.cpp index 4cff104456..38b02d5262 100644 --- a/src/dsql/user_dsql.cpp +++ b/src/dsql/user_dsql.cpp @@ -654,9 +654,7 @@ STATUS API_ROUTINE isc_embed_dsql_prepare(STATUS* user_status, init(db_handle); set_global_private_status(user_status, local_status); - if (SETJMP(UDSQL_error->dsql_env)) { - return error(); - } + try { NAME name = lookup_name(stmt_name, statement_names); @@ -708,7 +706,7 @@ STATUS API_ROUTINE isc_embed_dsql_prepare(STATUS* user_status, if (!statement) { - statement = (STMT) gds__alloc((SLONG) sizeof(struct stmt)); + statement = (STMT) gds__alloc((SLONG) sizeof(stmt)); /* FREE: by user calling isc_embed_dsql_release() */ if (!statement) /* NOMEM: */ error_post(isc_virmemexh, 0); @@ -731,6 +729,13 @@ STATUS API_ROUTINE isc_embed_dsql_prepare(STATUS* user_status, statement->stmt_cursor = NULL; return s; + + } // try + catch (...) + { + return error(); + } + } @@ -1437,7 +1442,7 @@ static void error_post(STATUS status, ...) // Give up whatever we were doing and return to the user. - LONGJMP(UDSQL_error->dsql_env, (int) UDSQL_error->dsql_status[1]); + Firebird::status_longjmp_error::raise(UDSQL_error->dsql_status[1]); } @@ -1450,7 +1455,7 @@ static void init(HNDL* db_handle) // If we haven't been initialized yet, do it now if (!init_flag) { - UDSQL_error = (ERR) gds__alloc((SLONG) sizeof(struct err)); + UDSQL_error = (ERR) gds__alloc((SLONG) sizeof(err)); // FREE: by exit cleanup() if (!UDSQL_error) { // NOMEM: return; // Don't set the init_flag @@ -1470,7 +1475,7 @@ static void init(HNDL* db_handle) } } - dbb = (DBB) gds__alloc((SLONG) sizeof(struct dbb)); + dbb = (DBB) gds__alloc((SLONG) sizeof(dbb)); // FREE: by database exit handler cleanup_database() if (!dbb) { // NOMEM @@ -1506,7 +1511,7 @@ static NAME insert_name( TEXT * symbol, NAME* list_ptr, STMT stmt) TEXT *p; l = name_length(symbol); - name = (NAME) gds__alloc((SLONG) sizeof(struct name) + l); + name = (NAME) gds__alloc((SLONG) sizeof(name) + l); /* FREE: by exit handler cleanup() or database_cleanup() */ if (!name) /* NOMEM: */ error_post(gds_virmemexh, 0); diff --git a/src/dsql/utld.cpp b/src/dsql/utld.cpp index 14fa30cde2..3c2fac6625 100644 --- a/src/dsql/utld.cpp +++ b/src/dsql/utld.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: utld.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +$Id: utld.cpp,v 1.3 2001-12-24 02:50:48 tamlin Exp $ */ #include "firebird.h" diff --git a/src/dudley/ddl.cpp b/src/dudley/ddl.cpp index edcd4fb29d..1b8f0493e5 100644 --- a/src/dudley/ddl.cpp +++ b/src/dudley/ddl.cpp @@ -110,7 +110,7 @@ static struct in_sw_tab_t gdef_in_sw_table[] = { IN_SW_GDEF_0, 0, NULL, 0, 0, 0, FALSE, 0, 0, NULL }; - +#ifndef SUPERSERVER int CLIB_ROUTINE main( int argc, char *argv[]) { /************************************** @@ -475,7 +475,7 @@ int CLIB_ROUTINE main( int argc, char *argv[]) DDL_exit(FINI_OK); } - +#endif UCHAR *DDL_alloc(register int size) { diff --git a/src/dudley/expand.cpp b/src/dudley/expand.cpp index 0318533203..162917ce0d 100644 --- a/src/dudley/expand.cpp +++ b/src/dudley/expand.cpp @@ -103,8 +103,7 @@ static void expand_action( ACT action) /* Set up an environment to catch syntax errors. If one occurs, scan looking for semi-colon to continue processing. */ - if (setjmp(exp_env)) - return; + try { DDL_line = action->act_line; @@ -192,6 +191,11 @@ static void expand_action( ACT action) default: DDL_msg_put(97, NULL, NULL, NULL, NULL, NULL); /* msg 97: object can not be resolved */ } + + } // try + catch (...) { + } + return; } @@ -213,7 +217,7 @@ static void expand_error( **************************************/ DDL_err(number, arg1, arg2, arg3, arg4, arg5); - longjmp(exp_env, TRUE); + Firebird::status_longjmp_error::raise(TRUE); } diff --git a/src/dudley/parse.cpp b/src/dudley/parse.cpp index aaa1c86a01..776de7aeae 100644 --- a/src/dudley/parse.cpp +++ b/src/dudley/parse.cpp @@ -196,7 +196,7 @@ void PARSE_error( USHORT number, TEXT * arg1, TEXT * arg2) **************************************/ DDL_err(number, arg1, arg2, NULL, NULL, NULL); - longjmp(parse_env, TRUE); + Firebird::status_longjmp_error::raise(TRUE); } @@ -2988,14 +2988,7 @@ static BOOLEAN parse_action(void) /* Set up an environment to catch syntax errors. If one occurs, scan looking for semi-colon to continue processing. */ - if (setjmp(parse_env)) { - if (DDL_interactive) - LEX_flush(); - else - while (!DDL_eof && !KEYWORD(KW_SEMI)) - LEX_token(); - return TRUE; - } + try { DDL_prompt = PROMPT; LEX_token(); @@ -3154,6 +3147,16 @@ static BOOLEAN parse_action(void) PARSE_error(186, DDL_token.tok_string, 0); /* msg 186: expected command, encountered \"%s\" */ return FALSE; + + } // try + catch (...) { + if (DDL_interactive) + LEX_flush(); + else + while (!DDL_eof && !KEYWORD(KW_SEMI)) + LEX_token(); + return TRUE; + } } diff --git a/src/extlib/ib_udf.sql b/src/extlib/ib_udf.sql index e98610354d..872bff428f 100644 --- a/src/extlib/ib_udf.sql +++ b/src/extlib/ib_udf.sql @@ -15,7 +15,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: ib_udf.sql,v 1.1.1.1 2001-05-23 13:25:38 tamlin Exp $ + * $Id: ib_udf.sql,v 1.2 2001-12-24 02:50:48 tamlin Exp $ * Revision 1.2 2000/11/28 06:47:52 fsg * Changed declaration of ascii_char in ib_udf.sql * to get correct result as proposed by Claudio Valderrama diff --git a/src/extlib/ib_util.c b/src/extlib/ib_util.c index d241ceef5d..fb58e93ca4 100644 --- a/src/extlib/ib_util.c +++ b/src/extlib/ib_util.c @@ -16,11 +16,11 @@ * All Rights Reserved. * Contributor(s): ______________________________________. */ -#include "../include/fb_config.h" +#include "../include/firebird.h" #include #include "ib_udf.h" -void *EXPORT ib_util_malloc( long size) +void* EXPORT ib_util_malloc(long size) { return malloc(size); } diff --git a/src/fbutil/FirebirdConfig.cpp b/src/fbutil/FirebirdConfig.cpp index db6c4cd1c1..c55ba494cc 100644 --- a/src/fbutil/FirebirdConfig.cpp +++ b/src/fbutil/FirebirdConfig.cpp @@ -1,4 +1,9 @@ #include "firebird.h" + +#ifdef _MSC_VER +#pragma warning (disable: 4786) // debug identifier truncated +#endif + #include "FirebirdConfig.h" #include "FirebirdConfigFile.h" @@ -22,7 +27,7 @@ static FirebirdConfigFile sysConfig; // // -string FirebirdConfig::getSysString(const string& key) { +FirebirdConfig::string FirebirdConfig::getSysString(const FirebirdConfig::string& key) { return sysConfig.getString(key); } @@ -31,7 +36,7 @@ string FirebirdConfig::getSysString(const string& key) { // // -int FirebirdConfig::getSysInt(const string& key) { +int FirebirdConfig::getSysInt(const FirebirdConfig::string& key) { return sysConfig.getInt(key); } @@ -40,7 +45,7 @@ int FirebirdConfig::getSysInt(const string& key) { // // -bool FirebirdConfig::getSysBoolean(const string& key) { +bool FirebirdConfig::getSysBoolean(const FirebirdConfig::string& key) { return sysConfig.getBoolean(key); } @@ -56,7 +61,7 @@ void FirebirdConfig::loadSysConfig() { // // // -const string FirebirdConfig::getSysConfigFile() { +const Firebird::string FirebirdConfig::getSysConfigFile() { return sysConfig.getConfigFile(); } @@ -64,7 +69,7 @@ const string FirebirdConfig::getSysConfigFile() { // // // -void FirebirdConfig::setSysConfigFile(const string& newFile) { +void FirebirdConfig::setSysConfigFile(const FirebirdConfig::string& newFile) { sysConfig.setConfigFile(newFile); } diff --git a/src/fbutil/FirebirdConfig.h b/src/fbutil/FirebirdConfig.h index 9149ac5951..b024e44004 100644 --- a/src/fbutil/FirebirdConfig.h +++ b/src/fbutil/FirebirdConfig.h @@ -1,14 +1,14 @@ -#ifndef _FirebirdConfig_H -#define _FirebirdConfig_H +#ifndef FIREBIRDCONFIG_H +#define FIREBIRDCONFIG_H -#include -#include -#include +#include "../include/fb_types.h" +#include "../include/fb_string.h" - -class FirebirdConfig { +class FirebirdConfig +{ public: + typedef Firebird::string string; static string getSysString(const string& key); static int getSysInt(const string& key); @@ -35,4 +35,4 @@ public: }; -#endif +#endif // FIREBIRDCONFIG_H diff --git a/src/fbutil/FirebirdConfigFile.cpp b/src/fbutil/FirebirdConfigFile.cpp index 449fcf44ae..84fef987a1 100644 --- a/src/fbutil/FirebirdConfigFile.cpp +++ b/src/fbutil/FirebirdConfigFile.cpp @@ -1,10 +1,19 @@ #include "firebird.h" + +#ifdef _MSC_VER +#pragma warning (disable: 4786) // debug identifier truncated +#endif + #include "FirebirdConfigFile.h" +#include "../jrd/gds.h" +#include "../include/fb_macros.h" #ifdef HAVE_STDLIB_H #include #endif +#include +#include @@ -16,6 +25,7 @@ FirebirdConfigFile::FirebirdConfigFile() { isLoadedFlg = false; +#pragma FB_COMPILER_MESSAGE("Error! This is a *nix only thing!") configFile = "/etc/firebird.conf"; } @@ -24,14 +34,14 @@ FirebirdConfigFile::FirebirdConfigFile() // // -void stripLeadingWhiteSpace(string& s) +void stripLeadingWhiteSpace(FirebirdConfig::string& s) { if (!s.size()) { return; } - const string::size_type startPos = s.find_first_not_of(" \t"); - if (startPos == string::npos) { + const Firebird::string::size_type startPos = s.find_first_not_of(" \t"); + if (startPos == Firebird::string::npos) { s.erase(); // nothing but air } else if (startPos) { s = s.substr(startPos); @@ -43,14 +53,14 @@ void stripLeadingWhiteSpace(string& s) // // -void stripTrailingWhiteSpace(string& s) +void stripTrailingWhiteSpace(FirebirdConfig::string& s) { if (!s.size()) { return; } - string::size_type endPos = s.find_last_not_of(" \t"); - if (endPos != string::npos) { + Firebird::string::size_type endPos = s.find_last_not_of(" \t"); + if (endPos != std::string::npos) { // Note that endPos is the index to the last non-ws char // why we have to inc. it ++endPos; @@ -63,13 +73,13 @@ void stripTrailingWhiteSpace(string& s) // // -void stripComments(string& s) +void stripComments(FirebirdConfig::string& s) { // Note that this is only a hack. It won't work in case inputLine // contains hash-marks embedded in quotes! Not that I know if we // should care about that case. - const string::size_type commentPos = s.find('#'); - if (commentPos != string::npos) { + const Firebird::string::size_type commentPos = s.find('#'); + if (commentPos != Firebird::string::npos) { s = s.substr(0, commentPos); } } @@ -80,7 +90,7 @@ void stripComments(string& s) // // -string FirebirdConfigFile::getString(const string& key) { +FirebirdConfig::string FirebirdConfigFile::getString(const FirebirdConfig::string& key) { checkLoadConfig(); @@ -92,7 +102,7 @@ string FirebirdConfigFile::getString(const string& key) { return lookup->second; } - return string(); + return FirebirdConfig::string(); } //----------------------------------------------------------------------------- @@ -100,11 +110,11 @@ string FirebirdConfigFile::getString(const string& key) { // // -int FirebirdConfigFile::getInt(const string& key) { +int FirebirdConfigFile::getInt(const FirebirdConfig::string& key) { checkLoadConfig(); - string data = getString(key); + Firebird::string data = getString(key); if (data.empty()) { return 0; @@ -119,7 +129,7 @@ int FirebirdConfigFile::getInt(const string& key) { // // -bool FirebirdConfigFile::getBoolean(const string& key) { +bool FirebirdConfigFile::getBoolean(const FirebirdConfig::string& key) { checkLoadConfig(); @@ -144,10 +154,11 @@ bool FirebirdConfigFile::getBoolean(const string& key) { // // -string parseKeyFrom(const string& inputLine, string::size_type& endPos) { +FirebirdConfig::string parseKeyFrom(const FirebirdConfig::string& inputLine, + FirebirdConfig::string::size_type& endPos) { endPos = inputLine.find_first_of("= \t"); - if (endPos == string::npos) { + if (endPos == Firebird::string::npos) { return inputLine; } @@ -161,16 +172,17 @@ string parseKeyFrom(const string& inputLine, string::size_type& endPos) { // // -string parseValueFrom(string inputLine, string::size_type initialPos) { +FirebirdConfig::string parseValueFrom(FirebirdConfig::string inputLine, + FirebirdConfig::string::size_type initialPos) { - if (initialPos == string::npos) { - return string(); + if (initialPos == Firebird::string::npos) { + return Firebird::string(); } // skip leading white spaces unsigned int startPos = inputLine.find_first_not_of("= \t", initialPos); - if (startPos == string::npos) { - return string(); + if (startPos == Firebird::string::npos) { + return Firebird::string(); } stripTrailingWhiteSpace(inputLine); @@ -199,7 +211,7 @@ void FirebirdConfigFile::loadConfig() { isLoadedFlg = true; - ifstream configFile(configFile.c_str()); + std::ifstream configFile(configFile.c_str()); if (!configFile) { // config file does not exist, a warning message would be nice. @@ -208,7 +220,7 @@ void FirebirdConfigFile::loadConfig() { string inputLine; while (!configFile.eof() ) { - getline(configFile, inputLine); + std::getline(configFile, inputLine); stripComments(inputLine); stripLeadingWhiteSpace(inputLine); @@ -220,7 +232,7 @@ void FirebirdConfigFile::loadConfig() { // cout << "read \"" << inputLine << "\"\n"; if (inputLine.find('=') == string::npos) { - cerr << "illegal line \"" << inputLine << "\"" << endl; + std::cerr << "illegal line \"" << inputLine << "\"" << std::endl; continue; } @@ -229,10 +241,10 @@ void FirebirdConfigFile::loadConfig() { string key = parseKeyFrom(inputLine, endPos); string value = parseValueFrom(inputLine, endPos); - cout << "adding \"" << key << "\" \"" << value << "\"" << endl; + std::cout << "adding \"" << key << "\" \"" << value << "\"" << std::endl; // parameters.insert(pair(key, value)); // Just to display yet another template function - parameters.insert(make_pair(key, value)); + parameters.insert(std::make_pair(key, value)); } } diff --git a/src/fbutil/FirebirdConfigFile.h b/src/fbutil/FirebirdConfigFile.h index d5d347878a..639b8fad80 100644 --- a/src/fbutil/FirebirdConfigFile.h +++ b/src/fbutil/FirebirdConfigFile.h @@ -1,17 +1,16 @@ -#ifndef _FirebirdConfigFile_H -#define _FirebirdConfigFile_H +#ifndef FIREBIRDCONFIGFILE_H +#define FIREBIRDCONFIGFILE_H -#include -#include #include -#include +#include "../include/fb_string.h" #include "FirebirdConfig.h" -class FirebirdConfigFile : public FirebirdConfig { -public: +class FirebirdConfigFile : public FirebirdConfig +{ +public: FirebirdConfigFile(); const string getConfigFile() { return configFile; } @@ -29,11 +28,10 @@ public: private: string configFile; bool isLoadedFlg; - typedef pair mypair; - typedef map mymap_t; + typedef std::map mymap_t; mymap_t parameters; }; -#endif +#endif // FIREBIRDCONFIGFILE_H diff --git a/src/gpre/ada.cpp b/src/gpre/ada.cpp index 03cd4b683a..646f53e0a9 100644 --- a/src/gpre/ada.cpp +++ b/src/gpre/ada.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: ada.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ +// $Id: ada.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/c_cxx.cpp b/src/gpre/c_cxx.cpp index 95fec7479c..b274579fa4 100644 --- a/src/gpre/c_cxx.cpp +++ b/src/gpre/c_cxx.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: c_cxx.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ +// $Id: c_cxx.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/cmd.cpp b/src/gpre/cmd.cpp index 2e3412b0e9..2d0705738c 100644 --- a/src/gpre/cmd.cpp +++ b/src/gpre/cmd.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: cmd.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ +// $Id: cmd.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/cme.cpp b/src/gpre/cme.cpp index bfe194288b..152df61925 100644 --- a/src/gpre/cme.cpp +++ b/src/gpre/cme.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: cme.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +// $Id: cme.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" @@ -99,56 +99,56 @@ struct op_table const op_table operators[] = { - nod_eq , blr_eql, - nod_ge , blr_geq, - nod_gt , blr_gtr, - nod_le , blr_leq, - nod_lt , blr_lss, - nod_ne , blr_neq, - nod_missing , blr_missing, - nod_between , blr_between, - nod_and , blr_and, - nod_or , blr_or, - nod_not , blr_not, - nod_matches , blr_matching, - nod_starting , blr_starting, - nod_containing , blr_containing, - nod_plus , blr_add, - nod_from , blr_from, - nod_via , blr_via, - nod_minus , blr_subtract, - nod_times , blr_multiply, - nod_divide , blr_divide, - nod_negate , blr_negate, - nod_null , blr_null, - nod_user_name , blr_user_name, -// count2 -// nod_count, blr_count2, + { nod_eq , blr_eql }, + { nod_ge , blr_geq }, + { nod_gt , blr_gtr }, + { nod_le , blr_leq }, + { nod_lt , blr_lss }, + { nod_ne , blr_neq }, + { nod_missing , blr_missing }, + { nod_between , blr_between }, + { nod_and , blr_and }, + { nod_or , blr_or }, + { nod_not , blr_not }, + { nod_matches , blr_matching }, + { nod_starting , blr_starting }, + { nod_containing , blr_containing }, + { nod_plus , blr_add }, + { nod_from , blr_from }, + { nod_via , blr_via }, + { nod_minus , blr_subtract }, + { nod_times , blr_multiply }, + { nod_divide , blr_divide }, + { nod_negate , blr_negate }, + { nod_null , blr_null }, + { nod_user_name , blr_user_name }, +// { count2 } +// { nod_count, blr_count2 }, // - nod_count , blr_count, - nod_max , blr_maximum, - nod_min , blr_minimum, - nod_average , blr_average, - nod_total , blr_total, - nod_any , blr_any, - nod_unique , blr_unique, - nod_agg_count , blr_agg_count2, - nod_agg_count , blr_agg_count, - nod_agg_max , blr_agg_max, - nod_agg_min , blr_agg_min, - nod_agg_total , blr_agg_total, - nod_agg_average , blr_agg_average, - nod_upcase , blr_upcase, - nod_sleuth , blr_matching2, - nod_concatenate , blr_concatenate, - nod_cast , blr_cast, - nod_ansi_any , blr_ansi_any, - nod_gen_id , blr_gen_id, - nod_ansi_all , blr_ansi_all, - nod_current_date, blr_current_date, - nod_current_time, blr_current_time, - nod_current_timestamp, blr_current_timestamp, - nod_any, 0 + { nod_count , blr_count }, + { nod_max , blr_maximum }, + { nod_min , blr_minimum }, + { nod_average , blr_average }, + { nod_total , blr_total }, + { nod_any , blr_any }, + { nod_unique , blr_unique }, + { nod_agg_count , blr_agg_count2 }, + { nod_agg_count , blr_agg_count }, + { nod_agg_max , blr_agg_max }, + { nod_agg_min , blr_agg_min }, + { nod_agg_total , blr_agg_total }, + { nod_agg_average , blr_agg_average }, + { nod_upcase , blr_upcase }, + { nod_sleuth , blr_matching2 }, + { nod_concatenate , blr_concatenate }, + { nod_cast , blr_cast }, + { nod_ansi_any , blr_ansi_any }, + { nod_gen_id , blr_gen_id }, + { nod_ansi_all , blr_ansi_all }, + { nod_current_date, blr_current_date }, + { nod_current_time, blr_current_time }, + { nod_current_timestamp, blr_current_timestamp }, + { nod_any, 0 } }; diff --git a/src/gpre/cmp.cpp b/src/gpre/cmp.cpp index c163b08446..879e5ba3f6 100644 --- a/src/gpre/cmp.cpp +++ b/src/gpre/cmp.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: cmp.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ +// $Id: cmp.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" @@ -304,7 +304,6 @@ void CMP_compile_request( register REQ request) case ACT_fetch: cmp_fetch(action); break; - } cmp_blr(request); @@ -1568,7 +1567,6 @@ static void cmp_sdl_fudge( REQ request, SLONG lower_bound) } } - //____________________________________________________________ // // Build an SDL loop for GET_SLICE/PUT_SLICE unless the upper and diff --git a/src/gpre/cob.cpp b/src/gpre/cob.cpp index c610e0b560..8473aef66a 100644 --- a/src/gpre/cob.cpp +++ b/src/gpre/cob.cpp @@ -25,10 +25,10 @@ // //____________________________________________________________ // -// $Id: cob.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ +// $Id: cob.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // - /* $Id: cob.cpp,v 1.3 2001-07-29 23:43:21 skywalker Exp $ */ + /* $Id: cob.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ */ #include "firebird.h" #include "../jrd/ib_stdio.h" diff --git a/src/gpre/dyntable.cpp b/src/gpre/dyntable.cpp index 0bd27ae5df..060b7eeba9 100644 --- a/src/gpre/dyntable.cpp +++ b/src/gpre/dyntable.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: dyntable.cpp,v 1.2 2001-07-29 23:43:21 skywalker Exp $ +// $Id: dyntable.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/exp.cpp b/src/gpre/exp.cpp index 88baca35bd..ea44362457 100644 --- a/src/gpre/exp.cpp +++ b/src/gpre/exp.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: exp.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: exp.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" @@ -90,32 +90,34 @@ static struct rel_ops { enum kwwords rel_kw; SSHORT rel_args; } relops[] = { - nod_eq, KW_EQ, 2, - nod_eq, KW_EQUALS, 2, - nod_ne, KW_NE, 2, - nod_gt, KW_GT, 2, - nod_ge, KW_GE, 2, - nod_le, KW_LE, 2, - nod_lt, KW_LT, 2, - nod_containing, KW_CONTAINING, 2, - nod_matches, KW_MATCHES, 2, - nod_like, KW_LIKE, 2, - nod_starting, KW_STARTING, 2, - nod_missing, KW_MISSING, 1, - nod_between, KW_BETWEEN, 3, nod_any, KW_none}; + { nod_eq, KW_EQ, 2 }, + { nod_eq, KW_EQUALS, 2 }, + { nod_ne, KW_NE, 2 }, + { nod_gt, KW_GT, 2 }, + { nod_ge, KW_GE, 2 }, + { nod_le, KW_LE, 2 }, + { nod_lt, KW_LT, 2 }, + { nod_containing, KW_CONTAINING, 2 }, + { nod_matches, KW_MATCHES, 2 }, + { nod_like, KW_LIKE, 2 }, + { nod_starting, KW_STARTING, 2 }, + { nod_missing, KW_MISSING, 1 }, + { nod_between, KW_BETWEEN, 3}, { nod_any, KW_none, 0} }; static struct dtypes { enum kwwords dtype_keyword; USHORT dtype_dtype; } data_types[] = { - KW_CHAR, dtype_text, - KW_VARYING, dtype_varying, - KW_STRING, dtype_cstring, - KW_SHORT, dtype_short, - KW_LONG, dtype_long, - KW_QUAD, dtype_quad, - KW_FLOAT, dtype_real, - KW_DOUBLE, dtype_double, KW_DATE, dtype_date, KW_none, 0}; + { KW_CHAR, dtype_text }, + { KW_VARYING, dtype_varying }, + { KW_STRING, dtype_cstring }, + { KW_SHORT, dtype_short }, + { KW_LONG, dtype_long }, + { KW_QUAD, dtype_quad }, + { KW_FLOAT, dtype_real }, + { KW_DOUBLE, dtype_double }, + { KW_DATE, dtype_date }, + { KW_none, 0} }; //____________________________________________________________ diff --git a/src/gpre/form.cpp b/src/gpre/form.cpp index f8a09ad924..dee340aa2b 100644 --- a/src/gpre/form.cpp +++ b/src/gpre/form.cpp @@ -20,7 +20,7 @@ // // All Rights Reserved. // Contributor(s): ______________________________________. -// $Id: form.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: form.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // Revision 1.2 2000/11/27 09:26:13 fsg // Fixed bugs in gpre to handle PYXIS forms // and allow edit.e and fred.e to go through @@ -35,7 +35,7 @@ // //____________________________________________________________ // -// $Id: form.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: form.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/form_trn.cpp b/src/gpre/form_trn.cpp index 1d52ade4d5..581321fd35 100644 --- a/src/gpre/form_trn.cpp +++ b/src/gpre/form_trn.cpp @@ -20,7 +20,7 @@ // // All Rights Reserved. // Contributor(s): ______________________________________. -// $Id: form_trn.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: form_trn.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // Revision 1.3 2000/11/29 11:11:56 fsg // Added some more PYXIS datatypes to form_trn.c // @@ -38,7 +38,7 @@ // //____________________________________________________________ // -// $Id: form_trn.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: form_trn.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/ftn.cpp b/src/gpre/ftn.cpp index d05c42d547..23c1041550 100644 --- a/src/gpre/ftn.cpp +++ b/src/gpre/ftn.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: ftn.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: ftn.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/gpre.cpp b/src/gpre/gpre.cpp index 3e7a2b4f9c..3afa92c23d 100644 --- a/src/gpre/gpre.cpp +++ b/src/gpre/gpre.cpp @@ -20,7 +20,7 @@ // // All Rights Reserved. // Contributor(s): ______________________________________. -// $Id: gpre.cpp,v 1.5 2001-07-31 18:34:05 skywalker Exp $ +// $Id: gpre.cpp,v 1.6 2001-12-24 02:50:49 tamlin Exp $ // Revision 1.2 2000/11/16 15:54:29 fsg // Added new switch -verbose to gpre that will dump // parsed lines to stderr @@ -38,7 +38,7 @@ // //____________________________________________________________ // -// $Id: gpre.cpp,v 1.5 2001-07-31 18:34:05 skywalker Exp $ +// $Id: gpre.cpp,v 1.6 2001-12-24 02:50:49 tamlin Exp $ // #define GPRE_MAIN @@ -158,70 +158,70 @@ typedef struct ext_table_t static struct ext_table_t dml_ext_table[] = { - lang_c, IN_SW_GPRE_C, ".e", ".c", + { lang_c, IN_SW_GPRE_C, ".e", ".c" }, #ifndef VMS #ifndef WIN_NT - lang_scxx, IN_SW_GPRE_SCXX, ".E", ".C", + { lang_scxx, IN_SW_GPRE_SCXX, ".E", ".C" }, #endif #endif - lang_cxx, IN_SW_GPRE_CXX, ".exx", ".cxx", - lang_cpp, IN_SW_GPRE_CXX, ".epp", ".cpp", - lang_internal, IN_SW_GPRE_G, ".e", ".c", - lang_pascal, IN_SW_GPRE_P, ".epas", ".pas", + { lang_cxx, IN_SW_GPRE_CXX, ".exx", ".cxx" }, + { lang_cpp, IN_SW_GPRE_CXX, ".epp", ".cpp" }, + { lang_internal, IN_SW_GPRE_G, ".e", ".c" }, + { lang_pascal, IN_SW_GPRE_P, ".epas", ".pas" }, #ifdef FORTRAN #ifdef VMS #define FORTRAN_EXTENSIONS - lang_fortran, IN_SW_GPRE_F, ".efor", ".for", + { lang_fortran, IN_SW_GPRE_F, ".efor", ".for" }, #endif #ifndef FORTRAN_EXTENSIONS - lang_fortran, IN_SW_GPRE_F, ".ef", ".f", + { lang_fortran, IN_SW_GPRE_F, ".ef", ".f" }, #endif #endif #ifdef COBOL #ifdef VMS #define COBOL_EXTENSIONS - lang_cobol, IN_SW_GPRE_COB, ".ecob", ".cob", + { lang_cobol, IN_SW_GPRE_COB, ".ecob", ".cob" }, #endif #ifndef COBOL_EXTENSIONS #define COBOL_EXTENSIONS - lang_cobol, IN_SW_GPRE_COB, ".ecbl", ".cbl", + { lang_cobol, IN_SW_GPRE_COB, ".ecbl", ".cbl" }, #endif #endif #ifdef BASIC - lang_basic, IN_SW_GPRE_BAS, ".ebas", ".bas", + { lang_basic, IN_SW_GPRE_BAS, ".ebas", ".bas" }, #endif #ifdef PLI - lang_pli, IN_SW_GPRE_PLI, ".epli", ".pli", + { lang_pli, IN_SW_GPRE_PLI, ".epli", ".pli" }, #endif #ifdef VMS #define ADA_EXTENSIONS - lang_ada, IN_SW_GPRE_ADA, ".eada", ".ada", + { lang_ada, IN_SW_GPRE_ADA, ".eada", ".ada" }, #endif #ifdef hpux #define ADA_EXTENSIONS - lang_ada, IN_SW_GPRE_ADA, ".eada", ".ada", + { lang_ada, IN_SW_GPRE_ADA, ".eada", ".ada" }, #endif #ifndef ADA_EXTENSIONS - lang_ada, IN_SW_GPRE_ADA, ".ea", ".a", + { lang_ada, IN_SW_GPRE_ADA, ".ea", ".a" }, #endif #ifdef ALSYS_ADA - lang_ada, IN_SW_GPRE_ALSYS, ".eada", ".ada", + { lang_ada, IN_SW_GPRE_ALSYS, ".eada", ".ada" }, #endif #if ( defined( PC_PLATFORM) || defined( WIN_NT)) - lang_cplusplus, IN_SW_GPRE_CPLUSPLUS, ".epp", ".cpp", + { lang_cplusplus, IN_SW_GPRE_CPLUSPLUS, ".epp", ".cpp" }, #else - lang_cplusplus, IN_SW_GPRE_CPLUSPLUS, ".exx", ".cxx", + { lang_cplusplus, IN_SW_GPRE_CPLUSPLUS, ".exx", ".cxx" }, #endif - lang_undef, IN_SW_GPRE_0, NULL, NULL + { lang_undef, IN_SW_GPRE_0, NULL, NULL } }; #define CHR_LETTER 1 @@ -871,8 +871,10 @@ int main(int argc, char* argv[]) sw_databases = isc_databases; - if (!setjmp(fatal_env)) - for (end_position = 0; end_position = compile_module(end_position);); + try { + for (end_position = 0; end_position = compile_module(end_position);); // empty loop + } // try + catch (...) {} // fall through to the cleanup code #ifdef FTN_BLK_DATA if (sw_language == lang_fortran) @@ -910,6 +912,7 @@ int main(int argc, char* argv[]) CPR_exit((errors) ? FINI_ERROR : FINI_OK); return 0; + } @@ -922,7 +925,7 @@ void CPR_abort() { ++fatals; - longjmp(fatal_env, 1); + Firebird::status_longjmp_error::raise(1); } diff --git a/src/gpre/gpre.h b/src/gpre/gpre.h index f57c280fd7..c3bf09472a 100644 --- a/src/gpre/gpre.h +++ b/src/gpre/gpre.h @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: gpre.h,v 1.1.1.1 2001-05-23 13:25:31 tamlin Exp $ + * $Id: gpre.h,v 1.2 2001-12-24 02:50:49 tamlin Exp $ * Revision 1.3 2000/11/27 09:26:13 fsg * Fixed bugs in gpre to handle PYXIS forms * and allow edit.e and fred.e to go through @@ -408,9 +408,11 @@ typedef struct bas { /* Blob block. Used for blob calls */ -typedef struct blb { +class blb +{ +public: struct req *blb_request; /* parent request */ - struct blb *blb_next; /* next blob in request */ + blb* blb_next; /* next blob in request */ struct ref *blb_reference; /* field reference for blob field */ struct sym *blb_symbol; /* Blob context variable */ USHORT blb_ident; /* Blob handle */ @@ -438,9 +440,10 @@ typedef struct blb { USHORT blb_from_charset; /* charset to translate from */ USHORT blb_to_charset; /* charset to translate to */ UCHAR blb_bpb[24]; -} *BLB; +}; +typedef blb* BLB; -#define BLB_LEN sizeof (struct blb) +#define BLB_LEN sizeof(blb) #define BLB_create 1 #define BLB_symbol_released 2 @@ -1112,7 +1115,7 @@ typedef struct req { struct por *req_aport; /* port for asynchronous message */ #endif struct req *req_routine; /* other requests in routine */ - struct blb *req_blobs; /* blobs in request */ + blb* req_blobs; /* blobs in request */ struct form *req_form; /* form for request */ struct slc *req_slice; /* slice for request */ struct ref *req_array_references; /* array fields referenced in context */ diff --git a/src/gpre/gpre_meta.epp b/src/gpre/gpre_meta.epp index 563859b40d..0317b31e64 100644 --- a/src/gpre/gpre_meta.epp +++ b/src/gpre/gpre_meta.epp @@ -3,7 +3,7 @@ *____________________________________________________________ * * PROGRAM: C preprocessor - * MODULE: gpre_meta.e + * MODULE: gpre_meta.epp * DESCRIPTION: Meta data interface to system * * The contents of this file are subject to the Interbase Public @@ -26,7 +26,7 @@ * *____________________________________________________________ * - * $Id: gpre_meta.epp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ + * $Id: gpre_meta.epp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ */ #include "firebird.h" @@ -82,7 +82,6 @@ FLD MET_context_field( CTX context, char *string) PRC procedure; FLD field; SCHAR name[NAME_SIZE]; - SSHORT length; if (context->ctx_relation) { return (MET_field(context->ctx_relation, string)); @@ -122,8 +121,6 @@ FLD MET_context_field( CTX context, char *string) BOOLEAN MET_database(DBB dbb, BOOLEAN print_version) { SCHAR dpb[MAX_PASSWORD_LENGTH + MAX_USER_LENGTH + 5], *d, *p; - SCHAR buffer[16], *data; - SSHORT l; static CONST UCHAR sql_version_info[] = { isc_info_base_level, isc_info_ods_version, isc_info_db_sql_dialect, @@ -179,7 +176,7 @@ BOOLEAN MET_database(DBB dbb, BOOLEAN print_version) } if (gds__attach_database - (gds__status, 0, GDS_VAL(dbb->dbb_filename), GDS_REF(DB), d - &dpb[0], + (gds_status, 0, GDS_VAL(dbb->dbb_filename), GDS_REF(DB), d - &dpb[0], dpb)) { /* We failed to attach, try in read only mode just in case if (d == dpb) @@ -188,9 +185,9 @@ BOOLEAN MET_database(DBB dbb, BOOLEAN print_version) *d++ = 1; *d++ = TRUE; if (gds__attach_database - (gds__status, 0, GDS_VAL(dbb->dbb_filename), GDS_REF(DB), d - &dpb[0], + (gds_status, 0, GDS_VAL(dbb->dbb_filename), GDS_REF(DB), d - &dpb[0], dpb)) {*/ - gds__print_status(gds__status); + gds__print_status(gds_status); return FALSE; //} } @@ -279,13 +276,16 @@ BOOLEAN MET_database(DBB dbb, BOOLEAN print_version) \n\tClient Sql dialect set to : %d\n\n", \sw_server_version, sw_ods_version, compiletime_db_dialect, \sw_sql_dialect); #endif #ifdef SCROLLABLE_CURSORS + + SCHAR buffer[16]; + /* get the base level of the engine */ - if (gds__database_info(gds__status, + if (gds__database_info(gds_status, GDS_REF(DB), sizeof(db_version_info), db_version_info, sizeof(buffer), buffer)) { - gds__print_status(gds__status); + gds__print_status(gds_status); return FALSE; } @@ -294,7 +294,7 @@ BOOLEAN MET_database(DBB dbb, BOOLEAN print_version) * more info items later */ - data = buffer; + SCHAR* data = buffer; while ((p = *data++) != gds__info_end) { l = isc_vax_integer(data, 2); data += 2; @@ -376,7 +376,7 @@ USHORT MET_domain_lookup(REQ request, FLD field, char *string) return FALSE; DB = dbb->dbb_handle; - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; if (!(dbb->dbb_flags & DBB_v3)) { FOR(REQUEST_HANDLE dbb->dbb_domain_request) @@ -457,7 +457,7 @@ BOOLEAN MET_get_domain_default(DBB dbb, TEXT * domain_name, TEXT * buffer, USHORT buff_length) { - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; SCHAR name[NAME_SIZE]; SSHORT length; BOOLEAN has_default; @@ -478,7 +478,7 @@ BOOLEAN MET_get_domain_default(DBB dbb, CPR_exit(FINI_ERROR); assert(dbb->dbb_transaction == NULL); - gds__trans = NULL; + gds_trans = NULL; DB = dbb->dbb_handle; @@ -490,7 +490,7 @@ BOOLEAN MET_get_domain_default(DBB dbb, blob_id = &FLD.RDB$DEFAULT_VALUE; /* open the blob */ - stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds__trans, (void**) &blob_handle, + stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds_trans, (void**) &blob_handle, blob_id, sizeof(blr_bpb), const_cast(blr_bpb)); if (stat) { gds__print_status(status_vect); @@ -556,7 +556,7 @@ BOOLEAN MET_get_column_default(REL relation, TEXT * buffer, USHORT buff_length) { DBB dbb; - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; SCHAR name[NAME_SIZE]; SSHORT length; BOOLEAN has_default; @@ -576,7 +576,7 @@ BOOLEAN MET_get_column_default(REL relation, CPR_exit(FINI_ERROR); assert(dbb->dbb_transaction == NULL); - gds__trans = NULL; + gds_trans = NULL; DB = dbb->dbb_handle; @@ -598,7 +598,7 @@ BOOLEAN MET_get_column_default(REL relation, if (has_default) { /* open the blob */ - stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds__trans, + stat = isc_open_blob2(status_vect, (void**) &DB, (void**) &gds_trans, (void**) &blob_handle, blob_id, sizeof(blr_bpb), const_cast(blr_bpb)); if (stat) { @@ -658,7 +658,7 @@ BOOLEAN MET_get_column_default(REL relation, LLS MET_get_primary_key(DBB dbb, TEXT * relation_name) { LLS fields = NULL, *ptr_fields; - SLONG *DB, *gds__trans; + SLONG *DB, *gds_trans; SCHAR name[NAME_SIZE]; STR field_name; TEXT *tmp; @@ -672,7 +672,7 @@ LLS MET_get_primary_key(DBB dbb, TEXT * relation_name) CPR_exit(FINI_ERROR); assert(dbb->dbb_transaction == NULL); - gds__trans = NULL; + gds_trans = NULL; DB = dbb->dbb_handle; @@ -741,7 +741,7 @@ FLD MET_field(REL relation, char *string) return NULL; DB = dbb->dbb_handle; - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; field = NULL; if (!(dbb->dbb_flags & DBB_v3)) { @@ -903,7 +903,7 @@ NOD MET_fields(CTX context) dbb = relation->rel_database; DB = dbb->dbb_handle; - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; count = 0; stack = NULL; @@ -944,7 +944,7 @@ void MET_fini( DBB end) for (dbb = isc_databases; dbb && dbb != end; dbb = dbb->dbb_next) if (DB = dbb->dbb_handle) { - if (gds__trans = dbb->dbb_transaction) + if (gds_trans = dbb->dbb_transaction) COMMIT; FINISH; dbb->dbb_handle = NULL; @@ -981,7 +981,6 @@ SCHAR *MET_generator(TEXT * string, DBB dbb) SYM symbol; SCHAR *gen_name = NULL; SCHAR name[NAME_SIZE]; - SSHORT length; strcpy(name, string); @@ -1366,7 +1365,7 @@ REL MET_get_view_relation(REQ request, dbb = request->req_database; DB = dbb->dbb_handle; - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; relation = NULL; @@ -1423,7 +1422,7 @@ IND MET_index(DBB dbb, TEXT * string) return NULL; DB = dbb->dbb_handle; - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; index = NULL; FOR(REQUEST_HANDLE dbb->dbb_index_request) @@ -1474,12 +1473,12 @@ void MET_load_hash_table( DBB dbb) /* we must have already loaded this one */ return; - gds__trans = NULL; + gds_trans = NULL; DB = dbb->dbb_handle; START_TRANSACTION; - dbb->dbb_transaction = (SLONG*) gds__trans; + dbb->dbb_transaction = (SLONG*) gds_trans; handle = handle2 = NULL; /* Determine if the database is V3. */ @@ -1492,7 +1491,7 @@ void MET_load_hash_table( DBB dbb) X.RDB$SYSTEM_FLAG = 1 post_v3_flag = TRUE; END_FOR; - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); if (!post_v3_flag) dbb->dbb_flags |= DBB_v3; @@ -1545,7 +1544,7 @@ void MET_load_hash_table( DBB dbb) END_FOR; } - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); /* Pick up all procedures (necessary to parse parts of the GDML grammar) */ @@ -1567,7 +1566,7 @@ void MET_load_hash_table( DBB dbb) END_ERROR; if (handle) - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); /* Pickup any user defined functions. If the database does not support UDF's, * this may fail @@ -1620,9 +1619,9 @@ void MET_load_hash_table( DBB dbb) } END_FOR ON_ERROR END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); if (handle2) - gds__release_request(gds__status, (void**) GDS_REF(handle2)); + gds__release_request(gds_status, (void**) GDS_REF(handle2)); /* Pick up all Collation names, might have several collations * for a given character set. @@ -1672,9 +1671,9 @@ void MET_load_hash_table( DBB dbb) /* assume pre V4 database, no collations */ END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); if (handle2) - gds__release_request(gds__status, (void**) GDS_REF(handle2)); + gds__release_request(gds_status, (void**) GDS_REF(handle2)); /* Now pick up all character set names - with the subtype set to * the type of the default collation for the character set. @@ -1720,9 +1719,9 @@ void MET_load_hash_table( DBB dbb) /* assume pre V4 database, no character sets */ END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); if (handle2) - gds__release_request(gds__status, (void**) GDS_REF(handle2)); + gds__release_request(gds_status, (void**) GDS_REF(handle2)); /* Pick up name of database default character set for SQL */ @@ -1740,7 +1739,7 @@ void MET_load_hash_table( DBB dbb) /* Assume V3 Db, no default charset */ END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); /* Pick up all generators for the database */ @@ -1752,7 +1751,7 @@ void MET_load_hash_table( DBB dbb) END_FOR ON_ERROR END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(handle)); + gds__release_request(gds_status, (void**) GDS_REF(handle)); /* now that we have attached to the database, resolve the character set * request (if any) (and if we can) @@ -1857,7 +1856,7 @@ BOOLEAN MET_type(FLD field, TEXT * string, SSHORT * ptr) relation = field->fld_relation; dbb = relation->rel_database; DB = dbb->dbb_handle; - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; /* Force the name to uppercase, using C locale rules for uppercasing */ for (p = buffer; *string && p < &buffer[sizeof(buffer) - 1]; @@ -1888,15 +1887,14 @@ BOOLEAN MET_type(FLD field, TEXT * string, SSHORT * ptr) * FALSE otherwise */ -BOOLEAN MET_trigger_exists(DBB dbb, TEXT * trigger_name) +BOOLEAN MET_trigger_exists(DBB dbb, TEXT* trigger_name) { - SCHAR name[NAME_SIZE]; - SSHORT length; + char name[NAME_SIZE]; strcpy(name, trigger_name); DB = dbb->dbb_handle; - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; FOR(REQUEST_HANDLE dbb->dbb_trigger_request) TRIG IN RDB$TRIGGERS WITH TRIG.RDB$TRIGGER_NAME EQ name return TRUE; @@ -2021,7 +2019,7 @@ static int get_intl_char_subtype( DB = dbb->dbb_handle; if (!DB) return (0); - gds__trans = dbb->dbb_transaction; + gds_trans = dbb->dbb_transaction; end_name = name + length; /* Force key to uppercase, following C locale rules for uppercasing @@ -2108,7 +2106,7 @@ static int resolve_charset_and_collation( /* Assume V3 DB, without default character set */ END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(request)); + gds__release_request(gds_status, (void**) GDS_REF(request)); if (charset == NULL) charset = (UCHAR *) DEFAULT_CHARACTER_SET_NAME; @@ -2129,7 +2127,7 @@ static int resolve_charset_and_collation( END_FOR ON_ERROR END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(request)); + gds__release_request(gds_status, (void**) GDS_REF(request)); return (found); } @@ -2144,7 +2142,7 @@ static int resolve_charset_and_collation( *id = MAP_CHARSET_TO_TTYPE(CS.RDB$CHARACTER_SET_ID); END_FOR ON_ERROR END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(request)); + gds__release_request(gds_status, (void**) GDS_REF(request)); return (found); } @@ -2162,7 +2160,7 @@ static int resolve_charset_and_collation( *id = MAP_CHARSET_TO_TTYPE(CS.RDB$CHARACTER_SET_ID); END_FOR ON_ERROR END_ERROR; - gds__release_request(gds__status, (void**) GDS_REF(request)); + gds__release_request(gds_status, (void**) GDS_REF(request)); return (found); } diff --git a/src/gpre/gpre_meta_boot.cpp b/src/gpre/gpre_meta_boot.cpp index eca02ae602..77eb783643 100644 --- a/src/gpre/gpre_meta_boot.cpp +++ b/src/gpre/gpre_meta_boot.cpp @@ -26,7 +26,7 @@ * *____________________________________________________________ * - * $Id: gpre_meta_boot.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ + * $Id: gpre_meta_boot.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ */ #include "firebird.h" @@ -977,3 +977,12 @@ void DLL_EXPORT CVT_move (struct dsc * a, struct dsc * b, FPTR_VOID c) /* Not available in boot_gpre */ } +extern "C" { +void DLL_EXPORT ERR_bugcheck(int number) +{ +} +BOOLEAN DLL_EXPORT ERR_post(STATUS status, ...) +{ +} + +} \ No newline at end of file diff --git a/src/gpre/gpreswi.h b/src/gpre/gpreswi.h index b2d5c13732..bb154a8c5e 100644 --- a/src/gpre/gpreswi.h +++ b/src/gpre/gpreswi.h @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: gpreswi.h,v 1.3 2001-07-31 18:34:05 skywalker Exp $ + * $Id: gpreswi.h,v 1.4 2001-12-24 02:50:49 tamlin Exp $ * Revision 1.2 2000/11/16 15:54:29 fsg * Added new switch -verbose to gpre that will dump * parsed lines to stderr diff --git a/src/gpre/hsh.cpp b/src/gpre/hsh.cpp index 7c223c1acc..9ad099b017 100644 --- a/src/gpre/hsh.cpp +++ b/src/gpre/hsh.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: hsh.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: hsh.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/int.cpp b/src/gpre/int.cpp index 5cbf14f6f3..b11eccbf09 100644 --- a/src/gpre/int.cpp +++ b/src/gpre/int.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: int.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: int.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/int_cxx.cpp b/src/gpre/int_cxx.cpp index a68b999204..074d2b2795 100644 --- a/src/gpre/int_cxx.cpp +++ b/src/gpre/int_cxx.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: int_cxx.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: int_cxx.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/jrdmet.cpp b/src/gpre/jrdmet.cpp index 19c3540cc2..d6f0cb8932 100644 --- a/src/gpre/jrdmet.cpp +++ b/src/gpre/jrdmet.cpp @@ -26,7 +26,7 @@ // //____________________________________________________________ // -// $Id: jrdmet.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: jrdmet.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/movg.cpp b/src/gpre/movg.cpp index 71e516135a..bb052f7cb1 100644 --- a/src/gpre/movg.cpp +++ b/src/gpre/movg.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: movg.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: movg.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/msc.cpp b/src/gpre/msc.cpp index 0f84a6892f..57702a00b0 100644 --- a/src/gpre/msc.cpp +++ b/src/gpre/msc.cpp @@ -25,10 +25,10 @@ // //____________________________________________________________ // -// $Id: msc.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: msc.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // // -//$Id: msc.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +//$Id: msc.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // // *************************************************** diff --git a/src/gpre/noform.cpp b/src/gpre/noform.cpp index a95fc2c025..9985706dee 100644 --- a/src/gpre/noform.cpp +++ b/src/gpre/noform.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: noform.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: noform.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/par.cpp b/src/gpre/par.cpp index a000c84a1f..715208f989 100644 --- a/src/gpre/par.cpp +++ b/src/gpre/par.cpp @@ -20,7 +20,7 @@ // // All Rights Reserved. // Contributor(s): ______________________________________. -// $Id: par.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: par.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // Revision 1.2 2000/11/27 09:26:13 fsg // Fixed bugs in gpre to handle PYXIS forms // and allow edit.e and fred.e to go through @@ -37,7 +37,7 @@ // //____________________________________________________________ // -// $Id: par.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: par.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" @@ -208,12 +208,7 @@ ACT PAR_action() CPR_token(); } - if (setjmp(env)) { - sw_sql = FALSE; - /* This is to force GPRE to get the next symbol. Fix for bug #274. DROOT */ - token.tok_symbol = NULL; - return NULL; - } + try { PAR_jmp_buf = &env; @@ -379,6 +374,14 @@ ACT PAR_action() break; } + } // try + catch (...) { + sw_sql = FALSE; + /* This is to force GPRE to get the next symbol. Fix for bug #274. DROOT */ + token.tok_symbol = NULL; + return NULL; + } + cur_statement = NULL; return NULL; } @@ -388,46 +391,60 @@ ACT PAR_action() switch (symbol->sym_type) { case SYM_context: - if (setjmp(env)) - return NULL; - PAR_jmp_buf = &env; - cur_statement = NULL; - return par_variable(); + try { + PAR_jmp_buf = &env; + cur_statement = NULL; + return par_variable(); + } + catch (...) { + return 0; + } case SYM_form_map: - if (setjmp(env)) - return NULL; - PAR_jmp_buf = &env; - cur_statement = NULL; - return par_form_field(); - + try { + PAR_jmp_buf = &env; + cur_statement = NULL; + return par_form_field(); + } + catch (...) { + return 0; + } case SYM_blob: - if (setjmp(env)) - return NULL; - PAR_jmp_buf = &env; - cur_statement = NULL; - return par_blob_field(); - + try { + PAR_jmp_buf = &env; + cur_statement = NULL; + return par_blob_field(); + } + catch (...) { + return 0; + } case SYM_relation: - if (setjmp(env)) - return NULL; - PAR_jmp_buf = &env; - cur_statement = NULL; - return par_type(); - + try { + PAR_jmp_buf = &env; + cur_statement = NULL; + return par_type(); + } + catch (...) { + return 0; + } case SYM_menu: - if (setjmp(env)) - return NULL; - PAR_jmp_buf = &env; - cur_statement = NULL; - return par_menu_att(); - + try { + PAR_jmp_buf = &env; + cur_statement = NULL; + return par_menu_att(); + } + catch (...) { + return 0; + } case SYM_menu_map: - if (setjmp(env)) - return NULL; - PAR_jmp_buf = &env; - cur_statement = NULL; - return par_menu_entree_att(); + try { + PAR_jmp_buf = &env; + cur_statement = NULL; + return par_menu_entree_att(); + } + catch (...) { + return 0; + } default: break; } @@ -1142,7 +1159,9 @@ void PAR_unwind() #pragma FB_COMPILER_MESSAGE("Fix! Wierd jmp_buf use! This might crash!") - longjmp(*PAR_jmp_buf, (SLONG) 1); + //longjmp(*PAR_jmp_buf, (SLONG) 1); + + Firebird::status_longjmp_error::raise(1); } diff --git a/src/gpre/pas.cpp b/src/gpre/pas.cpp index 724930a8f2..98199bb2e6 100644 --- a/src/gpre/pas.cpp +++ b/src/gpre/pas.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: pas.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: pas.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/pat.cpp b/src/gpre/pat.cpp index 6b53e19282..b9eba28717 100644 --- a/src/gpre/pat.cpp +++ b/src/gpre/pat.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: pat.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: pat.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" @@ -67,43 +67,49 @@ static struct ops { PAT_T ops_type; TEXT ops_string[3]; } operators[] = { - RH, "RH", - RL, "RL", - RT, "RT", - RI, "RI", - RS, "RS", - DH, "DH", - DF, "DF", - TH, "TH", - BH, "BH", - BI, "BI", - FH, "FH", - V1, "V1", - V2, "V2", - I1, "I1", - I2, "I2", - S1, "S1", - S2, "S2", - S3, "S3", - S4, "S4", - S5, "S5", - S6, "S6", - S7, "S7", - N1, "N1", - N2, "N2", - N3, "N3", - N4, "N4", - L1, "L1", - L2, "L2", - PN, "PN", - PL, "PL", - PI, "PI", - QN, "QN", - QL, "QL", - QI, "QI", - IF, "IF", - EL, "EL", - EN, "EN", RF, "RF", RE, "RE", VF, "VF", VE, "VE", FR, "FR", NL, ""}; + { RH, "RH" }, + { RL, "RL" }, + { RT, "RT" }, + { RI, "RI" }, + { RS, "RS" }, + { DH, "DH" }, + { DF, "DF" }, + { TH, "TH" }, + { BH, "BH" }, + { BI, "BI" }, + { FH, "FH" }, + { V1, "V1" }, + { V2, "V2" }, + { I1, "I1" }, + { I2, "I2" }, + { S1, "S1" }, + { S2, "S2" }, + { S3, "S3" }, + { S4, "S4" }, + { S5, "S5" }, + { S6, "S6" }, + { S7, "S7" }, + { N1, "N1" }, + { N2, "N2" }, + { N3, "N3" }, + { N4, "N4" }, + { L1, "L1" }, + { L2, "L2" }, + { PN, "PN" }, + { PL, "PL" }, + { PI, "PI" }, + { QN, "QN" }, + { QL, "QL" }, + { QI, "QI" }, + { IF, "IF" }, + { EL, "EL" }, + { EN, "EN" }, + { RF, "RF" }, + { RE, "RE" }, + { VF, "VF" }, + { VE, "VE" }, + { FR, "FR" }, + { NL, "" } }; //____________________________________________________________ diff --git a/src/gpre/pretty.cpp b/src/gpre/pretty.cpp index 485a5137d5..f115915e04 100644 --- a/src/gpre/pretty.cpp +++ b/src/gpre/pretty.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: pretty.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +// $Id: pretty.cpp,v 1.4 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/gpre/sqe.cpp b/src/gpre/sqe.cpp index 3c68874a4c..4b1259334c 100644 --- a/src/gpre/sqe.cpp +++ b/src/gpre/sqe.cpp @@ -20,7 +20,7 @@ // // All Rights Reserved. // Contributor(s): ______________________________________. -// $Id: sqe.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: sqe.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // Revision 1.3 2000/11/16 15:54:29 fsg // Added new switch -verbose to gpre that will dump // parsed lines to stderr @@ -38,7 +38,7 @@ // //____________________________________________________________ // -// $Id: sqe.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: sqe.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" #include @@ -132,37 +132,37 @@ typedef struct ops { } OPS; static OPS rel_ops[] = { - nod_eq, KW_EQ, nod_ne, - nod_eq, KW_EQUALS, nod_ne, - nod_ne, KW_NE, nod_eq, - nod_gt, KW_GT, nod_le, - nod_ge, KW_GE, nod_lt, - nod_le, KW_LE, nod_gt, - nod_lt, KW_LT, nod_ge, - nod_containing, KW_CONTAINING, nod_any, - nod_starting, KW_STARTING, nod_any, - nod_matches, KW_MATCHES, nod_any, - nod_any, KW_none, nod_any, - nod_ansi_any, KW_none, nod_ansi_any, - nod_ansi_all, KW_none, nod_ansi_all + { nod_eq, KW_EQ, nod_ne }, + { nod_eq, KW_EQUALS, nod_ne }, + { nod_ne, KW_NE, nod_eq }, + { nod_gt, KW_GT, nod_le }, + { nod_ge, KW_GE, nod_lt }, + { nod_le, KW_LE, nod_gt }, + { nod_lt, KW_LT, nod_ge }, + { nod_containing, KW_CONTAINING, nod_any }, + { nod_starting, KW_STARTING, nod_any }, + { nod_matches, KW_MATCHES, nod_any }, + { nod_any, KW_none, nod_any }, + { nod_ansi_any, KW_none, nod_ansi_any }, + { nod_ansi_all, KW_none, nod_ansi_all } }, scalar_stat_ops[] = { - nod_count, KW_COUNT, nod_any, - nod_max, KW_MAX, nod_any, - nod_min, KW_MIN, nod_any, - nod_total, KW_TOTAL, nod_any, - nod_total, KW_SUM, nod_any, - nod_average, KW_AVERAGE, nod_any, + { nod_count, KW_COUNT, nod_any }, + { nod_max, KW_MAX, nod_any }, + { nod_min, KW_MIN, nod_any }, + { nod_total, KW_TOTAL, nod_any }, + { nod_total, KW_SUM, nod_any }, + { nod_average, KW_AVERAGE, nod_any }, - nod_via, KW_none, nod_any}, stat_ops[] = { - nod_agg_count, KW_COUNT, nod_any, - nod_agg_max, KW_MAX, nod_any, - nod_agg_min, KW_MIN, nod_any, - nod_agg_total, KW_TOTAL, nod_any, - nod_agg_total, KW_SUM, nod_any, - nod_agg_average, KW_AVERAGE, nod_any, - nod_any, KW_none, nod_any, - nod_ansi_any, KW_none, nod_ansi_any, - nod_ansi_all, KW_none, nod_ansi_all}; + { nod_via, KW_none, nod_any} }, stat_ops[] = { + { nod_agg_count, KW_COUNT, nod_any }, + { nod_agg_max, KW_MAX, nod_any }, + { nod_agg_min, KW_MIN, nod_any }, + { nod_agg_total, KW_TOTAL, nod_any }, + { nod_agg_total, KW_SUM, nod_any }, + { nod_agg_average, KW_AVERAGE, nod_any }, + { nod_any, KW_none, nod_any }, + { nod_ansi_any, KW_none, nod_ansi_any }, + { nod_ansi_all, KW_none, nod_ansi_all }}; static NOD_T relationals[] = { nod_eq, nod_ne, nod_gt, nod_ge, nod_le, nod_lt, nod_containing, diff --git a/src/gpre/sql.cpp b/src/gpre/sql.cpp index f8a6a0f602..0f9a881455 100644 --- a/src/gpre/sql.cpp +++ b/src/gpre/sql.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: sql.cpp,v 1.2 2001-07-29 23:43:22 skywalker Exp $ +// $Id: sql.cpp,v 1.3 2001-12-24 02:50:49 tamlin Exp $ // #include "firebird.h" diff --git a/src/include/fb_blk.h b/src/include/fb_blk.h index fc853fe7e0..f710dba390 100644 --- a/src/include/fb_blk.h +++ b/src/include/fb_blk.h @@ -1,24 +1,78 @@ #ifndef INCLUDE_FB_BLK #define INCLUDE_FB_BLK -#ifndef JRD_COMMON_H -#include "../jrd/common.h" -#endif +#include "../common/memory/memory_pool.h" +//#include -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct blk +struct blk { - UCHAR blk_type; - UCHAR blk_pool_id; - USHORT blk_length; -} *BLK; +}; +typedef blk* BLK; -#ifdef __cplusplus -} /* extern "C" */ -#endif +//typedef PtrWrapper BlkPtr; +typedef blk* BlkPtr; + +template +class pool_alloc : public blk +{ + public: + void* operator new(size_t s, MemoryPool& p ) + { return p.allocate(s, TYPE); } + void operator delete(void* mem, MemoryPool& p) + { p.deallocate(mem); } + + void* operator new[](size_t s, MemoryPool& p) + { return p.allocate(s, TYPE); } + void operator delete[](void* mem, MemoryPool& p) + { p.deallocate(mem); } + + void operator delete(void* mem) { MemoryPool::deallocate(mem); } + void operator delete[](void* mem) { MemoryPool::deallocate(mem); } + +private: + /* These operators are off-limits */ + void* operator new(size_t s) { return 0; } + void* operator new[](size_t s) { return 0; } +}; + +template +class pool_alloc_rpt : public blk +{ + public: + void* operator new(size_t s, MemoryPool& p, int rpt) + { return p.allocate(s + sizeof(RPT)*rpt, TYPE); } + void operator delete(void* mem, MemoryPool& p,int rpt) + { p.deallocate(mem); } + void operator delete(void* mem) { MemoryPool::deallocate(mem); } + + private: + // These operations are not supported on static repeat-base objects + void* operator new[](size_t s, MemoryPool& p) + { return 0; } + void operator delete[](void* mem, MemoryPool& p) + { } + void operator delete[](void* mem) { } + +private: + /* These operators are off-limits */ + void* operator new(size_t s) { return 0; } + void* operator new[](size_t s) { return 0; } +}; + +/* template +class vector_rpt : public BASE +{ + private: + MemoryPool::allocator rptAllocator; + vector_rpt(int size, MemoryPool& pool) + : rptAllocator(pool, TYPE), rpt(size, rptAllocator) {} + + public: + std::vector rpt; + + static vector_rpt* allocate(int size, MemoryPool& p) + { return new(p) vector_rpt(size,p); } +}; */ #endif /* INCLUDE_FB_BLK */ diff --git a/src/include/fb_exception.h b/src/include/fb_exception.h new file mode 100644 index 0000000000..ad69522bd9 --- /dev/null +++ b/src/include/fb_exception.h @@ -0,0 +1,72 @@ +// +// Copyright (c) 2001 M. Nordell +// +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + */ +// +// Special permission is given to the Firebird project to include, +// use and modify this file in the Firebird database engine. +// +#ifndef FB_EXCEPTION_H +#define FB_EXCEPTION_H + +#include +#include "fb_types.h" + + +namespace Firebird { + +class status_longjmp_error : public std::exception +{ +public: + explicit status_longjmp_error(STATUS s) + : m_s(s) + {} + virtual ~status_longjmp_error() {} + virtual const char* what() const + { return "Firebird::status_longjmp_error"; } + STATUS value() const { return m_s; } + + // TMN: to be moved into its own source file! + static void raise(STATUS s) { throw status_longjmp_error(s); } + +private: + STATUS m_s; +}; + +class red_zone_error : public std::exception +{ +public: + virtual const char* what() const + { return "Firebird::red_zone_error"; } + + // TMN: to be moved into its own source file! + static void raise() { throw red_zone_error(); } +}; + +class memory_corrupt : public std::exception +{ +public: + virtual const char* what() const + { return "Firebird::memory_corrupt"; } + + // TMN: to be moved into its own source file! + static void raise() { throw memory_corrupt(); } +}; + +} // namespace Firebird + +#endif // FB_EXCEPTION_H diff --git a/src/include/fb_string.h b/src/include/fb_string.h new file mode 100644 index 0000000000..4ed5b6f8fc --- /dev/null +++ b/src/include/fb_string.h @@ -0,0 +1,24 @@ +/* + * fb_string.h + * firebird_test + * + * Created by john on Fri Dec 14 2001. + * Copyright (c) 2001 __MyCompanyName__. All rights reserved. + * + */ + +#ifndef FB_STRING_H +#define FB_STRING_H + +#include "../include/fb_types.h" +#include "../common/memory/allocators.h" + +#include + +namespace Firebird +{ + typedef std::basic_string, + Firebird::allocator > string; +}; + +#endif // FB_STRING_H diff --git a/src/include/fb_types.h b/src/include/fb_types.h index 76571f9e16..a01194ba13 100644 --- a/src/include/fb_types.h +++ b/src/include/fb_types.h @@ -27,7 +27,7 @@ * Mark O'Donohue * * - * $Id: fb_types.h,v 1.2 2001-07-29 17:19:15 skywalker Exp $ + * $Id: fb_types.h,v 1.3 2001-12-24 02:50:49 tamlin Exp $ * */ @@ -117,7 +117,28 @@ typedef struct GDS_QUAD_t GDS_QUAD; #endif /* DEFINED_GDS_QUAD */ +// +// TMN: some misc data types from all over the place +// +struct vary +{ + SSHORT vary_length; + char vary_string[1]; +}; +// TMN: Currently we can't do this, since remote uses a different +// definition of VARY than the rest of the code! :-< +//typedef vary* VARY; +struct lstring +{ + ULONG lstr_length; + ULONG lstr_allocated; + UCHAR* lstr_address; +}; +typedef struct lstring LSTRING; + + +typedef unsigned char BOOLEAN; typedef char TEXT; /* To be expunged over time */ typedef unsigned char STEXT; /* Signed text - very rare */ typedef unsigned char UTEXT; /* Unsigned text - common */ @@ -148,5 +169,4 @@ typedef USHORT FLD_LENGTH; #define GDS_STATUS long - #endif /* INCLUDE_FB_TYPES_H */ diff --git a/src/include/fb_vector.h b/src/include/fb_vector.h new file mode 100644 index 0000000000..9e37a88cd8 --- /dev/null +++ b/src/include/fb_vector.h @@ -0,0 +1,34 @@ +/* + * fb_vector.h + * firebird_test + * + * Created by john on Fri Dec 14 2001. + * Copyright (c) 2001 __MyCompanyName__. All rights reserved. + * + */ + +#ifndef FB_VECTOR_H +#define FB_VECTOR_H + +#include "../include/fb_types.h" +#include "../common/memory/allocators.h" + +#include + +namespace Firebird +{ + template + class vector : public std::vector > + { + public: + vector(int len) : std::vector >(len) {} + vector(int len, MemoryPool &p, SSHORT type = 0) + : std::vector >(len, T(), + Firebird::allocator(p, type)) {} + vector(MemoryPool &p, SSHORT type = 0) + : std::vector >( + Firebird::allocator(p, type) ) {} + }; +}; + +#endif // FB_VECTOR_H diff --git a/src/include/firebird.h b/src/include/firebird.h index ee7c1757af..a9e288e917 100644 --- a/src/include/firebird.h +++ b/src/include/firebird.h @@ -30,12 +30,15 @@ * John Bellardo * * - * $Id: firebird.h,v 1.1 2001-07-29 17:19:15 skywalker Exp $ + * $Id: firebird.h,v 1.2 2001-12-24 02:50:49 tamlin Exp $ * */ #include "gen/autoconfig.h" +#ifdef __cplusplus +#include "fb_exception.h" +#endif #endif /* INCLUDE_Firebird */ diff --git a/src/include/old_fb_blk.h b/src/include/old_fb_blk.h new file mode 100644 index 0000000000..6320499f94 --- /dev/null +++ b/src/include/old_fb_blk.h @@ -0,0 +1,26 @@ +#ifndef INCLUDE_FB_BLK +#define INCLUDE_FB_BLK + +#define INCLUDE_OLD_FB_BLK + +#ifndef JRD_COMMON_H +#include "../jrd/common.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct blk +{ + UCHAR blk_type; + UCHAR blk_pool_id; + USHORT blk_length; +} *BLK; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* INCLUDE_FB_BLK */ diff --git a/src/install/arch-specific/darwin/FrameworkInfo.plist b/src/install/arch-specific/darwin/FrameworkInfo.plist index a2005d1f87..13951bb174 100644 --- a/src/install/arch-specific/darwin/FrameworkInfo.plist +++ b/src/install/arch-specific/darwin/FrameworkInfo.plist @@ -5,9 +5,9 @@ CFBundleDevelopmentRegion English CFBundleExecutable - Firebird + Firebird2 CFBundleIdentifier - com.firebird.Firebird + com.firebird.Firebird2 CFBundleInfoDictionaryVersion __VERSION__ CFBundlePackageType diff --git a/src/install/arch-specific/linux/Makefile.in b/src/install/arch-specific/linux/Makefile.in index cbde946e3a..a96607136e 100644 --- a/src/install/arch-specific/linux/Makefile.in +++ b/src/install/arch-specific/linux/Makefile.in @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in,v 1.2 2001-08-15 18:10:35 skywalker Exp $ +# $Id: Makefile.in,v 1.3 2001-12-24 02:50:50 tamlin Exp $ # #RedhatPackageDir=/usr/src/redhat/RPMS/i386 diff --git a/src/ipserver/ipc.h b/src/ipserver/ipc.h index d0f6c6e95e..4960168c56 100644 --- a/src/ipserver/ipc.h +++ b/src/ipserver/ipc.h @@ -139,7 +139,7 @@ typedef struct bid { /* Block types */ #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif /* Block types */ diff --git a/src/ipserver/ipserver.cpp b/src/ipserver/ipserver.cpp index e246b5d851..a9238af304 100644 --- a/src/ipserver/ipserver.cpp +++ b/src/ipserver/ipserver.cpp @@ -549,15 +549,21 @@ static void ipi_end_thread( ICC icc) { UnmapViewOfFile(ipm->ipm_address); CloseHandle(ipm->ipm_handle); - if (ipserver_private_data.ipms == ipm) + + if (ipserver_private_data.ipms == ipm){ ipserver_private_data.ipms = ipm->ipm_next; - else - for (pipm = ipserver_private_data.ipms; pipm->ipm_next; pipm = pipm->ipm_next) + } else { + for (pipm = ipserver_private_data.ipms; + pipm->ipm_next; + pipm = pipm->ipm_next) + { if (pipm->ipm_next == ipm) { pipm->ipm_next = ipm->ipm_next; break; } + } + } ALLI_free((UCHAR *) ipm); } @@ -585,22 +591,14 @@ static void ipi_server( ICC icc) **************************************/ ips_comm_area *comm; TEXT *comm_ptr; - JMP_BUF env; -#ifdef IP_TRACE - char line[200]; -#endif - /* start this thread */ + // start this thread gds__thread_enable(-1); /* error handler */ - if (SETJMP(env)) - { - gds__log("ipi_server: error during startup, shutting down"); - return; - } + try { /* request processing loop */ @@ -611,10 +609,13 @@ static void ipi_server( ICC icc) GET_COMM_OBJECT; comm->ips_ops_count++; #ifdef IP_TRACE - sprintf(line, "%8lX %8lX %8lX %d ipserver %s", - (long) GetCurrentThreadId(), (long) icc, - comm, comm->ips_operation, op_strings[comm->ips_operation]); - gds__log(line); + { + char line[200]; + sprintf(line, "%8lX %8lX %8lX %d ipserver %s", + (long) GetCurrentThreadId(), (long) icc, + comm, comm->ips_operation, op_strings[comm->ips_operation]); + gds__log(line); + } #endif switch (comm->ips_operation) { @@ -796,6 +797,11 @@ static void ipi_server( ICC icc) shutdown_attachments(icc); ipi_end_thread(icc); + + } // try + catch (...) { + gds__log("ipi_server: error during startup, shutting down"); + } } @@ -845,8 +851,9 @@ static void allocate_statement( ICC icc) statement->isr_packed = NULL; idb->idb_sql_requests = statement; } - else + else { ips->ips_st_handle = NULL; + } send_response(icc, status_vector); } diff --git a/src/isql/extract.epp b/src/isql/extract.epp index 15eefd13e6..41e7b9d08a 100644 --- a/src/isql/extract.epp +++ b/src/isql/extract.epp @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: extract.epp,v 1.3 2001-08-27 15:29:18 skywalker Exp $ + * $Id: extract.epp,v 1.4 2001-12-24 02:50:50 tamlin Exp $ * Revision 1.3 2000/11/22 17:07:25 patrickgriffin * In get_procedure_args change comment style from // to c style * @@ -74,7 +74,7 @@ static void list_generators(void); static void list_index(void); static void list_views(void); -static void get_procedure_args(SCHAR *); +static void get_procedure_args(char*); #define MAX_INTSUBTYPES 2 #define MAXSUBTYPES 8 @@ -794,7 +794,7 @@ void EXTRACT_list_view( SCHAR * viewname) #endif -static void get_procedure_args( SCHAR * proc_name) +static void get_procedure_args(char* proc_name) { /************************************** * @@ -808,7 +808,6 @@ static void get_procedure_args( SCHAR * proc_name) * **************************************/ SSHORT ptype, first_time, i, header = TRUE; - TEXT msg[MSG_LENGTH]; SCHAR char_sets[86]; /* query to retrieve the parameters. */ @@ -1146,9 +1145,8 @@ static void list_all_procs() * procname -- Name of procedure to investigate * **************************************/ - SSHORT first_time, i, header = TRUE; + SSHORT header = TRUE; TEXT msg[MSG_LENGTH]; - SCHAR char_sets[86]; static CONST SCHAR *create_procedure_str1 = "CREATE PROCEDURE %s "; static CONST SCHAR *create_procedure_str2 = "BEGIN EXIT; END %s%s"; diff --git a/src/isql/isql.epp b/src/isql/isql.epp index 7e5ad91e34..b0f29dc430 100644 --- a/src/isql/isql.epp +++ b/src/isql/isql.epp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* - $Id: isql.epp,v 1.5 2001-10-17 22:48:01 bellardo Exp $ + $Id: isql.epp,v 1.6 2001-12-24 02:50:50 tamlin Exp $ Revision 1.5 2000/11/18 16:49:24 fsg Increased PRINT_BUFFER_LENGTH to 2048 to show larger plans Fixed Bug #122563 in extract.e get_procedure_args @@ -31,12 +31,19 @@ 2001/05/20 Neil McCalden add planonly option */ +#ifdef DARWIN +#define _STLP_CCTYPE +#endif + #include "firebird.h" #include "../jrd/ib_stdio.h" #include #include #include #include +#ifdef DARWIN +#include +#endif #include #include @@ -288,7 +295,7 @@ static RI_ACTIONS ri_actions_all[] = { #ifndef GUI_TOOLS -int CLIB_ROUTINE main( int argc, char *argv[]) +int CLIB_ROUTINE main(int argc, char* argv[]) { /************************************** * @@ -323,7 +330,7 @@ int CLIB_ROUTINE main( int argc, char *argv[]) Exit_value = ISQL_main(argc, argv); - exit(Exit_value); + return Exit_value; } #endif @@ -2365,8 +2372,10 @@ static SSHORT add_row(TEXT * tabname) * **************************************/ SSHORT n_cols, length, type, nullable, i, j, i_cols, done; - SCHAR string[BUFFER_LENGTH120], name[WORDLENGTH], - buffer[BUFFER_LENGTH512], infobuf[BUFFER_LENGTH180]; + SCHAR string[BUFFER_LENGTH120]; + SCHAR name[WORDLENGTH]; + // SCHAR buffer[BUFFER_LENGTH512]; + SCHAR infobuf[BUFFER_LENGTH180]; SCHAR *insertstring = NULL, *stringvalue = NULL, cmd[5]; SSHORT *nullind = NULL, *nullp; /* Data types */ @@ -2375,7 +2384,7 @@ static SSHORT add_row(TEXT * tabname) SLONG *integer; SINT64 *pi64, n; float *fvalue; - double *dvalue, numeric; + double *dvalue; SCHAR bfile[120]; struct tm times; XSQLDA *sqlda = NULL, *isqlda; @@ -2977,7 +2986,7 @@ static SSHORT copy_table( TEXT * source, TEXT * destination, TEXT * otherdb) * **************************************/ IB_FILE *holdout; - TEXT *p, ftmp[128]; + TEXT ftmp[128]; TEXT errbuf[MSG_LENGTH]; TEXT cmd[512]; TEXT *altdb; @@ -3001,7 +3010,7 @@ static SSHORT copy_table( TEXT * source, TEXT * destination, TEXT * otherdb) process! So we will get a temp name on our own. [Note that gds__temp_file returns -1 on error, not 0] */ - p = tempnam(NULL, SCRATCH); + TEXT p = tempnam(NULL, SCRATCH); strcpy(ftmp, p); free(p); Out = ib_fopen(ftmp, "w+"); @@ -3325,7 +3334,7 @@ static void do_isql(void) * Process incoming SQL statements * **************************************/ - TEXT *p; + TEXT *statement = NULL; TEXT *errbuf; USHORT bufsize = 0; @@ -3350,14 +3359,16 @@ static void do_isql(void) process! So we will get a temp name on our own. [Note that gds__temp_file returns -1 on error, not 0] */ - p = tempnam(NULL, SCRATCH); + TEXT* p = tempnam(NULL, SCRATCH); strcpy(Tmpfile, p); free(p); Ofp = ib_fopen(Tmpfile, "w+"); - if (!Ofp) + if (!Ofp) { Ofp = (IB_FILE *) - 1; + } #endif - if (Ofp == (IB_FILE *) - 1) { + if (Ofp == (IB_FILE *) - 1) + { /* If we can't open a temp file then bail */ gds__msg_format(NULL_PTR, ISQL_MSG_FAC, FILE_OPEN_ERR, MSG_LENGTH, @@ -3729,7 +3740,9 @@ static int end_trans(void) * Returns success or failure. * **************************************/ - TEXT buffer[BUFFER_LENGTH80], infobuf[BUFFER_LENGTH60]; + + // TEXT buffer[BUFFER_LENGTH80]; + TEXT infobuf[BUFFER_LENGTH60]; int ret; ret = CONT; @@ -3879,10 +3892,10 @@ static SSHORT frontend( TEXT * statement) * Parameters: statement is the string typed by the user * **************************************/ - TEXT *p, *a, *cmd, *q; + TEXT *p, *a, *cmd; TEXT *parms[MAX_TERMS], *lparms[MAX_TERMS], *buffer, *errbuf; SSHORT lgth, i, j, length; - SSHORT ret = SKIP, slen; + SSHORT ret = SKIP; TEXT *psw, *usr, *numbufs, *sql_role_nm; TEXT end_quote; SCHAR *dialect_str; @@ -6403,7 +6416,6 @@ static SSHORT print_item( TEXT ** s, XSQLVAR * var, SLONG printlength) SSHORT dscale; struct tm times; SLONG length; - double numeric, exponent; ISC_QUAD blobid; TEXT blobbuf[30]; @@ -6521,8 +6533,8 @@ static SSHORT print_item( TEXT ** s, XSQLVAR * var, SLONG printlength) if (dscale) { /* Handle floating scale and precision */ - numeric = *(SQUAD *) (var->sqldata); - exponent = -dscale; + double numeric = *(SQUAD *) (var->sqldata); + double exponent = -dscale; numeric = numeric / pow(10.0, exponent); sprintf(p, "%*.*f ", (int) length, (int) -dscale, numeric); if (List) { diff --git a/src/isql/isql.h b/src/isql/isql.h index 62ed448a57..2e5b825917 100644 --- a/src/isql/isql.h +++ b/src/isql/isql.h @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: isql.h,v 1.3 2001-08-27 15:29:18 skywalker Exp $ + * $Id: isql.h,v 1.4 2001-12-24 02:50:50 tamlin Exp $ * Revision 1.2 2000/11/18 16:49:24 fsg * Increased PRINT_BUFFER_LENGTH to 2048 to show larger plans * Fixed Bug #122563 in extract.e get_procedure_args @@ -263,10 +263,7 @@ static SCHAR *alpha_months[] = { "DEC" }; -typedef struct vary { - SSHORT vary_length; - SCHAR vary_string[1]; -} VARY; +typedef vary VARY; typedef struct sqltypes { SSHORT type; diff --git a/src/isql/show.epp b/src/isql/show.epp index dfb127f451..c27e3b2a27 100644 --- a/src/isql/show.epp +++ b/src/isql/show.epp @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: show.epp,v 1.3 2001-08-27 15:29:18 skywalker Exp $ + * $Id: show.epp,v 1.4 2001-12-24 02:50:50 tamlin Exp $ * Revision 1.2 2000/11/19 07:02:49 fsg * Change in show.e to use CHARACTER_LENGTH instead of FIELD_LENGTH in * SHOW PROCEDURE @@ -64,8 +64,8 @@ extern USHORT minor_ods; extern SSHORT V4; extern SSHORT V33; -static void *local_fprintf(UCHAR *, UCHAR *); -static SCHAR *remove_delimited_double_quotes(TEXT *); +static void local_fprintf(const char*, const char*); +static void remove_delimited_double_quotes(TEXT *); static void make_priv_string(USHORT, UCHAR *); static int show_all_tables(SSHORT); static void show_charsets(SCHAR *, SCHAR *); @@ -910,9 +910,8 @@ void SHOW_grant_roles( SCHAR * terminator) * All membership privilege may have the with_admin option set. * **************************************/ - SCHAR with_option[18]; - SCHAR user_string[44]; - SCHAR role_name[44]; + char with_option[18]; + char user_string[44]; /* process role "object" */ @@ -964,7 +963,12 @@ void SHOW_print_metadata_text_blob( IB_FILE * fp, ISC_QUAD * blobid) **************************************/ isc_blob_handle blob_handle; USHORT length; - UCHAR *buffer, *b, *start; + UCHAR* buffer; + +#ifdef GUI_TOOLS + UCHAR* b; + UCHAR* start; +#endif /* Don't bother with null blobs */ @@ -1383,7 +1387,7 @@ int SHOW_metadata( SCHAR ** cmd, SCHAR ** lcmd) } -static void *local_fprintf( UCHAR * format, UCHAR * string) +static void local_fprintf(const char* format, const char* string) { /************************************** * @@ -1407,7 +1411,7 @@ static void *local_fprintf( UCHAR * format, UCHAR * string) } -static SCHAR *remove_delimited_double_quotes( TEXT * string) +static void remove_delimited_double_quotes(TEXT* string) { /************************************** * @@ -3205,7 +3209,6 @@ static int show_table( SCHAR * relation_name) * **************************************/ SSHORT i, subtype; - ISC_QUAD default_source; SCHAR *collist; SSHORT first = TRUE; diff --git a/src/journal/archive.cpp b/src/journal/archive.cpp index ca3c5967e2..e56270fe40 100644 --- a/src/journal/archive.cpp +++ b/src/journal/archive.cpp @@ -28,7 +28,7 @@ #include "../jrd/common.h" #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../wal/wal.h" diff --git a/src/journal/gjrn.cpp b/src/journal/gjrn.cpp index 6dd3227251..36b51399d7 100644 --- a/src/journal/gjrn.cpp +++ b/src/journal/gjrn.cpp @@ -151,8 +151,7 @@ int CLIB_ROUTINE main( int argc, argc -= 4; } - if (exit_code = setjmp(gjrn_env)) - exit(exit_code); + try { s_argc = argc; s_argv = argv; @@ -205,6 +204,11 @@ int CLIB_ROUTINE main( int argc, exit(FINI_ERROR); else exit(FINI_OK); + + } // try + catch (const Firebird::status_longjmp_error& e) { + exit(e.value()); + } } @@ -229,7 +233,7 @@ void GJRN_abort( int number) gjrn_msg_partial(0, 0, 0, 0, 0, 0); /* msg 0: gbak:: */ GJRN_printf(1, NULL, NULL, NULL, NULL); /* msg 1: exiting journal utility due to errors */ - longjmp(gjrn_env, FINI_ERROR); + Firebird::status_longjmp_error::raise(FINI_ERROR); } @@ -437,7 +441,7 @@ static int start_disable( int argc, SCHAR ** argv) if ((*argv)[0] != '-') { if (database) { GJRN_printf(12, database, NULL, NULL, NULL); /* msg 12: database file name (%s) already specified */ - longjmp(gjrn_env, FINI_ERROR); + Firebird::status_longjmp_error::raise(FINI_ERROR); } database = *argv++; continue; @@ -536,7 +540,7 @@ static int start_dump( int argc, SCHAR ** argv) if ((*argv)[0] != '-') { if (database) { GJRN_printf(12, database, NULL, NULL, NULL); /* msg 12: database file name (%s) already specified */ - longjmp(gjrn_env, FINI_ERROR); + Firebird::status_longjmp_error::raise(FINI_ERROR); } database = *argv++; continue; @@ -571,7 +575,7 @@ static int start_dump( int argc, SCHAR ** argv) old_file_size = atoi(*argv++); if (old_file_size <= 0) { GJRN_printf(16, NULL, NULL, NULL, NULL); /* msg 16: online dump file size must be greater than zero */ - longjmp(gjrn_env, FINI_ERROR); + Firebird::status_longjmp_error::raise(FINI_ERROR); } } else @@ -695,7 +699,7 @@ static int start_dump( int argc, SCHAR ** argv) if (handle) gds__detach_database(status_vector, GDS_REF(handle)); - longjmp(gjrn_env, FINI_ERROR); + Firebird::status_longjmp_error::raise(FINI_ERROR); } if (handle) @@ -755,7 +759,7 @@ static int start_enable( int argc, SCHAR ** argv) if ((*argv)[0] != '-') { if (database) { GJRN_printf(12, database, NULL, NULL, NULL); /* msg 12: database file name (%s) already specified */ - longjmp(gjrn_env, FINI_ERROR); + Firebird::status_longjmp_error::raise(FINI_ERROR); } database = *argv++; continue; diff --git a/src/journal/misc.cpp b/src/journal/misc.cpp index e24997bc95..8aea46dc9a 100644 --- a/src/journal/misc.cpp +++ b/src/journal/misc.cpp @@ -39,7 +39,7 @@ #include "../journal/journal.h" #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../jrd/jrn.h" diff --git a/src/journal/server.e b/src/journal/server.e index a69d892736..ece90a9b58 100644 --- a/src/journal/server.e +++ b/src/journal/server.e @@ -44,7 +44,7 @@ /* Block types */ #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../jrd/jrn.h" diff --git a/src/jrd/ail.cpp b/src/jrd/ail.cpp index 62f3bcba96..8731f0113c 100644 --- a/src/jrd/ail.cpp +++ b/src/jrd/ail.cpp @@ -211,7 +211,7 @@ void AIL_commit(SLONG number) /* Prepare WAL message */ - MOVE_CLEAR(&commit_rec, LTJC_SIZE); + MOVE_CLEAR((SLONG*)&commit_rec, LTJC_SIZE); commit_rec.ltjc_header.jrnh_type = JRN_COMMIT; commit_rec.ltjc_header.jrnh_length = LTJC_SIZE; @@ -497,7 +497,7 @@ void AIL_enable( for (i = 0; i < number; i++) if (!(log_files[i]->lg_flags & LOG_serial)) { for (i = 0; i < number; i++) - ALL_release(reinterpret_cast < frb * >(log_files[i])); + delete log_files[i]; ERR_post(gds_no_archive, 0); } } @@ -639,8 +639,8 @@ void AIL_get_file_list(LLS * stack) continue; temp_fname = LOGF_NAME(logf); fname_term_length = strlen(temp_fname) + 1; - fname = (STR) ALLOCPV(type_str, fname_term_length); - MOVE_FAST(temp_fname, fname->str_data, fname_term_length); + fname = new(*dbb->dbb_permanent, fname_term_length) str(); + MOVE_FAST(temp_fname, (SCHAR*)fname->str_data, fname_term_length); LLS_PUSH(fname, stack); } } @@ -675,8 +675,8 @@ void AIL_get_file_list(LLS * stack) while (TRUE) { if (!(log_flags & WALFH_RAW)) { fname_term_length = strlen(curr_name) + 1; - fname = (STR) ALLOCPV(type_str, fname_term_length); - MOVE_FAST(curr_name, fname->str_data, fname_term_length); + fname = new(*dbb->dbb_permanent, fname_term_length) str(); + MOVE_FAST(curr_name, (SCHAR*)fname->str_data, fname_term_length); LLS_PUSH(fname, stack); } @@ -1054,7 +1054,7 @@ void AIL_recover_page(SLONG page_no, PAG page) for (p = logp->log_data; (*p != LOG_ctrl_file1); p += 2 + p[1]); - MOVE_FAST(p + 2, rwal, logp->log_cp_1.cp_fn_length); + MOVE_FAST((SCHAR*)(p + 2), rwal, logp->log_cp_1.cp_fn_length); rwal[logp->log_cp_1.cp_fn_length] = 0; @@ -1216,7 +1216,7 @@ void AIL_upd_cntrl_pt( *p++ = LOG_ctrl_file2; p++; q = reinterpret_cast < UCHAR * >(walname); - if (len = w_len) + if ( (len = w_len) ) do *p++ = *q++; while (--len); @@ -1230,7 +1230,7 @@ void AIL_upd_cntrl_pt( p = p3 + 2; q = reinterpret_cast < UCHAR * >(walname); - if (len = w_len) + if ( (len = w_len) ) do *p++ = *q++; while (--len); @@ -1548,7 +1548,7 @@ USHORT activate_shadow, SBM * sbm_rec) /* Do some initial actions for setting up page */ - if (first_time = logp->log_flags & log_add) + if ( (first_time = logp->log_flags & log_add) ) set_first_user(log_files, logp, walname); else get_walinfo(walname); @@ -1627,7 +1627,7 @@ USHORT activate_shadow, SBM * sbm_rec) */ for (i = 0; i < number; i++) - ALL_release(reinterpret_cast < frb * >(log_files[i])); + delete log_files[i]; #endif } @@ -1711,7 +1711,7 @@ USHORT activate_shadow, SBM * sbm_rec) for (p = logp->log_data; (*p != LOG_ctrl_file1); p += 2 + p[1]); - MOVE_FAST(p + 2, rwal, logp->log_cp_1.cp_fn_length); + MOVE_FAST((SCHAR*)(p + 2), rwal, logp->log_cp_1.cp_fn_length); rwal[logp->log_cp_1.cp_fn_length] = 0; @@ -1727,7 +1727,7 @@ USHORT activate_shadow, SBM * sbm_rec) win.win_flags = 0; hdr = (HDR) CCH_FETCH(tdbb, &win, LCK_read, pag_header); for (p = hdr->hdr_data; (*p != HDR_root_file_name); p += 2 + p[1]); - MOVE_FAST(p + 2, root_db, p[1]); + MOVE_FAST((SCHAR*)(p + 2), root_db, p[1]); root_db[p[1]] = 0; CCH_RELEASE(tdbb, &win); REC_recover(root_db, rwal, &cp1, sbm_rec, activate_shadow); @@ -1798,15 +1798,15 @@ static void set_first_user(LGFILE ** log_files, LIP logp, TEXT * walname) for (p = logp->log_data; (*p != LOG_end); p += 2 + p[1]) { switch (*p) { case LOG_ctrl_file1: - MOVE_FAST(walname, p + 2, len); + MOVE_FAST(walname, (SCHAR*)(p + 2), len); break; case LOG_ctrl_file2: - MOVE_FAST(walname, p + 2, len); + MOVE_FAST(walname, (SCHAR*)(p + 2), len); break; case LOG_logfile: - MOVE_FAST(walname, p + 2, len); + MOVE_FAST(walname, (SCHAR*)(p + 2), len); break; } } diff --git a/src/jrd/align.cpp b/src/jrd/align.cpp index 6b22007385..a93d727d64 100644 --- a/src/jrd/align.cpp +++ b/src/jrd/align.cpp @@ -17,7 +17,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: align.cpp,v 1.2 2001-07-29 17:42:21 skywalker Exp $ +$Id: align.cpp,v 1.3 2001-12-24 02:50:50 tamlin Exp $ */ #include "firebird.h" @@ -137,26 +137,24 @@ static int check_double() long vector[3]; #endif - if (SETJMP(env)) + try { + signal(SIGBUS, handler); + signal(SIGSEGV, handler); + p = (double *) &vector[0]; + *p = 3; + *p *= 2.5; + p = (double *) &vector[1]; + *p = 3; + *p *= 2.5; + } + catch(...) { return 1; - - signal(SIGBUS, handler); - signal(SIGSEGV, handler); - p = (double *) &vector[0]; - *p = 3; - *p *= 2.5; - p = (double *) &vector[1]; - *p = 3; - *p *= 2.5; + } return 0; } -#ifdef __STDC__ -static void handler(void) -#else static void handler() -#endif { - LONGJMP(env, 1); + Firebird::status_longjmp_error::raise(1); } diff --git a/src/jrd/all.cpp b/src/jrd/all.cpp index 9cc0c86350..37fa1783af 100644 --- a/src/jrd/all.cpp +++ b/src/jrd/all.cpp @@ -42,178 +42,28 @@ #include "../jrd/mov_proto.h" #include "../jrd/thd_proto.h" -#define BLKDEF(type, root, tail) { sizeof (struct root), tail }, - -extern "C" { - - -static const struct { - SSHORT typ_root_length; - SSHORT typ_tail_length; -} block_sizes[] = { - {0, 0}, -#ifndef GATEWAY -#include "../jrd/blk.h" -#else -#include ".._gway/gway/blk.h" -#endif - {0, 0} -}; - -#undef BLKDEF - #ifdef SUPERSERVER +extern "C" { extern SLONG trace_pools; +} SLONG all_delta_alloc = 0; -#define BLKDEF(type, root, tail) 0, - -SLONG all_block_type_count[] = { -#include "../jrd/blk.h" - 0 -}; -#undef BLKDEF - -#define BLKDEF(type, root, tail) #type, -const char ALL_types[][24] = { - "type_MIN", -#include "../jrd/blk.h" - "type_MAX" -}; -#undef BLKDEF - #endif // SUPERSERVER -static BLK alloc_huge_hunk(PLB, UCHAR, ULONG, ERR_T); -static BOOLEAN extend_pool(PLB, ULONG, ERR_T); -static ULONG find_block_length(BLK); -static PLB find_pool(BLK); -static void release(FRB, PLB); - #ifdef SHLIB_DEFS #define strlen (*_libgds_strlen) extern int strlen(); #endif - -BLK ALL_alloc(PLB pool, UCHAR type, ULONG count_argument, ERR_T err_ret) -{ -/************************************** - * - * A L L _ a l l o c - * - ************************************** - * - * Functional description - * Allocate a block from a given pool and initialize the block. - * This is the primary block allocation routine. - * - **************************************/ - register BLK block; - FRB free, *best, *ptr; - ULONG size, count; - SLONG best_tail, tail; - USHORT units; - -/* this is a kludge to allow OS/2 to accept the - incoming argument as an int but do calculations - like everybody else -- this avoids changing a lot of source */ - - count = count_argument; - - if (type <= (UCHAR) type_MIN || type >= (UCHAR) type_MAX) - BUGCHECK(150); /* msg 150 request to allocate invalid block type */ - -/* Compute block length */ - - size = block_sizes[type].typ_root_length; - - if ((tail = block_sizes[type].typ_tail_length) && count >= FUDGE) - size += (count - FUDGE) * tail; - - size = (size + MIN_ALLOC - 1) & ~((ULONG) MIN_ALLOC - 1); -/* TMN: Here we should really have the following assert */ -/* assert((size >> SHIFT) <= MAX_USHORT); */ - units = (USHORT) (size >> SHIFT); - - if (size >= MAX_BLOCK) - return alloc_huge_hunk(pool, type, size, err_ret); - -/* Find best fit. Best fit is defined to be the free block of shortest - tail. If there isn't a fit, extend the pool and try, try again. */ - - while (TRUE) { - V4_MUTEX_LOCK(pool->plb_mutex); - - best = NULL; - best_tail = MAX_BLOCK; - for (ptr = &pool->plb_free; (free = *ptr); ptr = &free->frb_next) { - if ((SCHAR HUGE_PTR *) free >= (SCHAR HUGE_PTR *) free->frb_next - && free->frb_next) { - V4_MUTEX_UNLOCK(pool->plb_mutex); - BUGCHECK(152); /* msg 152 memory pool free list is invalid */ - } - if ((tail = (ULONG) free->frb_header.blk_length - (ULONG) units) - >= 0 && tail < best_tail) { - best = ptr; - best_tail = tail; - if (tail == 0) - break; - } - } - if (best) - break; - - V4_MUTEX_UNLOCK(pool->plb_mutex); - if (!extend_pool(pool, size, err_ret)) - return 0; - } - -/* We've got our free block. If there's enough left of the free block - after taking out our block, chop out out block. If not, allocate - the entire free block as our block (a little extra won't hurt). */ - - best_tail <<= SHIFT; - free = *best; - - if (best_tail > sizeof(struct frb)) { - block = - (BLK) ((SCHAR *) free + (free->frb_header.blk_length << SHIFT)); - block = (BLK) ((SCHAR *) block - size); - free->frb_header.blk_length -= units; - } - else { - *best = free->frb_next; - units = free->frb_header.blk_length; - size = units << SHIFT; - block = (BLK) free; - } - -#ifdef SUPERSERVER - if (trace_pools) { - ++all_block_type_count[type]; - ++pool->plb_blk_type_count[type]; - } -#endif - - V4_MUTEX_UNLOCK(pool->plb_mutex); - - MOVE_CLEAR(block, size); - block->blk_type = type; -/* TMN: Here we should really have the following assert */ -/* assert(pool->plb_pool_id <= MAX_UCHAR); */ - block->blk_pool_id = (UCHAR) pool->plb_pool_id; - block->blk_length = units; - - return block; -} +#define PERM_EXTEND_SIZE (16 * 1024) +#define CACH_EXTEND_SIZE (16 * 1024) #ifdef DEV_BUILD -void ALL_check_memory(void) +void ALL_check_memory() { /************************************** * @@ -233,30 +83,21 @@ void ALL_check_memory(void) * executed. * **************************************/ - DBB dbb; - VEC vector; - PLB pool; - USHORT pool_id; - HNK hunk; - dbb = GET_DBB; + Firebird::vector::iterator itr; + + DBB Dbb = GET_DBB; V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_read); -/* walk through all the pools in the database */ - - vector = dbb->dbb_pools; - for (pool_id = 0; pool_id < vector->vec_count; pool_id++) { - pool = (PLB) vector->vec_object[pool_id]; - if (!pool) - continue; - - /* walk through all the hunks in the pool */ - - V4_MUTEX_LOCK(pool->plb_mutex); - for (hunk = pool->plb_hunks; hunk; hunk = hunk->hnk_next); - for (hunk = pool->plb_huge_hunks; hunk; hunk = hunk->hnk_next); - V4_MUTEX_UNLOCK(pool->plb_mutex); + // walk through all the pools in the database + for (itr = Dbb->dbb_pools.begin(); itr < Dbb->dbb_pools.end(); ++itr) + { + JrdMemoryPool* pool = *itr; + if (pool) { + // walk through all the hunks in the pool + pool->verify_pool(); + } } V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); @@ -264,7 +105,7 @@ void ALL_check_memory(void) #endif /* DEV_BUILD */ -TEXT *ALL_cstring(TEXT * in_string) +TEXT* ALL_cstring(TEXT* in_string) { /************************************** * @@ -279,7 +120,7 @@ TEXT *ALL_cstring(TEXT * in_string) * **************************************/ TDBB tdbb; - struct plb *pool; + JrdMemoryPool *pool; TEXT *p, *q; STR string; ULONG length; @@ -299,7 +140,7 @@ TEXT *ALL_cstring(TEXT * in_string) } length = strlen(in_string); - string = (STR) ALL_alloc(pool, type_str, length, ERR_jmp); + string = (STR) pool->allocate(type_str, length); /* TMN: Here we should really have the following assert */ /* assert(length <= MAX_USHORT); */ string->str_length = (USHORT) length; @@ -315,49 +156,6 @@ TEXT *ALL_cstring(TEXT * in_string) } -BLK ALL_extend(BLK* pointer, ULONG size) -{ -/************************************** - * - * A L L _ e x t e n d - * - ************************************** - * - * Functional description - * Extend a repeating block, copying the constant part. - * NOTE: This routine does not lock any mutexes on - * its own behalf. It is assumed that mutexes will - * have been locked before entry. - * - **************************************/ - BLK block, new_; - PLB pool; - ULONG old_length, new_length; - - block = *pointer; - pool = find_pool(block); - new_ = ALL_alloc(pool, block->blk_type, size, ERR_jmp); - - if (!(old_length = block->blk_length << SHIFT)) - old_length = find_block_length(block); - if (!(new_length = new_->blk_length << SHIFT)) - new_length = find_block_length(new_); - MOVE_FASTER((SCHAR *) block + sizeof(struct blk), - (SCHAR *) new_ + sizeof(struct blk), - MIN(old_length, new_length) - sizeof(struct blk)); - release(reinterpret_cast < frb * >(block), pool); - - if (new_->blk_type == (UCHAR) type_vec) - ((VEC) new_)->vec_count = size; - else if (new_->blk_type == (UCHAR) type_vcl) - ((VCL) new_)->vcl_count = size; - - *pointer = new_; - - return new_; -} - - void ALL_fini(void) { /************************************** @@ -377,117 +175,11 @@ void ALL_fini(void) * **************************************/ DBB dbb; - VEC pools; - register PLB pool, *vector, *until; - register HNK hunks, hunk; dbb = GET_DBB; - pools = dbb->dbb_pools; - -/* We release the database block simply to invalidate it's block type. */ - - ALL_release(reinterpret_cast < frb * >(dbb)); - - until = (PLB *) pools->vec_object; - for (vector = until + pools->vec_count; --vector >= until;) - if (pool = *vector) { -#ifdef SUPERSERVER - if (trace_pools && pool->plb_blk_type_count) { - int i = 0; - for (i = 0; i < type_MAX; i++) - all_block_type_count[i] -= pool->plb_blk_type_count[i]; - gds__free(pool->plb_blk_type_count); - } -#endif - for (hunks = pool->plb_huge_hunks; hunk = hunks;) { - hunks = hunk->hnk_next; - gds__sys_free(hunk->hnk_address); - } - for (hunks = pool->plb_hunks; hunk = hunks;) { - hunks = hunk->hnk_next; -#ifdef SUPERSERVER - all_delta_alloc -= gds__free(hunk->hnk_address); -#else - gds__free(hunk->hnk_address); -#endif - } - } -} - - -void ALL_free(SCHAR * memory) -{ -/************************************** - * - * A L L _ f r e e - * - ************************************** - * - * Functional description - * Give space back to internal memory heap. - * The process retains the memory for quick - * reallocations. - * - **************************************/ - DBB dbb; - - dbb = GET_DBB; - - V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); - -#ifdef SUPERSERVER - { - SLONG freed; - freed = gds__free(memory); - dbb->dbb_current_memory -= freed; - all_delta_alloc -= freed; - } -#else - dbb->dbb_current_memory -= gds__free(memory); -#endif - - V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); -} - - -ULONG ALL_get_free_object(PLB pool, VEC * vector_ptr, USHORT increment) -{ -/************************************** - * - * A L L _ g e t _ f r e e _ o b j e c t - * - ************************************** - * - * Functional description - * Find a free slot in a vector. If no - * slot is available, extend the vector. - * - **************************************/ - VEC vector; - ULONG slot; - BLK *ptr, *end; - - if (!(vector = *vector_ptr)) { - vector = *vector_ptr = - (VEC) ALL_alloc(pool, type_vec, increment, ERR_jmp); - vector->vec_count = increment; - slot = 0; - } - else { - BLKCHK(vector, type_vec); - for (ptr = vector->vec_object, end = ptr + vector->vec_count; - ptr < end && *ptr; ptr++); - if (ptr < end) - slot = ptr - vector->vec_object; - else { - slot = vector->vec_count; - ALL_extend(reinterpret_cast < blk ** >(vector_ptr), - slot + increment); - } - } - - return slot; + /* Don't know if we even need to do this, so it is commented out */ + //delete dbb; } @@ -508,151 +200,20 @@ void ALL_init(void) **************************************/ TDBB tdbb; DBB dbb; - SLONG temp_vector[20]; - VEC vector; - PLB pool; + JrdMemoryPool* pool; tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; - dbb->dbb_pools = vector = (VEC) temp_vector; - vector->vec_count = 1; - vector->vec_object[0] = NULL; + pool = tdbb->tdbb_default = dbb->dbb_permanent; + dbb->dbb_permanent->setExtendSize(PERM_EXTEND_SIZE); + dbb->dbb_pools[0] = pool; - tdbb->tdbb_default = dbb->dbb_permanent = pool = ALL_pool(); - dbb->dbb_pools = vector = (VEC) ALL_alloc(pool, type_vec, 10, ERR_jmp); - vector->vec_count = 10; - vector->vec_object[0] = (BLK) pool; - - dbb->dbb_bufferpool = ALL_pool(); + dbb->dbb_bufferpool = new(*pool) JrdMemoryPool(CACH_EXTEND_SIZE); + dbb->dbb_pools[1] = dbb->dbb_bufferpool; } - -SCHAR *ALL_malloc(ULONG size, ERR_T err_ret) -{ -/************************************** - * - * A L L _ m a l l o c - * - ************************************** - * - * Functional description - * Get memory from internal memory heap. - * - **************************************/ - DBB dbb; - register SCHAR *memory; - - if (memory = (SCHAR *) gds__alloc((SLONG) (size))) { - /* FREE: Done at attachment detach, process exit, and other misc times */ - - dbb = GET_DBB; - - V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); -#ifdef SUPERSERVER - all_delta_alloc += size; -#endif - dbb->dbb_current_memory += size; - if (dbb->dbb_current_memory > dbb->dbb_max_memory) - dbb->dbb_max_memory = dbb->dbb_current_memory; - V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); - return memory; - } - -/* NOMEM: post user level error */ - if (err_ret == ERR_jmp) - ERR_post(gds_sys_request, gds_arg_string, "gds__alloc", gds_arg_gds, - gds_virmemexh, 0); - - return NULL; -} - - -PLB ALL_pool(void) -{ -/************************************** - * - * A L L _ p o o l - * - ************************************** - * - * Functional description - * Allocate a new pool. This is done by creating a tempory - * pool block on the stack, then allocating a real pool block. - * In USHORT, by mirrors. - * - **************************************/ - DBB dbb; - struct plb temp_pool; - register VEC vector; - register PLB pool; - register USHORT pool_id; - - dbb = GET_DBB; - - V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_write); - -/* Start by assigning a pool id */ - - vector = dbb->dbb_pools; - - for (pool_id = 0; pool_id < vector->vec_count; pool_id++) - if (!(vector->vec_object[pool_id])) - break; - - if (pool_id >= vector->vec_count) - vector = - (VEC) ALL_extend(reinterpret_cast < blk ** >(&dbb->dbb_pools), - pool_id + 10); - - vector->vec_object[pool_id] = (BLK) & temp_pool; - temp_pool.plb_free = NULL; - temp_pool.plb_hunks = NULL; - temp_pool.plb_pool_id = pool_id; - temp_pool.plb_extend_size = MIN_ALLOCATION; - temp_pool.plb_blk_type_count = NULL; -#ifdef SUPERSERVER - if (trace_pools) { - temp_pool.plb_blk_type_count = - (SLONG *) gds__alloc(sizeof(all_block_type_count)); - if (!temp_pool.plb_blk_type_count) - trace_pools = 0; /* No memmory!! stop tracing pool info */ - else - memset(temp_pool.plb_blk_type_count, 0, - sizeof(all_block_type_count)); - } -#endif - V4_MUTEX_INIT(temp_pool.plb_mutex); - if (pool_id == 0) { - dbb->dbb_permanent = &temp_pool; - temp_pool.plb_extend_size = PERM_EXTEND_SIZE; - } - if (pool_id == 1) - temp_pool.plb_extend_size = CACH_EXTEND_SIZE; - - pool = (PLB) ALL_alloc(&temp_pool, type_plb, 0, ERR_jmp); - pool->plb_pool_id = pool_id; - pool->plb_extend_size = temp_pool.plb_extend_size; - pool->plb_free = temp_pool.plb_free; - pool->plb_hunks = temp_pool.plb_hunks; -#ifdef SUPERSERVER - pool->plb_blk_type_count = temp_pool.plb_blk_type_count; -#endif - vector->vec_object[pool_id] = (BLK) pool; - - V4_MUTEX_DESTROY(temp_pool.plb_mutex); - V4_MUTEX_INIT(pool->plb_mutex); - - V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); - - if (pool_id == 0) - dbb->dbb_permanent = pool; - - return pool; -} - - -void ALL_push(BLK object, register LLS * stack) +void JrdMemoryPool::ALL_push(BLK object, register LLS * stack) { /************************************** * @@ -666,30 +227,19 @@ void ALL_push(BLK object, register LLS * stack) **************************************/ TDBB tdbb; register LLS node; - PLB pool; + JrdMemoryPool* pool; tdbb = GET_THREAD_DATA; pool = tdbb->tdbb_default; - - V4_MUTEX_LOCK(pool->plb_mutex); - - if (node = pool->plb_lls) { - pool->plb_lls = node->lls_next; - V4_MUTEX_UNLOCK(pool->plb_mutex); - } - else { - V4_MUTEX_UNLOCK(pool->plb_mutex); - node = (LLS) ALL_alloc(pool, type_lls, 0, ERR_jmp); - } - + node = pool->lls_cache.newBlock(); node->lls_object = object; node->lls_next = *stack; *stack = node; } -BLK ALL_pop(register LLS * stack) +BLK JrdMemoryPool::ALL_pop(register LLS *stack) { /************************************** * @@ -703,26 +253,24 @@ BLK ALL_pop(register LLS * stack) * **************************************/ register LLS node; - register PLB pool; + JrdMemoryPool* pool; BLK object; node = *stack; *stack = node->lls_next; object = node->lls_object; - pool = find_pool((BLK) node); - V4_MUTEX_LOCK(pool->plb_mutex); - node->lls_next = pool->plb_lls; - pool->plb_lls = node; - V4_MUTEX_UNLOCK(pool->plb_mutex); + pool = (JrdMemoryPool*)MemoryPool::blk_pool(node); + pool->lls_cache.returnBlock(node); return object; } #ifdef SUPERSERVER -void ALL_print_memory_pool_info(IB_FILE * fptr, DBB databases) +void ALL_print_memory_pool_info(IB_FILE* fptr, DBB databases) { +#if 0 /*********************************************************** * * A L L _ p r i n t _ m e m o r y _ p o o l _ i n f o @@ -737,596 +285,89 @@ void ALL_print_memory_pool_info(IB_FILE * fptr, DBB databases) DBB dbb; STR string; VEC vector; - PLB myPool; HNK hnk; ATT att; int i, j, k, col; ib_fprintf(fptr, "\n\tALL_xx block types\n"); ib_fprintf(fptr, "\t------------------"); - for (i = 0, col = 0; i < type_MAX; i++) - if (all_block_type_count[i]) { + for (i = 0, col = 0; i < types->type_MAX; i++) { + if (types->all_block_type_count[i]) { if (col % 5 == 0) ib_fprintf(fptr, "\n\t"); - ib_fprintf(fptr, "%s = %d ", ALL_types[i], - all_block_type_count[i]); + ib_fprintf(fptr, "%s = %d ", types->ALL_types[i], + types->all_block_type_count[i]); ++col; } + } ib_fprintf(fptr, "\n"); + // TMN: Note. Evil code. for (i = 0, dbb = databases; dbb; dbb = dbb->dbb_next, ++i); ib_fprintf(fptr, "\tNo of dbbs = %d\n", i); - for (k = 1, dbb = databases; dbb; dbb = dbb->dbb_next, ++k) { + + for (k = 1, dbb = databases; dbb; dbb = dbb->dbb_next, ++k) + { string = dbb->dbb_filename; ib_fprintf(fptr, "\n\t dbb%d -> %s\n", k, string->str_data); vector = (VEC) dbb->dbb_pools; - for (j = 0, i = 0; i < (int) vector->vec_count; i++) { - myPool = (PLB) vector->vec_object[i]; - if (myPool) + j = 0; + for (pool_vec_type::iterator itr = dbb->dbb_pools.begin(); + itr != dbb->dbb_pools.end(); ++itr) + { + PLB myPool = *itr; + if (myPool) { ++j; + } } ib_fprintf(fptr, "\t %s has %d pools", string->str_data, j); for (j = 0, att = dbb->dbb_attachments; att; att = att->att_next) + { j++; + } ib_fprintf(fptr, " and %d attachment(s)", j); - for (i = 0; i < (int) vector->vec_count; i++) { - myPool = (PLB) vector->vec_object[i]; - if (!myPool) + for (i = 0; i < (int) vector->vec_count; i++) + { + PLB myPool = (PLB) vector->vec_object[i]; + if (!myPool) { continue; + } ib_fprintf(fptr, "\n\t Pool %d", myPool->plb_pool_id); - for (j = 0, hnk = myPool->plb_hunks; hnk; hnk = hnk->hnk_next) - j++; - if (j) + + // Count # of hunks + for (j = 0, hnk = myPool->plb_hunks; hnk; hnk = hnk->hnk_next) { + ++j; + } + if (j) { ib_fprintf(fptr, " has %d hunks", j); - for (j = 0, hnk = myPool->plb_huge_hunks; hnk; - hnk = hnk->hnk_next) j++; - if (j) + } + j = 0; + + // Count # of "huge" hunks + for (hnk = myPool->plb_huge_hunks; hnk; hnk = hnk->hnk_next) + { + ++j; + } + if (j) { ib_fprintf(fptr, " and %d huge_hunks", j); + } ib_fprintf(fptr, " Extend size is %d", myPool->plb_extend_size); - for (j = 0, col = 0; j < type_MAX; j++) - if (myPool->plb_blk_type_count[j]) { + for (j = 0, col = 0; j < types->type_MAX; j++) + { + if (myPool->plb_blk_type_count[j]) + { if (col % 5 == 0) + { ib_fprintf(fptr, "\n\t "); - ib_fprintf(fptr, "%s = %d ", ALL_types[j], + } + ib_fprintf(fptr, "%s = %d ", types->ALL_types[j], myPool->plb_blk_type_count[j]); ++col; } - } - } -} -#endif - - -void ALL_release(register FRB block) -{ -/************************************** - * - * A L L _ r e l e a s e - * - ************************************** - * - * Functional description - * Release a block to its pool. If it is contiguous to - * another free block, combine them. Otherwise link it - * into the free block linked list (kept in ascending order - * of addresses). - * - **************************************/ - -/* TMN: Here we should probably have the following assert */ -/* assert(block); */ - release(block, find_pool(block ? &block->frb_header : (BLK) 0)); -} - - -void ALL_rlpool(PLB pool) -{ -/************************************** - * - * A L L _ r l p o o l - * - ************************************** - * - * Functional description - * Release a storage pool. This involves nothing more than returning - * hunks to the free hunk list. - * - **************************************/ - DBB dbb; - register HNK hunks, hunk; - - dbb = GET_DBB; - - V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_write); - dbb->dbb_pools->vec_object[pool->plb_pool_id] = NULL; - V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); - - V4_MUTEX_DESTROY(pool->plb_mutex); - -#ifdef SUPERSERVER - if (trace_pools && pool->plb_blk_type_count) { - int i = 0; - for (i = 0; i < type_MAX; i++) - all_block_type_count[i] -= pool->plb_blk_type_count[i]; - gds__free(pool->plb_blk_type_count); - } -#endif - - for (hunks = pool->plb_huge_hunks; hunk = hunks;) { - hunks = hunk->hnk_next; - ALL_sys_free(hunk->hnk_address); - } - for (hunks = pool->plb_hunks; hunk = hunks;) { - hunks = hunk->hnk_next; - ALL_free(hunk->hnk_address); - } -} - - -SCHAR *ALL_sys_alloc(ULONG size, ERR_T err_ret) -{ -/************************************** - * - * A L L _ s y s _ a l l o c - * - ************************************** - * - * Functional description - * Get memory from OS in such a way - * that it can be freed back to OS. - * - **************************************/ - DBB dbb; - register SCHAR *memory; - - if (memory = (SCHAR *) gds__sys_alloc((SLONG) size)) { - /* FREE: Done at attachment detach, process exit, and other misc times */ - - dbb = GET_DBB; - - V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); - dbb->dbb_current_memory += size; - if (dbb->dbb_current_memory > dbb->dbb_max_memory) - dbb->dbb_max_memory = dbb->dbb_current_memory; - V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); - return memory; - } - -/* NOMEM: post user level error */ - if (err_ret == ERR_jmp) - ERR_post(gds_sys_request, gds_arg_string, "gds__sys_alloc", - gds_arg_gds, gds_virmemexh, 0); - - return NULL; -} - - -void ALL_sys_free(SCHAR * memory) -{ -/************************************** - * - * A L L _ s y s _ f r e e - * - ************************************** - * - * Functional description - * Give space back to OS ... really! - * - **************************************/ - DBB dbb; - - dbb = GET_DBB; - - V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); - - dbb->dbb_current_memory -= gds__sys_free(memory); - - V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); -} - - -ULONG ALL_tail(UCHAR type) -{ -/************************************** - * - * A L L _ t a i l - * - ************************************** - * - * Functional description - * Compute maximum repeating tail count. - * - **************************************/ - ULONG root, tail; - - if (type <= (UCHAR) type_MIN || type >= (SCHAR) type_MAX) - BUGCHECK(150); /* msg 150 request to allocate invalid block type */ - -/* Compute repeating tail count */ - - root = block_sizes[type].typ_root_length; - if (!(tail = block_sizes[type].typ_tail_length)) - return 0; - - return ((MAX_BLOCK - MIN_ALLOC - root) / tail) + FUDGE; -} - - -VEC ALL_vector(PLB pool, VEC* ptr, USHORT count) -{ -/************************************** - * - * A L L _ v e c t o r - * - ************************************** - * - * Functional description - * Allocate, extend, or no-op a vector making sure it is "long enough". - * NOTE: This routine does not lock any mutexes on - * its own behalf. It is assumed that mutexes will - * have been locked before entry. - * - **************************************/ - VEC vector; - - ++count; - - if (!(vector = *ptr)) { - vector = *ptr = (VEC) ALL_alloc(pool, type_vec, count, ERR_jmp); - vector->vec_count = count; - return vector; - } - - BLKCHK(vector, type_vec); - - if (vector->vec_count >= count) - return vector; - - return (VEC) ALL_extend(reinterpret_cast < blk ** >(ptr), count); -} - - -static BLK alloc_huge_hunk(PLB pool, UCHAR type, ULONG size, ERR_T err_ret) -{ -/************************************** - * - * a l l o c _ h u g e _ h u n k - * - ************************************** - * - * Functional description - * Allocate a hunk of memory larger than - * MAX_BLOCK. Link it into a special - * list of huge hunks belonging to the pool. - * - **************************************/ - HNK hunk; - BLK block; - ULONG minimum_size; - - minimum_size = size + sizeof(struct hnk); - size = - (minimum_size + MIN_ALLOCATION - 1) & ~((ULONG) MIN_ALLOCATION - 1); - - if (!(hunk = (HNK) ALL_sys_alloc((ULONG) size, err_ret))) - return 0; - hunk->hnk_header.blk_length = sizeof(struct hnk) >> SHIFT; - hunk->hnk_header.blk_type = (UCHAR) type_hnk; -/* TMN: Here we should really have the following assert */ -/* assert(pool->plb_pool_id <= MAX_UCHAR); */ - hunk->hnk_header.blk_pool_id = (UCHAR) pool->plb_pool_id; - hunk->hnk_address = (SCHAR *) hunk; - hunk->hnk_length = size; - V4_MUTEX_LOCK(pool->plb_mutex); - hunk->hnk_next = pool->plb_huge_hunks; - pool->plb_huge_hunks = hunk; - V4_MUTEX_UNLOCK(pool->plb_mutex); - - block = (BLK) (hunk + 1); - MOVE_CLEAR(block, size - sizeof(struct hnk)); - block->blk_length = 0; - block->blk_type = type; -/* TMN: Here we should really have the following assert */ -/* assert(pool->plb_pool_id <= MAX_UCHAR); */ - block->blk_pool_id = (UCHAR) pool->plb_pool_id; - - return block; -} - - -static BOOLEAN extend_pool(PLB pool, ULONG size, ERR_T err_ret) -{ -/************************************** - * - * e x t e n d _ p o o l - * - ************************************** - * - * Functional description - * Extend a pool by at least enough to accomodate a block - * of given size. - * - **************************************/ - register HNK hunk; - register BLK block; - ULONG minimum_size, extend_size; - - minimum_size = size + sizeof(struct hnk); - -/* Keep minimum allocation roundup for blocks larger than pool - extend size. */ - - extend_size = (ULONG) pool->plb_extend_size; - if (extend_size < minimum_size) - extend_size = MIN_ALLOCATION; - - size = (minimum_size + extend_size - 1) & ~(extend_size - 1); - - if (!(block = (BLK) ALL_malloc((ULONG) size, err_ret))) - return FALSE; -/* TMN: Here we should really have the following assert */ -/* assert((size >> SHIFT) <= MAX_USHORT); */ - block->blk_length = (USHORT) (size >> SHIFT); - block->blk_type = (UCHAR) type_frb; -/* TMN: Here we should really have the following assert */ -/* assert(pool->plb_pool_id <= MAX_UCHAR); */ - block->blk_pool_id = (UCHAR) pool->plb_pool_id; -#ifdef SUPERSERVER - if (trace_pools) { - ++all_block_type_count[block->blk_type]; - ++pool->plb_blk_type_count[block->blk_type]; - } -#endif - release(reinterpret_cast < frb * >(block), pool); - - if (!(hunk = (HNK) ALL_alloc(pool, type_hnk, 0, err_ret))) - return FALSE; - hunk->hnk_address = (SCHAR *) block; - hunk->hnk_length = size; - - V4_MUTEX_LOCK(pool->plb_mutex); - hunk->hnk_next = pool->plb_hunks; - pool->plb_hunks = hunk; - V4_MUTEX_UNLOCK(pool->plb_mutex); - return TRUE; -} - - -static ULONG find_block_length(BLK block) -{ -/************************************** - * - * f i n d _ b l o c k _ l e n g t h - * - ************************************** - * - * Functional description - * The blocks that are associated with huge - * hunks always have a zero block length. - * Their length can be determined indirectly, - * using the length of the hunk. - * - **************************************/ - HNK hunk; - - hunk = (HNK) block - 1; - - return (hunk->hnk_length - sizeof(struct hnk)); -} - - -static PLB find_pool(BLK block) -{ -/************************************** - * - * f i n d _ p o o l - * - ************************************** - * - * Functional description - * Find pool associate with block. - * - **************************************/ - DBB dbb; - VEC pools; - PLB pool; - HNK hunk; - USHORT pool_id, huge_flag; -#ifdef V4_THREADING - USHORT dbb_pool_flag; -#endif - - dbb = GET_DBB; - -#ifdef V4_THREADING - if (!(dbb_pool_flag = (block == (BLK) dbb->dbb_pools))) - V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_read); -#endif - - pools = dbb->dbb_pools; - -/* Turn on this optimization someday */ - - if (pools->vec_count < 256) - if ((pool_id = block->blk_pool_id) < pools->vec_count && - (pool = (PLB) pools->vec_object[pool_id])) { -#ifdef V4_THREADING - if (!dbb_pool_flag) - V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); -#endif - return pool; - } - else { -#ifdef V4_THREADING - if (!dbb_pool_flag) - V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); -#endif - BUGCHECK(153); - } - - huge_flag = (block->blk_length) ? FALSE : TRUE; - - for (pool_id = block->blk_pool_id; pool_id < pools->vec_count; - pool_id += 256) - if (pool = (PLB) pools->vec_object[pool_id]) { - hunk = (huge_flag) ? pool->plb_huge_hunks : pool->plb_hunks; - for (; hunk; hunk = hunk->hnk_next) - if ((SCHAR HUGE_PTR *) block >= - (SCHAR HUGE_PTR *) hunk->hnk_address - && (SCHAR HUGE_PTR *) block < - (SCHAR HUGE_PTR *) hunk->hnk_address + hunk->hnk_length) { -#ifdef V4_THREADING - if (!dbb_pool_flag) - V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); -#endif - return pool; - } - } - -#ifdef V4_THREADING - if (!dbb_pool_flag) - V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); -#endif - BUGCHECK(153); /* msg 153 invalid pool id encountered */ -/* Harbor Software: */ -/* this code should not be reached. */ - return NULL; -} - - -static void release(FRB block, PLB pool) -{ -/************************************** - * - * r e l e a s e - * - ************************************** - * - * Functional description - * Release a block to its pool. If it is contiguous to - * another free block, combine them. Otherwise link it - * into the free block linked list (kept in ascending order - * of addresses). - * - **************************************/ - register FRB prior, free; - FRB *ptr; - ULONG length; -#ifdef SUPERSERVER - UCHAR blk_header_type; -#endif - - V4_MUTEX_LOCK(pool->plb_mutex); - - if (!block->frb_header.blk_length) { - /* A block with no length indicates a HUGE hunk. Find it and free it. */ - - HNK hunk, *ptr; - - for (ptr = &pool->plb_huge_hunks; hunk = *ptr; ptr = &hunk->hnk_next) - if ((SCHAR *) block >= (SCHAR *) hunk->hnk_address && - (SCHAR *) block < - (SCHAR *) hunk->hnk_address + hunk->hnk_length) { - *ptr = hunk->hnk_next; - V4_MUTEX_UNLOCK(pool->plb_mutex); - ALL_sys_free(hunk->hnk_address); - return; } - V4_MUTEX_UNLOCK(pool->plb_mutex); - BUGCHECK(154); /* msg 154 attempt to release free block */ - } - -#ifdef SUPERSERVER - blk_header_type = block->frb_header.blk_type; -#endif - block->frb_header.blk_type = (UCHAR) type_frb; - prior = NULL; - -#ifdef DEBUG_GDS_ALLOC -/* Debugging code to erase memory locations after a release - - * this will assist in catching dangling memory references to - * freed locations. - * Note that the header parts of the freed block may still be used, - * for the free chain, so we don't zap those locations. - */ - -/* Pattern to set "released" memory to */ -#define ALL_RELEASED_FREE_PATTERN 0xBB - { - ULONG units, size; - units = block->frb_header.blk_length; - size = (units << SHIFT) - sizeof(*block); - memset(((UCHAR *) block) + sizeof(*block), ALL_RELEASED_FREE_PATTERN, - size); - }; -#endif /* DEBUG_GDS_ALLOC */ - - for (ptr = &pool->plb_free; free = *ptr; - prior = free, ptr = - &free->frb_next) if ((SCHAR HUGE_PTR *) block <= - (SCHAR HUGE_PTR *) free) break; - - if ((SCHAR HUGE_PTR *) block == (SCHAR HUGE_PTR *) free) { - V4_MUTEX_UNLOCK(pool->plb_mutex); - BUGCHECK(154); /* msg 154 attempt to release free block */ - } - -/* Merge block into list first, then try to combine blocks */ - - block->frb_next = free; - *ptr = block; - -/* Try to merge the free block with the next one down. */ - - length = block->frb_header.blk_length << SHIFT; - - if (free) { - if ((SCHAR HUGE_PTR *) block + length == (SCHAR HUGE_PTR *) free) { - block->frb_header.blk_length += free->frb_header.blk_length; - block->frb_next = free->frb_next; -#ifdef DEBUG_GDS_ALLOC - /* We've joined the blocks, so paint the header of the merged away - * block as freed. - */ - memset(((UCHAR *) free), ALL_RELEASED_FREE_PATTERN, - sizeof(*free)); -#endif - } - else if ((SCHAR HUGE_PTR *) block + length > (SCHAR HUGE_PTR *) free) { - V4_MUTEX_UNLOCK(pool->plb_mutex); - BUGCHECK(155); /* msg 155 attempt to release block overlapping following free block */ } } - -/* Try and merge the block with the prior free block */ - - if (prior && (length = prior->frb_header.blk_length << SHIFT)) { - if ((SCHAR HUGE_PTR *) prior + length == (SCHAR HUGE_PTR *) block) { - prior->frb_header.blk_length += block->frb_header.blk_length; - prior->frb_next = block->frb_next; -#ifdef DEBUG_GDS_ALLOC - /* We've joined the blocks, so paint the header of the merged away - * block as freed. - */ - memset(((UCHAR *) block), ALL_RELEASED_FREE_PATTERN, - sizeof(*block)); -#endif - } - else if ((SCHAR HUGE_PTR *) prior + length > (SCHAR HUGE_PTR *) block) { - V4_MUTEX_UNLOCK(pool->plb_mutex); - BUGCHECK(156); /* msg 156 attempt to release block overlapping prior free block */ - } - } - -#ifdef SUPERSERVER - if (trace_pools) { - --all_block_type_count[blk_header_type]; - --pool->plb_blk_type_count[blk_header_type]; - } -#endif - - V4_MUTEX_UNLOCK(pool->plb_mutex); +#endif // 0 } +#endif // SUPERSERVER - -} // extern "C" diff --git a/src/jrd/all.h b/src/jrd/all.h index eb3c32b1ee..52cc489642 100644 --- a/src/jrd/all.h +++ b/src/jrd/all.h @@ -21,81 +21,46 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_ALL_H_ -#define _JRD_ALL_H_ +#ifndef JRD_ALL_H +#define JRD_ALL_H -#if ALIGNMENT == 8 -#define MIN_ALLOC 8 -#else -#define MIN_ALLOC 4 +#include "../jrd/jrd.h" +#include "../common/memory/allocators.h" +#include "../jrd/block_cache.h" +#include "../jrd/lls.h" + +TEXT* ALL_cstring(TEXT* in_string); +void ALL_fini(void); +void ALL_init(void); +//void ALL_push(BLK , LLS *); +//BLK ALL_pop(LLS *); +void ALL_print_memory_pool_info(IB_FILE*, class dbb*); + +#ifdef DEV_BUILD +void ALL_check_memory(void); #endif -/* MAX_BLOCK for OS/2 is calculated by taking the max memory - available in a segment (65534 bytes), subtracting 4 bytes - for a length, 8 bytes for a free block, and 2 bytes to - allow rounding to a 4 byte boundary */ +class JrdMemoryPool : public MemoryPool +{ +public: + JrdMemoryPool(int extSize = 0, MemoryPool* p = FB_MemoryPool) + : MemoryPool(extSize, p), + plb_buckets(0), + plb_segments(0), + plb_dccs(0), + lls_cache(*this) + { + } -#if (defined PC_PLATFORM && !defined NETWARE_386) -#define MAX_BLOCK 65520 -#else -#define MAX_BLOCK (262144 - MIN_ALLOCATION - sizeof (struct hnk) - 8) -#endif + static class blk* ALL_pop(class lls**); + static void ALL_push(class blk*, class lls**); -#define FUDGE 1 + struct sbm* plb_buckets; /* available bit map buckets */ + struct bms* plb_segments; /* available bit map segments */ + struct Dcc* plb_dccs; -#define SHIFT SHIFTLONG +private: + BlockCache lls_cache; /* Was plb_lls */ +}; -#define MIN_ALLOCATION 1024 /* Minimum allocation from operating system */ - -/* Prevent shared memory pools from fragmenting into very long - free block lists. Any hunk residual larger than a free block - structure will lengthen the free list. A larger extend size - reduces the number of times the pool is extended and reduces - the length of the free block list. */ - -#ifdef SUPERSERVER -#define PERM_EXTEND_SIZE (16 * MIN_ALLOCATION) -#define CACH_EXTEND_SIZE (16 * MIN_ALLOCATION) -#else -#define PERM_EXTEND_SIZE MIN_ALLOCATION -#define CACH_EXTEND_SIZE MIN_ALLOCATION -#endif - -#define EXTEND(vector_count) vector_count + vector_count % 10 - - - -/* Free block */ - -typedef struct frb { - struct blk frb_header; - struct frb *frb_next; /* Next free block in pool */ -} *FRB; - -/* Pool block */ - -typedef struct plb { - struct blk plb_header; - USHORT plb_pool_id; /* pool id */ - USHORT plb_extend_size; /* pool extend size */ - struct frb *plb_free; /* first free block */ - struct hnk *plb_hunks; /* first hunk block */ - struct hnk *plb_huge_hunks; /* first huge hunk block (blocks > MAX_BLOCK) */ - struct lls *plb_lls; /* available linked list stack nodes */ - struct dcc *plb_dccs; /* available data compression control blocks */ - struct sbm *plb_buckets; /* available bit map buckets */ - struct bms *plb_segments; /* available bit map segments */ - MUTX plb_mutex[1]; - SLONG *plb_blk_type_count; /* array to keep track of block types */ -} *PLB; - -/* Hunk blocks */ - -typedef struct hnk { - struct blk hnk_header; - SCHAR *hnk_address; /* start of memory hunk */ - SLONG hnk_length; /* length of memory hunk */ - struct hnk *hnk_next; /* next memory hunk in structure */ -} *HNK; - -#endif /* _JRD_ALL_H_ */ +#endif // JRD_ALL_H diff --git a/src/jrd/all_old.cpp b/src/jrd/all_old.cpp new file mode 100644 index 0000000000..9cc0c86350 --- /dev/null +++ b/src/jrd/all_old.cpp @@ -0,0 +1,1332 @@ +/* + * PROGRAM: JRD Access Method + * MODULE: all.c + * DESCRIPTION: Internal block allocator + * + * The contents of this file are subject to the Interbase Public + * License Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy + * of the License at http://www.Inprise.com/IPL.html + * + * Software distributed under the License is distributed on an + * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express + * or implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code was created by Inprise Corporation + * and its predecessors. Portions created by Inprise Corporation are + * Copyright (C) Inprise Corporation. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + */ + +#ifdef SHLIB_DEFS +#define LOCAL_SHLIB_DEFS +#endif + +#include "firebird.h" +#include +#include "../jrd/ib_stdio.h" + +#include "gen/codes.h" + +#ifndef GATEWAY +#include "../jrd/everything.h" +#else +#include ".._gway/gway/everything.h" +#endif +#include "../jrd/all_proto.h" +#include "../jrd/err_proto.h" +#include "../jrd/gds_proto.h" +#include "../jrd/mov_proto.h" +#include "../jrd/thd_proto.h" + +#define BLKDEF(type, root, tail) { sizeof (struct root), tail }, + +extern "C" { + + +static const struct { + SSHORT typ_root_length; + SSHORT typ_tail_length; +} block_sizes[] = { + {0, 0}, +#ifndef GATEWAY +#include "../jrd/blk.h" +#else +#include ".._gway/gway/blk.h" +#endif + {0, 0} +}; + +#undef BLKDEF + +#ifdef SUPERSERVER + +extern SLONG trace_pools; +SLONG all_delta_alloc = 0; + +#define BLKDEF(type, root, tail) 0, + +SLONG all_block_type_count[] = { +#include "../jrd/blk.h" + 0 +}; +#undef BLKDEF + +#define BLKDEF(type, root, tail) #type, +const char ALL_types[][24] = { + "type_MIN", +#include "../jrd/blk.h" + "type_MAX" +}; +#undef BLKDEF + +#endif // SUPERSERVER + + +static BLK alloc_huge_hunk(PLB, UCHAR, ULONG, ERR_T); +static BOOLEAN extend_pool(PLB, ULONG, ERR_T); +static ULONG find_block_length(BLK); +static PLB find_pool(BLK); +static void release(FRB, PLB); + +#ifdef SHLIB_DEFS +#define strlen (*_libgds_strlen) + +extern int strlen(); +#endif + + +BLK ALL_alloc(PLB pool, UCHAR type, ULONG count_argument, ERR_T err_ret) +{ +/************************************** + * + * A L L _ a l l o c + * + ************************************** + * + * Functional description + * Allocate a block from a given pool and initialize the block. + * This is the primary block allocation routine. + * + **************************************/ + register BLK block; + FRB free, *best, *ptr; + ULONG size, count; + SLONG best_tail, tail; + USHORT units; + +/* this is a kludge to allow OS/2 to accept the + incoming argument as an int but do calculations + like everybody else -- this avoids changing a lot of source */ + + count = count_argument; + + if (type <= (UCHAR) type_MIN || type >= (UCHAR) type_MAX) + BUGCHECK(150); /* msg 150 request to allocate invalid block type */ + +/* Compute block length */ + + size = block_sizes[type].typ_root_length; + + if ((tail = block_sizes[type].typ_tail_length) && count >= FUDGE) + size += (count - FUDGE) * tail; + + size = (size + MIN_ALLOC - 1) & ~((ULONG) MIN_ALLOC - 1); +/* TMN: Here we should really have the following assert */ +/* assert((size >> SHIFT) <= MAX_USHORT); */ + units = (USHORT) (size >> SHIFT); + + if (size >= MAX_BLOCK) + return alloc_huge_hunk(pool, type, size, err_ret); + +/* Find best fit. Best fit is defined to be the free block of shortest + tail. If there isn't a fit, extend the pool and try, try again. */ + + while (TRUE) { + V4_MUTEX_LOCK(pool->plb_mutex); + + best = NULL; + best_tail = MAX_BLOCK; + for (ptr = &pool->plb_free; (free = *ptr); ptr = &free->frb_next) { + if ((SCHAR HUGE_PTR *) free >= (SCHAR HUGE_PTR *) free->frb_next + && free->frb_next) { + V4_MUTEX_UNLOCK(pool->plb_mutex); + BUGCHECK(152); /* msg 152 memory pool free list is invalid */ + } + if ((tail = (ULONG) free->frb_header.blk_length - (ULONG) units) + >= 0 && tail < best_tail) { + best = ptr; + best_tail = tail; + if (tail == 0) + break; + } + } + if (best) + break; + + V4_MUTEX_UNLOCK(pool->plb_mutex); + if (!extend_pool(pool, size, err_ret)) + return 0; + } + +/* We've got our free block. If there's enough left of the free block + after taking out our block, chop out out block. If not, allocate + the entire free block as our block (a little extra won't hurt). */ + + best_tail <<= SHIFT; + free = *best; + + if (best_tail > sizeof(struct frb)) { + block = + (BLK) ((SCHAR *) free + (free->frb_header.blk_length << SHIFT)); + block = (BLK) ((SCHAR *) block - size); + free->frb_header.blk_length -= units; + } + else { + *best = free->frb_next; + units = free->frb_header.blk_length; + size = units << SHIFT; + block = (BLK) free; + } + +#ifdef SUPERSERVER + if (trace_pools) { + ++all_block_type_count[type]; + ++pool->plb_blk_type_count[type]; + } +#endif + + V4_MUTEX_UNLOCK(pool->plb_mutex); + + MOVE_CLEAR(block, size); + block->blk_type = type; +/* TMN: Here we should really have the following assert */ +/* assert(pool->plb_pool_id <= MAX_UCHAR); */ + block->blk_pool_id = (UCHAR) pool->plb_pool_id; + block->blk_length = units; + + return block; +} + + +#ifdef DEV_BUILD +void ALL_check_memory(void) +{ +/************************************** + * + * A L L _ c h e c k _ m e m o r y + * + ************************************** + * + * Functional description + * This routine goes through all allocated + * memory pools and checks the hunks of + * memory allocated to make sure they are + * valid. It is designed to be used for + * debugging purposes to find bad memory + * areas as soon as they are corrupted. + * A call to this routine can be made from + * looper() to ensure that it will be regularly + * executed. + * + **************************************/ + DBB dbb; + VEC vector; + PLB pool; + USHORT pool_id; + HNK hunk; + + dbb = GET_DBB; + + V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_read); + +/* walk through all the pools in the database */ + + vector = dbb->dbb_pools; + for (pool_id = 0; pool_id < vector->vec_count; pool_id++) { + pool = (PLB) vector->vec_object[pool_id]; + if (!pool) + continue; + + /* walk through all the hunks in the pool */ + + V4_MUTEX_LOCK(pool->plb_mutex); + for (hunk = pool->plb_hunks; hunk; hunk = hunk->hnk_next); + for (hunk = pool->plb_huge_hunks; hunk; hunk = hunk->hnk_next); + V4_MUTEX_UNLOCK(pool->plb_mutex); + } + + V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); +} +#endif /* DEV_BUILD */ + + +TEXT *ALL_cstring(TEXT * in_string) +{ +/************************************** + * + * A L L _ c s t r i n g + * + ************************************** + * + * Functional description + * Copy a stack local string to an allocated + * string so it doesn't disappear before we + * return to the user or where ever. + * + **************************************/ + TDBB tdbb; + struct plb *pool; + TEXT *p, *q; + STR string; + ULONG length; + + tdbb = GET_THREAD_DATA; + + if (!(pool = tdbb->tdbb_default)) { + if (tdbb->tdbb_transaction) + pool = tdbb->tdbb_transaction->tra_pool; + else if (tdbb->tdbb_request) + pool = tdbb->tdbb_request->req_pool; + + /* theoretically this shouldn't happen, but just in case */ + + if (!pool) + return NULL; + } + + length = strlen(in_string); + string = (STR) ALL_alloc(pool, type_str, length, ERR_jmp); +/* TMN: Here we should really have the following assert */ +/* assert(length <= MAX_USHORT); */ + string->str_length = (USHORT) length; + + p = (TEXT *) string->str_data; + q = in_string; + + while (length--) + *p++ = *q++; + *p = 0; + + return (TEXT *) string->str_data; +} + + +BLK ALL_extend(BLK* pointer, ULONG size) +{ +/************************************** + * + * A L L _ e x t e n d + * + ************************************** + * + * Functional description + * Extend a repeating block, copying the constant part. + * NOTE: This routine does not lock any mutexes on + * its own behalf. It is assumed that mutexes will + * have been locked before entry. + * + **************************************/ + BLK block, new_; + PLB pool; + ULONG old_length, new_length; + + block = *pointer; + pool = find_pool(block); + new_ = ALL_alloc(pool, block->blk_type, size, ERR_jmp); + + if (!(old_length = block->blk_length << SHIFT)) + old_length = find_block_length(block); + if (!(new_length = new_->blk_length << SHIFT)) + new_length = find_block_length(new_); + MOVE_FASTER((SCHAR *) block + sizeof(struct blk), + (SCHAR *) new_ + sizeof(struct blk), + MIN(old_length, new_length) - sizeof(struct blk)); + release(reinterpret_cast < frb * >(block), pool); + + if (new_->blk_type == (UCHAR) type_vec) + ((VEC) new_)->vec_count = size; + else if (new_->blk_type == (UCHAR) type_vcl) + ((VCL) new_)->vcl_count = size; + + *pointer = new_; + + return new_; +} + + +void ALL_fini(void) +{ +/************************************** + * + * A L L _ f i n i + * + ************************************** + * + * Functional description + * Get rid of everything. + * NOTE: This routine does not lock any mutexes on + * its own behalf. It is assumed that mutexes will + * have been locked before entry. + * Call gds__free explicitly instead of ALL_free + * because it references the dbb block which gets + * released at the top of this routine. + * + **************************************/ + DBB dbb; + VEC pools; + register PLB pool, *vector, *until; + register HNK hunks, hunk; + + dbb = GET_DBB; + + pools = dbb->dbb_pools; + +/* We release the database block simply to invalidate it's block type. */ + + ALL_release(reinterpret_cast < frb * >(dbb)); + + until = (PLB *) pools->vec_object; + for (vector = until + pools->vec_count; --vector >= until;) + if (pool = *vector) { +#ifdef SUPERSERVER + if (trace_pools && pool->plb_blk_type_count) { + int i = 0; + for (i = 0; i < type_MAX; i++) + all_block_type_count[i] -= pool->plb_blk_type_count[i]; + gds__free(pool->plb_blk_type_count); + } +#endif + for (hunks = pool->plb_huge_hunks; hunk = hunks;) { + hunks = hunk->hnk_next; + gds__sys_free(hunk->hnk_address); + } + for (hunks = pool->plb_hunks; hunk = hunks;) { + hunks = hunk->hnk_next; +#ifdef SUPERSERVER + all_delta_alloc -= gds__free(hunk->hnk_address); +#else + gds__free(hunk->hnk_address); +#endif + } + } +} + + +void ALL_free(SCHAR * memory) +{ +/************************************** + * + * A L L _ f r e e + * + ************************************** + * + * Functional description + * Give space back to internal memory heap. + * The process retains the memory for quick + * reallocations. + * + **************************************/ + DBB dbb; + + dbb = GET_DBB; + + V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); + +#ifdef SUPERSERVER + { + SLONG freed; + freed = gds__free(memory); + dbb->dbb_current_memory -= freed; + all_delta_alloc -= freed; + } +#else + dbb->dbb_current_memory -= gds__free(memory); +#endif + + V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); +} + + +ULONG ALL_get_free_object(PLB pool, VEC * vector_ptr, USHORT increment) +{ +/************************************** + * + * A L L _ g e t _ f r e e _ o b j e c t + * + ************************************** + * + * Functional description + * Find a free slot in a vector. If no + * slot is available, extend the vector. + * + **************************************/ + VEC vector; + ULONG slot; + BLK *ptr, *end; + + if (!(vector = *vector_ptr)) { + vector = *vector_ptr = + (VEC) ALL_alloc(pool, type_vec, increment, ERR_jmp); + vector->vec_count = increment; + slot = 0; + } + else { + BLKCHK(vector, type_vec); + for (ptr = vector->vec_object, end = ptr + vector->vec_count; + ptr < end && *ptr; ptr++); + if (ptr < end) + slot = ptr - vector->vec_object; + else { + slot = vector->vec_count; + ALL_extend(reinterpret_cast < blk ** >(vector_ptr), + slot + increment); + } + } + + return slot; +} + + +void ALL_init(void) +{ +/************************************** + * + * A L L _ i n i t + * + ************************************** + * + * Functional description + * Initialize the pool system. + * NOTE: This routine does not lock any mutexes on + * its own behalf. It is assumed that mutexes will + * have been locked before entry. + * + **************************************/ + TDBB tdbb; + DBB dbb; + SLONG temp_vector[20]; + VEC vector; + PLB pool; + + tdbb = GET_THREAD_DATA; + dbb = tdbb->tdbb_database; + + dbb->dbb_pools = vector = (VEC) temp_vector; + vector->vec_count = 1; + vector->vec_object[0] = NULL; + + tdbb->tdbb_default = dbb->dbb_permanent = pool = ALL_pool(); + dbb->dbb_pools = vector = (VEC) ALL_alloc(pool, type_vec, 10, ERR_jmp); + vector->vec_count = 10; + vector->vec_object[0] = (BLK) pool; + + dbb->dbb_bufferpool = ALL_pool(); +} + + +SCHAR *ALL_malloc(ULONG size, ERR_T err_ret) +{ +/************************************** + * + * A L L _ m a l l o c + * + ************************************** + * + * Functional description + * Get memory from internal memory heap. + * + **************************************/ + DBB dbb; + register SCHAR *memory; + + if (memory = (SCHAR *) gds__alloc((SLONG) (size))) { + /* FREE: Done at attachment detach, process exit, and other misc times */ + + dbb = GET_DBB; + + V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); +#ifdef SUPERSERVER + all_delta_alloc += size; +#endif + dbb->dbb_current_memory += size; + if (dbb->dbb_current_memory > dbb->dbb_max_memory) + dbb->dbb_max_memory = dbb->dbb_current_memory; + V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); + return memory; + } + +/* NOMEM: post user level error */ + if (err_ret == ERR_jmp) + ERR_post(gds_sys_request, gds_arg_string, "gds__alloc", gds_arg_gds, + gds_virmemexh, 0); + + return NULL; +} + + +PLB ALL_pool(void) +{ +/************************************** + * + * A L L _ p o o l + * + ************************************** + * + * Functional description + * Allocate a new pool. This is done by creating a tempory + * pool block on the stack, then allocating a real pool block. + * In USHORT, by mirrors. + * + **************************************/ + DBB dbb; + struct plb temp_pool; + register VEC vector; + register PLB pool; + register USHORT pool_id; + + dbb = GET_DBB; + + V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_write); + +/* Start by assigning a pool id */ + + vector = dbb->dbb_pools; + + for (pool_id = 0; pool_id < vector->vec_count; pool_id++) + if (!(vector->vec_object[pool_id])) + break; + + if (pool_id >= vector->vec_count) + vector = + (VEC) ALL_extend(reinterpret_cast < blk ** >(&dbb->dbb_pools), + pool_id + 10); + + vector->vec_object[pool_id] = (BLK) & temp_pool; + temp_pool.plb_free = NULL; + temp_pool.plb_hunks = NULL; + temp_pool.plb_pool_id = pool_id; + temp_pool.plb_extend_size = MIN_ALLOCATION; + temp_pool.plb_blk_type_count = NULL; +#ifdef SUPERSERVER + if (trace_pools) { + temp_pool.plb_blk_type_count = + (SLONG *) gds__alloc(sizeof(all_block_type_count)); + if (!temp_pool.plb_blk_type_count) + trace_pools = 0; /* No memmory!! stop tracing pool info */ + else + memset(temp_pool.plb_blk_type_count, 0, + sizeof(all_block_type_count)); + } +#endif + V4_MUTEX_INIT(temp_pool.plb_mutex); + if (pool_id == 0) { + dbb->dbb_permanent = &temp_pool; + temp_pool.plb_extend_size = PERM_EXTEND_SIZE; + } + if (pool_id == 1) + temp_pool.plb_extend_size = CACH_EXTEND_SIZE; + + pool = (PLB) ALL_alloc(&temp_pool, type_plb, 0, ERR_jmp); + pool->plb_pool_id = pool_id; + pool->plb_extend_size = temp_pool.plb_extend_size; + pool->plb_free = temp_pool.plb_free; + pool->plb_hunks = temp_pool.plb_hunks; +#ifdef SUPERSERVER + pool->plb_blk_type_count = temp_pool.plb_blk_type_count; +#endif + vector->vec_object[pool_id] = (BLK) pool; + + V4_MUTEX_DESTROY(temp_pool.plb_mutex); + V4_MUTEX_INIT(pool->plb_mutex); + + V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); + + if (pool_id == 0) + dbb->dbb_permanent = pool; + + return pool; +} + + +void ALL_push(BLK object, register LLS * stack) +{ +/************************************** + * + * A L L _ p u s h + * + ************************************** + * + * Functional description + * Push an object on an LLS stack. + * + **************************************/ + TDBB tdbb; + register LLS node; + PLB pool; + + tdbb = GET_THREAD_DATA; + + pool = tdbb->tdbb_default; + + V4_MUTEX_LOCK(pool->plb_mutex); + + if (node = pool->plb_lls) { + pool->plb_lls = node->lls_next; + V4_MUTEX_UNLOCK(pool->plb_mutex); + } + else { + V4_MUTEX_UNLOCK(pool->plb_mutex); + node = (LLS) ALL_alloc(pool, type_lls, 0, ERR_jmp); + } + + node->lls_object = object; + node->lls_next = *stack; + *stack = node; +} + + +BLK ALL_pop(register LLS * stack) +{ +/************************************** + * + * A L L _ p o p + * + ************************************** + * + * Functional description + * Pop an object off a linked list stack. Save the node for + * further use. + * + **************************************/ + register LLS node; + register PLB pool; + BLK object; + + node = *stack; + *stack = node->lls_next; + object = node->lls_object; + + pool = find_pool((BLK) node); + V4_MUTEX_LOCK(pool->plb_mutex); + node->lls_next = pool->plb_lls; + pool->plb_lls = node; + V4_MUTEX_UNLOCK(pool->plb_mutex); + + return object; +} + + +#ifdef SUPERSERVER +void ALL_print_memory_pool_info(IB_FILE * fptr, DBB databases) +{ +/*********************************************************** + * + * A L L _ p r i n t _ m e m o r y _ p o o l _ i n f o + * + *********************************************************** + * + * Functional description + * Print the different block types allocated in the pool. + * Walk the dbb's to print out pool info of every database + * + **************************************/ + DBB dbb; + STR string; + VEC vector; + PLB myPool; + HNK hnk; + ATT att; + int i, j, k, col; + + ib_fprintf(fptr, "\n\tALL_xx block types\n"); + ib_fprintf(fptr, "\t------------------"); + for (i = 0, col = 0; i < type_MAX; i++) + if (all_block_type_count[i]) { + if (col % 5 == 0) + ib_fprintf(fptr, "\n\t"); + ib_fprintf(fptr, "%s = %d ", ALL_types[i], + all_block_type_count[i]); + ++col; + } + ib_fprintf(fptr, "\n"); + + for (i = 0, dbb = databases; dbb; dbb = dbb->dbb_next, ++i); + ib_fprintf(fptr, "\tNo of dbbs = %d\n", i); + for (k = 1, dbb = databases; dbb; dbb = dbb->dbb_next, ++k) { + string = dbb->dbb_filename; + ib_fprintf(fptr, "\n\t dbb%d -> %s\n", k, string->str_data); + vector = (VEC) dbb->dbb_pools; + for (j = 0, i = 0; i < (int) vector->vec_count; i++) { + myPool = (PLB) vector->vec_object[i]; + if (myPool) + ++j; + } + ib_fprintf(fptr, "\t %s has %d pools", string->str_data, j); + for (j = 0, att = dbb->dbb_attachments; att; att = att->att_next) + j++; + ib_fprintf(fptr, " and %d attachment(s)", j); + for (i = 0; i < (int) vector->vec_count; i++) { + myPool = (PLB) vector->vec_object[i]; + if (!myPool) + continue; + ib_fprintf(fptr, "\n\t Pool %d", myPool->plb_pool_id); + for (j = 0, hnk = myPool->plb_hunks; hnk; hnk = hnk->hnk_next) + j++; + if (j) + ib_fprintf(fptr, " has %d hunks", j); + for (j = 0, hnk = myPool->plb_huge_hunks; hnk; + hnk = hnk->hnk_next) j++; + if (j) + ib_fprintf(fptr, " and %d huge_hunks", j); + ib_fprintf(fptr, " Extend size is %d", myPool->plb_extend_size); + for (j = 0, col = 0; j < type_MAX; j++) + if (myPool->plb_blk_type_count[j]) { + if (col % 5 == 0) + ib_fprintf(fptr, "\n\t "); + ib_fprintf(fptr, "%s = %d ", ALL_types[j], + myPool->plb_blk_type_count[j]); + ++col; + } + } + } +} +#endif + + +void ALL_release(register FRB block) +{ +/************************************** + * + * A L L _ r e l e a s e + * + ************************************** + * + * Functional description + * Release a block to its pool. If it is contiguous to + * another free block, combine them. Otherwise link it + * into the free block linked list (kept in ascending order + * of addresses). + * + **************************************/ + +/* TMN: Here we should probably have the following assert */ +/* assert(block); */ + release(block, find_pool(block ? &block->frb_header : (BLK) 0)); +} + + +void ALL_rlpool(PLB pool) +{ +/************************************** + * + * A L L _ r l p o o l + * + ************************************** + * + * Functional description + * Release a storage pool. This involves nothing more than returning + * hunks to the free hunk list. + * + **************************************/ + DBB dbb; + register HNK hunks, hunk; + + dbb = GET_DBB; + + V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_write); + dbb->dbb_pools->vec_object[pool->plb_pool_id] = NULL; + V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); + + V4_MUTEX_DESTROY(pool->plb_mutex); + +#ifdef SUPERSERVER + if (trace_pools && pool->plb_blk_type_count) { + int i = 0; + for (i = 0; i < type_MAX; i++) + all_block_type_count[i] -= pool->plb_blk_type_count[i]; + gds__free(pool->plb_blk_type_count); + } +#endif + + for (hunks = pool->plb_huge_hunks; hunk = hunks;) { + hunks = hunk->hnk_next; + ALL_sys_free(hunk->hnk_address); + } + for (hunks = pool->plb_hunks; hunk = hunks;) { + hunks = hunk->hnk_next; + ALL_free(hunk->hnk_address); + } +} + + +SCHAR *ALL_sys_alloc(ULONG size, ERR_T err_ret) +{ +/************************************** + * + * A L L _ s y s _ a l l o c + * + ************************************** + * + * Functional description + * Get memory from OS in such a way + * that it can be freed back to OS. + * + **************************************/ + DBB dbb; + register SCHAR *memory; + + if (memory = (SCHAR *) gds__sys_alloc((SLONG) size)) { + /* FREE: Done at attachment detach, process exit, and other misc times */ + + dbb = GET_DBB; + + V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); + dbb->dbb_current_memory += size; + if (dbb->dbb_current_memory > dbb->dbb_max_memory) + dbb->dbb_max_memory = dbb->dbb_current_memory; + V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); + return memory; + } + +/* NOMEM: post user level error */ + if (err_ret == ERR_jmp) + ERR_post(gds_sys_request, gds_arg_string, "gds__sys_alloc", + gds_arg_gds, gds_virmemexh, 0); + + return NULL; +} + + +void ALL_sys_free(SCHAR * memory) +{ +/************************************** + * + * A L L _ s y s _ f r e e + * + ************************************** + * + * Functional description + * Give space back to OS ... really! + * + **************************************/ + DBB dbb; + + dbb = GET_DBB; + + V4_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); + + dbb->dbb_current_memory -= gds__sys_free(memory); + + V4_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_statistics); +} + + +ULONG ALL_tail(UCHAR type) +{ +/************************************** + * + * A L L _ t a i l + * + ************************************** + * + * Functional description + * Compute maximum repeating tail count. + * + **************************************/ + ULONG root, tail; + + if (type <= (UCHAR) type_MIN || type >= (SCHAR) type_MAX) + BUGCHECK(150); /* msg 150 request to allocate invalid block type */ + +/* Compute repeating tail count */ + + root = block_sizes[type].typ_root_length; + if (!(tail = block_sizes[type].typ_tail_length)) + return 0; + + return ((MAX_BLOCK - MIN_ALLOC - root) / tail) + FUDGE; +} + + +VEC ALL_vector(PLB pool, VEC* ptr, USHORT count) +{ +/************************************** + * + * A L L _ v e c t o r + * + ************************************** + * + * Functional description + * Allocate, extend, or no-op a vector making sure it is "long enough". + * NOTE: This routine does not lock any mutexes on + * its own behalf. It is assumed that mutexes will + * have been locked before entry. + * + **************************************/ + VEC vector; + + ++count; + + if (!(vector = *ptr)) { + vector = *ptr = (VEC) ALL_alloc(pool, type_vec, count, ERR_jmp); + vector->vec_count = count; + return vector; + } + + BLKCHK(vector, type_vec); + + if (vector->vec_count >= count) + return vector; + + return (VEC) ALL_extend(reinterpret_cast < blk ** >(ptr), count); +} + + +static BLK alloc_huge_hunk(PLB pool, UCHAR type, ULONG size, ERR_T err_ret) +{ +/************************************** + * + * a l l o c _ h u g e _ h u n k + * + ************************************** + * + * Functional description + * Allocate a hunk of memory larger than + * MAX_BLOCK. Link it into a special + * list of huge hunks belonging to the pool. + * + **************************************/ + HNK hunk; + BLK block; + ULONG minimum_size; + + minimum_size = size + sizeof(struct hnk); + size = + (minimum_size + MIN_ALLOCATION - 1) & ~((ULONG) MIN_ALLOCATION - 1); + + if (!(hunk = (HNK) ALL_sys_alloc((ULONG) size, err_ret))) + return 0; + hunk->hnk_header.blk_length = sizeof(struct hnk) >> SHIFT; + hunk->hnk_header.blk_type = (UCHAR) type_hnk; +/* TMN: Here we should really have the following assert */ +/* assert(pool->plb_pool_id <= MAX_UCHAR); */ + hunk->hnk_header.blk_pool_id = (UCHAR) pool->plb_pool_id; + hunk->hnk_address = (SCHAR *) hunk; + hunk->hnk_length = size; + V4_MUTEX_LOCK(pool->plb_mutex); + hunk->hnk_next = pool->plb_huge_hunks; + pool->plb_huge_hunks = hunk; + V4_MUTEX_UNLOCK(pool->plb_mutex); + + block = (BLK) (hunk + 1); + MOVE_CLEAR(block, size - sizeof(struct hnk)); + block->blk_length = 0; + block->blk_type = type; +/* TMN: Here we should really have the following assert */ +/* assert(pool->plb_pool_id <= MAX_UCHAR); */ + block->blk_pool_id = (UCHAR) pool->plb_pool_id; + + return block; +} + + +static BOOLEAN extend_pool(PLB pool, ULONG size, ERR_T err_ret) +{ +/************************************** + * + * e x t e n d _ p o o l + * + ************************************** + * + * Functional description + * Extend a pool by at least enough to accomodate a block + * of given size. + * + **************************************/ + register HNK hunk; + register BLK block; + ULONG minimum_size, extend_size; + + minimum_size = size + sizeof(struct hnk); + +/* Keep minimum allocation roundup for blocks larger than pool + extend size. */ + + extend_size = (ULONG) pool->plb_extend_size; + if (extend_size < minimum_size) + extend_size = MIN_ALLOCATION; + + size = (minimum_size + extend_size - 1) & ~(extend_size - 1); + + if (!(block = (BLK) ALL_malloc((ULONG) size, err_ret))) + return FALSE; +/* TMN: Here we should really have the following assert */ +/* assert((size >> SHIFT) <= MAX_USHORT); */ + block->blk_length = (USHORT) (size >> SHIFT); + block->blk_type = (UCHAR) type_frb; +/* TMN: Here we should really have the following assert */ +/* assert(pool->plb_pool_id <= MAX_UCHAR); */ + block->blk_pool_id = (UCHAR) pool->plb_pool_id; +#ifdef SUPERSERVER + if (trace_pools) { + ++all_block_type_count[block->blk_type]; + ++pool->plb_blk_type_count[block->blk_type]; + } +#endif + release(reinterpret_cast < frb * >(block), pool); + + if (!(hunk = (HNK) ALL_alloc(pool, type_hnk, 0, err_ret))) + return FALSE; + hunk->hnk_address = (SCHAR *) block; + hunk->hnk_length = size; + + V4_MUTEX_LOCK(pool->plb_mutex); + hunk->hnk_next = pool->plb_hunks; + pool->plb_hunks = hunk; + V4_MUTEX_UNLOCK(pool->plb_mutex); + return TRUE; +} + + +static ULONG find_block_length(BLK block) +{ +/************************************** + * + * f i n d _ b l o c k _ l e n g t h + * + ************************************** + * + * Functional description + * The blocks that are associated with huge + * hunks always have a zero block length. + * Their length can be determined indirectly, + * using the length of the hunk. + * + **************************************/ + HNK hunk; + + hunk = (HNK) block - 1; + + return (hunk->hnk_length - sizeof(struct hnk)); +} + + +static PLB find_pool(BLK block) +{ +/************************************** + * + * f i n d _ p o o l + * + ************************************** + * + * Functional description + * Find pool associate with block. + * + **************************************/ + DBB dbb; + VEC pools; + PLB pool; + HNK hunk; + USHORT pool_id, huge_flag; +#ifdef V4_THREADING + USHORT dbb_pool_flag; +#endif + + dbb = GET_DBB; + +#ifdef V4_THREADING + if (!(dbb_pool_flag = (block == (BLK) dbb->dbb_pools))) + V4_RW_LOCK_LOCK(dbb->dbb_rw_locks + DBB_WLCK_pools, WLCK_read); +#endif + + pools = dbb->dbb_pools; + +/* Turn on this optimization someday */ + + if (pools->vec_count < 256) + if ((pool_id = block->blk_pool_id) < pools->vec_count && + (pool = (PLB) pools->vec_object[pool_id])) { +#ifdef V4_THREADING + if (!dbb_pool_flag) + V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); +#endif + return pool; + } + else { +#ifdef V4_THREADING + if (!dbb_pool_flag) + V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); +#endif + BUGCHECK(153); + } + + huge_flag = (block->blk_length) ? FALSE : TRUE; + + for (pool_id = block->blk_pool_id; pool_id < pools->vec_count; + pool_id += 256) + if (pool = (PLB) pools->vec_object[pool_id]) { + hunk = (huge_flag) ? pool->plb_huge_hunks : pool->plb_hunks; + for (; hunk; hunk = hunk->hnk_next) + if ((SCHAR HUGE_PTR *) block >= + (SCHAR HUGE_PTR *) hunk->hnk_address + && (SCHAR HUGE_PTR *) block < + (SCHAR HUGE_PTR *) hunk->hnk_address + hunk->hnk_length) { +#ifdef V4_THREADING + if (!dbb_pool_flag) + V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); +#endif + return pool; + } + } + +#ifdef V4_THREADING + if (!dbb_pool_flag) + V4_RW_LOCK_UNLOCK(dbb->dbb_rw_locks + DBB_WLCK_pools); +#endif + BUGCHECK(153); /* msg 153 invalid pool id encountered */ +/* Harbor Software: */ +/* this code should not be reached. */ + return NULL; +} + + +static void release(FRB block, PLB pool) +{ +/************************************** + * + * r e l e a s e + * + ************************************** + * + * Functional description + * Release a block to its pool. If it is contiguous to + * another free block, combine them. Otherwise link it + * into the free block linked list (kept in ascending order + * of addresses). + * + **************************************/ + register FRB prior, free; + FRB *ptr; + ULONG length; +#ifdef SUPERSERVER + UCHAR blk_header_type; +#endif + + V4_MUTEX_LOCK(pool->plb_mutex); + + if (!block->frb_header.blk_length) { + /* A block with no length indicates a HUGE hunk. Find it and free it. */ + + HNK hunk, *ptr; + + for (ptr = &pool->plb_huge_hunks; hunk = *ptr; ptr = &hunk->hnk_next) + if ((SCHAR *) block >= (SCHAR *) hunk->hnk_address && + (SCHAR *) block < + (SCHAR *) hunk->hnk_address + hunk->hnk_length) { + *ptr = hunk->hnk_next; + V4_MUTEX_UNLOCK(pool->plb_mutex); + ALL_sys_free(hunk->hnk_address); + return; + } + V4_MUTEX_UNLOCK(pool->plb_mutex); + BUGCHECK(154); /* msg 154 attempt to release free block */ + } + +#ifdef SUPERSERVER + blk_header_type = block->frb_header.blk_type; +#endif + block->frb_header.blk_type = (UCHAR) type_frb; + prior = NULL; + +#ifdef DEBUG_GDS_ALLOC +/* Debugging code to erase memory locations after a release - + * this will assist in catching dangling memory references to + * freed locations. + * Note that the header parts of the freed block may still be used, + * for the free chain, so we don't zap those locations. + */ + +/* Pattern to set "released" memory to */ +#define ALL_RELEASED_FREE_PATTERN 0xBB + { + ULONG units, size; + units = block->frb_header.blk_length; + size = (units << SHIFT) - sizeof(*block); + memset(((UCHAR *) block) + sizeof(*block), ALL_RELEASED_FREE_PATTERN, + size); + }; +#endif /* DEBUG_GDS_ALLOC */ + + for (ptr = &pool->plb_free; free = *ptr; + prior = free, ptr = + &free->frb_next) if ((SCHAR HUGE_PTR *) block <= + (SCHAR HUGE_PTR *) free) break; + + if ((SCHAR HUGE_PTR *) block == (SCHAR HUGE_PTR *) free) { + V4_MUTEX_UNLOCK(pool->plb_mutex); + BUGCHECK(154); /* msg 154 attempt to release free block */ + } + +/* Merge block into list first, then try to combine blocks */ + + block->frb_next = free; + *ptr = block; + +/* Try to merge the free block with the next one down. */ + + length = block->frb_header.blk_length << SHIFT; + + if (free) { + if ((SCHAR HUGE_PTR *) block + length == (SCHAR HUGE_PTR *) free) { + block->frb_header.blk_length += free->frb_header.blk_length; + block->frb_next = free->frb_next; +#ifdef DEBUG_GDS_ALLOC + /* We've joined the blocks, so paint the header of the merged away + * block as freed. + */ + memset(((UCHAR *) free), ALL_RELEASED_FREE_PATTERN, + sizeof(*free)); +#endif + } + else if ((SCHAR HUGE_PTR *) block + length > (SCHAR HUGE_PTR *) free) { + V4_MUTEX_UNLOCK(pool->plb_mutex); + BUGCHECK(155); /* msg 155 attempt to release block overlapping following free block */ + } + } + +/* Try and merge the block with the prior free block */ + + if (prior && (length = prior->frb_header.blk_length << SHIFT)) { + if ((SCHAR HUGE_PTR *) prior + length == (SCHAR HUGE_PTR *) block) { + prior->frb_header.blk_length += block->frb_header.blk_length; + prior->frb_next = block->frb_next; +#ifdef DEBUG_GDS_ALLOC + /* We've joined the blocks, so paint the header of the merged away + * block as freed. + */ + memset(((UCHAR *) block), ALL_RELEASED_FREE_PATTERN, + sizeof(*block)); +#endif + } + else if ((SCHAR HUGE_PTR *) prior + length > (SCHAR HUGE_PTR *) block) { + V4_MUTEX_UNLOCK(pool->plb_mutex); + BUGCHECK(156); /* msg 156 attempt to release block overlapping prior free block */ + } + } + +#ifdef SUPERSERVER + if (trace_pools) { + --all_block_type_count[blk_header_type]; + --pool->plb_blk_type_count[blk_header_type]; + } +#endif + + V4_MUTEX_UNLOCK(pool->plb_mutex); +} + + +} // extern "C" diff --git a/src/jrd/all_old.h b/src/jrd/all_old.h new file mode 100644 index 0000000000..eb3c32b1ee --- /dev/null +++ b/src/jrd/all_old.h @@ -0,0 +1,101 @@ +/* + * PROGRAM: JRD Access Method + * MODULE: all.h + * DESCRIPTION: Block allocator blocks + * + * The contents of this file are subject to the Interbase Public + * License Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy + * of the License at http://www.Inprise.com/IPL.html + * + * Software distributed under the License is distributed on an + * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express + * or implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code was created by Inprise Corporation + * and its predecessors. Portions created by Inprise Corporation are + * Copyright (C) Inprise Corporation. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + */ + +#ifndef _JRD_ALL_H_ +#define _JRD_ALL_H_ + +#if ALIGNMENT == 8 +#define MIN_ALLOC 8 +#else +#define MIN_ALLOC 4 +#endif + +/* MAX_BLOCK for OS/2 is calculated by taking the max memory + available in a segment (65534 bytes), subtracting 4 bytes + for a length, 8 bytes for a free block, and 2 bytes to + allow rounding to a 4 byte boundary */ + +#if (defined PC_PLATFORM && !defined NETWARE_386) +#define MAX_BLOCK 65520 +#else +#define MAX_BLOCK (262144 - MIN_ALLOCATION - sizeof (struct hnk) - 8) +#endif + +#define FUDGE 1 + +#define SHIFT SHIFTLONG + +#define MIN_ALLOCATION 1024 /* Minimum allocation from operating system */ + +/* Prevent shared memory pools from fragmenting into very long + free block lists. Any hunk residual larger than a free block + structure will lengthen the free list. A larger extend size + reduces the number of times the pool is extended and reduces + the length of the free block list. */ + +#ifdef SUPERSERVER +#define PERM_EXTEND_SIZE (16 * MIN_ALLOCATION) +#define CACH_EXTEND_SIZE (16 * MIN_ALLOCATION) +#else +#define PERM_EXTEND_SIZE MIN_ALLOCATION +#define CACH_EXTEND_SIZE MIN_ALLOCATION +#endif + +#define EXTEND(vector_count) vector_count + vector_count % 10 + + + +/* Free block */ + +typedef struct frb { + struct blk frb_header; + struct frb *frb_next; /* Next free block in pool */ +} *FRB; + +/* Pool block */ + +typedef struct plb { + struct blk plb_header; + USHORT plb_pool_id; /* pool id */ + USHORT plb_extend_size; /* pool extend size */ + struct frb *plb_free; /* first free block */ + struct hnk *plb_hunks; /* first hunk block */ + struct hnk *plb_huge_hunks; /* first huge hunk block (blocks > MAX_BLOCK) */ + struct lls *plb_lls; /* available linked list stack nodes */ + struct dcc *plb_dccs; /* available data compression control blocks */ + struct sbm *plb_buckets; /* available bit map buckets */ + struct bms *plb_segments; /* available bit map segments */ + MUTX plb_mutex[1]; + SLONG *plb_blk_type_count; /* array to keep track of block types */ +} *PLB; + +/* Hunk blocks */ + +typedef struct hnk { + struct blk hnk_header; + SCHAR *hnk_address; /* start of memory hunk */ + SLONG hnk_length; /* length of memory hunk */ + struct hnk *hnk_next; /* next memory hunk in structure */ +} *HNK; + +#endif /* _JRD_ALL_H_ */ diff --git a/src/jrd/all_proto.h b/src/jrd/all_proto.h index 03bab37fd4..0ab837a68b 100644 --- a/src/jrd/all_proto.h +++ b/src/jrd/all_proto.h @@ -24,38 +24,6 @@ #ifndef JRD_ALL_PROTO_H #define JRD_ALL_PROTO_H -#include "../jrd/jrd.h" -#include "../jrd/all.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct blk *ALL_alloc(struct plb *, UCHAR, ULONG, enum err_t); -#ifdef DEV_BUILD -void ALL_check_memory(void); -#endif -TEXT *ALL_cstring(TEXT *); -struct blk *ALL_extend(struct blk **, ULONG); -void ALL_fini(void); -void ALL_free(SCHAR *); -ULONG ALL_get_free_object(struct plb *, struct vec **, USHORT); -void ALL_init(void); -SCHAR *ALL_malloc(ULONG, enum err_t); -struct plb *ALL_pool(void); -void ALL_push(struct blk *, register struct lls **); -struct blk *ALL_pop(register struct lls **); -void ALL_release(register struct frb *); -void ALL_rlpool(struct plb *); -SCHAR *ALL_sys_alloc(ULONG, enum err_t); -void ALL_sys_free(SCHAR *); -ULONG ALL_tail(UCHAR); -struct vec *ALL_vector(struct plb *, struct vec **, USHORT); - -#define ALL_RELEASE(block) ALL_release ((struct frb *) block) - -#ifdef __cplusplus -} /* extern "C" */ -#endif +#include "../jrd/all.h" // everything is defined in all.h now. #endif /* JRD_ALL_PROTO_H */ diff --git a/src/jrd/alt_use_sec.h b/src/jrd/alt_use_sec.h new file mode 100644 index 0000000000..0c93f9e07d --- /dev/null +++ b/src/jrd/alt_use_sec.h @@ -0,0 +1,54 @@ +#ifndef INCLUDE_alt_use_sec +#define INCLUDE_alt_use_sec +/* + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * Alternatively, the contents of this file may be used under the + * terms of the GNU General Public License Version 2 or later (the + * "GPL"), in which case the provisions of the GPL are applicable + * instead of those above. You may obtain a copy of the Licence at + * http://www.gnu.org/copyleft/gpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Relevant for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + * + * Contributor(s): + * Mark O'Donohue + * John Bellardo + * + * + * $Id: alt_use_sec.h,v 1.1 2001-12-24 02:50:50 tamlin Exp $ + * + */ + + +// During the build process in the initial stages the isc4.gdb database does +// not exist, but to build the isc4.gdb database the tools need to be built. +// So the following #define is set/unset in the makefile depending upon which +// stage in the compile process we are up to. +// +// In the earlier stages it is set to "1" then after we have build a set of +// tools mainly gpre_static and gbak_static it is changed to an "undef". +// +// The alt_use_sec.h file is built from alt_use_sec.h.pre using sed +// See the Makefile.in.jrd for the two places where the .h file is built. +// +// The build is done this way to allow the makefile to have a simple set +// of dependancies to determine the makeup and up to date check for +// libgds.a/so. + +#define PHASE_1_BUILD_NO_SECURITY_DB + +#endif diff --git a/src/jrd/alt_use_sec.h.pre b/src/jrd/alt_use_sec.h.pre index 11c5f96d3b..93fc999091 100644 --- a/src/jrd/alt_use_sec.h.pre +++ b/src/jrd/alt_use_sec.h.pre @@ -29,7 +29,7 @@ * John Bellardo * * - * $Id: alt_use_sec.h.pre,v 1.1 2001-07-29 17:42:21 skywalker Exp $ + * $Id: alt_use_sec.h.pre,v 1.2 2001-12-24 02:50:50 tamlin Exp $ * */ diff --git a/src/jrd/blb.cpp b/src/jrd/blb.cpp index 6efa7f28a1..beb7cf523f 100644 --- a/src/jrd/blb.cpp +++ b/src/jrd/blb.cpp @@ -24,7 +24,7 @@ * readonly databases. */ /* -$Id: blb.cpp,v 1.4 2001-07-29 17:42:21 skywalker Exp $ +$Id: blb.cpp,v 1.5 2001-12-24 02:50:50 tamlin Exp $ */ #include "firebird.h" @@ -64,9 +64,6 @@ $Id: blb.cpp,v 1.4 2001-07-29 17:42:21 skywalker Exp $ #include "../jrd/thd_proto.h" -//extern "C" { - - #define STREAM (blob->blb_flags & BLB_stream) #define SEGMENTED !STREAM @@ -113,7 +110,7 @@ void BLB_cancel(TDBB tdbb, BLB blob) } -void BLB_close(TDBB tdbb, BLB blob) +void BLB_close(TDBB tdbb, class blb* blob) { /************************************** * @@ -223,9 +220,9 @@ BLB BLB_create2(TDBB tdbb, if (to_charset == CS_dynamic) to_charset = tdbb->tdbb_attachment->att_charset; if ((to_charset != CS_NONE) && (from_charset != to_charset)) { - filter = (BLF) ALLOCP(type_blf); + filter = new(*dbb->dbb_permanent) blf(); filter->blf_filter = - reinterpret_cast < STATUS (*) (USHORT, CTL) > (filter_transliterate_text); + reinterpret_cast(filter_transliterate_text); filter_required = TRUE; } } @@ -291,7 +288,7 @@ void BLB_garbage_collect( **************************************/ LLS stack1, stack2; REC rec1, rec2; - DSC *desc, desc1, desc2; + DSC desc1, desc2; FMT format; BID blob, blob2; USHORT id; @@ -307,9 +304,9 @@ void BLB_garbage_collect( /* Look for active blob records */ - for (id = 0, desc = format->fmt_desc; id < format->fmt_count; - id++, desc++) { - if (!DTYPE_IS_BLOB(desc->dsc_dtype) + for (id = 0; id < format->fmt_count; + id++) { + if (!DTYPE_IS_BLOB(format->fmt_desc[id].dsc_dtype) || !EVL_field(0, rec1, id, &desc1)) continue; blob = (BID) desc1.dsc_address; @@ -375,7 +372,7 @@ BLB BLB_get_array(TDBB tdbb, TRA transaction, BID blob_id, ADS desc) BLB_get_segment(tdbb, blob, reinterpret_cast < UCHAR * >(desc), sizeof(struct ads)); - if (n = desc->ads_length - sizeof(struct ads)) + if ( (n = desc->ads_length - sizeof(struct ads)) ) BLB_get_segment(tdbb, blob, (UCHAR *) desc + sizeof(struct ads), n); return blob; @@ -461,9 +458,9 @@ USHORT BLB_get_segment(TDBB tdbb, if (blob->blb_filter) { blob->blb_fragment_size = 0; - if (status = + if ( (status = BLF_get_segment(tdbb, &blob->blb_filter, &length, buffer_length, - segment)) { + segment)) ) { if (status == gds_segstr_eof) blob->blb_flags |= BLB_eof; else if (status == gds_segment) @@ -647,8 +644,10 @@ SLONG BLB_get_slice(TDBB tdbb, struct sdl_info info; struct slice arg; JMP_BUF env, *old_env; + DBB dbb; SET_TDBB(tdbb); + dbb = GET_DBB; tdbb->tdbb_default = transaction->tra_pool; /* Checkout slice description language */ @@ -664,7 +663,7 @@ SLONG BLB_get_slice(TDBB tdbb, /* Get someplace to put data */ - data = (UCHAR *) ALL_malloc(desc->ads_total_length, ERR_jmp); + data = (UCHAR*) dbb->dbb_permanent->allocate(desc->ads_total_length); /* zero out memory, so that it does not have to be done for each element */ @@ -678,11 +677,7 @@ SLONG BLB_get_slice(TDBB tdbb, old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ALL_free(reinterpret_cast < char *>(data)); - ERR_punt(); - } + try { /* If we know something about the subscript bounds, prepare to fetch only stuff we really care about */ @@ -728,10 +723,18 @@ SLONG BLB_get_slice(TDBB tdbb, reinterpret_cast < struct slice *>(&arg)); tdbb->tdbb_setjmp = (UCHAR *) old_env; - ALL_free(reinterpret_cast < char *>(data)); + MemoryPool::deallocate(data); - if (status) + if (status) { ERR_punt(); + } + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + MemoryPool::deallocate(data); + ERR_punt(); + } return (SLONG) (arg.slice_count * arg.slice_element_length); } @@ -774,6 +777,9 @@ SLONG BLB_lseek(BLB blob, USHORT mode, SLONG offset) #ifdef REPLAY_OSRI_API_CALLS_SUBSYSTEM + +extern "C" { + void DLL_EXPORT BLB_map_blobs(TDBB tdbb, BLB old_blob, BLB new_blob) { /************************************** @@ -798,14 +804,17 @@ void DLL_EXPORT BLB_map_blobs(TDBB tdbb, BLB old_blob, BLB new_blob) dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - new_map = (MAP) ALLOCP(type_map); + new_map = new(*dbb->dbb_permanent) map(); new_map->map_old_blob = old_blob; new_map->map_new_blob = new_blob; new_map->map_next = dbb->dbb_blob_map; dbb->dbb_blob_map = new_map; } -#endif + +} // extern "C" + +#endif // REPLAY_OSRI_API_CALLS_SUBSYSTEM void BLB_move(TDBB tdbb, DSC * from_desc, DSC * to_desc, NOD field) @@ -918,7 +927,7 @@ void BLB_move(TDBB tdbb, DSC * from_desc, DSC * to_desc, NOD field) } if (!blob || - blob->blb_header.blk_type != (UCHAR) type_blb || + MemoryPool::blk_type(blob) != type_blb || blob->blb_attachment != tdbb->tdbb_attachment || !(blob->blb_flags & BLB_closed) || (blob->blb_request && blob->blb_request != request)) @@ -981,7 +990,6 @@ BLB BLB_open2(TDBB tdbb, **************************************/ DBB dbb; BLB blob, new_; - VEC vector; VCL new_pages, pages; CTL control; SSHORT from, to; @@ -1023,7 +1031,7 @@ BLB BLB_open2(TDBB tdbb, if (to_charset == CS_dynamic) to_charset = tdbb->tdbb_attachment->att_charset; if ((to_charset != CS_NONE) && (from_charset != to_charset)) { - filter = (BLF) ALLOCP(type_blf); + filter = new(*dbb->dbb_permanent) blf(); filter->blf_filter = reinterpret_cast < STATUS (*) (USHORT, CTL) > (filter_transliterate_text); filter_required = TRUE; @@ -1083,12 +1091,10 @@ BLB BLB_open2(TDBB tdbb, blob->blb_max_segment = new_->blb_max_segment; blob->blb_level = new_->blb_level; blob->blb_flags = new_->blb_flags & BLB_stream; - if (pages = new_->blb_pages) { - blob->blb_pages = new_pages = - (VCL) ALLOCTV(type_vcl, pages->vcl_count); - new_pages->vcl_count = pages->vcl_count; - MOVE_FAST(pages->vcl_long, new_pages->vcl_long, - sizeof(pages->vcl_long[0]) * pages->vcl_count); + pages = new_->blb_pages; + if (pages) { + new_pages = vcl::newVector(*transaction->tra_pool, *pages); + blob->blb_pages = new_pages; } if (blob->blb_level == 0) { blob->blb_space_remaining = @@ -1105,12 +1111,14 @@ BLB BLB_open2(TDBB tdbb, know about the relation, the blob id has got to be invalid anyway. */ - vector = dbb->dbb_relations; + VEC vector = dbb->dbb_relations; - if (blob_id->bid_relation_id >= vector->vec_count || + if (blob_id->bid_relation_id >= vector->count() || !(blob->blb_relation = - (REL) vector->vec_object[blob_id->bid_relation_id])) + reinterpret_cast( (*vector)[blob_id->bid_relation_id]) ) ) + { ERR_post(gds_bad_segstr_id, 0); + } DPM_get_blob(tdbb, blob, blob_id->bid_stuff.bid_number, FALSE, (SLONG) 0); @@ -1196,7 +1204,7 @@ void BLB_put_segment(TDBB tdbb, BLB blob, UCHAR* seg, USHORT segment_length) TRA transaction; transaction = blob->blb_transaction; - blob->blb_pages = (VCL) ALLOCTV(type_vcl, blob->blb_max_pages); + blob->blb_pages = vcl::newVector(*transaction->tra_pool, blob->blb_max_pages+1); l = dbb->dbb_page_size - BLP_SIZE; blob->blb_space_remaining += l - blob->blb_clump_size; blob->blb_clump_size = l; @@ -1439,16 +1447,16 @@ void BLB_release_array(ARR array) ARR *ptr; if (array->arr_data) - ALL_free(reinterpret_cast < char *>(array->arr_data)); + MemoryPool::deallocate(array->arr_data); - if (transaction = array->arr_transaction) + if ( (transaction = array->arr_transaction) ) for (ptr = &transaction->tra_arrays; *ptr; ptr = &(*ptr)->arr_next) if (*ptr == array) { *ptr = array->arr_next; break; } - ALL_release(reinterpret_cast < frb * >(array)); + delete array; } @@ -1486,7 +1494,7 @@ void BLB_scalar( desc.dsc_address = (UCHAR *) temp; } else { temp_str = - (STR) ALLOCDV(type_str, desc.dsc_length + DOUBLE_ALIGN - 1); + new(*tdbb->tdbb_default, desc.dsc_length + DOUBLE_ALIGN - 1) str; desc.dsc_address = (UCHAR *) FB_ALIGN((U_IPTR) temp_str->str_data, DOUBLE_ALIGN); } @@ -1498,7 +1506,7 @@ void BLB_scalar( if (number < 0) { BLB_close(tdbb, blob); if (desc.dsc_address != (UCHAR *) temp) - ALL_release(reinterpret_cast < frb * >(temp_str)); + delete temp_str; ERR_punt(); } @@ -1514,7 +1522,7 @@ void BLB_scalar( EVL_make_value(tdbb, &desc, value); BLB_close(tdbb, blob); if (desc.dsc_address != (UCHAR *) temp) - ALL_release(reinterpret_cast < frb * >(temp_str)); + delete temp_str; } @@ -1532,11 +1540,14 @@ static ARR alloc_array(TRA transaction, ADS proto_desc) **************************************/ ARR array; USHORT n; + DBB dbb; + + dbb = GET_DBB; /* Compute size and allocate block */ n = MAX(proto_desc->ads_struct_count, proto_desc->ads_dimensions); - array = (ARR) ALLOCTV(type_arr, n); + array = new(*transaction->tra_pool, n) arr(); /* Copy prototype descriptor */ @@ -1551,7 +1562,7 @@ static ARR alloc_array(TRA transaction, ADS proto_desc) /* Allocate large block to hold array */ array->arr_data = - (UCHAR *) ALL_malloc(array->arr_desc.ads_total_length, ERR_jmp); + (UCHAR*) dbb->dbb_permanent->allocate(array->arr_desc.ads_total_length); return array; } @@ -1577,7 +1588,7 @@ static BLB allocate_blob(TDBB tdbb, TRA transaction) /* Create a blob large enough to hold a single data page */ - blob = (BLB) ALLOCTV(type_blb, dbb->dbb_page_size); + blob = new(*transaction->tra_pool, dbb->dbb_page_size) blb(); blob->blb_attachment = tdbb->tdbb_attachment; blob->blb_next = transaction->tra_blobs; transaction->tra_blobs = blob; @@ -1609,8 +1620,6 @@ static STATUS blob_filter( * Filter of last resort for filtered blob access handled by Y-valve. * **************************************/ - USHORT length; - VCL vector; BLB blob; TRA transaction; SLONG *blob_id; @@ -1670,13 +1679,10 @@ static STATUS blob_filter( return SUCCESS; case ACTION_alloc: - length = ROUNDUP(sizeof(struct ctl), sizeof(SLONG)); - vector = (VCL) ALLOCTV(type_vcl, length); - return (STATUS) (vector->vcl_long); + return (STATUS) new(*transaction->tra_pool) ctl(); case ACTION_free: - vector = (VCL) ((UCHAR *) control - OFFSETA(VCL, vcl_long)); - ALL_release(reinterpret_cast < frb * >(vector)); + delete control; return SUCCESS; case ACTION_seek: @@ -1721,7 +1727,7 @@ static void check_BID_validity(BLB blob, TDBB tdbb) **************************************/ if (!blob || - blob->blb_header.blk_type != (UCHAR) type_blb || + MemoryPool::blk_type(blob) != type_blb || blob->blb_attachment != tdbb->tdbb_attachment || blob->blb_level > 2 || !(blob->blb_flags & BLB_temporary)) @@ -1772,7 +1778,7 @@ static BLB copy_blob(TDBB tdbb, BID source, REL relation, BID destination) #endif { - string = (STR) ALLOCDV(type_str, input->blb_max_segment); + string = new(*tdbb->tdbb_default, input->blb_max_segment) str(); buff = (UCHAR *) string->str_data; } else { @@ -1788,7 +1794,7 @@ static BLB copy_blob(TDBB tdbb, BID source, REL relation, BID destination) } if (string) - ALL_release(reinterpret_cast < frb * >(string)); + delete string; #ifdef STACK_REDUCTION gds__free((SLONG *) buffer); @@ -1820,7 +1826,8 @@ static void delete_blob(TDBB tdbb, BLB blob, ULONG prior_page) VCL vector; WIN window; BLP page; - SLONG *ptr, *end, *ptr2, *end2; + vcl::iterator ptr, end; + SLONG *ptr2, *end2; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; @@ -1837,8 +1844,8 @@ static void delete_blob(TDBB tdbb, BLB blob, ULONG prior_page) /* Level 1 blobs just need the root page level released */ vector = blob->blb_pages; - ptr = vector->vcl_long; - end = ptr + vector->vcl_count; + ptr = vector->begin(); + end = vector->end(); if (blob->blb_level == 1) { for (; ptr < end; ptr++) @@ -1855,7 +1862,7 @@ static void delete_blob(TDBB tdbb, BLB blob, ULONG prior_page) window.win_scans = 1; for (; ptr < end; ptr++) - if (window.win_page = *ptr) { + if ( (window.win_page = *ptr) ) { page = (BLP) CCH_FETCH(tdbb, &window, LCK_read, pag_blob); MOVE_FASTER(page, blob->blb_data, dbb->dbb_page_size); CCH_RELEASE_TAIL(tdbb, &window); @@ -2026,12 +2033,12 @@ static BLP get_next_page(TDBB tdbb, BLB blob, WIN * window) CCH_PREFETCH(tdbb, pages, i); } #endif - window->win_page = vector->vcl_long[blob->blb_sequence]; + window->win_page = (*vector)[blob->blb_sequence]; page = (BLP) CCH_FETCH(tdbb, window, LCK_read, pag_blob); } else { window->win_page = - vector->vcl_long[blob->blb_sequence / blob->blb_pointers]; + (*vector)[blob->blb_sequence / blob->blb_pointers]; page = (BLP) CCH_FETCH(tdbb, window, LCK_read, pag_blob); #ifdef SUPERSERVER_V2 /* Perform prefetch of blob level 2 data pages. */ @@ -2169,9 +2176,7 @@ static void insert_page(TDBB tdbb, BLB blob) the vector. */ if (blob->blb_sequence < blob->blb_max_pages) { - vector->vcl_long[blob->blb_sequence] = page_number; - if (blob->blb_sequence >= vector->vcl_count) - vector->vcl_count = blob->blb_sequence + 1; + (*vector)[blob->blb_sequence] = page_number; return; } @@ -2182,10 +2187,10 @@ static void insert_page(TDBB tdbb, BLB blob) page->blp_header.pag_flags = blp_pointers; page->blp_header.pag_type = pag_blob; page->blp_lead_page = blob->blb_lead_page; - page->blp_length = vector->vcl_count << SHIFTLONG; - MOVE_FASTER(vector->vcl_long, page->blp_page, page->blp_length); - vector->vcl_long[0] = window.win_page; - vector->vcl_count = 1; + page->blp_length = vector->count() << SHIFTLONG; + MOVE_FASTER(vector->memPtr(), page->blp_page, page->blp_length); + vector->clear(); + (*vector)[0] = window.win_page; CCH_RELEASE(tdbb, &window); } @@ -2194,8 +2199,8 @@ static void insert_page(TDBB tdbb, BLB blob) l = blob->blb_sequence / blob->blb_pointers; - if (l < vector->vcl_count) { - window.win_page = vector->vcl_long[l]; + if (l < vector->count()) { + window.win_page = (*vector)[l]; window.win_flags = 0; page = (BLP) CCH_FETCH(tdbb, &window, LCK_write, pag_blob); } @@ -2204,8 +2209,7 @@ static void insert_page(TDBB tdbb, BLB blob) page->blp_header.pag_flags = blp_pointers; page->blp_header.pag_type = pag_blob; page->blp_lead_page = blob->blb_lead_page; - vector->vcl_count = l + 1; - vector->vcl_long[l] = window.win_page; + (*vector)[l] = window.win_page; } CCH_precedence(tdbb, &window, page_number); @@ -2246,12 +2250,12 @@ static void release_blob(BLB blob, USHORT purge_flag) } if (blob->blb_pages) { - ALL_release(reinterpret_cast < frb * >(blob->blb_pages)); + delete blob->blb_pages; blob->blb_pages = NULL; } if (purge_flag) - ALL_release(reinterpret_cast < frb * >(blob)); + delete blob; } @@ -2316,7 +2320,7 @@ static void slice_callback(SLICE arg, ULONG count, DSC * descriptors) tdbb = GET_THREAD_DATA; tmp_len = array_desc->dsc_length; - tmp_buffer = (STR) ALLOCDV(type_str, tmp_len); + tmp_buffer = new(*tdbb->tdbb_default, tmp_len) str(); len = MOV_make_string(slice_desc, INTL_TEXT_TYPE(*array_desc), &p, @@ -2324,7 +2328,7 @@ static void slice_callback(SLICE arg, ULONG count, DSC * descriptors) vary * >(tmp_buffer->str_data), tmp_len); MOVE_FAST(&len, array_desc->dsc_address, sizeof(USHORT)); MOVE_FAST(p, array_desc->dsc_address + sizeof(USHORT), (int) len); - ALL_release(reinterpret_cast < frb * >(tmp_buffer)); + delete tmp_buffer; } else MOV_move(slice_desc, array_desc); @@ -2363,7 +2367,7 @@ static void slice_callback(SLICE arg, ULONG count, DSC * descriptors) MOV_move(array_desc, slice_desc); ++arg->slice_count; } - else if (l = slice_desc->dsc_length) + else if ( (l = slice_desc->dsc_length) ) memset(slice_desc->dsc_address, 0, l); } @@ -2421,5 +2425,3 @@ static BLB store_array(TDBB tdbb, TRA transaction, BID blob_id) return blob; } - -//} // extern "C" diff --git a/src/jrd/blb.h b/src/jrd/blb.h index 069b635c70..83606d1611 100644 --- a/src/jrd/blb.h +++ b/src/jrd/blb.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_BLB_H_ -#define _JRD_BLB_H_ +#ifndef JRD_BLB_H +#define JRD_BLB_H /* Blob id. A blob has two states -- temporary and permanent. In each case, the blob id is 8 bytes (2 longwords) long. In the case of a @@ -36,7 +36,7 @@ typedef struct bid { #ifndef DECOSF ULONG bid_relation_id; /* Relation id (or null) */ union { - struct blb *bid_blob; /* Pointer to blob block */ + class blb *bid_blob; /* Pointer to blob block */ ULONG bid_number; /* Record number */ } bid_stuff; #else @@ -51,18 +51,19 @@ typedef struct bid { /* Your basic blob block. */ -typedef struct blb { - struct blk blb_header; - struct att *blb_attachment; /* database attachment */ - struct rel *blb_relation; /* Relation, if known */ +class blb : public pool_alloc_rpt +{ + public: + att *blb_attachment; /* database attachment */ + rel *blb_relation; /* Relation, if known */ struct tra *blb_transaction; /* Parent transaction block */ - struct blb *blb_next; /* Next blob in transaction */ + blb *blb_next; /* Next blob in transaction */ UCHAR *blb_segment; /* Next segment to be addressed */ struct ctl *blb_filter; /* Blob filter control block, if any */ struct bid blb_blob_id; /* Id of materialized blob */ struct req *blb_request; /* request that assigned temporary blob */ #ifndef GATEWAY - struct vcl *blb_pages; /* Vector of pages */ + vcl *blb_pages; /* Vector of pages */ USHORT blb_pointers; /* Max pointer on a page */ #else struct vec *blb_pages; /* Vector of pages */ @@ -85,7 +86,8 @@ typedef struct blb { ULONG blb_seek; /* Seek location */ /* blb_data must be longword aligned */ UCHAR blb_data[1]; /* A page's worth of blob */ -} *BLB; +}; +typedef blb *BLB; #define BLB_temporary 1 /* Newly created blob */ #define BLB_eof 2 /* This blob is exhausted */ @@ -104,12 +106,13 @@ typedef struct blb { */ /* mapping blob ids for REPLAY */ - -typedef struct map { - struct blk map_header; - struct map *map_next; - struct blb *map_old_blob; - struct blb *map_new_blob; -} *MAP; +class map : public pool_alloc +{ + public: + map *map_next; + blb *map_old_blob; + blb *map_new_blob; +}; +typedef map *MAP; #endif /* _JRD_BLB_H_ */ diff --git a/src/jrd/blb_proto.h b/src/jrd/blb_proto.h index e1fcbc4c4a..3df31e4723 100644 --- a/src/jrd/blb_proto.h +++ b/src/jrd/blb_proto.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_BLB_PROTO_H_ -#define _JRD_BLB_PROTO_H_ +#ifndef JRD_BLB_PROTO_H +#define JRD_BLB_PROTO_H #include "../jrd/jrd.h" #include "../jrd/blb.h" @@ -30,38 +30,43 @@ #include "../jrd/lls.h" #include "../jrd/val.h" -#ifdef __cplusplus -//extern "C" { +// fwd decl. +class blb; +struct tra; +struct bid; +struct lls; +struct rel; +struct dsc; +struct arr; +struct nod; +struct vlu; +struct ads; + +void BLB_cancel(TDBB, blb*); +void BLB_close(TDBB, blb*); +blb* BLB_create(TDBB, tra*, bid*); +blb* BLB_create2(TDBB, tra*, bid*, USHORT, UCHAR*); +void BLB_garbage_collect(TDBB, lls*, lls*, SLONG, rel*); +blb* BLB_get_array(TDBB, tra*, bid*, ads*); +SLONG BLB_get_data(TDBB, blb*, UCHAR *, SLONG); +USHORT BLB_get_segment(TDBB, blb*, UCHAR*, USHORT); +SLONG BLB_get_slice(TDBB, tra*, bid*, UCHAR*, USHORT, SLONG*, SLONG, UCHAR*); +SLONG BLB_lseek(blb*, USHORT, SLONG); + +void BLB_move(TDBB, dsc*, dsc*, nod*); +blb* BLB_open(TDBB, tra*, bid*); +blb* BLB_open2(TDBB, tra*, bid*, USHORT, + UCHAR *); +void BLB_put_segment(TDBB, blb*, UCHAR *, USHORT); +void BLB_put_slice(TDBB, tra*, bid*, UCHAR*, USHORT, SLONG*, SLONG, UCHAR*); +void BLB_release_array(arr*); +void BLB_scalar(TDBB, tra*, bid*, USHORT, SLONG*, vlu*); + + +#ifdef REPLAY_OSRI_API_CALLS_SUBSYSTEM +extern "C" { +void DLL_EXPORT BLB_map_blobs(TDBB, struct blb*, struct blb*); +} #endif -extern void BLB_cancel(TDBB, struct blb *); -extern void BLB_close(TDBB, struct blb *); -extern struct blb *BLB_create(TDBB, struct tra *, struct bid *); -extern struct blb *BLB_create2(TDBB, struct tra *, struct bid *, USHORT, - UCHAR *); -extern void BLB_garbage_collect(TDBB, struct lls *, struct lls *, SLONG, - struct rel *); -extern struct blb *BLB_get_array(TDBB, struct tra *, struct bid *, - struct ads *); -extern SLONG BLB_get_data(TDBB, struct blb *, UCHAR *, SLONG); -extern USHORT BLB_get_segment(TDBB, struct blb *, UCHAR *, USHORT); -extern SLONG BLB_get_slice(TDBB, struct tra *, struct bid *, UCHAR *, USHORT, - SLONG *, SLONG, UCHAR *); -extern SLONG BLB_lseek(struct blb *, USHORT, SLONG); -extern void DLL_EXPORT BLB_map_blobs(TDBB, struct blb *, struct blb *); -extern void BLB_move(TDBB, struct dsc *, struct dsc *, struct nod *); -extern struct blb *BLB_open(TDBB, struct tra *, struct bid *); -extern struct blb *BLB_open2(TDBB, struct tra *, struct bid *, USHORT, - UCHAR *); -extern void BLB_put_segment(TDBB, struct blb *, UCHAR *, USHORT); -extern void BLB_put_slice(TDBB, struct tra *, struct bid *, UCHAR *, USHORT, - SLONG *, SLONG, UCHAR *); -extern void BLB_release_array(struct arr *); -extern void BLB_scalar(TDBB, struct tra *, struct bid *, USHORT, SLONG *, - struct vlu *); - -#ifdef __cplusplus -//} /* extern "C" */ -#endif - -#endif /* _JRD_BLB_PROTO_H_ */ +#endif // JRD_BLB_PROTO_H diff --git a/src/jrd/blf_proto.h b/src/jrd/blf_proto.h index 721dbad185..fe24c6e040 100644 --- a/src/jrd/blf_proto.h +++ b/src/jrd/blf_proto.h @@ -24,9 +24,7 @@ #ifndef _JRD_BLF_PROTO_H_ #define _JRD_BLF_PROTO_H_ -#ifdef __cplusplus -//extern "C" { -#endif +extern "C" { extern STATUS DLL_EXPORT BLF_close_blob(TDBB, struct ctl **); extern STATUS DLL_EXPORT BLF_create_blob(TDBB, TRA, struct ctl **, SLONG *, @@ -39,8 +37,6 @@ extern STATUS DLL_EXPORT BLF_open_blob(TDBB, TRA, struct ctl **, SLONG *, extern STATUS DLL_EXPORT BLF_put_segment(TDBB, struct ctl **, USHORT, UCHAR *); -#ifdef __cplusplus -//} /* extern "C" */ -#endif +} /* extern "C" */ #endif /* _JRD_BLF_PROTO_H_ */ diff --git a/src/jrd/blk.h b/src/jrd/blk.h index d757308fd7..fd6666debc 100644 --- a/src/jrd/blk.h +++ b/src/jrd/blk.h @@ -21,36 +21,41 @@ * Contributor(s): ______________________________________. */ -BLKDEF(type_frb, frb, 0) -BLKDEF(type_hnk, hnk, 0) -BLKDEF(type_plb, plb, 0) +/* In the new memory management code the frb, hnk, and plb types are + * internal to the management implementation, and as such are not given + * types using the general db engine typing scheme. + **/ +// BLKDEF(type_frb, frb, 0) +// BLKDEF(type_hnk, hnk, 0) +// BLKDEF(type_plb, plb, 0) + BLKDEF(type_vec, vec, sizeof(((VEC) 0)->vec_object[0])) BLKDEF(type_dbb, dbb, 0) -BLKDEF(type_bcb, bcb, sizeof(((BCB) 0)->bcb_rpt[0])) +BLKDEF(type_bcb, bcb, sizeof(((BCB) 0)->bcb_rpt[0])) /* Done 2 */ BLKDEF(type_bdb, bdb, 0) BLKDEF(type_pre, pre, 0) BLKDEF(type_lck, lck, 1) BLKDEF(type_fil, fil, 1) BLKDEF(type_pgc, pgc, 0) BLKDEF(type_rel, rel, 0) -BLKDEF(type_fmt, fmt, sizeof(((FMT) 0)->fmt_desc[0])) -BLKDEF(type_vcl, vcl, sizeof(((VCL) 0)->vcl_long[0])) -BLKDEF(type_req, req, sizeof(((REQ) 0)->req_rpb[0])) +BLKDEF(type_fmt, fmt, sizeof(((FMT) 0)->fmt_desc[0])) /* Done */ +BLKDEF(type_vcl, vcl, sizeof(((VCL) 0)->vcl_long[0])) /* Done */ +BLKDEF(type_req, req, sizeof(((REQ) 0)->req_rpb[0])) /* Done */ BLKDEF(type_tra, tra, 1) -BLKDEF(type_nod, nod, sizeof(((NOD) 0)->nod_arg[0])) -BLKDEF(type_csb, csb, sizeof(((CSB) 0)->csb_rpt[0])) +BLKDEF(type_nod, nod, sizeof(((NOD) 0)->nod_arg[0])) /* Done */ +BLKDEF(type_csb, Csb, sizeof(((CSB) 0)->csb_rpt[0])) /* Done */ BLKDEF(type_lls, lls, 0) /* linked list stack */ BLKDEF(type_rec, rec, 1) /* record parameter */ -BLKDEF(type_rsb, rsb, sizeof(((RSB) 0)->rsb_arg[0])) /* record source */ +BLKDEF(type_rsb, Rsb, sizeof(((RSB) 0)->rsb_arg[0])) /* Done record source */ BLKDEF(type_bms, bms, 0) /* bit map segment */ BLKDEF(type_dfw, dfw, 1) /* deferred work block */ BLKDEF(type_tfb, tfb, 0) /* temporary field block */ BLKDEF(type_str, str, 1) /* random string block */ -BLKDEF(type_dcc, dcc, 0) /* data compression control */ -BLKDEF(type_sbm, sbm, sizeof(((SBM) 0)->sbm_segments[0])) /* sparse bit map */ -BLKDEF(type_smb, smb, sizeof(((SMB) 0)->smb_rpt[0])) /* sort map block */ +BLKDEF(type_dcc, Dcc, 0) /* data compression control */ +BLKDEF(type_sbm, sbm, sizeof(((SBM) 0)->sbm_segments[0])) /* done sparse bit map */ +BLKDEF(type_smb, smb, sizeof(((SMB) 0)->smb_rpt[0])) /* done sort map block */ BLKDEF(type_blb, blb, 1) -BLKDEF(type_irb, irb, sizeof(((IRB) 0)->irb_value[0])) /* Index retrieval */ +BLKDEF(type_irb, irb, sizeof(((IRB) 0)->irb_value[0])) /* Done Index retrieval */ BLKDEF(type_jrn, jrn, 1) BLKDEF(type_scl, scl, 1) BLKDEF(type_fld, fld, 1) @@ -60,16 +65,16 @@ BLKDEF(type_riv, riv, 1) /* River block -- used in optimizer */ BLKDEF(type_usr, usr, 1) /* User identification block */ BLKDEF(type_att, att, 0) /* Database attachment */ BLKDEF(type_sym, sym, 0) -BLKDEF(type_fun, fun, sizeof(((FUN) 0)->fun_rpt[0])) /* Function definition */ +BLKDEF(type_fun, fun, sizeof(((FUN) 0)->fun_rpt[0])) /* Done Function definition */ BLKDEF(type_irl, irl, 0) BLKDEF(type_acc, acc, 0) BLKDEF(type_idl, idl, 0) -BLKDEF(type_rsc, rsc, 0) +BLKDEF(type_rsc, Rsc, 0) BLKDEF(type_sdw, sdw, 0) BLKDEF(type_vct, vct, 0) /* Verb actions */ BLKDEF(type_btb, btb, 0) BLKDEF(type_blf, blf, 0) -BLKDEF(type_arr, arr, sizeof(((ADS) 0)->ads_rpt[0])) /* Array description */ +BLKDEF(type_arr, arr, sizeof(((ADS) 0)->ads_rpt[0])) /* Done, but funny Array description */ BLKDEF(type_map, map, 0) BLKDEF(type_log, log, 0) BLKDEF(type_dls, dls, 1) @@ -89,4 +94,10 @@ BLKDEF(type_svc, svc, 1) /* services */ BLKDEF(type_lwt, lwt, 0) /* latch wait block */ BLKDEF(type_vcx, vcx, 0) /* view context block */ BLKDEF(type_srpb, srpb, 0) /* save rpb block */ -BLKDEF(type_opt, opt, 0) +BLKDEF(type_opt, Opt, 0) +BLKDEF(type_prf, prf, 0) +BLKDEF(type_rse, rse, 0) +BLKDEF(type_lit, lit, 0) +BLKDEF(type_asb, asb, 0) +BLKDEF(type_srl, srl, 0) +BLKDEF(type_ctl, ctl, 0) diff --git a/src/jrd/blob_filter.epp b/src/jrd/blob_filter.epp index 042b1ea16e..8e9ca585fb 100644 --- a/src/jrd/blob_filter.epp +++ b/src/jrd/blob_filter.epp @@ -70,6 +70,9 @@ static PTR filters[] = { filter_trans /* should be filter_external_file */ }; + +extern "C" { + static STATUS open_blob(TDBB, TRA, CTL*, @@ -81,7 +84,6 @@ static STATUS open_blob(TDBB, BLF); - STATUS DLL_EXPORT BLF_close_blob(TDBB tdbb, CTL * filter_handle) { /************************************** @@ -113,7 +115,7 @@ STATUS DLL_EXPORT BLF_close_blob(TDBB tdbb, CTL * filter_handle) /* Sign off from filter */ /* Walk the chain again, telling each filter stage to close */ - for (next = *filter_handle; control = next;) { + for (next = *filter_handle; (control = next);) { /* Close this stage of the filter */ control->ctl_status = user_status; @@ -132,7 +134,7 @@ STATUS DLL_EXPORT BLF_close_blob(TDBB tdbb, CTL * filter_handle) (*callback) (ACTION_free, control); } - END_CHECK_FOR_EXCEPTIONS(next->ctl_exception_message) + END_CHECK_FOR_EXCEPTIONS((TEXT*)next->ctl_exception_message) return 0; } @@ -206,7 +208,7 @@ STATUS DLL_EXPORT BLF_get_segment(TDBB tdbb, user_status[2] = gds_arg_end; } - END_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message) + END_CHECK_FOR_EXCEPTIONS((TEXT*)control->ctl_exception_message) return status; } @@ -224,7 +226,7 @@ BLF DLL_EXPORT BLF_lookup_internal_filter(TDBB tdbb, SSHORT from, SSHORT to) * Lookup blob filter in data structures. * **************************************/ - BLF blf; + BLF result; STR exception_msg; DBB dbb; @@ -234,18 +236,18 @@ BLF DLL_EXPORT BLF_lookup_internal_filter(TDBB tdbb, SSHORT from, SSHORT to) if (to == BLOB_text && from >= 0 && from < sizeof(filters) / sizeof(filters[0])) { - blf = (BLF) ALLOCP(type_blf); - blf->blf_next = NULL; - blf->blf_from = from; - blf->blf_to = to; - blf->blf_filter = filters[from]; - exception_msg = (STR) ALLOCPV(type_str, 100); + result = new(*dbb->dbb_permanent) blf; + result->blf_next = NULL; + result->blf_from = from; + result->blf_to = to; + result->blf_filter = filters[from]; + exception_msg = new(*dbb->dbb_permanent, 100) str; // SIGN ISSUE, arg 1 sprintf((char*)exception_msg->str_data, "Exception occurred in system provided internal filters for filtering internal subtype %d to text.", from); - blf->blf_exception_message = exception_msg; - return blf; + result->blf_exception_message = exception_msg; + return result; } return NULL; @@ -313,7 +315,7 @@ STATUS DLL_EXPORT BLF_put_segment(TDBB tdbb, user_status[2] = gds_arg_end; } - END_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message) + END_CHECK_FOR_EXCEPTIONS((TEXT*)control->ctl_exception_message) return status; } @@ -416,7 +418,7 @@ USHORT bpb_length, UCHAR * bpb, PTR callback, USHORT action, BLF filter) /* Initialize filter */ status = (*filter->blf_filter) (action, control); - END_CHECK_FOR_EXCEPTIONS(control->ctl_exception_message) + END_CHECK_FOR_EXCEPTIONS((TEXT*)control->ctl_exception_message) if (status) { STATUS local_status[ISC_STATUS_LENGTH]; @@ -442,3 +444,5 @@ USHORT bpb_length, UCHAR * bpb, PTR callback, USHORT action, BLF filter) return status; } + +} // extern "C" diff --git a/src/jrd/blob_filter.h b/src/jrd/blob_filter.h index 5ac95206e4..87bf7d4036 100644 --- a/src/jrd/blob_filter.h +++ b/src/jrd/blob_filter.h @@ -24,14 +24,18 @@ #ifndef JRD_BLF_H #define JRD_BLF_H +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + /* Note: The CTL structure is the internal version of the * blob control structure (ISC_BLOB_CTL) which is in ibase.h. * Therefore this structure should be kept in sync with that one, * with the exception of the internal members, which are all the * once which appear after ctl_internal. */ -typedef struct ctl +class ctl : public pool_alloc { +public: STATUS (*ctl_source)(USHORT, struct ctl*); /* Source filter */ struct ctl* ctl_source_handle; /* Argument to pass to source filter */ SSHORT ctl_to_sub_type; /* Target type */ @@ -48,21 +52,23 @@ typedef struct ctl IPTR ctl_data[8]; /* Application specific data */ void* ctl_internal[3]; /* InterBase internal-use only */ UCHAR* ctl_exception_message; /* Message to use in case of filter exception */ -} *CTL; +}; +typedef ctl *CTL; typedef STATUS(*PTR) (USHORT, CTL); /* Blob filter management */ -typedef struct blf +class blf : public pool_alloc { - struct blk blf_header; - struct blf* blf_next; /* Next known filter */ + public: + class blf* blf_next; /* Next known filter */ SSHORT blf_from; /* Source sub-type */ SSHORT blf_to; /* Target sub-type */ PTR blf_filter; /* Entrypoint of filter */ STR blf_exception_message; /* message to be used in case of filter exception */ -} *BLF; +}; +typedef blf *BLF; #define ACTION_open 0 #define ACTION_get_segment 1 diff --git a/src/jrd/block_cache.h b/src/jrd/block_cache.h new file mode 100644 index 0000000000..ab095e9d30 --- /dev/null +++ b/src/jrd/block_cache.h @@ -0,0 +1,68 @@ +#ifndef _JRD_BLOCK_CACHE_H_ +#define _JRD_BLOCK_CACHE_H_ + +#include "../common/memory/memory_pool.h" +#include "../jrd/smp_impl.h" + +template +class BlockCache +{ +public: + BlockCache(MemoryPool& p) : pool(p), head(0) {} + ~BlockCache(); + + T* newBlock(); + void returnBlock(T*) ; + +private: + struct Node + { + Node* next; + }; + MemoryPool& pool; + Node* head; + V4Mutex lock; +}; + +template +inline T* BlockCache::newBlock() +{ + lock.aquire(); + if (head) + { + T* result = reinterpret_cast(head); + head = head->next; + lock.release(); + return result; + } + lock.release(); + return new(pool) T; +} + +template +inline void BlockCache::returnBlock(T* back) +{ + Node* returned = reinterpret_cast(back); + lock.aquire(); + returned->next = head; + head = returned; + lock.release(); +} + +template +BlockCache::~BlockCache() +{ + // Notice there is no destructor? This is because all our memory + // is allocated from a pool. When the pool gets freed so will our + // storage, simple as that. No need to waste extra processor time + // freeing memory just to have it freed again! +/* Node *next; + while(head) + { + next = head->next; + delete ((T*)head); + head = next; + } */ +} + +#endif diff --git a/src/jrd/bookmark.cpp b/src/jrd/bookmark.cpp index 14f6324884..c36748e8ae 100644 --- a/src/jrd/bookmark.cpp +++ b/src/jrd/bookmark.cpp @@ -64,7 +64,7 @@ BKM BKM_allocate(RSB rsb, USHORT length) /* allocate the bookmark and link it into the linked list hanging off the attachment block */ - bookmark = (BKM) ALLOCPV(type_bkm, length); + bookmark = new(*dbb->dbb_permanent, length) bkm(); attachment = tdbb->tdbb_attachment; bookmark->bkm_next = attachment->att_bookmarks; diff --git a/src/jrd/btr.cpp b/src/jrd/btr.cpp index b0e9232ce8..f5708b0877 100644 --- a/src/jrd/btr.cpp +++ b/src/jrd/btr.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: btr.cpp,v 1.2 2001-07-29 17:42:21 skywalker Exp $ +$Id: btr.cpp,v 1.3 2001-12-24 02:50:50 tamlin Exp $ */ #include "firebird.h" @@ -241,7 +241,7 @@ USHORT BTR_all(TDBB tdbb, if ((SLONG) (root->irt_count * sizeof(IDX)) > *idx_size) { size = (sizeof(IDX) * MAX_IDX) + ALIGNMENT; - *csb_idx_allocation = new_buffer = (STR) ALLOCPV(type_str, size); + *csb_idx_allocation = new_buffer = new(*dbb->dbb_permanent, size) str(); buffer = *start_buffer = (IDX *) FB_ALIGN((U_IPTR) new_buffer->str_data, ALIGNMENT); *idx_size = size - ALIGNMENT; @@ -942,11 +942,8 @@ IDX_E BTR_key(TDBB tdbb, old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - key->key_length = 0; - return idx_e_conversion; - } + try { + #ifdef IGNORE_NULL_IDX_KEY /* Initialize KEY flags */ key->key_flags = 0; #endif /* IGNORE_NULL_IDX_KEY */ @@ -1042,6 +1039,13 @@ IDX_E BTR_key(TDBB tdbb, tdbb->tdbb_setjmp = (UCHAR *) old_env; return result; + + } // try + catch(...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + key->key_length = 0; + return idx_e_conversion; + } } @@ -1764,7 +1768,7 @@ float BTR_selectivity(TDBB tdbb, REL relation, USHORT id) /* keep the key value current for comparison with the next key */ key.key_length = l; - if (l = node->btn_length) { + if ( (l = node->btn_length) ) { p = key.key_data + node->btn_prefix; q = node->btn_data; do @@ -2266,7 +2270,7 @@ static USHORT compress_root(TDBB tdbb, IRT page) dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - temp = (UCHAR *) ALL_malloc((SLONG) dbb->dbb_page_size, ERR_jmp); + temp = (UCHAR *) tdbb->tdbb_default->allocate((SLONG) dbb->dbb_page_size); MOVE_FASTER(page, temp, dbb->dbb_page_size); p = temp + dbb->dbb_page_size; @@ -2279,7 +2283,7 @@ static USHORT compress_root(TDBB tdbb, IRT page) root_idx->irt_desc = p - temp; } l = p - temp; - ALL_free(reinterpret_cast < char *>(temp)); + MemoryPool::deallocate(temp); return l; } @@ -2334,7 +2338,7 @@ static void copy_key(KEY * in, KEY * out) out->key_flags = in->key_flags; #endif /* IGNORE_NULL_IDX_KEY */ - if (l = out->key_length = in->key_length) { + if ( (l = out->key_length = in->key_length) ) { p = out->key_data; q = in->key_data; do @@ -2632,15 +2636,15 @@ static SLONG fast_load(TDBB tdbb, tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_flags |= TDBB_no_cache_unwind; + try { + /* If there's an error during index construction, fall thru to release the last index bucket at each level of the index. This will prepare for a single attempt to deallocate the index pages for reuse. */ - if (SETJMP(env)) - error = TRUE; - - while (!error) { + while (!error) + { /* Get the next record in sorted order. */ DEBUG; @@ -2708,8 +2712,8 @@ static SLONG fast_load(TDBB tdbb, BTN_PREFIX(split_node) = 0; p = BTN_DATA(split_node); q = key->key_data; - assert(key->key_length <= MAX_UCHAR) - if (l = BTN_LENGTH(split_node) = (UCHAR) key->key_length) + assert(key->key_length <= MAX_UCHAR); + if ( (l = BTN_LENGTH(split_node) = (UCHAR) key->key_length) ) do *p++ = *q++; while (--l); @@ -2761,7 +2765,7 @@ static SLONG fast_load(TDBB tdbb, quad_put(isr->isr_record_number, BTN_NUMBER(node)); p = BTN_DATA(node); q = record + prefix; - if (l = BTN_LENGTH(node) = isr->isr_key_length - prefix) + if ( (l = BTN_LENGTH(node) = isr->isr_key_length - prefix) ) do *p++ = *q++; while (--l); @@ -2784,7 +2788,7 @@ static SLONG fast_load(TDBB tdbb, p = key->key_data; q = record; - if (l = key->key_length = isr->isr_key_length) + if ( (l = key->key_length = isr->isr_key_length) ) do *p++ = *q++; while (--l); @@ -2808,7 +2812,7 @@ static SLONG fast_load(TDBB tdbb, bucket->btr_header.pag_type = pag_index; bucket->btr_relation = relation->rel_id; bucket->btr_id = idx->idx_id; - assert(level <= MAX_UCHAR) + assert(level <= MAX_UCHAR); bucket->btr_level = (UCHAR) level; if (idx->idx_flags & idx_descending) bucket->btr_header.pag_flags |= btr_descending; @@ -2855,8 +2859,8 @@ static SLONG fast_load(TDBB tdbb, BTN_PREFIX(split_node) = 0; p = BTN_DATA(split_node); q = key->key_data; - assert(key->key_length <= MAX_UCHAR) - if (l = BTN_LENGTH(split_node) = (UCHAR) key->key_length) + assert(key->key_length <= MAX_UCHAR); + if ( (l = BTN_LENGTH(split_node) = (UCHAR) key->key_length) ) do MOVE_BYTE(q, p); while (--l); @@ -2894,7 +2898,7 @@ static SLONG fast_load(TDBB tdbb, p = BTN_DATA(node); q = temp_key.key_data + prefix; - if (l = BTN_LENGTH(node) = temp_key.key_length - prefix) + if ( (l = BTN_LENGTH(node) = temp_key.key_length - prefix) ) do MOVE_BYTE(q, p); while (--l); @@ -2965,16 +2969,16 @@ static SLONG fast_load(TDBB tdbb, SORT_fini(sort_handle, tdbb->tdbb_attachment); + } // try + catch (...) { + error = TRUE; + } + + /* If index flush fails, try to delete the index tree. If the index delete fails, just go ahead and punt. */ - if (SETJMP(env)) - if (!error) - error = TRUE; - else { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ERR_punt(); - } + try { if (error) { delete_tree(tdbb, relation->rel_id, idx->idx_id, window->win_page, 0); @@ -2989,6 +2993,16 @@ static SLONG fast_load(TDBB tdbb, tdbb->tdbb_setjmp = (UCHAR *) old_env; return window->win_page; + + } // try + catch(...) { + if (!error) + error = TRUE; + else { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + ERR_punt(); + } + } } @@ -3252,7 +3266,7 @@ static CONTENTS garbage_collect(TDBB tdbb, WIN * window, SLONG parent_number) /* fetch the right sibling page */ - if (right_window.win_page = gc_page->btr_sibling) { + if ( (right_window.win_page = gc_page->btr_sibling) ) { right_window.win_flags = 0; right_page = (BTR) CCH_FETCH(tdbb, &right_window, LCK_write, pag_index); @@ -3361,9 +3375,9 @@ static CONTENTS garbage_collect(TDBB tdbb, WIN * window, SLONG parent_number) assert(number != END_NON_NULL); #else for (last_node = left_page->btr_nodes; - number = BTR_get_quad(BTN_NUMBER(last_node)) - >= 0; last_node = NEXT_NODE(last_node)) - if (l = BTN_LENGTH(last_node)) { + (number = BTR_get_quad(BTN_NUMBER(last_node)) + >= 0); last_node = NEXT_NODE(last_node)) + if ( (l = BTN_LENGTH(last_node)) ) { p = last_key.key_data + BTN_PREFIX(last_node); q = BTN_DATA(last_node); do @@ -3734,15 +3748,12 @@ static SLONG insert_node(TDBB tdbb, /* allocate an overflow buffer which is large enough, and set up to release it in case of error */ - overflow_page = (SLONG *) ALL_malloc((SLONG) - OVERSIZE, ERR_jmp); + overflow_page = (SLONG *) plb::ALL_malloc((SLONG) + OVERSIZE); tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (overflow_page) - ALL_free(overflow_page); - ERR_punt(); - } + + try { + #endif MOVE_FASTER(bucket, overflow_page, bucket->btr_length); node = (BTN) ((UCHAR *) overflow_page + node_offset); @@ -3777,7 +3788,7 @@ static SLONG insert_node(TDBB tdbb, quad_put(insertion->iib_number, BTN_NUMBER(node)); p = BTN_DATA(node); q = key->key_data + prefix; - if (l = BTN_LENGTH(node) = key->key_length - prefix) { + if ( (l = BTN_LENGTH(node) = key->key_length - prefix) ) { do MOVE_BYTE(q, p); while (--l); @@ -3839,8 +3850,18 @@ static SLONG insert_node(TDBB tdbb, #if (defined PC_PLATFORM && !defined NETWARE_386) if (overflow_page) - ALL_free(overflow_page); + plb::ALL_free(overflow_page); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (overflow_page) { + plb::ALL_free(overflow_page); + } + ERR_punt(); + } + #endif return 0; @@ -3881,7 +3902,7 @@ midpoint = (UCHAR *) new_node; p = BTN_DATA(node); q = new_key->key_data + BTN_PREFIX(node); new_key->key_length = BTN_PREFIX(node) + BTN_LENGTH(node); - if (l = BTN_LENGTH(node)) + if ( (l = BTN_LENGTH(node)) ) do *q++ = *p++; while (--l); @@ -3928,9 +3949,8 @@ midpoint = (UCHAR *) new_node; QUAD_MOVE(BTN_NUMBER(node), BTN_NUMBER(new_node)); p = BTN_DATA(new_node); q = new_key->key_data; - assert(new_key->key_length <= - MAX_UCHAR) if (l = - BTN_LENGTH(new_node) = (UCHAR) new_key->key_length) + assert(new_key->key_length <= MAX_UCHAR); + if ( (l = BTN_LENGTH(new_node) = (UCHAR) new_key->key_length) ) do MOVE_BYTE(q, p); while (--l); @@ -4011,7 +4031,7 @@ midpoint = (UCHAR *) new_node; #if (defined PC_PLATFORM && !defined NETWARE_386) if (overflow_page) - ALL_free(overflow_page); + plb::ALL_free(overflow_page); tdbb->tdbb_setjmp = (UCHAR *) old_env; #endif @@ -4335,7 +4355,7 @@ static CONTENTS remove_leaf_node(TDBB tdbb, IIB * insertion, WIN * window) /* check to make sure the node has the same value */ p = BTN_DATA(node); q = key->key_data + BTN_PREFIX(node); - if (l = BTN_LENGTH(node)) + if ( (l = BTN_LENGTH(node)) ) do if (*p++ != *q++) { #ifdef BTR_DEBUG diff --git a/src/jrd/btr.h b/src/jrd/btr.h index 1f2b792b17..ebeace00e0 100644 --- a/src/jrd/btr.h +++ b/src/jrd/btr.h @@ -21,22 +21,18 @@ * Contributor(s): ______________________________________. */ /* -$Id: btr.h,v 1.1.1.1 2001-05-23 13:26:06 tamlin Exp $ +$Id: btr.h,v 1.2 2001-12-24 02:50:50 tamlin Exp $ */ #ifndef _JRD_BTR_H_ #define _JRD_BTR_H_ -/* Index error types */ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" -typedef enum idx_e { - idx_e_ok = 0, - idx_e_duplicate, - idx_e_keytoobig, - idx_e_nullunique, - idx_e_conversion, - idx_e_foreign -} IDX_E; +#include + +#include "../jrd/err_proto.h" /* Index error types */ #define MAX_IDX 64 /* that should be plenty of indexes */ #define MAX_KEY 256 @@ -161,8 +157,9 @@ typedef struct isr { /* Index retrieval block -- hold stuff for index retrieval */ -typedef struct irb { - struct blk irb_header; +class irb : public pool_alloc_rpt +{ + public: IDX irb_desc; /* Index descriptor */ USHORT irb_index; /* Index id */ USHORT irb_generic; /* Flags for generic search */ @@ -170,8 +167,9 @@ typedef struct irb { USHORT irb_lower_count; /* Number of segments for retrieval */ USHORT irb_upper_count; /* Number of segments for retrieval */ KEY *irb_key; /* key for equality retrival */ - struct nod *irb_value[1]; -} *IRB; + nod* irb_value[1]; +}; +typedef irb *IRB; #define irb_partial 1 /* Partial match: not all segments or starting of key only */ #define irb_starting 2 /* Only compute "starting with" key for index segment */ diff --git a/src/jrd/builtin.cpp b/src/jrd/builtin.cpp index 0811ebd3b0..49695ebb43 100644 --- a/src/jrd/builtin.cpp +++ b/src/jrd/builtin.cpp @@ -20,7 +20,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: builtin.cpp,v 1.2 2001-07-29 17:42:21 skywalker Exp $ + * $Id: builtin.cpp,v 1.3 2001-12-24 02:50:50 tamlin Exp $ */ #include "firebird.h" diff --git a/src/jrd/cch.cpp b/src/jrd/cch.cpp index 51e25b7b7c..96184af348 100644 --- a/src/jrd/cch.cpp +++ b/src/jrd/cch.cpp @@ -43,6 +43,7 @@ #include "../jrd/sbm.h" #include "../jrd/iberr.h" #include "../jrd/rse.h" +#include "../jrd/btr.h" #include "../jrd/gdsassert.h" #include "../jrd/all_proto.h" #include "../jrd/cch_proto.h" @@ -141,7 +142,7 @@ static void unmark(TDBB, WIN *); #define PAGE_LOCK_ASSERT(lock) #define PAGE_LOCK_OPT(lock, lock_type, wait) #define PAGE_LOCK_RE_POST(lock) { 0; } /* TMN: Silence compilers */ -#define PAGE_OVERHEAD (sizeof (bcb::bcb_repeat) + sizeof (struct bdb) + \ +#define PAGE_OVERHEAD (sizeof (bcb_repeat) + sizeof (struct bdb) + \ (int) dbb->dbb_page_size) #else #define PAGE_LOCK(lock, lock_type, wait) LCK_lock (tdbb, lock, lock_type, wait) @@ -149,7 +150,7 @@ static void unmark(TDBB, WIN *); #define PAGE_LOCK_ASSERT(lock) LCK_assert (tdbb, lock) #define PAGE_LOCK_OPT(lock, lock_type, wait) LCK_lock_opt (tdbb, lock, lock_type, wait) #define PAGE_LOCK_RE_POST(lock) LCK_re_post (lock) -#define PAGE_OVERHEAD (sizeof (bcb::bcb_repeat) + sizeof (struct bdb) + \ +#define PAGE_OVERHEAD (sizeof (bcb_repeat) + sizeof (struct bdb) + \ sizeof (struct lck) + (int) dbb->dbb_page_size) #endif @@ -309,15 +310,15 @@ void CCH_down_grade_dbb(DBB dbb) BCB bcb; LCK lock; struct tdbb thd_context, *tdbb; - bcb::bcb_repeat * tail, *end; + bcb_repeat *tail, *end; STATUS ast_status[20]; /* Ignore the request if the database or lock block does not appear to be valid . */ - if ((dbb->dbb_header.blk_type != (UCHAR) type_dbb) || + if ((MemoryPool::blk_type(dbb) != type_dbb) || !(lock = dbb->dbb_lock) || - (lock->lck_header.blk_type != (UCHAR) type_lck) || !(lock->lck_id)) + (MemoryPool::blk_type(lock) != type_lck) || !(lock->lck_id)) return; /* Since this routine will be called asynchronously, we must establish @@ -378,9 +379,9 @@ if (dbb->dbb_use_count) ISC_ast_enter(); dbb->dbb_ast_flags |= DBB_assert_locks; - if (bcb = dbb->dbb_bcb) { + if ( (bcb = dbb->dbb_bcb) ) { if (bcb->bcb_count) - for (tail = bcb->bcb_rpt, end = tail + bcb->bcb_count; tail < end; + for (tail = bcb->bcb_rpt, end = bcb->bcb_rpt + bcb->bcb_count; tail < end; tail++) PAGE_LOCK_ASSERT(tail->bcb_bdb->bdb_lock); } @@ -831,7 +832,7 @@ SSHORT CCH_fetch_lock(TDBB tdbb, be discarded */ if (bdb->bdb_expanded_buffer && (lock_type > LCK_read)) { - ALL_free((SCHAR *) bdb->bdb_expanded_buffer); + delete bdb->bdb_expanded_buffer; bdb->bdb_expanded_buffer = NULL; } @@ -988,12 +989,12 @@ void CCH_fini(TDBB tdbb) BDB bdb; BOOLEAN flush_error; JMP_BUF env, *old_env; - bcb::bcb_repeat * tail, *end; + bcb_repeat *tail, *end; #ifdef CACHE_WRITER EVENT event; SLONG count; QUE que; - LWT lwt; + LWT lwt_; #endif SET_TDBB(tdbb); @@ -1002,27 +1003,23 @@ void CCH_fini(TDBB tdbb) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - if (!flush_error) - flush_error = TRUE; - else { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ERR_punt(); - } + try { /* If we've been initialized, either flush buffers or release locks, depending on where we've been bug-checked; as a defensive programming measure, make sure that the buffers were actually allocated */ - if ((bcb = dbb->dbb_bcb) && (tail = bcb->bcb_rpt) && (tail->bcb_bdb)) + if ((bcb = dbb->dbb_bcb) && + (tail = bcb->bcb_rpt) && (tail->bcb_bdb)) if (dbb->dbb_flags & DBB_bugcheck || flush_error) - for (end = tail + bcb->bcb_count; tail < end; tail++) { + for (end = bcb->bcb_rpt + bcb->bcb_count; + tail < end; tail++) { bdb = tail->bcb_bdb; if (bdb->bdb_length) continue; if (bdb->bdb_expanded_buffer) { - ALL_free((SCHAR *) bdb->bdb_expanded_buffer); + delete bdb->bdb_expanded_buffer; bdb->bdb_expanded_buffer = NULL; } PAGE_LOCK_RELEASE(bdb->bdb_lock); @@ -1078,19 +1075,31 @@ void CCH_fini(TDBB tdbb) PIO_close(dbb->dbb_file); SDW_close(); - if (bcb = dbb->dbb_bcb) { + if ( (bcb = dbb->dbb_bcb) ) { while (bcb->bcb_memory) - ALL_sys_free((SCHAR *) LLS_POP(&bcb->bcb_memory)); + MemoryPool::free_from_system(LLS_POP(&bcb->bcb_memory)); #ifdef CACHE_WRITER /* Dispose off any associated latching semaphores */ while (QUE_NOT_EMPTY(bcb->bcb_free_lwt)) { que = bcb->bcb_free_lwt.que_forward; QUE_DELETE((*que)); - lwt = (LWT) BLOCK(que, LWT, lwt_waiters); - ISC_event_fini(&lwt->lwt_event); + lwt_ = (LWT) BLOCK(que, LWT, lwt_waiters); + ISC_event_fini(&lwt_->lwt_event); } #endif } + + } // try + catch (...) + { + if (!flush_error) { + flush_error = TRUE; + } else { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + ERR_punt(); + } + } + } @@ -1381,9 +1390,9 @@ void CCH_init(TDBB tdbb, ULONG number) * **************************************/ DBB dbb; - register BCB bcb; + register BCB bcb_ = 0; SLONG count; - EVENT event; + //EVENT event; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; @@ -1404,38 +1413,42 @@ void CCH_init(TDBB tdbb, ULONG number) /* Allocate and initialize buffers control block */ - while (!(bcb = (BCB) ALLOCBVR(type_bcb, number))) { - /* If the buffer control block can't be allocated, memory is - very low. Recalculate the number of buffers to account for - page buffer overhead and reduce that number by a 25% fudge - factor. */ + while (!bcb_) { + try { + bcb_ = new(*dbb->dbb_bufferpool, number) bcb; + } catch(...) { + /* If the buffer control block can't be allocated, memory is + very low. Recalculate the number of buffers to account for + page buffer overhead and reduce that number by a 25% fudge + factor. */ - number = (sizeof(bcb::bcb_repeat) * number) / PAGE_OVERHEAD; - number -= number >> 2; + number = (sizeof(bcb_repeat) * number) / PAGE_OVERHEAD; + number -= number >> 2; - if (number < MIN_PAGE_BUFFERS) - ERR_post(isc_cache_too_small, 0); + if (number < MIN_PAGE_BUFFERS) + ERR_post(isc_cache_too_small, 0); + } } - dbb->dbb_bcb = bcb; - QUE_INIT(bcb->bcb_in_use); - QUE_INIT(bcb->bcb_empty); - QUE_INIT(bcb->bcb_free_lwt); + dbb->dbb_bcb = bcb_; + QUE_INIT(bcb_->bcb_in_use); + QUE_INIT(bcb_->bcb_empty); + QUE_INIT(bcb_->bcb_free_lwt); /* initialization of memory is system-specific */ - bcb->bcb_count = memory_init(tdbb, bcb, number); - bcb->bcb_free_minimum = (SSHORT) MIN(bcb->bcb_count / 4, 128); + bcb_->bcb_count = memory_init(tdbb, bcb_, number); + bcb_->bcb_free_minimum = (SSHORT) MIN(bcb_->bcb_count / 4, 128); - if (bcb->bcb_count < MIN_PAGE_BUFFERS) + if (bcb_->bcb_count < MIN_PAGE_BUFFERS) ERR_post(isc_cache_too_small, 0); /* Log if requested number of page buffers could not be allocated. */ - if (count != (SLONG) bcb->bcb_count) + if (count != (SLONG) bcb_->bcb_count) gds__log ("Database: %s\n\tAllocated %ld page buffers of %ld requested", - dbb->dbb_file->fil_string, bcb->bcb_count, count); + dbb->dbb_file->fil_string, bcb_->bcb_count, count); if (dbb->dbb_lock->lck_logical != LCK_EX) dbb->dbb_ast_flags |= DBB_assert_locks; @@ -1455,7 +1468,7 @@ void CCH_init(TDBB tdbb, ULONG number) #ifdef CACHE_WRITER if (!(dbb->dbb_flags & DBB_read_only)) { - event = dbb->dbb_writer_event; + EVENT event = dbb->dbb_writer_event; ISC_event_init(event, 0, 0); count = ISC_event_clear(event); if (gds__thread_start @@ -1499,7 +1512,7 @@ void CCH_journal_page(TDBB tdbb, WIN * window) bdb = window->win_bdb; - if (journal = bdb->bdb_jrn_bdb) { + if ( (journal = bdb->bdb_jrn_bdb) ) { bdb->bdb_jrn_bdb = NULL; journal->bdb_length = 0; BCB_MUTEX_ACQUIRE; @@ -1750,7 +1763,7 @@ void CCH_must_write(WIN * window) -LCK CCH_page_lock(TDBB tdbb, ERR_T err_ret) +LCK CCH_page_lock(TDBB tdbb) { /************************************** * @@ -1768,13 +1781,7 @@ LCK CCH_page_lock(TDBB tdbb, ERR_T err_ret) SET_TDBB(tdbb); dbb = tdbb->tdbb_database; - if (err_ret == ERR_jmp) - lock = (LCK) ALLOCBV(type_lck, sizeof(SLONG)); - else { - lock = (LCK) ALLOCBVR(type_lck, sizeof(SLONG)); - if (!lock) - return 0; - } + lock = new(*dbb->dbb_bufferpool, sizeof(SLONG)) lck; lock->lck_type = LCK_bdb; lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type); lock->lck_length = sizeof(SLONG); @@ -2165,7 +2172,7 @@ void CCH_release_exclusive(TDBB tdbb) dbb = tdbb->tdbb_database; dbb->dbb_flags &= ~DBB_exclusive; - if (attachment = tdbb->tdbb_attachment) + if ( (attachment = tdbb->tdbb_attachment) ) attachment->att_flags &= ~ATT_exclusive; if (dbb->dbb_ast_flags & DBB_blocking) @@ -2262,7 +2269,7 @@ void DLL_EXPORT CCH_shutdown_database(DBB dbb) **************************************/ BCB bcb; BDB bdb; - bcb::bcb_repeat * tail, *end; + bcb_repeat * tail, *end; TDBB tdbb; tdbb = GET_THREAD_DATA; @@ -2298,11 +2305,7 @@ void CCH_unwind(TDBB tdbb, BOOLEAN punt) DBB dbb; BCB bcb; BDB bdb; -#ifndef SUPERSERVER - PAG page; -#endif - SSHORT i; - bcb::bcb_repeat * tail, *end; + bcb_repeat * tail, *end; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; @@ -2315,28 +2318,34 @@ void CCH_unwind(TDBB tdbb, BOOLEAN punt) - page locking (not latching) deadlock (doesn't happen on Netware) */ if (!(bcb = dbb->dbb_bcb) || (tdbb->tdbb_flags & TDBB_no_cache_unwind)) { - if (punt) + if (punt) { ERR_punt(); - else + } else { return; + } } /* A cache error has occurred. Scan the cache for buffers which may be in use and release them. */ - for (tail = bcb->bcb_rpt, end = tail + bcb->bcb_count; tail < end; tail++) { + for (tail = bcb->bcb_rpt, end = tail + bcb->bcb_count; tail < end; tail++) + { bdb = tail->bcb_bdb; #ifndef SUPERSERVER - if (bdb->bdb_length || !bdb->bdb_use_count) + if (bdb->bdb_length || !bdb->bdb_use_count) { continue; - if (bdb->bdb_flags & BDB_marked) + } + if (bdb->bdb_flags & BDB_marked) { cache_bugcheck(268); /* msg 268 buffer marked during cache unwind */ + } bdb->bdb_flags &= ~BDB_writer; - while (bdb->bdb_use_count) + while (bdb->bdb_use_count) { release_bdb(tdbb, bdb, TRUE, FALSE, FALSE); - page = bdb->bdb_buffer; + } + PAG page = bdb->bdb_buffer; if ((page->pag_type == pag_header) || - (page->pag_type == pag_transactions)) { + (page->pag_type == pag_transactions)) + { ++bdb->bdb_use_count; bdb->bdb_flags &= ~(BDB_dirty | BDB_writer | BDB_marked | BDB_faked | @@ -2345,10 +2354,12 @@ void CCH_unwind(TDBB tdbb, BOOLEAN punt) --bdb->bdb_use_count; } #else - if (!bdb->bdb_use_count) + if (!bdb->bdb_use_count) { continue; - if (bdb->bdb_io == tdbb) + } + if (bdb->bdb_io == tdbb) { release_bdb(tdbb, bdb, TRUE, FALSE, FALSE); + } if (bdb->bdb_exclusive == tdbb) { /* The sanity check below can't be enforced for the log page because the ail.c code does IO while having the log page marked (should be @@ -2358,9 +2369,11 @@ void CCH_unwind(TDBB tdbb, BOOLEAN punt) bdb->bdb_flags &= ~(BDB_writer | BDB_faked | BDB_must_write); release_bdb(tdbb, bdb, TRUE, FALSE, FALSE); } - for (i = 0; i < BDB_max_shared; i++) - if (bdb->bdb_shared[i] == tdbb) + for (int i = 0; i < BDB_max_shared; ++i) { + if (bdb->bdb_shared[i] == tdbb) { release_bdb(tdbb, bdb, TRUE, FALSE, FALSE); + } + } #endif } @@ -2436,22 +2449,19 @@ BOOLEAN CCH_write_all_shadows(TDBB tdbb, sdw = shadow ? shadow : dbb->dbb_shadow; - if (!sdw) + if (!sdw) { return TRUE; + } + + try { if (bdb->bdb_page == HEADER_PAGE) { /* allocate a spare buffer which is large enough, and set up to release it in case of error */ spare_buffer = - (SLONG *) ALL_malloc((SLONG) dbb->dbb_page_size, ERR_jmp); + (SLONG *) dbb->dbb_bufferpool->allocate((SLONG) dbb->dbb_page_size); tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (spare_buffer) - ALL_free((SCHAR *) spare_buffer); - ERR_punt(); - } page = (PAG) spare_buffer; MOVE_FAST((UCHAR *) bdb->bdb_buffer, (UCHAR *) page, HDR_SIZE); @@ -2493,7 +2503,7 @@ BOOLEAN CCH_write_all_shadows(TDBB tdbb, PAG_add_header_entry(header, HDR_root_file_name, (USHORT) strlen((char *) q), q); - if (next_file = shadow_file->fil_next) { + if ( (next_file = shadow_file->fil_next) ) { q = (UCHAR *) next_file->fil_string; last = next_file->fil_min_page - 1; PAG_add_header_entry(header, HDR_file, @@ -2542,8 +2552,18 @@ BOOLEAN CCH_write_all_shadows(TDBB tdbb, bdb->bdb_buffer = old_buffer; if (spare_buffer) - ALL_free((SCHAR *) spare_buffer); + MemoryPool::deallocate(spare_buffer); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (spare_buffer) { + MemoryPool::deallocate(spare_buffer); + } + ERR_punt(); + } + return result; } @@ -2560,7 +2580,7 @@ static BDB alloc_bdb(TDBB tdbb, BCB bcb, UCHAR ** memory) * Allocate buffer descriptor block. * **************************************/ - BDB bdb; + BDB bdb_; #ifndef PAGE_LATCHING LCK lock; #endif @@ -2569,29 +2589,30 @@ static BDB alloc_bdb(TDBB tdbb, BCB bcb, UCHAR ** memory) SET_TDBB(tdbb); dbb = tdbb->tdbb_database; - if (!(bdb = (BDB) ALLOCBR(type_bdb))) - return 0; - - bdb->bdb_dbb = dbb; + bdb_ = new(*dbb->dbb_bufferpool) bdb; + bdb_->bdb_dbb = dbb; #ifndef PAGE_LATCHING - if (!(bdb->bdb_lock = lock = CCH_page_lock(tdbb, ERR_val))) { - ALL_release((FRB)bdb); - return 0; + try { + bdb_->bdb_lock = lock = CCH_page_lock(tdbb); + } + catch (std::exception&) { + delete bdb_; + throw; } lock->lck_ast = reinterpret_cast(blocking_ast_bdb); - lock->lck_object = (BLK) bdb; + lock->lck_object = (class blk*) bdb_; #endif - bdb->bdb_buffer = (PAG) * memory; + bdb_->bdb_buffer = (PAG) * memory; *memory += dbb->dbb_page_size; - QUE_INIT(bdb->bdb_higher); - QUE_INIT(bdb->bdb_lower); - QUE_INIT(bdb->bdb_waiters); - QUE_INSERT(bcb->bcb_empty, bdb->bdb_que); + QUE_INIT(bdb_->bdb_higher); + QUE_INIT(bdb_->bdb_lower); + QUE_INIT(bdb_->bdb_waiters); + QUE_INSERT(bcb->bcb_empty, bdb_->bdb_que); - return bdb; + return bdb_; } @@ -2658,6 +2679,8 @@ static int blocking_ast_bdb(BDB bdb) RESTORE_THREAD_DATA; ISC_ast_exit(); + + return 0; } #endif @@ -2706,7 +2729,7 @@ static void btc_flush( /* Walk tree. If we get lost, reposition and continue */ - while (bdb = next) { + while ( (bdb = next) ) { /* If we're lost, reposition */ if ((bdb->bdb_page != next_page) || @@ -2894,9 +2917,9 @@ static void btc_remove(BDB bdb) /* make a new child out of the left and right children */ - if (new_child = bdb->bdb_left) { + if ( (new_child = bdb->bdb_left) ) { for (ptr = new_child; ptr->bdb_right; ptr = ptr->bdb_right); - if (ptr->bdb_right = bdb->bdb_right) + if ( (ptr->bdb_right = bdb->bdb_right) ) ptr->bdb_right->bdb_parent = ptr; } else @@ -2981,29 +3004,29 @@ static void THREAD_ROUTINE cache_reader(DBB dbb) tdbb->tdbb_default = dbb->dbb_bufferpool; tdbb->tdbb_status_vector = status_vector; tdbb->tdbb_quantum = QUANTUM; - tdbb->tdbb_attachment = (ATT) ALLOCB(type_att); + tdbb->tdbb_attachment = new(*dbb->dbb_bufferpool) att(); tdbb->tdbb_attachment->att_database = dbb; tdbb->tdbb_setjmp = (UCHAR *) env; /* This SETJMP is specifically to protect the LCK_init call: if LCK_init fails we won't be able to accomplish anything anyway, so return, unlike the other SETJMP clause further down the page. */ - if (SETJMP(env)) { + + try { + + LCK_init(tdbb, LCK_OWNER_attachment); + reader_event = dbb->dbb_reader_event; + bcb = dbb->dbb_bcb; + bcb->bcb_flags |= BCB_cache_reader; + ISC_event_post(reader_event); /* Notify our creator that we have started */ + } + catch (...) { gds__log_status(dbb->dbb_file->fil_string, status_vector); THREAD_EXIT; return; } - LCK_init(tdbb, LCK_OWNER_attachment); - reader_event = dbb->dbb_reader_event; - bcb = dbb->dbb_bcb; - bcb->bcb_flags |= BCB_cache_reader; - ISC_event_post(reader_event); /* Notify our creator that we have started */ - - if (SETJMP(env)) { - bcb = dbb->dbb_bcb; - gds__log_status(dbb->dbb_file->fil_string, status_vector); - } + try { /* Set up dual prefetch control blocks to keep multiple prefetch requests active at a time. Also helps to prevent the cache reader @@ -3092,10 +3115,16 @@ static void THREAD_ROUTINE cache_reader(DBB dbb) } LCK_fini(tdbb, LCK_OWNER_attachment); - ALL_release(tdbb->tdbb_attachment); + delete tdbb->tdbb_attachment; bcb->bcb_flags &= ~BCB_cache_reader; ISC_event_post(reader_event); THREAD_EXIT; + + } // try + catch (...) { + bcb = dbb->dbb_bcb; + gds__log_status(dbb->dbb_file->fil_string, status_vector); + } } #endif @@ -3117,7 +3146,7 @@ static void THREAD_ROUTINE cache_writer(DBB dbb) * **************************************/ struct tdbb thd_context, *tdbb; - bcb::bcb_repeat * tail, *end; + bcb_repeat * tail, *end; BCB bcb; BDB bdb; SLONG count, seq, p_off, off, starting_page; @@ -3145,31 +3174,31 @@ static void THREAD_ROUTINE cache_writer(DBB dbb) tdbb->tdbb_default = dbb->dbb_bufferpool; tdbb->tdbb_status_vector = status_vector; tdbb->tdbb_quantum = QUANTUM; - tdbb->tdbb_attachment = (ATT) ALLOCB(type_att); + tdbb->tdbb_attachment = new(*dbb->dbb_bufferpool) att; tdbb->tdbb_attachment->att_database = dbb; tdbb->tdbb_setjmp = (UCHAR *) env; /* This SETJMP is specifically to protect the LCK_init call: if LCK_init fails we won't be able to accomplish anything anyway, so return, unlike the other SETJMP clause further down the page. */ - if (SETJMP(env)) { + + try { + LCK_init(tdbb, LCK_OWNER_attachment); + writer_event = dbb->dbb_writer_event; + bcb = dbb->dbb_bcb; + bcb->bcb_flags |= BCB_cache_writer; + ISC_event_post(writer_event); + } + catch (...) { gds__log_status(dbb->dbb_file->fil_string, status_vector); THREAD_EXIT; return; } - LCK_init(tdbb, LCK_OWNER_attachment); - writer_event = dbb->dbb_writer_event; - bcb = dbb->dbb_bcb; - bcb->bcb_flags |= BCB_cache_writer; - ISC_event_post(writer_event); + try { - if (SETJMP(env)) { - bcb = dbb->dbb_bcb; - gds__log_status(dbb->dbb_file->fil_string, status_vector); - } - - while (bcb->bcb_flags & BCB_cache_writer) { + while (bcb->bcb_flags & BCB_cache_writer) + { count = ISC_event_clear(writer_event); bcb->bcb_flags |= BCB_writer_active; starting_page = -1; @@ -3287,10 +3316,16 @@ static void THREAD_ROUTINE cache_writer(DBB dbb) } LCK_fini(tdbb, LCK_OWNER_attachment); - ALL_release(reinterpret_cast < frb * >(tdbb->tdbb_attachment)); + delete tdbb->tdbb_attachment; bcb->bcb_flags &= ~BCB_cache_writer; ISC_event_post(writer_event); THREAD_EXIT; + + } // try + catch (...) { + bcb = dbb->dbb_bcb; + gds__log_status(dbb->dbb_file->fil_string, status_vector); + } } #endif @@ -3409,10 +3444,10 @@ static void check_precedence(TDBB tdbb, WIN * window, SLONG page) bcb = dbb->dbb_bcb; /* Re-initialize */ - if (precedence = bcb->bcb_free) + if ( (precedence = bcb->bcb_free) ) bcb->bcb_free = (PRE) precedence->pre_hi; else - precedence = (PRE) ALLOCB(type_pre); + precedence = new(*dbb->dbb_bufferpool) pre; precedence->pre_low = low; precedence->pre_hi = high; @@ -3483,10 +3518,10 @@ static BDB dealloc_bdb(BDB bdb) if (bdb) { #ifndef PAGE_LATCHING if (bdb->bdb_lock) - ALL_release((FRB)bdb->bdb_lock); + delete bdb->bdb_lock; #endif QUE_DELETE(bdb->bdb_que); - ALL_release(reinterpret_cast < frb * >(bdb)); + delete bdb; } return 0; @@ -3654,8 +3689,8 @@ static void expand_buffers(TDBB tdbb, ULONG number) LLS stack; QUE que, mod_que; UCHAR *memory; - struct plb *old_pool; - bcb::bcb_repeat * new_tail, *old_tail, *new_end, *old_end; + JrdMemoryPool* old_pool; + bcb_repeat * new_tail, *old_tail, *new_end, *old_end; ULONG num_per_seg, num_in_seg, left_to_do; SET_TDBB(tdbb); @@ -3680,7 +3715,7 @@ static void expand_buffers(TDBB tdbb, ULONG number) old = dbb->dbb_bcb; old_end = old->bcb_rpt + old->bcb_count; - BCB new_ = (BCB) ALLOCBV(type_bcb, number); + BCB new_ = new(*dbb->dbb_bufferpool, number) bcb; new_->bcb_count = number; new_->bcb_free_minimum = (SSHORT) MIN(number / 4, 128); /* 25% clean page reserve */ new_->bcb_checkpoint = old->bcb_checkpoint; @@ -3736,8 +3771,8 @@ static void expand_buffers(TDBB tdbb, ULONG number) /* if current segment is exhausted, allocate another */ if (!num_in_seg) { - memory = (UCHAR *) ALL_sys_alloc(((SLONG) dbb->dbb_page_size * - (num_per_seg + 1)), ERR_jmp); + memory = (UCHAR *) MemoryPool::malloc_from_system(((SLONG) dbb->dbb_page_size * + (num_per_seg + 1))); LLS_PUSH(memory, &new_->bcb_memory); memory = (UCHAR *) (((U_IPTR) memory + dbb->dbb_page_size - 1) & ~((int) dbb->dbb_page_size - 1)); @@ -3754,7 +3789,7 @@ static void expand_buffers(TDBB tdbb, ULONG number) dbb->dbb_bcb = new_; - ALL_release(reinterpret_cast < frb * >(old)); + delete old; tdbb->tdbb_default = old_pool; } @@ -3822,8 +3857,8 @@ static BDB get_buffer(TDBB tdbb, SLONG page, LATCH latch, SSHORT latch_wait) #endif QUE_MOST_RECENTLY_USED(bdb->bdb_in_use); BCB_MUTEX_RELEASE; - if (latch_return = - latch_bdb(tdbb, latch, bdb, page, latch_wait)) { + if ( (latch_return = + latch_bdb(tdbb, latch, bdb, page, latch_wait)) ) { if (latch_return == 1) return (BDB) 0; /* permitted timeout happened */ BCB_MUTEX_ACQUIRE; @@ -4000,7 +4035,7 @@ static BDB get_buffer(TDBB tdbb, SLONG page, LATCH latch, SSHORT latch_wait) /* if the page has an expanded index buffer, release it */ if (bdb->bdb_expanded_buffer) { - ALL_free((SCHAR *) bdb->bdb_expanded_buffer); + delete bdb->bdb_expanded_buffer; bdb->bdb_expanded_buffer = NULL; } @@ -4141,7 +4176,7 @@ static SSHORT latch_bdb( * -1: latch not acquired, bdb doesn't corresponds to page. * **************************************/ - LWT lwt; + LWT lwt_; SLONG count; EVENT event; QUE que; @@ -4292,31 +4327,31 @@ static SSHORT latch_bdb( if (QUE_NOT_EMPTY(bcb->bcb_free_lwt)) { que = bcb->bcb_free_lwt.que_forward; QUE_DELETE((*que)); - lwt = (LWT) BLOCK(que, LWT, lwt_waiters); + lwt_ = (LWT) BLOCK(que, LWT, lwt_waiters); } else { - lwt = (LWT) ALLOCB(type_lwt); - QUE_INIT(lwt->lwt_waiters); - ISC_event_init(&lwt->lwt_event, 0, 0); + lwt_ = new(*dbb->dbb_bufferpool) lwt; + QUE_INIT(lwt_->lwt_waiters); + ISC_event_init(&lwt_->lwt_event, 0, 0); } - lwt->lwt_flags |= LWT_pending; - lwt->lwt_latch = type; - lwt->lwt_tdbb = tdbb; + lwt_->lwt_flags |= LWT_pending; + lwt_->lwt_latch = type; + lwt_->lwt_tdbb = tdbb; /* Give priority to IO. This might prevent deadlocks while performing precedence writes. This does not cause starvation because an exclusive latch is needed to dirty the page again. */ if ((type == LATCH_io) || (type == LATCH_mark)) - QUE_INSERT(bdb->bdb_waiters, lwt->lwt_waiters) + QUE_INSERT(bdb->bdb_waiters, lwt_->lwt_waiters) else - QUE_APPEND(bdb->bdb_waiters, lwt->lwt_waiters); + QUE_APPEND(bdb->bdb_waiters, lwt_->lwt_waiters); - event = &lwt->lwt_event; + event = &lwt_->lwt_event; /* Loop until the latch is granted or until a timeout occurrs. */ for (count = ISC_event_clear(event); - ((lwt->lwt_flags & LWT_pending) && !timeout_occurred); + ((lwt_->lwt_flags & LWT_pending) && !timeout_occurred); count = ISC_event_clear(event)) { LATCH_MUTEX_RELEASE; THREAD_EXIT; @@ -4333,11 +4368,11 @@ static SSHORT latch_bdb( } bcb = dbb->dbb_bcb; /* Re-initialize */ - QUE_DELETE(lwt->lwt_waiters); - QUE_INSERT(bcb->bcb_free_lwt, lwt->lwt_waiters); + QUE_DELETE(lwt_->lwt_waiters); + QUE_INSERT(bcb->bcb_free_lwt, lwt_->lwt_waiters); /* If the latch is not granted then a timeout must have occurred. */ - if ((lwt->lwt_flags & LWT_pending) && timeout_occurred) { + if ((lwt_->lwt_flags & LWT_pending) && timeout_occurred) { LATCH_MUTEX_RELEASE; if (latch_wait == 1) { IBERR_build_status(tdbb->tdbb_status_vector, gds_deadlock, 0); @@ -4450,7 +4485,7 @@ static SSHORT lock_buffer( struct lck refresh; MOVE_CLEAR(&refresh, sizeof(struct lck)); - refresh.lck_header.blk_type = type_lck; + //refresh.lck_header.blk_type = type_lck; refresh.lck_dbb = dbb; refresh.lck_type = LCK_bdb; refresh.lck_owner_handle = @@ -4500,7 +4535,7 @@ static SSHORT lock_buffer( assert(page_type == pag_header || page_type == pag_transactions); lock->lck_ast = reinterpret_cast(blocking_ast_bdb); - lock->lck_object = (BLK) bdb; + lock->lck_object = (class blk*) bdb; bdb->bdb_flags |= BDB_no_blocking_ast; } return 1; @@ -4509,7 +4544,7 @@ static SSHORT lock_buffer( if (!lock->lck_ast) { assert(page_type == pag_header || page_type == pag_transactions); lock->lck_ast = reinterpret_cast(blocking_ast_bdb); - lock->lck_object = (BLK) bdb; + lock->lck_object = (class blk*) bdb; } /* Case: a timeout was specified, or the caller didn't want to wait, @@ -4596,7 +4631,7 @@ static ULONG memory_init(TDBB tdbb, BCB bcb, ULONG number) **************************************/ UCHAR *memory, *memory_end; SLONG page_size, memory_size, buffers, old_buffers; - bcb::bcb_repeat * tail, *end, *tail2, *old_tail; + bcb_repeat * tail, *end, *tail2, *old_tail; DBB dbb; SET_TDBB(tdbb); @@ -4614,7 +4649,7 @@ static ULONG memory_init(TDBB tdbb, BCB bcb, ULONG number) if (memory_size > (SLONG) (page_size * (number + 1))) memory_size = page_size * (number + 1); - while (!(memory = (UCHAR *) ALL_sys_alloc(memory_size, ERR_val))) { + while (!(memory = (UCHAR *) MemoryPool::malloc_from_system(memory_size))) { /* Either there's not enough virtual memory or there is but it's not virtually contiguous. Let's find out by cutting the size in half to see if the buffers can be @@ -4646,7 +4681,7 @@ static ULONG memory_init(TDBB tdbb, BCB bcb, ULONG number) overhead. Reduce this number by a 25% fudge factor to leave some memory for useful work. */ - ALL_sys_free((SCHAR *) LLS_POP(&bcb->bcb_memory)); + MemoryPool::free_from_system(LLS_POP(&bcb->bcb_memory)); memory = 0; for (tail2 = old_tail; tail2 < tail; tail2++) tail2->bcb_bdb = dealloc_bdb(tail2->bcb_bdb); @@ -4971,7 +5006,7 @@ static void release_bdb( * If rel_mark_latch is TRUE, the the value of downgrade_latch is ignored. * **************************************/ - LWT lwt; + LWT lwt_; QUE wait_que, que; SSHORT i, granted; @@ -5055,8 +5090,8 @@ static void release_bdb( for (que = wait_que->que_forward; que != wait_que; que = que->que_forward) /* Note that this loop assumes that requests for LATCH_io and LATCH_mark are queued before LATCH_shared and LATCH_exclusive. */ - if ((lwt = BLOCK(que, LWT, lwt_waiters))->lwt_flags & LWT_pending) { - switch (lwt->lwt_latch) { + if ((lwt_ = BLOCK(que, LWT, lwt_waiters))->lwt_flags & LWT_pending) { + switch (lwt_->lwt_latch) { case (LATCH_exclusive): if (bdb->bdb_use_count) { LATCH_MUTEX_RELEASE; @@ -5064,9 +5099,9 @@ static void release_bdb( } else { ++bdb->bdb_use_count; - bdb->bdb_exclusive = lwt->lwt_tdbb; - lwt->lwt_flags &= ~LWT_pending; - ISC_event_post(&lwt->lwt_event); + bdb->bdb_exclusive = lwt_->lwt_tdbb; + lwt_->lwt_flags &= ~LWT_pending; + ISC_event_post(&lwt_->lwt_event); LATCH_MUTEX_RELEASE; return; } @@ -5076,22 +5111,22 @@ static void release_bdb( break; else { ++bdb->bdb_use_count; - bdb->bdb_io = lwt->lwt_tdbb; - lwt->lwt_flags &= ~LWT_pending; - ISC_event_post(&lwt->lwt_event); + bdb->bdb_io = lwt_->lwt_tdbb; + lwt_->lwt_flags &= ~LWT_pending; + ISC_event_post(&lwt_->lwt_event); granted = TRUE; break; } case (LATCH_mark): - if (bdb->bdb_exclusive != lwt->lwt_tdbb) + if (bdb->bdb_exclusive != lwt_->lwt_tdbb) cache_bugcheck(298); /* missing exclusive latch */ if (bdb->bdb_io) break; else { - bdb->bdb_io = lwt->lwt_tdbb; - lwt->lwt_flags &= ~LWT_pending; - ISC_event_post(&lwt->lwt_event); + bdb->bdb_io = lwt_->lwt_tdbb; + lwt_->lwt_flags &= ~LWT_pending; + ISC_event_post(&lwt_->lwt_event); granted = TRUE; break; } @@ -5107,9 +5142,9 @@ static void release_bdb( if (i >= BDB_max_shared) break; ++bdb->bdb_use_count; - bdb->bdb_shared[i] = lwt->lwt_tdbb; - lwt->lwt_flags &= ~LWT_pending; - ISC_event_post(&lwt->lwt_event); + bdb->bdb_shared[i] = lwt_->lwt_tdbb; + lwt_->lwt_flags &= ~LWT_pending; + ISC_event_post(&lwt_->lwt_event); granted = TRUE; break; } @@ -5348,7 +5383,7 @@ static int write_buffer( (bdb->bdb_flags & BDB_dirty || (write_thru && bdb->bdb_flags & BDB_db_dirty)) && !(bdb->bdb_flags & BDB_marked)) { - if (result = write_page(tdbb, bdb, write_thru, status, FALSE)) + if ( (result = write_page(tdbb, bdb, write_thru, status, FALSE)) ) clear_precedence(dbb, bdb); } else diff --git a/src/jrd/cch.h b/src/jrd/cch.h index 61b8f66bd4..88b4c3cb1c 100644 --- a/src/jrd/cch.h +++ b/src/jrd/cch.h @@ -24,16 +24,23 @@ #ifndef _JRD_CCH_H_ #define _JRD_CCH_H_ +#include "../include/fb_blk.h" + /* Page buffer cache size constraints. */ #define MIN_PAGE_BUFFERS 50L #define MAX_PAGE_BUFFERS 65535L /* BCB -- Buffer control block -- one per system */ + struct bcb_repeat + { + struct bdb* bcb_bdb; /* Buffer descriptor block */ + struct que bcb_page_mod; /* Que of buffers with page mod n */ + }; -typedef struct bcb +class bcb : public pool_alloc_rpt { - struct blk bcb_header; + public: struct lls* bcb_memory; /* Large block partitioned into buffers */ struct que bcb_in_use; /* Que of buffers in use */ struct que bcb_empty; /* Que of empty buffers */ @@ -45,12 +52,9 @@ typedef struct bcb ULONG bcb_count; /* Number of buffers allocated */ ULONG bcb_checkpoint; /* Count of buffers to checkpoint */ struct sbm* bcb_prefetch; /* Bitmap of pages to prefetch */ - struct bcb_repeat - { - struct bdb* bcb_bdb; /* Buffer descriptor block */ - struct que bcb_page_mod; /* Que of buffers with page mod n */ - } bcb_rpt[1]; -} *BCB; + bcb_repeat bcb_rpt[1]; +}; +typedef bcb *BCB; #define BCB_keep_pages 1 /* set during btc_flush(), pages not removed from dirty binary tree */ #define BCB_cache_writer 2 /* cache writer thread has been started */ @@ -65,9 +69,9 @@ typedef struct bcb #define BDB_max_shared 20 /* maximum number of shared latch owners per bdb */ -typedef struct bdb +class bdb : public pool_alloc { - struct blk bdb_header; + public: struct dbb* bdb_dbb; /* Database block (for ASTs) */ struct lck* bdb_lock; /* Lock block for buffer */ struct que bdb_que; /* Buffer que */ @@ -95,7 +99,8 @@ typedef struct bdb SSHORT bdb_use_count; /* Number of active users */ SSHORT bdb_scan_count; /* concurrent sequential scans */ struct tdbb*bdb_shared[BDB_max_shared]; /* threads holding shared latches */ -} *BDB; +}; +typedef bdb *BDB; /* bdb_flags */ @@ -123,15 +128,16 @@ typedef struct bdb /* PRE -- Precedence block */ -typedef struct pre +class pre : public pool_alloc { - struct blk pre_header; + public: struct bdb* pre_hi; struct bdb* pre_low; struct que pre_lower; struct que pre_higher; SSHORT pre_flags; -} *PRE; +}; +typedef pre *PRE; #define PRE_cleared 1 @@ -172,15 +178,16 @@ typedef enum /* LWT -- Latch wait block */ -typedef struct lwt +class lwt : public pool_alloc { - struct blk lwt_header; + public: struct tdbb* lwt_tdbb; LATCH lwt_latch; /* latch type requested */ struct que lwt_waiters; /* latch queue */ struct event lwt_event; /* grant event to wait on */ USHORT lwt_flags; -} *LWT; +}; +typedef lwt *LWT; #define LWT_pending 1 /* latch request is pending */ @@ -193,9 +200,9 @@ typedef struct lwt /* Prefetch block */ -typedef struct prf +class prf : public pool_alloc { - struct blk prf_header; + public: struct tdbb*prf_tdbb; /* thread database context */ SLONG prf_start_page; /* starting page of multipage prefetch */ USHORT prf_max_prefetch; /* maximum no. of pages to prefetch */ @@ -206,7 +213,8 @@ typedef struct prf UCHAR prf_flags; struct bdb* prf_bdbs[PREFETCH_MAX_TRANSFER / MIN_PAGE_SIZE]; SCHAR prf_unaligned_buffer[PREFETCH_MAX_TRANSFER + MIN_PAGE_SIZE]; -} *PRF; +}; +typedef prf *PRF; #define PRF_active 1 /* prefetch block currently in use */ diff --git a/src/jrd/cch_proto.h b/src/jrd/cch_proto.h index 93c401554c..cfc9fc5286 100644 --- a/src/jrd/cch_proto.h +++ b/src/jrd/cch_proto.h @@ -55,7 +55,7 @@ void CCH_journal_record(TDBB, struct win *, UCHAR *, USHORT, UCHAR *, void CCH_mark(TDBB, struct win *, USHORT); void CCH_mark_must_write(TDBB, struct win *); void CCH_must_write(struct win *); -struct lck* CCH_page_lock(TDBB, enum err_t); +struct lck* CCH_page_lock(TDBB); void CCH_precedence(TDBB, struct win *, SLONG); void CCH_prefetch(struct tdbb *, SLONG *, SSHORT); BOOLEAN CCH_prefetch_pages(TDBB); diff --git a/src/jrd/cmp.cpp b/src/jrd/cmp.cpp index 4bb3775750..9097511aeb 100644 --- a/src/jrd/cmp.cpp +++ b/src/jrd/cmp.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: cmp.cpp,v 1.3 2001-07-29 17:42:21 skywalker Exp $ +$Id: cmp.cpp,v 1.4 2001-12-24 02:50:51 tamlin Exp $ */ #include "firebird.h" @@ -83,8 +83,6 @@ rel_MAX} RIDS; #undef FIELD #undef END_RELATION -extern "C" { - /* InterBase provides transparent conversion from string to date in * contexts where it makes sense. This macro checks a descriptor to * see if it is something that *could* represent a date value @@ -162,18 +160,18 @@ int DLL_EXPORT CMP_clone_active(REQ request) * Determine if a request or any of its clones are active. * **************************************/ - REQ *sub_req, *end; VEC vector; + vec::iterator sub_req, end; DEV_BLKCHK(request, type_req); if (request->req_flags & req_in_use) return TRUE; - if (vector = request->req_sub_requests) - for (sub_req = (REQ *) vector->vec_object, end = - sub_req + vector->vec_count; sub_req < end; sub_req++) - if (*sub_req && (*sub_req)->req_flags & req_in_use) + if ( (vector = request->req_sub_requests) ) + for (sub_req = vector->begin(), end = vector->end(); + sub_req < end; sub_req++) + if (*sub_req && ((REQ)(*sub_req))->req_flags & req_in_use) return TRUE; return FALSE; @@ -243,13 +241,13 @@ REQ DLL_EXPORT CMP_clone_request(TDBB tdbb, return request; if ((vector = request->req_sub_requests) && - level < vector->vec_count && - (clone = (REQ) vector->vec_object[level])) return clone; + level < vector->count() && + (clone = (REQ) (*vector)[level])) return clone; /* We need to clone the request -- find someplace to put it */ if (validate) { - if (procedure = request->req_procedure) { + if ( (procedure = request->req_procedure) ) { prc_sec_name = (procedure->prc_security_name ? (TEXT *) procedure-> prc_security_name->str_data : (TEXT *) 0); @@ -274,15 +272,22 @@ REQ DLL_EXPORT CMP_clone_request(TDBB tdbb, } } - vector = ALL_vector(request->req_pool, &request->req_sub_requests, level); + if (!vector) + { + vector = request->req_sub_requests = + vec::newVector(*request->req_pool, level+1); + } + + if (level >= vector->count()) + vector->resize(level + 1); /* Clone the request */ n = (USHORT) ((request->req_impure_size - REQ_SIZE + REQ_TAIL - 1) / REQ_TAIL); - clone = (REQ) ALL_alloc(request->req_pool, type_req, n, ERR_jmp); - vector->vec_object[level] = (BLK) clone; + clone = new(*request->req_pool, n) req; + (*vector)[level] = (BLK) clone; clone->req_attachment = tdbb->tdbb_attachment; clone->req_count = request->req_count; clone->req_pool = request->req_pool; @@ -345,59 +350,62 @@ REQ DLL_EXPORT CMP_compile2(TDBB tdbb, UCHAR* blr, USHORT internal_flag) * Compile a BLR request. * **************************************/ - CSB csb; + REQ request = 0; - PLB old_pool, new_pool; ACC access; - SCL class_; - JMP_BUF env, *old_env; SET_TDBB(tdbb); - old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = new_pool = ALL_pool(); + JrdMemoryPool* old_pool = tdbb->tdbb_default; + JrdMemoryPool* new_pool = new(*tdbb->tdbb_database->dbb_permanent) + JrdMemoryPool; + tdbb->tdbb_default = new_pool; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; + try { + + CSB csb = PAR_parse(tdbb, blr, internal_flag); + request = CMP_make_request(tdbb, &csb); + + if (internal_flag) { + request->req_flags |= req_internal; + } + + for (access = request->req_access; access; access = access->acc_next) + { +#ifndef GATEWAY + SCL class_ = SCL_get_class(access->acc_security_name); + SCL_check_access(class_, access->acc_view, access->acc_trg_name, + access->acc_prc_name, access->acc_mask, + access->acc_type, access->acc_name); +#else + SCL_check_access(access->acc_security_name, access->acc_view, + access->acc_trg_name, access->acc_prc_name, + access->acc_mask, access->acc_type, + access->acc_name); +#endif + } + + delete csb; tdbb->tdbb_default = old_pool; - if (request) + + } + catch (...) { + tdbb->tdbb_default = old_pool; + if (request) { CMP_release(tdbb, request); - else if (new_pool) - ALL_rlpool(new_pool); + } else if (new_pool) { + // TMN: Are we not to release the pool, just beqause + // we have a request?! + delete new_pool; + } ERR_punt(); } - csb = PAR_parse(tdbb, blr, internal_flag); - request = CMP_make_request(tdbb, &csb); - - if (internal_flag) - request->req_flags |= req_internal; - - for (access = request->req_access; access; access = access->acc_next) { -#ifndef GATEWAY - class_ = SCL_get_class(access->acc_security_name); - SCL_check_access(class_, access->acc_view, access->acc_trg_name, - access->acc_prc_name, access->acc_mask, - access->acc_type, access->acc_name); -#else - SCL_check_access(access->acc_security_name, access->acc_view, - access->acc_trg_name, access->acc_prc_name, - access->acc_mask, access->acc_type, - access->acc_name); -#endif - } - - ALL_RELEASE(csb); - tdbb->tdbb_setjmp = (UCHAR *) old_env; - tdbb->tdbb_default = old_pool; - return request; } -csb_repeat *DLL_EXPORT CMP_csb_element(CSB * csb, USHORT element) +csb_repeat* DLL_EXPORT CMP_csb_element(CSB* csb, USHORT element) { /************************************** * @@ -413,8 +421,8 @@ csb_repeat *DLL_EXPORT CMP_csb_element(CSB * csb, USHORT element) DEV_BLKCHK(*csb, type_csb); - if (element >= (*csb)->csb_count) { - *csb = (CSB) ALL_extend((BLK *) csb, element + 5); + if (element >= (*csb)->csb_rpt.size()) { + (*csb)->csb_rpt.resize(element + 5); (*csb)->csb_count = element + 5; } @@ -436,7 +444,8 @@ void DLL_EXPORT CMP_expunge_transaction(TRA transaction) * **************************************/ VEC vector; - REQ request, *sub, *end; + REQ request; + vec::iterator sub, end; DEV_BLKCHK(transaction, type_tra); @@ -444,11 +453,11 @@ void DLL_EXPORT CMP_expunge_transaction(TRA transaction) request; request = request->req_request) { if (request->req_transaction == transaction) request->req_transaction = NULL; - if (vector = request->req_sub_requests) - for (sub = (REQ *) vector->vec_object, end = - sub + vector->vec_count; sub < end; sub++) - if (*sub && (*sub)->req_transaction == transaction) - (*sub)->req_transaction = NULL; + if ( (vector = request->req_sub_requests) ) + for (sub = vector->begin(), end = vector->end(); + sub < end; sub++) + if (*sub && ((REQ)(*sub))->req_transaction == transaction) + ((REQ)(*sub))->req_transaction = NULL; } } @@ -1604,13 +1613,13 @@ IDL DLL_EXPORT CMP_get_index_lock(TDBB tdbb, REL relation, USHORT id) if (index->idl_id == id) return index; - index = (IDL) ALLOCP(type_idl); + index = new(*dbb->dbb_permanent) idl(); index->idl_next = relation->rel_index_locks; relation->rel_index_locks = index; index->idl_relation = relation; index->idl_id = id; - index->idl_lock = lock = (LCK) ALLOCPV(type_lck, 0); + index->idl_lock = lock = new(*dbb->dbb_permanent, 0) lck; lock->lck_parent = dbb->dbb_lock; lock->lck_dbb = dbb; lock->lck_key.lck_long = relation->rel_id * 1000 + id; @@ -1660,49 +1669,30 @@ REQ DLL_EXPORT CMP_make_request(TDBB tdbb, CSB * csb_ptr) * Turn a parsed request into an executable request. * **************************************/ -#ifdef GATEWAY - DBB dbb; -#endif - RPB *rpb; - NOD node; - CSB csb; - IDL index; - RSC resource; - REL relation; - PRC procedure; - register REQ request, old_request; - int n; - csb_repeat *tail, *end; + + REQ request = 0; LLS temp; - USHORT count; - BLK *ptr; - JMP_BUF env, *old_env; + vec::iterator ptr; DEV_BLKCHK(*csb_ptr, type_csb); SET_TDBB(tdbb); #ifdef GATEWAY - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; #endif - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - old_request = tdbb->tdbb_request; + REQ old_request = tdbb->tdbb_request; tdbb->tdbb_request = NULL; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - tdbb->tdbb_request = old_request; - ERR_punt(); - } + try { /* Once any expansion required has been done, make a pass to assign offsets into the impure area and throw away any unnecessary crude. Execution optimizations can be performed here */ DEBUG; - node = pass1(tdbb, csb_ptr, (*csb_ptr)->csb_node, 0, 0, FALSE); - csb = *csb_ptr; + NOD node = pass1(tdbb, csb_ptr, (*csb_ptr)->csb_node, 0, 0, FALSE); + CSB csb = *csb_ptr; csb->csb_node = node; csb->csb_impure = REQ_SIZE + REQ_TAIL * csb->csb_n_stream; csb->csb_node = pass2(tdbb, csb, csb->csb_node, 0); @@ -1717,8 +1707,8 @@ REQ DLL_EXPORT CMP_make_request(TDBB tdbb, CSB * csb_ptr) /* Build the final request block. First, compute the "effective" repeat count of hold the impure areas. */ - n = (csb->csb_impure - REQ_SIZE + REQ_TAIL - 1) / REQ_TAIL; - request = (REQ) ALLOCDV(type_req, n); + int n = (csb->csb_impure - REQ_SIZE + REQ_TAIL - 1) / REQ_TAIL; + request = new(*tdbb->tdbb_default, n) req; request->req_count = csb->csb_n_stream; request->req_pool = tdbb->tdbb_default; request->req_impure_size = csb->csb_impure; @@ -1726,8 +1716,9 @@ REQ DLL_EXPORT CMP_make_request(TDBB tdbb, CSB * csb_ptr) request->req_access = csb->csb_access; request->req_variables = csb->csb_variables; request->req_resources = csb->csb_resources; - if (csb->csb_g_flags & csb_blr_version4) + if (csb->csb_g_flags & csb_blr_version4) { request->req_flags |= req_blr_version4; + } #ifdef SCROLLABLE_CURSORS request->req_async_message = csb->csb_async_message; @@ -1743,30 +1734,38 @@ REQ DLL_EXPORT CMP_make_request(TDBB tdbb, CSB * csb_ptr) a little complicated since relation locks MUST be taken before index locks */ - for (resource = request->req_resources; resource; - resource = resource->rsc_next) { - switch (resource->rsc_type) { + for (RSC resource = request->req_resources; resource; + resource = resource->rsc_next) + { + switch (resource->rsc_type) + { case rsc_relation: { - relation = resource->rsc_rel; + REL relation = resource->rsc_rel; MET_post_existence(tdbb, relation); break; } case rsc_index: { - relation = resource->rsc_rel; - if (index = - CMP_get_index_lock(tdbb, relation, resource->rsc_id)) { + REL relation = resource->rsc_rel; + IDL index = + CMP_get_index_lock(tdbb, relation, resource->rsc_id); + if (index) + { if (!index->idl_count) - LCK_lock_non_blocking(tdbb, index->idl_lock, LCK_SR, - TRUE); + { + LCK_lock_non_blocking( tdbb, + index->idl_lock, + LCK_SR, + TRUE); + } ++index->idl_count; } break; } case rsc_procedure: { - procedure = resource->rsc_prc; + PRC procedure = resource->rsc_prc; procedure->prc_use_count++; #ifdef DEBUG_PROCS { @@ -1784,11 +1783,12 @@ REQ DLL_EXPORT CMP_make_request(TDBB tdbb, CSB * csb_ptr) } } - tail = csb->csb_rpt; - end = tail + csb->csb_n_stream; + csb_repeat* tail = csb->csb_rpt.begin(); + csb_repeat* end = tail + csb->csb_n_stream; DEBUG; - for (rpb = request->req_rpb; tail < end; rpb++, tail++) { + for (RPB* rpb = request->req_rpb; tail < end; rpb++, tail++) + { /* Fetch input stream for update if all booleans matched against indices. */ if (tail->csb_flags & csb_update @@ -1805,13 +1805,22 @@ REQ DLL_EXPORT CMP_make_request(TDBB tdbb, CSB * csb_ptr) #endif } - for (temp = csb->csb_fors, count = 0; temp; count++) + USHORT count; + for (temp = csb->csb_fors, count = 0; temp; count++) { temp = temp->lls_next; + } if (count) { - request->req_fors = - ALL_vector(request->req_pool, &request->req_fors, count); - ptr = request->req_fors->vec_object; + if (!request->req_fors) + { + request->req_fors = + vec::newVector(*request->req_pool, count+1); + } + if (count >= request->req_fors->count()) + { + request->req_fors->resize(count+1); + } + ptr = request->req_fors->begin(); while (csb->csb_fors) *ptr++ = (BLK) LLS_POP(&csb->csb_fors); } @@ -1819,20 +1828,33 @@ REQ DLL_EXPORT CMP_make_request(TDBB tdbb, CSB * csb_ptr) /* make a vector of all invariant-type nodes, so that we will be able to easily reinitialize them when we restart the request */ - for (temp = csb->csb_invariants, count = 0; temp; count++) + for (temp = csb->csb_invariants, count = 0; temp; count++) { temp = temp->lls_next; + } if (count) { - request->req_invariants = - ALL_vector(request->req_pool, &request->req_invariants, count); - ptr = request->req_invariants->vec_object; + if (!request->req_invariants) + { + request->req_invariants = + vec::newVector(*request->req_pool , count+1); + } + if (count >= request->req_invariants->count()) + { + request->req_invariants->resize(count+1); + } + ptr = request->req_invariants->begin(); while (csb->csb_invariants) *ptr++ = (BLK) LLS_POP(&csb->csb_invariants); } DEBUG; tdbb->tdbb_request = old_request; - tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_request = old_request; + ERR_punt(); + } return request; } @@ -1897,7 +1919,7 @@ int DLL_EXPORT CMP_post_access(TDBB tdbb, } - access = (ACC) ALLOCD(type_acc); + access = new(*tdbb->tdbb_default) acc; /* append the security class to the existing list */ if (last_entry) @@ -1957,7 +1979,7 @@ void DLL_EXPORT CMP_post_resource( if (resource->rsc_type == type && resource->rsc_id == id) return; - resource = (RSC) ALLOCD(type_rsc); + resource = new(*tdbb->tdbb_default) Rsc; resource->rsc_next = *rsc_ptr; *rsc_ptr = resource; resource->rsc_type = type; @@ -1995,7 +2017,7 @@ void DLL_EXPORT CMP_release_resource( DEV_BLKCHK(*rsc_ptr, type_rsc); - for (; resource = *rsc_ptr; rsc_ptr = &resource->rsc_next) + for (; (resource = *rsc_ptr); rsc_ptr = &resource->rsc_next) if (resource->rsc_type == type && resource->rsc_id == id) break; @@ -2005,7 +2027,7 @@ void DLL_EXPORT CMP_release_resource( /* take out of the linked list and release */ *rsc_ptr = resource->rsc_next; - ALL_RELEASE(resource); + delete resource; } @@ -2044,8 +2066,9 @@ void DLL_EXPORT CMP_decrement_prc_use_count(TDBB tdbb, PRC procedure) floating copy .i.e. an old copy or a deleted procedure. */ if ((procedure->prc_use_count == 0) && - (tdbb->tdbb_database->dbb_procedures->vec_object[procedure->prc_id] - != &procedure->prc_header)) { + ( (*tdbb->tdbb_database->dbb_procedures)[procedure->prc_id] + //!= &procedure->prc_header)) { + != (BLK) procedure)) { CMP_release(tdbb, procedure->prc_request); procedure->prc_flags &= ~PRC_being_altered; MET_remove_procedure(tdbb, procedure->prc_id, procedure); @@ -2071,7 +2094,7 @@ void DLL_EXPORT CMP_release(TDBB tdbb, REQ request) RSC resource; #ifdef GATEWAY VEC vector; - REQ *sub_req, *end; + vec::iterator sub_req, end; #endif ATT attachment; @@ -2096,10 +2119,10 @@ void DLL_EXPORT CMP_release(TDBB tdbb, REQ request) case rsc_index: { relation = resource->rsc_rel; - if (index = + if ( (index = CMP_get_index_lock(tdbb, relation, resource-> - rsc_id)) if (!--index->idl_count) + rsc_id)) ) if (!--index->idl_count) LCK_release(tdbb, index->idl_lock); break; } @@ -2119,11 +2142,11 @@ void DLL_EXPORT CMP_release(TDBB tdbb, REQ request) /* Unwind and release cursors of any sub-requests */ if (vector = request->req_sub_requests) - for (sub_req = (REQ *) vector->vec_object, end = - sub_req + vector->vec_count; sub_req < end; sub_req++) + for (sub_req = vector->begin(), end = vector->end(); + sub_req < end; sub_req++) if (*sub_req) { - EXE_unwind(tdbb, *sub_req); - FRGN_release_cursors(*sub_req); + EXE_unwind(tdbb, (REQ)*sub_req); + FRGN_release_cursors((REQ)*sub_req); } /* Unwind and release cursors of top level request */ @@ -2147,7 +2170,7 @@ void DLL_EXPORT CMP_release(TDBB tdbb, REQ request) break; } - ALL_rlpool(request->req_pool); + delete request->req_pool; } @@ -2165,8 +2188,10 @@ void DLL_EXPORT CMP_shutdown_database(TDBB tdbb) * release any data structures. * **************************************/ - REL relation, *ptr, *end; - PRC procedure, *pptr, *pend; + REL relation; + vec::iterator ptr, end; + PRC procedure; + vec::iterator pptr, pend; IDL index; VEC vector; DBB dbb; @@ -2183,9 +2208,8 @@ void DLL_EXPORT CMP_shutdown_database(TDBB tdbb) /* Go through relations and indeces and release all existence locks that might have been taken */ - for (ptr = (REL *) vector->vec_object, end = ptr + vector->vec_count; - ptr < end; ptr++) - if (relation = *ptr) { + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) + if ( (relation = (REL)*ptr) ) { if (relation->rel_existence_lock) { LCK_release(tdbb, relation->rel_existence_lock); relation->rel_use_count = 0; @@ -2203,9 +2227,8 @@ void DLL_EXPORT CMP_shutdown_database(TDBB tdbb) /* Release all procedure existence locks that might have been taken */ - for (pptr = (PRC *) vector->vec_object, pend = pptr + vector->vec_count; - pptr < pend; pptr++) - if (procedure = *pptr) { + for (pptr = vector->begin(), pend = vector->end(); pptr < pend; pptr++) + if ( (procedure = (PRC)*pptr) ) { if (procedure->prc_existence_lock) { LCK_release(tdbb, procedure->prc_existence_lock); procedure->prc_use_count = 0; @@ -2232,7 +2255,7 @@ static UCHAR *alloc_map(TDBB tdbb, CSB * csb, USHORT stream) SET_TDBB(tdbb); - string = (STR) ALLOCDV(type_str, MAP_LENGTH); + string = new(*tdbb->tdbb_default, MAP_LENGTH) str; string->str_length = MAP_LENGTH; (*csb)->csb_rpt[stream].csb_map = (UCHAR *) string->str_data; /* TMN: Here we should really have the following assert */ @@ -2724,7 +2747,7 @@ static void expand_view_nodes( /* If the stream references a view, follow map */ - if (map = csb->csb_rpt[stream].csb_map) { + if ( (map = csb->csb_rpt[stream].csb_map) ) { ++map; while (*map) expand_view_nodes(tdbb, csb, *map++, stack, type); @@ -2775,8 +2798,8 @@ static void ignore_dbkey(TDBB tdbb, CSB csb, RSE rse, REL view) stream = (USHORT) node->nod_arg[e_rel_stream]; csb->csb_rpt[stream].csb_flags |= csb_no_dbkey; - tail = csb->csb_rpt + stream; - if (relation = tail->csb_relation) + tail = &csb->csb_rpt[stream]; + if ( (relation = tail->csb_relation) ) CMP_post_access(tdbb, csb, relation->rel_security_name, (tail->csb_view) ? tail->csb_view : view, 0, 0, SCL_read, "table", relation->rel_name); @@ -2812,7 +2835,7 @@ static NOD make_defaults(TDBB tdbb, CSB * csb, USHORT stream, NOD statement) NOD node, value; LLS stack; VEC vector; - FLD *ptr1, *end; + vec::iterator ptr1, end; REL relation; USHORT field_id; UCHAR *map, local_map[MAP_LENGTH]; @@ -2841,10 +2864,9 @@ static NOD make_defaults(TDBB tdbb, CSB * csb, USHORT stream, NOD statement) stack = NULL; - for (ptr1 = (FLD *) vector->vec_object, end = - ptr1 + vector->vec_count, field_id = 0; ptr1 < end; - ptr1++, field_id++) - if (*ptr1 && (value = (*ptr1)->fld_default_value)) { + for (ptr1 = vector->begin(), end = vector->end(), field_id = 0; + ptr1 < end; ptr1++, field_id++) + if (*ptr1 && (value = ((FLD)(*ptr1))->fld_default_value)) { node = PAR_make_node(tdbb, e_asgn_length); node->nod_type = nod_assignment; node->nod_arg[e_asgn_from] = @@ -2881,7 +2903,7 @@ static NOD make_validation(TDBB tdbb, CSB * csb, USHORT stream) NOD node, validation; LLS stack; VEC vector; - FLD *ptr1, *end; + vec::iterator ptr1, end; REL relation; USHORT field_id; UCHAR *map, local_map[MAP_LENGTH]; @@ -2908,10 +2930,9 @@ static NOD make_validation(TDBB tdbb, CSB * csb, USHORT stream) stack = NULL; - for (ptr1 = (FLD *) vector->vec_object, end = - ptr1 + vector->vec_count, field_id = 0; ptr1 < end; - ptr1++, field_id++) { - if (*ptr1 && (validation = (*ptr1)->fld_validation)) { + for (ptr1 = vector->begin(), end = vector->end(), field_id = 0; + ptr1 < end; ptr1++, field_id++) { + if (*ptr1 && (validation = ((FLD)(*ptr1))->fld_validation)) { node = PAR_make_node(tdbb, e_val_length); node->nod_type = nod_validate; node->nod_arg[e_val_boolean] = @@ -2922,7 +2943,7 @@ static NOD make_validation(TDBB tdbb, CSB * csb, USHORT stream) LLS_PUSH(node, &stack); } - if (*ptr1 && (validation = (*ptr1)->fld_not_null)) { + if (*ptr1 && (validation = ((FLD)(*ptr1))->fld_not_null)) { node = PAR_make_node(tdbb, e_val_length); node->nod_type = nod_validate; node->nod_arg[e_val_boolean] = @@ -3012,7 +3033,7 @@ static NOD pass1( break; rse->nod_flags |= rse_variant; } - tail = (*csb)->csb_rpt + stream; + tail = &(*csb)->csb_rpt[stream]; if (!(relation = tail->csb_relation) || !(field = MET_get_field(relation, @@ -3135,7 +3156,7 @@ static NOD pass1( if (sub->nod_type != nod_field) break; stream = (USHORT) sub->nod_arg[e_fld_stream]; - tail = (*csb)->csb_rpt + stream; + tail = &(*csb)->csb_rpt[stream]; if (! (field = MET_get_field(tail->csb_relation, @@ -3154,21 +3175,21 @@ static NOD pass1( case nod_modify: stream = (USHORT) node->nod_arg[e_mod_new_stream]; - tail = (*csb)->csb_rpt + stream; + tail = &(*csb)->csb_rpt[stream]; tail->csb_flags |= csb_modify; pass1_modify(tdbb, csb, node); /* TMN: Here we should really have the following assert */ /* assert(node->nod_arg [e_mod_new_stream] <= MAX_USHORT); */ - if (node->nod_arg[e_mod_validate] = + if ( (node->nod_arg[e_mod_validate] = make_validation(tdbb, csb, (USHORT) node-> - nod_arg[e_mod_new_stream])) node->nod_count = + nod_arg[e_mod_new_stream])) ) node->nod_count = MAX(node->nod_count, (USHORT) e_mod_validate + 1); break; case nod_erase: stream = (USHORT) node->nod_arg[e_erase_stream]; - tail = (*csb)->csb_rpt + stream; + tail = &(*csb)->csb_rpt[stream]; tail->csb_flags |= csb_erase; pass1_erase(tdbb, csb, node); break; @@ -3183,7 +3204,7 @@ static NOD pass1( case nod_store: sub = node->nod_arg[e_sto_relation]; stream = (USHORT) sub->nod_arg[e_rel_stream]; - tail = (*csb)->csb_rpt + stream; + tail = &(*csb)->csb_rpt[stream]; tail->csb_flags |= csb_store; sub = pass1_store(tdbb, csb, node); if (sub) { @@ -3343,7 +3364,7 @@ static void pass1_erase(TDBB tdbb, CSB * csb, NOD node) for (;;) { stream = new_stream = (USHORT) node->nod_arg[e_erase_stream]; - tail = (*csb)->csb_rpt + stream; + tail = &(*csb)->csb_rpt[stream]; tail->csb_flags |= csb_erase; relation = (*csb)->csb_rpt[stream].csb_relation; view = (relation->rel_view_rse) ? relation : view; @@ -3433,7 +3454,8 @@ static NOD pass1_expand_view( NOD assign, node; REL relation; VEC fields; - FLD *ptr, *end, field; + vec::iterator ptr, end; + FLD field; LLS stack; USHORT id = 0, new_id = 0; DSC desc; @@ -3447,9 +3469,9 @@ static NOD pass1_expand_view( relation = csb->csb_rpt[org_stream].csb_relation; fields = relation->rel_fields; - for (ptr = (FLD *) fields->vec_object, end = ptr + fields->vec_count, id = - 0; ptr < end; ptr++, id++) - if (*ptr && !(*ptr)->fld_computation) { + for (ptr = fields->begin(), end = fields->end(), id = 0; + ptr < end; ptr++, id++) + if (*ptr && !((FLD)(*ptr))->fld_computation) { if (remap) { field = MET_get_field(relation, id); if (field->fld_source) @@ -3463,7 +3485,7 @@ static NOD pass1_expand_view( node = PAR_gen_field(tdbb, new_stream, new_id); CMP_get_desc(tdbb, csb, node, &desc); if (!desc.dsc_address) { - ALL_RELEASE(node); + delete node; continue; } assign = PAR_make_node(tdbb, e_asgn_length); @@ -3518,7 +3540,7 @@ static void pass1_modify(TDBB tdbb, CSB * csb, NOD node) for (;;) { stream = (USHORT) node->nod_arg[e_mod_org_stream]; new_stream = (USHORT) node->nod_arg[e_mod_new_stream]; - tail = (*csb)->csb_rpt + new_stream; + tail = &(*csb)->csb_rpt[new_stream]; tail->csb_flags |= csb_modify; relation = (*csb)->csb_rpt[stream].csb_relation; view = (relation->rel_view_rse) ? relation : view; @@ -4011,7 +4033,7 @@ static NOD pass1_store(TDBB tdbb, CSB * csb, NOD node) for (;;) { original = node->nod_arg[e_sto_relation]; stream = (USHORT) original->nod_arg[e_rel_stream]; - tail = (*csb)->csb_rpt + stream; + tail = &(*csb)->csb_rpt[stream]; tail->csb_flags |= csb_store; relation = (*csb)->csb_rpt[stream].csb_relation; view = (relation->rel_view_rse) ? relation : view; @@ -4428,7 +4450,7 @@ static NOD pass2(TDBB tdbb, register CSB csb, register NOD node, NOD parent) { NOD value; - if (value = node->nod_arg[e_asgn_missing2]) + if ( (value = node->nod_arg[e_asgn_missing2]) ) pass2(tdbb, csb, value, node); } break; @@ -4513,13 +4535,13 @@ static NOD pass2(TDBB tdbb, register CSB csb, register NOD node, NOD parent) case nod_modify: { FMT format; - DSC *desc; + fmt::fmt_desc_iterator desc; stream = (USHORT) node->nod_arg[e_mod_org_stream]; csb->csb_rpt[stream].csb_flags |= csb_update; #ifndef GATEWAY format = CMP_format(tdbb, csb, stream); - desc = format->fmt_desc; + desc = format->fmt_desc.begin(); for (id = 0; id < format->fmt_count; id++, desc++) if (desc->dsc_dtype) SBM_set(tdbb, &csb->csb_rpt[stream].csb_fields, id); @@ -4916,7 +4938,7 @@ static void plan_set(CSB csb, RSE rse, NOD plan) /* find the tail for the relation specified in the rse */ stream = (USHORT) plan_relation_node->nod_arg[e_rel_stream]; - tail = csb->csb_rpt + stream; + tail = &csb->csb_rpt[stream]; /* if the plan references a view, find the real base relation we are interested in by searching the view map */ @@ -4944,9 +4966,9 @@ static void plan_set(CSB csb, RSE rse, NOD plan) /* loop through potentially a stack of views to find the appropriate base table */ - while (map_base = tail->csb_map) { + while ( (map_base = tail->csb_map) ) { map = map_base; - tail = csb->csb_rpt + *map; + tail = &csb->csb_rpt[*map]; view_relation = tail->csb_relation; /* if the plan references the view itself, make sure that @@ -4956,7 +4978,7 @@ static void plan_set(CSB csb, RSE rse, NOD plan) if (view_relation->rel_id == plan_relation->rel_id) { if (!map_base[2]) { map++; - tail = csb->csb_rpt + *map; + tail = &csb->csb_rpt[*map]; } else /* view %s has more than one base relation; use aliases to distinguish */ @@ -4977,7 +4999,7 @@ static void plan_set(CSB csb, RSE rse, NOD plan) duplicate_map = map_base; map = NULL; for (duplicate_map++; *duplicate_map; duplicate_map++) { - duplicate_tail = csb->csb_rpt + *duplicate_map; + duplicate_tail = &csb->csb_rpt[*duplicate_map]; relation = duplicate_tail->csb_relation; if (relation && relation->rel_id == plan_relation->rel_id) { if (duplicate_relation) @@ -5000,7 +5022,7 @@ static void plan_set(CSB csb, RSE rse, NOD plan) map = map_base; for (map++; *map; map++) { - tail = csb->csb_rpt + *map; + tail = &csb->csb_rpt[*map]; relation = tail->csb_relation; alias = tail->csb_alias; @@ -5200,7 +5222,7 @@ static void post_trigger_access(TDBB tdbb, CSB csb, VEC triggers, REL view) * **************************************/ ACC access; - REQ *ptr, *end; + vec::iterator ptr, end; USHORT read_only; SET_TDBB(tdbb); @@ -5212,11 +5234,10 @@ static void post_trigger_access(TDBB tdbb, CSB csb, VEC triggers, REL view) if (!triggers) return; - for (ptr = (REQ *) triggers->vec_object, end = ptr + triggers->vec_count; - ptr < end; ptr++) + for (ptr = triggers->begin(), end = triggers->end(); ptr < end; ptr++) if (*ptr) { read_only = TRUE; - for (access = (*ptr)->req_access; access; + for (access = ((REQ)(*ptr))->req_access; access; access = access->acc_next) if (access->acc_mask & ~SCL_read) { read_only = FALSE; break; @@ -5226,7 +5247,7 @@ static void post_trigger_access(TDBB tdbb, CSB csb, VEC triggers, REL view) we must check for read-only to make sure people don't abuse the REFERENCES privilege */ - for (access = (*ptr)->req_access; access; + for (access = ((REQ)(*ptr))->req_access; access; access = access->acc_next) { if (read_only && (access->acc_mask & SCL_read)) { access->acc_mask &= ~SCL_read; @@ -5245,7 +5266,7 @@ static void post_trigger_access(TDBB tdbb, CSB csb, VEC triggers, REL view) CMP_post_access(tdbb, csb, access->acc_security_name, (access-> acc_view) ? access->acc_view : view, - (*ptr)->req_trg_name, 0, access->acc_mask, + ((REQ)(*ptr))->req_trg_name, 0, access->acc_mask, access->acc_type, access->acc_name); } } @@ -5267,7 +5288,7 @@ static void process_map(TDBB tdbb, CSB csb, NOD map, FMT * input_format) **************************************/ NOD *ptr, *end, assignment, field; FMT format; - DSC *desc, *end_desc, desc2; + DSC *desc, desc2; USHORT id, min, max, align; DEV_BLKCHK(csb, type_csb); @@ -5277,7 +5298,7 @@ static void process_map(TDBB tdbb, CSB csb, NOD map, FMT * input_format) SET_TDBB(tdbb); if (!(format = *input_format)) { - format = *input_format = (FMT) ALLOCDV(type_fmt, map->nod_count); + format = *input_format = fmt::newFmt(*tdbb->tdbb_default, map->nod_count); format->fmt_count = map->nod_count; } @@ -5290,8 +5311,7 @@ static void process_map(TDBB tdbb, CSB csb, NOD map, FMT * input_format) field = assignment->nod_arg[e_asgn_to]; id = (USHORT) field->nod_arg[e_fld_id]; if (id >= format->fmt_count) { - format = (FMT) ALL_extend((BLK *) input_format, id + 1); - format->fmt_count = id + 1; + format->fmt_desc.resize(id + 1); } desc = &format->fmt_desc[id]; CMP_get_desc(tdbb, csb, assignment->nod_arg[e_asgn_from], &desc2); @@ -5357,14 +5377,15 @@ static void process_map(TDBB tdbb, CSB csb, NOD map, FMT * input_format) /* TMN: Here we should really have the following assert */ /* assert(FLAG_BYTES (format->fmt_count) <= MAX_USHORT); */ format->fmt_length = (USHORT) FLAG_BYTES(format->fmt_count); + fmt::fmt_desc_iterator desc3, end_desc; - for (desc = format->fmt_desc, end_desc = desc + format->fmt_count; - desc < end_desc; desc++) { - align = type_alignments[desc->dsc_dtype]; + for (desc3 = format->fmt_desc.begin(), end_desc= format->fmt_desc.end(); + desc3 < end_desc; desc3++) { + align = type_alignments[desc3->dsc_dtype]; if (align) format->fmt_length = FB_ALIGN(format->fmt_length, align); - desc->dsc_address = (UCHAR *) (SLONG) format->fmt_length; - format->fmt_length += desc->dsc_length; + desc3->dsc_address = (UCHAR *) (SLONG) format->fmt_length; + format->fmt_length += desc3->dsc_length; } } @@ -5436,5 +5457,3 @@ static BOOLEAN stream_in_rse(USHORT stream, RSE rse) return FALSE; /* mark this rse as variant */ } - -} // extern "C" diff --git a/src/jrd/cmp_proto.h b/src/jrd/cmp_proto.h index 23c8bc69c9..9c3213f7af 100644 --- a/src/jrd/cmp_proto.h +++ b/src/jrd/cmp_proto.h @@ -21,51 +21,43 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_CMP_PROTO_H_ -#define _JRD_CMP_PROTO_H_ +#ifndef JRD_CMP_PROTO_H +#define JRD_CMP_PROTO_H #include "../jrd/req.h" -#ifdef __cplusplus -extern "C" { -#endif - -extern int DLL_EXPORT CMP_clone_active(struct req *); -extern struct nod *DLL_EXPORT CMP_clone_node(TDBB, struct csb *, - struct nod *); -extern struct req *DLL_EXPORT CMP_clone_request(TDBB, struct req *, USHORT, +int DLL_EXPORT CMP_clone_active(struct req*); +struct nod* DLL_EXPORT CMP_clone_node(TDBB, struct Csb*, + struct nod*); +struct req* DLL_EXPORT CMP_clone_request(TDBB, struct req*, USHORT, BOOLEAN); -extern struct req *DLL_EXPORT CMP_compile(USHORT, UCHAR *, USHORT); -extern struct req *DLL_EXPORT CMP_compile2(TDBB, UCHAR *, USHORT); -extern struct csb_repeat *DLL_EXPORT CMP_csb_element(struct csb **, USHORT); -extern void DLL_EXPORT CMP_expunge_transaction(struct tra *); -extern void DLL_EXPORT CMP_decrement_prc_use_count(TDBB, PRC); -extern struct req *DLL_EXPORT CMP_find_request(TDBB, USHORT, USHORT); -extern void DLL_EXPORT CMP_fini(TDBB); -extern struct fmt *DLL_EXPORT CMP_format(TDBB, struct csb *, USHORT); -extern void DLL_EXPORT CMP_get_desc(TDBB, register struct csb *, - register struct nod *, struct dsc *); -extern struct idl *DLL_EXPORT CMP_get_index_lock(TDBB, struct rel *, USHORT); -extern SLONG DLL_EXPORT CMP_impure(struct csb *, USHORT); -extern struct req *DLL_EXPORT CMP_make_request(TDBB, struct csb **); -extern int DLL_EXPORT CMP_post_access(TDBB, - struct csb*, - /* INOUT */ TEXT*, - struct rel*, - CONST TEXT*, - CONST TEXT*, - USHORT, - CONST TEXT*, - CONST TEXT*); -extern void DLL_EXPORT CMP_post_resource(TDBB, struct rsc **, struct blk *, - enum rsc_s, USHORT); -extern void DLL_EXPORT CMP_release_resource(struct rsc **, enum rsc_s, - USHORT); -extern void DLL_EXPORT CMP_release(TDBB, struct req *); -extern void DLL_EXPORT CMP_shutdown_database(TDBB); +struct req* DLL_EXPORT CMP_compile(USHORT, UCHAR*, USHORT); +struct req* DLL_EXPORT CMP_compile2(TDBB, UCHAR*, USHORT); +struct csb_repeat* DLL_EXPORT CMP_csb_element(struct Csb**, USHORT); +void DLL_EXPORT CMP_expunge_transaction(struct tra*); +void DLL_EXPORT CMP_decrement_prc_use_count(TDBB, PRC); +struct req* DLL_EXPORT CMP_find_request(TDBB, USHORT, USHORT); +void DLL_EXPORT CMP_fini(TDBB); +struct fmt* DLL_EXPORT CMP_format(TDBB, struct Csb*, USHORT); +void DLL_EXPORT CMP_get_desc(TDBB, register struct Csb*, + register struct nod*, struct dsc*); +struct idl* DLL_EXPORT CMP_get_index_lock(TDBB, struct rel*, USHORT); +SLONG DLL_EXPORT CMP_impure(struct Csb*, USHORT); +struct req* DLL_EXPORT CMP_make_request(TDBB, struct Csb**); +int DLL_EXPORT CMP_post_access(TDBB, + struct Csb*, + /* INOUT */ TEXT*, + struct rel*, + CONST TEXT*, + CONST TEXT*, + USHORT, + CONST TEXT*, + CONST TEXT*); +void DLL_EXPORT CMP_post_resource(TDBB, struct Rsc**, struct blk*, + enum rsc_s, USHORT); +void DLL_EXPORT CMP_release_resource(struct Rsc**, enum rsc_s, + USHORT); +void DLL_EXPORT CMP_release(TDBB, struct req*); +void DLL_EXPORT CMP_shutdown_database(TDBB); -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* _JRD_CMP_PROTO_H_ */ +#endif /* JRD_CMP_PROTO_H */ diff --git a/src/jrd/common.h b/src/jrd/common.h index 2f045f2d3c..ed150a3b21 100644 --- a/src/jrd/common.h +++ b/src/jrd/common.h @@ -27,12 +27,14 @@ * readonly databases. */ /* -$Id: common.h,v 1.5 2001-07-29 17:42:21 skywalker Exp $ +$Id: common.h,v 1.6 2001-12-24 02:50:51 tamlin Exp $ */ #ifndef JRD_COMMON_H #define JRD_COMMON_H +#include "../include/gen/autoconfig.h" + #ifdef HAVE_STDLIB_H #include #endif @@ -105,6 +107,8 @@ $Id: common.h,v 1.5 2001-07-29 17:42:21 skywalker Exp $ /* Darwin Platforms */ #ifdef DARWIN +#define __LINE__IS_INT +#define SLONGFORMAT "ld" #define ALIGNMENT 4 #define DOUBLE_ALIGN 4 #define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1)) @@ -629,8 +633,8 @@ typedef unsigned __int64 UINT64; #define DLL_EXPORT #endif -#define BOOLEAN_DEFINED -typedef unsigned char BOOLEAN; +//#define BOOLEAN_DEFINED +//typedef unsigned char BOOLEAN; #ifdef DEV_BUILD #define DEBUG_GDS_ALLOC @@ -1154,11 +1158,13 @@ typedef unsigned long UATOM; #undef ATOM_DEFINED #endif +/* #ifndef BOOLEAN_DEFINED typedef USHORT BOOLEAN; #else #undef BOOLEAN_DEFINED #endif +*/ #ifndef ISC_TIMESTAMP_DEFINED typedef SLONG ISC_DATE; @@ -1185,6 +1191,11 @@ typedef struct #endif +#ifndef SLONGFORMAT +#define SLONGFORMAT "d" +#endif + + /* variable argument definitions */ diff --git a/src/jrd/cvt.cpp b/src/jrd/cvt.cpp index 3c7afab9ec..f3fec1d6c3 100644 --- a/src/jrd/cvt.cpp +++ b/src/jrd/cvt.cpp @@ -52,6 +52,12 @@ #ifdef HAVE_TIME_H #include +#ifdef DARWIN +#include +#endif +#if defined DARWIN && !defined _TIME_H_ +#error john +#endif #endif #if !(defined REQUESTER && defined SUPERCLIENT) @@ -1161,7 +1167,7 @@ USHORT CVT_get_string_ptr(DSC * desc, desc->dsc_length - 1); if (desc->dsc_dtype == dtype_varying) { varying = (VARY *) desc->dsc_address; - *address = varying->vary_string; + *address = reinterpret_cast(varying->vary_string); return MIN(varying->vary_length, desc->dsc_length - sizeof(USHORT)); } @@ -1175,7 +1181,7 @@ USHORT CVT_get_string_ptr(DSC * desc, INTL_ASSIGN_TTYPE(&temp_desc, ttype_ascii); temp_desc.dsc_dtype = dtype_varying; CVT_move(desc, &temp_desc, err); - *address = temp->vary_string; + *address = reinterpret_cast(temp->vary_string); *ttype = INTL_TTYPE(&temp_desc); return temp->vary_length; @@ -1297,7 +1303,7 @@ USHORT CVT_make_string(DSC * desc, from_len - 1); if (desc->dsc_dtype == dtype_varying) { varying = (VARY *) desc->dsc_address; - *address = varying->vary_string; + *address = reinterpret_cast(varying->vary_string); return MIN(varying->vary_length, from_len - sizeof(USHORT)); } } @@ -1310,7 +1316,7 @@ USHORT CVT_make_string(DSC * desc, INTL_ASSIGN_TTYPE(&temp_desc, to_interp); temp_desc.dsc_dtype = dtype_varying; CVT_move(desc, &temp_desc, err); - *address = temp->vary_string; + *address = reinterpret_cast(temp->vary_string); return temp->vary_length; } @@ -1653,7 +1659,7 @@ void DLL_EXPORT CVT_move(DSC * from, DSC * to, FPTR_VOID err) /* TMN: Here we should really have the following assert */ /* assert(length <= MAX_USHORT); */ ((VARY *) p)->vary_length = (USHORT) length; - p = ((VARY *) p)->vary_string; + p = reinterpret_cast(((VARY *) p)->vary_string); CVT_COPY_BUFF(q, p, length); break; } @@ -2202,7 +2208,7 @@ static void float_to_text(DSC * from, DSC * to, FPTR_VOID err) /* Now move the result to the destination array. */ - DSC intermediate = { 0 }; + DSC intermediate; intermediate.dsc_dtype = dtype_text; intermediate.dsc_ttype = ttype_ascii; intermediate.dsc_address = (UCHAR *) temp; diff --git a/src/jrd/cvt2.cpp b/src/jrd/cvt2.cpp index b0e3b489ad..e27ee840c8 100644 --- a/src/jrd/cvt2.cpp +++ b/src/jrd/cvt2.cpp @@ -354,33 +354,42 @@ SSHORT CVT2_compare(DSC * arg1, DSC * arg2, FPTR_VOID err) /* At this point, the type of arg1 is guaranteed to be "greater than" arg2, in the sense that it is the preferred type for comparing the two. */ - switch (arg1->dsc_dtype) { - DSC desc; + switch (arg1->dsc_dtype) + { SLONG date[2]; case dtype_timestamp: + { + DSC desc; MOVE_CLEAR(&desc, sizeof(desc)); desc.dsc_dtype = dtype_timestamp; desc.dsc_length = sizeof(date); desc.dsc_address = (UCHAR *) date; CVT_move(arg2, &desc, err); return CVT2_compare(arg1, &desc, err); + } case dtype_sql_time: + { + DSC desc; MOVE_CLEAR(&desc, sizeof(desc)); desc.dsc_dtype = dtype_sql_time; desc.dsc_length = sizeof(date[0]); desc.dsc_address = (UCHAR *) date; CVT_move(arg2, &desc, err); return CVT2_compare(arg1, &desc, err); + } case dtype_sql_date: + { + DSC desc; MOVE_CLEAR(&desc, sizeof(desc)); desc.dsc_dtype = dtype_sql_date; desc.dsc_length = sizeof(date[0]); desc.dsc_address = (UCHAR *) date; CVT_move(arg2, &desc, err); return CVT2_compare(arg1, &desc, err); + } case dtype_short: { @@ -556,7 +565,7 @@ USHORT CVT2_make_string2(DSC * desc, else if (desc->dsc_dtype == dtype_varying) { varying = (VARY *) desc->dsc_address; - from_buf = varying->vary_string; + from_buf = reinterpret_cast(varying->vary_string); from_len = MIN(varying->vary_length, desc->dsc_length - sizeof(SSHORT)); from_interp = INTL_TTYPE(desc); @@ -585,7 +594,7 @@ USHORT CVT2_make_string2(DSC * desc, cs2, from_buf, from_len, err); tempptr = (UCHAR *) temp; if (needed_len > length) { - *ptr = (STR) ALLOCDV(type_str, needed_len); + *ptr = new(*tdbb->tdbb_default, needed_len) str(); (*ptr)->str_length = needed_len; tempptr = (*ptr)->str_data; length = needed_len; @@ -605,7 +614,7 @@ USHORT CVT2_make_string2(DSC * desc, INTL_ASSIGN_TTYPE(&temp_desc, to_interp); temp_desc.dsc_dtype = dtype_varying; CVT_move(desc, &temp_desc, err); - *address = temp->vary_string; + *address = reinterpret_cast(temp->vary_string); return temp->vary_length; } diff --git a/src/jrd/dbg.cpp b/src/jrd/dbg.cpp index 801e11516a..c3f14a87d2 100644 --- a/src/jrd/dbg.cpp +++ b/src/jrd/dbg.cpp @@ -71,7 +71,7 @@ int (*dbg_block) (blk *) = DBG_block; int (*dbg_eval) (int) = DBG_eval; int (*dbg_open) () = DBG_open; int (*dbg_close) () = DBG_close; -int (*dbg_pool) (int) = DBG_pool; +int (*dbg_pool) (JrdMemoryPool*) = DBG_pool; int (*dbg_pretty) (nod *, int) = DBG_pretty; int (*dbg_window) (int *) = DBG_window; int (*dbg_rpb) (rpb *) = DBG_rpb; @@ -146,19 +146,20 @@ int DBG_all(void) * **************************************/ - DBB dbb; - VEC vector; - - dbb = GET_DBB; + DBB dbb = GET_DBB; if (!dbg_file) { dbg_file = ib_fopen("tt:", "w"); } - if (!dbb || !(vector = dbb->dbb_pools)) { +// if (!dbb || !(vector = dbb->dbb_pools)) + if (!dbb || !dbb->dbb_pools.size()) + { return TRUE; } - for (unsigned int i = 0; i < vector->vec_count; ++i) { - DBG_pool(i); + dbb::pool_vec_type::iterator itr; + dbb::pool_vec_type::iterator end = dbb->dbb_pools.end(); + for (itr = dbb->dbb_pools.begin(); itr < end; ++itr) { + DBG_pool(*itr); } return TRUE; } @@ -212,7 +213,7 @@ int DBG_analyze(int pool_id) if (pool = (PLB) vector->vec_object[pool_id]) { for (hunk = pool->plb_hunks; hunk; hunk = hunk->hnk_next) { - hunk_end = hunk->hnk_address + hunk->hnk_length; + hunk_end = ((char*)hunk->hnk_address) + hunk->hnk_length; for (block = (BLK) hunk->hnk_address; block != (BLK) hunk_end; block = (BLK) ((SCHAR *) block + length)) { type = block->blk_type; @@ -346,7 +347,7 @@ int DBG_precedence(void) for (unsigned int i = 0; i < bcb->bcb_count; i++) { bdb = bcb->bcb_rpt[i].bcb_bdb; if (bdb->bdb_flags || bdb->bdb_ast_flags) { - ib_fprintf(dbg_file, "BDB %d:\tpage %d", i, bdb->bdb_page); + ib_fprintf(dbg_file, "BDB %d:\tpage %"SLONGFORMAT"", i, bdb->bdb_page); if (bdb->bdb_flags & BDB_dirty) ib_fprintf(dbg_file, ", dirty"); if (bdb->bdb_ast_flags & BDB_blocking) @@ -382,7 +383,7 @@ int DBG_precedence(void) que != &bdb->bdb_higher; que = que->que_forward) { precedence = BLOCK(que, PRE, pre_higher); hi_bdb = precedence->pre_hi; - ib_fprintf(dbg_file, " %d", hi_bdb->bdb_page); + ib_fprintf(dbg_file, " %"SLONGFORMAT"", hi_bdb->bdb_page); if (precedence->pre_flags & PRE_cleared) ib_fprintf(dbg_file, "(cleared)"); } @@ -394,7 +395,7 @@ int DBG_precedence(void) que = que->que_forward) { precedence = BLOCK(que, PRE, pre_lower); lo_bdb = precedence->pre_low; - ib_fprintf(dbg_file, " %d", lo_bdb->bdb_page); + ib_fprintf(dbg_file, " %"SLONGFORMAT"", lo_bdb->bdb_page); if (precedence->pre_flags & PRE_cleared) ib_fprintf(dbg_file, "(cleared)"); } @@ -521,6 +522,8 @@ int DBG_block(register BLK block) } ib_fprintf(dbg_file, "\n"); break; + default: /* Shut up compiler warnings */ + break; } return TRUE; @@ -554,9 +557,9 @@ int DBG_check(int pool_id) if (!(vector = dbb->dbb_pools)) return corrupt; - if (pool = (PLB) vector->vec_object[pool_id]) { + if ( (pool = (PLB) vector->vec_object[pool_id]) ) { for (hunk = pool->plb_hunks; hunk; hunk = hunk->hnk_next) { - hunk_end = hunk->hnk_address + hunk->hnk_length; + hunk_end = ((char*)hunk->hnk_address) + hunk->hnk_length; for (block = (BLK) hunk->hnk_address; block != (BLK) hunk_end; block = (BLK) ((SCHAR *) block + (block->blk_length << SHIFT))) { @@ -685,7 +688,7 @@ int DBG_open(void) } -int DBG_pool(int pool_id) +int DBG_pool(JrdMemoryPool *pool) { /************************************** * @@ -697,37 +700,7 @@ int DBG_pool(int pool_id) * Print all known blocks. * **************************************/ - DBB dbb; - HNK hunk; - BLK block; - VEC vector; - PLB pool; - SCHAR *hunk_end; - - dbb = GET_DBB; - - if (!(vector = dbb->dbb_pools)) - return TRUE; - - if (pool = (PLB) vector->vec_object[pool_id]) { - ib_fprintf(dbg_file, "\nPool %d\n", pool->plb_pool_id); - for (hunk = pool->plb_hunks; hunk; hunk = hunk->hnk_next) { - ib_fprintf(dbg_file, "HUNK address %X, length %d\n", - hunk->hnk_address, hunk->hnk_length); - hunk_end = hunk->hnk_address + hunk->hnk_length; - for (block = (BLK) hunk->hnk_address; block != (BLK) hunk_end; - block = - (BLK) ((SCHAR *) block + (block->blk_length << SHIFT))) { - if (block->blk_pool_id != (UCHAR) pool_id) { - ib_fprintf(dbg_file, "%X\t*** BAD POOL ID (%d) ***\n", - block, block->blk_pool_id); - break; - } - if (!DBG_block(block)) - break; - } - } - } + pool->print_memory_pool_info(dbg_file, 0, DBG_block); return TRUE; } @@ -753,8 +726,8 @@ int DBG_pretty(register NOD node, register int column) #define NODE(struct) ((struct) node) - if (node && node->nod_header.blk_type == (SCHAR) type_rsb) - return rsb_pretty(reinterpret_cast < rsb * >(node), column); + if (node && node->blk_type == (SCHAR) type_rsb) + return rsb_pretty(reinterpret_cast < Rsb * >(node), column); ib_fprintf(dbg_file, "%8X\t", node); for (i = 0; i < column; i++) @@ -763,10 +736,10 @@ int DBG_pretty(register NOD node, register int column) if (node == NULL) return ib_fprintf(dbg_file, "*** null ***\n"); - if (node->nod_header.blk_type != (SCHAR) type_nod) + if (node->blk_type != (SCHAR) type_nod) return ib_fprintf(dbg_file, "*** bad node ***\n"); - ib_fprintf(dbg_file, "%s (%d)", node_names[(int) node->nod_type], + ib_fprintf(dbg_file, "%s (%"SLONGFORMAT")", node_names[(int) node->nod_type], node->nod_impure); column += 4; @@ -879,9 +852,11 @@ int DBG_pretty(register NOD node, register int column) } if (node->nod_type == nod_for && node->nod_arg[e_for_rsb]) - rsb_pretty(reinterpret_cast < rsb * >(node->nod_arg[e_for_rsb]), + rsb_pretty(reinterpret_cast < Rsb * >(node->nod_arg[e_for_rsb]), column); return TRUE; + + return FALSE; } extern "C" @@ -1162,7 +1137,7 @@ static int prt_fields(SCHAR * block, int *fields) column = 99; - while (string = (TEXT *) * fields++) { + while ( (string = (TEXT *) * fields++) ) { offset = *fields++; length = *fields++; ptr = (SCHAR *) block + offset; @@ -1236,14 +1211,14 @@ static int rsb_pretty(register RSB rsb, register int column) if (rsb == NULL) return ib_fprintf(dbg_file, "*** null ***\n"); - if (rsb->rsb_header.blk_type != (SCHAR) type_rsb) + if (rsb->blk_type != (SCHAR) type_rsb) return ib_fprintf(dbg_file, "*** bad rsb ***\n"); ib_fprintf(dbg_file, "%s (%d), stream: %d", rsb_names[(int) rsb->rsb_type], rsb->rsb_impure, rsb->rsb_stream); - if (relation = rsb->rsb_relation) + if ( (relation = rsb->rsb_relation) ) ib_fprintf(dbg_file, " %s", relation->rel_name); column += 4; diff --git a/src/jrd/dbg_proto.h b/src/jrd/dbg_proto.h index 594bda2338..03bb171589 100644 --- a/src/jrd/dbg_proto.h +++ b/src/jrd/dbg_proto.h @@ -43,7 +43,7 @@ int DBG_eval(int); int DBG_examine(int *); int DBG_init(void); int DBG_open(void); -int DBG_pool(int); +int DBG_pool(class JrdMemoryPool*); int DBG_pretty(struct nod *, int); int DBG_rpb(struct rpb *); int DBG_smb(struct smb *, int); diff --git a/src/jrd/dbt.cpp b/src/jrd/dbt.cpp index b47acd6ab8..45919c9ba3 100644 --- a/src/jrd/dbt.cpp +++ b/src/jrd/dbt.cpp @@ -46,23 +46,27 @@ TEXT_PTR dbt_window[] = { FLD(WIN *, "Buffer: %x", win_buffer), FLD(WIN *, "BDB: %x", win_bdb), FLD(WIN *, "Scans: %d", win_scans), - FLD(WIN *, "Flags: %x", win_flags), 0 -}, dbt_rpb[] = { + FLD(WIN *, "Flags: %x", win_flags), + 0 +}, +dbt_rpb[] = { FLD(RPB *, "Relation %x", rpb_relation), - FLD(RPB *, "Number %ld", rpb_number), - FLD(RPB *, "Trans %ld", rpb_transaction), - FLD(RPB *, "Page %ld", rpb_page), - FLD(RPB *, "Line %x", rpb_line), - FLD(RPB *, "Back page %ld", rpb_b_page), - FLD(RPB *, "Line %x", rpb_b_line), - FLD(RPB *, "Fragment page %ld", rpb_f_page), - FLD(RPB *, "Line %x", rpb_f_line), - FLD(RPB *, "Format %x", rpb_format_number), - FLD(RPB *, "Address: %x ", rpb_address), - FLD(RPB *, "Length %x", rpb_length), - FLD(RPB *, "Record %x", rpb_record), - FLD(RPB *, "Flags %x", rpb_flags), 0}; + FLD(RPB *, "Number %ld", rpb_number), + FLD(RPB *, "Trans %ld", rpb_transaction), + FLD(RPB *, "Page %ld", rpb_page), + FLD(RPB *, "Line %x", rpb_line), + FLD(RPB *, "Back page %ld", rpb_b_page), + FLD(RPB *, "Line %x", rpb_b_line), + FLD(RPB *, "Fragment page %ld", rpb_f_page), + FLD(RPB *, "Line %x", rpb_f_line), + FLD(RPB *, "Format %x", rpb_format_number), + FLD(RPB *, "Address: %x ", rpb_address), + FLD(RPB *, "Length %x", rpb_length), + FLD(RPB *, "Record %x", rpb_record), + FLD(RPB *, "Flags %x", rpb_flags), + 0 +}; static TEXT_PTR dbb_stuff[] = { "DATABASE", @@ -75,63 +79,106 @@ static TEXT_PTR dbb_stuff[] = { FLD(DBB, "Page_size: %d", dbb_page_size), FLD(DBB, "dp_per_pp: %d", dbb_dp_per_pp), 0 -}, vec[] = { -"VECTOR", FLD(VEC, "Count %d", vec_count), 0}, vcl[] = { -"VECTOR OF ULONGS", FLD(VCL, "Count %d", vcl_count), 0}, frb[] = { -"FREE", FLD(FRB, "Next %x", frb_next), 0}, hnk[] = { - +}, +vec[] = { + "VECTOR", +// TMN: FIXFIX! John? +// FLD(VEC, "Count %d", vec_count), + "Count %d", (SCHAR*)4, (SCHAR*)4, + 0 +}, +vcl[] = { + "VECTOR OF ULONGS", +// TMN: FIXFIX! John? +// FLD(VCL, "Count %d", vcl_count), + "Count %d", (SCHAR*)4, (SCHAR*)4, + 0 +}; +/*frb[] = { + "FREE", +// TMN: FIXFIX! John? +// FLD(FRB, "Next %x", frb_next), + "Next %x", (SCHAR*)4, (SCHAR*)4, + 0 +};*/ +/*static TEXT_PTR hnk[] = { "HUNK", FLD(HNK, "Addr: %x", hnk_address), FLD(HNK, "Len: %d", hnk_length), - - FLD(HNK, "Next: %x", hnk_next), 0}, plb[] = { + FLD(HNK, "Next: %x", hnk_next), + 0 +}; +*/ +/*static TEXT_PTR plb[] = { "POOL", FLD(PLB, "Id: %d", plb_pool_id), FLD(PLB, "Free: %x", plb_free), + FLD(PLB, "Hunk: %x", plb_hunks), + 0 +};*/ - FLD(PLB, "Hunk: %x", plb_hunks), 0}, bcb[] = { -"BUFFER CONTROL", FLD(BCB, "Count: %x", bcb_count), 0}, bdb[] = { - +static TEXT_PTR bcb[] = { + "BUFFER CONTROL", + FLD(BCB, "Count: %x", bcb_count), + 0 +}, +bdb[] = { "BUFFER DESCRIPTOR", FLD(BDB, "Page: %ld", bdb_page), FLD(BDB, "Lock: %x", bdb_lock), FLD(BDB, "Buffer: %x", bdb_buffer), FLD(BDB, "Use count: %x", bdb_use_count), - FLD(BDB, "Flags: %x", bdb_flags), 0}, pre[] = { - + FLD(BDB, "Flags: %x", bdb_flags), + 0 +}, +pre[] = { "PRECEDENCE", FLD(PRE, "Flags: %x", pre_flags), FLD(PRE, "Low: %x", pre_low), - - FLD(PRE, "High: %x", pre_hi), 0}, lck[] = { + FLD(PRE, "High: %x", pre_hi), + 0 +}, +lck[] = { "LOCK", FLD(LCK, "Parent: %x", lck_parent), FLD(LCK, "Object: %x", lck_object), FLD(LCK, "Type: %x", lck_type), FLD(LCK, "Physical: %x", lck_physical), FLD(LCK, "Logical: %x", lck_logical), - FLD(LCK, "Length: %x", lck_length), 0}, fil[] = { -"FILE", FLD(FIL, "File desc: %x", fil_desc), 0}, pgc[] = { - + FLD(LCK, "Length: %x", lck_length), + 0 +}, +fil[] = { + "FILE", + FLD(FIL, "File desc: %x", fil_desc), + 0 +}, +pgc[] = { "PAGE CONTROL", FLD(PGC, "High water: %d", pgc_high_water), FLD(PGC, "Pages/PIP: %x", pgc_ppp), FLD(PGC, "First PIP: %x", pgc_pip), - FLD(PGC, "Bytes/PIP: %x", pgc_bytes), 0}, rel[] = { - + FLD(PGC, "Bytes/PIP: %x", pgc_bytes), + 0 +}, +rel[] = { "RELATION", FLD(REL, "%s", rel_name), FLD(REL, "Id: %d", rel_id), FLD(REL, "Current format: %x", rel_current_format), FLD(REL, "Formats: %x", rel_formats), FLD(REL, "Pages: %x", rel_pages), - FLD(REL, "Root: %ld", rel_index_root), 0}, fmt[] = { - + FLD(REL, "Root: %ld", rel_index_root), + 0 +}, +fmt[] = { "FORMAT", FLD(FMT, "Count: %d", fmt_count), FLD(FMT, "Length: %d", fmt_length), - FLD(FMT, "Version: %d", fmt_version), 0}, req[] = { - + FLD(FMT, "Version: %d", fmt_version), + 0 +}, +req[] = { "REQUEST", FLD(REQ, "COUNT: %x", req_count), FLD(REQ, "Impure: %x", req_impure_size), @@ -149,8 +196,10 @@ static TEXT_PTR dbb_stuff[] = { FLD(REQ, "Next: %x", req_next), FLD(REQ, "Label: %x", req_label), FLD(REQ, "Op: %x", req_operation), - - FLD(REQ, "Flags: %x", req_flags), 0}, tra[] = { + FLD(REQ, "Flags: %x", req_flags), + 0 +}, +tra[] = { "TRANSACTION", FLD(TRA, "Number: %ld", tra_number), FLD(TRA, "Oldest: %ld", tra_oldest), @@ -158,62 +207,91 @@ static TEXT_PTR dbb_stuff[] = { FLD(TRA, "Pool: %x", tra_pool), FLD(TRA, "Lock: %x", tra_lock), FLD(TRA, "Locks: %x", tra_relation_locks), - FLD(TRA, "Flags: %x", tra_flags), 0}, nod[] = { - + FLD(TRA, "Flags: %x", tra_flags), + 0 +}, +nod[] = { "NODE", FLD(NOD, "Type: %x", nod_type), - - FLD(NOD, "Impure: %x", nod_impure), 0}, lls[] = { + FLD(NOD, "Impure: %x", nod_impure), + 0 +}, +lls[] = { "LINKED LIST STACK", FLD(LLS, "Object: %x", lls_object), - - FLD(LLS, "Next: %x", lls_next), 0}, rec[] = { -"RECORD", FLD(REC, "Format: %x", rec_format), 0}, rsb[] = { - + FLD(LLS, "Next: %x", lls_next), + 0 +}, +rec[] = { + "RECORD", + FLD(REC, "Format: %x", rec_format), + 0 +}, +Rsb[] = { "RECORD SOURCE BLOCK", FLD(RSB, "Type: %x", rsb_type), FLD(RSB, "Stream: %x", rsb_stream), FLD(RSB, "Relation: %x", rsb_relation), FLD(RSB, "Next: %x", rsb_next), - - FLD(RSB, "Count: %x", rsb_count), 0}, opt[] = { + FLD(RSB, "Count: %x", rsb_count), + 0 +}, +opt[] = { "OPTIMIZER", FLD(OPT, "CSB: %x", opt_csb), - - FLD(OPT, "Cnt: %x", opt_count), 0}, bms[] = { + FLD(OPT, "Cnt: %x", opt_count), + 0 +}, +bms[] = { "BIT MAP SEGMENT", FLD(BMS, "Min: %x", bms_min), - - FLD(BMS, "Max: %x", bms_max), 0}, dfw[] = { + FLD(BMS, "Max: %x", bms_max), + 0 +}, +dfw[] = { "DEFERRED WORK BLOCK", FLD(DFW, "type: %d", dfw_type), FLD(DFW, "next: %x", dfw_next), - - FLD(DFW, "name: %s", dfw_name), 0}, tfb[] = { + FLD(DFW, "name: %s", dfw_name), + 0 +}, +tfb[] = { "TEMPORY FIELD BLOCK", FLD(TFB, "id: %d", tfb_id), FLD(TFB, "dtype: %d", tfb_desc.dsc_dtype), FLD(TFB, "scale: %d", tfb_desc.dsc_scale), - FLD(TFB, "len: %d", tfb_desc.dsc_length), 0}, str[] = { -"string", FLD(STR, "length: %d", str_length), 0}, dcc[] = { - + FLD(TFB, "len: %d", tfb_desc.dsc_length), + 0 +}, +str[] = { + "string", + FLD(STR, "length: %d", str_length), + 0 +}, +Dcc[] = { "DATA COMPRESSION CONTROL", FLD(DCC, "next: %x", dcc_next), - - FLD(DCC, "end: %x", dcc_end), 0}, sbm[] = { + FLD(DCC, "end: %x", dcc_end), + 0 +}, +sbm[] = { "SPARE BIT MAP", FLD(SBM, "state: %d", sbm_state), FLD(SBM, "count: %d", sbm_count), FLD(SBM, "used: %d", sbm_used), FLD(SBM, "high water: %d", sbm_high_water), - FLD(SBM, "number: %d", sbm_number), 0}, smb[] = { - + FLD(SBM, "number: %d", sbm_number), + 0 +}, +smb[] = { "SORT MAP", FLD(SMB, "count: %d", smb_count), FLD(SMB, "keys: %d", smb_keys), FLD(SMB, "length: %d", smb_length), - FLD(SMB, "sort key: %x", smb_key_desc), 0}, blb[] = { - + FLD(SMB, "sort key: %x", smb_key_desc), + 0 +}, +blb[] = { "BLOB", FLD(BLB, "Relation: %x", blb_relation), FLD(BLB, "Count: %d", blb_count), @@ -221,44 +299,62 @@ static TEXT_PTR dbb_stuff[] = { FLD(BLB, "Max seg: %d", blb_max_segment), FLD(BLB, "Flags: %x", blb_flags), FLD(BLB, "Trans: %x", blb_transaction), - FLD(BLB, "Next: %x", blb_segment), 0}, irb[] = { + FLD(BLB, "Next: %x", blb_segment), + 0 +}, +irb[] = { "INDEX RETRIEVAL", FLD(IRB, "index: %d", irb_index), FLD(IRB, "relation: %x", irb_relation), FLD(IRB, "lower bounds: %d", irb_lower_count), - FLD(IRB, "upper boudns: %d", irb_upper_count), 0}, jrn[] = { -"JOURNAL", 0}, scl[] = { -"SECURITY CLASS", 0}, fld[] = { -"FIELD", 0}, ext[] = { -"EXTERNAL FILE", 0}, mfb[] = { -"MERGE EQUIVALENCE FILE BLOCK", 0}, riv[] = { -"SORT MERGE RIVER", 0}, plc[] = { -"PAGE/LOCK SERVER CONNECTION", 0}, usr[] = { -"USER IDENTIFICATION BLOCK ", 0}, att[] = { -"ATTACHMENT BLOCK", 0}, sym[] = { -"SYMBOL", 0}, fun[] = { -"FUNCTION", 0}, irl[] = { -"INDEXED RELATIONSHIP", 0}, acc[] = { -"ACCESS", 0}, rsc[] = { -"RESOURCE", 0}, idl[] = { -"INDEX LOCK", 0}, sdw[] = { -"SHADOW", 0}, sav[] = { -"SAVE POINT", 0}, vct[] = { -"VERB", 0}, btb[] = { -"BLOCKED THREAD", 0}, blf[] = { -"BLOB FILTER", 0}, arr[] = { -"ARRAY DESCRIPTION", 0}, map[] = { -"MAP BLOCK", 0}, log[] = { -"LOG BLOCK", 0}, dls[] = { -"DIR LIST BLOCK", 0}, prc[] = { -"PROCEDURE", FLD(PRC, "%s", prc_name), FLD(PRC, "Id: %d", prc_id), 0}, prm[] = { -"PARAMETER", FLD(PRM, "%s", prm_name), 0}, idb[] = { -"INDEX BLOCK", 0}, bkm[] = { -"BOOKMARK BLOCK", 0}, rng[] = { -"REFRESH RANGE BLOCK", 0}, tpc[] = { -"TIP CACHE BLOCK", 0}, xcp[] = { -"EXCEPTION LIST BLOCK", 0}, + FLD(IRB, "upper boudns: %d", irb_upper_count), + 0 +}, +ctl[] = { + "BLOB CONTROL", 0 +}; + +static TEXT_PTR jrn[] = { "JOURNAL", 0}; +static TEXT_PTR scl[] = { "SECURITY CLASS", 0}; +static TEXT_PTR fld[] = { "FIELD", 0}; +static TEXT_PTR ext[] = { "EXTERNAL FILE", 0}; +static TEXT_PTR mfb[] = { "MERGE EQUIVALENCE FILE BLOCK", 0}; +static TEXT_PTR riv[] = { "SORT MERGE RIVER", 0}; +static TEXT_PTR plc[] = { "PAGE/LOCK SERVER CONNECTION", 0}; +static TEXT_PTR usr[] = { "USER IDENTIFICATION BLOCK ", 0}; +static TEXT_PTR att[] = { "ATTACHMENT BLOCK", 0}; +static TEXT_PTR sym[] = { "SYMBOL", 0}; +static TEXT_PTR fun[] = { "FUNCTION", 0}; +static TEXT_PTR irl[] = { "INDEXED RELATIONSHIP", 0}; +static TEXT_PTR acc[] = { "ACCESS", 0}; +static TEXT_PTR Rsc[] = { "RESOURCE", 0}; +static TEXT_PTR idl[] = { "INDEX LOCK", 0}; +static TEXT_PTR sdw[] = { "SHADOW", 0}; +static TEXT_PTR sav[] = { "SAVE POINT", 0}; +static TEXT_PTR vct[] = { "VERB", 0}; +static TEXT_PTR btb[] = { "BLOCKED THREAD", 0}; +static TEXT_PTR blf[] = { "BLOB FILTER", 0}; +static TEXT_PTR arr[] = { "ARRAY DESCRIPTION", 0}; +static TEXT_PTR map[] = { "MAP BLOCK", 0}; +static TEXT_PTR log[] = { "LOG BLOCK", 0}; +static TEXT_PTR dls[] = { "DIR LIST BLOCK", 0}; +static TEXT_PTR prc[] = { + "PROCEDURE", + FLD(PRC, "%s", prc_name), + FLD(PRC, "Id: %d", prc_id), 0}; +static TEXT_PTR prm[] = { "PARAMETER", FLD(PRM, "%s", prm_name), 0}; +static TEXT_PTR idb[] = { "INDEX BLOCK", 0}; +static TEXT_PTR bkm[] = { "BOOKMARK BLOCK", 0}; +static TEXT_PTR rng[] = { "REFRESH RANGE BLOCK", 0}; +static TEXT_PTR tpc[] = { "TIP CACHE BLOCK", 0}; +static TEXT_PTR xcp[] = { "EXCEPTION LIST BLOCK", 0}; +static TEXT_PTR Opt[] = { "OPTIMIZATION BLOCK", 0}; +static TEXT_PTR prf[] = { "PRF", 0}; +static TEXT_PTR rse[] = { "RECORD SELECTION EXPRESSION", 0}; +static TEXT_PTR lit[] = { "LITERAL", 0}; +static TEXT_PTR asb[] = { "ASB", 0}; +static TEXT_PTR srl[] = { "SRL", 0}; /* xxx x [] = { @@ -266,43 +362,56 @@ static TEXT_PTR dbb_stuff[] = { FLD (x, "x: %x", x), 0}, */ - csb[] = { +static TEXT_PTR Csb[] = { "COMPILE SCRATCH BLOCK", FLD(CSB, "Count: %x", csb_count), FLD(CSB, "Node: %x", csb_node), FLD(CSB, "Streams: %x", csb_n_stream), FLD(CSB, "Running: %x", csb_running), - - FLD(CSB, "BLR: %x", csb_blr), 0}, texttype[] = { + FLD(CSB, "BLR: %x", csb_blr), + 0 +}; +static TEXT_PTR texttype[] = { "INTL TEXT OBJECT", FLD(TEXTTYPE, "Name: %s", texttype_name), FLD(TEXTTYPE, "Vers: %d", texttype_version), FLD(TEXTTYPE, "ID: %d", texttype_type), FLD(TEXTTYPE, "CS: %d", texttype_character_set), FLD(TEXTTYPE, "Cntry:%d", texttype_country), - FLD(TEXTTYPE, "Flags:%d", texttype_flags), 0}, charset[] = { - + FLD(TEXTTYPE, "Flags:%d", texttype_flags), + 0 +}; +static TEXT_PTR charset[] = { "INTL Character Set", FLD(CHARSET, "Name: %s", charset_name), FLD(CHARSET, "Vers: %d", charset_version), FLD(CHARSET, "ID: %d", charset_id), FLD(CHARSET, "B/Ch: %d", charset_max_bytes_per_char), FLD(CHARSET, "B/Ch: %d", charset_min_bytes_per_char), - FLD(CHARSET, "Flags:%d", charset_flags), 0}, csconvert[] = { + FLD(CHARSET, "Flags:%d", charset_flags), + 0 +}; +static TEXT_PTR csconvert[] = { "INTL Character set converter", FLD(CSCONVERT, "Name: %s", csconvert_name), FLD(CSCONVERT, "from: %d", csconvert_from), - FLD(CSCONVERT, "to: %d", csconvert_to), 0}, tdbb[] = { + FLD(CSCONVERT, "to: %d", csconvert_to), + 0 +}; +static TEXT_PTR tdbb[] = { "THREAD DATA BLOCK", FLD(TDBB, "Status vec: %x", tdbb_status_vector), - FLD(TDBB, "Default: %x", tdbb_default), 0}, logfiles[] = { -"WRITE AHEAD LOG FILE", 0}, svc[] = { -"SERVICE MANAGER BLOCK", 0}, lwt[] = { -"LATCH WAIT BLOCK", 0}, vcx[] = { -"VIEW CONTEXT BLOCK", 0}, srpb[] = { -"RPB BLOCK", 0}; + FLD(TDBB, "Default: %x", tdbb_default), + 0 +}; +static TEXT_PTR logfiles[] = { "WRITE AHEAD LOG FILE", 0}; +static TEXT_PTR svc[] = { "SERVICE MANAGER BLOCK", 0}; +static TEXT_PTR lwt[] = { "LATCH WAIT BLOCK", 0}; +static TEXT_PTR vcx[] = { "VIEW CONTEXT BLOCK", 0}; +static TEXT_PTR srpb[] = { "RPB BLOCK", 0}; + static int (*dbg_all) (), (*dbg_block) (), (*dbg_examine) (), (*dbg_eval) (), (*dbg_open) (), (*dbg_close) (), (*dbg_pool) (), (*dbg_pretty) (), @@ -349,10 +458,31 @@ struct symb dbt_symbols[] = { #define dbb dbb_stuff -TEXT *dbt_blocks[] = { 0, +TEXT* dbt_blocks[] = { 0, #include "../jrd/blk.h" 0 }; +#undef BLKDEF } // extern "C" + + +const char* DBT_jrd_type_map(int type) +{ +#define BLKDEF(enum_c, str_c, ext) case enum_c: return str_c[0]; + switch(type) + { + #include "../jrd/blk.h" + default: + break; + } +#undef BLKDEF + return "Uknown Jrd Obj"; +} + +void MP_GDB_print(MemoryPool *p) +{ + p->print_contents(stdout, DBT_jrd_type_map); +} + diff --git a/src/jrd/dfw.epp b/src/jrd/dfw.epp index 883a0e4dc2..2b99a63818 100644 --- a/src/jrd/dfw.epp +++ b/src/jrd/dfw.epp @@ -131,35 +131,35 @@ DATABASE DB = FILENAME "ODS.RDB"; ** **================================================================== */ -static BOOLEAN add_file(TDBB, SSHORT, DFW, TRA); -static BOOLEAN add_shadow(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_shadow(TDBB, SSHORT, DFW, TRA); -static BOOLEAN compute_security(TDBB, SSHORT, DFW, TRA); -static BOOLEAN create_index(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_index(TDBB, SSHORT, DFW, TRA); -static BOOLEAN create_log(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_log(TDBB, SSHORT, DFW, TRA); -static BOOLEAN create_procedure(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_procedure(TDBB, SSHORT, DFW, TRA); -static BOOLEAN modify_procedure(TDBB, SSHORT, DFW, TRA); -static BOOLEAN create_relation(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_relation(TDBB, SSHORT, DFW, TRA); -static BOOLEAN scan_relation(TDBB, SSHORT, DFW, TRA); -static BOOLEAN create_trigger(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_trigger(TDBB, SSHORT, DFW, TRA); -static BOOLEAN modify_trigger(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_exception(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_field(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_global(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_parameter(TDBB, SSHORT, DFW, TRA); -static BOOLEAN delete_rfr(TDBB, SSHORT, DFW, TRA); -static BOOLEAN make_version(TDBB, SSHORT, DFW, TRA); +static bool add_file(TDBB, SSHORT, DFW, TRA); +static bool add_shadow(TDBB, SSHORT, DFW, TRA); +static bool delete_shadow(TDBB, SSHORT, DFW, TRA); +static bool compute_security(TDBB, SSHORT, DFW, TRA); +static bool create_index(TDBB, SSHORT, DFW, TRA); +static bool delete_index(TDBB, SSHORT, DFW, TRA); +static bool create_log(TDBB, SSHORT, DFW, TRA); +static bool delete_log(TDBB, SSHORT, DFW, TRA); +static bool create_procedure(TDBB, SSHORT, DFW, TRA); +static bool delete_procedure(TDBB, SSHORT, DFW, TRA); +static bool modify_procedure(TDBB, SSHORT, DFW, TRA); +static bool create_relation(TDBB, SSHORT, DFW, TRA); +static bool delete_relation(TDBB, SSHORT, DFW, TRA); +static bool scan_relation(TDBB, SSHORT, DFW, TRA); +static bool create_trigger(TDBB, SSHORT, DFW, TRA); +static bool delete_trigger(TDBB, SSHORT, DFW, TRA); +static bool modify_trigger(TDBB, SSHORT, DFW, TRA); +static bool delete_exception(TDBB, SSHORT, DFW, TRA); +static bool delete_field(TDBB, SSHORT, DFW, TRA); +static bool delete_global(TDBB, SSHORT, DFW, TRA); +static bool delete_parameter(TDBB, SSHORT, DFW, TRA); +static bool delete_rfr(TDBB, SSHORT, DFW, TRA); +static bool make_version(TDBB, SSHORT, DFW, TRA); /* ---------------------------------------------------------------- */ static void check_dependencies(TDBB, TEXT*, TEXT*, USHORT, TRA); static void check_filename(TEXT*, USHORT); -static BOOLEAN find_depend_in_dfw(TDBB, TEXT*, USHORT, USHORT, TRA); +static bool find_depend_in_dfw(TDBB, TEXT*, USHORT, USHORT, TRA); static void get_array_desc(TDBB, TEXT*, ADS); static void get_procedure_dependencies(DFW); static void get_trigger_dependencies(DFW); @@ -167,8 +167,8 @@ static FMT make_format(TDBB, REL, USHORT, TFB); static USHORT name_length(TEXT *); static void put_summary_blob(BLB, enum rsr_t, SLONG[2]); static void put_summary_record(BLB, enum rsr_t, UCHAR *, USHORT); -static BOOLEAN shadow_defined(TDBB); -static BOOLEAN wal_defined(TDBB); +static bool shadow_defined(TDBB); +static bool wal_defined(TDBB); static CONST UCHAR nonnull_validation_blr[] = { @@ -182,40 +182,40 @@ static CONST UCHAR nonnull_validation_blr[] = typedef struct task { ENUM dfw_t task_type; - BOOLEAN(*task_routine) (TDBB, SSHORT, DFW, TRA); + bool (*task_routine) (TDBB, SSHORT, DFW, TRA); } TASK; static CONST TASK task_table[] = { - dfw_add_file, add_file, - dfw_add_shadow, add_shadow, - dfw_delete_index, delete_index, - dfw_delete_rfr, delete_rfr, - dfw_delete_relation, delete_relation, - dfw_delete_shadow, delete_shadow, - dfw_delete_field, delete_field, - dfw_delete_global, delete_global, - dfw_create_relation, create_relation, - dfw_update_format, make_version, - dfw_scan_relation, scan_relation, - dfw_compute_security, compute_security, - dfw_create_index, create_index, + { dfw_add_file, add_file }, + { dfw_add_shadow, add_shadow }, + { dfw_delete_index, delete_index }, + { dfw_delete_rfr, delete_rfr }, + { dfw_delete_relation, delete_relation }, + { dfw_delete_shadow, delete_shadow }, + { dfw_delete_field, delete_field }, + { dfw_delete_global, delete_global }, + { dfw_create_relation, create_relation }, + { dfw_update_format, make_version }, + { dfw_scan_relation, scan_relation }, + { dfw_compute_security, compute_security }, + { dfw_create_index, create_index }, #ifdef EXPRESSION_INDICES - dfw_create_expression_index, PCMET_expression_index, + { dfw_create_expression_index, PCMET_expression_index }, #endif - dfw_delete_expression_index, delete_index, - dfw_grant, (BOOLEAN(*)(TDBB, SSHORT, DFW, TRA))GRANT_privileges, - dfw_create_trigger, create_trigger, - dfw_delete_trigger, delete_trigger, - dfw_modify_trigger, modify_trigger, - dfw_create_log, create_log, - dfw_delete_log, delete_log, - dfw_create_procedure, create_procedure, - dfw_delete_procedure, delete_procedure, - dfw_modify_procedure, modify_procedure, - dfw_delete_prm, delete_parameter, - dfw_delete_exception, delete_exception, - dfw_null, NULL + { dfw_delete_expression_index, delete_index }, + { dfw_grant, (bool(*)(TDBB, SSHORT, DFW, TRA))GRANT_privileges }, + { dfw_create_trigger, create_trigger }, + { dfw_delete_trigger, delete_trigger }, + { dfw_modify_trigger, modify_trigger }, + { dfw_create_log, create_log }, + { dfw_delete_log, delete_log }, + { dfw_create_procedure, create_procedure }, + { dfw_delete_procedure, delete_procedure }, + { dfw_modify_procedure, modify_procedure }, + { dfw_delete_prm, delete_parameter }, + { dfw_delete_exception, delete_exception }, + { dfw_null, NULL } }; #ifdef SHLIB_DEFS @@ -229,13 +229,12 @@ static CONST TASK task_table[] = #define _iob (*_libgds__iob) #define ib_fprintf (*_libgds_fprintf) -extern int strlen(); -extern int strcmp(); -extern int SETJMP(); -extern int memcmp(); -extern int strncmp(); -extern SCHAR *strcpy(); -extern int unlink(); +extern int strlen(const char*); +extern int strcmp(const char*, const char*); +extern int memcmp(const void*, const void*, size_t); +extern int strncmp(const char*, char*, size_t); +extern char* strcpy(char* const char*); +extern int unlink(const char*); extern IB_FILE _iob[]; extern int ib_fprintf(); #endif @@ -258,7 +257,8 @@ USHORT DFW_assign_index_type(DFW work, SSHORT field_type, SSHORT ttype) tdbb = GET_THREAD_DATA; - if (field_type == dtype_varying || field_type == dtype_text) { + if (field_type == dtype_varying || field_type == dtype_text) + { STATUS status[20]; if (ttype == ttype_none) @@ -331,12 +331,12 @@ void DFW_delete_deferred( TRA transaction, SLONG sav_number) /* Remove deferred work and events which are to be rolled back */ - for (ptr = &transaction->tra_deferred_work; work = *ptr;) + for (ptr = &transaction->tra_deferred_work; (work = *ptr);) { if ((work->dfw_sav_number == sav_number) || (sav_number == -1)) { *ptr = work->dfw_next; - ALL_release((FRB)work); + delete work; } else { @@ -379,7 +379,7 @@ void DFW_merge_work(TRA transaction, * i.e. merge with the previous level. */ - for (ptr = &transaction->tra_deferred_work; work = *ptr;) + for (ptr = &transaction->tra_deferred_work; (work = *ptr);) { if (work->dfw_sav_number == old_sav_number) { @@ -413,18 +413,20 @@ void DFW_merge_work(TRA transaction, *ptr = work->dfw_next; - if (work_m->dfw_name_length) + if (work_m->dfw_name_length) { work_m->dfw_count += work->dfw_count; + } - ALL_release((FRB)work); + delete work; work = (DFW) 0; break; } } } - if (work) + if (work) { ptr = &(*ptr)->dfw_next; + } } } @@ -463,14 +465,11 @@ void DFW_perform_work(TRA transaction) * come. * **************************************/ + TDBB tdbb = GET_THREAD_DATA; - BOOLEAN dump_shadow = FALSE; + bool dump_shadow = false; SSHORT phase = 1; - JMP_BUF env; - JMP_BUF* old_env; - BOOLEAN more; DFW work; - DFW* ptr; /* If no deferred work or it's all deferred event posting don't bother */ @@ -491,53 +490,53 @@ void DFW_perform_work(TRA transaction) designated as the cleanup phase. If any non-zero phase punts, then phase 0 is executed for all deferred work blocks to cleanup work-in-progress. */ - old_env = (JMP_BUF*) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) - { - /* Do any necessary cleanup */ - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - phase = 0; - } + bool more; do { - const TASK* task; - more = FALSE; - for (task = task_table; task->task_type != dfw_null; task++) - { - for (work = transaction->tra_deferred_work; - work; - work = work->dfw_next) + more = false; + try { + const TASK* task; + for (task = task_table; task->task_type != dfw_null; ++task) { - if (work->dfw_type == task->task_type) + for (work = transaction->tra_deferred_work; + work; + work = work->dfw_next) { - if (work->dfw_type == dfw_add_shadow) + if (work->dfw_type == task->task_type) { - dump_shadow = TRUE; - } - if ((*task->task_routine)(tdbb, phase, work, transaction)) - { - more = TRUE; + if (work->dfw_type == dfw_add_shadow) + { + dump_shadow = true; + } + if ((*task->task_routine)(tdbb, phase, work, transaction)) + { + more = true; + } } } } + if (!phase) { + ERR_punt(); + } + ++phase; + } + catch (...) { + /* Do any necessary cleanup */ + if (!phase) { + ERR_punt(); + } + phase = 0; + more = true; } - if (!phase) { - ERR_punt(); - } - phase++; - } while (more); - tdbb->tdbb_setjmp = (UCHAR *) old_env; + } while (more); /* Remove deferred work blocks so that system transaction and commit retaining transactions don't re-execute them. Leave events to be posted after commit */ - for (ptr = &transaction->tra_deferred_work; work = *ptr;) + for (DFW* ptr = &transaction->tra_deferred_work; (work = *ptr);) { if ((work->dfw_type == dfw_post_event) || (work->dfw_type == dfw_delete_shadow)) @@ -547,7 +546,7 @@ void DFW_perform_work(TRA transaction) else { *ptr = work->dfw_next; - ALL_release((FRB)work); + delete work; } } @@ -590,7 +589,7 @@ void DFW_perform_post_commit_work(TRA transaction) lock = dbb->dbb_lock; #endif - for (ptr = &transaction->tra_deferred_work; work = *ptr;) + for (ptr = &transaction->tra_deferred_work; (work = *ptr);) if (work->dfw_type == dfw_post_event) { #ifndef WINDOWS_ONLY /* Events are not supported under LIBS */ @@ -602,13 +601,13 @@ void DFW_perform_post_commit_work(TRA transaction) work->dfw_count); #endif *ptr = work->dfw_next; - ALL_release((FRB)work); + delete work; } else if (work->dfw_type == dfw_delete_shadow) { unlink(work->dfw_name); *ptr = work->dfw_next; - ALL_release((FRB)work); + delete work; } else { @@ -673,7 +672,7 @@ void DFW_post_work( TRA transaction, ENUM dfw_t type, DSC * desc, USHORT id) /* Check to see if work is already posted */ - for (ptr = &transaction->tra_deferred_work; work = *ptr; + for (ptr = &transaction->tra_deferred_work; (work = *ptr); ptr = &(*ptr)->dfw_next) { if (work->dfw_type == type && @@ -692,7 +691,7 @@ void DFW_post_work( TRA transaction, ENUM dfw_t type, DSC * desc, USHORT id) /* Not already posted, so do so now. */ - *ptr = work = (DFW) ALLOCTV(type_dfw, length); + *ptr = work = new(*transaction->tra_pool, length) dfw; work->dfw_type = type; work->dfw_id = id; work->dfw_count = 1; @@ -745,7 +744,7 @@ void DFW_update_index( DFW work, USHORT id, float selectivity) } -static BOOLEAN add_file( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) +static bool add_file(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -773,16 +772,16 @@ static BOOLEAN add_file( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { case 0: CCH_release_exclusive(tdbb); - return FALSE; + return false; case 1: case 2: - return TRUE; + return true; case 3: if (CCH_exclusive(tdbb, LCK_EX, WAIT_PERIOD)) { - return TRUE; + return true; } else { @@ -791,7 +790,7 @@ static BOOLEAN add_file( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) gds_arg_gds, gds_obj_in_use, gds_arg_string, ERR_cstring(dbb->dbb_file->fil_string), 0); - return FALSE; + return false; } case 4: CCH_flush(tdbb, (USHORT) FLUSH_FINI, 0L); @@ -799,10 +798,11 @@ static BOOLEAN add_file( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) handle = handle2 = NULL; /* Check the file name for node name. This has already been done for - ** shadows in add_shadow () */ + ** shadows in add_shadow() */ - if (work->dfw_type != dfw_add_shadow) + if (work->dfw_type != dfw_add_shadow) { check_filename(work->dfw_name, work->dfw_name_length); + } /* get any files to extend into */ @@ -872,12 +872,12 @@ static BOOLEAN add_file( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) break; } - return FALSE; + return false; } -static BOOLEAN add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) +static bool add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -892,32 +892,34 @@ static BOOLEAN add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) * in sequence order. * **************************************/ - DBB dbb; + BLK handle; SDW shadow; USHORT sequence, add_sequence; - BOOLEAN finished; + bool finished; ULONG min_page; TEXT expanded_fname[1024]; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; switch (phase) { case 0: CCH_release_exclusive(tdbb); - return FALSE; + return false; case 1: case 2: case 3: - return TRUE; + return true; case 4: if (wal_defined(tdbb)) + { ERR_post(gds_no_meta_update, gds_arg_gds, gds_wal_shadow_err, 0); + } /* Msg309: Write-Ahead Log with Shadowing configuration not allowed */ check_filename(work->dfw_name, work->dfw_name_length); @@ -929,7 +931,7 @@ static BOOLEAN add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) fetched in totem and prepared for writing to, so just ignore it */ - finished = FALSE; + finished = false; handle = NULL; FOR(REQUEST_HANDLE handle) F IN RDB$FILES @@ -944,10 +946,12 @@ static BOOLEAN add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) !(shadow->sdw_flags & SDW_IGNORE)) { if (F.RDB$FILE_FLAGS & FILE_shadow) + { /* This is the case of a bogus duplicate posted * work when we added a multi-file shadow */ - finished = TRUE; + finished = true; + } else if (shadow->sdw_flags & (SDW_dumped)) { /* Case of adding a file to a currently active @@ -964,7 +968,7 @@ static BOOLEAN add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) ERR_cstring(dbb->dbb_file->fil_string), 0); add_file(tdbb, phase, work, (TRA) 0); - finished = TRUE; + finished = true; } else { @@ -983,8 +987,9 @@ static BOOLEAN add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) END_FOR; CMP_release(tdbb, (REQ)handle); - if (finished) - return FALSE; + if (finished) { + return false; + } /* this file is part of a new shadow, so get all files for the shadow in order of the starting page for the file */ @@ -1053,7 +1058,7 @@ static BOOLEAN add_shadow( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) break; } - return FALSE; + return false; } @@ -1210,10 +1215,10 @@ static void check_filename( TEXT * name, USHORT l) } -static BOOLEAN compute_security(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool compute_security( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -1237,7 +1242,7 @@ static BOOLEAN compute_security(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: /* Get security class. This may return NULL if it doesn't exist */ @@ -1255,7 +1260,7 @@ static BOOLEAN compute_security(TDBB tdbb, break; } - return FALSE; + return false; /**** OBSOLETE!!! Only security class name strings in relations and fields. Note: fld_security_class --> fld_security_name @@ -1285,10 +1290,10 @@ CMP_release (tdbb, handle); } -static BOOLEAN create_index(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool create_index( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -1300,7 +1305,7 @@ static BOOLEAN create_index(TDBB tdbb, * Create a new index or change the state of an index between active/inactive. * **************************************/ - DBB dbb; + BLK request; REL relation, partner_relation; IDX idx; @@ -1312,7 +1317,7 @@ static BOOLEAN create_index(TDBB tdbb, WIN window; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; switch (phase) { @@ -1353,11 +1358,11 @@ static BOOLEAN create_index(TDBB tdbb, CMP_release(tdbb, (REQ)handle); CCH_release_exclusive(tdbb); - return FALSE; + return false; case 1: case 2: - return TRUE; + return true; case 3: key_count = 0; @@ -1405,7 +1410,7 @@ static BOOLEAN create_index(TDBB tdbb, (USHORT)(IDX.RDB$INDEX_ID - 1)); END_MODIFY; EXE_unwind(tdbb, (REQ)request); - return FALSE; + return false; } if (IDX.RDB$INDEX_ID) { @@ -1419,7 +1424,7 @@ static BOOLEAN create_index(TDBB tdbb, if (IDX.RDB$INDEX_INACTIVE) { EXE_unwind(tdbb, (REQ)request); - return FALSE; + return false; } idx.idx_count = IDX.RDB$SEGMENT_COUNT; if (!idx.idx_count || idx.idx_count > 16) @@ -1578,11 +1583,11 @@ static BOOLEAN create_index(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN create_log( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) +static bool create_log(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -1605,15 +1610,15 @@ static BOOLEAN create_log( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { case 0: CCH_release_exclusive(tdbb); - return 0; + return false; case 1: case 2: - return TRUE; + return true; case 3: if (CCH_exclusive(tdbb, LCK_EX, WAIT_PERIOD)) - return TRUE; + return true; else { ERR_post(gds_no_meta_update, @@ -1621,15 +1626,17 @@ static BOOLEAN create_log( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) gds_arg_gds, gds_obj_in_use, gds_arg_string, ERR_cstring(dbb->dbb_file->fil_string), 0); - return FALSE; + return false; } case 4: handle = NULL; if (shadow_defined(tdbb)) + { ERR_post(gds_no_meta_update, gds_arg_gds, gds_wal_shadow_err, 0); + } /* Msg309: Write-Ahead Log with Shadowing configuration not allowed */ check_filename(work->dfw_name, work->dfw_name_length); @@ -1646,18 +1653,18 @@ static BOOLEAN create_log( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) transaction->tra_flags |= TRA_add_log; PAG_modify_log(transaction->tra_number, TRA_add_log); - return TRUE; + return true; case 5: CCH_release_exclusive(tdbb); break; } - return FALSE; + return false; } -static BOOLEAN create_procedure(TDBB tdbb, +static bool create_procedure( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) @@ -1672,7 +1679,6 @@ static BOOLEAN create_procedure(TDBB tdbb, * Create a new procedure. * **************************************/ - PRC procedure; SET_TDBB(tdbb); @@ -1680,24 +1686,28 @@ static BOOLEAN create_procedure(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: - get_procedure_dependencies(work); - if (!(procedure = MET_lookup_procedure(tdbb, work->dfw_name))) - return FALSE; - procedure->prc_flags |= PRC_create; + { + get_procedure_dependencies(work); + PRC procedure = MET_lookup_procedure(tdbb, work->dfw_name); + if (!procedure) { + return false; + } + procedure->prc_flags |= PRC_create; + } break; } - return FALSE; + return false; } -static BOOLEAN create_relation(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool create_relation(TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -1736,20 +1746,20 @@ static BOOLEAN create_relation(TDBB tdbb, if (work->dfw_lock) { LCK_release(tdbb, work->dfw_lock); - ALL_release((FRB)work->dfw_lock); + delete work->dfw_lock; work->dfw_lock = NULL; } break; case 1: case 2: - return TRUE; + return true; case 3: /* Take a relation lock on rel id -1 before actually generating a relation id. */ - work->dfw_lock = lock = (LCK) ALLOCDV(type_lck, sizeof(SLONG)); + work->dfw_lock = lock = new(*tdbb->tdbb_default, sizeof(SLONG)) lck; lock->lck_dbb = dbb; lock->lck_attachment = tdbb->tdbb_attachment; lock->lck_length = sizeof(SLONG); @@ -1789,7 +1799,7 @@ static BOOLEAN create_relation(TDBB tdbb, rel_id = X.RDB$RELATION_ID = local_min_relation_id; } - while (relation = MET_lookup_relation_id(tdbb, rel_id++, FALSE)) + while ( (relation = MET_lookup_relation_id(tdbb, rel_id++, FALSE)) ) { if (rel_id < local_min_relation_id || rel_id > MAX_RELATION_ID) @@ -1834,7 +1844,7 @@ static BOOLEAN create_relation(TDBB tdbb, END_FOR; LCK_release(tdbb, lock); - ALL_release((FRB)lock); + delete lock; work->dfw_lock = NULL; if (!REQUEST(irq_c_relation)) @@ -1862,14 +1872,11 @@ static BOOLEAN create_relation(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN create_trigger(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool create_trigger(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -1888,21 +1895,21 @@ static BOOLEAN create_trigger(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: get_trigger_dependencies(work); break; } - return FALSE; + return false; } -static BOOLEAN delete_exception(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_exception( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -1921,31 +1928,31 @@ static BOOLEAN delete_exception(TDBB tdbb, switch (phase) { case 0: - return FALSE; + return false; case 1: check_dependencies(tdbb, work->dfw_name, (TEXT*)NULL_PTR, obj_exception, transaction); - return TRUE; + return true; case 2: - return TRUE; + return true; case 3: - return TRUE; + return true; case 4: break; } - return FALSE; + return false; } -static BOOLEAN delete_field(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_field( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -1959,12 +1966,12 @@ static BOOLEAN delete_field(TDBB tdbb, * delete a global field that is in use * **************************************/ - DBB dbb; + int field_count; BLK handle; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; switch (phase) { @@ -2002,21 +2009,18 @@ static BOOLEAN delete_field(TDBB tdbb, 0); /* Msg310: there are %ld dependencies */ case 2: - return TRUE; + return true; case 3: MET_delete_dependencies(tdbb, work->dfw_name, obj_computed); break; } - return FALSE; + return false; } -static BOOLEAN delete_global(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_global(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -2043,7 +2047,7 @@ static BOOLEAN delete_global(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: handle = NULL; @@ -2059,14 +2063,11 @@ static BOOLEAN delete_global(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN delete_index(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_index(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -2087,29 +2088,37 @@ static BOOLEAN delete_index(TDBB tdbb, switch (phase) { case 0: - if (!(relation = MET_lookup_relation(tdbb, work->dfw_name))) - return FALSE; + relation = MET_lookup_relation(tdbb, work->dfw_name); + if (!relation) { + return false; + } id = work->dfw_id - 1; - if (index = CMP_get_index_lock(tdbb, relation, id)) - if (!index->idl_count) + index = CMP_get_index_lock(tdbb, relation, id); + if (index) { + if (!index->idl_count) { LCK_release(tdbb, index->idl_lock); - return FALSE; + } + } + return false; case 1: case 2: - return TRUE; + return true; case 3: /* Look up the relation. If we can't find the relation, don't worry about the index. */ - if (!(relation = MET_lookup_relation(tdbb, work->dfw_name))) - return FALSE; + relation = MET_lookup_relation(tdbb, work->dfw_name); + if (!relation) { + return false; + } /* Make sure nobody is currently using the index */ id = work->dfw_id - 1; - if (index = CMP_get_index_lock(tdbb, relation, id)) + index = CMP_get_index_lock(tdbb, relation, id); + if (index) { wait = (transaction->tra_flags & TRA_nowait) ? FALSE : TRUE; if (index->idl_count || @@ -2123,19 +2132,23 @@ static BOOLEAN delete_index(TDBB tdbb, index->idl_count++; } - return TRUE; + return true; case 4: - if (!(relation = MET_lookup_relation(tdbb, work->dfw_name))) - return FALSE; + relation = MET_lookup_relation(tdbb, work->dfw_name); + if (!relation) { + return false; + } id = work->dfw_id - 1; index = CMP_get_index_lock(tdbb, relation, id); IDX_delete_index(tdbb, relation, id); if (work->dfw_type == dfw_delete_expression_index) + { MET_delete_dependencies(tdbb, work->dfw_name, obj_expression_index); + } if (index) { @@ -2162,9 +2175,9 @@ static BOOLEAN delete_index(TDBB tdbb, if (index->idl_lock) { LCK_release(tdbb, index->idl_lock); - ALL_release((FRB)index->idl_lock); + delete index->idl_lock; } - ALL_release((FRB)index); + delete index; /* Release index refresh lock and memory. */ @@ -2180,8 +2193,8 @@ static BOOLEAN delete_index(TDBB tdbb, /* Lock was released in IDX_delete_index(). */ if (index_block->idb_lock) - ALL_release((FRB)index_block->idb_lock); - ALL_release((FRB)index_block); + delete index_block->idb_lock; + delete index_block; break; } } @@ -2190,11 +2203,11 @@ static BOOLEAN delete_index(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN delete_log(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) +static bool delete_log(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -2215,38 +2228,36 @@ static BOOLEAN delete_log(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { case 1: case 2: - return TRUE; + return true; case 3: - if (CCH_exclusive(tdbb, LCK_EX, WAIT_PERIOD)) - return TRUE; - else - { - ERR_post(gds_no_meta_update, - gds_arg_gds, gds_lock_timeout, - gds_arg_gds, gds_obj_in_use, - gds_arg_string, ERR_cstring(dbb->dbb_file->fil_string), - 0); - return FALSE; + if (CCH_exclusive(tdbb, LCK_EX, WAIT_PERIOD)) { + return true; } + ERR_post(gds_no_meta_update, + gds_arg_gds, gds_lock_timeout, + gds_arg_gds, gds_obj_in_use, + gds_arg_string, ERR_cstring(dbb->dbb_file->fil_string), + 0); + return false; case 4: transaction->tra_flags |= TRA_delete_log; PAG_modify_log(transaction->tra_number, TRA_delete_log); - return TRUE; + return true; case 5: CCH_release_exclusive(tdbb); break; } - return FALSE; + return false; } -static BOOLEAN delete_parameter(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_parameter( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -2267,24 +2278,26 @@ static BOOLEAN delete_parameter(TDBB tdbb, { case 1: if (MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, 0)) + { check_dependencies(tdbb, work->dfw_name, work->dfw_name, obj_procedure, transaction); + } case 2: - return TRUE; + return true; case 3: break; } - return FALSE; + return false; } -static BOOLEAN delete_procedure(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_procedure( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -2306,24 +2319,28 @@ static BOOLEAN delete_procedure(TDBB tdbb, switch (phase) { case 0: - if (!(procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, 0))) - return FALSE; + procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, 0); + if (!procedure) { + return false; + } wait = (transaction->tra_flags & TRA_nowait) ? FALSE : TRUE; LCK_convert_non_blocking( tdbb, procedure->prc_existence_lock, LCK_SR, wait); - return FALSE; + return false; case 1: check_dependencies(tdbb, work->dfw_name, (TEXT*)NULL_PTR, obj_procedure, transaction); - return TRUE; + return true; case 2: - if (!(procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, 0))) - return FALSE; + procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, 0); + if (!procedure) { + return false; + } wait = (transaction->tra_flags & TRA_nowait) ? FALSE : TRUE; if (!LCK_convert_non_blocking( tdbb, @@ -2341,23 +2358,25 @@ static BOOLEAN delete_procedure(TDBB tdbb, procedure obsolete. Unmark and we will remark it later. */ procedure->prc_flags &= ~PRC_obsolete; - return TRUE; + return true; case 3: - return TRUE; + return true; case 4: - if (!(procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, TRUE, 0))) - return FALSE; + procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, TRUE, 0); + if (!procedure) { + return false; + } if (procedure->prc_use_count) { MET_delete_dependencies(tdbb, work->dfw_name, obj_procedure); LCK_release(tdbb, procedure->prc_existence_lock); - tdbb->tdbb_database-> - dbb_procedures->vec_object[procedure->prc_id] = (BLK) NULL_PTR; - return FALSE; + (*tdbb->tdbb_database->dbb_procedures)[procedure->prc_id] = + (BLK) NULL_PTR; + return false; } old_flags = procedure->prc_flags; @@ -2385,14 +2404,11 @@ static BOOLEAN delete_procedure(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN delete_relation(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_relation(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -2405,20 +2421,22 @@ static BOOLEAN delete_relation(TDBB tdbb, * a relation, and if so, clean up after it. * **************************************/ - DBB dbb; + BLK request; REL relation; RSC rsc; USHORT wait, view_count, adjusted; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; switch (phase) { case 0: - if (!(relation = MET_lookup_relation_id(tdbb, work->dfw_id, FALSE))) - return FALSE; + relation = MET_lookup_relation_id(tdbb, work->dfw_id, FALSE); + if (!relation) { + return false; + } if (relation->rel_existence_lock) { @@ -2430,7 +2448,7 @@ static BOOLEAN delete_relation(TDBB tdbb, } relation->rel_flags &= ~REL_deleting; - return FALSE; + return false; case 1: /* check if any views use this as a base relation */ @@ -2443,12 +2461,15 @@ static BOOLEAN delete_relation(TDBB tdbb, /* If the view is also being deleted, there's no dependency */ if (!find_depend_in_dfw(tdbb, X.RDB$VIEW_NAME, obj_view, 0, transaction)) + { view_count++; + } END_FOR; CMP_release(tdbb, (REQ)request); if (view_count) + { ERR_post(gds_no_meta_update, gds_arg_gds, gds_no_delete, /* Msg353: can not delete */ gds_arg_gds, gds_table_name, @@ -2456,18 +2477,22 @@ static BOOLEAN delete_relation(TDBB tdbb, gds_arg_gds, gds_dependency, gds_arg_number, (SLONG) view_count, 0); /* Msg310: there are %ld dependencies */ + } check_dependencies(tdbb, work->dfw_name, (TEXT*)NULL_PTR, obj_relation, transaction); - return TRUE; + return true; case 2: - if (!(relation = MET_lookup_relation_id(tdbb, work->dfw_id, FALSE))) - return FALSE; + relation = MET_lookup_relation_id(tdbb, work->dfw_id, FALSE); + if (!relation) { + return false; + } /* Let relation be deleted if only this transaction is using it */ adjusted = FALSE; if (relation->rel_use_count == 1) + { for (rsc = transaction->tra_resources; rsc; rsc = rsc->rsc_next) { if (rsc->rsc_rel == relation) @@ -2477,6 +2502,7 @@ static BOOLEAN delete_relation(TDBB tdbb, break; } } + } wait = (transaction->tra_flags & TRA_nowait) ? FALSE : TRUE; if (relation->rel_use_count || @@ -2486,21 +2512,24 @@ static BOOLEAN delete_relation(TDBB tdbb, LCK_EX, wait))) { - if (adjusted) + if (adjusted) { ++relation->rel_use_count; + } ERR_post(gds_no_meta_update, gds_arg_gds, gds_obj_in_use, gds_arg_string, ERR_cstring(work->dfw_name), 0); } - return TRUE; + return true; case 3: - return TRUE; + return true; case 4: - if (!(relation = MET_lookup_relation_id(tdbb, work->dfw_id, TRUE))) - return FALSE; + relation = MET_lookup_relation_id(tdbb, work->dfw_id, TRUE); + if (!relation) { + return false; + } /* Flag relation delete in progress so that active sweep or garbage collector threads working on relation can skip over it. */ @@ -2514,20 +2543,23 @@ static BOOLEAN delete_relation(TDBB tdbb, count doesn't run down. */ for (wait = 0; wait < 60; wait++) - if (!relation->rel_sweep_count) + { + if (!relation->rel_sweep_count) { break; - else - { - THREAD_EXIT; - THREAD_SLEEP(1 * 1000); - THREAD_ENTER; } + THREAD_EXIT; + THREAD_SLEEP(1 * 1000); + THREAD_ENTER; + } + if (relation->rel_sweep_count) + { ERR_post(gds_no_meta_update, gds_arg_gds, gds_obj_in_use, gds_arg_string, ERR_cstring(work->dfw_name), 0); + } #ifdef GARBAGE_THREAD /* Free any memory associated with the relation's @@ -2536,29 +2568,34 @@ static BOOLEAN delete_relation(TDBB tdbb, if (relation->rel_gc_bitmap) { SBM_release(relation->rel_gc_bitmap); - relation->rel_gc_bitmap = NULL_PTR; + relation->rel_gc_bitmap = 0; } #endif - if (relation->rel_file) + if (relation->rel_file) { EXT_fini (relation); + } - if (relation->rel_index_root) + if (relation->rel_index_root) { IDX_delete_indices(tdbb, relation); + } - if (relation->rel_pages) + if (relation->rel_pages) { DPM_delete_relation(tdbb, relation); + } /* if this is a view (or even if we don't know), delete dependency lists */ - if (relation->rel_view_rse || !(relation->rel_flags & REL_scanned)) + if (relation->rel_view_rse || !(relation->rel_flags & REL_scanned)) { MET_delete_dependencies(tdbb, work->dfw_name, obj_view); + } /* Now that the data, pointer, and index pages are gone, get rid of formats as well */ - if (relation->rel_existence_lock) + if (relation->rel_existence_lock) { LCK_release(tdbb, relation->rel_existence_lock); + } request = NULL; FOR(REQUEST_HANDLE request) X IN RDB$FORMATS WITH @@ -2573,11 +2610,11 @@ static BOOLEAN delete_relation(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN delete_rfr( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) +static bool delete_rfr(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -2631,7 +2668,7 @@ static BOOLEAN delete_rfr( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) } *p = 0; field_count++; - } + } END_FOR; CMP_release(tdbb, (REQ)handle); @@ -2647,7 +2684,7 @@ static BOOLEAN delete_rfr( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) /* now check if there are any dependencies generated through the blr that defines the relation */ - if (relation = MET_lookup_relation_id(tdbb, work->dfw_id, FALSE)) + if ( (relation = MET_lookup_relation_id(tdbb, work->dfw_id, FALSE)) ) check_dependencies(tdbb, relation->rel_name, work->dfw_name, obj_relation, transaction); @@ -2690,7 +2727,7 @@ static BOOLEAN delete_rfr( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) } case 2: - return TRUE; + return true; case 3: /* Unlink field from data structures. Don't try to actually release field and @@ -2704,24 +2741,24 @@ static BOOLEAN delete_rfr( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { vector = relation->rel_fields; if (vector && - (ULONG)id < vector->vec_count && - vector->vec_object[id]) + (ULONG)id < vector->count() && + (*vector)[id]) { - vector->vec_object[id] = NULL; + (*vector)[id] = NULL; } } } break; } - return FALSE; + return false; } -static BOOLEAN delete_shadow(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_shadow( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -2741,21 +2778,21 @@ static BOOLEAN delete_shadow(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: MET_delete_shadow(tdbb, work->dfw_id); break; } - return FALSE; + return false; } -static BOOLEAN delete_trigger(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool delete_trigger( TDBB tdbb, + SSHORT phase, + DFW work, + TRA transaction) { /************************************** * @@ -2774,7 +2811,7 @@ static BOOLEAN delete_trigger(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: /* get rid of dependencies */ @@ -2783,15 +2820,15 @@ static BOOLEAN delete_trigger(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN find_depend_in_dfw(TDBB tdbb, - TEXT * object_name, - USHORT dep_type, - USHORT rel_id, - TRA transaction) +static bool find_depend_in_dfw( TDBB tdbb, + TEXT* object_name, + USHORT dep_type, + USHORT rel_id, + TRA transaction) { /************************************** * @@ -2805,17 +2842,18 @@ static BOOLEAN find_depend_in_dfw(TDBB tdbb, * Return FALSE if it is, TRUE otherwise. * **************************************/ - DBB dbb; + BLK request; TEXT *p; ENUM dfw_t dfw_type; DFW work; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; - for (p = object_name; *p && *p != ' '; p++) + for (p = object_name; *p && *p != ' '; p++) { ; + } *p = 0; switch (dep_type) @@ -2848,7 +2886,7 @@ static BOOLEAN find_depend_in_dfw(TDBB tdbb, !strcmp(object_name, work->dfw_name) && (!rel_id || rel_id == work->dfw_id)) { - return TRUE; + return true; } } @@ -2872,17 +2910,18 @@ static BOOLEAN find_depend_in_dfw(TDBB tdbb, REL.RDB$RELATION_ID, transaction)) { EXE_unwind(tdbb, (REQ)request); - return FALSE; + return false; } END_FOR; - if (!REQUEST(irq_ch_cmp_dpd)) + if (!REQUEST(irq_ch_cmp_dpd)) { REQUEST(irq_ch_cmp_dpd) = (BLK) request; + } - return TRUE; + return true; } - return FALSE; + return false; } @@ -2963,7 +3002,7 @@ static void get_procedure_dependencies(DFW work) GDS__QUAD blob_id; REQ request; BLK handle; - PLB old_pool; + JrdMemoryPool *old_pool; tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; @@ -2990,20 +3029,20 @@ static void get_procedure_dependencies(DFW work) if (procedure && !NULL_BLOB(blob_id)) { old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = ALL_pool(); + tdbb->tdbb_default = new(*dbb->dbb_permanent) JrdMemoryPool; MET_get_dependencies(tdbb, (struct rel*)NULL_PTR, (TEXT*)NULL_PTR, - (struct csb*)NULL_PTR, + (CSB)NULL_PTR, (SLONG*)&blob_id, &request, - (struct csb**)NULL_PTR, + (CSB*)NULL_PTR, work->dfw_name, obj_procedure); if (request) CMP_release(tdbb, request); else - ALL_rlpool(tdbb->tdbb_default); + delete tdbb->tdbb_default; tdbb->tdbb_default = old_pool; } @@ -3030,7 +3069,7 @@ static void get_trigger_dependencies( DFW work) GDS__QUAD blob_id; REQ request; BLK handle; - PLB old_pool; + JrdMemoryPool *old_pool; tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; @@ -3056,17 +3095,18 @@ static void get_trigger_dependencies( DFW work) if (relation && !NULL_BLOB(blob_id)) { + JrdMemoryPool tempPool; old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = ALL_pool(); + tdbb->tdbb_default = &tempPool; + MET_get_dependencies(tdbb, relation, (TEXT*)NULL_PTR, - (struct csb*)NULL_PTR, + (CSB)NULL_PTR, (SLONG*)&blob_id, &request, - (struct csb**)NULL_PTR, + (CSB*)NULL_PTR, work->dfw_name, obj_trigger); - ALL_rlpool(tdbb->tdbb_default); tdbb->tdbb_default = old_pool; } } @@ -3087,7 +3127,6 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) DBB dbb; BLK request; FMT format; - VEC vector; TFB tfb; BLB blob; USHORT count; @@ -3103,7 +3142,7 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) for (tfb = stack; tfb; tfb = tfb->tfb_next) count = MAX(count, tfb->tfb_id); - format = (FMT) ALLOCPV(type_fmt, count + 1); + format = fmt::newFmt(*dbb->dbb_permanent, count + 1); format->fmt_count = count + 1; format->fmt_version = version; @@ -3111,7 +3150,7 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) for (tfb = stack; tfb; tfb = tfb->tfb_next) { - desc = format->fmt_desc + tfb->tfb_id; + desc = &format->fmt_desc[tfb->tfb_id]; if (tfb->tfb_flags & TFB_array) { desc->dsc_dtype = dtype_array; @@ -3127,19 +3166,20 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) offset = FLAG_BYTES(count); - for (count = 0, desc = format->fmt_desc; + count = 0; + for (fmt::fmt_desc_iterator desc2 = format->fmt_desc.begin(); count < format->fmt_count; - count++, desc++) + count++, desc2++) { - if (desc->dsc_dtype & COMPUTED_FLAG) + if (desc2->dsc_dtype & COMPUTED_FLAG) { - desc->dsc_dtype &= ~COMPUTED_FLAG; + desc2->dsc_dtype &= ~COMPUTED_FLAG; continue; } - if (desc->dsc_dtype) + if (desc2->dsc_dtype) { old_offset = offset; - offset = MET_align(desc, (USHORT) offset); + offset = MET_align(desc2, (USHORT) offset); /* see of record too big */ @@ -3148,8 +3188,8 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) offset += 65536L; break; } - desc->dsc_address = (UCHAR *) (SLONG) offset; - offset += desc->dsc_length; + desc2->dsc_address = (UCHAR *) (SLONG) offset; + offset += desc2->dsc_length; } } @@ -3159,15 +3199,15 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) /* Release the temporary field blocks */ - while (tfb = stack) + while ( (tfb = stack) ) { stack = tfb->tfb_next; - ALL_release((FRB)tfb); + delete tfb; } if (offset > MAX_FORMAT_SIZE) { - ALL_release((FRB)format); + delete format; ERR_post(gds_no_meta_update, gds_arg_gds, gds_rec_size_err, gds_arg_number, (SLONG) offset, @@ -3179,8 +3219,14 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) /* Link the format block into the world */ - vector = ALL_vector(dbb->dbb_permanent, &relation->rel_formats, version); - vector->vec_object[version] = (BLK) format; + VEC vector = relation->rel_formats; + if (!vector) { + vector = vec::newVector(*dbb->dbb_permanent, version+1); + relation->rel_formats = vector; + } else { + vector->resize(version+1); + } + (*vector)[version] = (BLK) format; /* Store format in system relation */ @@ -3195,7 +3241,7 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) blob = BLB_create(tdbb, dbb->dbb_sys_trans, (BID)&FMT.RDB$DESCRIPTOR); BLB_put_segment(tdbb, blob, - (UCHAR*)format->fmt_desc, + (UCHAR*)format->fmt_desc.begin(), (USHORT)(format->fmt_count * sizeof(struct dsc))); BLB_close(tdbb, blob); END_STORE; @@ -3207,10 +3253,7 @@ static FMT make_format( TDBB tdbb, REL relation, USHORT version, TFB stack) } -static BOOLEAN make_version(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool make_version(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -3228,7 +3271,7 @@ static BOOLEAN make_version(TDBB tdbb, **************************************/ DBB dbb; BLK request_fmt1, request_fmtx; - TFB stack, external, tfb; + TFB stack, external, tfb_; REL relation; BLB blob; GDS__QUAD blob_id; @@ -3248,28 +3291,31 @@ static BOOLEAN make_version(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: relation = NULL; stack = external = NULL; computed_field = FALSE; - for (n = 0; n < TRIGGER_MAX; n++) + for (n = 0; n < TRIGGER_MAX; n++) { triggers[n] = (VEC) NULL_PTR; + } request_fmt1 = (BLK) CMP_find_request(tdbb, irq_format1, IRQ_REQUESTS); FOR(REQUEST_HANDLE request_fmt1) REL IN RDB$RELATIONS WITH REL.RDB$RELATION_NAME EQ work->dfw_name - if (!REQUEST(irq_format1)) + if (!REQUEST(irq_format1)) { REQUEST(irq_format1) = (BLK) request_fmt1; - if (!(relation = - MET_lookup_relation_id(tdbb, REL.RDB$RELATION_ID, FALSE))) + } + relation = + MET_lookup_relation_id(tdbb, REL.RDB$RELATION_ID, FALSE); + if (!relation) { EXE_unwind(tdbb, (REQ)request_fmt1); - return FALSE; + return false; } blob_id = REL.RDB$VIEW_BLR; null_view = NULL_BLOB(blob_id); @@ -3398,9 +3444,9 @@ static BOOLEAN make_version(TDBB tdbb, /* Make a temporary field block */ - tfb = (TFB) ALLOCD(type_tfb); - tfb->tfb_next = stack; - stack = tfb; + tfb_ = new(*tdbb->tdbb_default) tfb; + tfb_->tfb_next = stack; + stack = tfb_; /* for text data types, grab the CHARACTER_SET and COLLATION to give the type of international text */ @@ -3414,21 +3460,21 @@ static BOOLEAN make_version(TDBB tdbb, if (!RFR.RDB$COLLATION_ID.NULL) collation = RFR.RDB$COLLATION_ID; - DSC_make_descriptor(&tfb->tfb_desc, FLD.RDB$FIELD_TYPE, + DSC_make_descriptor(&tfb_->tfb_desc, FLD.RDB$FIELD_TYPE, FLD.RDB$FIELD_SCALE, FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, FLD.RDB$CHARACTER_SET_ID, collation); /* Make sure the text type specified is implemented */ - if ((IS_DTYPE_ANY_TEXT(tfb->tfb_desc.dsc_dtype) && + if ((IS_DTYPE_ANY_TEXT(tfb_->tfb_desc.dsc_dtype) && !INTL_defined_type(tdbb, status, - tfb->tfb_desc.dsc_ttype)) || - (tfb->tfb_desc.dsc_dtype == dtype_blob && - tfb->tfb_desc.dsc_sub_type == BLOB_text && + tfb_->tfb_desc.dsc_ttype)) || + (tfb_->tfb_desc.dsc_dtype == dtype_blob && + tfb_->tfb_desc.dsc_sub_type == BLOB_text && !INTL_defined_type(tdbb, status, - tfb->tfb_desc.dsc_scale))) + tfb_->tfb_desc.dsc_scale))) { EXE_unwind(tdbb, (REQ)request_fmt1); EXE_unwind(tdbb, (REQ)request_fmtx); @@ -3440,22 +3486,22 @@ static BOOLEAN make_version(TDBB tdbb, } if (!NULL_BLOB(FLD.RDB$COMPUTED_BLR)) - tfb->tfb_flags |= TFB_computed; - tfb->tfb_id = RFR.RDB$FIELD_ID; + tfb_->tfb_flags |= TFB_computed; + tfb_->tfb_id = RFR.RDB$FIELD_ID; - if (n = FLD.RDB$DIMENSIONS) + if ( (n = FLD.RDB$DIMENSIONS) ) { put_summary_record( blob, RSR_dimensions, (UCHAR*)&n, sizeof(n)); - tfb->tfb_flags |= TFB_array; + tfb_->tfb_flags |= TFB_array; array = (ADS) stuff; MOVE_CLEAR(array, (SLONG) sizeof(struct ads)); assert(n <= MAX_UCHAR); array->ads_dimensions = (UCHAR)n; array->ads_struct_count = 1; - array->ads_rpt[0].ads_desc = tfb->tfb_desc; + array->ads_rpt[0].ads_desc = tfb_->tfb_desc; get_array_desc(tdbb, FLD.RDB$FIELD_NAME, array); put_summary_record(blob, RSR_array_desc, @@ -3465,16 +3511,16 @@ static BOOLEAN make_version(TDBB tdbb, if (external_flag) { - tfb = (TFB) ALLOCD(type_tfb); - tfb->tfb_next = external; - external = tfb; + tfb_ = new(*tdbb->tdbb_default) tfb; + tfb_->tfb_next = external; + external = tfb_; assert(FLD.RDB$EXTERNAL_TYPE <= MAX_UCHAR); - tfb->tfb_desc.dsc_dtype = (UCHAR)FLD.RDB$EXTERNAL_TYPE; + tfb_->tfb_desc.dsc_dtype = (UCHAR)FLD.RDB$EXTERNAL_TYPE; assert(FLD.RDB$EXTERNAL_SCALE >= MIN_SCHAR && FLD.RDB$EXTERNAL_SCALE <= MAX_SCHAR); - tfb->tfb_desc.dsc_scale = (SCHAR)FLD.RDB$EXTERNAL_SCALE; - tfb->tfb_desc.dsc_length = FLD.RDB$EXTERNAL_LENGTH; - tfb->tfb_id = RFR.RDB$FIELD_ID; + tfb_->tfb_desc.dsc_scale = (SCHAR)FLD.RDB$EXTERNAL_SCALE; + tfb_->tfb_desc.dsc_length = FLD.RDB$EXTERNAL_LENGTH; + tfb_->tfb_id = RFR.RDB$FIELD_ID; } END_FOR; @@ -3613,8 +3659,9 @@ static BOOLEAN make_version(TDBB tdbb, /* If we didn't find the relation, it is probably being dropped */ - if (!relation) - return FALSE; + if (!relation) { + return false; + } if (!(relation->rel_flags & REL_sys_trigs_being_loaded)) { @@ -3677,11 +3724,11 @@ static BOOLEAN make_version(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN modify_procedure(TDBB tdbb, +static bool modify_procedure( TDBB tdbb, SSHORT phase, DFW work, TRA transaction) @@ -3710,56 +3757,55 @@ static BOOLEAN modify_procedure(TDBB tdbb, work->dfw_id, FALSE, 0); - if (!procedure) - return FALSE; + if (!procedure) { + return false; + } wait = (transaction->tra_flags & TRA_nowait) ? FALSE : TRUE; LCK_convert_non_blocking(tdbb, procedure->prc_existence_lock, LCK_SR, wait); - return FALSE; + return false; } case 1: - return TRUE; + return true; case 2: - return TRUE; + return true; case 3: - if (!(procedure = - MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, - 0))) return FALSE; + procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, 0); + if (!procedure) { + return false; + } wait = (transaction->tra_flags & TRA_nowait) ? FALSE : TRUE; /* Let relation be deleted if only this transaction is using it */ if (!LCK_convert_non_blocking(tdbb, procedure->prc_existence_lock, LCK_EX, wait)) + { ERR_post(gds_no_meta_update, gds_arg_gds, gds_obj_in_use, gds_arg_string, ERR_cstring(work->dfw_name), 0); + } /* If we are in a multi-client server, someone else may have marked procedure obsolete. Unmark and we will remark it later. */ procedure->prc_flags &= ~PRC_obsolete; - return TRUE; + return true; case 4: - if (!(procedure = - MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, - 0))) return FALSE; + procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, FALSE, 0); + if (!procedure) { + return false; + } + + try { old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { -#ifdef SUPERSERVER - THD_rec_mutex_unlock(&tdbb->tdbb_database->dbb_sp_rec_mutex); -#endif - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ERR_punt(); - } #ifdef SUPERSERVER if (!(tdbb->tdbb_database->dbb_flags & DBB_sp_rec_mutex_init)) @@ -3771,7 +3817,7 @@ static BOOLEAN modify_procedure(TDBB tdbb, if (THD_rec_mutex_lock(&tdbb->tdbb_database->dbb_sp_rec_mutex)) { THREAD_ENTER; - return FALSE; + return false; } THREAD_ENTER; #endif /* SUPERSERVER */ @@ -3788,8 +3834,8 @@ static BOOLEAN modify_procedure(TDBB tdbb, /* Msg357: too many versions */ } LCK_release(tdbb, procedure->prc_existence_lock); - tdbb->tdbb_database-> - dbb_procedures->vec_object[procedure->prc_id] = (BLK) NULL_PTR; + (*tdbb->tdbb_database->dbb_procedures) + [procedure->prc_id] = (BLK) NULL_PTR; if (!(procedure = MET_lookup_procedure_id(tdbb, work->dfw_id, @@ -3800,7 +3846,7 @@ static BOOLEAN modify_procedure(TDBB tdbb, THD_rec_mutex_unlock(&tdbb->tdbb_database->dbb_sp_rec_mutex); #endif tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } procedure->prc_alter_count = ++prc_alter_count; } @@ -3846,6 +3892,17 @@ static BOOLEAN modify_procedure(TDBB tdbb, procedure->prc_flags &= ~(PRC_obsolete | PRC_being_altered); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) + { +#ifdef SUPERSERVER + THD_rec_mutex_unlock(&tdbb->tdbb_database->dbb_sp_rec_mutex); +#endif + tdbb->tdbb_setjmp = (UCHAR *) old_env; + ERR_punt(); + } + #ifdef SUPERSERVER THD_rec_mutex_unlock(&tdbb->tdbb_database->dbb_sp_rec_mutex); #endif @@ -3853,14 +3910,11 @@ static BOOLEAN modify_procedure(TDBB tdbb, break; } - return FALSE; + return false; } -static BOOLEAN modify_trigger(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool modify_trigger(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -3879,7 +3933,7 @@ static BOOLEAN modify_trigger(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: /* get rid of old dependencies, bring in the new */ @@ -3889,11 +3943,11 @@ static BOOLEAN modify_trigger(TDBB tdbb, break; } - return FALSE; + return false; } -static USHORT name_length( TEXT * name) +static USHORT name_length(TEXT* name) { /************************************** * @@ -3906,21 +3960,19 @@ static USHORT name_length( TEXT * name) * Trailing blanks are ignored. * **************************************/ - TEXT *p, *q; -#define BLANK '\040' - q = name - 1; - for (p = name; *p; p++) - { - if (*p != BLANK) + TEXT* q = name - 1; + for (TEXT* p = name; *p; p++) { + if (*p != ' ') { q = p; + } } return ((q + 1) - name); } -static void put_summary_blob( BLB blob, RSR_T type, SLONG blob_id[2]) +static void put_summary_blob(BLB blob, RSR_T type, SLONG blob_id[2]) { /************************************** * @@ -3932,56 +3984,49 @@ static void put_summary_blob( BLB blob, RSR_T type, SLONG blob_id[2]) * Put an attribute record to the relation summary blob. * **************************************/ - TDBB tdbb; - DBB dbb; - BLB blr; - UCHAR *buffer, temp[128]; - USHORT length; - JMP_BUF env, *old_env; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + UCHAR temp[128]; -/* If blob is null, don't both */ + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; - if (!blob_id[0] && !blob_id[1]) + /* If blob is null, don't both */ + + if (!blob_id[0] && !blob_id[1]) { return; + } -/* Go ahead and open blob */ + // Go ahead and open blob - blr = BLB_open(tdbb, dbb->dbb_sys_trans, (BID)blob_id); + BLB blr = BLB_open(tdbb, dbb->dbb_sys_trans, (BID)blob_id); assert(blr->blb_length <= MAX_USHORT); - length = (USHORT)blr->blb_length; - buffer = (length > sizeof(temp)) ? - (UCHAR *) ALL_malloc((SLONG) blr->blb_length, ERR_jmp) : temp; + USHORT length = (USHORT)blr->blb_length; + UCHAR* buffer = (length > sizeof(temp)) ? + (UCHAR*) MemoryPool::malloc_from_system((SLONG) blr->blb_length) : temp; -/* Setup to cleanup after any error that may occur */ + // Setup to cleanup after any error that may occur - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) - { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (buffer != temp) - ALL_free((SCHAR*) buffer); + try { + length = (USHORT)BLB_get_data(tdbb, blr, buffer, (SLONG) length); + put_summary_record(blob, type, buffer, length); + } + catch (...) { + if (buffer != temp) { + MemoryPool::free_from_system(buffer); + } ERR_punt(); } - length = (USHORT)BLB_get_data(tdbb, blr, buffer, (SLONG) length); - put_summary_record(blob, type, buffer, length); - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - - if (buffer != temp) - ALL_free((SCHAR*) buffer); + if (buffer != temp) { + MemoryPool::free_from_system(buffer); + } } -static void put_summary_record(BLB blob, - RSR_T type, - UCHAR* data, - USHORT length) +static void put_summary_record(BLB blob, + RSR_T type, + UCHAR* data, + USHORT length) { /************************************** * @@ -3993,48 +4038,40 @@ static void put_summary_record(BLB blob, * Put an attribute record to the relation summary blob. * **************************************/ - TDBB tdbb; - UCHAR *p, *buffer, temp[129]; - JMP_BUF env, *old_env; - tdbb = GET_THREAD_DATA; + TDBB tdbb = GET_THREAD_DATA; + UCHAR temp[129]; - p = buffer = (length + 1 > sizeof(temp)) ? - (UCHAR *) ALL_malloc((SLONG) (length + 1), ERR_jmp) : temp; + UCHAR* buffer = (length + 1 > sizeof(temp)) ? + (UCHAR *) MemoryPool::malloc_from_system((SLONG) (length + 1)) : temp; + + UCHAR* p = buffer; *p++ = (UCHAR) type; - if (length) - do + if (length) { + do { *p++ = *data++; - while (--length); + } while (--length); + } -/* Setup to cleanup after any error that may occur */ - - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) - { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (buffer != temp) - ALL_free((SCHAR*) buffer); + try { + BLB_put_segment(tdbb, blob, buffer, (USHORT)(p - buffer)); + } + catch (...) { + if (buffer != temp) { + MemoryPool::free_from_system(buffer); + } ERR_punt(); } - BLB_put_segment(tdbb, blob, buffer, (USHORT)(p - buffer)); - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - - if (buffer != temp) - ALL_free((SCHAR*) buffer); + if (buffer != temp) { + MemoryPool::free_from_system(buffer); + } } -static BOOLEAN scan_relation(TDBB tdbb, - SSHORT phase, - DFW work, - TRA transaction) +static bool scan_relation(TDBB tdbb, SSHORT phase, DFW work, TRA transaction) { /************************************** * @@ -4054,18 +4091,18 @@ static BOOLEAN scan_relation(TDBB tdbb, { case 1: case 2: - return TRUE; + return true; case 3: MET_scan_relation(tdbb, MET_relation(tdbb, work->dfw_id)); break; } - return FALSE; + return false; } -static BOOLEAN shadow_defined(TDBB tdbb) +static bool shadow_defined(TDBB tdbb) { /************************************** * @@ -4078,19 +4115,16 @@ static BOOLEAN shadow_defined(TDBB tdbb) * for the database else return FALSE. * **************************************/ - DBB dbb; - BOOLEAN result; - BLK handle; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; - result = FALSE; - handle = NULL; + bool result = false; + BLK handle = NULL; FOR(REQUEST_HANDLE handle) FIRST 1 X IN RDB$FILES WITH X.RDB$SHADOW_NUMBER > 0 - result = TRUE; + result = true; END_FOR CMP_release(tdbb, (REQ)handle); @@ -4099,7 +4133,7 @@ static BOOLEAN shadow_defined(TDBB tdbb) } -static BOOLEAN wal_defined(TDBB tdbb) +static bool wal_defined(TDBB tdbb) { /************************************** * @@ -4112,18 +4146,15 @@ static BOOLEAN wal_defined(TDBB tdbb) * for the database else return FALSE. * **************************************/ - DBB dbb; - BOOLEAN result; - BLK handle; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; - result = FALSE; - handle = NULL; + bool result = false; + BLK handle = NULL; FOR(REQUEST_HANDLE handle) FIRST 1 X IN RDB$LOG_FILES - result = TRUE; + result = true; END_FOR CMP_release(tdbb, (REQ)handle); diff --git a/src/jrd/dpm.epp b/src/jrd/dpm.epp index 38627add3e..720b63bea9 100644 --- a/src/jrd/dpm.epp +++ b/src/jrd/dpm.epp @@ -110,7 +110,7 @@ PAG DPM_allocate(TDBB tdbb, WIN * window) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) - ib_printf("DPM_allocate (window page %d)\n", + ib_printf("DPM_allocate (window page %"SLONGFORMAT")\n", window ? window->win_page : 0); #endif @@ -148,10 +148,10 @@ void DPM_backout( TDBB tdbb, RPB * rpb) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("DPM_backout (rpb %d)\n", rpb->rpb_number); + ib_printf("DPM_backout (rpb %"SLONGFORMAT")\n", rpb->rpb_number); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -175,7 +175,7 @@ void DPM_backout( TDBB tdbb, RPB * rpb) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" old record %d:%d, new record %d:%d, old dpg_count %d, ", + (" old record %"SLONGFORMAT":%d, new record %"SLONGFORMAT":%d, old dpg_count %d, ", rpb->rpb_page, rpb->rpb_line, rpb->rpb_b_page, rpb->rpb_b_line, page->dpg_count); #endif @@ -223,7 +223,7 @@ int DPM_chain( TDBB tdbb, RPB * org_rpb, RPB * new_rpb) RHD header; RPB temp; DPG page; - struct dcc dcc; + Dcc dcc; UCHAR *p; SLONG length, fill; /* Accomodate max record size i.e. 64K */ USHORT size; @@ -236,17 +236,17 @@ int DPM_chain( TDBB tdbb, RPB * org_rpb, RPB * new_rpb) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("DPM_chain (org_rpb %d, new_rpb %d)\n", org_rpb->rpb_number, + ib_printf("DPM_chain (org_rpb %"SLONGFORMAT", new_rpb %"SLONGFORMAT")\n", org_rpb->rpb_number, new_rpb ? new_rpb->rpb_number : 0); if (debug_flag > DEBUG_WRITES_INFO) { ib_printf - (" org record %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" org record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", org_rpb->rpb_page, org_rpb->rpb_line, org_rpb->rpb_transaction, org_rpb->rpb_b_page, org_rpb->rpb_b_line, org_rpb->rpb_f_page, org_rpb->rpb_f_line, org_rpb->rpb_flags); if (new_rpb) - ib_printf(" new record length %d transaction %d flags %d\n", + ib_printf(" new record length %d transaction %"SLONGFORMAT" flags %d\n", new_rpb->rpb_length, new_rpb->rpb_transaction, new_rpb->rpb_flags); } @@ -425,7 +425,7 @@ int DPM_compress( TDBB tdbb, DPG page) UCHAR temp_page[MAX_PAGE_SIZE]; #endif dpg::dpg_repeat *index, *end; - JMP_BUF env, *old_env; + //JMP_BUF env, *old_env; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; @@ -434,7 +434,7 @@ int DPM_compress( TDBB tdbb, DPG page) if (debug_flag > DEBUG_TRACE_ALL) ib_printf("compress (page)\n"); if (debug_flag > DEBUG_TRACE_ALL_INFO) - ib_printf(" sequence %d\n", page->dpg_sequence); + ib_printf(" sequence %"SLONGFORMAT"\n", page->dpg_sequence); #endif #if (defined PC_PLATFORM && !defined NETWARE_386) @@ -442,30 +442,31 @@ int DPM_compress( TDBB tdbb, DPG page) and set up to release it in case of error */ temp_page = (UCHAR *) ALL_malloc((SLONG) dbb->dbb_page_size, ERR_jmp); - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (temp_page) - ALL_free(temp_page); - ERR_punt(); - } + + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; + #else - if (dbb->dbb_page_size > sizeof(temp_page)) + if (dbb->dbb_page_size > sizeof(temp_page)) { BUGCHECK(250); /* msg 250 temporary page buffer too small */ + } #endif space = dbb->dbb_page_size; end = page->dpg_rpt + page->dpg_count; for (index = page->dpg_rpt; index < end; index++) - if (index->dpg_offset) { + { + if (index->dpg_offset) + { l = index->dpg_length; space -= ROUNDUP(l, ODS_ALIGNMENT); MOVE_FAST((UCHAR *) page + index->dpg_offset, temp_page + space, l); index->dpg_offset = space; } + } MOVE_FASTER(temp_page + space, (UCHAR *) page + space, dbb->dbb_page_size - space); @@ -474,9 +475,19 @@ int DPM_compress( TDBB tdbb, DPG page) BUGCHECK(251); /* msg 251 damaged data page */ #if (defined PC_PLATFORM && !defined NETWARE_386) - if (temp_page) + if (temp_page) { ALL_free(temp_page); + } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (temp_page) { + ALL_free(temp_page); + } + ERR_punt(); + } #endif return space; @@ -540,9 +551,8 @@ void DPM_create_relation( TDBB tdbb, REL relation) /* Keep track in memory of the first pointer page */ - relation->rel_pages = vector = (VCL) ALLOCPV(type_vcl, 1); - vector->vcl_count = 1; - vector->vcl_long[0] = window.win_page; + relation->rel_pages = vector = vcl::newVector(*dbb->dbb_permanent, 1); + (*vector)[0] = window.win_page; /* Create an index root page */ @@ -612,7 +622,7 @@ SLONG DPM_data_pages(TDBB tdbb, REL relation) #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) - ib_printf(" returned pages: %d\n", pages); + ib_printf(" returned pages: %"SLONGFORMAT"\n", pages); #endif return pages; @@ -653,11 +663,11 @@ void DPM_delete( TDBB tdbb, RPB * rpb, SLONG prior_page) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("DPM_delete (rpb %d, prior_page %d)\n", rpb->rpb_number, + ib_printf("DPM_delete (rpb %"SLONGFORMAT", prior_page %"SLONGFORMAT")\n", rpb->rpb_number, prior_page); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -769,7 +779,7 @@ void DPM_delete( TDBB tdbb, RPB * rpb, SLONG prior_page) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - ("\tDPM_delete: page %d is empty and about to be released from relation %d\n", + ("\tDPM_delete: page %"SLONGFORMAT" is empty and about to be released from relation %d\n", window->win_page, rpb->rpb_relation->rel_id); #endif @@ -893,7 +903,7 @@ void DPM_delete_relation( TDBB tdbb, REL relation) } } - ALL_RELEASE(relation->rel_pages); + delete relation->rel_pages; relation->rel_pages = NULL; relation->rel_data_pages = 0; @@ -937,9 +947,9 @@ BOOLEAN DPM_fetch(TDBB tdbb, register RPB * rpb, USHORT lock) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) - ib_printf("DPM_fetch (rpb %d, lock %d)\n", rpb->rpb_number, lock); + ib_printf("DPM_fetch (rpb %"SLONGFORMAT", lock %d)\n", rpb->rpb_number, lock); if (debug_flag > DEBUG_READS_INFO) - ib_printf(" record %d:%d\n", rpb->rpb_page, rpb->rpb_line); + ib_printf(" record %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line); #endif number = rpb->rpb_number; @@ -954,7 +964,7 @@ BOOLEAN DPM_fetch(TDBB tdbb, register RPB * rpb, USHORT lock) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -999,12 +1009,12 @@ SSHORT DPM_fetch_back(TDBB tdbb, #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) { - ib_printf("DPM_fetch_back (rpb %d, lock %d)\n", rpb->rpb_number, + ib_printf("DPM_fetch_back (rpb %"SLONGFORMAT", lock %d)\n", rpb->rpb_number, lock); } if (debug_flag > DEBUG_READS_INFO) { - ib_printf(" record %d:%d transaction %d back %d:%d\n", + ib_printf(" record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line); } @@ -1034,7 +1044,7 @@ SSHORT DPM_fetch_back(TDBB tdbb, #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) { - ib_printf(" record fetched %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + ib_printf(" record fetched %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -1066,10 +1076,10 @@ void DPM_fetch_fragment( TDBB tdbb, register RPB * rpb, USHORT lock) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) - ib_printf("DPM_fetch_fragment (rpb %d, lock %d)\n", rpb->rpb_number, + ib_printf("DPM_fetch_fragment (rpb %"SLONGFORMAT", lock %d)\n", rpb->rpb_number, lock); if (debug_flag > DEBUG_READS_INFO) - ib_printf(" record %d:%d transaction %d back %d:%d\n", + ib_printf(" record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line); #endif @@ -1087,7 +1097,7 @@ void DPM_fetch_fragment( TDBB tdbb, register RPB * rpb, USHORT lock) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record fetched %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" record fetched %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -1125,7 +1135,7 @@ SINT64 DPM_gen_id(TDBB tdbb, SLONG generator, USHORT initialize, SINT64 val) #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) - ib_printf("DPM_gen_id (generator %d, val %" QUADFORMAT "d)\n", + ib_printf("DPM_gen_id (generator %"SLONGFORMAT", val %" QUADFORMAT "d)\n", generator, val); #endif @@ -1133,10 +1143,10 @@ SINT64 DPM_gen_id(TDBB tdbb, SLONG generator, USHORT initialize, SINT64 val) offset = generator % dbb->dbb_pcontrol->pgc_gpg; if (!(vector = dbb->dbb_gen_id_pages) || - (sequence >= vector->vcl_count) || !(vector->vcl_long[sequence])) { + (sequence >= vector->count()) || !((*vector)[sequence])) { DPM_scan_pages(tdbb); if (!(vector = dbb->dbb_gen_id_pages) || - (sequence >= vector->vcl_count) || !(vector->vcl_long[sequence])) { + (sequence >= vector->count()) || !((*vector)[sequence])) { page = (GPG) DPM_allocate(tdbb, &window); page->gpg_header.pag_type = pag_ids; page->gpg_sequence = sequence; @@ -1145,18 +1155,17 @@ SINT64 DPM_gen_id(TDBB tdbb, SLONG generator, USHORT initialize, SINT64 val) DPM_pages(tdbb, 0, pag_ids, (ULONG) sequence, window.win_page); if (!(vector = dbb->dbb_gen_id_pages)) { vector = dbb->dbb_gen_id_pages = - (VCL) ALLOCPV(type_vcl, sequence + 1); - vector->vcl_count = sequence + 1; + vcl::newVector(*dbb->dbb_permanent, sequence + 1); } - else if (sequence >= vector->vcl_count) + else if (sequence >= vector->count()) { - vector = (VCL)ALL_extend((BLK*)&dbb->dbb_gen_id_pages, sequence + 1); + vector->resize(sequence + 1); } - vector->vcl_long[sequence] = window.win_page; + (*vector)[sequence] = window.win_page; } } - window.win_page = vector->vcl_long[sequence]; + window.win_page = (*vector)[sequence]; window.win_flags = 0; if (dbb->dbb_flags & DBB_read_only) page = (GPG) CCH_FETCH(tdbb, &window, LCK_read, pag_ids); @@ -1254,7 +1263,7 @@ int DPM_get( TDBB tdbb, register RPB * rpb, SSHORT lock_type) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) - ib_printf("DPM_get (rpb %d, lock type %d)\n", rpb->rpb_number, + ib_printf("DPM_get (rpb %"SLONGFORMAT", lock type %d)\n", rpb->rpb_number, lock_type); #endif @@ -1283,7 +1292,7 @@ int DPM_get( TDBB tdbb, register RPB * rpb, SSHORT lock_type) ib_printf(" record %d:%d\n", page->ppg_page[slot], line); #endif - if (page_number = page->ppg_page[slot]) { + if ( (page_number = page->ppg_page[slot]) ) { CCH_HANDOFF(tdbb, window, page_number, lock_type, pag_data); if (get_header(window, line, rpb) && !(rpb->rpb_flags & (rpb_blob | rpb_chained | rpb_fragment))) @@ -1336,7 +1345,7 @@ ULONG DPM_get_blob(TDBB tdbb, #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) ib_printf - ("DPM_get_blob (blob, record_number %d, delete_flag %d, prior_page %d)\n", + ("DPM_get_blob (blob, record_number %d, delete_flag %d, prior_page %"SLONGFORMAT")\n", record_number, delete_flag, prior_page); #endif @@ -1429,10 +1438,10 @@ ULONG DPM_get_blob(TDBB tdbb, transaction = blob->blb_transaction; vector = blob->blb_pages = - (VCL) ALLOCTV(type_vcl, blob->blb_max_pages); + vcl::newVector(*transaction->tra_pool, blob->blb_max_pages); } - vector->vcl_count = length / sizeof(SLONG); - MOVE_FASTER(q, vector->vcl_long, length); + vector->resize(length / sizeof(SLONG)); + MOVE_FASTER(q, vector->memPtr(), length); } if (!delete_flag) { @@ -1485,7 +1494,7 @@ BOOLEAN DPM_next(TDBB tdbb, #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) - ib_printf("DPM_next (rpb %d)\n", rpb->rpb_number); + ib_printf("DPM_next (rpb %"SLONGFORMAT")\n", rpb->rpb_number); #endif window = &rpb->rpb_window; @@ -1516,7 +1525,7 @@ BOOLEAN DPM_next(TDBB tdbb, DPM_scan_pages(tdbb); if (!(vector = rpb->rpb_relation->rel_pages)) return FALSE; - pp_sequence = vector->vcl_count; + pp_sequence = vector->count(); rpb->rpb_number = (((SLONG) (pp_sequence * dbb->dbb_dp_per_pp) * dbb->dbb_max_records) - @@ -1548,7 +1557,7 @@ BOOLEAN DPM_next(TDBB tdbb, if (backwards && slot >= ppage->ppg_count) slot = ppage->ppg_count - 1; for (; slot >= 0 && slot < ppage->ppg_count;) { - if (page_number = ppage->ppg_page[slot]) { + if ( (page_number = ppage->ppg_page[slot]) ) { #ifdef SUPERSERVER_V2 /* Perform sequential prefetch of relation's data pages. This may need more work for scrollable cursors. */ @@ -1671,7 +1680,7 @@ void DPM_pages( #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) - ib_printf("DPM_pages (rel_id %d, type %d, sequence %d, page %d)\n", + ib_printf("DPM_pages (rel_id %d, type %d, sequence %d, page %"SLONGFORMAT")\n", rel_id, type, sequence, page); #endif @@ -1782,15 +1791,15 @@ void DPM_scan_pages( TDBB tdbb) relation = MET_relation(tdbb, 0); address = &relation->rel_pages; vector = *address; - sequence = vector->vcl_count - 1; - window.win_page = vector->vcl_long[sequence]; + sequence = vector->count() - 1; + window.win_page = (*vector)[sequence]; window.win_flags = 0; ppage = (PPG) CCH_FETCH(tdbb, &window, LCK_read, pag_pointer); while (ppage->ppg_next) { ++sequence; - vector = (VCL) ALL_extend((BLK*)address, sequence + 1); - vector->vcl_long[sequence] = ppage->ppg_next; + vector->resize(sequence + 1); + (*vector)[sequence] = ppage->ppg_next; ppage = (PPG) CCH_HANDOFF(tdbb, &window, ppage->ppg_next, LCK_read, pag_pointer); @@ -1828,12 +1837,11 @@ void DPM_scan_pages( TDBB tdbb) } n = sequence + 1; if (!(vector = *address)) { - vector = *address = (VCL) ALLOCPV(type_vcl, n); - vector->vcl_count = n; + vector = *address = vcl::newVector(*dbb->dbb_permanent, n); } - else if (sequence >= vector->vcl_count) - vector = (VCL) ALL_extend((BLK*)address, n); - vector->vcl_long[sequence] = X.RDB$PAGE_NUMBER; + else if (sequence >= vector->count()) + vector->resize(n); + (*vector)[sequence] = X.RDB$PAGE_NUMBER; END_FOR; if (!REQUEST(irq_r_pages)) @@ -1856,7 +1864,7 @@ void DPM_store( TDBB tdbb, register RPB * rpb, LLS * stack, USHORT type) **************************************/ DBB dbb; register RHD header; - struct dcc dcc; + Dcc dcc; UCHAR *p; SLONG fill, length; /* Accomodate max record size i.e. 64K */ USHORT size; @@ -1867,11 +1875,11 @@ void DPM_store( TDBB tdbb, register RPB * rpb, LLS * stack, USHORT type) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("DPM_store (rpb %d, stack, type %d)\n", rpb->rpb_number, + ib_printf("DPM_store (rpb %"SLONGFORMAT", stack, type %d)\n", rpb->rpb_number, type); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record to store %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" record to store %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -1906,7 +1914,7 @@ void DPM_store( TDBB tdbb, register RPB * rpb, LLS * stack, USHORT type) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d, length %d, rpb_flags %d, f_page %d:%d, b_page %d:%d\n", + (" record %"SLONGFORMAT":%d, length %"SLONGFORMAT", rpb_flags %d, f_page %"SLONGFORMAT":%d, b_page %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, length, rpb->rpb_flags, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_b_page, rpb->rpb_b_line); @@ -1942,7 +1950,7 @@ SLONG DPM_store_blob(TDBB tdbb, BLB blob, REC record) RPB rpb; BLH header; USHORT length; - SLONG *ptr, *end; + vcl::iterator ptr, end; UCHAR *p, *q; VCL vector; DPG page; @@ -1967,8 +1975,10 @@ SLONG DPM_store_blob(TDBB tdbb, BLB blob, REC record) } else { vector = blob->blb_pages; - length = vector->vcl_count * sizeof(SLONG); - q = (UCHAR *) vector->vcl_long; + length = vector->count() * sizeof(SLONG); + //q = (UCHAR *) vector->vcl_long; + // JMB: Not such a good thing with std::vector + q = (UCHAR *) vector->begin(); } /* Figure out precedence pages, if any */ @@ -1976,7 +1986,7 @@ SLONG DPM_store_blob(TDBB tdbb, BLB blob, REC record) stack = NULL; if (blob->blb_level > 0) - for (ptr = vector->vcl_long, end = ptr + vector->vcl_count; + for (ptr = vector->begin(), end = vector->end(); ptr < end;) LLS_PUSH((BLK) * ptr++, &stack); /* Locate space to store blob */ @@ -2047,9 +2057,9 @@ void DPM_rewrite_header( TDBB tdbb, RPB * rpb) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("DPM_rewrite_header (rpb %d)\n", rpb->rpb_number); + ib_printf("DPM_rewrite_header (rpb %"SLONGFORMAT")\n", rpb->rpb_number); if (debug_flag > DEBUG_WRITES_INFO) - ib_printf(" record %d:%d\n", rpb->rpb_page, rpb->rpb_line); + ib_printf(" record %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line); #endif window = &rpb->rpb_window; @@ -2059,11 +2069,11 @@ void DPM_rewrite_header( TDBB tdbb, RPB * rpb) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) { ib_printf - (" old flags %d, old transaction %d, old format %d, old back record %d:%d\n", + (" old flags %d, old transaction %"SLONGFORMAT", old format %d, old back record %"SLONGFORMAT":%d\n", header->rhd_flags, header->rhd_transaction, header->rhd_format, header->rhd_b_page, header->rhd_b_line); ib_printf - (" new flags %d, new transaction %d, new format %d, new back record %d:%d\n", + (" new flags %d, new transaction %"SLONGFORMAT", new format %d, new back record %"SLONGFORMAT":%d\n", rpb->rpb_flags, rpb->rpb_transaction, rpb->rpb_format_number, rpb->rpb_b_page, rpb->rpb_b_line); } @@ -2094,7 +2104,7 @@ void DPM_update( TDBB tdbb, register RPB * rpb, LLS * stack, TRA transaction) DBB dbb; RHD header; DPG page; - struct dcc dcc; + Dcc dcc; UCHAR *p; SLONG length, fill; /* Accomodate max record size i.e. 64K */ USHORT size; @@ -2107,11 +2117,11 @@ void DPM_update( TDBB tdbb, register RPB * rpb, LLS * stack, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("DPM_update (rpb %d, stack, transaction %d)\n", + ib_printf("DPM_update (rpb %"SLONGFORMAT", stack, transaction %d)\n", rpb->rpb_number, transaction ? transaction->tra_number : 0); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -2149,7 +2159,7 @@ void DPM_update( TDBB tdbb, register RPB * rpb, LLS * stack, TRA transaction) for (index = page->dpg_rpt, end = index + page->dpg_count; index < end; index++) - if (offset = index->dpg_offset) { + if ( (offset = index->dpg_offset) ) { available -= ROUNDUP(index->dpg_length, ODS_ALIGNMENT); space = MIN(space, offset); } @@ -2179,7 +2189,7 @@ void DPM_update( TDBB tdbb, register RPB * rpb, LLS * stack, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d, dpg_length %d, rpb_flags %d, rpb_f record %d:%d, rpb_b record %d:%d\n", + (" record %"SLONGFORMAT":%d, dpg_length %d, rpb_flags %d, rpb_f record %"SLONGFORMAT":%d, rpb_b record %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, page->dpg_rpt[slot].dpg_length, rpb->rpb_flags, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_b_page, rpb->rpb_b_line); @@ -2225,7 +2235,7 @@ static void delete_tail( TDBB tdbb, RHDF header, USHORT length) if (debug_flag > DEBUG_WRITES) ib_printf("delete_tail (header, length)\n"); if (debug_flag > DEBUG_WRITES_INFO) - ib_printf(" transaction %d flags %d fragment %d:%d back %d:%d\n", + ib_printf(" transaction %"SLONGFORMAT" flags %d fragment %"SLONGFORMAT":%d back %"SLONGFORMAT":%d\n", header->rhdf_transaction, header->rhdf_flags, header->rhdf_f_page, header->rhdf_f_line, header->rhdf_b_page, header->rhdf_b_line); @@ -2351,12 +2361,12 @@ static void fragment( #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) ib_printf - ("fragment (rpb %d, available_space %d, dcc, length %d, transaction %d)\n", + ("fragment (rpb %"SLONGFORMAT", available_space %d, dcc, length %d, transaction %d)\n", rpb->rpb_number, available_space, length, transaction ? transaction->tra_number : 0); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d transaction %d back %d:%d fragment %d:%d flags %d\n", + (" record %"SLONGFORMAT":%d transaction %"SLONGFORMAT" back %"SLONGFORMAT":%d fragment %"SLONGFORMAT":%d flags %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_flags); @@ -2405,7 +2415,7 @@ static void fragment( #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" rhdf_transaction %d, window record %d:%d, available_space %d, rhdf_flags %d, rhdf_f record %d:%d, rhdf_b record %d:%d\n", + (" rhdf_transaction %"SLONGFORMAT", window record %"SLONGFORMAT":%d, available_space %d, rhdf_flags %d, rhdf_f record %"SLONGFORMAT":%d, rhdf_b record %"SLONGFORMAT":%d\n", header->rhdf_transaction, window->win_page, line, available_space, header->rhdf_flags, header->rhdf_f_page, header->rhdf_f_line, header->rhdf_b_page, header->rhdf_b_line); @@ -2467,7 +2477,7 @@ static void fragment( if (debug_flag > DEBUG_WRITES_INFO) { ib_printf(" fragment head \n"); ib_printf - (" rhdf_trans %d, window record %d:%d, dpg_length %d\n\trhdf_flags %d, rhdf_f record %d:%d, rhdf_b record %d:%d\n", + (" rhdf_trans %"SLONGFORMAT", window record %"SLONGFORMAT":%d, dpg_length %d\n\trhdf_flags %d, rhdf_f record %"SLONGFORMAT":%d, rhdf_b record %"SLONGFORMAT":%d\n", header->rhdf_transaction, window->win_page, line, page->dpg_rpt[line].dpg_length, header->rhdf_flags, header->rhdf_f_page, header->rhdf_f_line, header->rhdf_b_page, @@ -2569,8 +2579,14 @@ static void extend_relation( TDBB tdbb, REL relation, WIN * window) CCH_must_write(&new_pp_window); CCH_RELEASE(tdbb, &new_pp_window); - vector = (VCL) ALL_extend((BLK*)&relation->rel_pages, pp_sequence + 1); - vector->vcl_long[pp_sequence] = new_pp_window.win_page; + vector = relation->rel_pages; + if (!vector) { + vector = vcl::newVector(*dbb->dbb_permanent, pp_sequence + 1); + relation->rel_pages = vector; + } else { + vector->resize(pp_sequence + 1); + } + (*vector)[pp_sequence] = new_pp_window.win_page; if (relation->rel_id) DPM_pages(tdbb, relation->rel_id, pag_pointer, (SLONG) pp_sequence, new_pp_window.win_page); @@ -2644,7 +2660,7 @@ static void extend_relation( TDBB tdbb, REL relation, WIN * window) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) - ib_printf(" extended_relation (relation %d, window_page %d)\n", + ib_printf(" extended_relation (relation %d, window_page %"SLONGFORMAT")\n", relation->rel_id, window->win_page); #endif } @@ -2828,26 +2844,26 @@ static PPG get_pointer_page( SET_TDBB(tdbb); - if (!(vector = relation->rel_pages) || sequence >= vector->vcl_count) { + if (!(vector = relation->rel_pages) || sequence >= vector->count()) { for (;;) { DPM_scan_pages(tdbb); /* If the relation is gone, then we can't do anything anymore. */ if ((!relation) || (!(vector = relation->rel_pages))) return NULL; - if (sequence < vector->vcl_count) + if (sequence < vector->count()) break; /* we are in business again */ - window->win_page = vector->vcl_long[vector->vcl_count - 1]; + window->win_page = (*vector)[vector->count() - 1]; page = (PPG) CCH_FETCH(tdbb, window, lock, pag_pointer); next_ppg = page->ppg_next; CCH_RELEASE(tdbb, window); if (!next_ppg) return NULL; - DPM_pages(tdbb, relation->rel_id, pag_pointer, vector->vcl_count, + DPM_pages(tdbb, relation->rel_id, pag_pointer, vector->count(), next_ppg); } } - window->win_page = vector->vcl_long[sequence]; + window->win_page = (*vector)[sequence]; page = (PPG) CCH_FETCH(tdbb, window, lock, pag_pointer); if (page->ppg_relation != relation->rel_id || @@ -2924,13 +2940,13 @@ static RHD locate_space( if (type == DPM_secondary) { DECOMPOSE_QUOTIENT(rpb->rpb_number, dbb->dbb_max_records, sequence); DECOMPOSE(sequence, dbb->dbb_dp_per_pp, pp_sequence, slot); - if (ppage = + if ( (ppage = get_pointer_page(tdbb, relation, window, pp_sequence, - LCK_read)) if (slot < ppage->ppg_count - && (dp_number = - ppage->ppg_page[slot])) { + LCK_read)) ) if (slot < ppage->ppg_count + && ( (dp_number = + ppage->ppg_page[slot])) ) { CCH_HANDOFF(tdbb, window, dp_number, LCK_write, pag_data); - if (space = find_space(tdbb, rpb, size, stack, record, type)) + if ( (space = find_space(tdbb, rpb, size, stack, record, type)) ) return (RHD) space; } else @@ -2950,7 +2966,7 @@ static RHD locate_space( if ((dp_number = ppage->ppg_page[slot]) && ~bits[slot >> 2] & (1 << ((slot & 3) << 1))) { CCH_HANDOFF(tdbb, window, dp_number, LCK_write, pag_data); - if (space = find_space(tdbb, rpb, size, stack, record, type)) + if ( (space = find_space(tdbb, rpb, size, stack, record, type)) ) return (RHD) space; window->win_page = pp_number; ppage = (PPG) CCH_FETCH(tdbb, window, LCK_read, pag_pointer); @@ -2969,7 +2985,7 @@ static RHD locate_space( for (i = 0; i < 20; i++) { DPM_allocate(tdbb, window); extend_relation(tdbb, relation, window); - if (space = find_space(tdbb, rpb, size, stack, record, type)) + if ( (space = find_space(tdbb, rpb, size, stack, record, type)) ) break; } if (i == 20) @@ -2980,8 +2996,8 @@ static RHD locate_space( #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) - ib_printf(" extended relation %d with page %d to get %d bytes\n", - relation->rel_id, window->win_page); + ib_printf(" extended relation %d with page %"SLONGFORMAT" to get %d bytes\n", + relation->rel_id, window->win_page, size); #endif return (RHD) space; @@ -3109,14 +3125,11 @@ static void release_dcc( DCC dcc) * **************************************/ DCC temp; - PLB pool; while (dcc) { temp = dcc; dcc = temp->dcc_next; - pool = temp->dcc_pool; - temp->dcc_next = pool->plb_dccs; - pool->plb_dccs = temp; + delete dcc; } } @@ -3232,7 +3245,7 @@ static void store_big_record( if (debug_flag > DEBUG_WRITES_INFO) { ib_printf(" back portion\n"); ib_printf - (" rpb_window page %d, max_data %d, \n\trhdf_flags %d, prior %d\n", + (" rpb_window page %"SLONGFORMAT", max_data %d, \n\trhdf_flags %d, prior %"SLONGFORMAT"\n", rpb->rpb_window.win_page, max_data, header->rhdf_flags, prior); } @@ -3278,7 +3291,7 @@ static void store_big_record( if (debug_flag > DEBUG_WRITES_INFO) { ib_printf(" front part\n"); ib_printf - (" rhdf_trans %d, rpb_window record %d:%d, dpg_length %d \n\trhdf_flags %d, rhdf_f record %d:%d, rhdf_b record %d:%d\n", + (" rhdf_trans %"SLONGFORMAT", rpb_window record %"SLONGFORMAT":%d, dpg_length %d \n\trhdf_flags %d, rhdf_f record %"SLONGFORMAT":%d, rhdf_b record %"SLONGFORMAT":%d\n", header->rhdf_transaction, rpb->rpb_window.win_page, rpb->rpb_line, page->dpg_rpt[rpb->rpb_line].dpg_length, header->rhdf_flags, header->rhdf_f_page, header->rhdf_f_line, diff --git a/src/jrd/dpm_proto.h b/src/jrd/dpm_proto.h index 5e1e72dea6..2ba7bffe1b 100644 --- a/src/jrd/dpm_proto.h +++ b/src/jrd/dpm_proto.h @@ -21,41 +21,44 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_DPM_PROTO_H_ -#define _JRD_DPM_PROTO_H_ +#ifndef JRD_DPM_PROTO_H +#define JRD_DPM_PROTO_H #ifdef __cplusplus extern "C" { #endif -extern struct pag *DPM_allocate(TDBB, struct win *); -extern void DPM_backout(TDBB, struct rpb *); -extern int DPM_chain(TDBB, struct rpb *, struct rpb *); -extern int DPM_compress(TDBB, struct dpg *); -extern void DPM_create_relation(TDBB, struct rel *); -extern SLONG DPM_data_pages(TDBB, struct rel *); -extern void DPM_delete(TDBB, struct rpb *, SLONG); -extern void DPM_delete_relation(TDBB, struct rel *); -extern BOOLEAN DPM_fetch(TDBB, register struct rpb *, USHORT); -extern SSHORT DPM_fetch_back(TDBB, register struct rpb *, USHORT, SSHORT); -extern void DPM_fetch_fragment(TDBB, register struct rpb *, USHORT); -extern SINT64 DPM_gen_id(TDBB, SLONG, USHORT, SINT64); -extern int DPM_get(TDBB, register struct rpb *, SSHORT); -extern ULONG DPM_get_blob(TDBB, struct blb *, ULONG, USHORT, SLONG); -extern BOOLEAN DPM_next(TDBB, register struct rpb *, USHORT, BOOLEAN, - BOOLEAN); -extern void DPM_pages(TDBB, SSHORT, int, ULONG, SLONG); -extern SLONG DPM_prefetch_bitmap(struct tdbb *, struct rel *, struct sbm *, +// fwd. decl. +class blb; + +struct pag* DPM_allocate(TDBB, struct win*); +void DPM_backout(TDBB, struct rpb *); +int DPM_chain(TDBB, struct rpb *, struct rpb *); +int DPM_compress(TDBB, struct dpg *); +void DPM_create_relation(TDBB, struct rel *); +SLONG DPM_data_pages(TDBB, struct rel *); +void DPM_delete(TDBB, struct rpb *, SLONG); +void DPM_delete_relation(TDBB, struct rel *); +BOOLEAN DPM_fetch(TDBB, register struct rpb *, USHORT); +SSHORT DPM_fetch_back(TDBB, register struct rpb *, USHORT, SSHORT); +void DPM_fetch_fragment(TDBB, register struct rpb *, USHORT); +SINT64 DPM_gen_id(TDBB, SLONG, USHORT, SINT64); +int DPM_get(TDBB, register struct rpb *, SSHORT); +ULONG DPM_get_blob(TDBB, blb*, ULONG, USHORT, SLONG); +BOOLEAN DPM_next(TDBB, register struct rpb *, USHORT, BOOLEAN, + BOOLEAN); +void DPM_pages(TDBB, SSHORT, int, ULONG, SLONG); +SLONG DPM_prefetch_bitmap(struct tdbb *, struct rel *, struct sbm *, SLONG); -extern void DPM_scan_pages(TDBB); -extern void DPM_store(TDBB, register struct rpb *, struct lls **, USHORT); -extern SLONG DPM_store_blob(TDBB, struct blb *, struct rec *); -extern void DPM_rewrite_header(TDBB, struct rpb *); -extern void DPM_update(TDBB, register struct rpb *, struct lls **, +void DPM_scan_pages(TDBB); +void DPM_store(TDBB, register struct rpb *, struct lls **, USHORT); +SLONG DPM_store_blob(TDBB, blb*, struct rec *); +void DPM_rewrite_header(TDBB, struct rpb *); +void DPM_update(TDBB, register struct rpb *, struct lls **, struct tra *); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* _JRD_DPM_PROTO_H_ */ +#endif /* JRD_DPM_PROTO_H */ diff --git a/src/jrd/drq.h b/src/jrd/drq.h index 9d3e38856f..88b0bcdb49 100644 --- a/src/jrd/drq.h +++ b/src/jrd/drq.h @@ -44,7 +44,7 @@ #ifndef _JRD_DRQ_H_ #define _JRD_DRQ_H_ -#define DYN_REQUEST(drt) dbb->dbb_dyn_req->vec_object[drt] +#define DYN_REQUEST(drt) (*dbb->dbb_dyn_req)[drt] #define drq_l_prot_mask 0 /* lookup protection mask */ #define drq_l_user_name 1 /* lookup user name */ diff --git a/src/jrd/dsc.h b/src/jrd/dsc.h index 6e9e9c5046..68b892b2ab 100644 --- a/src/jrd/dsc.h +++ b/src/jrd/dsc.h @@ -37,13 +37,23 @@ extern "C" { See MET_format() and make_format() in MET.E for enlightenment. */ -typedef struct dsc { - UCHAR dsc_dtype; - SCHAR dsc_scale; - USHORT dsc_length; - SSHORT dsc_sub_type; - USHORT dsc_flags; - UCHAR *dsc_address; +typedef struct dsc +{ + dsc() + : dsc_dtype(0), + dsc_scale(0), + dsc_length(0), + dsc_sub_type(0), + dsc_flags(0), + dsc_address(0) + {} + + UCHAR dsc_dtype; + SCHAR dsc_scale; + USHORT dsc_length; + SSHORT dsc_sub_type; + USHORT dsc_flags; + UCHAR* dsc_address; } DSC; /* values for dsc_flags */ diff --git a/src/jrd/dyn.epp b/src/jrd/dyn.epp index 40bd13a43a..ba2fff1fe9 100644 --- a/src/jrd/dyn.epp +++ b/src/jrd/dyn.epp @@ -59,6 +59,7 @@ #include "../jrd/isc_f_proto.h" #include "../jrd/thd_proto.h" #include "../jrd/vio_proto.h" +#include "../jrd/sch_proto.h" #ifdef SUPERSERVER #define V4_THREADING @@ -72,15 +73,14 @@ DATABASE DB = STATIC "yachts.gdb"; static void grant(GBL, UCHAR **); -static BOOLEAN grantor_can_grant_role(TDBB, GBL, TEXT *, TEXT *); -static BOOLEAN grantor_can_grant(GBL, TEXT *, TEXT *, TEXT *, TEXT *, - BOOLEAN); +static bool grantor_can_grant_role(TDBB, GBL, TEXT *, TEXT *); +static bool grantor_can_grant(GBL, TEXT *, TEXT *, TEXT *, TEXT *, bool); static void revoke(GBL, UCHAR **); static void store_privilege(GBL, TEXT *, TEXT *, TEXT *, TEXT *, SSHORT, SSHORT, int); -void DYN_ddl( ATT attachment, TRA transaction, USHORT length, UCHAR * ddl) +void DYN_ddl(ATT attachment, TRA transaction, USHORT length, UCHAR * ddl) { /************************************** * @@ -92,98 +92,83 @@ void DYN_ddl( ATT attachment, TRA transaction, USHORT length, UCHAR * ddl) * Do meta-data. * **************************************/ - TDBB tdbb; + + TDBB tdbb = GET_THREAD_DATA; + #ifdef V4_THREADING - DBB dbb; -#endif - STATUS *status; - UCHAR *ptr; - PLB old_pool; - struct gbl gbl; - JMP_BUF env, *old_env; -#ifdef _PPC_ - JMP_BUF env1; + DBB dbb = tdbb->tdbb_database; #endif - tdbb = GET_THREAD_DATA; -#ifdef V4_THREADING - dbb = tdbb->tdbb_database; -#endif + UCHAR* ptr = ddl; - ptr = ddl; - - if (*ptr++ != gds_dyn_version_1) + if (*ptr++ != gds_dyn_version_1) { ERR_post(gds_wrodynver, 0); + } - status = tdbb->tdbb_status_vector; + STATUS* status = tdbb->tdbb_status_vector; *status++ = gds_arg_gds; *status++ = 0; *status = gds_arg_end; + struct gbl gbl; gbl.gbl_transaction = transaction; -/* Create a pool for DYN to operate in. It will be released when - the routine exits. */ + // Create a pool for DYN to operate in. It will be released when + // the routine exits. + JrdMemoryPool* old_pool = tdbb->tdbb_default; + JrdMemoryPool tempPool; + tdbb->tdbb_default = &tempPool; - old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = ALL_pool(); + try { - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - if (transaction->tra_save_point && - transaction->tra_save_point->sav_verb_count) { - /* An error during undo is very bad and has to be dealt with - by aborting the transaction. The easiest way is to kill the - application by calling bugcheck. */ -#ifdef _PPC_ - tdbb->tdbb_setjmp = (UCHAR *) env1; - if (!SETJMP(env1)) +#if defined(SUPERSERVER) && defined(WIN_NT) + THREAD_EXIT; + THD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); + THREAD_ENTER; #else - if (!SETJMP(env)) + V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); #endif - VIO_verb_cleanup(tdbb, transaction); - else { - tdbb->tdbb_setjmp = (UCHAR *) old_env; /* prepare for BUGCHECK's longjmp */ - BUGCHECK(290); /* msg 290 error during savepoint backout */ - } - } -#if ( defined( SUPERSERVER) && defined( WIN_NT)) + VIO_start_save_point(tdbb, transaction); + transaction->tra_save_point->sav_verb_count++; + + DYN_execute(&gbl, &ptr, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); + transaction->tra_save_point->sav_verb_count--; + VIO_verb_cleanup(tdbb, transaction); + +#if defined(SUPERSERVER) && defined(WIN_NT) + THD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); +#else + V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); +#endif + + } + catch (...) { + const sav* savepoint = transaction->tra_save_point; + if (savepoint && savepoint) + { + // An error during undo is very bad and has to be dealt with + // by aborting the transaction. The easiest way is to kill + // the application by calling bugcheck. + + try { + VIO_verb_cleanup(tdbb, transaction); + } + catch (...) { + BUGCHECK(290); /* msg 290 error during savepoint backout */ + } + } + +#if defined(SUPERSERVER) && defined(WIN_NT) THD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); #else V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); #endif - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ALL_rlpool(tdbb->tdbb_default); tdbb->tdbb_default = old_pool; ERR_punt(); } -#if ( defined( SUPERSERVER) && defined( WIN_NT)) - THREAD_EXIT; - THD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); - THREAD_ENTER; -#else - V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); -#endif - - VIO_start_save_point(tdbb, transaction); - transaction->tra_save_point->sav_verb_count++; - - DYN_execute(&gbl, &ptr, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); - transaction->tra_save_point->sav_verb_count--; - VIO_verb_cleanup(tdbb, transaction); - -#if ( defined( SUPERSERVER) && defined( WIN_NT)) - THD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); -#else - V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_dyn); -#endif - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ALL_rlpool(tdbb->tdbb_default); tdbb->tdbb_default = old_pool; } @@ -205,8 +190,10 @@ void DYN_delete_role( GBL gbl, UCHAR ** ptr) TDBB tdbb; DBB dbb; BLK request; - VOLATILE USHORT id, err_num; - TEXT role_name[32], security_class[32], role_owner[32], user[32]; + VOLATILE USHORT id; + //VOLATILE USHORT err_num; + TEXT role_name[32], role_owner[32], user[32]; + //TEXT security_class[32]; TEXT *ptr1, *ptr2; JMP_BUF env, *old_env; BOOLEAN del_role_ok = TRUE; @@ -221,26 +208,20 @@ void DYN_delete_role( GBL gbl, UCHAR ** ptr) if (ENCODE_ODS(major_version, minor_original) < ODS_9_0) { DYN_error(FALSE, 196, NULL, NULL, NULL, NULL, NULL); ERR_punt(); + return; // never reached } - else - { - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - if (id == drq_drop_role) - DYN_error_punt(TRUE, 191, NULL, NULL, NULL, NULL, NULL); - /* msg 191: "ERASE RDB$ROLES failed" */ - else - DYN_error_punt(TRUE, 62, NULL, NULL, NULL, NULL, NULL); - /* msg 62: "ERASE RDB$USER_PRIVILEGES failed" */ - } + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; + + try { for (ptr1 = tdbb->tdbb_attachment->att_user->usr_user_name, ptr2 = user; *ptr1; ptr1++, ptr2++) + { *ptr2 = UPPER7(*ptr1); + } *ptr2 = '\0'; @@ -257,6 +238,8 @@ void DYN_delete_role( GBL gbl, UCHAR ** ptr) DYN_terminate(XX.RDB$OWNER_NAME, sizeof(XX.RDB$OWNER_NAME)); strcpy(role_owner, XX.RDB$OWNER_NAME); +#pragma FB_COMPILER_MESSAGE("TMN: LOCKSMITH!") + if ((tdbb->tdbb_attachment->att_user->usr_flags & USR_locksmith) || (strcmp(role_owner, user) == 0)) { @@ -269,10 +252,12 @@ void DYN_delete_role( GBL gbl, UCHAR ** ptr) END_FOR; - if (!DYN_REQUEST(drq_drop_role)) + if (!DYN_REQUEST(drq_drop_role)) { DYN_REQUEST(drq_drop_role) = request; + } - if (del_role_ok) { + if (del_role_ok) + { request = (BLK) CMP_find_request(tdbb, drq_del_role_1, DYN_REQUESTS); id = drq_del_role_1; @@ -287,15 +272,17 @@ void DYN_delete_role( GBL gbl, UCHAR ** ptr) OR(PRIV.RDB$USER EQ role_name AND PRIV.RDB$USER_TYPE = obj_sql_role) - if (!DYN_REQUEST(drq_del_role_1)) - DYN_REQUEST(drq_del_role_1) = request; + if (!DYN_REQUEST(drq_del_role_1)) { + DYN_REQUEST(drq_del_role_1) = request; + } ERASE PRIV; END_FOR; - if (!DYN_REQUEST(drq_del_role_1)) + if (!DYN_REQUEST(drq_del_role_1)) { DYN_REQUEST(drq_del_role_1) = request; + } } else @@ -307,11 +294,24 @@ void DYN_delete_role( GBL gbl, UCHAR ** ptr) *****************************************************/ DYN_error(FALSE, 191, user, role_name, NULL, NULL, NULL); tdbb->tdbb_setjmp = (UCHAR *) old_env; - ERR_punt(); + goto do_punt; } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + const USHORT number = (id == drq_drop_role ? 191 : 62); + // msg 191: "ERASE RDB$ROLES failed" + // msg 62: "ERASE RDB$USER_PRIVILEGES failed" + DYN_error_punt(TRUE, number, NULL, NULL, NULL, NULL, NULL); } + + return; + +do_punt: // ugly, rethink logic of this function + ERR_punt(); } @@ -767,7 +767,7 @@ USHORT DYN_get_string(TEXT ** ptr, TEXT * field, USHORT size, USHORT err_flag) p = *ptr; length = (UCHAR) * p++; length |= ((USHORT) ((UCHAR) (*p++))) << 8; - if (l = length) { + if ( (l = length) ) { if (length >= size) { if (err_flag) DYN_error_punt(FALSE, 159, NULL, NULL, NULL, NULL, NULL); @@ -870,21 +870,22 @@ USHORT DYN_put_blr_blob(GBL gbl, UCHAR** ptr, GDS__QUAD* blob_id) return length; } - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { + blob = BLB_create(tdbb, gbl->gbl_transaction, (BID)blob_id); + BLB_put_segment(tdbb, blob, p, length); + BLB_close(tdbb, blob); + + tdbb->tdbb_setjmp = (UCHAR*) old_env; + } + catch (...) { tdbb->tdbb_setjmp = (UCHAR *) old_env; DYN_error_punt(TRUE, 106, NULL, NULL, NULL, NULL, NULL); /* msg 106: "Create metadata blob failed" */ } - blob = BLB_create(tdbb, gbl->gbl_transaction, (BID)blob_id); - BLB_put_segment(tdbb, blob, p, length); - BLB_close(tdbb, blob); - - tdbb->tdbb_setjmp = (UCHAR*) old_env; - *ptr = p + length; return length; @@ -941,23 +942,26 @@ USHORT DYN_put_blr_blob2(GBL gbl, UCHAR ** ptr, GDS__QUAD * blob_id) *p2++ = from_interp >> 8; bpb_length = p2 - bpb; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { + blob =(BLK)BLB_create2( tdbb, + gbl->gbl_transaction, + blob_id, + bpb_length, + bpb); + BLB_put_segment(tdbb, blob, p, length); + BLB_close(tdbb, blob); + + tdbb->tdbb_setjmp = (UCHAR*) old_env; + } + catch (...) { tdbb->tdbb_setjmp = (UCHAR *) old_env; DYN_error_punt(TRUE, 106, NULL, NULL, NULL, NULL, NULL); /* msg 106: "Create metadata blob failed" */ } - blob = - (BLK) BLB_create2(tdbb, gbl->gbl_transaction, blob_id, bpb_length, - bpb); - BLB_put_segment(tdbb, blob, p, length); - BLB_close(tdbb, blob); - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - *ptr = p + length; return length; @@ -994,26 +998,27 @@ USHORT DYN_put_text_blob(GBL gbl, UCHAR ** ptr, GDS__QUAD * blob_id) return length; } - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { + blob = BLB_create(tdbb, gbl->gbl_transaction, (BID)blob_id); + + for (end = p + length; p < end; p += TEXT_BLOB_LENGTH) + { + length = (p + TEXT_BLOB_LENGTH <= end) ? TEXT_BLOB_LENGTH : end - p; + BLB_put_segment(tdbb, blob, p, length); + } + BLB_close(tdbb, blob); + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { tdbb->tdbb_setjmp = (UCHAR *) old_env; DYN_error_punt(TRUE, 106, NULL, NULL, NULL, NULL, NULL); /* msg 106: "Create metadata blob failed" */ } - blob = BLB_create(tdbb, gbl->gbl_transaction, (BID)blob_id); - - for (end = p + length; p < end; p += TEXT_BLOB_LENGTH) - { - length = (p + TEXT_BLOB_LENGTH <= end) ? TEXT_BLOB_LENGTH : end - p; - BLB_put_segment(tdbb, blob, p, length); - } - BLB_close(tdbb, blob); - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - *ptr = end; return length; @@ -1066,27 +1071,31 @@ USHORT DYN_put_text_blob2(GBL gbl, UCHAR ** ptr, GDS__QUAD * blob_id) *p2++ = from_interp >> 8; bpb_length = p2 - bpb; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { + blob = (BLK)BLB_create2(tdbb, + gbl->gbl_transaction, + blob_id, + bpb_length, + bpb); + + for (end = p + length; p < end; p += TEXT_BLOB_LENGTH) + { + length = (p + TEXT_BLOB_LENGTH <= end) ? TEXT_BLOB_LENGTH : end - p; + BLB_put_segment(tdbb, blob, p, length); + } + BLB_close(tdbb, blob); + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { tdbb->tdbb_setjmp = (UCHAR *) old_env; DYN_error_punt(TRUE, 106, NULL, NULL, NULL, NULL, NULL); /* msg 106: "Create metadata blob failed" */ } - blob = - (BLK) BLB_create2(tdbb, gbl->gbl_transaction, blob_id, bpb_length, - bpb); - - for (end = p + length; p < end; p += TEXT_BLOB_LENGTH) { - length = (p + TEXT_BLOB_LENGTH <= end) ? TEXT_BLOB_LENGTH : end - p; - BLB_put_segment(tdbb, blob, p, length); - } - BLB_close(tdbb, blob); - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - *ptr = end; return length; @@ -1094,7 +1103,7 @@ USHORT DYN_put_text_blob2(GBL gbl, UCHAR ** ptr, GDS__QUAD * blob_id) #endif /* (defined JPN_SJIS || defined JPN_EUC) */ -void DYN_rundown_request( JMP_BUF * old_env, BLK handle, SSHORT id) +void DYN_rundown_request(JMP_BUF* old_env, BLK handle, SSHORT id) { /************************************** * @@ -1107,21 +1116,24 @@ void DYN_rundown_request( JMP_BUF * old_env, BLK handle, SSHORT id) * in the dyn internal request list. * **************************************/ - TDBB tdbb; - DBB dbb; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; - if (old_env) +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! We do not have a jmp_buf anymore!") + + if (old_env) { tdbb->tdbb_setjmp = (UCHAR *) old_env; + } - if (!handle) + if (!handle) { return; + } EXE_unwind(tdbb, (REQ)handle); - if (id >= 0 && !DYN_REQUEST(id)) + if (id >= 0 && !DYN_REQUEST(id)) { DYN_REQUEST(id) = handle; + } } @@ -1220,34 +1232,40 @@ static void grant( GBL gbl, UCHAR ** ptr) * Execute SQL grant operation. * **************************************/ - TDBB tdbb; - DBB dbb; + BLK request; - SSHORT user_type, obj_type; - VOLATILE SSHORT id, err_num; - int options, duplicate; - UCHAR verb; - TEXT privileges[16], object[32], field[32], user[32], *p, priv[2]; - JMP_BUF env, *old_env; - BOOLEAN grant_role_stmt = FALSE; - TEXT dummy_name[32], grantor[32], *ptr1, *ptr2; - USHORT major_version, minor_original; + //VOLATILE SSHORT err_num; + VOLATILE SSHORT id; + TEXT privileges[16]; + TEXT object[32]; + TEXT field[32]; + TEXT user[32]; + TEXT priv[2]; + bool grant_role_stmt = false; + TEXT grantor[32]; + TEXT* p; + TEXT* ptr1; + TEXT* ptr2; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; - major_version = (SSHORT) dbb->dbb_ods_version; - minor_original = (SSHORT) dbb->dbb_minor_original; + USHORT major_version = (SSHORT) dbb->dbb_ods_version; + USHORT minor_original = (SSHORT) dbb->dbb_minor_original; GET_STRING(ptr, privileges); - if (!strcmp(privileges, "A")) + if (!strcmp(privileges, "A")) { strcpy(privileges, ALL_PRIVILEGES); + } object[0] = field[0] = user[0] = 0; - options = 0; - obj_type = user_type = -1; + int options = 0; + SSHORT user_type = -1; + SSHORT obj_type = -1; + UCHAR verb; while ((verb = *(*ptr)++) != gds_dyn_end) + { switch (verb) { case gds_dyn_rel_name: obj_type = obj_relation; @@ -1269,14 +1287,17 @@ static void grant( GBL gbl, UCHAR ** ptr) break; case gds_dyn_grant_user: - GET_STRING(ptr, user); - if (DYN_is_it_sql_role(gbl, user, dummy_name, tdbb)) { - user_type = obj_sql_role; - } - else { - user_type = obj_user; - for (ptr1 = user; *ptr1; ptr1++) { - *ptr1 = UPPER7(*ptr1); + { + GET_STRING(ptr, user); + TEXT dummy_name[32]; + if (DYN_is_it_sql_role(gbl, user, dummy_name, tdbb)) { + user_type = obj_sql_role; + } + else { + user_type = obj_user; + for (ptr1 = user; *ptr1; ptr1++) { + *ptr1 = UPPER7(*ptr1); + } } } break; @@ -1289,7 +1310,7 @@ static void grant( GBL gbl, UCHAR ** ptr) else { obj_type = obj_sql_role; GET_STRING(ptr, object); - grant_role_stmt = TRUE; + grant_role_stmt = true; } break; @@ -1316,43 +1337,17 @@ static void grant( GBL gbl, UCHAR ** ptr) default: DYN_unsupported_verb(); } - - - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) { - /* we need to rundown as we have to set the env. - But in case the error is from store_priveledge we have already - unwound the request so passing that as null */ - DYN_rundown_request(old_env, - ((id == drq_s_grant || id == drq_gcg1) ? NULL : - request), -1); - if (id == drq_l_grant1) - DYN_error_punt(TRUE, 77, NULL, NULL, NULL, NULL, NULL); - /* msg 77: "SELECT RDB$USER_PRIVILEGES failed in grant" */ - else if (id == drq_l_grant2) - DYN_error_punt(TRUE, 78, NULL, NULL, NULL, NULL, NULL); - /* msg 78: "SELECT RDB$USER_PRIVILEGES failed in grant" */ - else if (id == drq_s_grant || id == drq_gcg1) - ERR_punt(); - /* store_priviledge || grantor_can_grant error already handled, - just bail out */ - else if (id == drq_get_role_nm) - ERR_punt(); - else { - assert(id == drq_gcg1); - DYN_error_punt(TRUE, 78, NULL, NULL, NULL, NULL, NULL); - /* msg 78: "SELECT RDB$USER_PRIVILEGES failed in grant" */ - } } + + try { + request = (BLK)CMP_find_request(tdbb, (USHORT)(field[0] ? drq_l_grant1 : drq_l_grant2), DYN_REQUESTS); for (p = privileges; *p; p++) { - duplicate = FALSE; + bool duplicate = false; priv[0] = *p; priv[1] = 0; if (field[0]) @@ -1367,14 +1362,20 @@ static void grant( GBL gbl, UCHAR ** ptr) PRIV.RDB$USER_TYPE = user_type AND PRIV.RDB$GRANTOR EQ UPPERCASE(RDB$USER_NAME) AND PRIV.RDB$FIELD_NAME EQ field - if (!DYN_REQUEST(drq_l_grant1)) + if (!DYN_REQUEST(drq_l_grant1)) { DYN_REQUEST(drq_l_grant1) = request; + } if ((PRIV.RDB$GRANT_OPTION.NULL) || (PRIV.RDB$GRANT_OPTION) || - (PRIV.RDB$GRANT_OPTION == options)) duplicate = TRUE; + (PRIV.RDB$GRANT_OPTION == options)) + { + duplicate = true; + } else + { ERASE PRIV; /* has to be 0 and options == 1 */ + } END_FOR; if (!DYN_REQUEST(drq_l_grant1)) { @@ -1400,7 +1401,7 @@ static void grant( GBL gbl, UCHAR ** ptr) (PRIV.RDB$GRANT_OPTION) || (PRIV.RDB$GRANT_OPTION == options)) { - duplicate = TRUE; + duplicate = true; } else { @@ -1413,14 +1414,17 @@ static void grant( GBL gbl, UCHAR ** ptr) } } - if (duplicate) + if (duplicate) { continue; + } if (grant_role_stmt) { - if (ENCODE_ODS(major_version, minor_original) < ODS_9_0) { + if (ENCODE_ODS(major_version, minor_original) < ODS_9_0) + { DYN_error(FALSE, 196, NULL, NULL, NULL, NULL, NULL); - ERR_punt(); + // ERR_punt(); + goto do_punt; } id = drq_get_role_nm; @@ -1431,8 +1435,10 @@ static void grant( GBL gbl, UCHAR ** ptr) } *ptr2 = '\0'; - if (!grantor_can_grant_role(tdbb, gbl, grantor, object)) - ERR_punt(); + if (!grantor_can_grant_role(tdbb, gbl, grantor, object)) { + // ERR_punt(); + goto do_punt; + } if (user_type == obj_sql_role) { /**************************************************** @@ -1443,12 +1449,12 @@ static void grant( GBL gbl, UCHAR ** ptr) ** *****************************************************/ DYN_error(FALSE, 192, user, NULL, NULL, NULL, NULL); - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ERR_punt(); + // ERR_punt(); + goto do_punt; } } - else { - + else + { /* In the case where the object is a view, then the grantor must have some kind of grant privileges on the base table(s)/view(s). If the grantor is the owner of the view, then we have to explicitely check @@ -1458,14 +1464,20 @@ static void grant( GBL gbl, UCHAR ** ptr) got its grant privilege on the view and no further checks are necessary. */ - if (!obj_type) { /* relation or view because we cannot distinguish at this point. */ + if (!obj_type) + { /* relation or view because we cannot distinguish at this point. */ id = drq_gcg1; - if (!grantor_can_grant - (gbl, tdbb->tdbb_attachment->att_user->usr_user_name, - priv, object, field, TRUE)) { - /* grantor_can_grant has moved the error string already. - just punt back to the setjump */ - ERR_punt(); + if (!grantor_can_grant(gbl, + tdbb->tdbb_attachment->att_user->usr_user_name, + priv, + object, + field, + true)) + { + // grantor_can_grant has moved the error string already. + // just punt back to the setjump + // ERR_punt(); + goto do_punt; } } } @@ -1473,18 +1485,52 @@ static void grant( GBL gbl, UCHAR ** ptr) id = drq_s_grant; store_privilege(gbl, object, user, field, p, user_type, obj_type, options); + } // for (...) + + } // try + catch (...) { + /* we need to rundown as we have to set the env. + But in case the error is from store_priveledge we have already + unwound the request so passing that as null */ + BLK req1 = (id == drq_s_grant || id == drq_gcg1) ? NULL : request; + DYN_rundown_request(0, req1, -1); + if (id == drq_l_grant1) + { + DYN_error_punt(TRUE, 77, NULL, NULL, NULL, NULL, NULL); + // msg 77: "SELECT RDB$USER_PRIVILEGES failed in grant" + } + else if (id == drq_l_grant2) + { + DYN_error_punt(TRUE, 78, NULL, NULL, NULL, NULL, NULL); + // msg 78: "SELECT RDB$USER_PRIVILEGES failed in grant" + } + else if (id == drq_s_grant || id == drq_gcg1) + { + ERR_punt(); + // store_priviledge || grantor_can_grant error already handled, + // just bail out + } else if (id == drq_get_role_nm) { + ERR_punt(); + } else { + assert(id == drq_gcg1); + DYN_error_punt(TRUE, 78, NULL, NULL, NULL, NULL, NULL); + // msg 78: "SELECT RDB$USER_PRIVILEGES failed in grant" + } } - tdbb->tdbb_setjmp = (UCHAR *) old_env; + return; + +do_punt: // ugly, rethink logic of this function + ERR_punt(); } -static BOOLEAN grantor_can_grant( - GBL gbl, - TEXT * grantor, - TEXT * privilege, - TEXT * relation_name, -TEXT * field_name, BOOLEAN top_level) +static bool grantor_can_grant( GBL gbl, + TEXT* grantor, + TEXT* privilege, + TEXT* relation_name, + TEXT* field_name, + bool top_level) { /************************************** * @@ -1497,6 +1543,7 @@ TEXT * field_name, BOOLEAN top_level) * FALSE otherwise. * **************************************/ + JMP_BUF env, *old_env; TDBB tdbb; DBB dbb; @@ -1522,16 +1569,9 @@ TEXT * field_name, BOOLEAN top_level) request = (BLK) CMP_find_request(tdbb, drq_gcg4, DYN_REQUESTS); - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, err_num, NULL, NULL, NULL, NULL, NULL); - /* msg 77: "SELECT RDB$USER_PRIVILEGES failed in grant" */ - - return FALSE; - } + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; err_num = 182; /* for the longjump */ @@ -1550,7 +1590,7 @@ TEXT * field_name, BOOLEAN top_level) DYN_error(FALSE, 175, relation_name, NULL, NULL, NULL, NULL); /* table/view .. does not exist */ tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } /* Verify the the input field exists. */ @@ -1574,7 +1614,7 @@ TEXT * field_name, BOOLEAN top_level) NULL); /* column .. does not exist in table/view .. */ tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } } @@ -1582,7 +1622,7 @@ TEXT * field_name, BOOLEAN top_level) if (tdbb->tdbb_attachment->att_user->usr_flags & USR_locksmith) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - return TRUE; + return true; } /* If this is a non-sql table, then the owner will probably not have any @@ -1604,7 +1644,7 @@ TEXT * field_name, BOOLEAN top_level) DYN_REQUEST(drq_gcg2) = request; if (!sql_relation && grantor_is_owner) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - return TRUE; + return true; } /* Verify that the grantor has the grant option for this relation/field @@ -1661,7 +1701,7 @@ TEXT * field_name, BOOLEAN top_level) NULL); /* no grant option for privilege .. on column .. of [base] table/view .. */ tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } else if (go_fld == -1) { @@ -1676,7 +1716,7 @@ TEXT * field_name, BOOLEAN top_level) NULL); /* no grant option for privilege .. on [base] table/view .. (for column ..) */ tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } else if (go_rel == -1) { @@ -1689,7 +1729,7 @@ TEXT * field_name, BOOLEAN top_level) NULL); /* no .. privilege with grant option on [base] table/view .. (for column ..) */ tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } } } @@ -1700,14 +1740,14 @@ TEXT * field_name, BOOLEAN top_level) DYN_error(FALSE, 173, privilege, relation_name, NULL, NULL, NULL); /* no grant option for privilege .. on table/view .. */ tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } else if (go_rel == -1) { DYN_error(FALSE, 174, privilege, relation_name, NULL, NULL, NULL); /* no .. privilege with grant option on table/view .. */ tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } } @@ -1717,7 +1757,7 @@ TEXT * field_name, BOOLEAN top_level) if (!grantor_is_owner) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - return TRUE; + return true; } /* Find all the base fields/relations and check for the correct @@ -1734,42 +1774,60 @@ TEXT * field_name, BOOLEAN top_level) G_FLD.RDB$BASE_FIELD NOT MISSING AND G_VIEW.RDB$VIEW_NAME EQ G_FLD.RDB$RELATION_NAME AND G_VIEW.RDB$VIEW_CONTEXT EQ G_FLD.RDB$VIEW_CONTEXT - if (!DYN_REQUEST(drq_gcg3)) DYN_REQUEST(drq_gcg3) = request; - DYN_terminate(G_FLD.RDB$BASE_FIELD, sizeof(G_FLD.RDB$BASE_FIELD)); - DYN_terminate(G_FLD.RDB$FIELD_NAME, sizeof(G_FLD.RDB$FIELD_NAME)); - DYN_terminate(G_VIEW.RDB$RELATION_NAME, + if (!DYN_REQUEST(drq_gcg3)) { + DYN_REQUEST(drq_gcg3) = request; + } + DYN_terminate(G_FLD.RDB$BASE_FIELD, sizeof(G_FLD.RDB$BASE_FIELD)); + DYN_terminate(G_FLD.RDB$FIELD_NAME, sizeof(G_FLD.RDB$FIELD_NAME)); + DYN_terminate(G_VIEW.RDB$RELATION_NAME, sizeof(G_VIEW.RDB$RELATION_NAME)); - if (field_name[0]) { + + if (field_name[0]) + { if (!strcmp(field_name, G_FLD.RDB$FIELD_NAME)) if (!grantor_can_grant (gbl, grantor, privilege, G_VIEW.RDB$RELATION_NAME, G_FLD.RDB$BASE_FIELD, FALSE)) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } } else { - if (!grantor_can_grant - (gbl, grantor, privilege, G_VIEW.RDB$RELATION_NAME, - G_FLD.RDB$BASE_FIELD, FALSE)) { + if (!grantor_can_grant(gbl, + grantor, + privilege, + G_VIEW.RDB$RELATION_NAME, + G_FLD.RDB$BASE_FIELD, + false)) + { tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; + return false; } } END_FOR; if (!DYN_REQUEST(drq_gcg3)) DYN_REQUEST(drq_gcg3) = request; -/* all done. */ + // all done. + + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, err_num, NULL, NULL, NULL, NULL, NULL); + /* msg 77: "SELECT RDB$USER_PRIVILEGES failed in grant" */ + + return false; + } + tdbb->tdbb_setjmp = (UCHAR *) old_env; - return TRUE; + return true; } -static BOOLEAN grantor_can_grant_role( - TDBB tdbb, - GBL gbl, - TEXT * grantor, TEXT * role_name) +static bool grantor_can_grant_role( TDBB tdbb, + GBL gbl, + TEXT* grantor, + TEXT* role_name) { /************************************** * @@ -1783,37 +1841,40 @@ static BOOLEAN grantor_can_grant_role( * FALSE otherwise. * **************************************/ - DBB dbb; - BLK request; - BOOLEAN grantable = FALSE; + + bool grantable = false; TEXT owner[32]; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; - if (tdbb->tdbb_attachment->att_user->usr_flags & USR_locksmith) - return TRUE; - -/* Fetch the name of the owner of the ROLE */ - if (DYN_is_it_sql_role(gbl, role_name, owner, tdbb)) { - /* The owner of the ROLE can always grant membership */ - if (strcmp(owner, grantor) == 0) - return TRUE; + if (tdbb->tdbb_attachment->att_user->usr_flags & USR_locksmith) { + return true; } - else { - /**************************************************** - ** - ** role name not exist. - ** - *****************************************************/ + + // Fetch the name of the owner of the ROLE + if (DYN_is_it_sql_role(gbl, role_name, owner, tdbb)) + { + // The owner of the ROLE can always grant membership + if (strcmp(owner, grantor) == 0) { + return true; + } + } + else + { + /**************************************************** + ** + ** role name not exist. + ** + *****************************************************/ DYN_error(FALSE, 188, role_name, NULL, NULL, NULL, NULL); - return FALSE; + return false; } - request = (BLK) CMP_find_request(tdbb, drq_get_role_au, DYN_REQUESTS); + BLK request = (BLK) CMP_find_request(tdbb, drq_get_role_au, DYN_REQUESTS); -/* The 'grantor' is not the owner of the ROLE, see if they have - admin privilege on the role */ + // The 'grantor' is not the owner of the ROLE, see if they + // have admin privilege on the role FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) PRV IN RDB$USER_PRIVILEGES WITH PRV.RDB$USER = UPPERCASE(grantor) AND @@ -1821,34 +1882,36 @@ static BOOLEAN grantor_can_grant_role( PRV.RDB$RELATION_NAME EQ role_name AND PRV.RDB$OBJECT_TYPE = obj_sql_role AND PRV.RDB$PRIVILEGE EQ "M" - if (!DYN_REQUEST(drq_get_role_au)) + if (!DYN_REQUEST(drq_get_role_au)) { DYN_REQUEST(drq_get_role_au) = request; + } - if (PRV.RDB$GRANT_OPTION == 2) - grantable = TRUE; - else { - /**************************************************** - ** - ** user have no admin option. - ** - *****************************************************/ + if (PRV.RDB$GRANT_OPTION == 2) { + grantable = true; + } else { + /**************************************************** + ** + ** user have no admin option. + ** + *****************************************************/ DYN_error(FALSE, 189, grantor, role_name, NULL, NULL, NULL); - return FALSE; + return false; } END_FOR; - if (!DYN_REQUEST(drq_get_role_au)) + if (!DYN_REQUEST(drq_get_role_au)) { DYN_REQUEST(drq_get_role_au) = request; + } if (!grantable) { - /**************************************************** - ** - ** user is not a member of the role. - ** - *****************************************************/ + /**************************************************** + ** + ** user is not a member of the role. + ** + *****************************************************/ DYN_error(FALSE, 190, grantor, role_name, NULL, NULL, NULL); - return FALSE; + return false; } return grantable; @@ -1879,7 +1942,8 @@ static void revoke( GBL gbl, UCHAR ** ptr) **************************************/ TDBB tdbb; DBB dbb; - BLK old_request, request; + BLK request; + //BLK old_request; VOLATILE USHORT old_id, id; UCHAR verb; SSHORT user_type, obj_type; @@ -1890,7 +1954,8 @@ static void revoke( GBL gbl, UCHAR ** ptr) JMP_BUF env, *old_env; USR revoking_user; TEXT revoking_user_name[32], dummy_name[32]; - TEXT grantor[32], *ptr1, *ptr2; + //TEXT grantor[32], *ptr2; + TEXT *ptr1; USHORT major_version, minor_original; @@ -1991,31 +2056,17 @@ static void revoke( GBL gbl, UCHAR ** ptr) DYN_REQUESTS); id = field[0] ? drq_e_grant1 : drq_e_grant2; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) { - /* we need to rundown as we have to set the env. - But in case the error is from store_priveledge we have already - unwound the request so passing that as null */ - DYN_rundown_request(old_env, ((id == drq_s_grant) ? NULL : request), - -1); - if (id == drq_e_grant1) - DYN_error_punt(TRUE, 111, NULL, NULL, NULL, NULL, NULL); - /* msg 111: "ERASE RDB$USER_PRIVILEGES failed in revoke(1)" */ - else if (id == drq_e_grant2) - DYN_error_punt(TRUE, 113, NULL, NULL, NULL, NULL, NULL); - /* msg 113: "ERASE RDB$USER_PRIVILEGES failed in revoke (3)" */ - else - ERR_punt(); - /* store_priviledge error already handled, just bail out */ - } + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; temp[1] = 0; - for (p = privileges; temp[0] = *p; p++) { + for (p = privileges; (temp[0] = *p); p++) + { grant_erased = FALSE; - if (field[0]) { + if (field[0]) + { FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) PRIV IN RDB$USER_PRIVILEGES WITH PRIV.RDB$PRIVILEGE EQ temp AND @@ -2029,16 +2080,19 @@ static void revoke( GBL gbl, UCHAR ** ptr) DYN_terminate(PRIV.RDB$GRANTOR, sizeof(PRIV.RDB$GRANTOR)); if ((revoking_user->usr_flags & USR_locksmith) || - (!strcmp(PRIV.RDB$GRANTOR, revoking_user_name))) { + (!strcmp(PRIV.RDB$GRANTOR, revoking_user_name))) + { ERASE PRIV; grant_erased = TRUE; }; END_FOR; - if (!DYN_REQUEST(drq_e_grant1)) + if (!DYN_REQUEST(drq_e_grant1)) { DYN_REQUEST(drq_e_grant1) = request; + } } - else { + else + { FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) PRIV IN RDB$USER_PRIVILEGES WITH PRIV.RDB$PRIVILEGE EQ temp AND @@ -2085,16 +2139,41 @@ static void revoke( GBL gbl, UCHAR ** ptr) } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + /* we need to rundown as we have to set the env. + But in case the error is from store_priveledge we have already + unwound the request so passing that as null */ + DYN_rundown_request(old_env, ((id == drq_s_grant) ? NULL : request), + -1); + if (id == drq_e_grant1) + { + DYN_error_punt(TRUE, 111, NULL, NULL, NULL, NULL, NULL); + /* msg 111: "ERASE RDB$USER_PRIVILEGES failed in revoke(1)" */ + } + else if (id == drq_e_grant2) + { + DYN_error_punt(TRUE, 113, NULL, NULL, NULL, NULL, NULL); + /* msg 113: "ERASE RDB$USER_PRIVILEGES failed in revoke (3)" */ + } + else + { + ERR_punt(); + /* store_priviledge error already handled, just bail out */ + } + } } -static void store_privilege( - GBL gbl, - TEXT * object, - TEXT * user, - TEXT * field, - TEXT * privilege, -SSHORT user_type, SSHORT obj_type, int option) +static void store_privilege(GBL gbl, + TEXT* object, + TEXT* user, + TEXT* field, + TEXT* privilege, + SSHORT user_type, + SSHORT obj_type, + int option) { /************************************** * @@ -2119,33 +2198,35 @@ SSHORT user_type, SSHORT obj_type, int option) request = (BLK) CMP_find_request(tdbb, drq_s_grant, DYN_REQUESTS); /* need to unwind our own request here!! SM 27-Sep-96 */ - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; + + STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + PRIV IN RDB$USER_PRIVILEGES PRIV.RDB$FIELD_NAME.NULL = TRUE; + strcpy(PRIV.RDB$RELATION_NAME, object); + strcpy(PRIV.RDB$USER, user); + PRIV.RDB$USER_TYPE = user_type; + PRIV.RDB$OBJECT_TYPE = obj_type; + if (field && field[0]) { + strcpy(PRIV.RDB$FIELD_NAME, field); + PRIV.RDB$FIELD_NAME.NULL = FALSE; + } + PRIV.RDB$PRIVILEGE[0] = privilege[0]; + PRIV.RDB$PRIVILEGE[1] = 0; + PRIV.RDB$GRANT_OPTION = option; + + END_STORE; + + if (!DYN_REQUEST(drq_s_grant)) { + DYN_REQUEST(drq_s_grant) = request; + } + tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { DYN_rundown_request(old_env, request, -1); DYN_error_punt(TRUE, 79, NULL, NULL, NULL, NULL, NULL); /* msg 79: "STORE RDB$USER_PRIVILEGES failed in grant" */ } - - - STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - PRIV IN RDB$USER_PRIVILEGES PRIV.RDB$FIELD_NAME.NULL = TRUE; - strcpy(PRIV.RDB$RELATION_NAME, object); - strcpy(PRIV.RDB$USER, user); - PRIV.RDB$USER_TYPE = user_type; - PRIV.RDB$OBJECT_TYPE = obj_type; - if (field && field[0]) { - strcpy(PRIV.RDB$FIELD_NAME, field); - PRIV.RDB$FIELD_NAME.NULL = FALSE; - } - PRIV.RDB$PRIVILEGE[0] = privilege[0]; - PRIV.RDB$PRIVILEGE[1] = 0; - PRIV.RDB$GRANT_OPTION = option; - - END_STORE; - - if (!DYN_REQUEST(drq_s_grant)) - DYN_REQUEST(drq_s_grant) = request; - tdbb->tdbb_setjmp = (UCHAR *) old_env; } diff --git a/src/jrd/dyn_def.epp b/src/jrd/dyn_def.epp index 1dfb72773b..e13617d71b 100644 --- a/src/jrd/dyn_def.epp +++ b/src/jrd/dyn_def.epp @@ -108,6 +108,14 @@ static BOOLEAN get_who(TDBB, GBL, SCHAR *); static BOOLEAN is_it_user_name(GBL, TEXT *, TDBB); +#pragma FB_COMPILER_MESSAGE("Remove once we updated gpre") +static inline void gds__vtov(CONST UCHAR* s1, SCHAR* s2, SSHORT val) +{ + gds__vtov(reinterpret_cast(s1), s2, val); +} + + + static int private_getODS() { TDBB tdbb = GET_THREAD_DATA; @@ -144,25 +152,13 @@ void DYN_define_cache( GBL gbl, UCHAR ** ptr) tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; request = NULL; + + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; id = -1; - if (SETJMP(env)) - { - if (id == drq_s_cache) - { - DYN_rundown_request(old_env, request, drq_s_cache); - DYN_error_punt(TRUE, 150, NULL, NULL, NULL, NULL, NULL); - /* msg 150: STORE RDB$FILES failed */ - } - else - { - DYN_rundown_request(old_env, request, drq_l_cache); - DYN_error_punt(TRUE, 156, NULL, NULL, NULL, NULL, NULL); - /* msg 156: Shared cache lookup failed */ - } - } id = drq_l_cache; request = (BLK) CMP_find_request(tdbb, drq_l_cache, DYN_REQUESTS); FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) @@ -170,13 +166,13 @@ void DYN_define_cache( GBL gbl, UCHAR ** ptr) found = TRUE; END_FOR; - if (!DYN_REQUEST(drq_l_cache)) + if (!DYN_REQUEST(drq_l_cache)) { DYN_REQUEST(drq_l_cache) = request; + } if (found) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(FALSE, 148, NULL, NULL, NULL, NULL, NULL); - /* msg 148: "Shared cache file already exists" */ + goto dyn_punt_148; } request = (BLK) CMP_find_request(tdbb, drq_s_cache, DYN_REQUESTS); @@ -211,13 +207,35 @@ void DYN_define_cache( GBL gbl, UCHAR ** ptr) } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (id == drq_s_cache) + { + DYN_rundown_request(old_env, request, drq_s_cache); + DYN_error_punt(TRUE, 150, NULL, NULL, NULL, NULL, NULL); + /* msg 150: STORE RDB$FILES failed */ + } + else + { + DYN_rundown_request(old_env, request, drq_l_cache); + DYN_error_punt(TRUE, 156, NULL, NULL, NULL, NULL, NULL); + /* msg 156: Shared cache lookup failed */ + } + } + + return; + +dyn_punt_148: + DYN_error_punt(FALSE, 148, NULL, NULL, NULL, NULL, NULL); + /* msg 148: "Shared cache file already exists" */ } -void DYN_define_constraint( - GBL gbl, - UCHAR ** ptr, - TEXT * relation_name, TEXT * field_name) +void DYN_define_constraint(GBL gbl, + UCHAR** ptr, + TEXT* relation_name, + TEXT* field_name) { /************************************** * @@ -241,7 +259,7 @@ void DYN_define_constraint( TEXT null_field_name[32], trigger_name[32]; int all_count, unique_count; LLS field_list = NULL, list_ptr; - STR str; + STR str_; USHORT found, foreign_flag = FALSE, not_null; JMP_BUF env; JMP_BUF *VOLATILE old_env; @@ -256,38 +274,10 @@ void DYN_define_constraint( request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (id == drq_s_rel_con) - { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 121, NULL, NULL, NULL, NULL, NULL); - /* msg 121: "STORE RDB$RELATION_CONSTRAINTS failed" */ - } - else if (id == drq_s_ref_con) - { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 127, NULL, NULL, NULL, NULL, NULL); - /* msg 127: "STORE RDB$REF_CONSTRAINTS failed" */ - } - - DYN_rundown_request(old_env, request, -1); - if (id == drq_c_unq_nam) - DYN_error_punt(TRUE, 121, NULL, NULL, NULL, NULL, NULL); - /* msg 121: "STORE RDB$RELATION_CONSTRAINTS failed" */ - else if (id == drq_n_idx_seg) - DYN_error_punt(TRUE, 124, constraint_name, NULL, NULL, NULL, - NULL); - /* msg 124: "A column name is repeated in the definition of constraint: %s" */ - else if (id == drq_c_dup_con) - DYN_error_punt(TRUE, 125, NULL, NULL, NULL, NULL, NULL); - /* msg 125: "Integrity constraint lookup failed" */ - else - DYN_error_punt(TRUE, 125, NULL, NULL, NULL, NULL, NULL); - /* msg 125: "Integrity constraint lookup failed" */ - } request = (BLK) CMP_find_request(tdbb, drq_s_rel_con, DYN_REQUESTS); id = drq_s_rel_con; @@ -344,9 +334,40 @@ void DYN_define_constraint( END_STORE; if (!DYN_REQUEST(drq_s_rel_con)) + { DYN_REQUEST(drq_s_rel_con) = request; + } - if (verb == gds_dyn_def_trigger) { + } // try + catch (...) { + SSHORT local_id = -1; + USHORT number; + // msg 121: "STORE RDB$RELATION_CONSTRAINTS failed" + // msg 124: "A column name is repeated in the definition of constraint: %s" + // msg 125: "Integrity constraint lookup failed" + // msg 127: "STORE RDB$REF_CONSTRAINTS failed" + switch (id) { + case drq_s_rel_con: number = 121; local_id = id; break; + case drq_s_ref_con: number = 127; local_id = id; break; + case drq_c_unq_nam: number = 121; break; + case drq_n_idx_seg: number = 124; break; + case drq_c_dup_con: number = 125; break; + default: number = 125; break; + } + + DYN_rundown_request(old_env, request, local_id); + + DYN_error_punt(TRUE, + number, + number == 124 ? constraint_name : NULL, + NULL, + NULL, + NULL, + NULL); + } + + if (verb == gds_dyn_def_trigger) + { tdbb->tdbb_setjmp = (UCHAR *) old_env; do { DYN_define_trigger(gbl, ptr, relation_name, trigger_name, FALSE); @@ -354,21 +375,26 @@ void DYN_define_constraint( trigger_name); } while ((verb = *(*ptr)++) == gds_dyn_def_trigger); - if (verb != gds_dyn_end) + if (verb != gds_dyn_end) { DYN_unsupported_verb(); + } return; } - if (verb == gds_dyn_fld_not_null) { + if (verb == gds_dyn_fld_not_null) + { tdbb->tdbb_setjmp = (UCHAR *) old_env; DYN_UTIL_store_check_constraints(tdbb, gbl, constraint_name, field_name); - if (*(*ptr)++ != gds_dyn_end) + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } return; } + try { + /* Make sure unique field names were specified for UNIQUE/PRIMARY/FOREIGN */ /* All fields must have the NOT NULL attribute specified for UNIQUE/PRIMARY. */ @@ -402,18 +428,18 @@ void DYN_define_constraint( } unique_count++; - str = (STR) ALLOCDV(type_str, sizeof(IDS.RDB$FIELD_NAME) - 1); - strcpy((char*)str->str_data, IDS.RDB$FIELD_NAME); - LLS_PUSH(str, &field_list); + str_ = new(*tdbb->tdbb_default, sizeof(IDS.RDB$FIELD_NAME) - 1) str(); + strcpy((char*)str_->str_data, IDS.RDB$FIELD_NAME); + LLS_PUSH(str_, &field_list); END_FOR; - if (!DYN_REQUEST(drq_c_unq_nam)) + if (!DYN_REQUEST(drq_c_unq_nam)) { DYN_REQUEST(drq_c_unq_nam) = request; + } if (not_null == FALSE) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error(FALSE, 123, null_field_name, NULL, NULL, NULL, NULL); + DYN_error_punt(FALSE, 123, null_field_name, NULL, NULL, NULL, NULL); /* msg 123: "Field: %s not defined as NOT NULL - can't be used in PRIMARY KEY/UNIQUE constraint definition" */ - ERR_punt(); } request = (BLK) CMP_find_request(tdbb, drq_n_idx_seg, DYN_REQUESTS); @@ -421,25 +447,26 @@ void DYN_define_constraint( FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) IDS IN RDB$INDEX_SEGMENTS WITH IDS.RDB$INDEX_NAME EQ index_name - if (!DYN_REQUEST(drq_n_idx_seg)) + if (!DYN_REQUEST(drq_n_idx_seg)) { DYN_REQUEST(drq_n_idx_seg) = request; + } all_count++; END_FOR; - if (!DYN_REQUEST(drq_n_idx_seg)) + if (!DYN_REQUEST(drq_n_idx_seg)) { DYN_REQUEST(drq_n_idx_seg) = request; + } if (unique_count != all_count) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error(FALSE, 124, constraint_name, NULL, NULL, NULL, NULL); - /* msg 124: "A column name is repeated in the definition of constraint: %s" */ - ERR_punt(); + goto dyn_punt_false_124; } /* For PRIMARY KEY/UNIQUE constraints, make sure same set of columns is not used in another constraint of either type */ - if (foreign_flag == FALSE) { + if (foreign_flag == FALSE) + { request = (BLK) CMP_find_request(tdbb, drq_c_dup_con, DYN_REQUESTS); id = drq_c_dup_con; @@ -458,39 +485,47 @@ void DYN_define_constraint( DYN_REQUEST(drq_c_dup_con) = request; DYN_terminate(CRT.RDB$INDEX_NAME, sizeof(CRT.RDB$INDEX_NAME)); - if (strcmp(index_name, CRT.RDB$INDEX_NAME)) { - if (list_ptr) + if (strcmp(index_name, CRT.RDB$INDEX_NAME)) + { + if (list_ptr) { found = FALSE; - if (found) + } + if (found) { break; + } list_ptr = field_list; strcpy(index_name, CRT.RDB$INDEX_NAME); found = TRUE; } - if (list_ptr) { - if (strcmp - ((char*)((STR) list_ptr->lls_object)->str_data, - IDS.RDB$FIELD_NAME)) found = FALSE; + if (list_ptr) + { + if (strcmp((char*)((STR) list_ptr->lls_object)->str_data, + IDS.RDB$FIELD_NAME)) + { + found = FALSE; + } list_ptr = list_ptr->lls_next; } - else + else { found = FALSE; + } END_FOR; - if (!DYN_REQUEST(drq_c_dup_con)) + if (!DYN_REQUEST(drq_c_dup_con)) { DYN_REQUEST(drq_c_dup_con) = request; + } - if (list_ptr) + if (list_ptr) { found = FALSE; + } if (found) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error(FALSE, 126, NULL, NULL, NULL, NULL, NULL); - /* msg 126: "Same set of columns cannot be used in more than one PRIMARY KEY and/or UNIQUE constraint definition" */ - ERR_punt(); + goto dyn_punt_false_126; } } - else { /* Foreign key being defined */ + else + { /* Foreign key being defined */ request = (BLK) CMP_find_request(tdbb, drq_s_ref_con, DYN_REQUESTS); id = drq_s_ref_con; @@ -556,13 +591,52 @@ void DYN_define_constraint( } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + SSHORT local_id = -1; + USHORT number; + // msg 121: "STORE RDB$RELATION_CONSTRAINTS failed" + // msg 124: "A column name is repeated in the definition of constraint: %s" + // msg 125: "Integrity constraint lookup failed" + // msg 127: "STORE RDB$REF_CONSTRAINTS failed" + switch (id) { + case drq_s_rel_con: number = 121; local_id = id; break; + case drq_s_ref_con: number = 127; local_id = id; break; + case drq_c_unq_nam: number = 121; break; + case drq_n_idx_seg: number = 124; break; + case drq_c_dup_con: number = 125; break; + default: number = 125; break; + } + + DYN_rundown_request(old_env, request, local_id); + + DYN_error_punt(TRUE, + number, + number == 124 ? constraint_name : NULL, + NULL, + NULL, + NULL, + NULL); + } + + return; + +dyn_punt_false_124: + DYN_error_punt(FALSE, 124, constraint_name, NULL, NULL, NULL, NULL); + /* msg 124: "A column name is repeated in the definition of constraint: %s" */ + return; + +dyn_punt_false_126: + DYN_error_punt(FALSE, 126, NULL, NULL, NULL, NULL, NULL); + /* msg 126: "Same set of columns cannot be used in more than one PRIMARY KEY and/or UNIQUE constraint definition" */ } -void DYN_define_dimension( - GBL gbl, - UCHAR ** ptr, - TEXT * relation_name, TEXT * field_name) +void DYN_define_dimension(GBL gbl, + UCHAR** ptr, + TEXT* relation_name, + TEXT* field_name) { /************************************** * @@ -620,6 +694,8 @@ void DYN_define_dimension( } } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -630,8 +706,9 @@ void DYN_define_dimension( } END_STORE; - if (!DYN_REQUEST(drq_s_dims)) + if (!DYN_REQUEST(drq_s_dims)) { DYN_REQUEST(drq_s_dims) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; } @@ -686,6 +763,8 @@ void DYN_define_exception( GBL gbl, UCHAR ** ptr) } } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -696,17 +775,19 @@ void DYN_define_exception( GBL gbl, UCHAR ** ptr) } END_STORE; - if (!DYN_REQUEST(drq_s_xcp)) + if (!DYN_REQUEST(drq_s_xcp)) { DYN_REQUEST(drq_s_xcp) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; } -void DYN_define_file( - GBL gbl, - UCHAR ** ptr, - SLONG shadow_number, SLONG * start, USHORT msg) +void DYN_define_file(GBL gbl, + UCHAR** ptr, + SLONG shadow_number, + SLONG* start, + USHORT msg) { /************************************** * @@ -733,24 +814,13 @@ void DYN_define_file( dbb = tdbb->tdbb_database; request = NULL; + + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; id = -1; - if (SETJMP(env)) - { - if (id == drq_l_files) - { - DYN_rundown_request(old_env, request, drq_l_files); - DYN_error_punt(FALSE, 166, NULL, NULL, NULL, NULL, NULL); - } - else - { - DYN_rundown_request(old_env, request, drq_s_files); - DYN_error_punt(TRUE, msg, NULL, NULL, NULL, NULL, NULL); - } - } - request = (BLK) CMP_find_request(tdbb, id = drq_l_files, DYN_REQUESTS); GET_STRING(ptr, temp_f1); @@ -813,6 +883,21 @@ void DYN_define_file( } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (id == drq_l_files) + { + DYN_rundown_request(old_env, request, drq_l_files); + DYN_error_punt(FALSE, 166, NULL, NULL, NULL, NULL, NULL); + } + else + { + DYN_rundown_request(old_env, request, drq_s_files); + DYN_error_punt(TRUE, msg, NULL, NULL, NULL, NULL, NULL); + } + } + } @@ -889,6 +974,8 @@ void DYN_define_filter( GBL gbl, UCHAR ** ptr) } } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -984,6 +1071,8 @@ void DYN_define_function( GBL gbl, UCHAR ** ptr) } } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -995,8 +1084,9 @@ void DYN_define_function( GBL gbl, UCHAR ** ptr) } END_STORE; - if (!DYN_REQUEST(drq_s_funcs)) + if (!DYN_REQUEST(drq_s_funcs)) { DYN_REQUEST(drq_s_funcs) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; } @@ -1024,15 +1114,10 @@ void DYN_define_function_arg(GBL gbl, UCHAR** ptr, TEXT* function_name) tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (request) - DYN_rundown_request(old_env, request, drq_s_func_args); - DYN_error_punt(TRUE, 12, NULL, NULL, NULL, NULL, NULL); - /* msg 12: "DEFINE FUNCTION ARGUMENT failed" */ - } request = (BLK) CMP_find_request(tdbb, drq_s_func_args, DYN_REQUESTS); @@ -1126,6 +1211,15 @@ void DYN_define_function_arg(GBL gbl, UCHAR** ptr, TEXT* function_name) DYN_REQUEST(drq_s_func_args) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (request) { + DYN_rundown_request(old_env, request, drq_s_func_args); + } + DYN_error_punt(TRUE, 12, NULL, NULL, NULL, NULL, NULL); + /* msg 12: "DEFINE FUNCTION ARGUMENT failed" */ + } } @@ -1157,6 +1251,8 @@ void DYN_define_generator( GBL gbl, UCHAR ** ptr) GET_STRING(ptr, X.RDB$GENERATOR_NAME); +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -1173,8 +1269,10 @@ void DYN_define_generator( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; if (*(*ptr)++ != gds_dyn_end) + { DYN_error_punt(TRUE, 9, NULL, NULL, NULL, NULL, NULL); - /* msg 9: "DEFINE GENERATOR unexpected dyn verb" */ + /* msg 9: "DEFINE GENERATOR unexpected dyn verb" */ + } } @@ -1236,64 +1334,78 @@ void DYN_define_role( GBL gbl, UCHAR ** ptr) ERR_punt(); } - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; /* save environment */ - tdbb->tdbb_setjmp = (UCHAR *) env; /* get new environment */ + try { - if (SETJMP(env)) - { - if (request) + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; /* save environment */ + tdbb->tdbb_setjmp = (UCHAR *) env; /* get new environment */ + + + if (is_it_user_name(gbl, role_name, tdbb)) { + /************************************************ + ** + ** user name could not be used for SQL role + ** + *************************************************/ + DYN_error(FALSE, 193, role_name, NULL, NULL, NULL, NULL); + tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ + goto do_err_punt; + } + + if (DYN_is_it_sql_role(gbl, role_name, dummy_name, tdbb)) { + /************************************************ + ** + ** SQL role already exist + ** + *************************************************/ + DYN_error(FALSE, 194, role_name, NULL, NULL, NULL, NULL); + tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ + goto do_err_punt; + } + + request = (BLK) CMP_find_request(tdbb, drq_role_gens, DYN_REQUESTS); + + STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + X IN RDB$ROLES + strcpy(X.RDB$ROLE_NAME, role_name); + strcpy(X.RDB$OWNER_NAME, owner_name); + + END_STORE; + + if (!DYN_REQUEST(drq_role_gens)) { + DYN_REQUEST(drq_role_gens) = request; + } + + if (*(*ptr)++ != gds_dyn_end) { + goto do_error_punt_9; + } + + tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ + } + catch (...) { + if (request) { DYN_rundown_request(old_env, request, drq_role_gens); + } tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ DYN_error_punt(TRUE, 8, NULL, NULL, NULL, NULL, NULL); /* msg 8: "DEFINE ROLE failed" */ } - if (is_it_user_name(gbl, role_name, tdbb)) { - /************************************************ - ** - ** user name could not be used for SQL role - ** - *************************************************/ - DYN_error(FALSE, 193, role_name, NULL, NULL, NULL, NULL); - tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ - ERR_punt(); - } + return; - if (DYN_is_it_sql_role(gbl, role_name, dummy_name, tdbb)) { - /************************************************ - ** - ** SQL role already exist - ** - *************************************************/ - DYN_error(FALSE, 194, role_name, NULL, NULL, NULL, NULL); - tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ - ERR_punt(); - } +do_err_punt: + ERR_punt(); + return; - request = (BLK) CMP_find_request(tdbb, drq_role_gens, DYN_REQUESTS); - - STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - X IN RDB$ROLES - strcpy(X.RDB$ROLE_NAME, role_name); - strcpy(X.RDB$OWNER_NAME, owner_name); - - END_STORE; - - if (!DYN_REQUEST(drq_role_gens)) - DYN_REQUEST(drq_role_gens) = request; - - if (*(*ptr)++ != gds_dyn_end) - DYN_error_punt(TRUE, 9, NULL, NULL, NULL, NULL, NULL); +do_error_punt_9: + DYN_error_punt(TRUE, 9, NULL, NULL, NULL, NULL, NULL); /* msg 9: "DEFINE ROLE unexpected dyn verb" */ - - tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ } -void DYN_define_global_field( - GBL gbl, - UCHAR ** ptr, - TEXT * relation_name, TEXT * field_name) +void DYN_define_global_field(GBL gbl, + UCHAR** ptr, + TEXT* relation_name, + TEXT* field_name) { /************************************** * @@ -1305,24 +1417,24 @@ void DYN_define_global_field( * Execute a dynamic ddl statement. * **************************************/ - TDBB tdbb; - DBB dbb; + UCHAR verb; VOLATILE BLK request; USHORT dtype; JMP_BUF env; - JMP_BUF *VOLATILE old_env; + JMP_BUF* VOLATILE old_env; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; request = (BLK) CMP_find_request(tdbb, drq_s_gfields, DYN_REQUESTS); STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) FLD IN RDB$FIELDS USING - if (!GET_STRING(ptr, FLD.RDB$FIELD_NAME)) + if (!GET_STRING(ptr, FLD.RDB$FIELD_NAME)) { DYN_UTIL_generate_field_name(tdbb, gbl, FLD.RDB$FIELD_NAME); + } FLD.RDB$SYSTEM_FLAG.NULL = TRUE; FLD.RDB$FIELD_SCALE.NULL = TRUE; @@ -1347,6 +1459,7 @@ void DYN_define_global_field( FLD.RDB$FIELD_PRECISION.NULL = TRUE; while ((verb = *(*ptr)++) != gds_dyn_end) + { switch (verb) { case gds_dyn_system_flag: @@ -1535,6 +1648,9 @@ void DYN_define_global_field( (field_name) ? field_name : FLD.RDB$FIELD_NAME, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); } + } + +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; @@ -1546,8 +1662,9 @@ void DYN_define_global_field( } END_STORE; - if (!DYN_REQUEST(drq_s_gfields)) + if (!DYN_REQUEST(drq_s_gfields)) { DYN_REQUEST(drq_s_gfields) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; } @@ -1582,7 +1699,7 @@ void DYN_define_index(GBL gbl, UCHAR index_name[32], referenced_relation[32]; UCHAR verb, seg_count, fld_count; LLS field_list = NULL, seg_list = NULL, list_ptr; - STR str; + STR str_; USHORT found, key_length, length, referred_cols = 0; JMP_BUF env; JMP_BUF *VOLATILE old_env; @@ -1597,35 +1714,10 @@ void DYN_define_index(GBL gbl, request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (id == drq_s_indices) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 21, NULL, NULL, NULL, NULL, NULL); - /* msg 21: "STORE RDB$INDICES failed" */ - } - else if (id == drq_s_idx_segs) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 15, NULL, NULL, NULL, NULL, NULL); - /* msg 15: "STORE RDB$INDICES failed" */ - } - - DYN_rundown_request(old_env, request, -1); - if (id == drq_l_lfield) - DYN_error_punt(TRUE, 15, NULL, NULL, NULL, NULL, NULL); - /* msg 15: "STORE RDB$INDICES failed" */ - else if (id == drq_l_unq_idx) - DYN_error_punt(TRUE, 17, NULL, NULL, NULL, NULL, NULL); - /* msg 17: "Primary Key field lookup failed" */ - else if (id == drq_l_view_idx) - DYN_error_punt(TRUE, 180, NULL, NULL, NULL, NULL, NULL); - /* msg 180: "Table Name lookup failed" */ - else - DYN_error_punt(TRUE, 19, NULL, NULL, NULL, NULL, NULL); - /* msg 19: "Primary Key lookup failed" */ - } request = (BLK) CMP_find_request(tdbb, drq_s_indices, DYN_REQUESTS); id = drq_s_indices; @@ -1704,17 +1796,17 @@ void DYN_define_index(GBL gbl, IDX.RDB$INDEX_TYPE = (SSHORT)DYN_get_number(ptr); IDX.RDB$INDEX_TYPE.NULL = FALSE; break; - + case gds_dyn_fld_name: - str = (STR) ALLOCDV(type_str, field_name_size - 1); - DYN_get_string((TEXT**)ptr, (TEXT*)str->str_data, field_name_size, TRUE); - LLS_PUSH(str, &seg_list); + str_ = new(*tdbb->tdbb_default, field_name_size - 1) str(); + DYN_get_string((TEXT**)ptr, (TEXT*)str_->str_data, field_name_size, TRUE); + LLS_PUSH(str_, &seg_list); seg_count++; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) F IN RDB$RELATION_FIELDS CROSS GF IN RDB$FIELDS WITH GF.RDB$FIELD_NAME EQ F.RDB$FIELD_SOURCE AND - F.RDB$FIELD_NAME EQ str->str_data AND + F.RDB$FIELD_NAME EQ str_->str_data AND IDX.RDB$RELATION_NAME EQ F.RDB$RELATION_NAME if (!DYN_REQUEST(drq_l_lfield)) { @@ -1810,9 +1902,9 @@ void DYN_define_index(GBL gbl, break; case gds_dyn_idx_ref_column: - str = (STR) ALLOCDV(type_str, field_name_size - 1); - DYN_get_string((TEXT**)ptr, (TEXT*)str->str_data, field_name_size, TRUE); - LLS_PUSH(str, &field_list); + str_ = new(*tdbb->tdbb_default, field_name_size - 1) str(); + DYN_get_string((TEXT**)ptr, (TEXT*)str_->str_data, field_name_size, TRUE); + LLS_PUSH(str_, &field_list); referred_cols++; break; @@ -1949,13 +2041,13 @@ void DYN_define_index(GBL gbl, (BLK) CMP_find_request(tdbb, drq_s_idx_segs, DYN_REQUESTS); id = drq_s_idx_segs; while (seg_list) { - str = (STR) LLS_POP(&seg_list); + str_ = (STR) LLS_POP(&seg_list); STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) X IN RDB$INDEX_SEGMENTS strcpy((char*)X.RDB$INDEX_NAME, (char*)IDX.RDB$INDEX_NAME); - strcpy(X.RDB$FIELD_NAME, (char*)str->str_data); + strcpy(X.RDB$FIELD_NAME, (char*)str_->str_data); X.RDB$FIELD_POSITION = --fld_count; - ALL_release((FRB)str); + delete str_; END_STORE; } if (!DYN_REQUEST(drq_s_idx_segs)) @@ -2093,10 +2185,39 @@ void DYN_define_index(GBL gbl, IDX.RDB$SEGMENT_COUNT = seg_count; END_STORE; - if (!DYN_REQUEST(drq_s_indices)) + if (!DYN_REQUEST(drq_s_indices)) { DYN_REQUEST(drq_s_indices) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + if (id == drq_s_indices) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 21, NULL, NULL, NULL, NULL, NULL); + /* msg 21: "STORE RDB$INDICES failed" */ + } + else if (id == drq_s_idx_segs) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 15, NULL, NULL, NULL, NULL, NULL); + /* msg 15: "STORE RDB$INDICES failed" */ + } + + DYN_rundown_request(old_env, request, -1); + if (id == drq_l_lfield) + DYN_error_punt(TRUE, 15, NULL, NULL, NULL, NULL, NULL); + /* msg 15: "STORE RDB$INDICES failed" */ + else if (id == drq_l_unq_idx) + DYN_error_punt(TRUE, 17, NULL, NULL, NULL, NULL, NULL); + /* msg 17: "Primary Key field lookup failed" */ + else if (id == drq_l_view_idx) + DYN_error_punt(TRUE, 180, NULL, NULL, NULL, NULL, NULL); + /* msg 180: "Table Name lookup failed" */ + else + DYN_error_punt(TRUE, 19, NULL, NULL, NULL, NULL, NULL); + /* msg 19: "Primary Key lookup failed" */ + } } @@ -2139,19 +2260,8 @@ void DYN_define_local_field(GBL gbl, old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (id == drq_s_lfields) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 23, NULL, NULL, NULL, NULL, NULL); - /* msg 23: "STORE RDB$RELATION_FIELDS failed" */ - } - else { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 22, NULL, NULL, NULL, NULL, NULL); - /* msg 22: "STORE RDB$FIELDS failed" */ - } - } + + try { request = (BLK) CMP_find_request(tdbb, drq_s_lfields, DYN_REQUESTS); id = drq_s_lfields; @@ -2442,10 +2552,25 @@ void DYN_define_local_field(GBL gbl, END_STORE; - if (!DYN_REQUEST(drq_s_lfields)) + if (!DYN_REQUEST(drq_s_lfields)) { DYN_REQUEST(drq_s_lfields) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + if (id == drq_s_lfields) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 23, NULL, NULL, NULL, NULL, NULL); + /* msg 23: "STORE RDB$RELATION_FIELDS failed" */ + } + else { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 22, NULL, NULL, NULL, NULL, NULL); + /* msg 22: "STORE RDB$FIELDS failed" */ + } + } } @@ -2480,23 +2605,13 @@ void DYN_define_log_file( request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (id == drq_s_log_files) { - DYN_rundown_request(old_env, request, drq_s_log_files); - DYN_error_punt(TRUE, 154, NULL, NULL, NULL, NULL, NULL); - /* msg 154: STORE RDB$LOG_FILES failed */ - } - else { - DYN_rundown_request(old_env, request, drq_l_log_files); - DYN_error_punt(TRUE, 155, NULL, NULL, NULL, NULL, NULL); - /* msg 155: Write ahead log lookup failed */ - } - } - if (first_log_file) { + if (first_log_file) + { id = drq_l_log_files; request = (BLK) CMP_find_request(tdbb, drq_l_log_files, DYN_REQUESTS); FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) @@ -2508,9 +2623,8 @@ void DYN_define_log_file( if (found) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(FALSE, 151, NULL, NULL, NULL, NULL, NULL); + goto local_punt_false_151; } - /* msg 151: "Write ahead log already exists" */ } request = (BLK) CMP_find_request(tdbb, drq_s_log_files, DYN_REQUESTS); @@ -2586,6 +2700,26 @@ void DYN_define_log_file( DYN_REQUEST(drq_s_log_files) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (id == drq_s_log_files) { + DYN_rundown_request(old_env, request, drq_s_log_files); + DYN_error_punt(TRUE, 154, NULL, NULL, NULL, NULL, NULL); + /* msg 154: STORE RDB$LOG_FILES failed */ + } + else { + DYN_rundown_request(old_env, request, drq_l_log_files); + DYN_error_punt(TRUE, 155, NULL, NULL, NULL, NULL, NULL); + /* msg 155: Write ahead log lookup failed */ + } + } + + return; + +local_punt_false_151: + DYN_error_punt(FALSE, 151, NULL, NULL, NULL, NULL, NULL); + /* msg 151: "Write ahead log already exists" */ } @@ -2620,28 +2754,11 @@ void DYN_define_parameter( GBL gbl, UCHAR ** ptr, TEXT * procedure_name) request = (BLK) CMP_find_request(tdbb, drq_s_prms, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; id = -1; - if (SETJMP(env)) - { - if (id == drq_s_prms) { - DYN_rundown_request(old_env, request, drq_s_prms); - DYN_error_punt(TRUE, 136, NULL, NULL, NULL, NULL, NULL); - /* msg 163: "STORE RDB$PROCEDURE_PARAMETERS failed" */ - } - else if (id == drq_s_prm_src) { - DYN_rundown_request(old_env, request, drq_s_prm_src); - DYN_error_punt(TRUE, 136, NULL, NULL, NULL, NULL, NULL); - /* msg 136: "STORE RDB$PROCEDURE_PARAMETERS failed" */ - } - DYN_rundown_request(old_env, request, -1); - - /* Control should never reach this point, - because id should always have one of the values tested above. */ - assert(0); - DYN_error_punt(TRUE, 0, NULL, NULL, NULL, NULL, NULL); - } f_length = f_type = f_subtype = f_charlength = f_scale = f_seg_length = 0; f_charset = f_collation = f_precision = 0; @@ -2816,6 +2933,26 @@ void DYN_define_parameter( GBL gbl, UCHAR ** ptr, TEXT * procedure_name) DYN_REQUEST(drq_s_prms) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (id == drq_s_prms) { + DYN_rundown_request(old_env, request, drq_s_prms); + DYN_error_punt(TRUE, 136, NULL, NULL, NULL, NULL, NULL); + /* msg 163: "STORE RDB$PROCEDURE_PARAMETERS failed" */ + } + else if (id == drq_s_prm_src) { + DYN_rundown_request(old_env, request, drq_s_prm_src); + DYN_error_punt(TRUE, 136, NULL, NULL, NULL, NULL, NULL); + /* msg 136: "STORE RDB$PROCEDURE_PARAMETERS failed" */ + } + DYN_rundown_request(old_env, request, -1); + + /* Control should never reach this point, + because id should always have one of the values tested above. */ + assert(0); + DYN_error_punt(TRUE, 0, NULL, NULL, NULL, NULL, NULL); + } } @@ -2850,31 +2987,10 @@ void DYN_define_procedure( GBL gbl, UCHAR ** ptr) request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (id == drq_s_prcs) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 134, NULL, NULL, NULL, NULL, NULL); - /* msg 134: "STORE RDB$PROCEDURES failed" */ - } - else if (id == drq_s_prc_usr_prvs) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 25, NULL, NULL, NULL, NULL, NULL); - /* msg 25: "STORE RDB$USER_PRIVILEGES failed defining a relation" */ - } - - DYN_rundown_request(old_env, request, -1); - if (id == drq_l_prc_name) - DYN_error_punt(TRUE, 134, NULL, NULL, NULL, NULL, NULL); - /* msg 134: "STORE RDB$PROCEDURES failed" */ - - /* Control should never reach this point, because id should have - one of the values tested-for above. */ - assert(0); - DYN_error_punt(TRUE, 0, NULL, NULL, NULL, NULL, NULL); - } id = drq_l_prc_name; check_unique_name(tdbb, gbl, procedure_name, TRUE); @@ -2982,6 +3098,30 @@ void DYN_define_procedure( GBL gbl, UCHAR ** ptr) } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (id == drq_s_prcs) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 134, NULL, NULL, NULL, NULL, NULL); + /* msg 134: "STORE RDB$PROCEDURES failed" */ + } + else if (id == drq_s_prc_usr_prvs) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 25, NULL, NULL, NULL, NULL, NULL); + /* msg 25: "STORE RDB$USER_PRIVILEGES failed defining a relation" */ + } + + DYN_rundown_request(old_env, request, -1); + if (id == drq_l_prc_name) + DYN_error_punt(TRUE, 134, NULL, NULL, NULL, NULL, NULL); + /* msg 134: "STORE RDB$PROCEDURES failed" */ + + /* Control should never reach this point, because id should have + one of the values tested-for above. */ + assert(0); + DYN_error_punt(TRUE, 0, NULL, NULL, NULL, NULL, NULL); + } } @@ -3018,34 +3158,10 @@ void DYN_define_relation( GBL gbl, UCHAR ** ptr) request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (id == drq_s_rels) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 24, NULL, NULL, NULL, NULL, NULL); - /* msg 24: "STORE RDB$RELATIONS failed" */ - } - else if (id == drq_s_usr_prvs) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 25, NULL, NULL, NULL, NULL, NULL); - /* msg 25: "STORE RDB$USER_PRIVILEGES failed defining a relation" */ - } - - DYN_rundown_request(old_env, request, -1); - if (id == drq_l_rel_name) - DYN_error_punt(TRUE, 24, NULL, NULL, NULL, NULL, NULL); - /* msg 24: "STORE RDB$RELATIONS failed" */ - else if (id == drq_l_view_rels) - DYN_error_punt(TRUE, 115, NULL, NULL, NULL, NULL, NULL); - /* msg 115: "CREATE VIEW failed" */ - - /* Control should never reach this point, because id should - always have one of the values test-for above. */ - assert(0); - DYN_error_punt(TRUE, 0, NULL, NULL, NULL, NULL, NULL); - } id = drq_l_rel_name; check_unique_name(tdbb, gbl, relation_name, FALSE); @@ -3211,6 +3327,33 @@ void DYN_define_relation( GBL gbl, UCHAR ** ptr) } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (id == drq_s_rels) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 24, NULL, NULL, NULL, NULL, NULL); + /* msg 24: "STORE RDB$RELATIONS failed" */ + } + else if (id == drq_s_usr_prvs) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 25, NULL, NULL, NULL, NULL, NULL); + /* msg 25: "STORE RDB$USER_PRIVILEGES failed defining a relation" */ + } + + DYN_rundown_request(old_env, request, -1); + if (id == drq_l_rel_name) + DYN_error_punt(TRUE, 24, NULL, NULL, NULL, NULL, NULL); + /* msg 24: "STORE RDB$RELATIONS failed" */ + else if (id == drq_l_view_rels) + DYN_error_punt(TRUE, 115, NULL, NULL, NULL, NULL, NULL); + /* msg 115: "CREATE VIEW failed" */ + + /* Control should never reach this point, because id should + always have one of the values test-for above. */ + assert(0); + DYN_error_punt(TRUE, 0, NULL, NULL, NULL, NULL, NULL); + } } @@ -3267,6 +3410,8 @@ void DYN_define_security_class( GBL gbl, UCHAR ** ptr) DYN_unsupported_verb(); } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -3317,21 +3462,10 @@ void DYN_define_sql_field(GBL gbl, request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - if (id == drq_s_sql_lfld) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 29, NULL, NULL, NULL, NULL, NULL); - /* msg 29: "STORE RDB$RELATION_FIELDS failed" */ - } - else { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 28, NULL, NULL, NULL, NULL, NULL); - /* msg 28: "STORE RDB$FIELDS failed" */ - } - } request = (BLK) CMP_find_request(tdbb, drq_s_sql_lfld, DYN_REQUESTS); id = drq_s_sql_lfld; @@ -3580,6 +3714,20 @@ void DYN_define_sql_field(GBL gbl, DYN_REQUEST(drq_s_sql_lfld) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (id == drq_s_sql_lfld) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 29, NULL, NULL, NULL, NULL, NULL); + /* msg 29: "STORE RDB$RELATION_FIELDS failed" */ + } + else { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 28, NULL, NULL, NULL, NULL, NULL); + /* msg 28: "STORE RDB$FIELDS failed" */ + } + } } @@ -3614,27 +3762,32 @@ void DYN_define_shadow( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_l_shadow, DYN_REQUESTS); - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { + try { + + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; + + FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + FIRST 1 X IN RDB$FILES WITH X.RDB$SHADOW_NUMBER EQ shadow_number + found = TRUE; + END_FOR; + + if (!DYN_REQUEST(drq_l_shadow)) { + DYN_REQUEST(drq_l_shadow) = request; + } + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { DYN_rundown_request(old_env, request, drq_l_shadow); DYN_error_punt(TRUE, 164, NULL, NULL, NULL, NULL, NULL); /* msg 164: "Shadow lookup failed" */ } - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - FIRST 1 X IN RDB$FILES WITH X.RDB$SHADOW_NUMBER EQ shadow_number - found = TRUE; - END_FOR; - - if (!DYN_REQUEST(drq_l_shadow)) - DYN_REQUEST(drq_l_shadow) = request; - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (found) + if (found) { DYN_error_punt(FALSE, 165, (TEXT *) shadow_number, NULL, NULL, NULL, NULL); + } /* msg 165: "Shadow %ld already exists" */ start = 0; @@ -3791,6 +3944,8 @@ void DYN_define_trigger( t, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -3879,6 +4034,8 @@ void DYN_define_trigger_msg( GBL gbl, UCHAR ** ptr, TEXT * trigger_name) DYN_unsupported_verb(); } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -3945,6 +4102,8 @@ void DYN_define_view_relation( GBL gbl, UCHAR ** ptr, TEXT * view) (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); } +#pragma FB_COMPILER_MESSAGE("TMN: FIXME! SETJMP across scope!") + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; if (SETJMP(env)) @@ -3989,10 +4148,46 @@ static void check_unique_name( request = NULL; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { + try { + + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; + + request = (BLK) CMP_find_request(tdbb, drq_l_rel_name, DYN_REQUESTS); + + found = FALSE; + FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + EREL IN RDB$RELATIONS WITH EREL.RDB$RELATION_NAME EQ object_name + if (!DYN_REQUEST(drq_l_rel_name)) + DYN_REQUEST(drq_l_rel_name) = request; + + found = TRUE; + END_FOR; + if (!DYN_REQUEST(drq_l_rel_name)) + DYN_REQUEST(drq_l_rel_name) = request; + + if (found) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + goto local_punt_false_132; + } + + request = (BLK) CMP_find_request(tdbb, drq_l_prc_name, DYN_REQUESTS); + + found = FALSE; + FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + EPRC IN RDB$PROCEDURES WITH EPRC.RDB$PROCEDURE_NAME EQ object_name + if (!DYN_REQUEST(drq_l_prc_name)) + DYN_REQUEST(drq_l_prc_name) = request; + + found = TRUE; + END_FOR; + if (!DYN_REQUEST(drq_l_prc_name)) + DYN_REQUEST(drq_l_prc_name) = request; + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { DYN_rundown_request(old_env, request, -1); if (!proc_flag) DYN_error_punt(TRUE, 24, NULL, NULL, NULL, NULL, NULL); @@ -4000,49 +4195,23 @@ static void check_unique_name( DYN_error_punt(TRUE, 134, NULL, NULL, NULL, NULL, NULL); } - request = (BLK) CMP_find_request(tdbb, drq_l_rel_name, DYN_REQUESTS); - - found = FALSE; - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - EREL IN RDB$RELATIONS WITH EREL.RDB$RELATION_NAME EQ object_name - if (!DYN_REQUEST(drq_l_rel_name)) - DYN_REQUEST(drq_l_rel_name) = request; - - found = TRUE; - END_FOR; - if (!DYN_REQUEST(drq_l_rel_name)) - DYN_REQUEST(drq_l_rel_name) = request; - if (found) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(FALSE, 132, object_name, NULL, NULL, NULL, NULL); + DYN_error_punt(FALSE, 135, object_name, NULL, NULL, NULL, NULL); } - request = (BLK) CMP_find_request(tdbb, drq_l_prc_name, DYN_REQUESTS); + return; - found = FALSE; - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - EPRC IN RDB$PROCEDURES WITH EPRC.RDB$PROCEDURE_NAME EQ object_name - if (!DYN_REQUEST(drq_l_prc_name)) - DYN_REQUEST(drq_l_prc_name) = request; - - found = TRUE; - END_FOR; - if (!DYN_REQUEST(drq_l_prc_name)) - DYN_REQUEST(drq_l_prc_name) = request; - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (found) - DYN_error_punt(FALSE, 135, object_name, NULL, NULL, NULL, NULL); +local_punt_false_132: + DYN_error_punt(FALSE, 132, object_name, NULL, NULL, NULL, NULL); } -static BOOLEAN find_field_source( - TDBB tdbb, - GBL gbl, - TEXT * view_name, - USHORT context, - TEXT * local_name, TEXT * field_name) +static BOOLEAN find_field_source(TDBB tdbb, + GBL gbl, + TEXT* view_name, + USHORT context, + TEXT* local_name, + TEXT* field_name) { /************************************** * @@ -4054,27 +4223,22 @@ static BOOLEAN find_field_source( * Find the original source for a view field. * **************************************/ - DBB dbb; + VOLATILE BLK request; BOOLEAN found; JMP_BUF env; JMP_BUF *VOLATILE old_env; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; request = (BLK) CMP_find_request(tdbb, drq_l_fld_src2, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 80, NULL, NULL, NULL, NULL, NULL); - /* msg 80: "Specified domain or source field does not exist" */ - } - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) VRL IN RDB$VIEW_RELATIONS CROSS @@ -4095,6 +4259,13 @@ static BOOLEAN find_field_source( tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 80, NULL, NULL, NULL, NULL, NULL); + /* msg 80: "Specified domain or source field does not exist" */ + } + return found; } @@ -4119,24 +4290,25 @@ static BOOLEAN get_who( TDBB tdbb, GBL gbl, SCHAR * name) request = (BLK) CMP_find_request(tdbb, drq_l_user_name, DYN_REQUESTS); - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; + try { - if (SETJMP(env)) - { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; + + if (!request) + { + request = (BLK) CMP_compile2(tdbb, const_cast(who_blr), TRUE); + } + EXE_start(tdbb, (REQ) request, gbl->gbl_transaction); + EXE_receive(tdbb, (REQ) request, 0, 32, (UCHAR*)name); + + DYN_rundown_request(old_env, request, drq_l_user_name); + } + catch (...) { DYN_rundown_request(old_env, request, drq_l_user_name); return FAILURE; } - if (!request) - { - request = (BLK) CMP_compile2(tdbb, const_cast(who_blr), TRUE); - } - EXE_start(tdbb, (REQ) request, gbl->gbl_transaction); - EXE_receive(tdbb, (REQ) request, 0, 32, (UCHAR*)name); - - DYN_rundown_request(old_env, request, drq_l_user_name); - return SUCCESS; } @@ -4164,15 +4336,10 @@ BOOLEAN is_it_user_name(GBL gbl, TEXT * role_name, TDBB tdbb) SET_TDBB(tdbb); dbb = tdbb->tdbb_database; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; /* save environment */ tdbb->tdbb_setjmp = (UCHAR *) env; /* get new environment */ - if (SETJMP(env)) - { - if (request) - DYN_rundown_request(old_env, request, request_id); - tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore old env */ - ERR_punt(); - } /* If there is a user with privilege or a grantor on a relation we can infer there is a user with this name */ @@ -4215,5 +4382,15 @@ BOOLEAN is_it_user_name(GBL gbl, TEXT * role_name, TDBB tdbb) DYN_REQUEST(drq_get_rel_owner) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore environment */ + + } + catch (...) { + if (request) { + DYN_rundown_request(old_env, request, request_id); + } + tdbb->tdbb_setjmp = (UCHAR *) old_env; /* restore old env */ + ERR_punt(); + } + return found; } diff --git a/src/jrd/dyn_del.epp b/src/jrd/dyn_del.epp index 69590bf0ee..bd20eb09c7 100644 --- a/src/jrd/dyn_del.epp +++ b/src/jrd/dyn_del.epp @@ -166,15 +166,11 @@ void DYN_delete_exception( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_e_xcp, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 143, NULL, NULL, NULL, NULL, NULL); - /* msg 143: "ERASE EXCEPTION failed" */ - } - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) X IN RDB$EXCEPTIONS @@ -190,9 +186,17 @@ void DYN_delete_exception( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (!found) + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 143, NULL, NULL, NULL, NULL, NULL); + /* msg 143: "ERASE EXCEPTION failed" */ + } + + if (!found) { DYN_error_punt(FALSE, 144, NULL, NULL, NULL, NULL, NULL); - /* msg 144: "Exception not found" */ + /* msg 144: "Exception not found" */ + } } @@ -221,15 +225,11 @@ void DYN_delete_filter( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_e_filters, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 36, NULL, NULL, NULL, NULL, NULL); - /* msg 36: "ERASE BLOB FILTER failed" */ - } - GET_STRING(ptr, f); found = FALSE; @@ -246,12 +246,21 @@ void DYN_delete_filter( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (!found) - DYN_error_punt(FALSE, 37, NULL, NULL, NULL, NULL, NULL); - /* msg 37: "Blob Filter not found" */ + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 36, NULL, NULL, NULL, NULL, NULL); + /* msg 36: "ERASE BLOB FILTER failed" */ + } - if (*(*ptr)++ != gds_dyn_end) + if (!found) { + DYN_error_punt(FALSE, 37, NULL, NULL, NULL, NULL, NULL); + /* msg 37: "Blob Filter not found" */ + } + + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } } @@ -281,19 +290,11 @@ void DYN_delete_function( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_e_func_args, DYN_REQUESTS); id = drq_e_func_args; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - if (id == drq_e_func_args) - DYN_error_punt(TRUE, 39, NULL, NULL, NULL, NULL, NULL); - /* msg 39: "ERASE RDB$FUNCTION_ARGUMENTS failed" */ - else - DYN_error_punt(TRUE, 40, NULL, NULL, NULL, NULL, NULL); - /* msg 40: "ERASE RDB$FUNCTIONS failed" */ - } - GET_STRING(ptr, f); FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) @@ -323,12 +324,30 @@ void DYN_delete_function( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (!found) - DYN_error_punt(FALSE, 41, NULL, NULL, NULL, NULL, NULL); - /* msg 41: "Function not found" */ + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + if (id == drq_e_func_args) + { + DYN_error_punt(TRUE, 39, NULL, NULL, NULL, NULL, NULL); + /* msg 39: "ERASE RDB$FUNCTION_ARGUMENTS failed" */ + } + else + { + DYN_error_punt(TRUE, 40, NULL, NULL, NULL, NULL, NULL); + /* msg 40: "ERASE RDB$FUNCTIONS failed" */ + } + } - if (*(*ptr)++ != gds_dyn_end) + if (!found) + { + DYN_error_punt(FALSE, 41, NULL, NULL, NULL, NULL, NULL); + /* msg 41: "Function not found" */ + } + + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } } @@ -358,19 +377,11 @@ void DYN_delete_global_field( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_l_fld_src, DYN_REQUESTS); id = drq_l_fld_src; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - if (id == drq_l_fld_src) - DYN_error_punt(TRUE, 44, NULL, NULL, NULL, NULL, NULL); - /* msg 44: "ERASE RDB$FIELDS failed" */ - else - DYN_error_punt(TRUE, 45, NULL, NULL, NULL, NULL, NULL); - /* msg 45: "ERASE RDB$FIELDS failed" */ - } - GET_STRING(ptr, f); FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) @@ -407,6 +418,21 @@ void DYN_delete_global_field( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + if (id == drq_l_fld_src) + { + DYN_error_punt(TRUE, 44, NULL, NULL, NULL, NULL, NULL); + /* msg 44: "ERASE RDB$FIELDS failed" */ + } + else + { + DYN_error_punt(TRUE, 45, NULL, NULL, NULL, NULL, NULL); + /* msg 45: "ERASE RDB$FIELDS failed" */ + } + } + if (!found) { DYN_error_punt(FALSE, 46, NULL, NULL, NULL, NULL, NULL); /* msg 46: "Field not found" */ @@ -414,7 +440,13 @@ void DYN_delete_global_field( GBL gbl, UCHAR ** ptr) while (*(*ptr)++ != gds_dyn_end) { --(*ptr); - DYN_execute(gbl, ptr, (TEXT*)NULL_PTR, f, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); + DYN_execute(gbl, + ptr, + (TEXT*)NULL_PTR, + f, + (TEXT*)NULL_PTR, + (TEXT*)NULL_PTR, + (TEXT*)NULL_PTR); } } @@ -444,15 +476,11 @@ void DYN_delete_index( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_e_indices, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 47, NULL, NULL, NULL, NULL, NULL); - /* msg 47: "ERASE RDB$INDICES failed" */ - } - GET_STRING(ptr, i); found = FALSE; @@ -470,17 +498,34 @@ void DYN_delete_index( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 47, NULL, NULL, NULL, NULL, NULL); + /* msg 47: "ERASE RDB$INDICES failed" */ + } + if (!found) + { DYN_error_punt(FALSE, 48, NULL, NULL, NULL, NULL, NULL); - /* msg 48: "Index not found" */ + /* msg 48: "Index not found" */ + } if (!delete_index_segment_records(gbl, i)) + { DYN_error_punt(FALSE, 50, NULL, NULL, NULL, NULL, NULL); - /* msg 50: "No segments found for index" */ + /* msg 50: "No segments found for index" */ + } while (*(*ptr)++ != gds_dyn_end) { --(*ptr); - DYN_execute(gbl, ptr, r, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); + DYN_execute(gbl, + ptr, + r, + (TEXT*)NULL_PTR, + (TEXT*)NULL_PTR, + (TEXT*)NULL_PTR, + (TEXT*)NULL_PTR); } } @@ -529,7 +574,7 @@ void DYN_delete_local_field( DBB dbb; BLK request, old_request; VOLATILE USHORT id, found; - TEXT tbl_nm[32], col_nm[32], i[32], constraint[32], index_name[32]; + TEXT tbl_nm[32], col_nm[32], constraint[32], index_name[32]; JMP_BUF env, *old_env; tdbb = GET_THREAD_DATA; @@ -549,19 +594,11 @@ void DYN_delete_local_field( request = (BLK) CMP_find_request(tdbb, drq_l_dep_flds, DYN_REQUESTS); id = drq_l_dep_flds; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - if (id == drq_l_dep_flds) - DYN_error_punt(TRUE, 53, NULL, NULL, NULL, NULL, NULL); - /* msg 53: "ERASE RDB$RELATION_FIELDS failed" */ - else - DYN_error_punt(TRUE, 54, NULL, NULL, NULL, NULL, NULL); - /* msg 54: "ERASE RDB$RELATION_FIELDS failed" */ - } - /* ** ================================================================ ** == @@ -712,17 +749,30 @@ void DYN_delete_local_field( RFR.RDB$FIELD_SOURCE, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); } END_FOR; - if (!DYN_REQUEST(drq_e_lfield)) + if (!DYN_REQUEST(drq_e_lfield)) { DYN_REQUEST(drq_e_lfield) = request; + } + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + if (id == drq_l_dep_flds) + { + DYN_error_punt(TRUE, 53, NULL, NULL, NULL, NULL, NULL); + /* msg 53: "ERASE RDB$RELATION_FIELDS failed" */ + } + else + { + DYN_error_punt(TRUE, 54, NULL, NULL, NULL, NULL, NULL); + /* msg 54: "ERASE RDB$RELATION_FIELDS failed" */ + } + } if (!found) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; DYN_error_punt(FALSE, 55, NULL, NULL, NULL, NULL, NULL); + /* msg 55: "Field not found for relation" */ } - /* msg 55: "Field not found for relation" */ - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - } @@ -739,38 +789,28 @@ void DYN_delete_parameter( GBL gbl, UCHAR ** ptr, TEXT * proc_name) * deletes a stored procedure parameter. * **************************************/ - TDBB tdbb; - DBB dbb; + BLK old_request, request; VOLATILE USHORT old_id, id, found; TEXT name[32]; JMP_BUF env, *old_env; GET_STRING(ptr, name); - if (**ptr == gds_dyn_prc_name) + if (**ptr == gds_dyn_prc_name) { DYN_get_string((TEXT**)++ptr, proc_name, PROC_NAME_SIZE, TRUE); + } - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; request = (BLK) CMP_find_request(tdbb, drq_e_prm, DYN_REQUESTS); id = drq_e_prms; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - if (id == drq_e_prms) { - DYN_error_punt(TRUE, 138, NULL, NULL, NULL, NULL, NULL); - /* msg 138: "ERASE RDB$PROCEDURE_PARAMETERS failed" */ - } - else { - DYN_error_punt(TRUE, 35, NULL, NULL, NULL, NULL, NULL); - /* msg 35: "ERASE RDB$FIELDS failed" */ - } - } - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) PP IN RDB$PROCEDURE_PARAMETERS WITH PP.RDB$PROCEDURE_NAME EQ proc_name @@ -806,16 +846,33 @@ void DYN_delete_parameter( GBL gbl, UCHAR ** ptr, TEXT * proc_name) ERASE PP; END_FOR; - if (!DYN_REQUEST(drq_e_prm)) + if (!DYN_REQUEST(drq_e_prm)) { DYN_REQUEST(drq_e_prm) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (!found) - DYN_error_punt(FALSE, 146, name, proc_name, NULL, NULL, NULL); - /* msg 146: "Parameter %s in procedure %s not found" */ - if (*(*ptr)++ != gds_dyn_end) + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + if (id == drq_e_prms) { + DYN_error_punt(TRUE, 138, NULL, NULL, NULL, NULL, NULL); + /* msg 138: "ERASE RDB$PROCEDURE_PARAMETERS failed" */ + } + else { + DYN_error_punt(TRUE, 35, NULL, NULL, NULL, NULL, NULL); + /* msg 35: "ERASE RDB$FIELDS failed" */ + } + } + + if (!found) { + DYN_error_punt(FALSE, 146, name, proc_name, NULL, NULL, NULL); + /* msg 146: "Parameter %s in procedure %s not found" */ + } + + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } } @@ -856,27 +913,11 @@ void DYN_delete_procedure( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_e_prms, DYN_REQUESTS); id = drq_e_prms; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - DYN_rundown_request(old_env, request, -1); - if (id == drq_e_prms) - DYN_error_punt(TRUE, 138, NULL, NULL, NULL, NULL, NULL); - /* msg 138: "ERASE RDB$PROCEDURE_PARAMETERS failed" */ - else if (id == drq_e_prcs) - DYN_error_punt(TRUE, 139, NULL, NULL, NULL, NULL, NULL); - /* msg 139: "ERASE RDB$PROCEDURES failed" */ - else if (id == drq_d_gfields) - DYN_error_punt(TRUE, 35, NULL, NULL, NULL, NULL, NULL); - /* msg 35: "ERASE RDB$FIELDS failed" */ - else - DYN_error_punt(TRUE, 62, NULL, NULL, NULL, NULL, NULL); - /* msg 62: "ERASE RDB$USER_PRIVILEGES failed" */ - } - - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) PP IN RDB$PROCEDURE_PARAMETERS WITH PP.RDB$PROCEDURE_NAME EQ name @@ -911,8 +952,9 @@ void DYN_delete_procedure( GBL gbl, UCHAR ** ptr) ERASE PP; END_FOR; - if (!DYN_REQUEST(drq_e_prms)) + if (!DYN_REQUEST(drq_e_prms)) { DYN_REQUEST(drq_e_prms) = request; + } request = (BLK) CMP_find_request(tdbb, drq_e_prcs, DYN_REQUESTS); id = drq_e_prcs; @@ -921,23 +963,25 @@ void DYN_delete_procedure( GBL gbl, UCHAR ** ptr) FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) P IN RDB$PROCEDURES WITH P.RDB$PROCEDURE_NAME EQ name - if (!DYN_REQUEST(drq_e_prcs)) + if (!DYN_REQUEST(drq_e_prcs)) { DYN_REQUEST(drq_e_prcs) = request; + } - if (!P.RDB$SECURITY_CLASS.NULL) + if (!P.RDB$SECURITY_CLASS.NULL) { delete_security_class2(gbl, P.RDB$SECURITY_CLASS); + } ERASE P; found = TRUE; END_FOR; - if (!DYN_REQUEST(drq_e_prcs)) + if (!DYN_REQUEST(drq_e_prcs)) { DYN_REQUEST(drq_e_prcs) = request; + } if (!found) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(FALSE, 140, name, NULL, NULL, NULL, NULL); - /* msg 140: "Procedure %s not found" */ + goto dyn_punt_140; } request = (BLK) CMP_find_request(tdbb, drq_e_prc_prvs, DYN_REQUESTS); @@ -958,8 +1002,40 @@ void DYN_delete_procedure( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (*(*ptr)++ != gds_dyn_end) + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + if (id == drq_e_prms) + { + DYN_error_punt(TRUE, 138, NULL, NULL, NULL, NULL, NULL); + /* msg 138: "ERASE RDB$PROCEDURE_PARAMETERS failed" */ + } + else if (id == drq_e_prcs) + { + DYN_error_punt(TRUE, 139, NULL, NULL, NULL, NULL, NULL); + /* msg 139: "ERASE RDB$PROCEDURES failed" */ + } + else if (id == drq_d_gfields) + { + DYN_error_punt(TRUE, 35, NULL, NULL, NULL, NULL, NULL); + /* msg 35: "ERASE RDB$FIELDS failed" */ + } + else + { + DYN_error_punt(TRUE, 62, NULL, NULL, NULL, NULL, NULL); + /* msg 62: "ERASE RDB$USER_PRIVILEGES failed" */ + } + } + + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } + + return; + +dyn_punt_140: + DYN_error_punt(FALSE, 140, name, NULL, NULL, NULL, NULL); + /* msg 140: "Procedure %s not found" */ } @@ -981,7 +1057,7 @@ void DYN_delete_relation( GBL gbl, UCHAR ** ptr, TEXT * relation) DBB dbb; BLK request; VOLATILE USHORT id, found; - TEXT relation_name[32], security_class[32]; + TEXT relation_name[32]; JMP_BUF env, *old_env; tdbb = GET_THREAD_DATA; @@ -995,43 +1071,11 @@ void DYN_delete_relation( GBL gbl, UCHAR ** ptr, TEXT * relation) request = (BLK) CMP_find_request(tdbb, drq_e_rel_con2, DYN_REQUESTS); id = drq_e_rel_con2; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - if (id == drq_e_rel_con2) - DYN_error_punt(TRUE, 129, NULL, NULL, NULL, NULL, NULL); - /* msg 129: "ERASE RDB$RELATION_CONSTRAINTS failed" */ - else if (id == drq_e_rel_idxs) - DYN_error_punt(TRUE, 57, NULL, NULL, NULL, NULL, NULL); - /* msg 57: "ERASE RDB$INDICES failed" */ - else if (id == drq_e_trg_msgs2) - DYN_error_punt(TRUE, 65, NULL, NULL, NULL, NULL, NULL); - /* msg 65: "ERASE RDB$TRIGGER_MESSAGES failed" */ - else if (id == drq_e_trigger2) - DYN_error_punt(TRUE, 66, NULL, NULL, NULL, NULL, NULL); - /* msg 66: "ERASE RDB$TRIGGERS failed" */ - else if (id == drq_e_rel_flds) - DYN_error_punt(TRUE, 58, NULL, NULL, NULL, NULL, NULL); - /* msg 58: "ERASE RDB$RELATION_FIELDS failed" */ - else if (id == drq_e_view_rels) - DYN_error_punt(TRUE, 59, NULL, NULL, NULL, NULL, NULL); - /* msg 59: "ERASE RDB$VIEW_RELATIONS failed" */ - else if (id == drq_e_relation) - DYN_error_punt(TRUE, 60, NULL, NULL, NULL, NULL, NULL); - /* msg 60: "ERASE RDB$RELATIONS failed" */ - else if (id == drq_e_rel_con2) - DYN_error_punt(TRUE, 129, NULL, NULL, NULL, NULL, NULL); - /* msg 129: "ERASE RDB$RELATION_CONSTRAINTS failed" */ - else if (id == drq_e_sec_class) - DYN_error_punt(TRUE, 74, NULL, NULL, NULL, NULL, NULL); - /* msg 74: "ERASE RDB$SECURITY_CLASSES failed" */ - else - DYN_error_punt(TRUE, 62, NULL, NULL, NULL, NULL, NULL); - /* msg 62: "ERASE RDB$USER_PRIVILEGES failed" */ - } - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) CRT IN RDB$RELATION_CONSTRAINTS WITH CRT.RDB$RELATION_NAME EQ relation_name AND @@ -1141,8 +1185,7 @@ void DYN_delete_relation( GBL gbl, UCHAR ** ptr, TEXT * relation) if (!found) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(FALSE, 61, NULL, NULL, NULL, NULL, NULL); - /* msg 61: "Relation not found" */ + goto dyn_punt_61; } request = (BLK) CMP_find_request(tdbb, drq_e_rel_con3, DYN_REQUESTS); @@ -1195,16 +1238,59 @@ void DYN_delete_relation( GBL gbl, UCHAR ** ptr, TEXT * relation) ERASE PRIV; END_FOR; - if (!DYN_REQUEST(drq_e_usr_prvs)) + if (!DYN_REQUEST(drq_e_usr_prvs)) { DYN_REQUEST(drq_e_usr_prvs) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; - while (*(*ptr)++ != gds_dyn_end) { + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + + // lookup error # from id + // msg 57: "ERASE RDB$INDICES failed" + // msg 58: "ERASE RDB$RELATION_FIELDS failed" + // msg 59: "ERASE RDB$VIEW_RELATIONS failed" + // msg 60: "ERASE RDB$RELATIONS failed" + // msg 62: "ERASE RDB$USER_PRIVILEGES failed" + // msg 65: "ERASE RDB$TRIGGER_MESSAGES failed" + // msg 66: "ERASE RDB$TRIGGERS failed" + // msg 74: "ERASE RDB$SECURITY_CLASSES failed" + // msg 129: "ERASE RDB$RELATION_CONSTRAINTS failed" + USHORT number; + switch (id) { + case drq_e_rel_con2: number = 129; break; + case drq_e_rel_idxs: number = 57; break; + case drq_e_trg_msgs2: number = 65; break; + case drq_e_trigger2: number = 66; break; + case drq_e_rel_flds: number = 58; break; + case drq_e_view_rels: number = 59; break; + case drq_e_relation: number = 60; break; + case drq_e_sec_class: number = 74; break; + default: number = 62; break; + } + + DYN_error_punt(TRUE, number, NULL, NULL, NULL, NULL, NULL); + } + + while (*(*ptr)++ != gds_dyn_end) + { --(*ptr); - DYN_execute(gbl, ptr, relation_name, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR, + DYN_execute(gbl, + ptr, + relation_name, + (TEXT*)NULL_PTR, + (TEXT*)NULL_PTR, + (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); } + + return; + +dyn_punt_61: + DYN_error_punt(FALSE, 61, NULL, NULL, NULL, NULL, NULL); + /* msg 61: "Relation not found" */ } @@ -1271,15 +1357,11 @@ files = NULL; request = (BLK) CMP_find_request(tdbb, drq_e_shadow, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 63, NULL, NULL, NULL, NULL, NULL); - /* msg 63: "ERASE RDB$FILES failed" */ - } - shadow_number = DYN_get_number(ptr); FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) FIL IN RDB$FILES WITH FIL.RDB$SHADOW_NUMBER EQ shadow_number @@ -1289,7 +1371,7 @@ files = NULL; ERASE FIL; /**** - file = (STR) ALLOCDV (type_str, sizeof (FIL.RDB$FILE_NAME) - 1); + file = new(*tdbb->tdbb_default, sizeof (FIL.RDB$FILE_NAME) - 1) str(); strcpy (file->str_data, FIL.RDB$FILE_NAME); LLS_PUSH (file, &files); ****/ @@ -1300,6 +1382,13 @@ files = NULL; tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 63, NULL, NULL, NULL, NULL, NULL); + /* msg 63: "ERASE RDB$FILES failed" */ + } + /**** while (files) { @@ -1309,8 +1398,9 @@ while (files) } ****/ - if (*(*ptr)++ != gds_dyn_end) + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } } @@ -1340,22 +1430,11 @@ void DYN_delete_trigger( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_e_trg_msgs, DYN_REQUESTS); id = drq_e_trg_msgs; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - if (id == drq_e_trg_msgs) - DYN_error_punt(TRUE, 65, NULL, NULL, NULL, NULL, NULL); - /* msg 65: "ERASE RDB$TRIGGER_MESSAGES failed" */ - else if (id == drq_e_trigger) - DYN_error_punt(TRUE, 66, NULL, NULL, NULL, NULL, NULL); - /* msg 66: "ERASE RDB$TRIGGERS failed" */ - else - DYN_error_punt(TRUE, 68, NULL, NULL, NULL, NULL, NULL); - /* msg 68: "MODIFY RDB$VIEW_RELATIONS failed" */ - } - GET_STRING(ptr, t); FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) @@ -1390,8 +1469,7 @@ void DYN_delete_trigger( GBL gbl, UCHAR ** ptr) if (!found) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(FALSE, 67, NULL, NULL, NULL, NULL, NULL); - /* msg 67: "Trigger not found" */ + goto dyn_punt_67; } /* clear the update flags on the fields if this is the last remaining @@ -1438,8 +1516,35 @@ void DYN_delete_trigger( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (*(*ptr)++ != gds_dyn_end) + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + if (id == drq_e_trg_msgs) + { + DYN_error_punt(TRUE, 65, NULL, NULL, NULL, NULL, NULL); + /* msg 65: "ERASE RDB$TRIGGER_MESSAGES failed" */ + } + else if (id == drq_e_trigger) + { + DYN_error_punt(TRUE, 66, NULL, NULL, NULL, NULL, NULL); + /* msg 66: "ERASE RDB$TRIGGERS failed" */ + } + else + { + DYN_error_punt(TRUE, 68, NULL, NULL, NULL, NULL, NULL); + /* msg 68: "MODIFY RDB$VIEW_RELATIONS failed" */ + } + } + + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } + + return; + +dyn_punt_67: + DYN_error_punt(FALSE, 67, NULL, NULL, NULL, NULL, NULL); + /* msg 67: "Trigger not found" */ } @@ -1478,15 +1583,11 @@ void DYN_delete_trigger_msg( GBL gbl, UCHAR ** ptr, TEXT * trigger_name) request = (BLK) CMP_find_request(tdbb, drq_e_trg_msg, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 71, NULL, NULL, NULL, NULL, NULL); - /* msg 71: "ERASE TRIGGER MESSAGE failed" */ - } - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) X IN RDB$TRIGGER_MESSAGES @@ -1504,19 +1605,28 @@ void DYN_delete_trigger_msg( GBL gbl, UCHAR ** ptr, TEXT * trigger_name) tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (!found) - DYN_error_punt(FALSE, 72, NULL, NULL, NULL, NULL, NULL); - /* msg 72: "Trigger Message not found" */ + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 71, NULL, NULL, NULL, NULL, NULL); + /* msg 71: "ERASE TRIGGER MESSAGE failed" */ + } - if (*(*ptr)++ != gds_dyn_end) + if (!found) + { + DYN_error_punt(FALSE, 72, NULL, NULL, NULL, NULL, NULL); + /* msg 72: "Trigger Message not found" */ + } + + if (*(*ptr)++ != gds_dyn_end) { DYN_unsupported_verb(); + } } -static BOOLEAN delete_constraint_records( - GBL gbl, - TEXT * constraint_name, - TEXT * relation_name) +static BOOLEAN delete_constraint_records(GBL gbl, + TEXT* constraint_name, + TEXT* relation_name) { /************************************** * @@ -1540,15 +1650,11 @@ static BOOLEAN delete_constraint_records( request = (BLK) CMP_find_request(tdbb, drq_e_rel_con, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 129, NULL, NULL, NULL, NULL, NULL); - /* msg 129: "ERASE RDB$RELATION_CONSTRAINTS failed" */ - } - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) RC IN RDB$RELATION_CONSTRAINTS @@ -1567,11 +1673,18 @@ static BOOLEAN delete_constraint_records( tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 129, NULL, NULL, NULL, NULL, NULL); + /* msg 129: "ERASE RDB$RELATION_CONSTRAINTS failed" */ + } + return found; } -static BOOLEAN delete_dimension_records( GBL gbl, TEXT * field_name) +static BOOLEAN delete_dimension_records(GBL gbl, TEXT* field_name) { /************************************** * @@ -1595,41 +1708,44 @@ static BOOLEAN delete_dimension_records( GBL gbl, TEXT * field_name) request = (BLK) CMP_find_request(tdbb, drq_e_dims, DYN_REQUESTS); - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; + try { - if (SETJMP(env)) { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; + tdbb->tdbb_setjmp = (UCHAR *) env; + + found = FALSE; + FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + X IN RDB$FIELD_DIMENSIONS WITH X.RDB$FIELD_NAME EQ field_name + + if (!DYN_REQUEST(drq_e_dims)) + DYN_REQUEST(drq_e_dims) = request; + + found = TRUE; + ERASE X; + END_FOR; + + if (!DYN_REQUEST(drq_e_dims)) + DYN_REQUEST(drq_e_dims) = request; + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { DYN_rundown_request(old_env, request, -1); DYN_error_punt(TRUE, 35, NULL, NULL, NULL, NULL, NULL); /* msg 35: "ERASE RDB$FIELDS failed" */ } - found = FALSE; - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - X IN RDB$FIELD_DIMENSIONS WITH X.RDB$FIELD_NAME EQ field_name - - if (!DYN_REQUEST(drq_e_dims)) - DYN_REQUEST(drq_e_dims) = request; - - found = TRUE; - ERASE X; - END_FOR; - - if (!DYN_REQUEST(drq_e_dims)) - DYN_REQUEST(drq_e_dims) = request; - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - return found; } -static void delete_f_key_constraint( - TDBB tdbb, - GBL gbl, - TEXT * tbl_nm, - TEXT * col_nm, - TEXT * constraint_nm, TEXT * index_name) +static void delete_f_key_constraint(TDBB tdbb, + GBL gbl, + TEXT* tbl_nm, + TEXT* col_nm, + TEXT* constraint_nm, + TEXT* index_name) { /************************************** * @@ -1663,7 +1779,6 @@ static void delete_f_key_constraint( DBB dbb; BLK request; BOOLEAN found; - VOLATILE USHORT id; JMP_BUF env, *old_env; SET_TDBB(tdbb); @@ -1671,39 +1786,42 @@ static void delete_f_key_constraint( request = (BLK) CMP_find_request(tdbb, drq_e_rel_const, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { + found = FALSE; + FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + RC IN RDB$RELATION_CONSTRAINTS + WITH RC.RDB$CONSTRAINT_NAME EQ constraint_nm + AND RC.RDB$CONSTRAINT_TYPE EQ FOREIGN_KEY + AND RC.RDB$RELATION_NAME EQ tbl_nm + AND RC.RDB$INDEX_NAME EQ index_name + + if (!DYN_REQUEST(drq_e_rel_const)) + DYN_REQUEST(drq_e_rel_const) = request; + + found = TRUE; + ERASE RC; + END_FOR; + + if (!DYN_REQUEST(drq_e_rel_const)) + DYN_REQUEST(drq_e_rel_const) = request; + + if (!found) + { + DYN_error_punt(FALSE, 130, constraint_nm, NULL, NULL, NULL, NULL); + /* msg 130: "CONSTRAINT %s does not exist." */ + } + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { DYN_rundown_request(old_env, request, -1); DYN_error_punt(TRUE, 129, NULL, NULL, NULL, NULL, NULL); /* msg 49: "ERASE RDB$RELATION_CONSTRAINTS failed" */ } - - found = FALSE; - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - RC IN RDB$RELATION_CONSTRAINTS - WITH RC.RDB$CONSTRAINT_NAME EQ constraint_nm - AND RC.RDB$CONSTRAINT_TYPE EQ FOREIGN_KEY - AND RC.RDB$RELATION_NAME EQ tbl_nm - AND RC.RDB$INDEX_NAME EQ index_name - - if (!DYN_REQUEST(drq_e_rel_const)) - DYN_REQUEST(drq_e_rel_const) = request; - - found = TRUE; - ERASE RC; - END_FOR; - - if (!DYN_REQUEST(drq_e_rel_const)) - DYN_REQUEST(drq_e_rel_const) = request; - - if (!found) - DYN_error_punt(FALSE, 130, constraint_nm, NULL, NULL, NULL, NULL); - /* msg 130: "CONSTRAINT %s does not exist." */ - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - } @@ -1776,30 +1894,33 @@ static BOOLEAN delete_index_segment_records( GBL gbl, TEXT * index_name) request = (BLK) CMP_find_request(tdbb, drq_e_idx_segs, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { + + found = FALSE; + FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) + I_S IN RDB$INDEX_SEGMENTS WITH I_S.RDB$INDEX_NAME EQ index_name + + if (!DYN_REQUEST(drq_e_idx_segs)) + DYN_REQUEST(drq_e_idx_segs) = request; + + found = TRUE; + ERASE I_S; + END_FOR; + + if (!DYN_REQUEST(drq_e_idx_segs)) + DYN_REQUEST(drq_e_idx_segs) = request; + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { DYN_rundown_request(old_env, request, -1); DYN_error_punt(TRUE, 49, NULL, NULL, NULL, NULL, NULL); /* msg 49: "ERASE RDB$INDEX_SEGMENTS failed" */ } - found = FALSE; - FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - I_S IN RDB$INDEX_SEGMENTS WITH I_S.RDB$INDEX_NAME EQ index_name - - if (!DYN_REQUEST(drq_e_idx_segs)) - DYN_REQUEST(drq_e_idx_segs) = request; - - found = TRUE; - ERASE I_S; - END_FOR; - - if (!DYN_REQUEST(drq_e_idx_segs)) - DYN_REQUEST(drq_e_idx_segs) = request; - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - return found; } @@ -1817,27 +1938,21 @@ static BOOLEAN delete_security_class2( GBL gbl, TEXT * security_class) * which takes a string as input. * **************************************/ - TDBB tdbb; - DBB dbb; - BLK request; - BOOLEAN found; + JMP_BUF env, *old_env; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; - request = (BLK) CMP_find_request(tdbb, drq_e_class, DYN_REQUESTS); + BLK request = (BLK) CMP_find_request(tdbb, drq_e_class, DYN_REQUESTS); + + BOOLEAN found = FALSE; + + try { old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 74, NULL, NULL, NULL, NULL, NULL); - /* msg 74: "ERASE RDB$SECURITY_CLASSES failed" */ - } - - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) SC IN RDB$SECURITY_CLASSES WITH SC. RDB$SECURITY_CLASS EQ security_class @@ -1850,10 +1965,18 @@ static BOOLEAN delete_security_class2( GBL gbl, TEXT * security_class) END_FOR; - if (!DYN_REQUEST(drq_e_class)) + if (!DYN_REQUEST(drq_e_class)) { DYN_REQUEST(drq_e_class) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 74, NULL, NULL, NULL, NULL, NULL); + /* msg 74: "ERASE RDB$SECURITY_CLASSES failed" */ + } + return found; } diff --git a/src/jrd/dyn_mod.epp b/src/jrd/dyn_mod.epp index 4ec677ff7d..c6063d574b 100644 --- a/src/jrd/dyn_mod.epp +++ b/src/jrd/dyn_mod.epp @@ -126,21 +126,16 @@ void DYN_modify_database( GBL gbl, UCHAR ** ptr) request = NULL; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 84, NULL, NULL, NULL, NULL, NULL); - /* msg 84: "MODIFY DATABASE failed" */ - } - INF_database_info((SCHAR*)alloc_info, sizeof(alloc_info), (SCHAR*)s, sizeof(s)); if (s[0] != gds_info_allocation) { tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(TRUE, 84, NULL, NULL, NULL, NULL, NULL); - /* msg 84: "MODIFY DATABASE failed" */ + goto dyn_punt_84; } request = (BLK) CMP_find_request(tdbb, drq_m_database, DYN_REQUESTS); @@ -260,6 +255,19 @@ void DYN_modify_database( GBL gbl, UCHAR ** ptr) DYN_REQUEST(drq_m_database) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 84, NULL, NULL, NULL, NULL, NULL); + /* msg 84: "MODIFY DATABASE failed" */ + } + + return; + +dyn_punt_84: + DYN_error_punt(TRUE, 84, NULL, NULL, NULL, NULL, NULL); + /* msg 84: "MODIFY DATABASE failed" */ } @@ -288,15 +296,11 @@ void DYN_modify_exception( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_m_xcp, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 145, NULL, NULL, NULL, NULL, NULL); - /* msg 145: "MODIFY EXCEPTION failed" */ - } - GET_STRING(ptr, t); found = FALSE; @@ -334,9 +338,18 @@ void DYN_modify_exception( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 145, NULL, NULL, NULL, NULL, NULL); + /* msg 145: "MODIFY EXCEPTION failed" */ + } + if (!found) + { DYN_error_punt(FALSE, 144, NULL, NULL, NULL, NULL, NULL); - /* msg 144: "Exception not found" */ + /* msg 144: "Exception not found" */ + } } @@ -365,9 +378,16 @@ void DYN_modify_global_field( DYN_FLD orig_dom, new_dom; BOOLEAN dtype, scale, prec, subtype, charlen, collation, fldlen, nullflg, charset; - TEXT *qryname, *qryhdr, *qryhdr2, *edtstr, *edtstr2, *missingval, - *singvald, *fldvald, *fldvaldsrc, *fldvaldsrc2, *desc, *desc2, - *delvald, *deldflt, *flddftval, *flddfltsrc; + TEXT *qryname, *qryhdr, *edtstr, *missingval, + *fldvald, *fldvaldsrc, *desc, + *flddftval, *flddfltsrc; + +#if (defined JPN_SJIS || defined JPN_EUC) + TEXT* edtstr2; + TEXT* qryhdr2; + TEXT* desc2; + TEXT* fldvaldsrc2; +#endif BOOLEAN bqryname, bqryhdr, bqryhdr2, bedtstr, bedtstr2, bmissingval, bsingvald, bfldvald, bfldvaldsrc, bfldvaldsrc2, bdesc, bdesc2, @@ -387,31 +407,23 @@ void DYN_modify_global_field( request = (BLK) CMP_find_request(tdbb, drq_m_gfield, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - if (orig_dom) - gds__free((SLONG *) orig_dom); - - if (new_dom) - gds__free((SLONG *) new_dom); - - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 87, NULL, NULL, NULL, NULL, NULL); - /* msg 87: "MODIFY RDB$FIELDS failed" */ - } - /* Allocate the field structures */ orig_dom = (DYN_FLD) gds__alloc(sizeof(struct dyn_fld)); - if (!orig_dom) + if (!orig_dom) { DYN_error_punt(TRUE, 211, NULL, NULL, NULL, NULL, NULL); + } MOVE_CLEAR(orig_dom, sizeof(struct dyn_fld)); new_dom = (DYN_FLD) gds__alloc(sizeof(struct dyn_fld)); - if (!new_dom) + if (!new_dom) { DYN_error_punt(TRUE, 211, NULL, NULL, NULL, NULL, NULL); + } MOVE_CLEAR(new_dom, sizeof(struct dyn_fld)); @@ -910,9 +922,26 @@ void DYN_modify_global_field( tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + if (orig_dom) { + gds__free((SLONG *) orig_dom); + } + + if (new_dom) { + gds__free((SLONG *) new_dom); + } + + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 87, NULL, NULL, NULL, NULL, NULL); + /* msg 87: "MODIFY RDB$FIELDS failed" */ + } + if (!found) + { DYN_error_punt(FALSE, 89, NULL, NULL, NULL, NULL, NULL); - /* msg 89: "Global field not found" */ + /* msg 89: "Global field not found" */ + } } @@ -941,15 +970,11 @@ void DYN_modify_index( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_m_index, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 91, NULL, NULL, NULL, NULL, NULL); - /* msg 91: "MODIFY RDB$INDICES failed" */ - } - GET_STRING(ptr, name); found = FALSE; @@ -1006,9 +1031,18 @@ void DYN_modify_index( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 91, NULL, NULL, NULL, NULL, NULL); + /* msg 91: "MODIFY RDB$INDICES failed" */ + } + if (!found) + { DYN_error_punt(FALSE, 93, NULL, NULL, NULL, NULL, NULL); - /* msg 93: "Index field not found" */ + /* msg 93: "Index field not found" */ + } } @@ -1129,15 +1163,11 @@ void DYN_modify_local_field( request = (BLK) CMP_find_request(tdbb, drq_m_lfield, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 95, NULL, NULL, NULL, NULL, NULL); - /* msg 95: "MODIFY RDB$RELATION_FIELDS failed" */ - } - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) FLD IN RDB$RELATION_FIELDS @@ -1235,9 +1265,18 @@ void DYN_modify_local_field( tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 95, NULL, NULL, NULL, NULL, NULL); + /* msg 95: "MODIFY RDB$RELATION_FIELDS failed" */ + } + if (!found) + { DYN_error_punt(FALSE, 96, NULL, NULL, NULL, NULL, NULL); - /* msg 96: "Local column not found" */ + /* msg 96: "Local column not found" */ + } } @@ -1268,13 +1307,10 @@ void DYN_modify_procedure( GBL gbl, UCHAR ** ptr) request = NULL; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 141, NULL, NULL, NULL, NULL, NULL); - /* msg 141: "MODIFY RDB$PROCEDURES failed" */ - } request = (BLK) CMP_find_request(tdbb, drq_m_prcs, DYN_REQUESTS); @@ -1346,9 +1382,18 @@ void DYN_modify_procedure( GBL gbl, UCHAR ** ptr) DYN_REQUEST(drq_m_prcs) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (!found) + + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 141, NULL, NULL, NULL, NULL, NULL); + /* msg 141: "MODIFY RDB$PROCEDURES failed" */ + } + + if (!found) { DYN_error_punt(FALSE, 140, procedure_name, NULL, NULL, NULL, NULL); - /* msg 140: "Procedure %s not found" */ + /* msg 140: "Procedure %s not found" */ + } } @@ -1380,15 +1425,11 @@ void DYN_modify_relation( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_m_relation, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 99, NULL, NULL, NULL, NULL, NULL); - /* msg 99: "MODIFY RDB$RELATIONS failed" */ - } - found = FALSE; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) REL IN RDB$RELATIONS WITH REL.RDB$RELATION_NAME EQ name @@ -1457,9 +1498,18 @@ void DYN_modify_relation( GBL gbl, UCHAR ** ptr) tdbb->tdbb_setjmp = (UCHAR *) old_env; + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 99, NULL, NULL, NULL, NULL, NULL); + /* msg 99: "MODIFY RDB$RELATIONS failed" */ + } + if (!found) + { DYN_error_punt(FALSE, 101, NULL, NULL, NULL, NULL, NULL); - /* msg 101: "Relation field not found" */ + /* msg 101: "Relation field not found" */ + } } @@ -1488,15 +1538,11 @@ void DYN_modify_trigger( GBL gbl, UCHAR ** ptr) request = (BLK) CMP_find_request(tdbb, drq_m_trigger, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 102, NULL, NULL, NULL, NULL, NULL); - /* msg 102: "MODIFY TRIGGER failed" */ - } - GET_STRING(ptr, trigger_name); source = NULL; blr = NULL; @@ -1505,8 +1551,9 @@ void DYN_modify_trigger( GBL gbl, UCHAR ** ptr) FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) X IN RDB$TRIGGERS WITH X.RDB$TRIGGER_NAME EQ trigger_name - if (!DYN_REQUEST(drq_m_trigger)) + if (!DYN_REQUEST(drq_m_trigger)) { DYN_REQUEST(drq_m_trigger) = request; + } found = TRUE; MODIFY X @@ -1583,9 +1630,18 @@ void DYN_modify_trigger( GBL gbl, UCHAR ** ptr) DYN_REQUEST(drq_m_trigger) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (!found) + + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 102, NULL, NULL, NULL, NULL, NULL); + /* msg 102: "MODIFY TRIGGER failed" */ + } + + if (!found) { DYN_error_punt(FALSE, 147, trigger_name, NULL, NULL, NULL, NULL); - /* msg 147: "Trigger %s not found" */ + /* msg 147: "Trigger %s not found" */ + } } @@ -1614,15 +1670,11 @@ void DYN_modify_trigger_msg( GBL gbl, UCHAR ** ptr, TEXT * trigger_name) request = (BLK) CMP_find_request(tdbb, drq_m_trg_msg, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 105, NULL, NULL, NULL, NULL, NULL); - /* msg 105: "MODIFY TRIGGER MESSAGE failed" */ - } - number = DYN_get_number(ptr); if (trigger_name) strcpy(t, trigger_name); @@ -1670,6 +1722,13 @@ void DYN_modify_trigger_msg( GBL gbl, UCHAR ** ptr, TEXT * trigger_name) DYN_REQUEST(drq_m_trg_msg) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 105, NULL, NULL, NULL, NULL, NULL); + /* msg 105: "MODIFY TRIGGER MESSAGE failed" */ + } } @@ -1696,13 +1755,10 @@ static void drop_cache( GBL gbl) request = (BLK) CMP_find_request(tdbb, drq_d_cache, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, drq_s_cache); - DYN_error_punt(TRUE, 63, NULL, NULL, NULL, NULL, NULL); - /* msg 63: ERASE RDB$FILE failed */ - } FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) X IN RDB$FILES WITH X.RDB$FILE_FLAGS EQ FILE_cache @@ -1712,13 +1768,24 @@ static void drop_cache( GBL gbl) END_FOR; - if (!DYN_REQUEST(drq_d_cache)) + if (!DYN_REQUEST(drq_d_cache)) { DYN_REQUEST(drq_d_cache) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + DYN_rundown_request(old_env, request, drq_s_cache); + DYN_error_punt(TRUE, 63, NULL, NULL, NULL, NULL, NULL); + /* msg 63: ERASE RDB$FILE failed */ + } + if (!found) + { DYN_error_punt(FALSE, 149, NULL, NULL, NULL, NULL, NULL); - /* msg 149: "Shared cache file not found" */ + /* msg 149: "Shared cache file not found" */ + } } @@ -1745,13 +1812,10 @@ static void drop_log( GBL gbl) request = (BLK) CMP_find_request(tdbb, drq_d_log, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, drq_d_log); - DYN_error_punt(TRUE, 153, NULL, NULL, NULL, NULL, NULL); - /* msg 153: ERASE RDB$LOG_FILE failed */ - } FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) X IN RDB$LOG_FILES @@ -1764,9 +1828,19 @@ static void drop_log( GBL gbl) DYN_REQUEST(drq_d_log) = request; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + DYN_rundown_request(old_env, request, drq_d_log); + DYN_error_punt(TRUE, 153, NULL, NULL, NULL, NULL, NULL); + /* msg 153: ERASE RDB$LOG_FILE failed */ + } + if (!found) + { DYN_error_punt(FALSE, 152, NULL, NULL, NULL, NULL, NULL); - /* msg 152: "Write ahead log not found" */ + /* msg 152: "Write ahead log not found" */ + } } static void modify_lfield_position(TDBB tdbb, @@ -1809,14 +1883,11 @@ static void modify_lfield_position(TDBB tdbb, JMP_BUF env, *old_env; BOOLEAN move_down = FALSE; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_error_punt(TRUE, 95, NULL, NULL, NULL, NULL, NULL); - /* msg 95: "MODIFY RDB$RELATION_FIELDS failed" */ - } - /* Find the position of the last field in the relation */ DYN_UTIL_generate_field_position(tdbb, gbl, relation_name, &max_position); @@ -1883,6 +1954,12 @@ static void modify_lfield_position(TDBB tdbb, CMP_release(tdbb, (REQ)request); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + DYN_error_punt(TRUE, 95, NULL, NULL, NULL, NULL, NULL); + /* msg 95: "MODIFY RDB$RELATION_FIELDS failed" */ + } } static BOOLEAN check_view_dependency(TDBB tdbb, @@ -2115,27 +2192,14 @@ void DYN_modify_sql_field(GBL gbl, tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; dtype = scale = prec = subtype = charlen = collation = fldlen = nullflg = charset = FALSE; - if (SETJMP(env)) { - if (new_fld) - gds__free((SLONG *) new_fld); - - if (dom_fld) - gds__free((SLONG *) dom_fld); - - if (orig_fld) - gds__free((SLONG *) orig_fld); - - tdbb->tdbb_setjmp = (UCHAR *) old_env; - DYN_error_punt(TRUE, 95, NULL, NULL, NULL, NULL, NULL); - /* msg 95: "MODIFY RDB$RELATION_FIELDS failed" */ - } - /* Allocate the field structures */ orig_fld = (DYN_FLD) gds__alloc(sizeof(struct dyn_fld)); if (!orig_fld) @@ -2494,6 +2558,25 @@ void DYN_modify_sql_field(GBL gbl, gds__free((SLONG *) orig_fld); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + if (new_fld) { + gds__free((SLONG *) new_fld); + } + + if (dom_fld) { + gds__free((SLONG *) dom_fld); + } + + if (orig_fld) { + gds__free((SLONG *) orig_fld); + } + + tdbb->tdbb_setjmp = (UCHAR *) old_env; + DYN_error_punt(TRUE, 95, NULL, NULL, NULL, NULL, NULL); + /* msg 95: "MODIFY RDB$RELATION_FIELDS failed" */ + } } void get_domain_type(TDBB tdbb, DBB dbb, GBL gbl, DYN_FLD dom_fld) diff --git a/src/jrd/dyn_util.epp b/src/jrd/dyn_util.epp index bfd132eb39..e1c82f4341 100644 --- a/src/jrd/dyn_util.epp +++ b/src/jrd/dyn_util.epp @@ -194,11 +194,8 @@ void DYN_UTIL_generate_constraint_name( TDBB tdbb, GBL gbl, TEXT * buffer) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 131, NULL, NULL, NULL, NULL, NULL); - /* msg 131: "Generation of constraint name failed" */ - } + + try { do { id = drq_g_nxt_con; @@ -228,6 +225,13 @@ void DYN_UTIL_generate_constraint_name( TDBB tdbb, GBL gbl, TEXT * buffer) } while (found); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 131, NULL, NULL, NULL, NULL, NULL); + /* msg 131: "Generation of constraint name failed" */ + } } @@ -256,13 +260,10 @@ void DYN_UTIL_generate_field_name( TDBB tdbb, GBL gbl, TEXT * buffer) request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 81, NULL, NULL, NULL, NULL, NULL); - /* msg 81: "Generation of field name failed" */ - } do { id = drq_g_nxt_fld; @@ -291,6 +292,13 @@ void DYN_UTIL_generate_field_name( TDBB tdbb, GBL gbl, TEXT * buffer) } while (found); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 81, NULL, NULL, NULL, NULL, NULL); + /* msg 81: "Generation of field name failed" */ + } } @@ -323,13 +331,10 @@ void DYN_UTIL_generate_field_position( request = NULL; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, -1); - DYN_error_punt(TRUE, 162, NULL, NULL, NULL, NULL, NULL); - /* msg 162: "Looking up field position failed" */ - } request = (BLK) CMP_find_request(tdbb, drq_l_fld_pos, DYN_REQUESTS); @@ -348,11 +353,17 @@ void DYN_UTIL_generate_field_position( tdbb->tdbb_setjmp = (UCHAR *) old_env; *field_pos = field_position; + + } // try + catch (...) { + DYN_rundown_request(old_env, request, -1); + DYN_error_punt(TRUE, 162, NULL, NULL, NULL, NULL, NULL); + /* msg 162: "Looking up field position failed" */ + } } -void DYN_UTIL_generate_index_name( - TDBB tdbb, +void DYN_UTIL_generate_index_name(TDBB tdbb, GBL gbl, TEXT * buffer, UCHAR verb) { /************************************** @@ -379,15 +390,11 @@ void DYN_UTIL_generate_index_name( request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 82, NULL, NULL, NULL, NULL, NULL); - /* msg 82: "Generation of index name failed" */ - } - do { if (verb == gds_dyn_def_primary_key) format = "RDB$PRIMARY%" QUADFORMAT "d"; @@ -421,6 +428,13 @@ void DYN_UTIL_generate_index_name( } while (found); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 82, NULL, NULL, NULL, NULL, NULL); + /* msg 82: "Generation of index name failed" */ + } } @@ -449,15 +463,11 @@ void DYN_UTIL_generate_trigger_name( TDBB tdbb, GBL gbl, TEXT * buffer) request = NULL; id = -1; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, id); - DYN_error_punt(TRUE, 83, NULL, NULL, NULL, NULL, NULL); - /* msg 83: "Generation of trigger name failed" */ - } - do { id = drq_g_nxt_trg; sprintf(buffer, "CHECK_%" QUADFORMAT "d", @@ -485,6 +495,13 @@ void DYN_UTIL_generate_trigger_name( TDBB tdbb, GBL gbl, TEXT * buffer) } while (found); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + DYN_rundown_request(old_env, request, id); + DYN_error_punt(TRUE, 83, NULL, NULL, NULL, NULL, NULL); + /* msg 83: "Generation of trigger name failed" */ + } } @@ -518,18 +535,11 @@ BOOLEAN DYN_UTIL_get_prot(TDBB tdbb, request = CMP_find_request(tdbb, drq_l_prot_mask, DYN_REQUESTS); + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - /* Note that the following cast to BLK not only changes - * the type, it also casts away volatile! - */ - DYN_rundown_request(old_env, (BLK)request, drq_l_prot_mask); - return FAILURE; - } - if (!request) { request = CMP_compile2(tdbb, @@ -550,6 +560,13 @@ BOOLEAN DYN_UTIL_get_prot(TDBB tdbb, (BLK)request, drq_l_prot_mask); + } // try + catch (...) { + // Note that the following cast to BLK not only changes + // the type, it also casts away volatile! + DYN_rundown_request(old_env, (BLK)request, drq_l_prot_mask); + return FAILURE; + } return SUCCESS; } @@ -578,6 +595,8 @@ void DYN_UTIL_store_check_constraints(TDBB tdbb, request = (BLK) CMP_find_request(tdbb, drq_s_chk_con, DYN_REQUESTS); + try { + STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) CHK IN RDB$CHECK_CONSTRAINTS strcpy(CHK.RDB$CONSTRAINT_NAME, constraint_name); @@ -585,15 +604,18 @@ void DYN_UTIL_store_check_constraints(TDBB tdbb, old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - DYN_rundown_request(old_env, request, drq_s_chk_con); - DYN_error_punt(TRUE, 122, NULL, NULL, NULL, NULL, NULL); - /* msg 122: "STORE RDB$CHECK_CONSTRAINTS failed" */ - } END_STORE; - if (!DYN_REQUEST(drq_s_chk_con)) + if (!DYN_REQUEST(drq_s_chk_con)) { DYN_REQUEST(drq_s_chk_con) = request; + } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + DYN_rundown_request(old_env, request, drq_s_chk_con); + DYN_error_punt(TRUE, 122, NULL, NULL, NULL, NULL, NULL); + /* msg 122: "STORE RDB$CHECK_CONSTRAINTS failed" */ + } } diff --git a/src/jrd/entry.h b/src/jrd/entry.h index 653f3a0782..e7f37b13f4 100644 --- a/src/jrd/entry.h +++ b/src/jrd/entry.h @@ -54,164 +54,252 @@ #if 0 && defined(__cplusplus) -ENTRYPOINT("gds_attach_database", - jrd8_attach_database, +ENTRYPOINT( "gds_attach_database", + jrd8_attach_database, "jrd5_attach_database", - REM_attach_database, + REM_attach_database, "_REM_attach_database", - CSI_attach_database, - RDB_attach_database, - PSI_attach_database, - PSI5_attach_database, - "_jrd8_attach_database", - IPI_attach_database, - (STATUS *, SSHORT, SCHAR *, struct att **, SSHORT, SCHAR *, - SCHAR *)) + CSI_attach_database, + RDB_attach_database, + PSI_attach_database, + PSI5_attach_database, + "_jrd8_attach_database", + IPI_attach_database, + (STATUS*, SSHORT, SCHAR*, struct att**, SSHORT, SCHAR*,SCHAR*)) - ENTRYPOINT("gds_blob_info", jrd8_blob_info, "jrd5_blob_info", REM_blob_info, - "_REM_blob_info", CSI_blob_info, RDB_blob_info, PSI_blob_info, - PSI5_blob_info, "_jrd8_blob_info", IPI_blob_info, (STATUS *, - struct blb - **, SSHORT, - SCHAR *, - SSHORT, - SCHAR *)) +ENTRYPOINT( "gds_blob_info", + jrd8_blob_info, + "jrd5_blob_info", + REM_blob_info, + "_REM_blob_info", + CSI_blob_info, + RDB_blob_info, + PSI_blob_info, + PSI5_blob_info, + "_jrd8_blob_info", + IPI_blob_info, + (STATUS*, struct blb**, SSHORT, SCHAR*, SSHORT, SCHAR*)) - ENTRYPOINT("gds_cancel_blob", jrd8_cancel_blob, "jrd5_cancel_blob", - REM_cancel_blob, "_REM_cancel_blob", CSI_cancel_blob, - RDB_cancel_blob, PSI_cancel_blob, PSI5_cancel_blob, - "_jrd8_cancel_blob", IPI_cancel_blob, (STATUS *, - struct blb **)) +ENTRYPOINT( "gds_cancel_blob", + jrd8_cancel_blob, + "jrd5_cancel_blob", + REM_cancel_blob, + "_REM_cancel_blob", + CSI_cancel_blob, + RDB_cancel_blob, + PSI_cancel_blob, + PSI5_cancel_blob, + "_jrd8_cancel_blob", + IPI_cancel_blob, + (STATUS*, struct blb**)) - ENTRYPOINT("gds_close_blob", jrd8_close_blob, "jrd5_close_blob", - REM_close_blob, "_REM_close_blob", CSI_close_blob, RDB_close_blob, - PSI_close_blob, PSI5_close_blob, "_jrd8_close_blob", - IPI_close_blob, (STATUS *, struct blb **)) +ENTRYPOINT( "gds_close_blob", + jrd8_close_blob, + "jrd5_close_blob", + REM_close_blob, + "_REM_close_blob", + CSI_close_blob, + RDB_close_blob, + PSI_close_blob, + PSI5_close_blob, + "_jrd8_close_blob", + IPI_close_blob, + (STATUS*, struct blb**)) - ENTRYPOINT("gds_commit_transaction", jrd8_commit_transaction, - "jrd5_commit_transaction", REM_commit_transaction, - "_REM_commit_transaction", CSI_commit_transaction, - RDB_commit_transaction, PSI_commit_transaction, - PSI5_commit_transaction, "_jrd8_commit_transaction", - IPI_commit_transaction, (STATUS *, struct tra **)) +ENTRYPOINT( "gds_commit_transaction", + jrd8_commit_transaction, + "jrd5_commit_transaction", + REM_commit_transaction, + "_REM_commit_transaction", + CSI_commit_transaction, + RDB_commit_transaction, + PSI_commit_transaction, + PSI5_commit_transaction, + "_jrd8_commit_transaction", + IPI_commit_transaction, + (STATUS*, struct tra**)) - ENTRYPOINT("gds_compile_request", jrd8_compile_request, - "jrd5_compile_request", REM_compile_request, - "_REM_compile_request", CSI_compile_request, RDB_compile_request, -PSI_compile_request, PSI5_compile_request, "_jrd8_compile_request", IPI_compile_request, (STATUS *, - struct att **, - struct req **, - SSHORT, SCHAR *)) +ENTRYPOINT( "gds_compile_request", + jrd8_compile_request, + "jrd5_compile_request", + REM_compile_request, + "_REM_compile_request", + CSI_compile_request, + RDB_compile_request, + PSI_compile_request, + PSI5_compile_request, + "_jrd8_compile_request", + IPI_compile_request, + (STATUS*, struct att**, struct req**, SSHORT, SCHAR*)) - ENTRYPOINT("gds_create_blob", +ENTRYPOINT( "gds_create_blob", /**** jrd8_create_blob ***/ y_valve_no_entrypoint, /**** "jrd5_create_blob" ***/ NULL, /**** REM_create_blob ***/ y_valve_no_entrypoint, - "_REM_create_blob", + "_REM_create_blob", /**** CSI_create_blob ***/ y_valve_no_entrypoint, - RDB_create_blob, PSI_create_blob, PSI5_create_blob, + RDB_create_blob, + PSI_create_blob, + PSI5_create_blob, /**** "_jrd8_create_blob" ***/ "no_entrypoint", - IPI_create_blob, - (STATUS *, struct rdb **, struct rtr **, struct rbl **, - struct bid *)) + IPI_create_blob, + (STATUS*, struct rdb**, struct rtr**, struct rbl**, struct bid*)) - ENTRYPOINT("gds_create_database", jrd8_create_database, +ENTRYPOINT( "gds_create_database", + jrd8_create_database, /**** "jrd5_create_database" ***/ NULL, - REM_create_database, - "_REM_create_database", - CSI_create_database, RDB_create_database, PSI_create_database, + REM_create_database, + "_REM_create_database", + CSI_create_database, + RDB_create_database, + PSI_create_database, /**** PSI5_create_database ***/ y_valve_no_entrypoint, - "_jrd8_create_database", - IPI_create_database, - (STATUS *, USHORT, UCHAR *, struct att **, USHORT, UCHAR *, - USHORT, UCHAR *)) + "_jrd8_create_database", + IPI_create_database, + (STATUS*, USHORT, UCHAR*, struct att**, USHORT, UCHAR*, USHORT, UCHAR*)) - ENTRYPOINT("gds_database_info", jrd8_database_info, "jrd5_database_info", - REM_database_info, "_REM_database_info", CSI_database_info, - RDB_database_info, PSI_database_info, PSI5_database_info, - "_jrd8_database_info", IPI_database_info, (STATUS *, - struct att **, - SSHORT, SCHAR *, - SSHORT, SCHAR *)) +ENTRYPOINT( "gds_database_info", + jrd8_database_info, + "jrd5_database_info", + REM_database_info, + "_REM_database_info", + CSI_database_info, + RDB_database_info, + PSI_database_info, + PSI5_database_info, + "_jrd8_database_info", + IPI_database_info, + (STATUS*, struct att**, SSHORT, SCHAR*, SSHORT, SCHAR*)) - ENTRYPOINT("gds_detach_database", jrd8_detach_database, - "jrd5_detach_database", REM_detach_database, - "_REM_detach_database", CSI_detach_database, RDB_detach_database, -PSI_detach_database, PSI5_detach_database, "_jrd8_detach_database", IPI_detach_database, (STATUS *, - struct att **)) +ENTRYPOINT( "gds_detach_database", + jrd8_detach_database, + "jrd5_detach_database", + REM_detach_database, + "_REM_detach_database", + CSI_detach_database, + RDB_detach_database, + PSI_detach_database, + PSI5_detach_database, + "_jrd8_detach_database", + IPI_detach_database, + (STATUS*, struct att**)) - ENTRYPOINT("gds_get_segment", jrd8_get_segment, "jrd5_get_segment", - REM_get_segment, "_REM_get_segment", CSI_get_segment, - RDB_get_segment, PSI_get_segment, PSI5_get_segment, - "_jrd8_get_segment", IPI_get_segment, (STATUS *, struct blb **, - USHORT *, USHORT, - UCHAR *)) +ENTRYPOINT( "gds_get_segment", + jrd8_get_segment, + "jrd5_get_segment", + REM_get_segment, + "_REM_get_segment", + CSI_get_segment, + RDB_get_segment, + PSI_get_segment, + PSI5_get_segment, + "_jrd8_get_segment", + IPI_get_segment, + (STATUS*, struct blb**, USHORT*, USHORT, UCHAR*)) - ENTRYPOINT("gds_open_blob", +ENTRYPOINT( "gds_open_blob", /**** jrd8_open_blob ***/ y_valve_no_entrypoint, /**** "jrd5_open_blob" ***/ NULL, /**** REM_open_blob ***/ y_valve_no_entrypoint, - "_REM_open_blob", + "_REM_open_blob", /**** CSI_open_blob ***/ y_valve_no_entrypoint, - RDB_open_blob, PSI_open_blob, PSI5_open_blob, + RDB_open_blob, + PSI_open_blob, + PSI5_open_blob, /**** "_jrd8_open_blob" ***/ "no_entrypoint", - IPI_open_blob, - (STATUS *, struct rdb **, struct rtr **, struct rbl **, - struct bid *)) + IPI_open_blob, + (STATUS*, struct rdb**, struct rtr**, struct rbl**, struct bid*)) - ENTRYPOINT("gds_prepare_transaction", jrd8_prepare_transaction, - "jrd5_prepare_transaction", REM_prepare_transaction, - "_REM_prepare_transaction", CSI_prepare_transaction, - RDB_prepare_transaction, PSI_prepare_transaction, - PSI5_prepare_transaction, "_jrd8_prepare_transaction", - IPI_prepare_transaction, (STATUS *, struct tra **, USHORT, - UCHAR *)) +ENTRYPOINT( "gds_prepare_transaction", + jrd8_prepare_transaction, + "jrd5_prepare_transaction", + REM_prepare_transaction, + "_REM_prepare_transaction", + CSI_prepare_transaction, + RDB_prepare_transaction, + PSI_prepare_transaction, + PSI5_prepare_transaction, + "_jrd8_prepare_transaction", + IPI_prepare_transaction, + (STATUS*, struct tra**, USHORT, UCHAR*)) - ENTRYPOINT("gds_put_segment", jrd8_put_segment, "jrd5_put_segment", - REM_put_segment, "_REM_put_segment", CSI_put_segment, - RDB_put_segment, PSI_put_segment, PSI5_put_segment, - "_jrd8_put_segment", IPI_put_segment, (STATUS *, struct blb **, - USHORT, UCHAR *)) +ENTRYPOINT( "gds_put_segment", + jrd8_put_segment, + "jrd5_put_segment", + REM_put_segment, + "_REM_put_segment", + CSI_put_segment, + RDB_put_segment, + PSI_put_segment, + PSI5_put_segment, + "_jrd8_put_segment", + IPI_put_segment, + (STATUS*, struct blb**, USHORT, UCHAR*)) - ENTRYPOINT("gds_reconnect_transaction", jrd8_reconnect_transaction, - "jrd5_reconnect_transaction", REM_reconnect_transaction, - "_REM_reconnect_transaction", CSI_reconnect_transaction, - RDB_reconnect_transaction, PSI_reconnect_transaction, - PSI5_reconnect_transaction, "_jrd8_reconnect_transaction", - IPI_reconnect_transaction, (STATUS *, struct att **, - struct tra **, SSHORT, UCHAR *)) +ENTRYPOINT( "gds_reconnect_transaction", + jrd8_reconnect_transaction, + "jrd5_reconnect_transaction", + REM_reconnect_transaction, + "_REM_reconnect_transaction", + CSI_reconnect_transaction, + RDB_reconnect_transaction, + PSI_reconnect_transaction, + PSI5_reconnect_transaction, + "_jrd8_reconnect_transaction", + IPI_reconnect_transaction, + (STATUS*, struct att**, struct tra**, SSHORT, UCHAR*)) - ENTRYPOINT("gds_receive", jrd8_receive, "jrd5_receive", REM_receive, - "_REM_receive", CSI_receive, RDB_receive, PSI_receive, PSI5_receive, /* the bridge pipe server will have two less params, but should be OK */ - "_jrd8_receive", IPI_receive, (STATUS *, struct req **, USHORT, - USHORT, SCHAR *, SSHORT)) +ENTRYPOINT( "gds_receive", + jrd8_receive, + "jrd5_receive", + REM_receive, + "_REM_receive", + CSI_receive, + RDB_receive, + PSI_receive, + PSI5_receive, /* the bridge pipe server will have two less params, but should be OK */ + "_jrd8_receive", + IPI_receive, + (STATUS*, struct req**, USHORT, USHORT, SCHAR*, SSHORT)) - ENTRYPOINT("gds_release_request", jrd8_release_request, - "jrd5_release_request", REM_release_request, - "_REM_release_request", CSI_release_request, RDB_release_request, -PSI_release_request, PSI5_release_request, "_jrd8_release_request", IPI_release_request, (STATUS *, - struct req **)) +ENTRYPOINT( "gds_release_request", + jrd8_release_request, + "jrd5_release_request", + REM_release_request, + "_REM_release_request", + CSI_release_request, + RDB_release_request, + PSI_release_request, + PSI5_release_request, + "_jrd8_release_request", + IPI_release_request, + (STATUS*, struct req**)) - ENTRYPOINT("gds_request_info", jrd8_request_info, "jrd5_request_info", - REM_request_info, "_REM_request_info", CSI_request_info, - RDB_request_info, PSI_request_info, PSI5_request_info, - "_jrd8_request_info", IPI_request_info, (STATUS *, - struct req **, SSHORT, - SSHORT, SCHAR *, - SSHORT, SCHAR *)) +ENTRYPOINT( "gds_request_info", + jrd8_request_info, + "jrd5_request_info", + REM_request_info, + "_REM_request_info", + CSI_request_info, + RDB_request_info, + PSI_request_info, + PSI5_request_info, + "_jrd8_request_info", + IPI_request_info, + (STATUS*, struct req**, SSHORT, SSHORT, SCHAR*, SSHORT, SCHAR*)) - ENTRYPOINT("gds_rollback_transaction", jrd8_rollback_transaction, +ENTRYPOINT("gds_rollback_transaction", jrd8_rollback_transaction, "jrd5_rollback_transaction", REM_rollback_transaction, "_REM_rollback_transaction", CSI_rollback_transaction, RDB_rollback_transaction, PSI_rollback_transaction, PSI5_rollback_transaction, "_jrd8_rollback_transaction", IPI_rollback_transaction, (STATUS *, struct tra **)) - ENTRYPOINT("gds_send", jrd8_send, "jrd5_send", REM_send, "_REM_send", +ENTRYPOINT("gds_send", jrd8_send, "jrd5_send", REM_send, "_REM_send", CSI_send, RDB_send, PSI_send, PSI5_send, "_jrd8_send", IPI_send, (STATUS *, struct req **, USHORT, USHORT, SCHAR *, SSHORT)) - ENTRYPOINT("gds_start_and_send", jrd8_start_and_send, "jrd5_start_and_send", +ENTRYPOINT("gds_start_and_send", jrd8_start_and_send, "jrd5_start_and_send", REM_start_and_send, "_REM_start_and_send", CSI_start_and_send, RDB_start_and_send, PSI_start_and_send, PSI5_start_and_send, "_jrd8_start_and_send", IPI_start_and_send, (STATUS *, @@ -220,7 +308,7 @@ PSI_release_request, PSI5_release_request, "_jrd8_release_request", IPI_release_ USHORT, USHORT, SCHAR *, SSHORT)) - ENTRYPOINT("gds_start_request", jrd8_start_request, "jrd5_start_request", +ENTRYPOINT("gds_start_request", jrd8_start_request, "jrd5_start_request", REM_start_request, "_REM_start_request", CSI_start_request, RDB_start_request, PSI_start_request, PSI5_start_request, "_jrd8_start_request", IPI_start_request, (STATUS *, @@ -229,321 +317,373 @@ PSI_release_request, PSI5_release_request, "_jrd8_release_request", IPI_release_ register struct tra **, SSHORT)) - ENTRYPOINT("gds_start_multiple", jrd8_start_multiple, "jrd5_start_multiple", +ENTRYPOINT( "gds_start_multiple", + jrd8_start_multiple, + "jrd5_start_multiple", /**** REM_start_multiple ***/ y_valve_no_entrypoint, - "_REM_start_multiple", - CSI_start_multiple, - RDB_start_multiple, - PSI_start_multiple, - PSI5_start_multiple, - "_jrd8_start_multiple", - IPI_start_multiple, - (STATUS *, struct tra **, USHORT, struct teb *)) + "_REM_start_multiple", + CSI_start_multiple, + RDB_start_multiple, + PSI_start_multiple, + PSI5_start_multiple, + "_jrd8_start_multiple", + IPI_start_multiple, + (STATUS *, struct tra **, USHORT, struct teb *)) - ENTRYPOINT("gds_start_transaction", +ENTRYPOINT("gds_start_transaction", jrd8_start_transaction, "jrd5_start_transaction", -REM_start_transaction, -"_REM_start_transaction", -CSI_start_transaction, -RDB_start_transaction, -PSI_start_transaction, -PSI5_start_transaction, -"_jrd8_start_transaction", IPI_start_transaction, (STATUS *, struct tra **, SSHORT,...)) + REM_start_transaction, + "_REM_start_transaction", + CSI_start_transaction, + RDB_start_transaction, + PSI_start_transaction, + PSI5_start_transaction, + "_jrd8_start_transaction", + IPI_start_transaction, + (STATUS*, struct tra**, SSHORT, ...)) - ENTRYPOINT("gds_transaction_info", - jrd8_transaction_info, +ENTRYPOINT( "gds_transaction_info", + jrd8_transaction_info, "jrd5_transaction_info", -REM_transaction_info, -"_REM_transaction_info", -CSI_transaction_info, -RDB_transaction_info, -PSI_transaction_info, -PSI5_transaction_info, -"_jrd8_transaction_info", -IPI_transaction_info, (STATUS *, struct tra **, SSHORT, SCHAR *, SSHORT, SCHAR *)) + REM_transaction_info, + "_REM_transaction_info", + CSI_transaction_info, + RDB_transaction_info, + PSI_transaction_info, + PSI5_transaction_info, + "_jrd8_transaction_info", + IPI_transaction_info, + (STATUS*, struct tra**, SSHORT, SCHAR*, SSHORT, SCHAR*)) - ENTRYPOINT("gds_unwind_request", +ENTRYPOINT("gds_unwind_request", jrd8_unwind_request, "jrd5_unwind_request", REM_unwind_request, "_REM_unwind_request", -CSI_unwind_request, -RDB_unwind_request, -PSI_unwind_request, -PSI5_unwind_request, -"_jrd8_unwind_request", IPI_unwind_request, (STATUS *, struct req **, SSHORT)) + CSI_unwind_request, + RDB_unwind_request, + PSI_unwind_request, + PSI5_unwind_request, + "_jrd8_unwind_request", + IPI_unwind_request, + (STATUS*, struct req**, SSHORT)) - ENTRYPOINT("gds_commit_retaining", +ENTRYPOINT("gds_commit_retaining", jrd8_commit_retaining, "jrd5_commit_retaining", -REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, + REM_commit_retaining, + "_REM_commit_retaining", + CSI_commit_retaining, /**** RDB_commit_retaining ***/ y_valve_no_entrypoint, - PSI_commit_retaining, - PSI5_commit_retaining, - "_jrd8_commit_retaining", - IPI_commit_retaining, (STATUS *, struct tra **)) + PSI_commit_retaining, + PSI5_commit_retaining, + "_jrd8_commit_retaining", + IPI_commit_retaining, + (STATUS *, struct tra **)) - ENTRYPOINT("gds_que_events", +ENTRYPOINT("gds_que_events", jrd8_que_events, "jrd5_que_events", - REM_que_events, "_REM_que_events", CSI_que_events, + REM_que_events, + "_REM_que_events", + CSI_que_events, /**** RDB_que_events ***/ y_valve_no_entrypoint, PSI_que_events, PSI5_que_events, "_jrd8_que_events", IPI_que_events, - (STATUS *, struct att **, SLONG *, SSHORT, UCHAR *, FPTR_VOID, - void *)) + (STATUS*, struct att**, SLONG*, SSHORT, UCHAR*, FPTR_VOID, + void*)) - ENTRYPOINT("gds_cancel_events", jrd8_cancel_events, "jrd5_cancel_events", - REM_cancel_events, "_REM_cancel_events", CSI_cancel_events, +ENTRYPOINT("gds_cancel_events", + jrd8_cancel_events, + "jrd5_cancel_events", + REM_cancel_events, + "_REM_cancel_events", + CSI_cancel_events, /**** RDB_cancel_events ***/ y_valve_no_entrypoint, PSI_cancel_events, PSI5_cancel_events, "_jrd8_cancel_events", - IPI_cancel_events, (STATUS *, struct att **, SLONG *)) + IPI_cancel_events, + (STATUS*, struct att**, SLONG*)) - ENTRYPOINT("gds_ddl", jrd8_ddl, +ENTRYPOINT("gds_ddl", + jrd8_ddl, /**** "jrd5_ddl" ***/ NULL, - REM_ddl, "_REM_ddl", CSI_ddl, + REM_ddl, + "_REM_ddl", + CSI_ddl, /**** RDB_ddl ***/ y_valve_no_entrypoint, PSI_ddl, PSI5_ddl, "_jrd8_ddl", IPI_ddl, - (STATUS *, struct att **, struct tra **, USHORT, SCHAR *)) + (STATUS*, struct att**, struct tra**, USHORT, SCHAR*)) - ENTRYPOINT("gds_open_blob2", +ENTRYPOINT("gds_open_blob2", jrd8_open_blob2, "jrd5_open_blob2", - REM_open_blob2, "_REM_open_blob2", CSI_open_blob2, + REM_open_blob2, + "_REM_open_blob2", + CSI_open_blob2, /**** RDB_open_blob2 ***/ y_valve_no_entrypoint, PSI_open_blob2, PSI5_open_blob2, "_jrd8_open_blob2", IPI_open_blob2, - (STATUS *, struct att **, struct tra **, struct blb **, - struct bid *, USHORT, UCHAR *)) + (STATUS*, struct att**, struct tra**, struct blb**, + struct bid*, USHORT, UCHAR*)) - ENTRYPOINT("gds_create_blob2", jrd8_create_blob2, "jrd5_create_blob2", - REM_create_blob2, "_REM_create_blob2", CSI_create_blob2, +ENTRYPOINT("gds_create_blob2", + jrd8_create_blob2, + "jrd5_create_blob2", + REM_create_blob2, + "_REM_create_blob2", + CSI_create_blob2, /**** RDB_create_blob2 ***/ y_valve_no_entrypoint, PSI_create_blob2, PSI5_create_blob2, "_jrd8_create_blob2", IPI_create_blob2, - (STATUS *, struct att **, struct tra **, struct blb **, - struct bid *, USHORT, UCHAR *)) + (STATUS*, struct att**, struct tra**, struct blb**, + struct bid*, USHORT, UCHAR*)) - ENTRYPOINT("gds_get_slice", jrd8_get_slice, "jrd5_get_slice", REM_get_slice, - "_REM_get_slice", CSI_get_slice, +ENTRYPOINT( "gds_get_slice", + jrd8_get_slice, + "jrd5_get_slice", + REM_get_slice, + "_REM_get_slice", + CSI_get_slice, /**** RDB_get_slice ***/ y_valve_no_entrypoint, - PSI_get_slice, - PSI5_get_slice, - "_jrd8_get_slice", - IPI_get_slice, - (STATUS *, struct att **, struct tra **, SLONG *, USHORT, + PSI_get_slice, + PSI5_get_slice, + "_jrd8_get_slice", + IPI_get_slice, + (STATUS*, struct att **, struct tra **, SLONG *, USHORT, UCHAR *, USHORT, UCHAR *, SLONG, UCHAR *, SLONG *)) - ENTRYPOINT("gds_put_slice", jrd8_put_slice, "jrd5_put_slice", REM_put_slice, - "_REM_put_slice", CSI_put_slice, +ENTRYPOINT( "gds_put_slice", + jrd8_put_slice, + "jrd5_put_slice", + REM_put_slice, + "_REM_put_slice", + CSI_put_slice, /**** RDB_put_slice ***/ y_valve_no_entrypoint, - PSI_put_slice, - PSI5_put_slice, - "_jrd8_put_slice", - IPI_put_slice, - (STATUS *, struct att **, struct tra **, SLONG *, USHORT, - UCHAR *, USHORT, UCHAR *, SLONG, UCHAR *)) + PSI_put_slice, + PSI5_put_slice, + "_jrd8_put_slice", + IPI_put_slice, + (STATUS*, struct att**, struct tra**, SLONG*, USHORT, + UCHAR*, USHORT, UCHAR*, SLONG, UCHAR*)) - ENTRYPOINT("gds_seek_blob", jrd8_seek_blob, "jrd5_seek_blob", REM_seek_blob, - "_REM_seek_blob", CSI_seek_blob, +ENTRYPOINT( "gds_seek_blob", + jrd8_seek_blob, + "jrd5_seek_blob", + REM_seek_blob, + "_REM_seek_blob", + CSI_seek_blob, /**** RDB_seek_blob ***/ y_valve_no_entrypoint, - PSI_seek_blob, - PSI5_seek_blob, - "_jrd8_seek_blob", - IPI_seek_blob, - (STATUS *, struct blb **, SSHORT, SLONG, SLONG *)) + PSI_seek_blob, + PSI5_seek_blob, + "_jrd8_seek_blob", + IPI_seek_blob, + (STATUS*, struct blb**, SSHORT, SLONG, SLONG*)) - ENTRYPOINT("isc_transact_request", jrd8_transact_request, +ENTRYPOINT( "isc_transact_request", + jrd8_transact_request, /**** "jrd5_transact_request" ***/ NULL, - REM_transact_request, - "_REM_transact_request", CSI_transact_request, + REM_transact_request, + "_REM_transact_request", + CSI_transact_request, /**** RDB_transact_request ***/ y_valve_no_entrypoint, - PSI_transact_request, + PSI_transact_request, /**** PSI5_transact_request ***/ y_valve_no_entrypoint, - "_jrd8_transact_request", - IPI_transact_request, - (STATUS *, struct att **, struct tra **, USHORT, SCHAR *, - USHORT, SCHAR *, USHORT, SCHAR *)) + "_jrd8_transact_request", + IPI_transact_request, + (STATUS*, struct att**, struct tra**, USHORT, SCHAR*, + USHORT, SCHAR*, USHORT, SCHAR*)) - ENTRYPOINT("isc_drop_database", jrd8_drop_database, +ENTRYPOINT( "isc_drop_database", + jrd8_drop_database, /**** "jrd5_drop_database" ***/ NULL, - REM_drop_database, "_REM_drop_database", CSI_drop_database, + REM_drop_database, + "_REM_drop_database", + CSI_drop_database, /**** RDB_drop_database ***/ y_valve_no_entrypoint, - PSI_drop_database, + PSI_drop_database, /**** PSI5_drop_database ***/ y_valve_no_entrypoint, - "_jrd8_drop_database", - IPI_drop_database, (STATUS *, struct att **)) + "_jrd8_drop_database", + IPI_drop_database, + (STATUS*, struct att**)) /* and the DSQL entry points */ - ENTRYPOINT("isc_dsql_allocate_statement", - /**** jrd8_allocate_statement ***/ - y_valve_no_entrypoint, - "LDSQL_allocate_statement", REM_allocate_statement, +ENTRYPOINT("isc_dsql_allocate_statement", + /**** jrd8_allocate_statement ***/ y_valve_no_entrypoint, + "LDSQL_allocate_statement", + REM_allocate_statement, /**** "_REM_allocate_statement" ***/ "no_entrypoint", - CSI_allocate_statement, - /**** RDB_allocate_statement ***/ - y_valve_no_entrypoint, - PSI_allocate_statement, PSI5_allocate_statement, + CSI_allocate_statement, + /**** RDB_allocate_statement ***/ y_valve_no_entrypoint, + PSI_allocate_statement, + PSI5_allocate_statement, /**** "_jrd8_allocate_statement" ***/ "no_entrypoint", - IPI_allocate_statement, - (STATUS *, struct rdb **, struct rsr **)) + IPI_allocate_statement, + (STATUS*, struct rdb**, struct rsr**)) - ENTRYPOINT("isc_dsql_execute", +ENTRYPOINT( "isc_dsql_execute", /**** jrd8_execute ***/ y_valve_no_entrypoint, - "LDSQL_execute", REM_execute, + "LDSQL_execute", + REM_execute, /**** "_REM_execute" ***/ "no_entrypoint", - CSI_execute, + CSI_execute, /**** RDB_execute ***/ y_valve_no_entrypoint, - PSI_execute, PSI5_execute, + PSI_execute, + PSI5_execute, /**** "_jrd8_execute" ***/ "no_entrypoint", - IPI_execute, - (STATUS *, struct rtr **, struct rsr **, USHORT, UCHAR *, - USHORT, USHORT, UCHAR *)) + IPI_execute, + (STATUS*, struct rtr**, struct rsr**, USHORT, UCHAR*, + USHORT, USHORT, UCHAR*)) - ENTRYPOINT("isc_dsql_execute2", +ENTRYPOINT("isc_dsql_execute2", /**** jrd8_execute2 ***/ y_valve_no_entrypoint, /**** "jrd5_execute2" ***/ NULL, - REM_execute2, + REM_execute2, /**** "_REM_execute2" ***/ "no_entrypoint", - CSI_execute2, + CSI_execute2, /**** RDB_execute2 ***/ y_valve_no_entrypoint, - PSI_execute2, + PSI_execute2, /**** PSI5_execute2 ***/ y_valve_no_entrypoint, /**** "_jrd8_execute2" ***/ "no_entrypoint", - IPI_execute2, - (STATUS *, struct rtr **, struct rsr **, USHORT, UCHAR *, - USHORT, USHORT, UCHAR *, USHORT, UCHAR *, USHORT, USHORT, - UCHAR *)) + IPI_execute2, + (STATUS*, struct rtr**, struct rsr**, USHORT, UCHAR*, + USHORT, USHORT, UCHAR*, USHORT, UCHAR*, USHORT, USHORT, + UCHAR*)) - ENTRYPOINT("isc_dsql_execute_immediate", - /**** jrd8_execute_immediate ***/ - y_valve_no_entrypoint, - "LDSQL_execute_immediate", REM_execute_immediate, +ENTRYPOINT( "isc_dsql_execute_immediate", + /**** jrd8_execute_immediate ***/ y_valve_no_entrypoint, + "LDSQL_execute_immediate", + REM_execute_immediate, /**** "_REM_execute_immediate" ***/ "no_entrypoint", - CSI_execute_immediate, - /**** RDB_execute_immediate ***/ - y_valve_no_entrypoint, - PSI_execute_immediate, PSI5_execute_immediate, + CSI_execute_immediate, + /**** RDB_execute_immediate ***/ y_valve_no_entrypoint, + PSI_execute_immediate, + PSI5_execute_immediate, /**** "_jrd8_execute_immediate" ***/ "no_entrypoint", - IPI_execute_immediate, - (STATUS *, struct rdb **, struct rtr **, USHORT, UCHAR *, - USHORT, USHORT, UCHAR *, USHORT, USHORT, UCHAR *)) + IPI_execute_immediate, + (STATUS*, struct rdb**, struct rtr**, USHORT, UCHAR*, + USHORT, USHORT, UCHAR *, USHORT, USHORT, UCHAR*)) - ENTRYPOINT("isc_dsql_execute_immediate2", - /**** jrd8_execute_immediate2 ***/ - y_valve_no_entrypoint, +ENTRYPOINT( "isc_dsql_execute_immediate2", + /**** jrd8_execute_immediate2 ***/ y_valve_no_entrypoint, /**** "jrd5_execute_immediate2" ***/ NULL, - REM_execute_immediate2, + REM_execute_immediate2, /**** "_REM_execute_immediate2" ***/ "no_entrypoint", - CSI_execute_immediate2, - /**** RDB_execute_immediate2 ***/ - y_valve_no_entrypoint, - PSI_execute_immediate2, - /**** PSI5_execute_immediate2 ***/ - y_valve_no_entrypoint, + CSI_execute_immediate2, + /**** RDB_execute_immediate2 ***/ y_valve_no_entrypoint, + PSI_execute_immediate2, + /**** PSI5_execute_immediate2 ***/ y_valve_no_entrypoint, /**** "_jrd8_execute_immediate2" ***/ "no_entrypoint", - IPI_execute_immediate2, - (STATUS *, struct rdb **, struct rtr **, USHORT, UCHAR *, + IPI_execute_immediate2, + (STATUS*, struct rdb**, struct rtr**, USHORT, UCHAR*, USHORT, USHORT, UCHAR *, USHORT, USHORT, UCHAR *, USHORT, - UCHAR *, USHORT, USHORT, UCHAR *)) + UCHAR*, USHORT, USHORT, UCHAR*)) - ENTRYPOINT("isc_dsql_fetch", +ENTRYPOINT( "isc_dsql_fetch", /**** jrd8_fetch ***/ y_valve_no_entrypoint, - "LDSQL_fetch", REM_fetch, + "LDSQL_fetch", + REM_fetch, /**** "_REM_fetch" ***/ "no_entrypoint", - CSI_fetch, + CSI_fetch, /**** RDB_fetch ***/ y_valve_no_entrypoint, - PSI_fetch, PSI5_fetch, + PSI_fetch, + PSI5_fetch, /**** "_jrd8_fetch" ***/ "no_entrypoint", - IPI_fetch, - (STATUS *, struct rsr **, USHORT, UCHAR *, USHORT, USHORT, - UCHAR *)) + IPI_fetch, + (STATUS*, struct rsr**, USHORT, UCHAR*, USHORT, USHORT, UCHAR*)) - ENTRYPOINT("isc_dsql_free_statement", - /**** jrd8_free_statement ***/ - y_valve_no_entrypoint, - "LDSQL_free_statement", REM_free_statement, +ENTRYPOINT( "isc_dsql_free_statement", + /**** jrd8_free_statement ***/ y_valve_no_entrypoint, + "LDSQL_free_statement", + REM_free_statement, /**** "_REM_free_statement" ***/ "no_entrypoint", - CSI_free_statement, - /**** RDB_free_statement ***/ - y_valve_no_entrypoint, - PSI_free_statement, PSI5_free_statement, + CSI_free_statement, + /**** RDB_free_statement ***/ y_valve_no_entrypoint, + PSI_free_statement, + PSI5_free_statement, /**** "_jrd8_free_statement" ***/ "no_entrypoint", - IPI_free_statement, (STATUS *, struct rsr **, USHORT)) + IPI_free_statement, + (STATUS *, struct rsr **, USHORT)) - ENTRYPOINT("isc_dsql_insert", +ENTRYPOINT( "isc_dsql_insert", /**** jrd8_insert ***/ y_valve_no_entrypoint, /**** "jrd5_insert" ***/ NULL, - REM_insert, + REM_insert, /**** "_REM_insert" ***/ "no_entrypoint", - CSI_insert, + CSI_insert, /**** RDB_insert ***/ y_valve_no_entrypoint, - PSI_insert, + PSI_insert, /**** PSI5_insert ***/ y_valve_no_entrypoint, /**** "_jrd8_insert" ***/ "no_entrypoint", - IPI_insert, - (STATUS *, struct rsr **, USHORT, UCHAR *, USHORT, USHORT, - UCHAR *)) + IPI_insert, + (STATUS*, struct rsr**, USHORT, UCHAR*, USHORT, USHORT, UCHAR*)) - ENTRYPOINT("isc_dsql_prepare", +ENTRYPOINT( "isc_dsql_prepare", /**** jrd8_prepare ***/ y_valve_no_entrypoint, - "LDSQL_prepare", REM_prepare, + "LDSQL_prepare", + REM_prepare, /**** "_REM_prepare" ***/ "no_entrypoint", - CSI_prepare, + CSI_prepare, /**** RDB_prepare ***/ y_valve_no_entrypoint, - PSI_prepare, PSI5_prepare, + PSI_prepare, + PSI5_prepare, /**** "_jrd8_prepare" ***/ "no_entrypoint", - IPI_prepare, + IPI_prepare, (STATUS *, struct rtr **, struct rsr **, USHORT, UCHAR *, USHORT, USHORT, UCHAR *, USHORT, UCHAR *)) - ENTRYPOINT("isc_dsql_set_cursor", +ENTRYPOINT( "isc_dsql_set_cursor", /**** jrd8_set_cursor ***/ y_valve_no_entrypoint, - "LDSQL_set_cursor", REM_set_cursor_name, + "LDSQL_set_cursor", + REM_set_cursor_name, /**** "_REM_set_cursor" ***/ "no_entrypoint", - CSI_set_cursor_name, + CSI_set_cursor_name, /**** RDB_set_cursor ***/ y_valve_no_entrypoint, - PSI_set_cursor_name, PSI5_set_cursor_name, + PSI_set_cursor_name, + PSI5_set_cursor_name, /**** "_jrd8_set_cursor" ***/ "no_entrypoint", - IPI_set_cursor_name, + IPI_set_cursor_name, (STATUS *, struct rsr **, UCHAR *, USHORT)) - ENTRYPOINT("isc_dsql_sql_info", +ENTRYPOINT( "isc_dsql_sql_info", /**** jrd8_sql_info ***/ y_valve_no_entrypoint, - "LDSQL_sql_info", REM_sql_info, + "LDSQL_sql_info", + REM_sql_info, /**** "_REM_sql_info" ***/ "no_entrypoint", - CSI_sql_info, + CSI_sql_info, /**** RDB_sql_info ***/ y_valve_no_entrypoint, - PSI_sql_info, PSI5_sql_info, + PSI_sql_info, + PSI5_sql_info, /**** "_jrd8_sql_info" ***/ "no_entrypoint", - IPI_sql_info, + IPI_sql_info, (STATUS *, struct rsr **, SSHORT, UCHAR *, SSHORT, UCHAR *)) /* and service entry points */ - ENTRYPOINT("isc_service_attach", jrd8_service_attach, +ENTRYPOINT( "isc_service_attach", + jrd8_service_attach, /**** "jrd5_service_attach" ***/ NULL, - REM_service_attach, "REM_service_attach", + REM_service_attach, + "REM_service_attach", /**** CSI_service_attach ***/ y_valve_no_entrypoint, /**** RDB_service_attach ***/ y_valve_no_entrypoint, - PSI_attach_service, + PSI_attach_service, /**** PSI5_service_attach ***/ y_valve_no_entrypoint, - "_jrd8_service_attach", - IPI_service_attach, + "_jrd8_service_attach", + IPI_service_attach, (STATUS *, USHORT, TEXT *, struct rdb **, USHORT, SCHAR *)) - ENTRYPOINT("isc_service_detach", jrd8_service_detach, +ENTRYPOINT("isc_service_detach", jrd8_service_detach, /**** "jrd5_service_detach" ***/ NULL, REM_service_detach, "REM_service_detach", /**** CSI_service_detach ***/ y_valve_no_entrypoint, @@ -553,7 +693,7 @@ REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, "_jrd8_service_detach", IPI_service_detach, (STATUS *, struct rdb **)) - ENTRYPOINT("isc_service_query", jrd8_service_query, +ENTRYPOINT("isc_service_query", jrd8_service_query, /**** "jrd5_service_query" ***/ NULL, REM_service_query, "REM_service_query", /**** CSI_service_query ***/ y_valve_no_entrypoint, @@ -565,7 +705,7 @@ REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, (STATUS *, struct rdb **, USHORT, SCHAR *, USHORT, SCHAR *, USHORT, SCHAR *)) - ENTRYPOINT("isc_service_start", jrd8_service_start, +ENTRYPOINT("isc_service_start", jrd8_service_start, /**** "jrd5_service_start" ***/ NULL, REM_service_start, "REM_service_start", /**** CSI_service_start ***/ y_valve_no_entrypoint, @@ -576,7 +716,7 @@ REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, IPI_service_start, (STATUS *, struct svc **, ULONG *, USHORT, SCHAR *)) - ENTRYPOINT("isc_rollback_retaining", jrd8_rollback_retaining, +ENTRYPOINT("isc_rollback_retaining", jrd8_rollback_retaining, /**** "jrd5_rollback_retaining" ***/ NULL, REM_rollback_retaining, "_REM_rollback_retaining", /**** CSI_rollback_retaining ***/ y_valve_no_entrypoint, @@ -586,7 +726,7 @@ REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, "_jrd8_rollback_retaining", IPI_rollback_retaining, (STATUS *, struct tra **)) #ifdef CANCEL_OPERATION - ENTRYPOINT("gds_cancel_operation", jrd8_cancel_operation, +ENTRYPOINT("gds_cancel_operation", jrd8_cancel_operation, /*** "jrd5_cancel_operation" ***/ NULL, /*** REM_cancel_operation ***/ y_valve_no_entrypoint, /*** "REM_cancel_operation" ***/ NULL, @@ -598,7 +738,7 @@ REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, /*** IPI_cancel_operation ***/ y_valve_no_entrypoint, (STATUS *, struct att **, USHORT)) #else - ENTRYPOINT("gds_cancel_operation", +ENTRYPOINT("gds_cancel_operation", /*** jrd8_cancel_operation ***/ y_valve_no_entrypoint, /*** "jrd5_cancel_operation" ***/ NULL, /*** REM_cancel_operation ***/ y_valve_no_entrypoint, @@ -614,507 +754,671 @@ REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, #undef ENTRYPOINT #else // 0/1 -ENTRYPOINT("gds_attach_database", - jrd8_attach_database, - "jrd5_attach_database", - REM_attach_database, - "_REM_attach_database", - CSI_attach_database, - RDB_attach_database, - PSI_attach_database, - PSI5_attach_database, "_jrd8_attach_database", IPI_attach_database) +ENTRYPOINT( "gds_attach_database", + jrd8_attach_database, + "jrd5_attach_database", + REM_attach_database, + "_REM_attach_database", + CSI_attach_database, + RDB_attach_database, + PSI_attach_database, + PSI5_attach_database, + "_jrd8_attach_database", + IPI_attach_database) - ENTRYPOINT("gds_blob_info", - jrd8_blob_info, - "jrd5_blob_info", - REM_blob_info, - "_REM_blob_info", -CSI_blob_info, -RDB_blob_info, PSI_blob_info, PSI5_blob_info, "_jrd8_blob_info", IPI_blob_info) +ENTRYPOINT( "gds_blob_info", + jrd8_blob_info, + "jrd5_blob_info", + REM_blob_info, + "_REM_blob_info", + CSI_blob_info, + RDB_blob_info, + PSI_blob_info, + PSI5_blob_info, + "_jrd8_blob_info", + IPI_blob_info) - ENTRYPOINT("gds_cancel_blob", - jrd8_cancel_blob, - "jrd5_cancel_blob", - REM_cancel_blob, - "_REM_cancel_blob", -CSI_cancel_blob, -RDB_cancel_blob, -PSI_cancel_blob, PSI5_cancel_blob, "_jrd8_cancel_blob", IPI_cancel_blob) +ENTRYPOINT( "gds_cancel_blob", + jrd8_cancel_blob, + "jrd5_cancel_blob", + REM_cancel_blob, + "_REM_cancel_blob", + CSI_cancel_blob, + RDB_cancel_blob, + PSI_cancel_blob, + PSI5_cancel_blob, + "_jrd8_cancel_blob", + IPI_cancel_blob) - ENTRYPOINT("gds_close_blob", - jrd8_close_blob, - "jrd5_close_blob", - REM_close_blob, - "_REM_close_blob", - CSI_close_blob, - RDB_close_blob, - PSI_close_blob, PSI5_close_blob, "_jrd8_close_blob", IPI_close_blob) +ENTRYPOINT( "gds_close_blob", + jrd8_close_blob, + "jrd5_close_blob", + REM_close_blob, + "_REM_close_blob", + CSI_close_blob, + RDB_close_blob, + PSI_close_blob, + PSI5_close_blob, + "_jrd8_close_blob", + IPI_close_blob) - ENTRYPOINT("gds_commit_transaction", - jrd8_commit_transaction, - "jrd5_commit_transaction", -REM_commit_transaction, -"_REM_commit_transaction", -CSI_commit_transaction, -RDB_commit_transaction, -PSI_commit_transaction, PSI5_commit_transaction, "_jrd8_commit_transaction", IPI_commit_transaction) +ENTRYPOINT( "gds_commit_transaction", + jrd8_commit_transaction, + "jrd5_commit_transaction", + REM_commit_transaction, + "_REM_commit_transaction", + CSI_commit_transaction, + RDB_commit_transaction, + PSI_commit_transaction, + PSI5_commit_transaction, + "_jrd8_commit_transaction", + IPI_commit_transaction) - ENTRYPOINT("gds_compile_request", - jrd8_compile_request, - "jrd5_compile_request", - REM_compile_request, - "_REM_compile_request", -CSI_compile_request, -RDB_compile_request, -PSI_compile_request, -PSI5_compile_request, "_jrd8_compile_request", IPI_compile_request) +ENTRYPOINT( "gds_compile_request", + jrd8_compile_request, + "jrd5_compile_request", + REM_compile_request, + "_REM_compile_request", + CSI_compile_request, + RDB_compile_request, + PSI_compile_request, + PSI5_compile_request, + "_jrd8_compile_request", + IPI_compile_request) - ENTRYPOINT("gds_create_blob", - /**** jrd8_create_blob ***/ no_entrypoint, - /**** "jrd5_create_blob" ***/ NULL, - /**** REM_create_blob ***/ no_entrypoint, - "_REM_create_blob", - /**** CSI_create_blob ***/ no_entrypoint, - RDB_create_blob, PSI_create_blob, PSI5_create_blob, - /**** "_jrd8_create_blob" ***/ no_entrypoint, - IPI_create_blob) +ENTRYPOINT( "gds_create_blob", + /**** jrd8_create_blob ***/ no_entrypoint, + /**** "jrd5_create_blob" ***/ NULL, + /**** REM_create_blob ***/ no_entrypoint, + "_REM_create_blob", + /**** CSI_create_blob ***/ no_entrypoint, + RDB_create_blob, + PSI_create_blob, + PSI5_create_blob, + /**** "_jrd8_create_blob" ***/ no_entrypoint, + IPI_create_blob) - ENTRYPOINT("gds_create_database", jrd8_create_database, - /**** "jrd5_create_database" ***/ NULL, - REM_create_database, - "_REM_create_database", - CSI_create_database, RDB_create_database, PSI_create_database, - /**** PSI5_create_database ***/ no_entrypoint, - "_jrd8_create_database", IPI_create_database) +ENTRYPOINT( "gds_create_database", + jrd8_create_database, + /**** "jrd5_create_database" ***/ NULL, + REM_create_database, + "_REM_create_database", + CSI_create_database, + RDB_create_database, + PSI_create_database, + /**** PSI5_create_database ***/ no_entrypoint, + "_jrd8_create_database", + IPI_create_database) + +ENTRYPOINT( "gds_database_info", + jrd8_database_info, + "jrd5_database_info", + REM_database_info, + "_REM_database_info", + CSI_database_info, + RDB_database_info, + PSI_database_info, + PSI5_database_info, + "_jrd8_database_info", + IPI_database_info) - ENTRYPOINT("gds_database_info", - jrd8_database_info, - "jrd5_database_info", - REM_database_info, - "_REM_database_info", -CSI_database_info, -RDB_database_info, -PSI_database_info, PSI5_database_info, "_jrd8_database_info", IPI_database_info) +ENTRYPOINT( "gds_detach_database", + jrd8_detach_database, + "jrd5_detach_database", + REM_detach_database, + "_REM_detach_database", + CSI_detach_database, + RDB_detach_database, + PSI_detach_database, + PSI5_detach_database, + "_jrd8_detach_database", + IPI_detach_database) - ENTRYPOINT("gds_detach_database", - jrd8_detach_database, - "jrd5_detach_database", - REM_detach_database, - "_REM_detach_database", -CSI_detach_database, -RDB_detach_database, -PSI_detach_database, -PSI5_detach_database, "_jrd8_detach_database", IPI_detach_database) +ENTRYPOINT( "gds_get_segment", + jrd8_get_segment, + "jrd5_get_segment", + REM_get_segment, + "_REM_get_segment", + CSI_get_segment, + RDB_get_segment, + PSI_get_segment, + PSI5_get_segment, + "_jrd8_get_segment", + IPI_get_segment) - ENTRYPOINT("gds_get_segment", - jrd8_get_segment, - "jrd5_get_segment", - REM_get_segment, - "_REM_get_segment", -CSI_get_segment, -RDB_get_segment, -PSI_get_segment, PSI5_get_segment, "_jrd8_get_segment", IPI_get_segment) +ENTRYPOINT( "gds_open_blob", + /**** jrd8_open_blob ***/ no_entrypoint, + /**** "jrd5_open_blob" ***/ NULL, + /**** REM_open_blob ***/ no_entrypoint, + "_REM_open_blob", + /**** CSI_open_blob ***/ no_entrypoint, + RDB_open_blob, + PSI_open_blob, + PSI5_open_blob, + /**** "_jrd8_open_blob" ***/ no_entrypoint, + IPI_open_blob) - ENTRYPOINT("gds_open_blob", - /**** jrd8_open_blob ***/ no_entrypoint, - /**** "jrd5_open_blob" ***/ NULL, - /**** REM_open_blob ***/ no_entrypoint, - "_REM_open_blob", - /**** CSI_open_blob ***/ no_entrypoint, - RDB_open_blob, PSI_open_blob, PSI5_open_blob, - /**** "_jrd8_open_blob" ***/ no_entrypoint, - IPI_open_blob) +ENTRYPOINT( "gds_prepare_transaction", + jrd8_prepare_transaction, + "jrd5_prepare_transaction", + REM_prepare_transaction, + "_REM_prepare_transaction", + CSI_prepare_transaction, + RDB_prepare_transaction, + PSI_prepare_transaction, + PSI5_prepare_transaction, + "_jrd8_prepare_transaction", + IPI_prepare_transaction) - ENTRYPOINT("gds_prepare_transaction", - jrd8_prepare_transaction, - "jrd5_prepare_transaction", -REM_prepare_transaction, -"_REM_prepare_transaction", -CSI_prepare_transaction, -RDB_prepare_transaction, -PSI_prepare_transaction, PSI5_prepare_transaction, "_jrd8_prepare_transaction", IPI_prepare_transaction) +ENTRYPOINT( "gds_put_segment", + jrd8_put_segment, + "jrd5_put_segment", + REM_put_segment, + "_REM_put_segment", + CSI_put_segment, + RDB_put_segment, + PSI_put_segment, + PSI5_put_segment, + "_jrd8_put_segment", + IPI_put_segment) - ENTRYPOINT("gds_put_segment", - jrd8_put_segment, - "jrd5_put_segment", - REM_put_segment, - "_REM_put_segment", -CSI_put_segment, -RDB_put_segment, -PSI_put_segment, PSI5_put_segment, "_jrd8_put_segment", IPI_put_segment) +ENTRYPOINT( "gds_reconnect_transaction", + jrd8_reconnect_transaction, + "jrd5_reconnect_transaction", + REM_reconnect_transaction, + "_REM_reconnect_transaction", + CSI_reconnect_transaction, + RDB_reconnect_transaction, + PSI_reconnect_transaction, + PSI5_reconnect_transaction, + "_jrd8_reconnect_transaction", + IPI_reconnect_transaction) - ENTRYPOINT("gds_reconnect_transaction", - jrd8_reconnect_transaction, - "jrd5_reconnect_transaction", -REM_reconnect_transaction, -"_REM_reconnect_transaction", -CSI_reconnect_transaction, -RDB_reconnect_transaction, -PSI_reconnect_transaction, PSI5_reconnect_transaction, "_jrd8_reconnect_transaction", IPI_reconnect_transaction) +ENTRYPOINT( "gds_receive", + jrd8_receive, + "jrd5_receive", + REM_receive, + "_REM_receive", + CSI_receive, + RDB_receive, + PSI_receive, + PSI5_receive, /* the bridge pipe server will have two less params, but should be OK */ + "_jrd8_receive", + IPI_receive) - ENTRYPOINT("gds_receive", - jrd8_receive, "jrd5_receive", REM_receive, "_REM_receive", CSI_receive, RDB_receive, PSI_receive, PSI5_receive, /* the bridge pipe server will have two less params, but should be OK */ - "_jrd8_receive", IPI_receive) +ENTRYPOINT( "gds_release_request", + jrd8_release_request, + "jrd5_release_request", + REM_release_request, + "_REM_release_request", + CSI_release_request, + RDB_release_request, + PSI_release_request, + PSI5_release_request, + "_jrd8_release_request", + IPI_release_request) - ENTRYPOINT("gds_release_request", - jrd8_release_request, - "jrd5_release_request", - REM_release_request, - "_REM_release_request", -CSI_release_request, -RDB_release_request, -PSI_release_request, -PSI5_release_request, "_jrd8_release_request", IPI_release_request) +ENTRYPOINT( "gds_request_info", + jrd8_request_info, + "jrd5_request_info", + REM_request_info, + "_REM_request_info", + CSI_request_info, + RDB_request_info, + PSI_request_info, + PSI5_request_info, + "_jrd8_request_info", + IPI_request_info) - ENTRYPOINT("gds_request_info", - jrd8_request_info, - "jrd5_request_info", - REM_request_info, - "_REM_request_info", -CSI_request_info, -RDB_request_info, -PSI_request_info, PSI5_request_info, "_jrd8_request_info", IPI_request_info) +ENTRYPOINT( "gds_rollback_transaction", + jrd8_rollback_transaction, + "jrd5_rollback_transaction", + REM_rollback_transaction, + "_REM_rollback_transaction", + CSI_rollback_transaction, + RDB_rollback_transaction, + PSI_rollback_transaction, + PSI5_rollback_transaction, + "_jrd8_rollback_transaction", + IPI_rollback_transaction) - ENTRYPOINT("gds_rollback_transaction", - jrd8_rollback_transaction, - "jrd5_rollback_transaction", -REM_rollback_transaction, -"_REM_rollback_transaction", -CSI_rollback_transaction, -RDB_rollback_transaction, -PSI_rollback_transaction, PSI5_rollback_transaction, "_jrd8_rollback_transaction", IPI_rollback_transaction) +ENTRYPOINT( "gds_send", + jrd8_send, + "jrd5_send", + REM_send, + "_REM_send", + CSI_send, + RDB_send, + PSI_send, + PSI5_send, + "_jrd8_send", + IPI_send) - ENTRYPOINT("gds_send", - jrd8_send, - "jrd5_send", - REM_send, - "_REM_send", - CSI_send, RDB_send, PSI_send, PSI5_send, "_jrd8_send", IPI_send) +ENTRYPOINT( "gds_start_and_send", + jrd8_start_and_send, + "jrd5_start_and_send", + REM_start_and_send, + "_REM_start_and_send", + CSI_start_and_send, + RDB_start_and_send, + PSI_start_and_send, + PSI5_start_and_send, + "_jrd8_start_and_send", + IPI_start_and_send) - ENTRYPOINT("gds_start_and_send", - jrd8_start_and_send, - "jrd5_start_and_send", - REM_start_and_send, - "_REM_start_and_send", -CSI_start_and_send, -RDB_start_and_send, -PSI_start_and_send, PSI5_start_and_send, "_jrd8_start_and_send", IPI_start_and_send) +ENTRYPOINT( "gds_start_request", + jrd8_start_request, + "jrd5_start_request", + REM_start_request, + "_REM_start_request", + CSI_start_request, + RDB_start_request, + PSI_start_request, + PSI5_start_request, + "_jrd8_start_request", + IPI_start_request) - ENTRYPOINT("gds_start_request", - jrd8_start_request, - "jrd5_start_request", - REM_start_request, - "_REM_start_request", -CSI_start_request, -RDB_start_request, -PSI_start_request, PSI5_start_request, "_jrd8_start_request", IPI_start_request) +ENTRYPOINT( "gds_start_multiple", + jrd8_start_multiple, + "jrd5_start_multiple", + /**** REM_start_multiple ***/ no_entrypoint, + "_REM_start_multiple", + CSI_start_multiple, + RDB_start_multiple, + PSI_start_multiple, + PSI5_start_multiple, + "_jrd8_start_multiple", + IPI_start_multiple) - ENTRYPOINT("gds_start_multiple", jrd8_start_multiple, "jrd5_start_multiple", - /**** REM_start_multiple ***/ no_entrypoint, - "_REM_start_multiple", - CSI_start_multiple, - RDB_start_multiple, - PSI_start_multiple, - PSI5_start_multiple, - "_jrd8_start_multiple", IPI_start_multiple) +ENTRYPOINT( "gds_start_transaction", + jrd8_start_transaction, + "jrd5_start_transaction", + REM_start_transaction, + "_REM_start_transaction", + CSI_start_transaction, + RDB_start_transaction, + PSI_start_transaction, + PSI5_start_transaction, + "_jrd8_start_transaction", + IPI_start_transaction) - ENTRYPOINT("gds_start_transaction", - jrd8_start_transaction, - "jrd5_start_transaction", -REM_start_transaction, -"_REM_start_transaction", -CSI_start_transaction, -RDB_start_transaction, -PSI_start_transaction, PSI5_start_transaction, "_jrd8_start_transaction", IPI_start_transaction) +ENTRYPOINT( "gds_transaction_info", + jrd8_transaction_info, + "jrd5_transaction_info", + REM_transaction_info, + "_REM_transaction_info", + CSI_transaction_info, + RDB_transaction_info, + PSI_transaction_info, + PSI5_transaction_info, + "_jrd8_transaction_info", + IPI_transaction_info) - ENTRYPOINT("gds_transaction_info", - jrd8_transaction_info, - "jrd5_transaction_info", -REM_transaction_info, -"_REM_transaction_info", -CSI_transaction_info, -RDB_transaction_info, -PSI_transaction_info, PSI5_transaction_info, "_jrd8_transaction_info", IPI_transaction_info) +ENTRYPOINT( "gds_unwind_request", + jrd8_unwind_request, + "jrd5_unwind_request", + REM_unwind_request, + "_REM_unwind_request", + CSI_unwind_request, + RDB_unwind_request, + PSI_unwind_request, + PSI5_unwind_request, + "_jrd8_unwind_request", + IPI_unwind_request) - ENTRYPOINT("gds_unwind_request", - jrd8_unwind_request, - "jrd5_unwind_request", - REM_unwind_request, - "_REM_unwind_request", -CSI_unwind_request, -RDB_unwind_request, -PSI_unwind_request, PSI5_unwind_request, "_jrd8_unwind_request", IPI_unwind_request) +ENTRYPOINT( "gds_commit_retaining", + jrd8_commit_retaining, + "jrd5_commit_retaining", + REM_commit_retaining, + "_REM_commit_retaining", + CSI_commit_retaining, + /**** RDB_commit_retaining ***/ no_entrypoint, + PSI_commit_retaining, + PSI5_commit_retaining, + "_jrd8_commit_retaining", + IPI_commit_retaining) - ENTRYPOINT("gds_commit_retaining", - jrd8_commit_retaining, - "jrd5_commit_retaining", -REM_commit_retaining, "_REM_commit_retaining", CSI_commit_retaining, - /**** RDB_commit_retaining ***/ no_entrypoint, - PSI_commit_retaining, - PSI5_commit_retaining, - "_jrd8_commit_retaining", IPI_commit_retaining) +ENTRYPOINT( "gds_que_events", + jrd8_que_events, + "jrd5_que_events", + REM_que_events, + "_REM_que_events", + CSI_que_events, + /**** RDB_que_events ***/ no_entrypoint, + PSI_que_events, + PSI5_que_events, + "_jrd8_que_events", + IPI_que_events) - ENTRYPOINT("gds_que_events", - jrd8_que_events, - "jrd5_que_events", - REM_que_events, "_REM_que_events", CSI_que_events, - /**** RDB_que_events ***/ no_entrypoint, - PSI_que_events, - PSI5_que_events, "_jrd8_que_events", IPI_que_events) +ENTRYPOINT( "gds_cancel_events", + jrd8_cancel_events, + "jrd5_cancel_events", + REM_cancel_events, + "_REM_cancel_events", + CSI_cancel_events, + /**** RDB_cancel_events ***/ no_entrypoint, + PSI_cancel_events, + PSI5_cancel_events, + "_jrd8_cancel_events", + IPI_cancel_events) - ENTRYPOINT("gds_cancel_events", - jrd8_cancel_events, - "jrd5_cancel_events", - REM_cancel_events, "_REM_cancel_events", CSI_cancel_events, - /**** RDB_cancel_events ***/ no_entrypoint, - PSI_cancel_events, - PSI5_cancel_events, "_jrd8_cancel_events", IPI_cancel_events) +ENTRYPOINT( "gds_ddl", + jrd8_ddl, + /**** "jrd5_ddl" ***/ NULL, + REM_ddl, + "_REM_ddl", + CSI_ddl, + /**** RDB_ddl ***/ no_entrypoint, + PSI_ddl, + PSI5_ddl, + "_jrd8_ddl", + IPI_ddl) - ENTRYPOINT("gds_ddl", jrd8_ddl, - /**** "jrd5_ddl" ***/ NULL, - REM_ddl, "_REM_ddl", CSI_ddl, - /**** RDB_ddl ***/ no_entrypoint, - PSI_ddl, PSI5_ddl, "_jrd8_ddl", IPI_ddl) +ENTRYPOINT( "gds_open_blob2", + jrd8_open_blob2, + "jrd5_open_blob2", + REM_open_blob2, + "_REM_open_blob2", + CSI_open_blob2, + /**** RDB_open_blob2 ***/ no_entrypoint, + PSI_open_blob2, + PSI5_open_blob2, + "_jrd8_open_blob2", + IPI_open_blob2) - ENTRYPOINT("gds_open_blob2", - jrd8_open_blob2, - "jrd5_open_blob2", - REM_open_blob2, "_REM_open_blob2", CSI_open_blob2, - /**** RDB_open_blob2 ***/ no_entrypoint, - PSI_open_blob2, - PSI5_open_blob2, "_jrd8_open_blob2", IPI_open_blob2) +ENTRYPOINT( "gds_create_blob2", + jrd8_create_blob2, + "jrd5_create_blob2", + REM_create_blob2, + "_REM_create_blob2", + CSI_create_blob2, + /**** RDB_create_blob2 ***/ no_entrypoint, + PSI_create_blob2, + PSI5_create_blob2, + "_jrd8_create_blob2", + IPI_create_blob2) - ENTRYPOINT("gds_create_blob2", - jrd8_create_blob2, - "jrd5_create_blob2", - REM_create_blob2, "_REM_create_blob2", CSI_create_blob2, - /**** RDB_create_blob2 ***/ no_entrypoint, - PSI_create_blob2, - PSI5_create_blob2, "_jrd8_create_blob2", IPI_create_blob2) +ENTRYPOINT( "gds_get_slice", + jrd8_get_slice, + "jrd5_get_slice", + REM_get_slice, + "_REM_get_slice", + CSI_get_slice, + /**** RDB_get_slice ***/ no_entrypoint, + PSI_get_slice, + PSI5_get_slice, + "_jrd8_get_slice", + IPI_get_slice) - ENTRYPOINT("gds_get_slice", - jrd8_get_slice, - "jrd5_get_slice", REM_get_slice, "_REM_get_slice", CSI_get_slice, - /**** RDB_get_slice ***/ no_entrypoint, - PSI_get_slice, - PSI5_get_slice, "_jrd8_get_slice", IPI_get_slice) +ENTRYPOINT( "gds_put_slice", + jrd8_put_slice, + "jrd5_put_slice", + REM_put_slice, + "_REM_put_slice", + CSI_put_slice, + /**** RDB_put_slice ***/ no_entrypoint, + PSI_put_slice, + PSI5_put_slice, + "_jrd8_put_slice", + IPI_put_slice) - ENTRYPOINT("gds_put_slice", - jrd8_put_slice, - "jrd5_put_slice", REM_put_slice, "_REM_put_slice", CSI_put_slice, - /**** RDB_put_slice ***/ no_entrypoint, - PSI_put_slice, - PSI5_put_slice, "_jrd8_put_slice", IPI_put_slice) +ENTRYPOINT( "gds_seek_blob", + jrd8_seek_blob, + "jrd5_seek_blob", + REM_seek_blob, + "_REM_seek_blob", + CSI_seek_blob, + /**** RDB_seek_blob ***/ no_entrypoint, + PSI_seek_blob, + PSI5_seek_blob, + "_jrd8_seek_blob", + IPI_seek_blob) - ENTRYPOINT("gds_seek_blob", - jrd8_seek_blob, - "jrd5_seek_blob", REM_seek_blob, "_REM_seek_blob", CSI_seek_blob, - /**** RDB_seek_blob ***/ no_entrypoint, - PSI_seek_blob, - PSI5_seek_blob, "_jrd8_seek_blob", IPI_seek_blob) +ENTRYPOINT( "isc_transact_request", + jrd8_transact_request, + /**** "jrd5_transact_request" ***/ NULL, + REM_transact_request, + "_REM_transact_request", + CSI_transact_request, + /**** RDB_transact_request ***/ no_entrypoint, + PSI_transact_request, + /**** PSI5_transact_request ***/ no_entrypoint, + "_jrd8_transact_request", + IPI_transact_request) - ENTRYPOINT("isc_transact_request", jrd8_transact_request, - /**** "jrd5_transact_request" ***/ NULL, - REM_transact_request, - "_REM_transact_request", CSI_transact_request, - /**** RDB_transact_request ***/ no_entrypoint, - PSI_transact_request, - /**** PSI5_transact_request ***/ no_entrypoint, - "_jrd8_transact_request", IPI_transact_request) - - ENTRYPOINT("isc_drop_database", jrd8_drop_database, - /**** "jrd5_drop_database" ***/ NULL, - REM_drop_database, "_REM_drop_database", CSI_drop_database, - /**** RDB_drop_database ***/ no_entrypoint, - PSI_drop_database, - /**** PSI5_drop_database ***/ no_entrypoint, - "_jrd8_drop_database", IPI_drop_database) +ENTRYPOINT( "isc_drop_database", + jrd8_drop_database, + /**** "jrd5_drop_database" ***/ NULL, + REM_drop_database, + "_REM_drop_database", + CSI_drop_database, + /**** RDB_drop_database ***/ no_entrypoint, + PSI_drop_database, + /**** PSI5_drop_database ***/ no_entrypoint, + "_jrd8_drop_database", + IPI_drop_database) /* and the DSQL entry points */ - ENTRYPOINT("isc_dsql_allocate_statement", - /**** jrd8_allocate_statement ***/ no_entrypoint, - "LDSQL_allocate_statement", REM_allocate_statement, - /**** "_REM_allocate_statement" ***/ "no_entrypoint", - CSI_allocate_statement, - /**** RDB_allocate_statement ***/ no_entrypoint, - PSI_allocate_statement, PSI5_allocate_statement, - /**** "_jrd8_allocate_statement" ***/ no_entrypoint, - IPI_allocate_statement) - ENTRYPOINT("isc_dsql_execute", - /**** jrd8_execute ***/ no_entrypoint, - "LDSQL_execute", REM_execute, - /**** "_REM_execute" ***/ "no_entrypoint", - CSI_execute, - /**** RDB_execute ***/ no_entrypoint, - PSI_execute, PSI5_execute, - /**** "_jrd8_execute" ***/ no_entrypoint, - IPI_execute) +ENTRYPOINT( "isc_dsql_allocate_statement", + /**** jrd8_allocate_statement ***/ no_entrypoint, + "LDSQL_allocate_statement", + REM_allocate_statement, + /**** "_REM_allocate_statement" ***/ "no_entrypoint", + CSI_allocate_statement, + /**** RDB_allocate_statement ***/ no_entrypoint, + PSI_allocate_statement, + PSI5_allocate_statement, + /**** "_jrd8_allocate_statement" ***/ no_entrypoint, + IPI_allocate_statement) - ENTRYPOINT("isc_dsql_execute2", - /**** jrd8_execute2 ***/ no_entrypoint, - /**** "jrd5_execute2" ***/ NULL, - REM_execute2, - /**** "_REM_execute2" ***/ "no_entrypoint", - CSI_execute2, - /**** RDB_execute2 ***/ no_entrypoint, - PSI_execute2, - /**** PSI5_execute2 ***/ no_entrypoint, - /**** "_jrd8_execute2" ***/ no_entrypoint, - IPI_execute2) +ENTRYPOINT( "isc_dsql_execute", + /**** jrd8_execute ***/ no_entrypoint, + "LDSQL_execute", + REM_execute, + /**** "_REM_execute" ***/ "no_entrypoint", + CSI_execute, + /**** RDB_execute ***/ no_entrypoint, + PSI_execute, + PSI5_execute, + /**** "_jrd8_execute" ***/ no_entrypoint, + IPI_execute) - ENTRYPOINT("isc_dsql_execute_immediate", - /**** jrd8_execute_immediate ***/ no_entrypoint, - "LDSQL_execute_immediate", REM_execute_immediate, - /**** "_REM_execute_immediate" ***/ "no_entrypoint", - CSI_execute_immediate, - /**** RDB_execute_immediate ***/ no_entrypoint, - PSI_execute_immediate, PSI5_execute_immediate, - /**** "_jrd8_execute_immediate" ***/ no_entrypoint, - IPI_execute_immediate) +ENTRYPOINT( "isc_dsql_execute2", + /**** jrd8_execute2 ***/ no_entrypoint, + /**** "jrd5_execute2" ***/ NULL, + REM_execute2, + /**** "_REM_execute2" ***/ "no_entrypoint", + CSI_execute2, + /**** RDB_execute2 ***/ no_entrypoint, + PSI_execute2, + /**** PSI5_execute2 ***/ no_entrypoint, + /**** "_jrd8_execute2" ***/ no_entrypoint, + IPI_execute2) - ENTRYPOINT("isc_dsql_execute_immediate2", - /**** jrd8_execute_immediate2 ***/ no_entrypoint, - /**** "jrd5_execute_immediate2" ***/ NULL, - REM_execute_immediate2, - /**** "_REM_execute_immediate2" ***/ "no_entrypoint", - CSI_execute_immediate2, - /**** RDB_execute_immediate2 ***/ no_entrypoint, - PSI_execute_immediate2, - /**** PSI5_execute_immediate2 ***/ no_entrypoint, - /**** "_jrd8_execute_immediate2" ***/ no_entrypoint, - IPI_execute_immediate2) +ENTRYPOINT( "isc_dsql_execute_immediate", + /**** jrd8_execute_immediate ***/ no_entrypoint, + "LDSQL_execute_immediate", + REM_execute_immediate, + /**** "_REM_execute_immediate" ***/ "no_entrypoint", + CSI_execute_immediate, + /**** RDB_execute_immediate ***/ no_entrypoint, + PSI_execute_immediate, + PSI5_execute_immediate, + /**** "_jrd8_execute_immediate" ***/ no_entrypoint, + IPI_execute_immediate) - ENTRYPOINT("isc_dsql_fetch", - /**** jrd8_fetch ***/ no_entrypoint, - "LDSQL_fetch", REM_fetch, - /**** "_REM_fetch" ***/ "no_entrypoint", - CSI_fetch, - /**** RDB_fetch ***/ no_entrypoint, - PSI_fetch, PSI5_fetch, - /**** "_jrd8_fetch" ***/ no_entrypoint, - IPI_fetch) +ENTRYPOINT( "isc_dsql_execute_immediate2", + /**** jrd8_execute_immediate2 ***/ no_entrypoint, + /**** "jrd5_execute_immediate2" ***/ NULL, + REM_execute_immediate2, + /**** "_REM_execute_immediate2" ***/ "no_entrypoint", + CSI_execute_immediate2, + /**** RDB_execute_immediate2 ***/ no_entrypoint, + PSI_execute_immediate2, + /**** PSI5_execute_immediate2 ***/ no_entrypoint, + /**** "_jrd8_execute_immediate2" ***/ no_entrypoint, + IPI_execute_immediate2) - ENTRYPOINT("isc_dsql_free_statement", - /**** jrd8_free_statement ***/ no_entrypoint, - "LDSQL_free_statement", REM_free_statement, - /**** "_REM_free_statement" ***/ "no_entrypoint", - CSI_free_statement, - /**** RDB_free_statement ***/ no_entrypoint, - PSI_free_statement, PSI5_free_statement, - /**** "_jrd8_free_statement" ***/ no_entrypoint, - IPI_free_statement) +ENTRYPOINT( "isc_dsql_fetch", + /**** jrd8_fetch ***/ no_entrypoint, + "LDSQL_fetch", + REM_fetch, + /**** "_REM_fetch" ***/ "no_entrypoint", + CSI_fetch, + /**** RDB_fetch ***/ no_entrypoint, + PSI_fetch, + PSI5_fetch, + /**** "_jrd8_fetch" ***/ no_entrypoint, + IPI_fetch) - ENTRYPOINT("isc_dsql_insert", - /**** jrd8_insert ***/ no_entrypoint, - /**** "jrd5_insert" ***/ NULL, - REM_insert, - /**** "_REM_insert" ***/ "no_entrypoint", - CSI_insert, - /**** RDB_insert ***/ no_entrypoint, - PSI_insert, - /**** PSI5_insert ***/ no_entrypoint, - /**** "_jrd8_insert" ***/ no_entrypoint, - IPI_insert) +ENTRYPOINT( "isc_dsql_free_statement", + /**** jrd8_free_statement ***/ no_entrypoint, + "LDSQL_free_statement", + REM_free_statement, + /**** "_REM_free_statement" ***/ "no_entrypoint", + CSI_free_statement, + /**** RDB_free_statement ***/ no_entrypoint, + PSI_free_statement, + PSI5_free_statement, + /**** "_jrd8_free_statement" ***/ no_entrypoint, + IPI_free_statement) - ENTRYPOINT("isc_dsql_prepare", - /**** jrd8_prepare ***/ no_entrypoint, - "LDSQL_prepare", REM_prepare, - /**** "_REM_prepare" ***/ "no_entrypoint", - CSI_prepare, - /**** RDB_prepare ***/ no_entrypoint, - PSI_prepare, PSI5_prepare, - /**** "_jrd8_prepare" ***/ no_entrypoint, - IPI_prepare) +ENTRYPOINT( "isc_dsql_insert", + /**** jrd8_insert ***/ no_entrypoint, + /**** "jrd5_insert" ***/ NULL, + REM_insert, + /**** "_REM_insert" ***/ "no_entrypoint", + CSI_insert, + /**** RDB_insert ***/ no_entrypoint, + PSI_insert, + /**** PSI5_insert ***/ no_entrypoint, + /**** "_jrd8_insert" ***/ no_entrypoint, + IPI_insert) - ENTRYPOINT("isc_dsql_set_cursor", - /**** jrd8_set_cursor ***/ no_entrypoint, - "LDSQL_set_cursor", REM_set_cursor_name, - /**** "_REM_set_cursor" ***/ "no_entrypoint", - CSI_set_cursor_name, - /**** RDB_set_cursor ***/ no_entrypoint, - PSI_set_cursor_name, PSI5_set_cursor_name, - /**** "_jrd8_set_cursor" ***/ no_entrypoint, - IPI_set_cursor_name) +ENTRYPOINT( "isc_dsql_prepare", + /**** jrd8_prepare ***/ no_entrypoint, + "LDSQL_prepare", + REM_prepare, + /**** "_REM_prepare" ***/ "no_entrypoint", + CSI_prepare, + /**** RDB_prepare ***/ no_entrypoint, + PSI_prepare, + PSI5_prepare, + /**** "_jrd8_prepare" ***/ no_entrypoint, + IPI_prepare) - ENTRYPOINT("isc_dsql_sql_info", - /**** jrd8_sql_info ***/ no_entrypoint, - "LDSQL_sql_info", REM_sql_info, - /**** "_REM_sql_info" ***/ "no_entrypoint", - CSI_sql_info, - /**** RDB_sql_info ***/ no_entrypoint, - PSI_sql_info, PSI5_sql_info, - /**** "_jrd8_sql_info" ***/ no_entrypoint, - IPI_sql_info) +ENTRYPOINT( "isc_dsql_set_cursor", + /**** jrd8_set_cursor ***/ no_entrypoint, + "LDSQL_set_cursor", + REM_set_cursor_name, + /**** "_REM_set_cursor" ***/ "no_entrypoint", + CSI_set_cursor_name, + /**** RDB_set_cursor ***/ no_entrypoint, + PSI_set_cursor_name, + PSI5_set_cursor_name, + /**** "_jrd8_set_cursor" ***/ no_entrypoint, + IPI_set_cursor_name) + +ENTRYPOINT( "isc_dsql_sql_info", + /**** jrd8_sql_info ***/ no_entrypoint, + "LDSQL_sql_info", + REM_sql_info, + /**** "_REM_sql_info" ***/ "no_entrypoint", + CSI_sql_info, + /**** RDB_sql_info ***/ no_entrypoint, + PSI_sql_info, + PSI5_sql_info, + /**** "_jrd8_sql_info" ***/ no_entrypoint, + IPI_sql_info) /* and service entry points */ - ENTRYPOINT("isc_service_attach", jrd8_service_attach, - /**** "jrd5_service_attach" ***/ NULL, - REM_service_attach, "REM_service_attach", - /**** CSI_service_attach ***/ no_entrypoint, - /**** RDB_service_attach ***/ no_entrypoint, - PSI_attach_service, - /**** PSI5_service_attach ***/ no_entrypoint, - "_jrd8_service_attach", IPI_service_attach) - ENTRYPOINT("isc_service_detach", jrd8_service_detach, - /**** "jrd5_service_detach" ***/ NULL, - REM_service_detach, "REM_service_detach", - /**** CSI_service_detach ***/ no_entrypoint, - /**** RDB_service_detach ***/ no_entrypoint, - PSI_detach_service, - /**** PSI5_service_detach ***/ no_entrypoint, - "_jrd8_service_detach", IPI_service_detach) +ENTRYPOINT( "isc_service_attach", + jrd8_service_attach, + /**** "jrd5_service_attach" ***/ NULL, + REM_service_attach, + "REM_service_attach", + /**** CSI_service_attach ***/ no_entrypoint, + /**** RDB_service_attach ***/ no_entrypoint, + PSI_attach_service, + /**** PSI5_service_attach ***/ no_entrypoint, + "_jrd8_service_attach", + IPI_service_attach) - ENTRYPOINT("isc_service_query", jrd8_service_query, - /**** "jrd5_service_query" ***/ NULL, - REM_service_query, "REM_service_query", - /**** CSI_service_query ***/ no_entrypoint, - /**** RDB_service_query ***/ no_entrypoint, - PSI_query_service, - /**** PSI5_service_query ***/ no_entrypoint, - "_jrd8_service_query", IPI_service_query) +ENTRYPOINT( "isc_service_detach", + jrd8_service_detach, + /**** "jrd5_service_detach" ***/ NULL, + REM_service_detach, + "REM_service_detach", + /**** CSI_service_detach ***/ no_entrypoint, + /**** RDB_service_detach ***/ no_entrypoint, + PSI_detach_service, + /**** PSI5_service_detach ***/ no_entrypoint, + "_jrd8_service_detach", + IPI_service_detach) - ENTRYPOINT("isc_service_start", jrd8_service_start, - /**** "jrd5_service_start" ***/ NULL, - REM_service_start, "REM_service_start", - /**** CSI_service_start ***/ no_entrypoint, - /**** RDB_service_start ***/ no_entrypoint, - /**** PSI_service_start ***/ no_entrypoint, - /**** PSI5_service_start ***/ no_entrypoint, - "_jrd8_service_start", IPI_service_start) +ENTRYPOINT( "isc_service_query", + jrd8_service_query, + /**** "jrd5_service_query" ***/ NULL, + REM_service_query, + "REM_service_query", + /**** CSI_service_query ***/ no_entrypoint, + /**** RDB_service_query ***/ no_entrypoint, + PSI_query_service, + /**** PSI5_service_query ***/ no_entrypoint, + "_jrd8_service_query", + IPI_service_query) + +ENTRYPOINT( "isc_service_start", + jrd8_service_start, + /**** "jrd5_service_start" ***/ NULL, + REM_service_start, + "REM_service_start", + /**** CSI_service_start ***/ no_entrypoint, + /**** RDB_service_start ***/ no_entrypoint, + /**** PSI_service_start ***/ no_entrypoint, + /**** PSI5_service_start ***/ no_entrypoint, + "_jrd8_service_start", + IPI_service_start) + +ENTRYPOINT( "isc_rollback_retaining", + jrd8_rollback_retaining, + /**** "jrd5_rollback_retaining" ***/ NULL, + REM_rollback_retaining, + "_REM_rollback_retaining", + /**** CSI_rollback_retaining ***/ no_entrypoint, + /**** RDB_rollback_retaining ***/ no_entrypoint, + /**** PSI_rollback_retaining ***/ no_entrypoint, + /**** PSI5_rollback_retaining ***/ no_entrypoint, + "_jrd8_rollback_retaining", + IPI_rollback_retaining) - ENTRYPOINT("isc_rollback_retaining", jrd8_rollback_retaining, - /**** "jrd5_rollback_retaining" ***/ NULL, - REM_rollback_retaining, "_REM_rollback_retaining", - /**** CSI_rollback_retaining ***/ no_entrypoint, - /**** RDB_rollback_retaining ***/ no_entrypoint, - /**** PSI_rollback_retaining ***/ no_entrypoint, - /**** PSI5_rollback_retaining ***/ no_entrypoint, - "_jrd8_rollback_retaining", IPI_rollback_retaining) #ifdef CANCEL_OPERATION - ENTRYPOINT("gds_cancel_operation", jrd8_cancel_operation, - /*** "jrd5_cancel_operation" ***/ NULL, - /*** REM_cancel_operation ***/ no_entrypoint, - /*** "REM_cancel_operation" ***/ NULL, - /*** CSI_cancel_operation ***/ no_entrypoint, - /*** RDB_cancel_operation ***/ no_entrypoint, - /*** PSI_cancel_operation ***/ no_entrypoint, - /*** PSI5_cancel_operation ***/ no_entrypoint, - /*** "_jrd8_cancel_operation" ***/ NULL, - /*** IPI_cancel_operation ***/ no_entrypoint) +ENTRYPOINT( "gds_cancel_operation", + jrd8_cancel_operation, + /*** "jrd5_cancel_operation" ***/ NULL, + /*** REM_cancel_operation ***/ no_entrypoint, + /*** "REM_cancel_operation" ***/ NULL, + /*** CSI_cancel_operation ***/ no_entrypoint, + /*** RDB_cancel_operation ***/ no_entrypoint, + /*** PSI_cancel_operation ***/ no_entrypoint, + /*** PSI5_cancel_operation ***/ no_entrypoint, + /*** "_jrd8_cancel_operation" ***/ NULL, + /*** IPI_cancel_operation ***/ no_entrypoint) #else - ENTRYPOINT("gds_cancel_operation", - /*** jrd8_cancel_operation ***/ no_entrypoint, - /*** "jrd5_cancel_operation" ***/ NULL, - /*** REM_cancel_operation ***/ no_entrypoint, - /*** "REM_cancel_operation" ***/ NULL, - /*** CSI_cancel_operation ***/ no_entrypoint, - /*** RDB_cancel_operation ***/ no_entrypoint, - /*** PSI_cancel_operation ***/ no_entrypoint, - /*** PSI5_cancel_operation ***/ no_entrypoint, - /*** "_jrd8_cancel_operation" ***/ NULL, - /*** IPI_cancel_operation ***/ no_entrypoint) +ENTRYPOINT( "gds_cancel_operation", + /*** jrd8_cancel_operation ***/ no_entrypoint, + /*** "jrd5_cancel_operation" ***/ NULL, + /*** REM_cancel_operation ***/ no_entrypoint, + /*** "REM_cancel_operation" ***/ NULL, + /*** CSI_cancel_operation ***/ no_entrypoint, + /*** RDB_cancel_operation ***/ no_entrypoint, + /*** PSI_cancel_operation ***/ no_entrypoint, + /*** PSI5_cancel_operation ***/ no_entrypoint, + /*** "_jrd8_cancel_operation" ***/ NULL, + /*** IPI_cancel_operation ***/ no_entrypoint) #endif + #undef ENTRYPOINT #endif // 0/1 diff --git a/src/jrd/err.cpp b/src/jrd/err.cpp index f442cb4a00..563d6b1a96 100644 --- a/src/jrd/err.cpp +++ b/src/jrd/err.cpp @@ -491,7 +491,7 @@ void DLL_EXPORT ERR_post(STATUS status, ...) #endif -#if ( !defined( REQUESTER) && !defined( SUPERCLIENT)) +#if ( !defined( REQUESTER) && !defined(SUPERCLIENT)) void DLL_EXPORT ERR_punt(void) { /************************************** @@ -504,14 +504,14 @@ void DLL_EXPORT ERR_punt(void) * Error stuff has been copied to status vector. Now punt. * **************************************/ - TDBB tdbb; - DBB dbb; - TEXT *dbname; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; - if (dbb && (dbb->dbb_flags & DBB_bugcheck)) { + TEXT* dbname; + + if (dbb && (dbb->dbb_flags & DBB_bugcheck)) + { #ifndef GATEWAY dbname = ((dbb->dbb_file) ? dbb->dbb_file->fil_string : NULL); #else @@ -520,8 +520,9 @@ void DLL_EXPORT ERR_punt(void) gds__log_status(dbname, tdbb->tdbb_status_vector); } - LONGJMP( (JMP_BUF) tdbb->tdbb_setjmp, - (int) tdbb->tdbb_status_vector[1]); +#pragma FB_COMPILER_MESSAGE("FIXME! C functions can not throw! FIXME!") + + Firebird::status_longjmp_error::raise(tdbb->tdbb_status_vector[1]); } #endif diff --git a/src/jrd/err_proto.h b/src/jrd/err_proto.h index 321be1cc64..837c7b45ab 100644 --- a/src/jrd/err_proto.h +++ b/src/jrd/err_proto.h @@ -25,9 +25,24 @@ #define JRD_ERR_PROTO_H #ifndef REQUESTER -#include "../jrd/jrd.h" -#include "../jrd/btr.h" +/*#include "../jrd/jrd.h" +#include "../jrd/btr.h"*/ +#include "../include/fb_types.h" +/* Index error types */ + +typedef enum idx_e { + idx_e_ok = 0, + idx_e_duplicate, + idx_e_keytoobig, + idx_e_nullunique, + idx_e_conversion, + idx_e_foreign +} IDX_E; + +#define BUGCHECK(number) ERR_bugcheck (number) +#define CORRUPT(number) ERR_corrupt (number) +#define IBERROR(number) ERR_error (number) #ifdef __cplusplus extern "C" { diff --git a/src/jrd/event.cpp b/src/jrd/event.cpp index c1b27bd1a8..da57f42815 100644 --- a/src/jrd/event.cpp +++ b/src/jrd/event.cpp @@ -641,8 +641,9 @@ static FRB alloc_global(UCHAR type, ULONG length, BOOLEAN recurse) } #endif /* WIN_NT */ + EVH header = 0; #if !((defined SUPERSERVER) && (defined MMAP_SUPPORTED)) - EVH header = + header = reinterpret_cast < EVH > (ISC_remap_file(status_vector, &EVENT_data, ev_length, TRUE)); #endif diff --git a/src/jrd/everything.h b/src/jrd/everything.h index 94e49afefe..0ed672c473 100644 --- a/src/jrd/everything.h +++ b/src/jrd/everything.h @@ -16,6 +16,8 @@ * All Rights Reserved. * Contributor(s): ______________________________________. */ +#include "../jrd/common.h" +#include "../jrd/isc.h" #include "../jrd/jrd.h" #include "../jrd/lck.h" #include "../jrd/ods.h" diff --git a/src/jrd/evl.cpp b/src/jrd/evl.cpp index 2865c53ae8..27ab4d3bd6 100644 --- a/src/jrd/evl.cpp +++ b/src/jrd/evl.cpp @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: evl.cpp,v 1.4 2001-07-29 17:42:22 skywalker Exp $ + * $Id: evl.cpp,v 1.5 2001-12-24 02:50:51 tamlin Exp $ */ /* @@ -91,6 +91,9 @@ #include "../jrd/gds_proto.h" #include "../jrd/align.h" +#ifdef DARWIN +#include +#endif extern "C" { @@ -143,7 +146,7 @@ static DSC *lock_state(TDBB, NOD, VLU); static DSC *multiply(DSC *, VLU, NOD); static DSC *multiply2(DSC *, VLU, NOD); static DSC *divide2(DSC *, VLU, NOD); -static DSC *negate(TDBB, DSC *, VLU); +static DSC *negate_dsc(TDBB, DSC *, VLU); static DSC *record_version(TDBB, NOD, VLU); static BOOLEAN reject_duplicate(UCHAR *, UCHAR *, int); static DSC *scalar(TDBB, NOD, VLU); @@ -433,6 +436,10 @@ BOOLEAN DLL_EXPORT EVL_boolean(TDBB tdbb, register NOD node) || (*ptr)->nod_type == nod_ansi_all) request->req_flags |= req_ansi_not; value = EVL_boolean(tdbb, *ptr++); + break; + + default: /* Shut up some compiler warnings */ + break; } /* Evaluate node */ @@ -515,11 +522,11 @@ BOOLEAN DLL_EXPORT EVL_boolean(TDBB tdbb, register NOD node) } RSE_open(tdbb, reinterpret_cast < - struct rsb *>(node->nod_arg[e_any_rsb])); + struct Rsb *>(node->nod_arg[e_any_rsb])); value = RSE_get_record(tdbb, reinterpret_cast < - struct rsb *>(node->nod_arg[e_any_rsb]), + struct Rsb *>(node->nod_arg[e_any_rsb]), #ifdef SCROLLABLE_CURSORS RSE_get_next); #else @@ -527,7 +534,7 @@ BOOLEAN DLL_EXPORT EVL_boolean(TDBB tdbb, register NOD node) #endif RSE_close(tdbb, reinterpret_cast < - struct rsb *>(node->nod_arg[e_any_rsb])); + struct Rsb *>(node->nod_arg[e_any_rsb])); if (node->nod_type == nod_any) request->req_flags &= ~req_null; @@ -632,27 +639,27 @@ BOOLEAN DLL_EXPORT EVL_boolean(TDBB tdbb, register NOD node) } RSE_open(tdbb, - reinterpret_cast < rsb * >(node->nod_arg[e_any_rsb])); - if (value = + reinterpret_cast < Rsb * >(node->nod_arg[e_any_rsb])); + if ( (value = RSE_get_record(tdbb, reinterpret_cast < - rsb * >(node->nod_arg[e_any_rsb]), + Rsb * >(node->nod_arg[e_any_rsb]), #ifdef SCROLLABLE_CURSORS - RSE_get_next)) + RSE_get_next)) ) #else - RSE_get_forward)) + RSE_get_forward)) ) #endif value = !RSE_get_record(tdbb, reinterpret_cast < - rsb * >(node->nod_arg[e_any_rsb]), + Rsb * >(node->nod_arg[e_any_rsb]), #ifdef SCROLLABLE_CURSORS RSE_get_next); #else RSE_get_forward); #endif RSE_close(tdbb, - reinterpret_cast < rsb * >(node->nod_arg[e_any_rsb])); + reinterpret_cast < Rsb * >(node->nod_arg[e_any_rsb])); /* If this is an invariant node, save the return value. */ @@ -690,7 +697,7 @@ BOOLEAN DLL_EXPORT EVL_boolean(TDBB tdbb, register NOD node) } -DSC *DLL_EXPORT EVL_expr(TDBB tdbb, register NOD node) +DSC* DLL_EXPORT EVL_expr(TDBB tdbb, register NOD node) { /************************************** * @@ -767,28 +774,26 @@ DSC *DLL_EXPORT EVL_expr(TDBB tdbb, register NOD node) case nod_field: { - REC record; - - record = - request->req_rpb[(int) node-> - nod_arg[e_fld_stream]].rpb_record; + REC record = + request->req_rpb[(int)node->nod_arg[e_fld_stream]].rpb_record; /* In order to "map a null to a default" value (in EVL_field()), * the relation block is referenced. * Reference: Bug 10116, 10424 */ - if (!EVL_field - (request-> - req_rpb[(USHORT) node->nod_arg[e_fld_stream]].rpb_relation, - record, (USHORT) node->nod_arg[e_fld_id], &impure->vlu_desc)) + if (!EVL_field(request->req_rpb[(USHORT) node->nod_arg[e_fld_stream]].rpb_relation, + record, + (USHORT) node->nod_arg[e_fld_id], + &impure->vlu_desc)) + { request->req_flags |= req_null; + } return &impure->vlu_desc; } case nod_function: - FUN_evaluate(reinterpret_cast < - fun * >(node->nod_arg[e_fun_function]), + FUN_evaluate(reinterpret_cast(node->nod_arg[e_fun_function]), node->nod_arg[e_fun_args], - reinterpret_cast < vlu * >(&impure->vlu_desc)); + reinterpret_cast(&impure->vlu_desc)); return &impure->vlu_desc; case nod_literal: @@ -1036,6 +1041,8 @@ DSC *DLL_EXPORT EVL_expr(TDBB tdbb, register NOD node) impure->vlu_desc.dsc_address = (UCHAR *) & impure->vlu_misc.vlu_long; return &impure->vlu_desc; #endif + default: /* Shut up some compiler warnings */ + break; } { @@ -1087,7 +1094,7 @@ DSC *DLL_EXPORT EVL_expr(TDBB tdbb, register NOD node) return &impure->vlu_desc; case nod_negate: - return negate(tdbb, values[0], impure); + return negate_dsc(tdbb, values[0], impure); case nod_substr: return substring(tdbb, impure, @@ -1132,7 +1139,7 @@ BOOLEAN DLL_EXPORT EVL_field(register REL relation, return FALSE; } - if (format = record->rec_format) + if ( (format = record->rec_format) ) *desc = format->fmt_desc[id]; if (!format || id >= format->fmt_count || !desc->dsc_length) { @@ -1158,11 +1165,9 @@ BOOLEAN DLL_EXPORT EVL_field(register REL relation, MET_scan_relation(tdbb, relation); } - if (temp_field = - reinterpret_cast < - fld * - >(relation->rel_fields-> - vec_object[id])) if (temp_field->fld_default_value + if ( (temp_field = + reinterpret_cast ((fld*)(*relation->rel_fields)[id])) ) + if (temp_field->fld_default_value && temp_field->fld_not_null) { if (temp_field->fld_default_value->nod_type == nod_user_name) { @@ -1399,19 +1404,22 @@ USHORT DLL_EXPORT EVL_group(TDBB tdbb, BLK rsb, NOD node, USHORT state) case nod_literal: /* pjpg 20001124 */ EXE_assignment(tdbb, *ptr); break; + + default: /* Shut up some compiler warnings */ + break; } } /* If there isn't a record pending, open the stream and get one */ if ((state == 0) || (state == 3)) { - RSE_open(tdbb, reinterpret_cast < struct rsb *>(rsb)); + RSE_open(tdbb, reinterpret_cast < struct Rsb *>(rsb)); #ifdef SCROLLABLE_CURSORS if (!RSE_get_record - (tdbb, reinterpret_cast < struct rsb *>(rsb), RSE_get_next)) + (tdbb, reinterpret_cast < struct Rsb *>(rsb), RSE_get_next)) #else if (!RSE_get_record - (tdbb, reinterpret_cast < struct rsb *>(rsb), RSE_get_forward)) + (tdbb, reinterpret_cast < struct Rsb *>(rsb), RSE_get_forward)) #endif { if (group) @@ -1564,7 +1572,7 @@ USHORT DLL_EXPORT EVL_group(TDBB tdbb, BLK rsb, NOD node, USHORT state) if (!RSE_get_record(tdbb, rsb, RSE_get_next)) #else if (!RSE_get_record - (tdbb, reinterpret_cast < struct rsb *>(rsb), RSE_get_forward)) + (tdbb, reinterpret_cast < struct Rsb *>(rsb), RSE_get_forward)) #endif state = 2; } @@ -1574,7 +1582,7 @@ USHORT DLL_EXPORT EVL_group(TDBB tdbb, BLK rsb, NOD node, USHORT state) /* Finish up any residual computations and get out */ if (vtemp.vlu_string) - ALL_release(reinterpret_cast < frb * >(vtemp.vlu_string)); + delete vtemp.vlu_string; for (ptr = map->nod_arg, end = ptr + map->nod_count; ptr < end; ptr++) { from = (*ptr)->nod_arg[e_asgn_from]; @@ -1658,6 +1666,9 @@ USHORT DLL_EXPORT EVL_group(TDBB tdbb, BLK rsb, NOD node, USHORT state) } MOV_move(&temp, EVL_expr(tdbb, field)); break; + + default: /* Shut up some compiler warnings */ + break; } } @@ -1743,12 +1754,12 @@ void DLL_EXPORT EVL_make_value(TDBB tdbb, DSC * desc, VLU value) /* Allocate a string block of sufficient size. */ if ((string = value->vlu_string) && string->str_length < length) { - ALL_release(reinterpret_cast < frb * >(string)); + delete string; string = NULL; } if (!string) { - string = value->vlu_string = (STR) ALLOCDV(type_str, length); + string = value->vlu_string = new(*tdbb->tdbb_default, length) str(); string->str_length = length; } @@ -1804,11 +1815,11 @@ USHORT DLL_EXPORT EVL_mb_contains(TDBB tdbb, &err_pos); if (len1 > sizeof(buffer1)) { - buf1 = (STR) ALLOCDV(type_str, len1); + buf1 = new(*tdbb->tdbb_default, len1) str(); pp1 = (USHORT *) buf1->str_data; } if (len2 > sizeof(buffer2)) { - buf2 = (STR) ALLOCDV(type_str, len2); + buf2 = new(*tdbb->tdbb_default, len2) str(); pp2 = (USHORT *) buf2->str_data; } @@ -1830,9 +1841,9 @@ USHORT DLL_EXPORT EVL_mb_contains(TDBB tdbb, ret_val = EVL_wc_contains(tdbb, obj, pp1, len1, pp2, len2); if (pp1 != buffer1) - ALL_release(reinterpret_cast < frb * >(buf1)); + delete buf1; if (pp2 != buffer2) - ALL_release(reinterpret_cast < frb * >(buf2)); + delete buf2; return ret_val; } @@ -1883,11 +1894,11 @@ USHORT DLL_EXPORT EVL_mb_like(TDBB tdbb, &err_code, &err_pos); if (len1 > sizeof(buffer1)) { - buf1 = (STR) ALLOCDV(type_str, len1); + buf1 = new(*tdbb->tdbb_default, len1) str(); pp1 = (USHORT *) buf1->str_data; } if (len2 > sizeof(buffer2)) { - buf2 = (STR) ALLOCDV(type_str, len2); + buf2 = new(*tdbb->tdbb_default, len2) str(); pp2 = (USHORT *) buf2->str_data; } @@ -1909,9 +1920,9 @@ USHORT DLL_EXPORT EVL_mb_like(TDBB tdbb, ret_val = EVL_wc_like(tdbb, obj, pp1, len1, pp2, len2, escape_char); if (pp1 != buffer1) - ALL_release(reinterpret_cast(buf1)); + delete buf1; if (pp2 != buffer2) - ALL_release(reinterpret_cast(buf2)); + delete buf2; return ret_val; } @@ -1958,11 +1969,11 @@ USHORT DLL_EXPORT EVL_mb_matches(TDBB tdbb, &err_code, &err_pos); if (len1 > sizeof(buffer1)) { - buf1 = (STR) ALLOCDV(type_str, len1); + buf1 = new(*tdbb->tdbb_default, len1) str(); pp1 = (USHORT *) buf1->str_data; } if (len2 > sizeof(buffer2)) { - buf2 = (STR) ALLOCDV(type_str, len2); + buf2 = new(*tdbb->tdbb_default, len2) str(); pp2 = (USHORT *) buf2->str_data; } @@ -1984,9 +1995,9 @@ USHORT DLL_EXPORT EVL_mb_matches(TDBB tdbb, ret_val = EVL_wc_matches(tdbb, obj, pp1, len1, pp2, len2); if (pp1 != buffer1) - ALL_release(reinterpret_cast < frb * >(buf1)); + delete buf1; if (pp2 != buffer2) - ALL_release(reinterpret_cast < frb * >(buf2)); + delete buf2; return ret_val; } @@ -2037,7 +2048,7 @@ USHORT DLL_EXPORT EVL_mb_sleuth_check(TDBB tdbb, &err_code, &err_pos); if (len1 > sizeof(buffer1)) { - buf1 = (STR) ALLOCDV(type_str, len1); + buf1 = new(*tdbb->tdbb_default, len1) str(); pp1 = (USHORT *) buf1->str_data; } @@ -2056,7 +2067,7 @@ USHORT DLL_EXPORT EVL_mb_sleuth_check(TDBB tdbb, match_bytes); if (pp1 != buffer1) - ALL_release(reinterpret_cast < frb * >(buf1)); + delete buf1; return ret_val; } @@ -2111,11 +2122,11 @@ USHORT DLL_EXPORT EVL_mb_sleuth_merge(TDBB tdbb, &err_code, &err_pos); if (len1 > sizeof(buffer1)) { - buf1 = (STR) ALLOCDV(type_str, len1); + buf1 = new(*tdbb->tdbb_default, len1) str(); pp1 = (USHORT *) buf1->str_data; } if (len2 > sizeof(buffer2)) { - buf2 = (STR) ALLOCDV(type_str, len2); + buf2 = new(*tdbb->tdbb_default, len2) str(); pp2 = (USHORT *) buf2->str_data; } @@ -2142,9 +2153,9 @@ USHORT DLL_EXPORT EVL_mb_sleuth_merge(TDBB tdbb, combined_bytes); if (pp1 != buffer1) - ALL_release(reinterpret_cast < frb * >(buf1)); + delete buf1; if (pp2 != buffer2) - ALL_release(reinterpret_cast < frb * >(buf2)); + delete buf2; return ret_val; } @@ -3123,12 +3134,12 @@ static DSC *cast(TDBB tdbb, DSC * value, NOD node, VLU impure) /* Allocate a string block of sufficient size. */ if ((string = impure->vlu_string) && string->str_length < length) { - ALL_release(reinterpret_cast < frb * >(string)); + delete string; string = NULL; } if (!string) { - string = impure->vlu_string = (STR) ALLOCDV(type_str, length); + string = impure->vlu_string = new(*tdbb->tdbb_default, length) str(); string->str_length = length; } @@ -3217,6 +3228,9 @@ static SSHORT compute_agg_distinct(TDBB tdbb, NOD node) ++impure->vlux_count; ++impure->vlu_misc.vlu_long; break; + + default: /* Shut up some warnings */ + break; } } @@ -3315,7 +3329,7 @@ static DSC *concatenate(TDBB tdbb, NOD node, VLU impure) while (--length2); if (temp3) - ALL_release(reinterpret_cast < frb * >(temp3)); + delete temp3; } return &impure->vlu_desc; } @@ -3480,14 +3494,14 @@ static DSC *eval_statistical(TDBB tdbb, NOD node, VLU impure) count = 0; rsb = (BLK) node->nod_arg[e_stat_rsb]; - RSE_open(tdbb, reinterpret_cast < struct rsb *>(rsb)); + RSE_open(tdbb, reinterpret_cast < struct Rsb *>(rsb)); /* Handle each variety separately */ switch (node->nod_type) { case nod_count: flag = 0; - while (RSE_get_record(tdbb, reinterpret_cast < struct rsb *>(rsb), + while (RSE_get_record(tdbb, reinterpret_cast < struct Rsb *>(rsb), #ifdef SCROLLABLE_CURSORS RSE_get_next)) #else @@ -3498,7 +3512,7 @@ static DSC *eval_statistical(TDBB tdbb, NOD node, VLU impure) case nod_count2: flag = 0; - while (RSE_get_record(tdbb, reinterpret_cast < struct rsb *>(rsb), + while (RSE_get_record(tdbb, reinterpret_cast < struct Rsb *>(rsb), #ifdef SCROLLABLE_CURSORS RSE_get_next)) #else @@ -3513,7 +3527,7 @@ static DSC *eval_statistical(TDBB tdbb, NOD node, VLU impure) case nod_min: case nod_max: - while (RSE_get_record(tdbb, reinterpret_cast < struct rsb *>(rsb), + while (RSE_get_record(tdbb, reinterpret_cast < struct Rsb *>(rsb), #ifdef SCROLLABLE_CURSORS RSE_get_next)) #else @@ -3534,7 +3548,7 @@ static DSC *eval_statistical(TDBB tdbb, NOD node, VLU impure) break; case nod_from: - if (RSE_get_record(tdbb, reinterpret_cast < struct rsb *>(rsb), + if (RSE_get_record(tdbb, reinterpret_cast < struct Rsb *>(rsb), #ifdef SCROLLABLE_CURSORS RSE_get_next)) #else @@ -3555,7 +3569,7 @@ static DSC *eval_statistical(TDBB tdbb, NOD node, VLU impure) case nod_average: /* total or average with dialect-1 semantics */ case nod_total: - while (RSE_get_record(tdbb, reinterpret_cast < struct rsb *>(rsb), + while (RSE_get_record(tdbb, reinterpret_cast < struct Rsb *>(rsb), #ifdef SCROLLABLE_CURSORS RSE_get_next)) #else @@ -3588,7 +3602,7 @@ static DSC *eval_statistical(TDBB tdbb, NOD node, VLU impure) break; case nod_average2: /* average with dialect-3 semantics */ - while (RSE_get_record(tdbb, reinterpret_cast < struct rsb *>(rsb), + while (RSE_get_record(tdbb, reinterpret_cast < struct Rsb *>(rsb), #ifdef SCROLLABLE_CURSORS RSE_get_next)) #else @@ -3638,7 +3652,7 @@ static DSC *eval_statistical(TDBB tdbb, NOD node, VLU impure) /* Close stream and return value */ - RSE_close(tdbb, reinterpret_cast < struct rsb *>(rsb)); + RSE_close(tdbb, reinterpret_cast < struct Rsb *>(rsb)); request->req_flags &= ~req_null; request->req_flags |= flag; @@ -4022,7 +4036,6 @@ static DSC *lock_state(TDBB tdbb, NOD node, VLU impure) /* fill out a lock block, zeroing it out first */ MOVE_CLEAR(&temp_lock, sizeof(struct lck)); - temp_lock.lck_header.blk_type = type_lck; temp_lock.lck_parent = dbb->dbb_lock; temp_lock.lck_type = LCK_attachment; temp_lock.lck_owner_handle = @@ -4326,7 +4339,7 @@ static DSC *divide2(DSC * desc, VLU value, NOD node) } -static DSC *negate(TDBB tdbb, DSC * desc, VLU value) +static DSC *negate_dsc(TDBB tdbb, DSC * desc, VLU value) { /************************************** * @@ -4553,10 +4566,10 @@ static SSHORT sleuth(TDBB tdbb, NOD node, DSC * desc1, DSC * desc2) #ifdef STACK_REDUCTION /* do a block allocate */ - temp_str = (STR) ALLOCDV(type_str, ((SLONG) + temp_str = new(*tdbb->tdbb_default, ((SLONG) (sizeof(UCHAR) * (2 * TEMP_LENGTH + BUFFER_LARGE + - BUFFER_SMALL)))); + BUFFER_SMALL)))) str(); temp1 = temp_str->str_data; temp2 = temp1 + TEMP_LENGTH; buffer = temp2 + TEMP_LENGTH; @@ -4640,15 +4653,15 @@ static SSHORT sleuth(TDBB tdbb, NOD node, DSC * desc1, DSC * desc2) } if (data_str) - ALL_release(reinterpret_cast < frb * >(data_str)); + delete data_str; if (sleuth_str) - ALL_release(reinterpret_cast < frb * >(sleuth_str)); + delete sleuth_str; if (match_str) - ALL_release(reinterpret_cast < frb * >(match_str)); + delete match_str; #ifdef STACK_REDUCTION /* block de-alloc all local variables */ - ALL_release(temp_str); + delete temp_str; #endif return ret_val; } @@ -4688,9 +4701,9 @@ static SSHORT string_boolean(TDBB tdbb, NOD node, DSC * desc1, DSC * desc2) #ifdef STACK_REDUCTION /* do a block allocation of local variables */ temp_str = - (STR) ALLOCDV(type_str, + new(*tdbb->tdbb_default, (SLONG) (sizeof(UCHAR) * - (2 * TEMP_LENGTH + BUFFER_LARGE))); + (2 * TEMP_LENGTH + BUFFER_LARGE))) str(); temp1 = temp_str->str_data; temp2 = temp1 + TEMP_LENGTH; buffer = temp2 + TEMP_LENGTH; @@ -4764,11 +4777,11 @@ static SSHORT string_boolean(TDBB tdbb, NOD node, DSC * desc1, DSC * desc2) } if (match_str) - ALL_release(reinterpret_cast < frb * >(match_str)); + delete match_str; #ifdef STACK_REDUCTION /* do a block deallocation of local variables */ - ALL_release(temp_str); + delete temp_str; #endif return ret_val; } @@ -4836,7 +4849,7 @@ static SSHORT string_function( UCHAR *temp3; SET_TDBB(tdbb); - temp_str = (STR) ALLOCDV(type_str, (sizeof(UCHAR) * TEMP_LENGTH)); + temp_str = new(*tdbb->tdbb_default, (sizeof(UCHAR) * TEMP_LENGTH)) str(); temp3 = temp_str->str_data; #endif @@ -4856,7 +4869,7 @@ static SSHORT string_function( ERR_post(gds_like_escape_invalid, 0); #ifdef STACK_REDUCTION - ALL_release(temp_str); + delete temp_str; #endif } return reinterpret_cast < USHORT(*)(...) > diff --git a/src/jrd/exe.cpp b/src/jrd/exe.cpp index 8265338cc1..046a9f15ac 100644 --- a/src/jrd/exe.cpp +++ b/src/jrd/exe.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: exe.cpp,v 1.3 2001-07-29 17:42:22 skywalker Exp $ +$Id: exe.cpp,v 1.4 2001-12-24 02:50:51 tamlin Exp $ */ #include "firebird.h" @@ -77,6 +77,9 @@ $Id: exe.cpp,v 1.3 2001-07-29 17:42:22 skywalker Exp $ #include "TestStck.h" #endif +#ifdef DARWIN +#include +#endif extern "C" { @@ -186,52 +189,60 @@ void EXE_assignment(TDBB tdbb, NOD node) * Perform an assignment * **************************************/ - register REQ request; - DSC *to_desc, *from_desc, *missing, *indicator, temp; - register NOD to; - REC record; - SSHORT null, id, len; + + DSC temp; DEV_BLKCHK(node, type_nod); SET_TDBB(tdbb); - request = tdbb->tdbb_request; + REQ request = tdbb->tdbb_request; BLKCHK(node, type_nod); /* Get descriptors of receiving and sending fields/parmaters, variables, etc. */ - missing = NULL; - if (node->nod_arg[e_asgn_missing]) + DSC* missing = NULL; + if (node->nod_arg[e_asgn_missing]) { missing = EVL_expr(tdbb, node->nod_arg[e_asgn_missing]); + } + + NOD to = node->nod_arg[e_asgn_to]; + DSC* to_desc = EVL_assign_to(tdbb, to); - to = node->nod_arg[e_asgn_to]; - to_desc = EVL_assign_to(tdbb, to); request->req_flags &= ~req_null; - from_desc = EVL_expr(tdbb, node->nod_arg[e_asgn_from]); - null = (request->req_flags & req_null) ? -1 : 0; - if (!null && missing && MOV_compare(missing, from_desc) == 0) + DSC* from_desc = EVL_expr(tdbb, node->nod_arg[e_asgn_from]); + + SSHORT null = (request->req_flags & req_null) ? -1 : 0; + + if (!null && missing && MOV_compare(missing, from_desc) == 0) { null = -1; + } /* If the value is non-missing, move/convert it. Otherwise fill the field with appropriate nulls. */ - if (!null) { + if (!null) + { /* if necessary and appropriate, use the indicator variable */ - if (to->nod_type == nod_argument && to->nod_arg[e_arg_indicator]) { - indicator = EVL_assign_to(tdbb, to->nod_arg[e_arg_indicator]); - temp.dsc_dtype = dtype_short; - temp.dsc_length = sizeof(SSHORT); - temp.dsc_scale = 0; + if (to->nod_type == nod_argument && to->nod_arg[e_arg_indicator]) + { + DSC* indicator = EVL_assign_to(tdbb, to->nod_arg[e_arg_indicator]); + temp.dsc_dtype = dtype_short; + temp.dsc_length = sizeof(SSHORT); + temp.dsc_scale = 0; temp.dsc_sub_type = 0; + SSHORT len; + if ((from_desc->dsc_dtype <= dtype_varying) && (to_desc->dsc_dtype <= dtype_varying) && (TEXT_LEN(from_desc) > TEXT_LEN(to_desc))) + { len = TEXT_LEN(from_desc); - else + } else { len = 0; + } temp.dsc_address = (UCHAR *) & len; MOV_move(&temp, indicator); @@ -239,10 +250,11 @@ void EXE_assignment(TDBB tdbb, NOD node) if (len) { temp = *from_desc; temp.dsc_length = TEXT_LEN(to_desc); - if (temp.dsc_dtype == dtype_cstring) + if (temp.dsc_dtype == dtype_cstring) { temp.dsc_length += 1; - else if (temp.dsc_dtype == dtype_varying) + } else if (temp.dsc_dtype == dtype_varying) { temp.dsc_length += 2; + } from_desc = &temp; } } @@ -281,11 +293,13 @@ void EXE_assignment(TDBB tdbb, NOD node) to_desc->dsc_flags &= ~DSC_null; } else if (node->nod_arg[e_asgn_missing2] && - (missing = EVL_expr(tdbb, node->nod_arg[e_asgn_missing2]))) { + (missing = EVL_expr(tdbb, node->nod_arg[e_asgn_missing2]))) + { MOV_move(missing, to_desc); to_desc->dsc_flags |= DSC_null; } - else { + else + { UCHAR *p; USHORT l; @@ -295,10 +309,11 @@ void EXE_assignment(TDBB tdbb, NOD node) case dtype_text: /* YYY - not necessarily the right thing to do */ /* for text formats that don't have trailing spaces */ - if (l) - do + if (l) { + do { *p++ = ' '; - while (--l); + } while (--l); + } break; case dtype_cstring: @@ -320,15 +335,18 @@ void EXE_assignment(TDBB tdbb, NOD node) /* Handle the null flag as appropriate for fields and message arguments. */ - if (to->nod_type == nod_field) { - id = (USHORT) to->nod_arg[e_fld_id]; - record = request->req_rpb[(int) to->nod_arg[e_fld_stream]].rpb_record; - if (null) + if (to->nod_type == nod_field) + { + SSHORT id = (USHORT) to->nod_arg[e_fld_id]; + REC record = request->req_rpb[(int) to->nod_arg[e_fld_stream]].rpb_record; + if (null) { SET_NULL(record, id); - else + } else { CLEAR_NULL(record, id); + } } - else if (to->nod_type == nod_argument && to->nod_arg[e_arg_flag]) { + else if (to->nod_type == nod_argument && to->nod_arg[e_arg_flag]) + { to_desc = EVL_assign_to(tdbb, to->nod_arg[e_arg_flag]); /* If the null flag is a string with an effective length of one, @@ -337,9 +355,12 @@ void EXE_assignment(TDBB tdbb, NOD node) if (null && to_desc->dsc_dtype <= dtype_varying && to_desc->dsc_length <= - ((to_desc->dsc_dtype == dtype_text) ? 1 : ((to_desc->dsc_dtype == - dtype_cstring) ? 2 : - 3))) null = 1; + ((to_desc->dsc_dtype == dtype_text) ? 1 : + ((to_desc->dsc_dtype == dtype_cstring) ? 2 : + 3))) + { + null = 1; + } temp.dsc_dtype = dtype_short; temp.dsc_length = sizeof(SSHORT); @@ -444,7 +465,7 @@ REQ EXE_find_request(TDBB tdbb, REQ request, BOOLEAN validate) this attachment. If not found, return first inactive request. */ clones = (vector = - request->req_sub_requests) ? (vector->vec_count - 1) : 0; + request->req_sub_requests) ? (vector->count() - 1) : 0; for (n = 1; n <= clones; n++) { next = CMP_clone_request(tdbb, request, n, validate); @@ -543,6 +564,8 @@ void EXE_receive(TDBB tdbb, ERR_post(gds_req_sync, 0); } + try { + if (request->req_flags & req_proc_fetch) { /* request->req_proc_sav_point stores all the request savepoints. @@ -563,16 +586,6 @@ void EXE_receive(TDBB tdbb, old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) - { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - save_sav_point = transaction->tra_save_point; - transaction->tra_save_point = request->req_proc_sav_point; - request->req_proc_sav_point = save_sav_point; - release_proc_save_points(request); - LONGJMP(reinterpret_cast < jmp_buf & >(old_env), -1); - } } if (request->req_message->nod_type == nod_stall @@ -614,6 +627,17 @@ void EXE_receive(TDBB tdbb, VIO_merge_proc_sav_points(tdbb, transaction, &request->req_proc_sav_point); } + + } //try + catch (...) + { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + save_sav_point = transaction->tra_save_point; + transaction->tra_save_point = request->req_proc_sav_point; + request->req_proc_sav_point = save_sav_point; + release_proc_save_points(request); + Firebird::status_longjmp_error::raise(-1); + } } @@ -853,15 +877,14 @@ void EXE_start(TDBB tdbb, REQ request, TRA transaction) if (request->req_invariants) { /* Set all invariants to not computed. */ - NOD *ptr, *end; + vec::iterator ptr, end; USHORT *invariant_flags; VLU impure; - ptr = (NOD *) request->req_invariants->vec_object; - end = ptr + request->req_invariants->vec_count; - for (; ptr < end; ptr++) + for (ptr = request->req_invariants->begin(), + end = request->req_invariants->end(); ptr < end; ptr++) if (*ptr) { - impure = (VLU) ((SCHAR *) request + (*ptr)->nod_impure); + impure = (VLU) ((SCHAR *) request + ((NOD)(*ptr))->nod_impure); invariant_flags = (USHORT *) & impure->vlu_string; *invariant_flags = 0; } @@ -905,8 +928,8 @@ void EXE_unwind(TDBB tdbb, REQ request) * simple since nothing really needs to be done. * **************************************/ - BLK *ptr, *end; - struct plb *old_pool; + vec::iterator ptr, end; + JrdMemoryPool *old_pool; REQ old_request; DEV_BLKCHK(request, type_req); @@ -920,10 +943,10 @@ void EXE_unwind(TDBB tdbb, REQ request) old_request = tdbb->tdbb_request; tdbb->tdbb_request = request; tdbb->tdbb_transaction = request->req_transaction; - for (ptr = request->req_fors->vec_object, end = - ptr + request->req_fors->vec_count; ptr < end; ptr++) + for (ptr = request->req_fors->begin(), end = + request->req_fors->end(); ptr < end; ptr++) if (*ptr) - RSE_close(tdbb, reinterpret_cast < struct rsb *>(*ptr)); + RSE_close(tdbb, reinterpret_cast < class Rsb *>((Rsb*)(*ptr))); tdbb->tdbb_default = old_pool; tdbb->tdbb_request = old_request; } @@ -966,7 +989,7 @@ static NOD erase(TDBB tdbb, NOD node, SSHORT which_trig) FMT format; TRA transaction; #ifdef PC_ENGINE - LCK implicit_lock = NULL, record_locking; + LCK implicit_lock = NULL; RSB rsb = NULL; JMP_BUF env, *old_env; IRSB impure; @@ -1061,11 +1084,15 @@ static NOD erase(TDBB tdbb, NOD node, SSHORT which_trig) mode transaction, we already have an exclusive lock on the table, so don't bother */ - if (!(transaction->tra_flags & TRA_degree3)) { + try { + + if (!(transaction->tra_flags & TRA_degree3)) + { /* check whether record locking is turned on */ - record_locking = RLCK_record_locking(relation); - if (record_locking->lck_physical != LCK_PR) { + LCK record_locking = RLCK_record_locking(relation); + if (record_locking->lck_physical != LCK_PR) + { /* get an implicit lock on the record */ implicit_lock = implicit_record_lock(transaction, rpb); @@ -1075,11 +1102,6 @@ static NOD erase(TDBB tdbb, NOD node, SSHORT which_trig) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - RLCK_unlock_record_implicit(implicit_lock, 0); - LONGJMP(old_env, -1); - } } } #endif @@ -1106,30 +1128,44 @@ static NOD erase(TDBB tdbb, NOD node, SSHORT which_trig) which_trig != PRE_TRIG && (trigger = execute_triggers(tdbb, &relation->rel_post_erase, rpb->rpb_record, 0))) - trigger_failure(tdbb, trigger); + { + trigger_failure(tdbb, trigger); + } /* call IDX_erase (which checks constraints) after all post erase triggers have fired. This is required for cascading referential integrity, which can be implemented as post_erase triggers */ - if (!relation->rel_file & !relation->rel_view_rse) { + if (!relation->rel_file & !relation->rel_view_rse) + { REL bad_relation; USHORT bad_index; - IDX_E error_code; - if (error_code = - IDX_erase(tdbb, rpb, transaction, &bad_relation, - &bad_index)) ERR_duplicate_error(error_code, - bad_relation, - bad_index); + IDX_E error_code = + IDX_erase(tdbb, rpb, transaction, &bad_relation, &bad_index); + + if (error_code) { + ERR_duplicate_error(error_code, bad_relation, bad_index); + } } request->req_records_deleted++; - if (transaction != dbb->dbb_sys_trans) + if (transaction != dbb->dbb_sys_trans) { --transaction->tra_save_point->sav_verb_count; + } #ifdef PC_ENGINE + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (implicit_lock) { + RLCK_unlock_record_implicit(implicit_lock, 0); + } + Firebird::status_longjmp_error::raise(-1); + } + if (implicit_lock) { tdbb->tdbb_setjmp = (UCHAR *) old_env; RLCK_unlock_record_implicit(implicit_lock, 0); @@ -1137,8 +1173,9 @@ static NOD erase(TDBB tdbb, NOD node, SSHORT which_trig) /* if the stream is navigational, it is now positioned on a crack */ - if (rsb) + if (rsb) { RSE_MARK_CRACK(tdbb, rsb, irsb_crack); + } #endif #else VIO_erase(rpb, transaction, node->nod_arg[e_erase_sql]); @@ -1218,14 +1255,14 @@ static void execute_procedure(TDBB tdbb, NOD node) SLONG save_point_number; TRA transaction; JMP_BUF env, *old_env; - struct plb *old_pool; + JrdMemoryPool *old_pool; SET_TDBB(tdbb); BLKCHK(node, type_nod); request = tdbb->tdbb_request; - if (temp = node->nod_arg[e_esp_inputs]) { + if ( (temp = node->nod_arg[e_esp_inputs]) ) { NOD *ptr, *end; for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; @@ -1233,12 +1270,12 @@ static void execute_procedure(TDBB tdbb, NOD node) EXE_assignment(tdbb, *ptr); } - if (in_message = node->nod_arg[e_esp_in_msg]) { + if ( (in_message = node->nod_arg[e_esp_in_msg]) ) { format = (FMT) in_message->nod_arg[e_msg_format]; in_msg_length = format->fmt_length; in_msg = (SCHAR *) request + in_message->nod_impure; } - if (out_message = node->nod_arg[e_esp_out_msg]) { + if ( (out_message = node->nod_arg[e_esp_out_msg]) ) { format = (FMT) out_message->nod_arg[e_msg_format]; out_msg_length = format->fmt_length; out_msg = (SCHAR *) request + out_message->nod_impure; @@ -1251,7 +1288,7 @@ static void execute_procedure(TDBB tdbb, NOD node) format = (FMT) procedure->prc_output_msg->nod_arg[e_msg_format]; out_msg_length = format->fmt_length; temp_buffer = - (STR) ALLOCDV(type_str, out_msg_length + DOUBLE_ALIGN - 1); + new(*tdbb->tdbb_default, out_msg_length + DOUBLE_ALIGN - 1) str(); out_msg = (SCHAR *) FB_ALIGN((U_IPTR) temp_buffer->str_data, DOUBLE_ALIGN); } @@ -1266,17 +1303,7 @@ static void execute_procedure(TDBB tdbb, NOD node) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - tdbb->tdbb_default = old_pool; - tdbb->tdbb_request = request; - EXE_unwind(tdbb, proc_request); - proc_request->req_flags &= ~(req_in_use | req_proc_fetch); - proc_request->req_timestamp = 0; - if (temp_buffer) - ALL_release(reinterpret_cast < frb * >(temp_buffer)); - LONGJMP(reinterpret_cast < jmp_buf & >(old_env), -1); - } + try { transaction = request->req_transaction; save_point_number = transaction->tra_save_point->sav_number; @@ -1302,11 +1329,23 @@ static void execute_procedure(TDBB tdbb, NOD node) VIO_verb_cleanup(tdbb, transaction); } + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + tdbb->tdbb_default = old_pool; + tdbb->tdbb_request = request; + EXE_unwind(tdbb, proc_request); + proc_request->req_flags &= ~(req_in_use | req_proc_fetch); + proc_request->req_timestamp = 0; + delete temp_buffer; + Firebird::status_longjmp_error::raise(-1); + } + tdbb->tdbb_setjmp = (UCHAR *) old_env; tdbb->tdbb_default = old_pool; EXE_unwind(tdbb, proc_request); tdbb->tdbb_request = request; - if (temp = node->nod_arg[e_esp_outputs]) { + if ( (temp = node->nod_arg[e_esp_outputs]) ) { NOD *ptr, *end; for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; @@ -1314,7 +1353,7 @@ static void execute_procedure(TDBB tdbb, NOD node) EXE_assignment(tdbb, *ptr); } if (temp_buffer) - ALL_release(reinterpret_cast < frb * >(temp_buffer)); + delete temp_buffer; proc_request->req_attachment = NULL; proc_request->req_flags &= ~(req_in_use | req_proc_fetch); proc_request->req_timestamp = 0; @@ -1337,7 +1376,8 @@ static REQ execute_triggers( * if any blow up. * **************************************/ - REQ *ptr, *end, result; + REQ result; + vec::iterator ptr, end; VOLATILE REQ trigger = NULL; TRA transaction; VOLATILE VEC vector; @@ -1359,19 +1399,10 @@ static REQ execute_triggers( old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (vector != *triggers) - release_triggers(tdbb, vector); - if (!trigger) - LONGJMP(reinterpret_cast < jmp_buf & >(old_env), -1); - else - return trigger; - } + try { - for (ptr = (REQ *) vector->vec_object, end = ptr + vector->vec_count; - ptr < end; ptr++) { - trigger = EXE_find_request(tdbb, *ptr, FALSE); + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) { + trigger = EXE_find_request(tdbb, (REQ)(*ptr), FALSE); trigger->req_rpb[0].rpb_record = old_rec; trigger->req_rpb[1].rpb_record = new_rec; trigger->req_timestamp = tdbb->tdbb_request->req_timestamp; @@ -1391,6 +1422,18 @@ static REQ execute_triggers( release_triggers(tdbb, vector); return result; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (vector != *triggers) { + release_triggers(tdbb, vector); + } + if (!trigger) { + Firebird::status_longjmp_error::raise(-1); + } + return trigger; + } } #endif @@ -1521,16 +1564,13 @@ static LCK implicit_record_lock(TRA transaction, RPB * rpb) * a record that someone has explicitly locked. * **************************************/ - LCK lock, record_locking; - REL relation; - TDBB tdbb; - tdbb = GET_THREAD_DATA; + TDBB tdbb = GET_THREAD_DATA; DEV_BLKCHK(transaction, type_tra); - relation = rpb->rpb_relation; - record_locking = relation->rel_record_locking; + REL relation = rpb->rpb_relation; + LCK record_locking = relation->rel_record_locking; /* occasionally we should check whether we really still need to do record locking; this is defined as RECORD_LOCK_CHECK_INTERVAL-- @@ -1540,10 +1580,14 @@ static LCK implicit_record_lock(TRA transaction, RPB * rpb) if ((record_locking->lck_physical == LCK_none) && !(relation->rel_lock_total % RECORD_LOCK_CHECK_INTERVAL) && LCK_lock_non_blocking(tdbb, record_locking, LCK_PR, FALSE)) + { return NULL; + } - if (!(lock = RLCK_lock_record_implicit(transaction, rpb, LCK_SW, 0, 0))) + LCK lock = RLCK_lock_record_implicit(transaction, rpb, LCK_SW, 0, 0); + if (!lock) { ERR_post(gds_record_lock, 0); + } return lock; } @@ -1572,7 +1616,7 @@ static NOD looper(TDBB tdbb, REQ request, NOD in_node) VOLATILE NOD node, top_node = NULL, prev_node; TRA transaction; JMP_BUF env, *old_env; - struct plb *old_pool; + JrdMemoryPool *old_pool; #if defined(DEBUG_GDS_ALLOC) && FALSE int node_type; #endif @@ -1630,34 +1674,7 @@ static NOD looper(TDBB tdbb, REQ request, NOD in_node) tdbb->tdbb_setjmp = (UCHAR *) env; error_pending = FALSE; - if (SETJMP(env)) { - /* If the database is already bug-checked, then get out. */ - if (dbb->dbb_flags & DBB_bugcheck) - LONGJMP(reinterpret_cast < jmp_buf & >(old_env), - (int) tdbb->tdbb_status_vector[1]); - -#ifdef GATEWAY - /* Unwind request from connected DBMS's point of view. - Set up special error handling in case something - happens there. */ - - if (!SETJMP(env)) - FRGN_unwind(request); - - /* Continue with normal JRD unwind */ -#endif - - /* Since an error happened, the current savepoint needs to be undone. */ - if (transaction != dbb->dbb_sys_trans) { - ++transaction->tra_save_point->sav_verb_count; - VERB_CLEANUP; - } - - error_pending = TRUE; - tdbb->tdbb_setjmp = (UCHAR *) old_env; - request->req_operation = req::req_unwind; - request->req_label = 0; - } + try { /* Execute stuff until we drop */ @@ -1703,8 +1720,8 @@ static NOD looper(TDBB tdbb, REQ request, NOD in_node) if (variable->vlu_desc.dsc_dtype <= dtype_varying && !variable->vlu_string) { variable->vlu_string = - (STR) ALLOCDV(type_str, - variable->vlu_desc.dsc_length); + new(*tdbb->tdbb_default, + variable->vlu_desc.dsc_length) str(); variable->vlu_string->str_length = variable->vlu_desc.dsc_length; variable->vlu_desc.dsc_address = @@ -1886,7 +1903,7 @@ static NOD looper(TDBB tdbb, REQ request, NOD in_node) VERB_CLEANUP; } } - if (handlers = node->nod_arg[e_blk_handlers]) { + if ( (handlers = node->nod_arg[e_blk_handlers]) ) { ULONG prev_req_error_handler; node = node->nod_parent; @@ -2348,13 +2365,68 @@ static NOD looper(TDBB tdbb, REQ request, NOD in_node) longjmp'ed to the top of looper, and therefore that the last savepoint has already been deleted */ - if (request->req_flags & req_abort) - ERR_post(gds_req_sync, 0); + if (request->req_flags & req_abort) { + ERR_post(gds_req_sync, 0); + } + + } // try + catch (...) { + /* If the database is already bug-checked, then get out. */ + if (dbb->dbb_flags & DBB_bugcheck) { + Firebird::status_longjmp_error::raise(tdbb->tdbb_status_vector[1]); + } + +#ifdef GATEWAY + try { + + /* Unwind request from connected DBMS's point of view. + Set up special error handling in case something + happens there. */ + + FRGN_unwind(request); + + /* Continue with normal JRD unwind */ + + } // try + catch (...) { + } + +#endif + + /* Since an error happened, the current savepoint needs to be undone. */ + if (transaction != dbb->dbb_sys_trans) { + ++transaction->tra_save_point->sav_verb_count; + VERB_CLEANUP; + } + + error_pending = TRUE; + tdbb->tdbb_setjmp = (UCHAR *) old_env; + request->req_operation = req::req_unwind; + request->req_label = 0; + } return node; } +#ifdef PC_ENGINE +// TMN: Quick wrapper to remove one try/catch +class LCK_RAII_wrapper +{ + explicit LCK_RAII_wrapper(LCK lock) : l(lock) {} + ~LCK_RAII_wrapper() { + if (l) { + } + } + + LCK l; + +private: + LCK_RAII_wrapper(const LCK_RAII_wrapper&); // no impl. + void operator=(const LCK_RAII_wrapper&); // no impl. +}; +#endif + static NOD modify(TDBB tdbb, register NOD node, SSHORT which_trig) { /************************************** @@ -2468,20 +2540,19 @@ static NOD modify(TDBB tdbb, register NOD node, SSHORT which_trig) will be able to read or write the record but not when an explicit lock has been taken out */ - if (!(transaction->tra_flags & TRA_degree3)) { + try { + + if (!(transaction->tra_flags & TRA_degree3)) + { record_locking = RLCK_record_locking(relation); - if (record_locking->lck_physical != LCK_PR) { + if (record_locking->lck_physical != LCK_PR) + { implicit_lock = implicit_record_lock(transaction, org_rpb); /* set up to catch any errors so that we can release the lock */ old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - RLCK_unlock_record_implicit(implicit_lock, 0); - LONGJMP(old_env, -1); - } } } #endif @@ -2494,29 +2565,35 @@ static NOD modify(TDBB tdbb, register NOD node, SSHORT which_trig) (trigger = execute_triggers(tdbb, &relation->rel_pre_modify, org_rpb->rpb_record, new_rpb->rpb_record))) - trigger_failure(tdbb, trigger); + { + trigger_failure(tdbb, trigger); + } - if (node->nod_arg[e_mod_validate]) + if (node->nod_arg[e_mod_validate]) { validate(tdbb, node->nod_arg[e_mod_validate]); + } if (relation->rel_file) + { EXT_modify(org_rpb, new_rpb, - reinterpret_cast < int *>(transaction)); - else if (!relation->rel_view_rse) { + reinterpret_cast(transaction)); + } + else if (!relation->rel_view_rse) + { SSHORT bad_index; REL bad_relation; IDX_E error_code; VIO_modify(tdbb, org_rpb, new_rpb, transaction); - if (error_code = IDX_modify(tdbb, - org_rpb, - new_rpb, - transaction, - &bad_relation, - reinterpret_cast < - USHORT * - >(&bad_index))) - ERR_duplicate_error(error_code, bad_relation, bad_index); + error_code = IDX_modify(tdbb, + org_rpb, + new_rpb, + transaction, + &bad_relation, + reinterpret_cast(&bad_index)); + if (error_code) { + ERR_duplicate_error(error_code, bad_relation, bad_index); + } } if (relation->rel_post_modify && @@ -2524,32 +2601,46 @@ static NOD modify(TDBB tdbb, register NOD node, SSHORT which_trig) (trigger = execute_triggers(tdbb, &relation->rel_post_modify, org_rpb->rpb_record, new_rpb->rpb_record))) - trigger_failure(tdbb, trigger); + { + trigger_failure(tdbb, trigger); + } /* now call IDX_modify_check_constrints after all post modify triggers have fired. This is required for cascading referential integrity, which can be implemented as post_erase triggers */ - if (!relation->rel_file && !relation->rel_view_rse) { + if (!relation->rel_file && !relation->rel_view_rse) + { SSHORT bad_index; REL bad_relation; IDX_E error_code; - if (error_code = IDX_modify_check_constraints(tdbb, + if ( (error_code = IDX_modify_check_constraints(tdbb, org_rpb, new_rpb, transaction, &bad_relation, reinterpret_cast < USHORT * - >(&bad_index))) + >(&bad_index))) ) ERR_duplicate_error(error_code, bad_relation, bad_index); } - if (transaction != dbb->dbb_sys_trans) + if (transaction != dbb->dbb_sys_trans) { --transaction->tra_save_point->sav_verb_count; + } #ifdef PC_ENGINE + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (implicit_lock) { + RLCK_unlock_record_implicit(implicit_lock, 0); + } + Firebird::status_longjmp_error::raise(-1); + } + if (implicit_lock) { tdbb->tdbb_setjmp = (UCHAR *) old_env; RLCK_unlock_record_implicit(implicit_lock, 0); @@ -2710,7 +2801,7 @@ static void release_blobs(TDBB tdbb, REQ request) SET_TDBB(tdbb); DEV_BLKCHK(request, type_req); - if (transaction = request->req_transaction) { + if ( (transaction = request->req_transaction) ) { DEV_BLKCHK(transaction, type_tra); /* Release blobs assigned by this request */ @@ -2805,21 +2896,20 @@ static void release_triggers(TDBB tdbb, VEC vector) * Release vector of triggers if inactive. * **************************************/ - REQ *ptr, *end; + vec::iterator ptr, end; SET_TDBB(tdbb); - for (ptr = (REQ *) vector->vec_object, end = ptr + vector->vec_count; - ptr < end; ptr++) - if (*ptr && CMP_clone_active(*ptr)) + // JMB todo: Fix data type in the vector + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) + if (*ptr && CMP_clone_active((REQ)(*ptr))) return; - for (ptr = (REQ *) vector->vec_object, end = ptr + vector->vec_count; - ptr < end; ptr++) + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) if (*ptr) - CMP_release(tdbb, *ptr); + CMP_release(tdbb, (REQ)(*ptr)); - ALL_release(reinterpret_cast < frb * >(vector)); + delete vector; } @@ -3403,7 +3493,7 @@ static NOD store(TDBB tdbb, register NOD node, SSHORT which_trig) continue; p = record->rec_data + (SLONG) desc->dsc_address; if (TEST_NULL(record, n)) { - if (length = desc->dsc_length) + if ( (length = desc->dsc_length) ) do *p++ = 0; while (--length); @@ -3414,7 +3504,7 @@ static NOD store(TDBB tdbb, register NOD node, SSHORT which_trig) vary = (VARY *) p; if ((length = desc->dsc_length - sizeof(USHORT)) > vary->vary_length) { - p = vary->vary_string + vary->vary_length; + p = reinterpret_cast(vary->vary_string + vary->vary_length); length -= vary->vary_length; do *p++ = 0; @@ -3482,7 +3572,7 @@ static NOD store(TDBB tdbb, register NOD node, SSHORT which_trig) #ifndef GATEWAY p = record->rec_data; - if (n = (format->fmt_count + 7) >> 3) + if ( (n = (format->fmt_count + 7) >> 3) ) do *p++ = 0xff; while (--n); @@ -3703,8 +3793,8 @@ static void validate(TDBB tdbb, NOD list) relation = request->req_rpb[stream].rpb_relation; if ((vector = relation->rel_fields) && - id < vector->vec_count && - (field = (FLD) vector->vec_object[id])) + id < vector->count() && + (field = (FLD) (*vector)[id])) { name = field->fld_name; } diff --git a/src/jrd/exe.h b/src/jrd/exe.h index 2d8e0010db..05b57cccc8 100644 --- a/src/jrd/exe.h +++ b/src/jrd/exe.h @@ -24,6 +24,10 @@ #ifndef _JRD_EXE_H_ #define _JRD_EXE_H_ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" +#include "../include/fb_vector.h" + #define NODE(type, name, keyword) type, typedef ENUM nod_t { @@ -39,16 +43,29 @@ typedef ENUM nod_t { exactly the same way as structure nod through item nod_count. If you change one, be sure to change all of them. */ -typedef struct nod { - struct blk nod_header; - struct nod *nod_parent; - SLONG nod_impure; /* Inpure offset from request block */ - NOD_T nod_type; /* Type of node */ - UCHAR nod_flags; - SCHAR nod_scale; /* Target scale factor */ - USHORT nod_count; /* Number of arguments */ - struct nod *nod_arg[1]; -} *NOD; +class nod : public pool_alloc_rpt +{ +public: + nod() + : nod_parent(0), + nod_impure(0), + nod_type(nod_nop), + nod_flags(0), + nod_scale(0), + nod_count(0) + { + nod_arg[0] = 0; + } + + nod* nod_parent; + SLONG nod_impure; /* Inpure offset from request block */ + NOD_T nod_type; /* Type of node */ + UCHAR nod_flags; + SCHAR nod_scale; /* Target scale factor */ + USHORT nod_count; /* Number of arguments */ + nod* nod_arg[1]; +}; +typedef nod* NOD; #define nod_comparison 1 #define nod_id 1 /* marks a field node as a blr_fid guy */ @@ -65,28 +82,30 @@ typedef struct nod { /* Special RSE node */ -typedef struct rse { - struct blk nod_header; - struct nod *nod_parent; - SLONG nod_impure; /* Inpure offset from request block */ - NOD_T nod_type; /* Type of node */ - UCHAR nod_flags; - SCHAR nod_scale; /* Target scale factor */ - USHORT nod_count; /* Number of arguments */ - USHORT rse_count; - USHORT rse_jointype; /* inner, left, right, full */ +class rse : public pool_alloc_rpt +{ +public: + nod* nod_parent; + SLONG nod_impure; /* Inpure offset from request block */ + NOD_T nod_type; /* Type of node */ + UCHAR nod_flags; + SCHAR nod_scale; /* Target scale factor */ + USHORT nod_count; /* Number of arguments */ + USHORT rse_count; + USHORT rse_jointype; /* inner, left, right, full */ struct rsb *rse_rsb; - struct nod *rse_first; - struct nod *rse_boolean; - struct nod *rse_sorted; - struct nod *rse_projection; - struct nod *rse_aggregate; /* singleton aggregate for optimizing to index */ - struct nod *rse_plan; /* user-specified access plan */ + nod* rse_first; + nod* rse_boolean; + nod* rse_sorted; + nod* rse_projection; + nod* rse_aggregate; /* singleton aggregate for optimizing to index */ + nod* rse_plan; /* user-specified access plan */ #ifdef SCROLLABLE_CURSORS - struct nod *rse_async_message; /* asynchronous message to send for scrolling */ + nod* rse_async_message; /* asynchronous message to send for scrolling */ #endif - struct nod *rse_relation[1]; -} *RSE; + nod* rse_relation[1]; +}; +typedef rse* RSE; #define rse_stream 1 /* flags rse-type node as a blr_stream type */ #define rse_singular 2 /* flags rse-type node as from a singleton select */ @@ -97,35 +116,39 @@ typedef struct rse { /* Literal value */ -typedef struct lit { - struct blk nod_header; - struct nod *nod_parent; - SLONG nod_impure; /* Inpure offset from request block */ - NOD_T nod_type; /* Type of node */ - UCHAR nod_flags; - SCHAR nod_scale; /* Target scale factor */ - USHORT nod_count; /* Number of arguments */ - struct dsc lit_desc; - UCHAR lit_data[1]; -} *LIT; +class lit : public pool_alloc +{ +public: + nod* nod_parent; + SLONG nod_impure; /* Inpure offset from request block */ + NOD_T nod_type; /* Type of node */ + UCHAR nod_flags; + SCHAR nod_scale; /* Target scale factor */ + USHORT nod_count; /* Number of arguments */ + dsc lit_desc; + UCHAR lit_data[1]; +}; +typedef lit* LIT; -#define lit_delta (sizeof (struct dsc) / sizeof (NOD*)) +#define lit_delta (sizeof(dsc) / sizeof(NOD*)) /* Aggregate Sort Block (for DISTINCT aggregates) */ -typedef struct asb { - struct blk nod_header; - struct nod *nod_parent; - SLONG nod_impure; /* Impure offset from request block */ - NOD_T nod_type; /* Type of node */ - UCHAR nod_flags; - SCHAR nod_scale; - USHORT nod_count; - struct dsc asb_desc; - struct skd *asb_key_desc; /* for the aggregate */ - UCHAR asb_key_data[1]; -} *ASB; +class asb : public pool_alloc +{ +public: + nod* nod_parent; + SLONG nod_impure; /* Impure offset from request block */ + NOD_T nod_type; /* Type of node */ + UCHAR nod_flags; + SCHAR nod_scale; + USHORT nod_count; + dsc asb_desc; + struct skd* asb_key_desc; /* for the aggregate */ + UCHAR asb_key_data[1]; +}; +typedef asb* ASB; #define asb_delta ((sizeof(struct asb) - sizeof(struct nod)) / sizeof (NOD*)) @@ -200,7 +223,7 @@ typedef struct vluk { /* Inversion (i.e. nod_index) impure area */ typedef struct inv { - struct sbm *inv_bitmap; + struct sbm* inv_bitmap; } *INV; @@ -497,63 +520,124 @@ typedef struct iasb { * since it's part of the C API. Compiling as C++ would enclose it. */ -struct csb_repeat { +struct csb_repeat +{ + // We must zero-initialize this one + csb_repeat() + : csb_stream(0), + csb_view_stream(0), + csb_flags(0), + csb_indices(0), + csb_relation(0), + csb_alias(0), + csb_procedure(0), + csb_view(0), + csb_idx(0), + csb_idx_allocation(0), + csb_message(0), + csb_format(0), + csb_fields(0), +#ifndef GATEWAY + csb_cardinality(0.0f), // TMN: Non-natural cardinality?! + csb_plan(0), +#else + csb_asgn_flds(0), + csb_selct_rsb(0), + csb_selct_bool(0), + csb_selct_sort(0), + csb_sql_selct(0), + csb_other_nod(0), + csb_sql_other(0), +#endif + csb_map(0), + csb_rsb_ptr(0) + {} + UCHAR csb_stream; /* Map user context to internal stream */ UCHAR csb_view_stream; /* stream number for view relation, below */ USHORT csb_flags; USHORT csb_indices; /* Number of indices */ - struct rel *csb_relation; - struct str *csb_alias; /* SQL alias name for this instance of relation */ - struct prc *csb_procedure; - struct rel *csb_view; /* parent view */ + struct rel* csb_relation; + struct str* csb_alias; /* SQL alias name for this instance of relation */ + struct prc* csb_procedure; + struct rel* csb_view; /* parent view */ - struct idx *csb_idx; /* Packed description of indices */ - struct str *csb_idx_allocation; /* Memory allocated to hold index descriptions */ - struct nod *csb_message; /* Msg for send/receive */ - struct fmt *csb_format; /* Default fmt for stream */ - struct sbm *csb_fields; /* Fields referenced */ + struct idx* csb_idx; /* Packed description of indices */ + struct str* csb_idx_allocation; /* Memory allocated to hold index descriptions */ + nod* csb_message; /* Msg for send/receive */ + struct fmt* csb_format; /* Default fmt for stream */ + struct sbm* csb_fields; /* Fields referenced */ #ifndef GATEWAY float csb_cardinality; /* Cardinality of relation */ - struct nod *csb_plan; /* user-specified plan for this relation */ + nod* csb_plan; /* user-specified plan for this relation */ #else - struct sbm *csb_asgn_flds; /* Fields that are assigned from */ - struct rsb *csb_selct_rsb; /* SELECT statement's rsb */ - struct nod *csb_selct_bool; /* SELECT statement's boolean */ - struct nod *csb_selct_sort; /* SELECT statement's sort clause */ - struct sql *csb_sql_selct; /* SELECT statement */ - struct nod *csb_other_nod; /* non-SELECT statement's node */ - struct sql *csb_sql_other; /* non-SELECT statement */ + struct sbm* csb_asgn_flds; /* Fields that are assigned from */ + struct rsb* csb_selct_rsb; /* SELECT statement's rsb */ + nod* csb_selct_bool; /* SELECT statement's boolean */ + nod* csb_selct_sort; /* SELECT statement's sort clause */ + struct sql* csb_sql_selct; /* SELECT statement */ + nod* csb_other_nod; /* non-SELECT statement's node */ + struct sql* csb_sql_other; /* non-SELECT statement */ #endif - UCHAR *csb_map; /* Stream map for views */ - struct rsb **csb_rsb_ptr; /* point to rsb for nod_stream */ + UCHAR* csb_map; /* Stream map for views */ + struct rsb** csb_rsb_ptr; /* point to rsb for nod_stream */ }; -typedef struct csb { - struct blk csb_header; - UCHAR *csb_blr; - UCHAR *csb_running; - struct nod *csb_node; - struct acc *csb_access; /* Access items to be checked */ - struct vec *csb_variables; /* Vector of variables, if any */ - struct rsc *csb_resources; /* Resources (relations and indexes) */ - struct lls *csb_dependencies; /* objects this request depends upon */ - struct lls *csb_fors; /* stack of fors */ - struct lls *csb_invariants; /* stack of invariant nodes */ - struct lls *csb_current_rses; /* rse's within whose scope we are */ +class Csb : public pool_alloc +{ +public: + Csb(MemoryPool& p, size_t len) + : csb_blr(0), + csb_running(0), + csb_node(0), + csb_access(0), + csb_variables(0), + csb_resources(0), + csb_dependencies(0), + csb_fors(0), + csb_invariants(0), + csb_current_rses(0), #ifdef SCROLLABLE_CURSORS - struct rse *csb_current_rse; /* this holds the rse currently being processed; + csb_current_rse(0), +#endif + csb_async_message(0), + csb_count(0), + csb_n_stream(0), + csb_msg_number(0), + csb_impure(0), + csb_g_flags(0), + csb_rpt(len, p, type_csb) + {} + + static Csb* newCsb(MemoryPool& p, size_t len) + { return new(p) Csb(p, len); } + + UCHAR* csb_blr; + UCHAR* csb_running; + nod* csb_node; + struct acc* csb_access; /* Access items to be checked */ + struct vec* csb_variables; /* Vector of variables, if any */ + class Rsc* csb_resources; /* Resources (relations and indexes) */ + struct lls* csb_dependencies; /* objects this request depends upon */ + struct lls* csb_fors; /* stack of fors */ + struct lls* csb_invariants; /* stack of invariant nodes */ + struct lls* csb_current_rses; /* rse's within whose scope we are */ +#ifdef SCROLLABLE_CURSORS + struct rse* csb_current_rse; /* this holds the rse currently being processed; unlike the current_rses stack, it references any expanded view rse */ #endif - struct nod *csb_async_message; /* asynchronous message to send to request */ - USHORT csb_count; /* Current tail count */ - USHORT csb_n_stream; /* Next available stream */ - USHORT csb_msg_number; /* Highest used message number */ - SLONG csb_impure; /* Next offset into impure area */ - USHORT csb_g_flags; - struct csb_repeat csb_rpt[1]; -} *CSB; + nod* csb_async_message; /* asynchronous message to send to request */ + USHORT csb_count; /* Current tail count */ + USHORT csb_n_stream; /* Next available stream */ + USHORT csb_msg_number; /* Highest used message number */ + SLONG csb_impure; /* Next offset into impure area */ + USHORT csb_g_flags; + typedef Firebird::vector::iterator rpt_itr; + Firebird::vector csb_rpt; +}; +typedef Csb* CSB; #define csb_internal 0x1 /* "csb_g_flag" switch */ #define csb_get_dependencies 0x2 @@ -578,15 +662,18 @@ typedef struct csb { /* Exception condition list */ - -typedef struct xcp { - struct blk xcp_header; - SLONG xcp_count; struct xcp_repeat { SSHORT xcp_type; SLONG xcp_code; - } xcp_rpt[1]; -} *XCP; + }; + +class xcp : public pool_alloc_rpt +{ + public: + SLONG xcp_count; + xcp_repeat xcp_rpt[1]; +}; +typedef xcp *XCP; #define xcp_sql_code 1 #define xcp_gds_code 2 diff --git a/src/jrd/ext.cpp b/src/jrd/ext.cpp index d119aff57d..2ed74e5068 100644 --- a/src/jrd/ext.cpp +++ b/src/jrd/ext.cpp @@ -133,8 +133,8 @@ EXT EXT_file(REL relation, TEXT * file_name, SLONG * description) EXT_fini(relation); } relation->rel_file = file = - (EXT) ALLOCPV(type_ext, strlen(file_name) + 1); - strcpy(reinterpret_cast < char *>(file->ext_filename), file_name); + new(*dbb->dbb_permanent, (strlen(file_name) + 1)) ext(); + strcpy(reinterpret_cast(file->ext_filename), file_name); file->ext_flags = 0; file->ext_ifi = (int *) NULL; @@ -181,7 +181,7 @@ void EXT_fini(REL relation) if (file->ext_ifi) ib_fclose((IB_FILE *) file->ext_ifi); /* before zeroing out the rel_file we need to deallocate the memory */ - ALL_release(reinterpret_cast < frb * >(relation->rel_file)); + delete relation->rel_file; relation->rel_file = 0; } } @@ -207,10 +207,11 @@ int EXT_get(RSB rsb) REC record; FMT format; LIT literal; - DSC *desc_ptr, desc; FLD field, *field_ptr; + DSC desc; SSHORT c, l, offset, i; UCHAR *p; + vec::iterator itr; tdbb = GET_THREAD_DATA; @@ -248,14 +249,15 @@ int EXT_get(RSB rsb) /* Loop thru fields setting missing fields to either blanks/zeros or the missing value */ - field_ptr = (FLD *) relation->rel_fields->vec_object; - desc_ptr = format->fmt_desc; + fmt::fmt_desc_iterator desc_ptr = format->fmt_desc.begin(); - for (i = 0; i < format->fmt_count; i++, field_ptr++, desc_ptr++) { + for (i = 0, itr = relation->rel_fields->begin(); + i < format->fmt_count; i++, itr++, desc_ptr++) { + field_ptr = (FLD *) (*itr); SET_NULL(record, i); if (!desc_ptr->dsc_length || !(field = *field_ptr)) continue; - if (literal = (LIT) field->fld_missing_value) { + if ( (literal = (LIT) field->fld_missing_value) ) { desc = *desc_ptr; desc.dsc_address = record->rec_data + (int) desc.dsc_address; if (!MOV_compare(&literal->lit_desc, &desc)) @@ -336,7 +338,7 @@ RSB EXT_optimize(register OPT opt, SSHORT stream, NOD * sort_ptr) TDBB tdbb; register CSB csb; REL relation; - RSB rsb; + RSB rsb_; /* all these are un refrenced due to the code commented below NOD node, inversion; register opt::opt_repeat *tail, *opt_end; @@ -383,16 +385,16 @@ if (opt->opt_count) */ - rsb = (RSB) ALLOCDV(type_rsb, 0); - rsb->rsb_type = rsb_ext_sequential; + rsb_ = new(*tdbb->tdbb_default,0) Rsb; + rsb_->rsb_type = rsb_ext_sequential; size = sizeof(struct irsb); - rsb->rsb_stream = stream; - rsb->rsb_relation = relation; - rsb->rsb_impure = csb->csb_impure; + rsb_->rsb_stream = stream; + rsb_->rsb_relation = relation; + rsb_->rsb_impure = csb->csb_impure; csb->csb_impure += size; - return rsb; + return rsb_; } @@ -427,9 +429,9 @@ void EXT_store(RPB * rpb, int *transaction) REC record; FMT format; EXT file; - FLD *field_ptr, field; + FLD field; LIT literal; - DSC desc, *desc_ptr; + DSC desc; UCHAR *p; USHORT i, l, offset; @@ -459,15 +461,19 @@ void EXT_store(RPB * rpb, int *transaction) gds_arg_gds, gds_ext_readonly_err, 0); } - field_ptr = (FLD *) relation->rel_fields->vec_object; - desc_ptr = format->fmt_desc; + vec::iterator field_ptr = relation->rel_fields->begin(); + fmt::fmt_desc_iterator desc_ptr = format->fmt_desc.begin(); for (i = 0; i < format->fmt_count; i++, field_ptr++, desc_ptr++) - if ((field = *field_ptr) && + { + field = (FLD)*field_ptr; + if (field && !field->fld_computation && - desc_ptr->dsc_length && TEST_NULL(record, i)) { + desc_ptr->dsc_length && + TEST_NULL(record, i)) + { p = record->rec_data + (int) desc_ptr->dsc_address; - if (literal = (LIT) field->fld_missing_value) { + if ( (literal = (LIT) field->fld_missing_value) ) { desc = *desc_ptr; desc.dsc_address = p; MOV_move(&literal->lit_desc, &desc); @@ -480,6 +486,7 @@ void EXT_store(RPB * rpb, int *transaction) while (--l); } } + } offset = (USHORT) format->fmt_desc[0].dsc_address; p = record->rec_data + offset; diff --git a/src/jrd/ext.h b/src/jrd/ext.h index 5f65dd951f..385c2431db 100644 --- a/src/jrd/ext.h +++ b/src/jrd/ext.h @@ -26,8 +26,9 @@ /* External file access block */ -typedef struct ext { - struct blk ext_header; +class ext : public pool_alloc_rpt +{ + public: struct fmt *ext_format; /* External format */ UCHAR *ext_stuff; /* Random stuff */ USHORT ext_flags; /* Misc and cruddy flags */ @@ -44,7 +45,8 @@ typedef struct ext { UCHAR *ext_indices; /* Index descriptions */ UCHAR ext_dbkey[8]; /* DBKEY */ UCHAR ext_filename[1]; -} *EXT; +}; +typedef ext *EXT; #define EXT_opened 1 /* File has been opened */ #define EXT_eof 2 /* Positioned at EOF */ diff --git a/src/jrd/ext_proto.h b/src/jrd/ext_proto.h index b73c6d00f5..a79bb1e3bc 100644 --- a/src/jrd/ext_proto.h +++ b/src/jrd/ext_proto.h @@ -28,18 +28,18 @@ extern "C" { #endif -extern void EXT_close(struct rsb *); +extern void EXT_close(class Rsb *); extern void EXT_erase(struct rpb *, int *); extern struct ext *EXT_file(struct rel *, TEXT *, SLONG *); extern void EXT_fini(struct rel *); -extern int EXT_get(struct rsb *); +extern int EXT_get(class Rsb *); extern void EXT_modify(struct rpb *, struct rpb *, int *); #ifdef VMS -extern int EXT_open(struct rsb *); +extern int EXT_open(class Rsb *); #else -extern void EXT_open(struct rsb *); +extern void EXT_open(class Rsb *); #endif -extern struct rsb *EXT_optimize(register struct opt *, SSHORT, struct nod **); +extern class Rsb *EXT_optimize(register class Opt *, SSHORT, struct nod **); extern void EXT_ready(struct rel *); extern void EXT_store(struct rpb *, int *); extern void EXT_trans_commit(struct tra *); diff --git a/src/jrd/extvms.cpp b/src/jrd/extvms.cpp index f33f56f59e..a8ccbbe84e 100644 --- a/src/jrd/extvms.cpp +++ b/src/jrd/extvms.cpp @@ -169,7 +169,7 @@ EXT EXT_file(REL relation, TEXT * file_name, SLONG * description) format. */ l = strlen(file_name); - relation->rel_file = file = ALLOCPV(type_ext, l); + relation->rel_file = file = new(dbb->dbb_permanent, l) ext(); strcpy(file->ext_filename, file_name); format = file->ext_format = MET_format(tdbb, relation, 0); expand_format(format, MET_current(tdbb, relation)); @@ -243,7 +243,7 @@ EXT EXT_file(REL relation, TEXT * file_name, SLONG * description) index = (IDX *) (index->idx_rpt + index->idx_count); } if (l = (UCHAR *) index - index_buffer) { - string = (STR) ALLOCDV(type_str, l); + string = new(tdbb->tdbb_default, l) str(); MOVE_FAST(index_buffer, string->str_data, l); file->ext_indices = string->str_data; } @@ -486,21 +486,21 @@ RSB EXT_optimize(register OPT opt, SSHORT stream, NOD * sort_ptr) block */ if (dbkey) { - rsb = (RSB) ALLOCDV(type_rsb, 1); + rsb = new(tdbb->tdbb_default, 1) rsb(); rsb->rsb_type = rsb_ext_dbkey; rsb->rsb_count = 1; size = sizeof(struct irsb_index); rsb->rsb_arg[0] = (RSB) dbkey; } else if (inversion) { - rsb = (RSB) ALLOCDV(type_rsb, 1); + rsb = new(tdbb->tdbb_default, 1) rsb(); rsb->rsb_type = rsb_ext_indexed; rsb->rsb_count = 1; size = sizeof(struct irsb_index); rsb->rsb_arg[0] = (RSB) inversion; } else { - rsb = (RSB) ALLOCDV(type_rsb, 0); + rsb = new(tdbb->tdbb_default) rsb(); rsb->rsb_type = rsb_ext_sequential; size = sizeof(struct irsb); } diff --git a/src/jrd/file_params.h b/src/jrd/file_params.h index e9968060b0..15979634a6 100644 --- a/src/jrd/file_params.h +++ b/src/jrd/file_params.h @@ -128,6 +128,7 @@ #else #ifdef DARWIN #define ISC_PREFIX "/all/files/are/in/framework/resources" +/* #define ISC_PREFIX "/tmp" */ #define DARWIN_GEN_DIR "var" #define DARWIN_FRAMEWORK_ID "com.firebird.Firebird2" #else diff --git a/src/jrd/filters.cpp b/src/jrd/filters.cpp index 0c417f4cee..19e3a912df 100644 --- a/src/jrd/filters.cpp +++ b/src/jrd/filters.cpp @@ -658,11 +658,9 @@ STATUS filter_transliterate_text(USHORT action, CTL control) * **************************************/ CTL source; - TEXT *p, *left_over; - USHORT length, l, left_length, buffer_used; + USHORT length; USHORT unused_len; STATUS status; - USHORT outlen; SSHORT err_code; USHORT err_position; SSHORT can_use_more; diff --git a/src/jrd/flu.cpp b/src/jrd/flu.cpp index 5d62872e78..448c0af5b8 100644 --- a/src/jrd/flu.cpp +++ b/src/jrd/flu.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: flu.cpp,v 1.4 2001-07-29 17:42:22 skywalker Exp $ +$Id: flu.cpp,v 1.5 2001-12-24 02:50:51 tamlin Exp $ */ #include "firebird.h" @@ -168,6 +168,18 @@ static void terminate_at_space(char* psz) /* Windows NT stuff */ #ifdef WIN_NT +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#define NOUSER +#define NOGDI +#define NOCRYPT +#define NOMCX +#define NOIME +#ifndef NOMSG +#define NOMSG +#endif +#define NOSERVICE #include #include #include @@ -1002,7 +1014,6 @@ FPTR_INT ISC_lookup_entrypoint(TEXT* module, * **************************************/ FPTR_INT function; - TEXT *p; function = FUNCTIONS_entrypoint(module, name); if (function) diff --git a/src/jrd/fun.epp b/src/jrd/fun.epp index 9594e3c0bc..cee146b6e3 100644 --- a/src/jrd/fun.epp +++ b/src/jrd/fun.epp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: fun.epp,v 1.2 2001-07-29 17:42:22 skywalker Exp $ +$Id: fun.epp,v 1.3 2001-12-24 02:50:51 tamlin Exp $ */ #include "firebird.h" @@ -89,10 +89,10 @@ extern double MTH$CVT_D_G(), MTH$CVT_G_D(); static SSHORT blob_get_segment(BLB, UCHAR *, USHORT, USHORT *); static void blob_put_segment(BLB, UCHAR *, USHORT); static SLONG blob_lseek(BLB, USHORT, SLONG); -static SLONG get_scalar_array(fun::fun_repeat *, DSC *, SAD, LLS *); +static SLONG get_scalar_array(fun_repeat *, DSC *, SAD, LLS *); -void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) +void DLL_EXPORT FUN_evaluate(FUN function, NOD node, VLU value) { /************************************** * @@ -104,31 +104,22 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) * Evaluate a function. * **************************************/ - TDBB tdbb; - NOD *ptr; - DSC *input, temp_desc; - SLONG **ap, *arg_ptr, args[MAX_UDF_ARGUMENTS + 1], *ip; - SSHORT s, *sp; - SLONG l, *lp, null_quad[2], *blob_id; - SINT64 i64, *pi64; - USHORT length, null_flag; - float f, *fp; - double *dp, d; - UCHAR temp[800], *temp_ptr, *p; - STR string, temp_string; - LLS blob_stack, array_stack; - REQ request; - BLB blob; - BLOB blob_desc; - fun::fun_repeat *tail, *end, *return_ptr; + + SLONG args[MAX_UDF_ARGUMENTS + 1]; + USHORT length; + UCHAR temp[800]; + STR temp_string; + SSHORT unsup_datatype = 0; + JMP_BUF *old_env, env; - SSHORT unsup_datatype; - tdbb = GET_THREAD_DATA; + TDBB tdbb = GET_THREAD_DATA; -/* Start by constructing argument list */ + // Start by constructing argument list + UCHAR* temp_ptr; - if (function->fun_temp_length < sizeof(temp)) { + if (function->fun_temp_length < sizeof(temp)) + { temp_string = NULL; temp_ptr = temp; MOVE_CLEAR(temp, sizeof(temp)); @@ -139,68 +130,76 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) a number of data blocks with aligned length */ temp_string = - (STR) ALLOCDV(type_str, - function->fun_temp_length + DOUBLE_ALIGN - 1); + new(*tdbb->tdbb_default, + function->fun_temp_length + DOUBLE_ALIGN - 1) str; MOVE_CLEAR(temp_string->str_data, temp_string->str_length); temp_ptr = (UCHAR *) FB_ALIGN((U_IPTR) temp_string->str_data, DOUBLE_ALIGN); } MOVE_CLEAR(args, sizeof(args)); - arg_ptr = args; - blob_stack = array_stack = NULL; - request = tdbb->tdbb_request; - null_flag = (USHORT)(request->req_flags & req_null); - return_ptr = function->fun_rpt + function->fun_return_arg; + SLONG* arg_ptr = args; + LLS blob_stack = 0; + LLS array_stack = 0; + REQ request = tdbb->tdbb_request; + USHORT null_flag = (USHORT)(request->req_flags & req_null); + fun_repeat* return_ptr = function->fun_rpt + function->fun_return_arg; + NOD* ptr = node->nod_arg; + value->vlu_desc = return_ptr->fun_desc; value->vlu_desc.dsc_address = (UCHAR *) & value->vlu_misc; - ptr = node->nod_arg; /* Trap any potential errors */ +#pragma FB_COMPILER_MESSAGE("Note that we cannot use C++ EH here for Win32 SS!") +#if !defined(SUPERSERVER) && !defined(WINNT) + try { +#endif + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (temp_string) - ALL_release((FRB)temp_string); - while (array_stack) - ALL_free((SCHAR*)LLS_POP(&array_stack)); - ERR_punt(); - } - START_CHECK_FOR_EXCEPTIONS(function->fun_exception_message); -/* If the return data type is any of the string types, allocate space to - hold value */ + // If the return data type is any of the string types, + // allocate space to hold value - if (value->vlu_desc.dsc_dtype <= dtype_varying) { + + if (value->vlu_desc.dsc_dtype <= dtype_varying) + { length = value->vlu_desc.dsc_length; - if ((string = value->vlu_string) && string->str_length < length) { - ALL_release((FRB)string); + STR string = value->vlu_string; + if (string && string->str_length < length) { + delete string; string = NULL; } if (!string) { - string = (STR) ALLOCDV(type_str, length); + string = new(*tdbb->tdbb_default, length) str; string->str_length = length; value->vlu_string = string; } value->vlu_desc.dsc_address = string->str_data; } -/* Process arguments */ - for (tail = function->fun_rpt + 1, end = tail + function->fun_count; - tail < end; tail++) { - if (tail == return_ptr) + DSC temp_desc; + double d; + double* dp; + + // Process arguments + const fun_repeat* end = function->fun_rpt + 1 + function->fun_count; + for (fun_repeat* tail = function->fun_rpt + 1; tail < end; ++tail) + { + DSC* input; + if (tail == return_ptr) { input = (DSC *) value; - else + } else { input = EVL_expr(tdbb, *ptr++); - ap = (SLONG **) arg_ptr; + } + SLONG** ap = (SLONG **) arg_ptr; - /* If we're passing data type ISC descriptor, there's nothing left to - be done */ + // If we're passing data type ISC descriptor, there's + // nothing left to be done if (tail->fun_mechanism == FUN_descriptor) { *ap++ = (SLONG *) input; @@ -218,7 +217,7 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) { if (tail->fun_mechanism == FUN_value) { - p = (UCHAR *) arg_ptr; + UCHAR* p = (UCHAR *) arg_ptr; MOVE_CLEAR(p, (SLONG) length); p += length; arg_ptr = (SLONG *) p; @@ -240,77 +239,94 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) switch (tail->fun_desc.dsc_dtype) { case dtype_short: - s = MOV_get_long(input, (SSHORT) tail->fun_desc.dsc_scale); - if (tail->fun_mechanism == FUN_value) { - /* For (apparent) portability reasons, SHORT by value - * is always passed as a LONG. See v3.2 release notes - * Passing by value is not supported in SQL due to - * these problems, but can still occur in GDML. - * 1994-September-28 David Schnepper - */ - *arg_ptr++ = (SLONG) s; - continue; + { + SSHORT s = MOV_get_long(input, + (SSHORT) tail->fun_desc.dsc_scale); + if (tail->fun_mechanism == FUN_value) { + /* For (apparent) portability reasons, SHORT by value + * is always passed as a LONG. See v3.2 release notes + * Passing by value is not supported in SQL due to + * these problems, but can still occur in GDML. + * 1994-September-28 David Schnepper + */ + *arg_ptr++ = (SLONG) s; + continue; + } + { + SSHORT* sp = (SSHORT *) temp_ptr; + *sp = s; + } } - sp = (SSHORT *) temp_ptr; - *sp = s; break; case dtype_sql_time: case dtype_sql_date: case dtype_long: - /* this check added for bug 74193 */ - if (tail->fun_desc.dsc_dtype == dtype_long) { - l = - MOV_get_long(input, - (SSHORT) tail->fun_desc.dsc_scale); - } - else - { - /* for sql_date and sql_time just move the value to a long, - scale does not mean anything for it */ - l = *((SLONG *) (input->dsc_address)); - } + SLONG l; + /* this check added for bug 74193 */ + if (tail->fun_desc.dsc_dtype == dtype_long) + { + l = + MOV_get_long(input, + (SSHORT) tail->fun_desc.dsc_scale); + } + else + { + /* for sql_date and sql_time just move the value to a long, + scale does not mean anything for it */ + l = *((SLONG *) (input->dsc_address)); + } - if (tail->fun_mechanism == FUN_value) - { - *arg_ptr++ = l; - continue; + if (tail->fun_mechanism == FUN_value) + { + *arg_ptr++ = l; + continue; + } + { + SLONG* lp = (SLONG *) temp_ptr; + *lp = l; + } } - lp = (SLONG *) temp_ptr; - *lp = l; break; case dtype_int64: - i64 = MOV_get_int64(input, (SSHORT) tail->fun_desc.dsc_scale); - if (tail->fun_mechanism == FUN_value) { - pi64 = (SINT64 *) arg_ptr; - *pi64++ = i64; - arg_ptr = (SLONG *) pi64; - continue; + SINT64* pi64; + SINT64 i64 = + MOV_get_int64(input, (SSHORT)tail->fun_desc.dsc_scale); + + if (tail->fun_mechanism == FUN_value) + { + pi64 = (SINT64 *) arg_ptr; + *pi64++ = i64; + arg_ptr = (SLONG *) pi64; + continue; + } + pi64 = (SINT64 *) temp_ptr; + *pi64 = i64; } - pi64 = (SINT64 *) temp_ptr; - *pi64 = i64; break; case dtype_real: - f = (float) MOV_get_double(input); - if (tail->fun_mechanism == FUN_value) { - /* For (apparent) portability reasons, FLOAT by value - * is always passed as a DOUBLE. See v3.2 release notes - * Passing by value is not supported in SQL due to - * these problems, but can still occur in GDML. - * 1994-September-28 David Schnepper - */ - dp = (double *) arg_ptr; - *dp++ = (double) f; - arg_ptr = (SLONG *) dp; - continue; + float f = (float) MOV_get_double(input); + if (tail->fun_mechanism == FUN_value) + { + /* For (apparent) portability reasons, FLOAT by value + * is always passed as a DOUBLE. See v3.2 release notes + * Passing by value is not supported in SQL due to + * these problems, but can still occur in GDML. + * 1994-September-28 David Schnepper + */ + double* dp = (double *) arg_ptr; + *dp++ = (double) f; + arg_ptr = (SLONG *) dp; + continue; + } + float* fp = (float *) temp_ptr; + *fp = f; } - fp = (float *) temp_ptr; - *fp = f; break; case dtype_double: @@ -353,7 +369,9 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) break; case dtype_blob: - blob_desc = (BLOB) temp_ptr; + { + BLOB blob_desc = (BLOB) temp_ptr; + BLB blob; length = sizeof(struct blob); if (tail == return_ptr) { @@ -363,7 +381,10 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) } else { - if (request->req_flags & req_null) { + SLONG* blob_id; + if (request->req_flags & req_null) + { + SLONG null_quad[2]; null_quad[0] = null_quad[1] = 0; blob_id = null_quad; } @@ -371,9 +392,11 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) { if (input->dsc_dtype != dtype_quad && input->dsc_dtype != dtype_blob) + { ERR_post(gds_wish_list, gds_arg_gds, gds_blobnotsup, gds_arg_string, "conversion", 0); + } blob_id = (SLONG *) input->dsc_address; } blob = BLB_open(tdbb, @@ -388,6 +411,7 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) blob_desc->blob_number_segments = blob->blb_count; blob_desc->blob_max_segment = blob->blb_max_segment; blob_desc->blob_total_length = blob->blb_length; + } break; default: @@ -403,8 +427,6 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) temp_ptr += length; } - unsup_datatype = 0; - if (function->fun_return_arg) { THREAD_EXIT; @@ -514,9 +536,11 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) break; case dtype_timestamp: - ip = (SLONG *) temp_ptr; - value->vlu_misc.vlu_dbkey[0] = *ip++; - value->vlu_misc.vlu_dbkey[1] = *ip; + { + SLONG* ip = (SLONG *) temp_ptr; + value->vlu_misc.vlu_dbkey[0] = *ip++; + value->vlu_misc.vlu_dbkey[1] = *ip; + } break; default: @@ -530,15 +554,27 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) } } - END_CHECK_FOR_EXCEPTIONS(function->fun_exception_message); + END_CHECK_FOR_EXCEPTIONS((TEXT*)function->fun_exception_message); - if (unsup_datatype) + if (unsup_datatype) { IBERROR(169); /* msg 169 return data type not supported */ + } tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (temp_string) - ALL_release((FRB)temp_string); +#if !defined(SUPERSERVER) && !defined(WINNT) + } + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + delete temp_string; + while (array_stack) { + delete LLS_POP(&array_stack); + } + ERR_punt(); + } +#endif + + delete temp_string; while (blob_stack) { @@ -547,7 +583,7 @@ void DLL_EXPORT FUN_evaluate( FUN function, NOD node, VLU value) while (array_stack) { - ALL_free((SCHAR*)LLS_POP(&array_stack)); + delete LLS_POP(&array_stack); } if (temp_ptr == NULL) @@ -622,7 +658,7 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) LLS stack; USHORT count, args, l; ULONG length; - fun::fun_repeat *tail, temp[MAX_UDF_ARGUMENTS + 1]; + fun_repeat *tail, temp[MAX_UDF_ARGUMENTS + 1]; #ifdef GATEWAY JMP_BUF *old_env, env; #endif @@ -635,21 +671,20 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_udf); for (symbol = SYM_lookup(name); symbol; symbol = symbol->sym_homonym) + { if ((int) (symbol->sym_type = SYM_fun)) { V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_udf); return (FUN) symbol->sym_object; } + } #ifdef GATEWAY /* Trap any potential errors */ + try { old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - return prior; - } #endif prior = NULL; @@ -688,14 +723,14 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) l = sizeof(struct blob); length += l; END_FOR; - function = (FUN) ALLOCPV(type_fun, count + 1); + function = new(*dbb->dbb_permanent, count + 1) fun; function->fun_count = count; function->fun_args = args; function->fun_return_arg = X.RDB$RETURN_ARGUMENT; function->fun_type = X.RDB$FUNCTION_TYPE; function->fun_temp_length = length; MOVE_FAST(temp, function->fun_rpt, - (count + 1) * sizeof(fun::fun_repeat)); + (count + 1) * sizeof(fun_repeat)); #ifndef WIN_NT /* NT allows blanks in file paths */ for (p = X.RDB$MODULE_NAME; *p && *p != ' '; p++); *p = 0; @@ -707,10 +742,10 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) causes an exception. This is done at this time to save us from preparing (thus allocating) this message every time the function is called. */ exception_msg = - (STR) ALLOCPV(type_str, + new(*dbb->dbb_permanent, strlen(EXCEPTION_MESSAGE) + strlen(name) + strlen(X.RDB$ENTRYPOINT) + - strlen(X.RDB$MODULE_NAME) + 1); + strlen(X.RDB$MODULE_NAME) + 1) str; sprintf((char*)exception_msg->str_data, EXCEPTION_MESSAGE, name, X.RDB$ENTRYPOINT, X.RDB$MODULE_NAME); function->fun_exception_message = exception_msg; @@ -719,7 +754,7 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) ISC_lookup_entrypoint(X.RDB$MODULE_NAME, X.RDB$ENTRYPOINT, ISC_EXT_LIB_PATH_ENV); - if (module = FLU_lookup_module(X.RDB$MODULE_NAME)) { + if ( (module = FLU_lookup_module(X.RDB$MODULE_NAME)) ) { /* Register interest in the module by database. */ for (stack = dbb->dbb_modules; stack; stack = stack->lls_next) @@ -737,7 +772,7 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) } else { - PLB old_pool; + JrdMemoryPool *old_pool; old_pool = tdbb->tdbb_default; tdbb->tdbb_default = dbb->dbb_permanent; @@ -760,9 +795,9 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) else { prior = function; - function->fun_symbol = symbol = (SYM) ALLOCP(type_sym); + function->fun_symbol = symbol = new(*dbb->dbb_permanent) sym; symbol->sym_object = (BLK) function; - string = (STR) ALLOCPV(type_str, strlen(name)); + string = new(*dbb->dbb_permanent, strlen(name)) str; strcpy((char*)string->str_data, name); symbol->sym_string = (TEXT *) string->str_data; symbol->sym_type = SYM_fun; @@ -778,7 +813,15 @@ FUN DLL_EXPORT FUN_lookup_function(TEXT * name) V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_udf); #ifdef GATEWAY + tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + return prior; + } + #endif return prior; @@ -801,7 +844,7 @@ FUN DLL_EXPORT FUN_resolve(CSB csb, FUN function, NOD args) NOD *ptr, *end; DSC arg; int best_score, score; - fun::fun_repeat *tail; + fun_repeat *tail; TDBB tdbb; tdbb = GET_THREAD_DATA; @@ -923,7 +966,7 @@ static SSHORT blob_get_segment( #ifndef GATEWAY -static SLONG get_scalar_array(fun::fun_repeat* arg, +static SLONG get_scalar_array(fun_repeat* arg, DSC* value, SAD scalar_desc, LLS* stack) @@ -959,7 +1002,7 @@ static SLONG get_scalar_array(fun::fun_repeat* arg, tdbb->tdbb_request->req_transaction, (BID)value->dsc_address, array_desc); - data = (UCHAR *) ALL_malloc(array_desc->ads_total_length, ERR_jmp); + data = (UCHAR *) MemoryPool::malloc_from_system(array_desc->ads_total_length); BLB_get_data(tdbb, blob, data, array_desc->ads_total_length); dimensions = array_desc->ads_dimensions; @@ -972,12 +1015,12 @@ static SLONG get_scalar_array(fun::fun_repeat* arg, to.dsc_scale != from.dsc_scale || to.dsc_length != from.dsc_length) { n = array_desc->ads_count; to.dsc_address = temp = - (UCHAR *) ALL_malloc((SLONG) to.dsc_length * n, ERR_jmp); + (UCHAR *) MemoryPool::malloc_from_system((SLONG) to.dsc_length * n); from.dsc_address = data; for (; n; --n, to.dsc_address += to.dsc_length, from.dsc_address += array_desc->ads_element_length) MOV_move(&from, &to); - ALL_free((SCHAR*)data); + MemoryPool::free_from_system((SCHAR*)data); data = temp; } diff --git a/src/jrd/fun_proto.h b/src/jrd/fun_proto.h index a33aa6f24f..d077ff4bc9 100644 --- a/src/jrd/fun_proto.h +++ b/src/jrd/fun_proto.h @@ -32,7 +32,7 @@ extern void DLL_EXPORT FUN_evaluate(struct fun *, struct nod *, struct vlu *); extern void DLL_EXPORT FUN_fini(struct tdbb *); extern void DLL_EXPORT FUN_init(void); extern struct fun *DLL_EXPORT FUN_lookup_function(TEXT *); -extern struct fun *DLL_EXPORT FUN_resolve(struct csb *, struct fun *, +extern struct fun *DLL_EXPORT FUN_resolve(class Csb *, struct fun *, struct nod *); #ifdef __cplusplus diff --git a/src/jrd/gds.cpp b/src/jrd/gds.cpp index 27ebf643c4..5386353a52 100644 --- a/src/jrd/gds.cpp +++ b/src/jrd/gds.cpp @@ -53,6 +53,7 @@ #ifdef DARWIN #include #include +#include #endif #if (defined PC_PLATFORM && !defined NETWARE_386) @@ -98,7 +99,7 @@ #endif /* VMS */ -#include "fbutil/FirebirdConfig.h" +#include "../fbutil/FirebirdConfig.h" /* Turn on V4 mutex protection for gds__alloc/free */ @@ -234,6 +235,7 @@ typedef struct free { } *FREE; + #ifdef DEBUG_GDS_ALLOC #define DBG_MEM_FILE "memory.dbg" @@ -372,7 +374,6 @@ static char ib_prefix_msg_val[MAXPATHLEN]; #include "../include/fb_types.h" #endif - typedef struct msg { ULONG msg_top_tree; @@ -467,12 +468,10 @@ static struct #ifdef SHLIB_DEFS -#define SETJMP (*_libgds_setjmp) #define sprintf (*_libgds_sprintf) #define vsprintf (*_libgds_vsprintf) #define strlen (*_libgds_strlen) #define strcpy (*_libgds_strcpy) -#define LONGJMP (*_libgds_longjmp) #define _iob (*_libgds__iob) #define getpid (*_libgds_getpid) #define ib_fprintf (*_libgds_fprintf) @@ -503,12 +502,10 @@ static struct #define atexit (*_libgds_atexit) #define ib_vfprintf (*_libgds_vfprintf) -extern int SETJMP(); extern int sprintf(); extern int vsprintf(); extern int strlen(); extern SCHAR *strcpy(); -extern void LONGJMP(); extern IB_FILE _iob[]; extern pid_t getpid(); extern int ib_fprintf(); @@ -663,18 +660,27 @@ static const struct #ifdef SUPERSERVER + extern SLONG allr_delta_alloc; + +} // extern "C" + extern SLONG alld_delta_alloc; extern SLONG all_delta_alloc; + +extern "C" { + SLONG trace_pools = 0; SLONG free_map_debug = 0; static void freemap(int cod); void gds_print_delta_counters(IB_FILE *); -#endif + +#endif // SUPERSERVER +#if 0 #ifdef DEBUG_GDS_ALLOC void* API_ROUTINE gds__alloc_debug(SLONG size_request, @@ -915,7 +921,7 @@ void* API_ROUTINE gds__alloc(SLONG size_request) V4_MUTEX_UNLOCK(&alloc_mutex); return (UCHAR *) block + ALLOC_HEADER_SIZE; } - +#endif STATUS API_ROUTINE gds__decode(STATUS code, USHORT* fac, USHORT* class_) { @@ -1155,6 +1161,7 @@ void API_ROUTINE isc_encode_timestamp(void *times_arg, GDS_TIMESTAMP * date) } +#if 0 ULONG API_ROUTINE gds__free(void* blk) { /************************************** @@ -1227,6 +1234,7 @@ ULONG API_ROUTINE gds__free(void* blk) V4_MUTEX_UNLOCK(&alloc_mutex); return released; } +#endif #ifdef DEV_BUILD @@ -1328,6 +1336,8 @@ static void gds_alloc_validate(ALLOC p) * Test a memory buffer to see if it appears intact. * **************************************/ + // JMB: Need to rework the code for the new pools + #if 0 USHORT errors = 0; /* This might be a garbage pointer, so try and validate it first */ @@ -1393,6 +1403,7 @@ static void gds_alloc_validate(ALLOC p) DEV_REPORT(buffer); BREAKPOINT(__LINE__); } +#endif } #endif @@ -1415,6 +1426,8 @@ static BOOLEAN gds_alloc_validate_free_pattern(register UCHAR* ptr, * been clobbered. * **************************************/ + // JMB: Need to rework the code for the new pool + #if 0 while (len--) { if (*ptr++ != ALLOC_FREED_PATTERN) @@ -1428,7 +1441,7 @@ static BOOLEAN gds_alloc_validate_free_pattern(register UCHAR* ptr, return FALSE; } } - +#endif return TRUE; } #endif /* DEBUG_GDS_ALLOC */ @@ -1447,6 +1460,8 @@ static void gds_alloc_validate_freed(ALLOC p) * Test a memory buffer to see if it appears freed. * **************************************/ + // JMB: need to rework this code for the new pool + #if 0 USHORT errors = 0; /* This might be a garbage pointer, so try and validate it first */ @@ -1481,6 +1496,7 @@ static void gds_alloc_validate_freed(ALLOC p) DEV_REPORT(buffer); BREAKPOINT(__LINE__); } +#endif } #endif @@ -1499,7 +1515,8 @@ void gds_alloc_watch(void* p) * Start watching a memory location. * **************************************/ - +// JMB: need to rework this for new pools +#if 0 gds_alloc_watch_call_count++; /* Do we have a new place to watch? If so, set our watcher */ @@ -1514,6 +1531,7 @@ void gds_alloc_watch(void* p) { gds_alloc_validate(gds_alloc_watchpoint); } +#endif } #endif /* DEBUG_GDS_ALLOC */ @@ -1533,7 +1551,8 @@ void API_ROUTINE gds_alloc_flag_unfreed(void *blk) * don't report it in gds_alloc_report * **************************************/ - +// JMB: need to rework this for the new pools +#if 0 /* Point to the start of the block */ ALLOC p = (ALLOC) (((UCHAR *) blk) - ALLOC_HEADER_SIZE); @@ -1542,7 +1561,7 @@ void API_ROUTINE gds_alloc_flag_unfreed(void *blk) /* Flag it as "already known" */ p->alloc_flags |= ALLOC_dont_report; - +#endif } #endif /* DEBUG_GDS_ALLOC */ @@ -1562,6 +1581,8 @@ void API_ROUTINE gds_alloc_report(ULONG flags, char* filename, int lineno) * Or that might have been clobbered. * **************************************/ + // JMB: needs to be reworked for new pools + #if 0 ALLOC p; IB_FILE *f = NULL; char buffer[150]; @@ -1649,6 +1670,7 @@ void API_ROUTINE gds_alloc_report(ULONG flags, char* filename, int lineno) { ib_fclose(f); } +#endif } #endif @@ -2426,19 +2448,19 @@ void API_ROUTINE gds__prefix(TEXT * resultString, TEXT * root) #else // WIN_NT #ifdef DARWIN if ( (ibaseBundle = CFBundleGetBundleWithIdentifier( - CFSTR(DARWIN_FRAMEWORK_ID)) ) && - (msgFileUrl = CFBundleCopyResourceURL(ibaseBundle, - CFSTR(DARWIN_GEN_DIR), NULL, NULL)) && - (msgFilePath = CFURLCopyFileSystemPath(msgFileUrl, - kCFURLPOSIXPathStyle)) && - (CFStringGetCString(msgFilePath, ib_prefix_val, + CFSTR(DARWIN_FRAMEWORK_ID)) )) + if ((msgFileUrl = CFBundleCopyResourceURL(ibaseBundle, + CFSTR(DARWIN_GEN_DIR), NULL, NULL))) + if ((msgFilePath = CFURLCopyFileSystemPath(msgFileUrl, + kCFURLPOSIXPathStyle))) + if ( (CFStringGetCString(msgFilePath, ib_prefix_val, MAXPATHLEN, kCFStringEncodingMacRoman )) ) { } else #endif { // Try and get value from config file. - const string regPrefix = FirebirdConfig::getSysString("RootDirectory"); + const Firebird::string regPrefix = FirebirdConfig::getSysString("RootDirectory"); int len = regPrefix.length(); if ( len > 0) { if (len > sizeof(ib_prefix_val)) { @@ -2891,8 +2913,7 @@ int API_ROUTINE gds__print_blr( SLONG offset; SSHORT version, level; - if (SETJMP(env)) - return -1; + try { control = &ctl; level = 0; @@ -2930,6 +2951,11 @@ int API_ROUTINE gds__print_blr( blr_format(control, "blr_eoc"); PRINT_LINE; + } // try + catch (...) { + return -1; + } + return 0; } @@ -3137,7 +3163,8 @@ void* API_ROUTINE gds__sys_alloc(SLONG size) * memory pool. * **************************************/ - + return MemoryPool::malloc_from_system(size); +#if 0 #ifndef SUPERSERVER return gds__alloc(size); @@ -3210,7 +3237,7 @@ void* API_ROUTINE gds__sys_alloc(SLONG size) if (error == ERROR_NOT_ENOUGH_MEMORY) return NULL; else - ERR_post (gds__sys_request, gds_arg_string, "VirtualAlloc", + ERR_post (gds_sys_request, gds_arg_string, "VirtualAlloc", gds_arg_win32, error, 0); ***/ } @@ -3226,6 +3253,7 @@ void* API_ROUTINE gds__sys_alloc(SLONG size) #endif #endif /* SUPERSERVER */ +#endif } @@ -3241,6 +3269,8 @@ SLONG API_ROUTINE gds__sys_free(void* blk) * Free system memory back where it came from. * **************************************/ + return MemoryPool::free_from_system(blk); +#if 0 #ifndef SUPERSERVER return gds__free(blk); @@ -3283,7 +3313,7 @@ SLONG API_ROUTINE gds__sys_free(void* blk) if (!VirtualFree((LPVOID) blk, (DWORD) 0, MEM_RELEASE)) { const DWORD dwErr = GetLastError(); - ERR_post(gds__sys_request, gds_arg_string, "VirtualFree", + ERR_post(gds_sys_request, gds_arg_string, "VirtualFree", gds_arg_win32, dwErr, 0); } #define SYS_FREE_DEFINED @@ -3295,6 +3325,7 @@ SLONG API_ROUTINE gds__sys_free(void* blk) return 0L; #endif #endif /* SUPERSERVER */ +#endif } @@ -3837,7 +3868,7 @@ static void blr_error(CTL control, TEXT * string, TEXT * arg1) blr_format(control, string, arg1); offset = 0; PRINT_LINE; - LONGJMP(env, -1); + Firebird::status_longjmp_error::raise(-1); } diff --git a/src/jrd/gds.hxx b/src/jrd/gds.hxx index 6981f7ca99..a28a5eea00 100644 --- a/src/jrd/gds.hxx +++ b/src/jrd/gds.hxx @@ -1074,3 +1074,5 @@ const char PYXIS_MENU_TRANSPARENT = 5; const char PYXIS_MENU_HORIZONTAL = 6; const char PYXIS_MENU_VERTICAL = 7; const char PYXIS_MENU_END = -1; + + diff --git a/src/jrd/gdsassert.h b/src/jrd/gdsassert.h index e51cfb5a6d..ddafb35354 100644 --- a/src/jrd/gdsassert.h +++ b/src/jrd/gdsassert.h @@ -16,8 +16,8 @@ * All Rights Reserved. * Contributor(s): ______________________________________. */ -#ifndef _JRD_GDSASSERT_H_ -#define _JRD_GDSASSERT_H_ +#ifndef JRD_GDSASSERT_H +#define JRD_GDSASSERT_H #ifdef DEV_BUILD @@ -25,6 +25,7 @@ #include // abort() #include "../jrd/ib_stdio.h" +#include "../jrd/gds_proto.h" /* assert() has been made into a generic version that works across @@ -32,29 +33,40 @@ * usable within the engine. * 1996-Feb-09 David Schnepper */ -#ifdef SUPERSERVER -#define _assert(ex) {if (!(ex)){(void) gds__log ("GDS Assertion failure: %s %ld\n", __FILE__, __LINE__); abort();}} + +#ifdef __LINE__IS_INT +#define FB_GDS_ASSERT_FAILURE_STRING "GDS Assertion failure: %s %d\n" #else -#define _assert(ex) {if (!(ex)){(void) ib_fprintf (ib_stderr, "GDS Assertion failure: %s %ld\n", __FILE__, __LINE__); abort();}} +#define FB_GDS_ASSERT_FAILURE_STRING "GDS Assertion failure: %s %ld\n" #endif -#else +#ifdef SUPERSERVER -#define _assert(ex) /* nothing */ +#define fb_assert(ex) {if (!(ex)){(void) gds__log (FB_GDS_ASSERT_FAILURE_STRING, __FILE__, __LINE__); abort();}} + +#else // !SUPERSERVER + +#define fb_assert(ex) {if (!(ex)){(void) ib_fprintf (ib_stderr, FB_GDS_ASSERT_FAILURE_STRING, __FILE__, __LINE__); abort();}} + +#endif // SUPERSERVER + +#else // DEV_BUILD + +#define fb_assert(ex) /* nothing */ #endif /* DEV_BUILD */ -#define gds_assert(ex) _assert(ex) +#define gds_assert(ex) fb_assert(ex) -/* It's a bit poor, since asset is a standard function but this was the way it +/* It's a bit poor, since assert is a standard macro but this was the way it was done. It is preferable to use the gds_assert(x) function, but I've left the following for back compatibility since I don't want to wade through that much code at the moment. */ #ifndef assert -#define assert(ex) _assert(ex) +#define assert(ex) fb_assert(ex) #endif /* assert */ -#endif /* _JRD_GDSASSERT_H_ */ +#endif /* JRD_GDSASSERT_H */ diff --git a/src/jrd/grammar.cpp b/src/jrd/grammar.cpp index 46663ceb9b..2b6c75dff1 100644 --- a/src/jrd/grammar.cpp +++ b/src/jrd/grammar.cpp @@ -59,7 +59,10 @@ YYSTYPE yylval, yyval; # line 159 "grammar.y" +#define JLX_C_INCLUDED_BY_GRAMMAR_CPP #include "../jrd/jlx.c" +#undef JLX_C_INCLUDED_BY_GRAMMAR_CPP + int yyexca[] = { -1, 1, 0, -1, diff --git a/src/jrd/grammar.y b/src/jrd/grammar.y index a8a73d8f56..b38c52729c 100644 --- a/src/jrd/grammar.y +++ b/src/jrd/grammar.y @@ -134,4 +134,6 @@ expr : SYMBOL ; %% +#define JLX_C_INCLUDED_BY_GRAMMAR_CPP #include "../jrd/jlx.c" +#undef JLX_C_INCLUDED_BY_GRAMMAR_CPP diff --git a/src/jrd/grant.epp b/src/jrd/grant.epp index a53cbf360d..d8040a2e8a 100644 --- a/src/jrd/grant.epp +++ b/src/jrd/grant.epp @@ -111,7 +111,8 @@ STR GRANT_realloc_acl(STR start_ptr, /* realloc the new length, ERR_punt incase of no memory */ - (void) ALL_extend((BLK*)&start_ptr, realloc_length); + // (void) plb::ALL_extend((BLK*)&start_ptr, realloc_length); + str::extend(start_ptr, realloc_length); /* the write_ptr is set back to the same offset in the new buffer*/ *write_ptr = start_ptr->str_data + old_offset; @@ -174,22 +175,13 @@ int GRANT_privileges( TDBB tdbb, SSHORT phase, DFW work) /* start the acl off by giving the owner all privileges */ + try { old_env = (JMP_BUF*)tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (str_buffer) { - ALL_release((FRB)str_buffer); - } - if (str_default_buffer) - ALL_release((FRB)str_default_buffer); - ERR_punt(); - } - - str_buffer = (STR) ALLOCPV(type_str, ACL_BUFFER_SIZE); - str_default_buffer = (STR) ALLOCPV(type_str, ACL_BUFFER_SIZE); + str_buffer = new(*dbb->dbb_permanent, ACL_BUFFER_SIZE) str; + str_default_buffer = new(*dbb->dbb_permanent, ACL_BUFFER_SIZE) str; acl = str_buffer->str_data; @@ -208,11 +200,13 @@ int GRANT_privileges( TDBB tdbb, SSHORT phase, DFW work) get_user_privs(tdbb, &acl, work->dfw_name, work->dfw_id, owner, public_priv, &str_buffer, length_ptr); - if (work->dfw_id == obj_relation) { + if (work->dfw_id == obj_relation) + { /* If we have the space to copy the acl list no need to realloc */ if (length > default_length) { - (void) ALL_extend((BLK*)&str_default_buffer, length); + //(void) plb::ALL_extend((BLK*)&str_default_buffer, length); + str::extend(str_default_buffer, length); default_length = length; } /* Now handle field-level privileges. This might require adding @@ -273,10 +267,17 @@ int GRANT_privileges( TDBB tdbb, SSHORT phase, DFW work) } tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (str_buffer) { - ALL_release((FRB)str_buffer); - ALL_release((FRB)str_default_buffer); + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + delete str_buffer; + delete str_default_buffer; + ERR_punt(); } + + delete str_buffer; + delete str_default_buffer; V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_grant_priv); break; @@ -801,27 +802,23 @@ TEXT * relation_name, TEXT * owner, USHORT public_priv, ULONG * length_ptr) STR str_field_buffer = NULL, str_field_buffer_start = NULL; ULONG field_length, start_length; - ULONG *field_length_ptr = &field_length, *start_length_ptr = - &start_length; + ULONG *field_length_ptr = &field_length; + //ULONG *start_length_ptr = + // &start_length; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; + try { + old_env = (JMP_BUF*)tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (str_field_buffer) - ALL_release((FRB)str_field_buffer); - if (str_field_buffer_start) - ALL_release((FRB)str_field_buffer_start); - ERR_punt(); - } -/* initialize the field-level acl buffer to include all relation-level privs */ - str_field_buffer_start = (STR)ALLOCPV(type_str, *length_ptr); - str_field_buffer = (STR)ALLOCPV(type_str, *length_ptr); + /* initialize the field-level acl buffer to include all relation-level privs */ + + str_field_buffer_start = new(*dbb->dbb_permanent, *length_ptr) str; + str_field_buffer = new(*dbb->dbb_permanent, *length_ptr) str; field_length = start_length = *length_ptr; @@ -1053,11 +1050,17 @@ TEXT * relation_name, TEXT * owner, USHORT public_priv, ULONG * length_ptr) *acl_ptr = relation_acl; tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (str_field_buffer) - { - ALL_release((FRB)str_field_buffer); - ALL_release((FRB)str_field_buffer_start); + } + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + delete str_field_buffer; + delete str_field_buffer_start; + ERR_punt(); + } + + delete str_field_buffer; + delete str_field_buffer_start; return aggregate_public; } @@ -1229,12 +1232,12 @@ static SLONG squeeze_acl(UCHAR* acl_base, if (*acl++ != ACL_version) BUGCHECK(160); /* msg 160 wrong ACL version */ - while (c = *acl++) + while ( (c = *acl++) ) switch (c) { case ACL_id_list: dup_acl = acl - 1; hit = TRUE; - while (c = *acl++) { + while ( (c = *acl++) ) { switch (c) { case id_person: if (user_type != obj_user) @@ -1303,7 +1306,7 @@ static SLONG squeeze_acl(UCHAR* acl_base, case ACL_priv_list: if (hit) { - while (c = *acl++) + while ( (c = *acl++) ) switch (c) { case priv_control: privilege |= SCL_control; @@ -1390,7 +1393,7 @@ static BOOLEAN check_string( TEXT * acl, TEXT * string) /* JPN: Since Kanji User names are not allowed, No need to fix this UPPER loop. */ - if (l = *acl++) + if ( (l = *acl++) ) do { c1 = *acl++; c2 = *string++; diff --git a/src/jrd/ib_stdio.cpp b/src/jrd/ib_stdio.cpp index 74d79979ca..d78fa0f7c4 100644 --- a/src/jrd/ib_stdio.cpp +++ b/src/jrd/ib_stdio.cpp @@ -87,7 +87,7 @@ */ /* -$Id: ib_stdio.cpp,v 1.2 2001-07-29 17:42:22 skywalker Exp $ +$Id: ib_stdio.cpp,v 1.3 2001-12-24 02:50:51 tamlin Exp $ */ #include "firebird.h" diff --git a/src/jrd/ibase.h b/src/jrd/ibase.h index 1febd4d436..3a43d40cbc 100644 --- a/src/jrd/ibase.h +++ b/src/jrd/ibase.h @@ -22,7 +22,7 @@ * FSG 16.03.2001 */ /* -$Id: ibase.h,v 1.3 2001-07-29 17:42:22 skywalker Exp $ +$Id: ibase.h,v 1.4 2001-12-24 02:50:51 tamlin Exp $ */ #ifndef JRD_IBASE_H diff --git a/src/jrd/iberr.cpp b/src/jrd/iberr.cpp index 9064ac6dcf..2796ff3ba6 100644 --- a/src/jrd/iberr.cpp +++ b/src/jrd/iberr.cpp @@ -157,9 +157,11 @@ static void post_error( if (status_vector[1] == gds_db_corrupt || status_vector[1] == gds_bug_check) + { gds__log_status(dbname, status_vector); + } - if (longjmp_addr) - LONGJMP(reinterpret_cast < jmp_buf & >(longjmp_addr), - (int) status_vector[1]); + if (longjmp_addr) { + Firebird::status_longjmp_error::raise(status_vector[1]); + } } diff --git a/src/jrd/idx.cpp b/src/jrd/idx.cpp index 5b9baa5345..4f17513cce 100644 --- a/src/jrd/idx.cpp +++ b/src/jrd/idx.cpp @@ -200,10 +200,12 @@ void IDX_create_index( BTR_reserve_slot(tdbb, relation, transaction, idx); - if (index_id) + if (index_id) { *index_id = idx->idx_id; + } - primary.rpb_relation = secondary.rpb_relation = relation; + secondary.rpb_relation = relation; + primary.rpb_relation = relation; primary.rpb_number = -1; primary.rpb_window.win_flags = secondary.rpb_window.win_flags = 0; @@ -325,7 +327,7 @@ void IDX_create_index( &key) == idx_e_nullunique) { do { if (record != gc_record) - ALL_release(reinterpret_cast < frb * >(record)); + delete record; } while (stack && (record = (REC) LLS_POP(&stack))); SORT_fini(sort_handle, tdbb->tdbb_attachment); gc_record->rec_flags &= ~REC_gc_active; @@ -350,7 +352,7 @@ void IDX_create_index( { do { if (record != gc_record) - ALL_release(reinterpret_cast < frb * >(record)); + delete record; } while (stack && (record = (REC) LLS_POP(&stack))); SORT_fini(sort_handle, tdbb->tdbb_attachment); gc_record->rec_flags &= ~REC_gc_active; @@ -363,7 +365,7 @@ void IDX_create_index( reinterpret_cast < ULONG ** >(&p))) { do { if (record != gc_record) - ALL_release(reinterpret_cast < frb * >(record)); + delete record; } while (stack && (record = (REC) LLS_POP(&stack))); SORT_fini(sort_handle, tdbb->tdbb_attachment); gc_record->rec_flags &= ~REC_gc_active; @@ -377,7 +379,7 @@ void IDX_create_index( if ((idx->idx_flags & idx_unique) && ifl_data.ifl_duplicates) { do { if (record != gc_record) - ALL_release(reinterpret_cast < frb * >(record)); + delete record; } while (stack && (record = (REC) LLS_POP(&stack))); SORT_fini(sort_handle, tdbb->tdbb_attachment); gc_record->rec_flags &= ~REC_gc_active; @@ -411,7 +413,7 @@ void IDX_create_index( /* Offset BOOLEAN in the beginning of the sort record key */ if (l = key_length - key.key_length - sizeof(SORTP)) #else - if (l = key_length - key.key_length) + if ( (l = key_length - key.key_length) ) #endif /* IGNORE_NULL_IDX_KEY */ do *p++ = pad; @@ -421,7 +423,7 @@ void IDX_create_index( isr->isr_record_number = primary.rpb_number; isr->isr_flags = (stack) ? ISR_secondary : 0; if (record != gc_record) - ALL_release(reinterpret_cast < frb * >(record)); + delete record; } #ifdef MULTI_THREAD @@ -476,7 +478,7 @@ IDB IDX_create_index_block(TDBB tdbb, REL relation, UCHAR id) dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - index_block = (IDB) ALLOCP(type_idb); + index_block = new(*dbb->dbb_permanent) idb(); index_block->idb_id = id; /* link the block in with the relation linked list */ @@ -488,14 +490,14 @@ IDB IDX_create_index_block(TDBB tdbb, REL relation, UCHAR id) any modification to the index so that the cached information about the index will be discarded */ - index_block->idb_lock = lock = (LCK) ALLOCPV(type_lck, 0); + index_block->idb_lock = lock = new(*dbb->dbb_permanent, 0) lck; lock->lck_parent = dbb->dbb_lock; lock->lck_dbb = dbb; lock->lck_key.lck_long = index_block->idb_id; lock->lck_length = sizeof(lock->lck_key.lck_long); lock->lck_type = LCK_expression; lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type); - lock->lck_ast = reinterpret_cast < lck_ast_t > (index_block_flush); + lock->lck_ast = reinterpret_cast(index_block_flush); lock->lck_object = (BLK) index_block; return index_block; @@ -704,19 +706,19 @@ IDX_E IDX_modify(TDBB tdbb, (tdbb, org_rpb->rpb_relation, transaction, &idx, &window)) { *bad_index = idx.idx_id; *bad_relation = new_rpb->rpb_relation; - if (error_code = + if ( (error_code = BTR_key(tdbb, new_rpb->rpb_relation, new_rpb->rpb_record, &idx, - &key1)) { + &key1)) ) { CCH_RELEASE(tdbb, &window); break; } BTR_key(tdbb, org_rpb->rpb_relation, org_rpb->rpb_record, &idx, &key2); if (!key_equal(&key1, &key2)) { - if (error_code = + if (( error_code = insert_key(tdbb, new_rpb->rpb_relation, new_rpb->rpb_record, transaction, &window, &insertion, bad_relation, - bad_index)) return error_code; + bad_index)) ) return error_code; } } @@ -857,14 +859,14 @@ IDX_E IDX_store(TDBB tdbb, (tdbb, rpb->rpb_relation, transaction, &idx, &window)) { *bad_index = idx.idx_id; *bad_relation = rpb->rpb_relation; - if (error_code = - BTR_key(tdbb, rpb->rpb_relation, rpb->rpb_record, &idx, &key)) { + if ( (error_code = + BTR_key(tdbb, rpb->rpb_relation, rpb->rpb_record, &idx, &key)) ) { CCH_RELEASE(tdbb, &window); break; } - if (error_code = + if ( (error_code = insert_key(tdbb, rpb->rpb_relation, rpb->rpb_record, transaction, - &window, &insertion, bad_relation, bad_index)) + &window, &insertion, bad_relation, bad_index)) ) return error_code; } @@ -946,7 +948,7 @@ static IDX_E check_duplicates( } if (rpb.rpb_record) - ALL_release(reinterpret_cast < frb * >(rpb.rpb_record)); + delete rpb.rpb_record; return result; } @@ -995,20 +997,18 @@ REL * bad_relation, USHORT * bad_index) } else if (idx->idx_flags & (idx_primary | idx_unique)) for (index_number = 0; - index_number < idx->idx_foreign_primaries->vec_count; + index_number < idx->idx_foreign_primaries->count(); index_number++) { if (idx->idx_id != - (UCHAR) idx-> - idx_foreign_primaries->vec_object[index_number]) continue; + (UCHAR) (*idx->idx_foreign_primaries)[index_number]) continue; partner_relation = MET_relation(tdbb, - (int) idx-> - idx_foreign_relations->vec_object[index_number]); + (int) (*idx->idx_foreign_relations)[index_number]); index_id = - (USHORT) idx->idx_foreign_indexes->vec_object[index_number]; - if (result = + (USHORT) (*idx->idx_foreign_indexes)[index_number]; + if ( (result = check_partner_index(tdbb, relation, record, transaction, idx, - partner_relation, index_id)) + partner_relation, index_id)) ) break; } @@ -1084,7 +1084,7 @@ REL partner_relation, SSHORT index_id) bitmap = NULL; MOVE_CLEAR(&retrieval, sizeof(struct irb)); - retrieval.irb_header.blk_type = type_irb; + //retrieval.blk_type = type_irb; retrieval.irb_index = partner_idx.idx_id; MOVE_FAST(&partner_idx, &retrieval.irb_desc, sizeof(retrieval.irb_desc)); diff --git a/src/jrd/idx_proto.h b/src/jrd/idx_proto.h index 56cb08659d..8f93fa1f9a 100644 --- a/src/jrd/idx_proto.h +++ b/src/jrd/idx_proto.h @@ -32,7 +32,7 @@ extern "C" { #endif -extern void IDX_check_access(TDBB, struct csb *, struct rel *, struct rel *, +extern void IDX_check_access(TDBB, class Csb *, struct rel *, struct rel *, struct fld *); extern void IDX_create_index(TDBB, struct rel *, struct idx *, UCHAR *, USHORT *, struct tra *, float *); diff --git a/src/jrd/inf.cpp b/src/jrd/inf.cpp index a32dacd325..05e3eb30a6 100644 --- a/src/jrd/inf.cpp +++ b/src/jrd/inf.cpp @@ -540,7 +540,7 @@ int INF_database_info( for (att = dbb->dbb_attachments; att; att = att->att_next) { if (att->att_flags & ATT_shutdown) continue; - if (user = att->att_user) { + if ( (user = att->att_user) ) { p = buffer; *p++ = l = strlen(user->usr_user_name); for (q = user->usr_user_name; l; l--) @@ -561,11 +561,11 @@ int INF_database_info( err_att = tdbb->tdbb_attachment; if (err_att->att_val_errors) { err_val = - err_att->att_val_errors->vcl_long[VAL_PAG_WRONG_TYPE] - + err_att->att_val_errors->vcl_long[VAL_PAG_CHECKSUM_ERR] - + err_att->att_val_errors->vcl_long[VAL_PAG_DOUBLE_ALLOC] - + err_att->att_val_errors->vcl_long[VAL_PAG_IN_USE] - + err_att->att_val_errors->vcl_long[VAL_PAG_ORPHAN]; + (*err_att->att_val_errors)[VAL_PAG_WRONG_TYPE] + + (*err_att->att_val_errors)[VAL_PAG_CHECKSUM_ERR] + + (*err_att->att_val_errors)[VAL_PAG_DOUBLE_ALLOC] + + (*err_att->att_val_errors)[VAL_PAG_IN_USE] + + (*err_att->att_val_errors)[VAL_PAG_ORPHAN]; } else err_val = 0; @@ -577,9 +577,9 @@ int INF_database_info( err_att = tdbb->tdbb_attachment; if (err_att->att_val_errors) { err_val = - err_att->att_val_errors->vcl_long[VAL_BLOB_INCONSISTENT] - + err_att->att_val_errors->vcl_long[VAL_BLOB_CORRUPT] - + err_att->att_val_errors->vcl_long[VAL_BLOB_TRUNCATED]; + (*err_att->att_val_errors)[VAL_BLOB_INCONSISTENT] + + (*err_att->att_val_errors)[VAL_BLOB_CORRUPT] + + (*err_att->att_val_errors)[VAL_BLOB_TRUNCATED]; } else err_val = 0; @@ -591,14 +591,13 @@ int INF_database_info( err_att = tdbb->tdbb_attachment; if (err_att->att_val_errors) { err_val = - err_att->att_val_errors->vcl_long[VAL_REC_CHAIN_BROKEN] - + err_att->att_val_errors->vcl_long[VAL_REC_DAMAGED] - + err_att->att_val_errors->vcl_long[VAL_REC_BAD_TID] + (*err_att->att_val_errors)[VAL_REC_CHAIN_BROKEN] + + (*err_att->att_val_errors)[VAL_REC_DAMAGED] + + (*err_att->att_val_errors)[VAL_REC_BAD_TID] + - err_att-> - att_val_errors->vcl_long[VAL_REC_FRAGMENT_CORRUPT] + - err_att->att_val_errors->vcl_long[VAL_REC_WRONG_LENGTH] + - err_att->att_val_errors->vcl_long[VAL_REL_CHAIN_ORPHANS]; + (*err_att->att_val_errors)[VAL_REC_FRAGMENT_CORRUPT] + + (*err_att->att_val_errors)[VAL_REC_WRONG_LENGTH] + + (*err_att->att_val_errors)[VAL_REL_CHAIN_ORPHANS]; } else err_val = 0; @@ -610,9 +609,9 @@ int INF_database_info( err_att = tdbb->tdbb_attachment; if (err_att->att_val_errors) { err_val = - err_att->att_val_errors->vcl_long[VAL_DATA_PAGE_CONFUSED] + (*err_att->att_val_errors)[VAL_DATA_PAGE_CONFUSED] + - err_att->att_val_errors->vcl_long[VAL_DATA_PAGE_LINE_ERR]; + (*err_att->att_val_errors)[VAL_DATA_PAGE_LINE_ERR]; } else err_val = 0; @@ -624,13 +623,11 @@ int INF_database_info( err_att = tdbb->tdbb_attachment; if (err_att->att_val_errors) { err_val = - err_att->att_val_errors->vcl_long[VAL_INDEX_PAGE_CORRUPT] + (*err_att->att_val_errors)[VAL_INDEX_PAGE_CORRUPT] + - err_att-> - att_val_errors->vcl_long[VAL_INDEX_ROOT_MISSING] + - err_att->att_val_errors-> - vcl_long[VAL_INDEX_MISSING_ROWS] + - err_att->att_val_errors->vcl_long[VAL_INDEX_ORPHAN_CHILD]; + (*err_att->att_val_errors)[VAL_INDEX_ROOT_MISSING] + + (*err_att->att_val_errors)[VAL_INDEX_MISSING_ROWS] + + (*err_att->att_val_errors)[VAL_INDEX_ORPHAN_CHILD]; } else err_val = 0; @@ -641,10 +638,9 @@ int INF_database_info( case isc_info_ppage_errors: err_att = tdbb->tdbb_attachment; if (err_att->att_val_errors) { - err_val = err_att->att_val_errors->vcl_long[VAL_P_PAGE_LOST] + err_val = (*err_att->att_val_errors)[VAL_P_PAGE_LOST] + - err_att-> - att_val_errors->vcl_long[VAL_P_PAGE_INCONSISTENT]; + (*err_att->att_val_errors)[VAL_P_PAGE_INCONSISTENT]; } else err_val = 0; @@ -655,9 +651,9 @@ int INF_database_info( case isc_info_tpage_errors: err_att = tdbb->tdbb_attachment; if (err_att->att_val_errors) { - err_val = err_att->att_val_errors->vcl_long[VAL_TIP_LOST] - + err_att->att_val_errors->vcl_long[VAL_TIP_LOST_SEQUENCE] - + err_att->att_val_errors->vcl_long[VAL_TIP_CONFUSED]; + err_val = (*err_att->att_val_errors)[VAL_TIP_LOST] + + (*err_att->att_val_errors)[VAL_TIP_LOST_SEQUENCE] + + (*err_att->att_val_errors)[VAL_TIP_CONFUSED]; } else err_val = 0; @@ -1110,7 +1106,8 @@ static USHORT get_counts(USHORT count_id, UCHAR * buffer, USHORT length) * **************************************/ TDBB tdbb; - SLONG n, *ptr; + SLONG n; + vcl::iterator ptr; UCHAR *p, *end; USHORT relation_id; VCL vector; @@ -1123,8 +1120,8 @@ static USHORT get_counts(USHORT count_id, UCHAR * buffer, USHORT length) p = buffer; end = p + length - 6; - for (relation_id = 0, ptr = vector->vcl_long; - relation_id < vector->vcl_count && buffer < end; ++relation_id) + for (relation_id = 0, ptr = vector->begin(); + relation_id < vector->count() && buffer < end; ++relation_id) if (n = *ptr++) { STUFF_WORD(p, relation_id); p += INF_convert(n, reinterpret_cast < char *>(p)); diff --git a/src/jrd/ini.epp b/src/jrd/ini.epp index cfbc912c55..6158be73e7 100644 --- a/src/jrd/ini.epp +++ b/src/jrd/ini.epp @@ -88,109 +88,109 @@ static void store_trigger(TDBB, CONST TRG*, BLK*); static CONST TRG FAR_VARIABLE triggers[] = { - "RDB$TRIGGER_1", (UCHAR) nam_user_privileges, + { "RDB$TRIGGER_1", (UCHAR) nam_user_privileges, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger3), trigger3, - 0, ODS_8_0, - "RDB$TRIGGER_8", (UCHAR) nam_user_privileges, + 0, ODS_8_0 }, + { "RDB$TRIGGER_8", (UCHAR) nam_user_privileges, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger2), trigger2, - 0, ODS_8_0, - "RDB$TRIGGER_9", (UCHAR) nam_user_privileges, + 0, ODS_8_0 }, + { "RDB$TRIGGER_9", (UCHAR) nam_user_privileges, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger1), trigger1, - 0, ODS_8_0, - "RDB$TRIGGER_2", (UCHAR) nam_trgs, + 0, ODS_8_0 }, + { "RDB$TRIGGER_2", (UCHAR) nam_trgs, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger4), trigger4, - 0, ODS_8_0, - "RDB$TRIGGER_3", (UCHAR) nam_trgs, + 0, ODS_8_0 }, + { "RDB$TRIGGER_3", (UCHAR) nam_trgs, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger4), trigger4, - 0, ODS_8_0, - "RDB$TRIGGER_4", (UCHAR) nam_relations, + 0, ODS_8_0 }, + { "RDB$TRIGGER_4", (UCHAR) nam_relations, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger5), trigger5, - 0, ODS_8_0, - "RDB$TRIGGER_5", (UCHAR) nam_relations, + 0, ODS_8_0 }, + { "RDB$TRIGGER_5", (UCHAR) nam_relations, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger6), trigger6, - 0, ODS_8_0, - "RDB$TRIGGER_6", (UCHAR) nam_gens, + 0, ODS_8_0 }, + { "RDB$TRIGGER_6", (UCHAR) nam_gens, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger7), trigger7, - 0, ODS_8_0, - "RDB$TRIGGER_26", (UCHAR) nam_rel_constr, + 0, ODS_8_0 }, + { "RDB$TRIGGER_26", (UCHAR) nam_rel_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger26), trigger26, - 0, ODS_8_0, - "RDB$TRIGGER_25", (UCHAR) nam_rel_constr, + 0, ODS_8_0 }, + { "RDB$TRIGGER_25", (UCHAR) nam_rel_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger25), - trigger25, 0, ODS_8_0, - "RDB$TRIGGER_10", (UCHAR) nam_rel_constr, + trigger25, 0, ODS_8_0 }, + { "RDB$TRIGGER_10", (UCHAR) nam_rel_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger10), trigger10, - 0, ODS_8_0, - "RDB$TRIGGER_11", (UCHAR) nam_rel_constr, + 0, ODS_8_0 }, + { "RDB$TRIGGER_11", (UCHAR) nam_rel_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger11), - trigger11, 0, ODS_8_0, - "RDB$TRIGGER_12", (UCHAR) nam_ref_constr, + trigger11, 0, ODS_8_0 }, + { "RDB$TRIGGER_12", (UCHAR) nam_ref_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger12), trigger12, - 0, ODS_8_0, - "RDB$TRIGGER_13", (UCHAR) nam_ref_constr, + 0, ODS_8_0 }, + { "RDB$TRIGGER_13", (UCHAR) nam_ref_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger13), - trigger13, 0, ODS_8_0, - "RDB$TRIGGER_14", (UCHAR) nam_chk_constr, + trigger13, 0, ODS_8_0 }, + { "RDB$TRIGGER_14", (UCHAR) nam_chk_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger14), - trigger14, 0, ODS_8_0, - "RDB$TRIGGER_15", (UCHAR) nam_chk_constr, + trigger14, 0, ODS_8_0 }, + { "RDB$TRIGGER_15", (UCHAR) nam_chk_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger15), trigger15, - 0, ODS_8_0, - "RDB$TRIGGER_16", (UCHAR) nam_chk_constr, + 0, ODS_8_0 }, + { "RDB$TRIGGER_16", (UCHAR) nam_chk_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger16), - trigger16, 0, ODS_8_0, - "RDB$TRIGGER_17", (UCHAR) nam_i_segments, + trigger16, 0, ODS_8_0 }, + { "RDB$TRIGGER_17", (UCHAR) nam_i_segments, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger17), trigger17, - 0, ODS_8_0, - "RDB$TRIGGER_18", (UCHAR) nam_i_segments, + 0, ODS_8_0 }, + { "RDB$TRIGGER_18", (UCHAR) nam_i_segments, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger18), - trigger18, 0, ODS_8_0, - "RDB$TRIGGER_19", (UCHAR) nam_indices, + trigger18, 0, ODS_8_0 }, + { "RDB$TRIGGER_19", (UCHAR) nam_indices, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger19), trigger19, - 0, ODS_8_0, - "RDB$TRIGGER_20", (UCHAR) nam_indices, + 0, ODS_8_0 }, + { "RDB$TRIGGER_20", (UCHAR) nam_indices, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger20), - trigger20, 0, ODS_8_0, - "RDB$TRIGGER_21", (UCHAR) nam_trgs, + trigger20, 0, ODS_8_0 }, + { "RDB$TRIGGER_21", (UCHAR) nam_trgs, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger21), trigger21, - 0, ODS_8_0, - "RDB$TRIGGER_22", (UCHAR) nam_trgs, + 0, ODS_8_0 }, + { "RDB$TRIGGER_22", (UCHAR) nam_trgs, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger22), - trigger22, 0, ODS_8_0, - "RDB$TRIGGER_23", (UCHAR) nam_r_fields, + trigger22, 0, ODS_8_0 }, + { "RDB$TRIGGER_23", (UCHAR) nam_r_fields, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger23), trigger23, - 0, ODS_8_0, - "RDB$TRIGGER_24", (UCHAR) nam_r_fields, + 0, ODS_8_0 }, + { "RDB$TRIGGER_24", (UCHAR) nam_r_fields, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger24), - trigger24, 0, ODS_8_0, - "RDB$TRIGGER_27", (UCHAR) nam_r_fields, + trigger24, 0, ODS_8_0 }, + { "RDB$TRIGGER_27", (UCHAR) nam_r_fields, RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger27), - trigger27, 0, ODS_8_0, - "RDB$TRIGGER_28", (UCHAR) nam_procedures, + trigger27, 0, ODS_8_0 }, + { "RDB$TRIGGER_28", (UCHAR) nam_procedures, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger28), trigger28, - 0, ODS_8_0, - "RDB$TRIGGER_29", (UCHAR) nam_procedures, + 0, ODS_8_0 }, + { "RDB$TRIGGER_29", (UCHAR) nam_procedures, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger29), - trigger29, 0, ODS_8_0, - "RDB$TRIGGER_30", (UCHAR) nam_exceptions, + trigger29, 0, ODS_8_0 }, + { "RDB$TRIGGER_30", (UCHAR) nam_exceptions, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger30), trigger30, - 0, ODS_8_0, - "RDB$TRIGGER_31", (UCHAR) nam_user_privileges, + 0, ODS_8_0 }, + { "RDB$TRIGGER_31", (UCHAR) nam_user_privileges, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger31), - trigger31, 0, ODS_8_1, - "RDB$TRIGGER_32", (UCHAR) nam_user_privileges, + trigger31, 0, ODS_8_1 }, + { "RDB$TRIGGER_32", (UCHAR) nam_user_privileges, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger31), trigger31, - 0, ODS_8_1, - "RDB$TRIGGER_33", (UCHAR) nam_user_privileges, + 0, ODS_8_1 }, + { "RDB$TRIGGER_33", (UCHAR) nam_user_privileges, RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger31), trigger31, - 0, ODS_8_1, - "RDB$TRIGGER_34", (UCHAR) nam_rel_constr, + 0, ODS_8_1 }, + { "RDB$TRIGGER_34", (UCHAR) nam_rel_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger34), - trigger34, TRG_ignore_perm, ODS_8_1, - "RDB$TRIGGER_35", (UCHAR) nam_chk_constr, + trigger34, TRG_ignore_perm, ODS_8_1 }, + { "RDB$TRIGGER_35", (UCHAR) nam_chk_constr, RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger35), - trigger35, TRG_ignore_perm, ODS_8_1, - 0, 0, 0, 0, 0, 0 + trigger35, TRG_ignore_perm, ODS_8_1 }, + { 0, 0, 0, 0, 0, 0 } }; @@ -198,41 +198,41 @@ static CONST TRG FAR_VARIABLE triggers[] = static CONST TRIGMSG FAR_VARIABLE trigger_messages[] = { - "RDB$TRIGGER_9", 0, "grant_obj_notfound", ODS_8_0, - "RDB$TRIGGER_9", 1, "grant_fld_notfound", ODS_8_0, - "RDB$TRIGGER_9", 2, "grant_nopriv", ODS_8_0, - "RDB$TRIGGER_9", 3, "nonsql_security_rel", ODS_8_0, - "RDB$TRIGGER_9", 4, "nonsql_security_fld", ODS_8_0, - "RDB$TRIGGER_9", 5, "grant_nopriv_on_base", ODS_8_0, - "RDB$TRIGGER_1", 0, "existing_priv_mod", ODS_8_0, - "RDB$TRIGGER_2", 0, "systrig_update", ODS_8_0, - "RDB$TRIGGER_3", 0, "systrig_update", ODS_8_0, - "RDB$TRIGGER_5", 0, "not_rel_owner", ODS_8_0, - "RDB$TRIGGER_24", 1, "cnstrnt_fld_rename", ODS_8_0, - "RDB$TRIGGER_23", 1, "cnstrnt_fld_del", ODS_8_0, - "RDB$TRIGGER_22", 1, "check_trig_update", ODS_8_0, - "RDB$TRIGGER_21", 1, "check_trig_del", ODS_8_0, - "RDB$TRIGGER_20", 1, "integ_index_mod", ODS_8_0, - "RDB$TRIGGER_20", 2, "integ_index_deactivate", ODS_8_0, - "RDB$TRIGGER_20", 3, "integ_deactivate_primary", ODS_8_0, - "RDB$TRIGGER_19", 1, "integ_index_del", ODS_8_0, - "RDB$TRIGGER_18", 1, "integ_index_seg_mod", ODS_8_0, - "RDB$TRIGGER_17", 1, "integ_index_seg_del", ODS_8_0, - "RDB$TRIGGER_15", 1, "check_cnstrnt_del", ODS_8_0, - "RDB$TRIGGER_14", 1, "check_cnstrnt_update", ODS_8_0, - "RDB$TRIGGER_13", 1, "ref_cnstrnt_update", ODS_8_0, - "RDB$TRIGGER_12", 1, "ref_cnstrnt_notfound", ODS_8_0, - "RDB$TRIGGER_12", 2, "foreign_key_notfound", ODS_8_0, - "RDB$TRIGGER_10", 1, "primary_key_ref", ODS_8_0, - "RDB$TRIGGER_10", 2, "primary_key_notnull", ODS_8_0, - "RDB$TRIGGER_25", 1, "rel_cnstrnt_update", ODS_8_0, - "RDB$TRIGGER_26", 1, "constaint_on_view", ODS_8_0, - "RDB$TRIGGER_26", 2, "invld_cnstrnt_type", ODS_8_0, - "RDB$TRIGGER_26", 3, "primary_key_exists", ODS_8_0, - "RDB$TRIGGER_31", 0, "no_write_user_priv", ODS_8_1, - "RDB$TRIGGER_32", 0, "no_write_user_priv", ODS_8_1, - "RDB$TRIGGER_33", 0, "no_write_user_priv", ODS_8_1, - 0, 0, 0, 0 + { "RDB$TRIGGER_9", 0, "grant_obj_notfound", ODS_8_0 }, + { "RDB$TRIGGER_9", 1, "grant_fld_notfound", ODS_8_0 }, + { "RDB$TRIGGER_9", 2, "grant_nopriv", ODS_8_0 }, + { "RDB$TRIGGER_9", 3, "nonsql_security_rel", ODS_8_0 }, + { "RDB$TRIGGER_9", 4, "nonsql_security_fld", ODS_8_0 }, + { "RDB$TRIGGER_9", 5, "grant_nopriv_on_base", ODS_8_0 }, + { "RDB$TRIGGER_1", 0, "existing_priv_mod", ODS_8_0 }, + { "RDB$TRIGGER_2", 0, "systrig_update", ODS_8_0 }, + { "RDB$TRIGGER_3", 0, "systrig_update", ODS_8_0 }, + { "RDB$TRIGGER_5", 0, "not_rel_owner", ODS_8_0 }, + { "RDB$TRIGGER_24", 1, "cnstrnt_fld_rename", ODS_8_0 }, + { "RDB$TRIGGER_23", 1, "cnstrnt_fld_del", ODS_8_0 }, + { "RDB$TRIGGER_22", 1, "check_trig_update", ODS_8_0 }, + { "RDB$TRIGGER_21", 1, "check_trig_del", ODS_8_0 }, + { "RDB$TRIGGER_20", 1, "integ_index_mod", ODS_8_0 }, + { "RDB$TRIGGER_20", 2, "integ_index_deactivate", ODS_8_0 }, + { "RDB$TRIGGER_20", 3, "integ_deactivate_primary", ODS_8_0 }, + { "RDB$TRIGGER_19", 1, "integ_index_del", ODS_8_0 }, + { "RDB$TRIGGER_18", 1, "integ_index_seg_mod", ODS_8_0 }, + { "RDB$TRIGGER_17", 1, "integ_index_seg_del", ODS_8_0 }, + { "RDB$TRIGGER_15", 1, "check_cnstrnt_del", ODS_8_0 }, + { "RDB$TRIGGER_14", 1, "check_cnstrnt_update", ODS_8_0 }, + { "RDB$TRIGGER_13", 1, "ref_cnstrnt_update", ODS_8_0 }, + { "RDB$TRIGGER_12", 1, "ref_cnstrnt_notfound", ODS_8_0 }, + { "RDB$TRIGGER_12", 2, "foreign_key_notfound", ODS_8_0 }, + { "RDB$TRIGGER_10", 1, "primary_key_ref", ODS_8_0 }, + { "RDB$TRIGGER_10", 2, "primary_key_notnull", ODS_8_0 }, + { "RDB$TRIGGER_25", 1, "rel_cnstrnt_update", ODS_8_0 }, + { "RDB$TRIGGER_26", 1, "constaint_on_view", ODS_8_0 }, + { "RDB$TRIGGER_26", 2, "invld_cnstrnt_type", ODS_8_0 }, + { "RDB$TRIGGER_26", 3, "primary_key_exists", ODS_8_0 }, + { "RDB$TRIGGER_31", 0, "no_write_user_priv", ODS_8_1 }, + { "RDB$TRIGGER_32", 0, "no_write_user_priv", ODS_8_1 }, + { "RDB$TRIGGER_33", 0, "no_write_user_priv", ODS_8_1 }, + { 0, 0, 0, 0 } }; @@ -280,7 +280,7 @@ void INI_format(TEXT* owner) if (owner && *owner) { p = string; - while (*p++ = UPPER7(*owner)) + while ( (*p++ = UPPER7(*owner)) ) { ++owner; } @@ -488,29 +488,30 @@ void INI_init(void) DBB dbb; REL relation; FMT format; - FLD* field; + FLD field; VEC formats; VEC fields; int n; CONST UCHAR* relfld; - CONST UCHAR* fld; - DSC* desc; + CONST UCHAR* fld_; + fmt::fmt_desc_iterator desc; CONST GFLD* gfield; CONST TRG* trigger; TDBB tdbb; + vec::iterator itr; tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - for (relfld = relfields; relfld[RFLD_R_NAME]; relfld = fld + 1) + for (relfld = relfields; relfld[RFLD_R_NAME]; relfld = fld_ + 1) { relation = MET_relation(tdbb, relfld[RFLD_R_ID]); relation->rel_flags |= REL_system; relation->rel_name = (/* const_cast */ TEXT*)names[relfld[RFLD_R_NAME]]; relation->rel_length = strlen(relation->rel_name); n = 0; - for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH) + for (fld_ = relfld + RFLD_RPT; fld_[RFLD_F_NAME]; fld_ += RFLD_F_LENGTH) { n++; } @@ -527,25 +528,24 @@ void INI_init(void) } } - relation->rel_fields = fields = (VEC) ALLOCPV(type_vec, n); - fields->vec_count = n; - field = (FLD *) fields->vec_object; - relation->rel_current_format = format = (FMT) ALLOCPV(type_fmt, n); - relation->rel_formats = formats = (VEC) ALLOCPV(type_vec, 1); - formats->vec_count = 1; - formats->vec_object[0] = (BLK) format; + relation->rel_fields = fields = vec::newVector(*dbb->dbb_permanent, n); + //field = (FLD *) fields->vec_object; + itr = fields->begin(); + relation->rel_current_format = format = fmt::newFmt(*dbb->dbb_permanent, n); + relation->rel_formats = formats = vec::newVector(*dbb->dbb_permanent, 1); + (*formats)[0] = format; format->fmt_count = n; - desc = format->fmt_desc; + desc = format->fmt_desc.begin(); - for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; - fld += RFLD_F_LENGTH, desc++, field++) + for (fld_ = relfld + RFLD_RPT; fld_[RFLD_F_NAME]; + fld_ += RFLD_F_LENGTH, desc++, itr++) { - gfield = &gfields[fld[RFLD_F_ID]]; + gfield = &gfields[fld_[RFLD_F_ID]]; desc->dsc_length = gfield->gfld_length; desc->dsc_dtype = gfield->gfld_dtype; - *field = (FLD) ALLOCPV(type_fld, 0); - (*field)->fld_name = names[fld[RFLD_F_NAME]]; - (*field)->fld_length = strlen((*field)->fld_name); + *itr = field = new(*dbb->dbb_permanent,0) fld(); + field->fld_name = names[fld_[RFLD_F_NAME]]; + field->fld_length = strlen(field->fld_name); } } } @@ -570,7 +570,7 @@ void INI_init2(void) int n; CONST UCHAR* relfld; CONST UCHAR* fld; - DSC* desc; + fmt::fmt_desc_iterator desc; TDBB tdbb; USHORT major_version; USHORT minor_original; @@ -595,11 +595,11 @@ void INI_init2(void) ** ******************************************************/ id = relfld[RFLD_R_ID]; - relation = (REL)vector->vec_object[id]; - ALL_release((FRB)relation->rel_current_format); - ALL_release((FRB)relation->rel_formats); - ALL_release((FRB)relation->rel_fields); - vector->vec_object[id] = NULL; + relation = (REL)(*vector)[id]; + delete relation->rel_current_format; + delete relation->rel_formats; + delete relation->rel_fields; + (*vector)[id] = NULL; fld = relfld + RFLD_RPT; while (fld[RFLD_F_NAME]) { @@ -652,10 +652,11 @@ void INI_init2(void) } } - relation->rel_fields->vec_count = n; + VEC tmp = relation->rel_fields; + relation->rel_fields->resize(n); format->fmt_count = n; format->fmt_length = (USHORT)FLAG_BYTES(n); - desc = format->fmt_desc; + desc = format->fmt_desc.begin(); for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH, desc++) { @@ -955,8 +956,7 @@ static void add_index_set(DBB dbb, segment = &index->ini_idx_segment[position]; STORE(REQUEST_HANDLE handle2) Y IN RDB$INDEX_SEGMENTS field = - (FLD) relation->rel_fields-> - vec_object[segment->ini_idx_rfld_id]; + (FLD) (*relation->rel_fields)[segment->ini_idx_rfld_id]; Y.RDB$FIELD_POSITION = position; PAD(X.RDB$INDEX_NAME, Y.RDB$INDEX_NAME); diff --git a/src/jrd/ini.h b/src/jrd/ini.h index c1a739dff9..02c06095b4 100644 --- a/src/jrd/ini.h +++ b/src/jrd/ini.h @@ -63,9 +63,9 @@ gfld_MAX} GFLDS; /* Pick up actual global fields */ #ifndef GPRE -#define FIELD(type,name,dtype,length,sub_type,ods,dflt_blr) (UCHAR) type, (UCHAR) name, dtype, length, sub_type, ods, dflt_blr, sizeof (dflt_blr), +#define FIELD(type,name,dtype,length,sub_type,ods,dflt_blr) { (UCHAR) type, (UCHAR) name, dtype, length, sub_type, ods, dflt_blr, sizeof (dflt_blr) }, #else -#define FIELD(type,name,dtype,length,sub_type,ods,dflt_blr) (UCHAR) type, (UCHAR) name, dtype, length, sub_type, ods, NULL, 0, +#define FIELD(type,name,dtype,length,sub_type,ods,dflt_blr) { (UCHAR) type, (UCHAR) name, dtype, length, sub_type, ods, NULL, 0 }, #endif typedef struct gfld @@ -82,7 +82,7 @@ typedef struct gfld static CONST struct gfld FAR_VARIABLE gfields[] = { #include "../jrd/fields.h" - 0, 0, dtype_null, 0, 0, 0, NULL, 0 + { 0, 0, dtype_null, 0, 0, 0, NULL, 0 } }; #undef FIELD diff --git a/src/jrd/intl.cpp b/src/jrd/intl.cpp index ad7b5fd3b3..80599036a1 100644 --- a/src/jrd/intl.cpp +++ b/src/jrd/intl.cpp @@ -562,13 +562,11 @@ CSCONVERT DLL_EXPORT INTL_convert_lookup(TDBB tdbb, vector = charset->charset_converters; if (!(vector)) { - vector = charset->charset_converters = (VEC) ALLOCPV(type_vec, 10); - assert(vector != NULL); - vector->vec_count = 10; + vector = charset->charset_converters = vec::newVector(*dbb->dbb_permanent, 10); } - for (i = 0; i < vector->vec_count; i++) { - converter = (CSCONVERT) (vector->vec_object[i]); + for (i = 0; i < vector->count(); i++) { + converter = (CSCONVERT) ((*vector)[i]); if (converter == NULL) break; if (converter->csconvert_to == to_cs) { @@ -579,10 +577,8 @@ CSCONVERT DLL_EXPORT INTL_convert_lookup(TDBB tdbb, } } - if (i >= vector->vec_count) { - vector = - (VEC) ALL_extend(reinterpret_cast < - BLK * >(&charset->charset_converters), i + 10); + if (i >= vector->count()) { + vector->resize(i+11); converter = NULL; } @@ -598,13 +594,14 @@ CSCONVERT DLL_EXPORT INTL_convert_lookup(TDBB tdbb, } else { if (converter == NULL) - converter = (CSCONVERT) ALLOCP(type_csconvert); + //converter = (CSCONVERT) ALLOCP(type_csconvert); + converter = new(*dbb->dbb_permanent) csconvert; if (obj_init(type_csconvert, to_cs, from_cs, converter, NULL, NULL)) { /* Can't find a conversion object - cache that info in the * list of converters. */ - vector->vec_object[i] = (BLK) converter; + (*vector)[i] = (BLK) converter; converter->csconvert_flags = 0; converter->csconvert_from = from_cs; converter->csconvert_to = to_cs; @@ -612,7 +609,7 @@ CSCONVERT DLL_EXPORT INTL_convert_lookup(TDBB tdbb, } } - vector->vec_object[i] = (BLK) converter; + (*vector)[i] = (BLK) converter; converter->csconvert_flags |= CONVERTTYPE_init; assert(converter->csconvert_from == from_cs); @@ -719,7 +716,7 @@ int DLL_EXPORT INTL_convert_string(DSC * to, DSC * from, FPTR_VOID err) to_len = INTL_convert_bytes(tdbb, to_cs, - ((VARY *) to->dsc_address)->vary_string, + reinterpret_cast(((VARY *) to->dsc_address)->vary_string), to_size, from_cs, from_ptr, from_len, err); ((VARY *) to->dsc_address)->vary_length = to_len; from_fill = 0; /* Convert_bytes handles source truncation */ @@ -729,7 +726,7 @@ int DLL_EXPORT INTL_convert_string(DSC * to, DSC * from, FPTR_VOID err) to_len = MIN(from_len, to_size); from_fill = from_len - to_len; ((VARY *) p)->vary_length = to_len; - p = ((VARY *) p)->vary_string; + p = reinterpret_cast(((VARY *) p)->vary_string); if (to_len) do *p++ = *q++; @@ -992,13 +989,13 @@ typedef struct { } Tab; static CONST Tab tab[] = { - 0x80, 0x00, 0 * 6, 0x7F, 0, /* 1 byte sequence */ - 0xE0, 0xC0, 1 * 6, 0x7FF, 0x80, /* 2 byte sequence */ - 0xF0, 0xE0, 2 * 6, 0xFFFF, 0x800, /* 3 byte sequence */ - 0xF8, 0xF0, 3 * 6, 0x1FFFFF, 0x10000, /* 4 byte sequence */ - 0xFC, 0xF8, 4 * 6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */ - 0xFE, 0xFC, 5 * 6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */ - 0, /* end of table */ + { 0x80, 0x00, 0 * 6, 0x7F, 0 }, /* 1 byte sequence */ + { 0xE0, 0xC0, 1 * 6, 0x7FF, 0x80 }, /* 2 byte sequence */ + { 0xF0, 0xE0, 2 * 6, 0xFFFF, 0x800 }, /* 3 byte sequence */ + { 0xF8, 0xF0, 3 * 6, 0x1FFFFF, 0x10000 }, /* 4 byte sequence */ + { 0xFC, 0xF8, 4 * 6, 0x3FFFFFF, 0x200000 }, /* 5 byte sequence */ + { 0xFE, 0xFC, 5 * 6, 0x7FFFFFFF, 0x4000000 }, /* 6 byte sequence */ + { 0, 0, 0, 0, 0 } /* end of table */ }; @@ -1219,12 +1216,10 @@ void DLL_EXPORT INTL_init(TDBB tdbb) CHECK_DBB(dbb); if (!(vector = dbb->dbb_text_objects)) { - vector = dbb->dbb_text_objects = (VEC) ALLOCPV(type_vec, 25); - vector->vec_count = 25; + vector = dbb->dbb_text_objects = vec::newVector(*dbb->dbb_permanent, 25); } if (!(vector = dbb->dbb_charsets)) { - vector = dbb->dbb_charsets = (VEC) ALLOCPV(type_vec, 25); - vector->vec_count = 25; + vector = dbb->dbb_charsets = vec::newVector(*dbb->dbb_permanent, 25); } } @@ -1334,13 +1329,18 @@ void *DLL_EXPORT INTL_obj_lookup( vector = *pVector; assert(vector != NULL); - if (id >= vector->vec_count) - vector = - (VEC) ALL_extend(reinterpret_cast < BLK * >(pVector), id + 10); + if (id >= vector->count()) + vector->resize(id + 11); - if (!(cs_object = vector->vec_object[id])) { - cs_object = ALLOCP(objtype); - vector->vec_object[id] = (BLK) cs_object; + if (!(cs_object = (*vector)[id])) { + if (objtype == type_charset) + cs_object = (BLK) new(*dbb->dbb_permanent) charset; + else if (objtype == type_texttype) + cs_object = (BLK) new(*dbb->dbb_permanent) texttype; + else + assert(0); + + (*vector)[id] = (BLK) cs_object; } assert(cs_object != NULL); @@ -1352,8 +1352,7 @@ void *DLL_EXPORT INTL_obj_lookup( (objtype, TTYPE_TO_CHARSET(parm1), 0, cs_object, err, (STATUS *) status)) return (NULL); ((CHARSET) cs_object)->charset_collations = - (VEC) ALLOCPV(type_vec, 10); - ((CHARSET) cs_object)->charset_collations->vec_count = 10; + vec::newVector(*dbb->dbb_permanent, 10); ((CHARSET) cs_object)->charset_flags |= CHARSET_init; return (cs_object); } @@ -2338,8 +2337,8 @@ static BOOLEAN obj_init( /* The flu.c uses searchpath which expects a file name not a path */ strcpy(reinterpret_cast < char *>(path), INTL_MODULE1); INTL_TRACE(("INTL: trying %s %s\n", path, INTL_LOOKUP_ENTRY1)); - if (lookup_fn = reinterpret_cast - (ISC_lookup_entrypoint(reinterpret_cast < char *>(path), INTL_LOOKUP_ENTRY1, NULL))) { + if ( (lookup_fn = reinterpret_cast + (ISC_lookup_entrypoint(reinterpret_cast < char *>(path), INTL_LOOKUP_ENTRY1, NULL))) ) { INTL_TRACE(("INTL: calling lookup %s %s\n", path, INTL_LOOKUP_ENTRY1)); if ((*lookup_fn) (objtype, &function, parm1, parm2) != 0) { @@ -2358,11 +2357,11 @@ static BOOLEAN obj_init( #else gds__prefix(reinterpret_cast < char *>(path), INTL_MODULE2); INTL_TRACE(("INTL: trying %s %s\n", path, INTL_LOOKUP_ENTRY2)); - if (lookup_fn = + if ( (lookup_fn = reinterpret_cast < USHORT(*)(USHORT, USHORT(**)(), short, short) >(ISC_lookup_entrypoint - (reinterpret_cast < char *>(path), INTL_LOOKUP_ENTRY2, NULL))) { + (reinterpret_cast < char *>(path), INTL_LOOKUP_ENTRY2, NULL))) ) { INTL_TRACE( ("INTL: calling lookup %s %s\n", path, INTL_LOOKUP_ENTRY2)); @@ -2396,7 +2395,7 @@ static BOOLEAN obj_init( break; } INTL_TRACE(("INTL: trying user fn %s\n", entry)); - if (function_block = FUN_lookup_function(entry)) { + if ( (function_block = FUN_lookup_function(entry)) ) { INTL_TRACE(("INTL: found a user fn, validating\n")); if ((function_block->fun_count == argcount) && (function_block->fun_args == argcount) && diff --git a/src/jrd/intlobj.h b/src/jrd/intlobj.h index 57cc402f50..f19b3d42b5 100644 --- a/src/jrd/intlobj.h +++ b/src/jrd/intlobj.h @@ -41,8 +41,14 @@ typedef unsigned char NCHAR; /* Narrow Char */ typedef unsigned short WCHAR; /* Wide Char */ typedef unsigned char MBCHAR; /* Multibyte Char */ +typedef struct intl_blk { + UCHAR blk_type; + UCHAR blk_pool_id; + USHORT blk_length; +} intl_blk; + typedef struct texttype { - struct blk texttype_blk; + struct intl_blk texttype_blk; USHORT texttype_version; /* version ID of object */ USHORT texttype_flags; /* miscellanous flags */ TTYPE_ID texttype_type; /* Interpretation ID */ @@ -84,7 +90,7 @@ typedef struct texttype { typedef struct csconvert { - struct blk csconvert_blk; + struct intl_blk csconvert_blk; USHORT csconvert_version; USHORT csconvert_flags; SSHORT csconvert_id; @@ -113,8 +119,10 @@ typedef struct csconvert { -typedef struct charset { - struct blk charset_blk; +class charset +{ +public: + struct intl_blk charset_blk; USHORT charset_version; USHORT charset_flags; CHARSET_ID charset_id; @@ -132,7 +140,8 @@ typedef struct charset { VEC charset_converters; VEC charset_collations; ULONG *charset_unused[2]; -} *CHARSET; +}; +typedef charset *CHARSET; /* values for charset_flags */ diff --git a/src/jrd/irq.h b/src/jrd/irq.h index bffa4d2f9e..0a5bb26ef8 100644 --- a/src/jrd/irq.h +++ b/src/jrd/irq.h @@ -24,7 +24,7 @@ #ifndef _JRD_IRQ_H_ #define _JRD_IRQ_H_ -#define REQUEST(irt) dbb->dbb_internal->vec_object[irt] +#define REQUEST(irt) (*dbb->dbb_internal)[irt] #define irq_s_pages 0 /* store PAGES */ #define irq_r_pages 1 /* read PAGES */ diff --git a/src/jrd/isc.cpp b/src/jrd/isc.cpp index 62352b05fa..5068e554a2 100644 --- a/src/jrd/isc.cpp +++ b/src/jrd/isc.cpp @@ -24,8 +24,11 @@ * Solaris x86 changes - Konstantin Kuznetsov, Neil McCalden */ /* -$Id: isc.cpp,v 1.4 2001-08-20 08:15:33 skywalker Exp $ +$Id: isc.cpp,v 1.5 2001-12-24 02:50:51 tamlin Exp $ */ +#ifdef DARWIN +#define _STLP_CCTYPE +#endif #include "firebird.h" #include "../jrd/ib_stdio.h" @@ -179,8 +182,12 @@ typedef unsigned int mode_t; typedef int pid_t; #endif +#ifdef DARWIN +#include +#else extern struct passwd *getpwnam(), *getpwuid(); #endif +#endif void isc_internal_set_config_value(UCHAR, ULONG*, ULONG*); @@ -220,7 +227,6 @@ extern void endpwent(); extern gid_t getegid(); #endif - #ifndef REQUESTER void DLL_EXPORT ISC_ast_enter(void) { @@ -390,9 +396,9 @@ void DLL_EXPORT ISC_get_config(TEXT * config_file, IPCCFG config_table) from the in-memory copy rather than the disk copy */ ISC_cfg_tbl = ISC_def_cfg_tbl; - if (fd = ib_fopen(config_file, FOPEN_READ_TYPE)) + if ( (fd = ib_fopen(config_file, FOPEN_READ_TYPE)) ) { - while (p = ib_fgets(buf, sizeof(buf), fd)) + while ( (p = ib_fgets(buf, sizeof(buf), fd)) ) { /* The same keyword can be used more than once for temp directory definition hence it should be handled @@ -456,7 +462,7 @@ void DLL_EXPORT ISC_get_config(TEXT * config_file, IPCCFG config_table) continue; } - for (tbl = ISC_cfg_tbl; q = tbl->cfgtbl_keyword; tbl++) + for (tbl = ISC_cfg_tbl; (q = tbl->cfgtbl_keyword) ; tbl++) { p = buf; @@ -1483,7 +1489,7 @@ SLONG ISC_get_user_group_id(TEXT * user_group_name) n = 0; - if (user_group = getgrnam(user_group_name)) + if ( (user_group = getgrnam(user_group_name)) ) n = user_group->gr_gid; return (n); diff --git a/src/jrd/isc.h b/src/jrd/isc.h index f06904614a..4857868e33 100644 --- a/src/jrd/isc.h +++ b/src/jrd/isc.h @@ -23,7 +23,7 @@ * FSG 16.03.2001 */ /* -$Id: isc.h,v 1.1.1.1 2001-05-23 13:26:08 tamlin Exp $ +$Id: isc.h,v 1.2 2001-12-24 02:50:51 tamlin Exp $ */ #ifndef _JRD_ISC_H_ #define _JRD_ISC_H_ diff --git a/src/jrd/isc_file.cpp b/src/jrd/isc_file.cpp index ab01e07861..f91047866f 100644 --- a/src/jrd/isc_file.cpp +++ b/src/jrd/isc_file.cpp @@ -188,7 +188,11 @@ typedef struct mnt { #include #endif +#ifdef DARWIN +#include +#else extern struct passwd *getpwnam(), *getpwuid(); +#endif #endif // UNIX diff --git a/src/jrd/isc_ipc.cpp b/src/jrd/isc_ipc.cpp index 7fd4106fc2..70f71238f5 100644 --- a/src/jrd/isc_ipc.cpp +++ b/src/jrd/isc_ipc.cpp @@ -22,7 +22,7 @@ * Solaris x86 changes - Konstantin Kuznetsov, Neil McCalden */ - /* $Id: isc_ipc.cpp,v 1.5 2001-08-13 08:14:38 skywalker Exp $ */ + /* $Id: isc_ipc.cpp,v 1.6 2001-12-24 02:50:51 tamlin Exp $ */ #ifdef SHLIB_DEFS #define LOCAL_SHLIB_DEFS diff --git a/src/jrd/isc_sync.cpp b/src/jrd/isc_sync.cpp index a8a5bdb7b4..b72dabbca7 100644 --- a/src/jrd/isc_sync.cpp +++ b/src/jrd/isc_sync.cpp @@ -41,6 +41,10 @@ #include #endif +#ifdef DARWIN +#include +#endif + #ifdef HP10 #include #endif @@ -58,7 +62,7 @@ #include "../jrd/jrd.h" #include "../jrd/sch_proto.h" #include "../jrd/err_proto.h" - +#include "../jrd/thd_proto.h" // Keep the following SIG_FPTR definitions in sync // with the same code in isc_ipc.cpp @@ -295,7 +299,7 @@ static void make_object_name(TEXT *, TEXT *, TEXT *); #endif -#if defined FREEBSD || defined NETBSD +#if defined FREEBSD || defined NETBSD || defined DARWIN #define sigset signal #endif @@ -759,7 +763,7 @@ int ISC_event_init(EVENT event, int semid, int semnum) pthread_mutex_init(event->event_mutex, pthread_mutexattr_default); pthread_cond_init(event->event_semnum, pthread_condattr_default); #else -#ifdef linux +#if (defined linux || defined DARWIN) pthread_mutex_init(event->event_mutex, NULL); pthread_cond_init(event->event_semnum, NULL); #else @@ -831,7 +835,7 @@ int ISC_event_wait( EVENT * events, SLONG * values, SLONG micro_seconds, - void (*timeout_handler) (), void *handler_arg) + FPTR_VOID timeout_handler, void *handler_arg) { /************************************** * @@ -3624,7 +3628,7 @@ int ISC_mutex_init(MTX mutex, SLONG semaphore) **************************************/ int state; -#if (!defined HP10 && !defined linux) +#if (!defined HP10 && !defined linux && !defined DARWIN) pthread_mutexattr_t mattr; @@ -3644,7 +3648,7 @@ int ISC_mutex_init(MTX mutex, SLONG semaphore) server (until we are to implement local IPC using shared memory in which case we need interprocess thread sync. */ -#ifdef linux +#if (defined linux || defined DARWIN) return pthread_mutex_init(mutex->mtx_mutex, NULL); #else state = pthread_mutex_init(mutex->mtx_mutex, pthread_mutexattr_default); @@ -4880,7 +4884,7 @@ void longjmp_sig_handler(int sig_num) tdbb = GET_THREAD_DATA; - siglongjmp(tdbb->tdbb_sigsetjmp, sig_num); + siglongjmp((sigjmp_buf)tdbb->tdbb_sigsetjmp, sig_num); } #endif /* UNIX */ #endif /* SUPERSERVER */ diff --git a/src/jrd/isc_sync_win32.cpp b/src/jrd/isc_sync_win32.cpp index c5d13b7f1c..8ab016c7dc 100644 --- a/src/jrd/isc_sync_win32.cpp +++ b/src/jrd/isc_sync_win32.cpp @@ -432,7 +432,7 @@ void* ISC_make_signal( UCHAR * DLL_EXPORT ISC_map_file ( STATUS* status_vector, TEXT* filename, -#if 0 +#if 1 // TMN: Parameter is in errors! void (*init_routine)(void *, struct sh_mem *, int), #else @@ -518,7 +518,7 @@ retry: CloseHandle (event_handle); CloseHandle (file_handle); *status_vector++ = gds_arg_gds; - *status_vector++ = gds__unavailable; + *status_vector++ = gds_unavailable; *status_vector++ = gds_arg_end; return NULL; } @@ -870,7 +870,7 @@ void DLL_EXPORT ISC_unmap_file( static void error(STATUS* status_vector, TEXT* string, STATUS status) { *status_vector++ = gds_arg_gds; - *status_vector++ = gds__sys_request; + *status_vector++ = gds_sys_request; *status_vector++ = gds_arg_string; *status_vector++ = reinterpret_cast(string); *status_vector++ = SYS_ARG; diff --git a/src/jrd/isc_win32.cpp b/src/jrd/isc_win32.cpp index 00a4dd727c..0049057903 100644 --- a/src/jrd/isc_win32.cpp +++ b/src/jrd/isc_win32.cpp @@ -24,7 +24,7 @@ * Solaris x86 changes - Konstantin Kuznetsov, Neil McCalden */ /* -$Id: isc_win32.cpp,v 1.2 2001-07-29 17:42:22 skywalker Exp $ +$Id: isc_win32.cpp,v 1.3 2001-12-24 02:50:51 tamlin Exp $ */ #include "firebird.h" diff --git a/src/jrd/jlx.c b/src/jrd/jlx.c index 1e6eb83553..f7e08501bc 100644 --- a/src/jrd/jlx.c +++ b/src/jrd/jlx.c @@ -21,6 +21,10 @@ * Contributor(s): ______________________________________. */ +#ifndef JLX_C_INCLUDED_BY_GRAMMAR_CPP +#error This file gets included by grammar.cpp. Don not try to compile it stand-alone. +#endif + #include "firebird.h" #include "../jrd/ib_stdio.h" #include "../jrd/common.h" diff --git a/src/jrd/john.make b/src/jrd/john.make new file mode 100644 index 0000000000..8fa58405b6 --- /dev/null +++ b/src/jrd/john.make @@ -0,0 +1,5 @@ +all: + c++ -ggdb -DDEV_BUILD -g -pipe -MMD -p -fPIC -Wall -I../../src -I../../src/include -F/System/Library/Frameworks/CoreServices.framework/Frameworks -ggdb -DDEV_BUILD -g -pipe -MMD -p -fPIC -Wall -I../../src -I../../src/include -c ../../src/jrd/all.cpp -o ../../gen/jrd/all.o + +%.o: + c++ -ggdb -DDEV_BUILD -g -pipe -MMD -p -fPIC -Wall -I../../src -I../../src/include -F/System/Library/Frameworks/CoreServices.framework/Frameworks -ggdb -DDEV_BUILD -g -pipe -MMD -p -fPIC -Wall -I../../src -I../../src/include -c ../../src/jrd/$(@:%.o=%.cpp) -o ../../gen/jrd/$@ diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index fa5f1d2743..a3a92749d7 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -38,6 +38,9 @@ #ifndef WIN_NT #include #include +#ifdef DARWIN +#include +#endif #endif #include @@ -116,7 +119,7 @@ #include "../jrd/old_proto.h" -#include "fbutil/FirebirdConfig.h" +#include "../fbutil/FirebirdConfig.h" #ifdef GARBAGE_THREAD #include "vio_proto.h" @@ -141,10 +144,10 @@ typedef struct dbf { #define V4_THREADING /*TMN: fwd. decl. SHOULD BE IN A HEADER FILE*/ -extern "C" { -void gds_print_delta_counters(IB_FILE *); void ALL_print_memory_pool_info(IB_FILE * fptr, DBB databases); void ALLD_print_memory_pool_info(IB_FILE * fptr); +extern "C" { +void gds_print_delta_counters(IB_FILE *); } // extern "C" #endif /* SUPERSERVER */ @@ -340,9 +343,9 @@ static ULONG JRD_cache_default; static struct ipccfg JRD_hdrtbl[] = { - ISCCFG_DBCACHE, -1, reinterpret_cast(&JRD_cache_default), 0, - 0, - NULL, 0, NULL, 0, 0 + { ISCCFG_DBCACHE, -1, reinterpret_cast(&JRD_cache_default), 0, + 0 }, + { NULL, 0, NULL, 0, 0 } }; #ifdef GOVERNOR @@ -404,7 +407,7 @@ static TDBB get_thread_data() { TDBB p2 = (TDBB)p1; if (p2->tdbb_database && - p2->tdbb_database->dbb_header.blk_type != type_dbb) + MemoryPool::blk_type(p2->tdbb_database) != type_dbb) { BUGCHECK(147); } @@ -417,7 +420,7 @@ static TDBB get_thread_data() inline static void CHECK_DBB(DBB dbb) { #ifdef DEV_BUILD - assert(dbb && dbb->dbb_header.blk_type == type_dbb); + assert(dbb && MemoryPool::blk_type(dbb) == type_dbb); #endif // DEV_BUILD } @@ -427,7 +430,7 @@ inline static void check_tdbb(TDBB tdbb) assert(tdbb && (reinterpret_cast(tdbb)->thdd_type == THDD_TYPE_TDBB) && (!tdbb->tdbb_database || - tdbb->tdbb_database->dbb_header.blk_type == type_dbb)); + MemoryPool::blk_type(tdbb->tdbb_database) == type_dbb)); #endif // DEV_BUILD } @@ -451,7 +454,7 @@ static void SET_TDBB(TDBB& tdbb) if (SETJMP (env)) return error (user_status); #define CHECK_HANDLE(blk,type,error) \ - if (!blk || ((BLK) blk)->blk_type != (UCHAR) type) \ + if (!blk || MemoryPool::blk_type(blk) != type) \ return handle_error (user_status, error, tdbb) #define NULL_CHECK(ptr,code) \ @@ -563,9 +566,6 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, USHORT d_len, jd_len; JMP_BUF env; -#ifdef _PPC_ - JMP_BUF env1; -#endif struct tdbb thd_context; TEXT local_role_name[BUFFER_LENGTH128]; @@ -626,48 +626,7 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, attachment = *(&attachment); - if (SETJMP(env)) - { -#ifdef _PPC_ - tdbb->tdbb_setjmp = env1; - if (!SETJMP(env1)) -#else - if (!SETJMP(env)) -#endif - { -#ifdef V4_THREADING - if (initing_security) - V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); -#endif - tdbb->tdbb_status_vector = temp_status; - dbb->dbb_flags &= ~DBB_being_opened; - release_attachment(attachment); - - /* At this point, mutex dbb->dbb_mutexes [DBB_MUTX_init_fini] has been - unlocked and mutex databases_mutex has been locked. */ -#ifdef STACK_REDUCTION - if (allocated_space) - { - ALL_free(allocated_space); - } -#endif - if (dbb->dbb_header.blk_type == (UCHAR) type_dbb) - { - if (!dbb->dbb_attachments) - { - shutdown_database(dbb, TRUE); - } - else if (attachment) - { - ALL_RELEASE(attachment); - } - } - V4_JRD_MUTEX_UNLOCK(databases_mutex); - } - tdbb->tdbb_status_vector = status; - JRD_SS_MUTEX_UNLOCK; - return error(user_status); - } + try { /* Allocate buffer space */ @@ -729,7 +688,7 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, } #endif - tdbb->tdbb_attachment = attachment = (ATT) ALLOCP(type_att); + tdbb->tdbb_attachment = attachment = new(*dbb->dbb_permanent) att(); attachment->att_database = dbb; attachment->att_next = dbb->dbb_attachments; @@ -774,7 +733,8 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, LCK_init(tdbb, LCK_OWNER_attachment); /* For the attachment */ attachment->att_flags |= ATT_lck_init_done; - if (!dbb->dbb_filename) { + if (!dbb->dbb_filename) + { first = TRUE; dbb->dbb_filename = copy_string(expanded_filename, length_expanded); /* Extra LCK_init() done to keep the lock table until the @@ -830,13 +790,14 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, } /* Attachments to a ReadOnly database need NOT do garbage collection */ - if (dbb->dbb_flags & DBB_read_only) + if (dbb->dbb_flags & DBB_read_only) { attachment->att_flags |= ATT_no_cleanup; + } if (options.dpb_disable_wal) { ERR_post(gds_lock_timeout, gds_arg_gds, gds_obj_in_use, gds_arg_string, - ERR_string(reinterpret_cast < char *>(file_name), fl), + ERR_string(reinterpret_cast(file_name), fl), 0); } @@ -1009,7 +970,8 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); #endif - if (options.dpb_shutdown || options.dpb_online) { + if (options.dpb_shutdown || options.dpb_online) + { /* By releasing the DBB_MUTX_init_fini mutex here, we would be allowing other threads to proceed with their detachments, so that shutdown does not timeout for exclusive access and other threads don't have to wait @@ -1057,31 +1019,39 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, /* If database is shutdown then kick 'em out. */ if (dbb->dbb_ast_flags & (DBB_shut_attach | DBB_shut_tran)) + { ERR_post(gds_shutinprog, gds_arg_string, ERR_string(reinterpret_cast < char *>(file_name), fl), 0); + } if (dbb->dbb_ast_flags & DBB_shutdown && !(attachment->att_user->usr_flags & (USR_locksmith | USR_owner))) + { ERR_post(gds_shutdown, gds_arg_string, ERR_string(reinterpret_cast < char *>(file_name), fl), 0); + } - if (options.dpb_disable) + if (options.dpb_disable) { AIL_disable(); + } #ifdef REPLAY_OSRI_API_CALLS_SUBSYSTEM - if (options.dpb_quit_log) + if (options.dpb_quit_log) { LOG_disable(); + } #endif /* Figure out what character set & collation this attachment prefers */ find_intl_charset(tdbb, attachment, &options); - if (options.dpb_verify) { - if (!CCH_exclusive(tdbb, LCK_PW, WAIT_PERIOD)) + if (options.dpb_verify) + { + if (!CCH_exclusive(tdbb, LCK_PW, WAIT_PERIOD)) { ERR_post(gds_bad_dpb_content, gds_arg_gds, gds_cant_validate, 0); + } #ifdef GARBAGE_THREAD /* Can't allow garbage collection during database validation. */ @@ -1099,8 +1069,9 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); } - if (options.dpb_journal) - if (first) { + if (options.dpb_journal) { + if (first) + { archive_name[0] = 0; if (options.dpb_wal_backup_dir) @@ -1120,8 +1091,10 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, gds_arg_gds, gds_cant_start_journal, 0); } + } - if (options.dpb_wal_action) { + if (options.dpb_wal_action) + { /* Make sure WAL enabled before taking any WAL action. */ if (!dbb->dbb_wal) { @@ -1251,9 +1224,11 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, /* if there was an error, the status vector is all set */ - if (options.dpb_sweep & gds_dpb_records) { + if (options.dpb_sweep & gds_dpb_records) + { JRD_SS_MUTEX_UNLOCK; - if (!(TRA_sweep(tdbb, 0))) { + if (!(TRA_sweep(tdbb, 0))) + { JRD_SS_MUTEX_LOCK; ERR_punt(); } @@ -1277,6 +1252,47 @@ STATUS DLL_EXPORT GDS_ATTACH_DATABASE(STATUS* user_status, #endif return return_success(tdbb); + + } // try + catch (...) + { + try + { +#ifdef V4_THREADING + if (initing_security) + { + V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); + } +#endif + tdbb->tdbb_status_vector = temp_status; + dbb->dbb_flags &= ~DBB_being_opened; + release_attachment(attachment); + + /* At this point, mutex dbb->dbb_mutexes [DBB_MUTX_init_fini] has been + unlocked and mutex databases_mutex has been locked. */ +#ifdef STACK_REDUCTION + if (allocated_space) { + ALL_free(allocated_space); + } +#endif + if (MemoryPool::blk_type(dbb) == type_dbb) + { + if (!dbb->dbb_attachments) + { + shutdown_database(dbb, TRUE); + } + else if (attachment) + { + delete attachment; + } + } + V4_JRD_MUTEX_UNLOCK(databases_mutex); + } // try + catch (...) {} + tdbb->tdbb_status_vector = status; + JRD_SS_MUTEX_UNLOCK; + return error(user_status); + } } @@ -1419,9 +1435,9 @@ STATUS DLL_EXPORT GDS_CANCEL_OPERATION(STATUS * user_status, the routine "check_database" */ if (!attachment || - (attachment->att_header.blk_type != (UCHAR) type_att) || + (MemoryPool::blk_type(attachment) != type_att) || !(dbb = attachment->att_database) || - dbb->dbb_header.blk_type != (UCHAR) type_dbb) + MemoryPool::blk_type(dbb) != type_dbb) return handle_error(user_status, gds_bad_db_handle, 0); /* Make sure this is a valid attachment */ @@ -1664,9 +1680,6 @@ STATUS DLL_EXPORT GDS_CREATE_DATABASE(STATUS* user_status, STATUS temp_status[ISC_STATUS_LENGTH], *status; DPB options; JMP_BUF env; -#ifdef _PPC_ - JMP_BUF env1; -#endif struct tdbb thd_context; api_entry_point_init(user_status); @@ -1722,41 +1735,7 @@ STATUS DLL_EXPORT GDS_CREATE_DATABASE(STATUS* user_status, BOOLEAN initing_security = FALSE; #endif - if (SETJMP(env)) - { -#ifdef _PPC_ - tdbb->tdbb_setjmp = (UCHAR *) env1; - if (!SETJMP(env1)) -#else - if (!SETJMP(env)) -#endif - { -#ifdef V4_THREADING - if (initing_security) - V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); -#endif - tdbb->tdbb_status_vector = temp_status; - dbb->dbb_flags &= ~DBB_being_opened; - release_attachment(attachment); - - /* At this point, mutex dbb->dbb_mutexes [DBB_MUTX_init_fini] has been - unlocked and mutex databases_mutex has been locked. */ -#ifdef STACK_REDUCTION - if (allocated_space) { - ALL_free(allocated_space); - } -#endif - if (dbb->dbb_header.blk_type == (UCHAR) type_dbb) - if (!dbb->dbb_attachments) - shutdown_database(dbb, TRUE); - else if (attachment) - ALL_RELEASE(attachment); - V4_JRD_MUTEX_UNLOCK(databases_mutex); - } - tdbb->tdbb_status_vector = status; - JRD_SS_MUTEX_UNLOCK; - return error(user_status); - } + try { /* Process database parameter block */ @@ -1792,7 +1771,7 @@ STATUS DLL_EXPORT GDS_CREATE_DATABASE(STATUS* user_status, copy_string(options.dpb_key, strlen(options.dpb_key)); #endif - tdbb->tdbb_attachment = attachment = (ATT) ALLOCP(type_att); + tdbb->tdbb_attachment = attachment = new(*dbb->dbb_permanent) att(); attachment->att_database = dbb; attachment->att_next = dbb->dbb_attachments; dbb->dbb_attachments = attachment; @@ -1996,6 +1975,47 @@ STATUS DLL_EXPORT GDS_CREATE_DATABASE(STATUS* user_status, #endif return return_success(tdbb); + + } // try + catch (...) + { + try + { +#ifdef V4_THREADING + if (initing_security) + { + V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); + } +#endif + tdbb->tdbb_status_vector = temp_status; + dbb->dbb_flags &= ~DBB_being_opened; + release_attachment(attachment); + + /* At this point, mutex dbb->dbb_mutexes [DBB_MUTX_init_fini] has been + unlocked and mutex databases_mutex has been locked. */ +#ifdef STACK_REDUCTION + if (allocated_space) { + ALL_free(allocated_space); + } +#endif + if (MemoryPool::blk_type(dbb) == type_dbb) + { + if (!dbb->dbb_attachments) + { + shutdown_database(dbb, TRUE); + } + else if (attachment) + { + delete attachment; + } + } + V4_JRD_MUTEX_UNLOCK(databases_mutex); + } + catch (...) {} + tdbb->tdbb_status_vector = status; + JRD_SS_MUTEX_UNLOCK; + return error(user_status); + } } @@ -2069,17 +2089,22 @@ STATUS DLL_EXPORT GDS_DDL(STATUS * user_status, tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_status_vector = user_status; - if (SETJMP(env)) { - if (tdbb->tdbb_status_vector == temp_status) + + try { + + transaction = find_transaction(tdbb, *tra_handle, gds_segstr_wrong_db); + + DYN_ddl(attachment, transaction, ddl_length, + reinterpret_cast(ddl)); + + } // try + catch (...) { + if (tdbb->tdbb_status_vector == temp_status) { tdbb->tdbb_status_vector = user_status; + } return error(user_status); } - transaction = find_transaction(tdbb, *tra_handle, gds_segstr_wrong_db); - - DYN_ddl(attachment, transaction, ddl_length, - reinterpret_cast < UCHAR * >(ddl)); - /* * Perform an auto commit for autocommit transactions. * This is slightly tricky. If the commit retain works, @@ -2092,11 +2117,16 @@ STATUS DLL_EXPORT GDS_DDL(STATUS * user_status, * a new entry point may be added. */ - if (transaction->tra_flags & TRA_perform_autocommit) { + if (transaction->tra_flags & TRA_perform_autocommit) + { transaction->tra_flags &= ~TRA_perform_autocommit; tdbb->tdbb_setjmp = (UCHAR *) rollback_env; - if (SETJMP(rollback_env)) { + try { + TRA_commit(tdbb, transaction, TRUE); + tdbb->tdbb_setjmp = (UCHAR *) env; + } + catch (...) { tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_status_vector = temp_status; TRA_rollback(tdbb, transaction, TRUE); @@ -2105,9 +2135,6 @@ STATUS DLL_EXPORT GDS_DDL(STATUS * user_status, return error(user_status); } - - TRA_commit(tdbb, transaction, TRUE); - tdbb->tdbb_setjmp = (UCHAR *) env; }; return return_success(tdbb); @@ -2144,9 +2171,9 @@ STATUS DLL_EXPORT GDS_DETACH(STATUS * user_status, ATT * handle) the routine "check_database" */ if (!attachment || - (attachment->att_header.blk_type != (UCHAR) type_att) || + (MemoryPool::blk_type(attachment) != type_att) || !(dbb = attachment->att_database) || - dbb->dbb_header.blk_type != (UCHAR) type_dbb) + MemoryPool::blk_type(dbb) != type_dbb) return handle_error(user_status, gds_bad_db_handle, tdbb); /* Make sure this is a valid attachment */ @@ -2187,10 +2214,8 @@ STATUS DLL_EXPORT GDS_DETACH(STATUS * user_status, ATT * handle) tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_status_vector = user_status; - if (SETJMP(env)) { - JRD_SS_MUTEX_UNLOCK; - return error(user_status); - } + + try { /* Purge attachment, don't rollback open transactions */ @@ -2221,6 +2246,12 @@ STATUS DLL_EXPORT GDS_DETACH(STATUS * user_status, ATT * handle) *handle = NULL; return return_success(tdbb); + + } // try + catch (...) { + JRD_SS_MUTEX_UNLOCK; + return error(user_status); + } } @@ -2256,9 +2287,9 @@ STATUS DLL_EXPORT GDS_DROP_DATABASE(STATUS * user_status, ATT * handle) the routine "check_database" */ if (!attachment || - (attachment->att_header.blk_type != (UCHAR) type_att) || + (MemoryPool::blk_type(attachment) != type_att) || !(dbb = attachment->att_database) || - dbb->dbb_header.blk_type != (UCHAR) type_dbb) + MemoryPool::blk_type(dbb) != type_dbb) return handle_error(user_status, gds_bad_db_handle, tdbb); /* Make sure this is a valid attachment */ @@ -2306,18 +2337,14 @@ STATUS DLL_EXPORT GDS_DROP_DATABASE(STATUS * user_status, ATT * handle) V4_JRD_MUTEX_LOCK(databases_mutex); V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); - if (SETJMP(env)) { - V4_JRD_MUTEX_UNLOCK(databases_mutex); - V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); - JRD_SS_MUTEX_UNLOCK; - return error(user_status); - } + try { /* Check if same process has more attachments */ - if ((attach = dbb->dbb_attachments) && (attach->att_next)) + if ((attach = dbb->dbb_attachments) && (attach->att_next)) { ERR_post(gds_no_meta_update, gds_arg_gds, gds_obj_in_use, gds_arg_string, "DATABASE", 0); + } #ifdef CANCEL_OPERATION attachment->att_flags |= ATT_cancel_disable; @@ -2335,12 +2362,21 @@ STATUS DLL_EXPORT GDS_DROP_DATABASE(STATUS * user_status, ATT * handle) header->hdr_ods_version = 0; CCH_RELEASE(tdbb, &window); -/* A default catch all */ - if (SETJMP(env)) { + } // try + catch (...) { + // TMN: It might be that this catch should be moved + // to the very end of this function. Plese verify its + // behaviour and remove this comment - the original code + // using setjmp is in Firebird1 (InterBase "Open" Edition) + V4_JRD_MUTEX_UNLOCK(databases_mutex); + V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); JRD_SS_MUTEX_UNLOCK; return error(user_status); } +/* A default catch all */ + try { + /* This point on database is useless */ /* mark the dbb unusable */ @@ -2376,8 +2412,9 @@ STATUS DLL_EXPORT GDS_DROP_DATABASE(STATUS * user_status, ATT * handle) /* drop the files here. */ err = drop_files(file); - for (; shadow; shadow = shadow->sdw_next) + for (; shadow; shadow = shadow->sdw_next) { err |= drop_files(shadow->sdw_file); + } V4_JRD_MUTEX_UNLOCK(databases_mutex); JRD_SS_MUTEX_UNLOCK; @@ -2392,6 +2429,12 @@ STATUS DLL_EXPORT GDS_DROP_DATABASE(STATUS * user_status, ATT * handle) } return return_success(tdbb); + + } // try + catch (...) { + JRD_SS_MUTEX_UNLOCK; + return error(user_status); + } } @@ -2772,10 +2815,10 @@ STATUS DLL_EXPORT GDS_RECEIVE(STATUS * user_status, ERROR_INIT(env); - if (lev = level) + if ( (lev = level) ) if (!(vector = request->req_sub_requests) || - lev >= vector->vec_count || - !(request = (REQ) vector->vec_object[lev])) + lev >= vector->count() || + !(request = (REQ) (*vector)[lev])) ERR_post(gds_req_sync, 0); #ifdef SCROLLABLE_CURSORS @@ -2922,10 +2965,10 @@ STATUS DLL_EXPORT GDS_REQUEST_INFO(STATUS * user_status, ERROR_INIT(env); - if (lev = level) + if ( (lev = level) ) if (!(vector = request->req_sub_requests) || - lev >= vector->vec_count || - !(request = (REQ) vector->vec_object[lev])) + lev >= vector->count() || + !(request = (REQ) (*vector)[lev])) ERR_post(gds_req_sync, 0); INF_request_info(request, items, item_length, buffer, buffer_length); @@ -3081,10 +3124,10 @@ STATUS DLL_EXPORT GDS_SEND(STATUS * user_status, ERROR_INIT(env); - if (lev = level) + if ( (lev = level) ) if (!(vector = request->req_sub_requests) || - lev >= vector->vec_count || - !(request = (REQ) vector->vec_object[lev])) + lev >= vector->count() || + !(request = (REQ) (*vector)[lev])) ERR_post(gds_req_sync, 0); EXE_send(tdbb, request, msg_type, msg_length, @@ -3448,18 +3491,14 @@ STATUS DLL_EXPORT GDS_START_MULTIPLE(STATUS * user_status, prior = NULL; - if (SETJMP(env)) { - dbb = tdbb->tdbb_database; - --dbb->dbb_use_count; - if (prior) - rollback(tdbb, prior, temp_status, FALSE); - return error(user_status); - } + try { - for (v = vector; v < end; v++) { + for (v = vector; v < end; v++) + { attachment = *v->teb_database; - if (check_database(tdbb, attachment, user_status)) + if (check_database(tdbb, attachment, user_status)) { return user_status[1]; + } #ifdef REPLAY_OSRI_API_CALLS_SUBSYSTEM LOG_call(log_start_multiple, *tra_handle, count, vector); #endif @@ -3467,13 +3506,23 @@ STATUS DLL_EXPORT GDS_START_MULTIPLE(STATUS * user_status, tdbb->tdbb_status_vector = user_status; transaction = TRA_start(tdbb, v->teb_tpb_length, - reinterpret_cast < char *>(v->teb_tpb)); + reinterpret_cast(v->teb_tpb)); transaction->tra_sibling = prior; prior = transaction; dbb = tdbb->tdbb_database; --dbb->dbb_use_count; } + } // try + catch (...) { + dbb = tdbb->tdbb_database; + --dbb->dbb_use_count; + if (prior) { + rollback(tdbb, prior, temp_status, FALSE); + } + return error(user_status); + } + *tra_handle = transaction; #ifdef REPLAY_OSRI_API_CALLS_SUBSYSTEM LOG_call(log_handle_returned, *tra_handle); @@ -3541,12 +3590,9 @@ STATUS DLL_EXPORT GDS_TRANSACT_REQUEST(STATUS* user_status, ACC access; SCL class_; FMT format; - PLB old_pool, new_pool; + JrdMemoryPool *old_pool, *new_pool; USHORT i, len; JMP_BUF env; -#ifdef _PPC_ - JMP_BUF env1; -#endif struct tdbb thd_context; api_entry_point_init(user_status); @@ -3567,34 +3613,20 @@ STATUS DLL_EXPORT GDS_TRANSACT_REQUEST(STATUS* user_status, tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_status_vector = user_status; - if (SETJMP(env)) { - /* Set up to trap error in case release pool goes wrong. */ -#ifdef _PPC_ - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env1)) -#else - if (SETJMP(env)) -#endif - return error(user_status); - if (old_pool) - tdbb->tdbb_default = old_pool; - if (request) - CMP_release(tdbb, request); - else if (new_pool) - ALL_rlpool(new_pool); - return error(user_status); - } + try { transaction = find_transaction(tdbb, *tra_handle, gds_req_wrong_db); old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = new_pool = ALL_pool(); + tdbb->tdbb_default = new_pool = new(*tdbb->tdbb_database->dbb_permanent) + JrdMemoryPool; csb = PAR_parse(tdbb, reinterpret_cast < UCHAR * >(blr), FALSE); request = CMP_make_request(tdbb, &csb); - for (access = request->req_access; access; access = access->acc_next) { + for (access = request->req_access; access; access = access->acc_next) + { class_ = SCL_get_class(access->acc_security_name); SCL_check_access(class_, access->acc_view, access->acc_trg_name, access->acc_prc_name, access->acc_mask, @@ -3603,35 +3635,45 @@ STATUS DLL_EXPORT GDS_TRANSACT_REQUEST(STATUS* user_status, in_message = out_message = NULL; for (i = 0; i < csb->csb_count; i++) - if (node = csb->csb_rpt[i].csb_message) { - if ((int) node->nod_arg[e_msg_number] == 0) + { + if ( (node = csb->csb_rpt[i].csb_message) ) + { + if ((int) node->nod_arg[e_msg_number] == 0) { in_message = node; - else if ((int) node->nod_arg[e_msg_number] == 1) + } else if ((int) node->nod_arg[e_msg_number] == 1) { out_message = node; + } } + } tdbb->tdbb_default = old_pool; old_pool = NULL; request->req_attachment = attachment; - if (in_msg_length) { + if (in_msg_length) + { if (in_message) { format = (FMT) in_message->nod_arg[e_msg_format]; len = format->fmt_length; } - else + else { len = 0; + } if (in_msg_length != len) + { ERR_post(gds_port_len, gds_arg_number, (SLONG) in_msg_length, gds_arg_number, (SLONG) len, 0); - if ((U_IPTR) in_msg & (ALIGNMENT - 1)) + } + if ((U_IPTR) in_msg & (ALIGNMENT - 1)) { MOVE_FAST(in_msg, (SCHAR *) request + in_message->nod_impure, in_msg_length); - else + } + else { MOVE_FASTER(in_msg, (SCHAR *) request + in_message->nod_impure, in_msg_length); + } } EXE_start(tdbb, request, transaction); @@ -3640,26 +3682,52 @@ STATUS DLL_EXPORT GDS_TRANSACT_REQUEST(STATUS* user_status, format = (FMT) out_message->nod_arg[e_msg_format]; len = format->fmt_length; } - else + else { len = 0; - if (out_msg_length != len) + } + if (out_msg_length != len) { ERR_post(gds_port_len, gds_arg_number, (SLONG) out_msg_length, gds_arg_number, (SLONG) len, 0); + } - if (out_msg_length) - if ((U_IPTR) out_msg & (ALIGNMENT - 1)) + if (out_msg_length) { + if ((U_IPTR) out_msg & (ALIGNMENT - 1)) { MOVE_FAST((SCHAR *) request + out_message->nod_impure, out_msg, out_msg_length); - else + } + else { MOVE_FASTER((SCHAR *) request + out_message->nod_impure, out_msg, out_msg_length); + } + } check_autocommit(request, tdbb); CMP_release(tdbb, request); return return_success(tdbb); + + } // try + catch (...) + { + /* Set up to trap error in case release pool goes wrong. */ + + try { + if (old_pool) { + tdbb->tdbb_default = old_pool; + } + if (request) { + CMP_release(tdbb, request); + } else if (new_pool) { + delete new_pool; + } + } // try + catch (...) { + } + + return error(user_status); + } // catch } @@ -3739,19 +3807,25 @@ STATUS DLL_EXPORT GDS_UNWIND(STATUS * user_status, /* Make sure blocks look and feel kosher */ if (!(attachment = request->req_attachment) || - (attachment->att_header.blk_type != (UCHAR) type_att) || + (MemoryPool::blk_type(attachment) != type_att) || !(dbb = attachment->att_database) || - dbb->dbb_header.blk_type != (UCHAR) type_dbb) + MemoryPool::blk_type(dbb) != type_dbb) + { return handle_error(user_status, gds_bad_db_handle, tdbb); + } /* Make sure this is a valid attachment */ for (attach = dbb->dbb_attachments; attach; attach = attach->att_next) - if (attach == attachment) + { + if (attach == attachment) { break; + } + } - if (!attach) + if (!attach) { return handle_error(user_status, gds_bad_db_handle, tdbb); + } tdbb->tdbb_database = dbb; @@ -3765,18 +3839,18 @@ STATUS DLL_EXPORT GDS_UNWIND(STATUS * user_status, tdbb->tdbb_status_vector = user_status; tdbb->tdbb_attachment = attachment; - if (SETJMP(env)) { - JRD_restore_context(); - return user_status[1]; - } + try { /* Pick up and validate request level */ - if (lev = level) - if (!(vector = request->req_sub_requests) || - lev >= vector->vec_count || - !(request = (REQ) vector->vec_object[lev])) + if ( (lev = level) ) { + if (!(vector = request->req_sub_requests) || + lev >= vector->count() || + !(request = (REQ) (*vector)[lev])) + { ERR_post(gds_req_sync, 0); + } + } tdbb->tdbb_request = NULL; tdbb->tdbb_transaction = NULL; @@ -3793,6 +3867,12 @@ STATUS DLL_EXPORT GDS_UNWIND(STATUS * user_status, user_status[2] = gds_arg_end; return (user_status[1] = SUCCESS); + + } // try + catch (...) { + JRD_restore_context(); + return user_status[1]; + } } @@ -3831,7 +3911,7 @@ void JRD_blocked(ATT blocking, BTB * que) if (block) { dbb->dbb_free_btbs = block->btb_next; } else { - block = (BTB) ALLOCP(type_btb); + block = new(*dbb->dbb_permanent) btb; } block->btb_thread_id = (SLONG) SCH_current_thread(); @@ -3992,7 +4072,7 @@ void JRD_print_all_counters(char *fname) ib_fprintf(fptr, "==========================\n"); gds_print_delta_counters(fptr); ALL_print_memory_pool_info(fptr, databases); - ALLD_print_memory_pool_info(fptr); +// ALLD_print_memory_pool_info(fptr); V4_JRD_MUTEX_UNLOCK(databases_mutex); @@ -4015,7 +4095,8 @@ void JRD_print_procedure_info(TDBB tdbb, char *mesg) ******************************************************/ IB_FILE *fptr; TEXT fname[MAXPATHLEN]; - PRC procedure, *ptr, *end; + PRC procedure; + vec::iterator ptr, end; VEC procedures; gds__prefix(fname, "proc_info.log"); @@ -4034,9 +4115,9 @@ void JRD_print_procedure_info(TDBB tdbb, char *mesg) V4_JRD_MUTEX_LOCK(databases_mutex); if (procedures = tdbb->tdbb_database->dbb_procedures) { - for (ptr = (PRC *) procedures->vec_object, end = - ptr + procedures->vec_count; ptr < end; ptr++) - if (procedure = *ptr) + for (ptr = procedures->begin(), end = procedures->end(); + ptr < end; ptr++) + if ( (procedure = *ptr) ) ib_fprintf(fptr, "%s , %d, %X, %d, %d\n", (procedure-> prc_name) ? (char *) procedure->prc_name-> @@ -4337,10 +4418,10 @@ static BLB check_blob(TDBB tdbb, STATUS * user_status, BLB * blob_handle) blob = *blob_handle; if (!blob || - (blob->blb_header.blk_type != (UCHAR) type_blb) || + (MemoryPool::blk_type(blob) != type_blb) || check_database(tdbb, blob->blb_attachment, user_status) || !(transaction = blob->blb_transaction) || - transaction->tra_header.blk_type != (UCHAR) type_tra) { + MemoryPool::blk_type(transaction) != type_tra) { handle_error(user_status, gds_bad_segstr_handle, tdbb); return NULL; } @@ -4377,9 +4458,9 @@ static STATUS check_database(TDBB tdbb, ATT attachment, STATUS * user_status) /* Make sure blocks look and feel kosher */ if (!attachment || - (attachment->att_header.blk_type != (UCHAR) type_att) || + (MemoryPool::blk_type(attachment) != type_att) || !(dbb = attachment->att_database) || - dbb->dbb_header.blk_type != (UCHAR) type_dbb) + MemoryPool::blk_type(dbb)!= type_dbb) return handle_error(user_status, gds_bad_db_handle, tdbb); /* Make sure this is a valid attachment */ @@ -4505,15 +4586,13 @@ static STATUS commit( if (transaction->tra_sibling && !(transaction->tra_flags & TRA_prepared) && prepare(tdbb, transaction, ptr, 0, NULL)) - return error(user_status); - - if (SETJMP(env)) { - dbb = tdbb->tdbb_database; - --dbb->dbb_use_count; + { return error(user_status); } - while (transaction = next) { + try { + + while ( (transaction = next) ) { next = transaction->tra_sibling; check_database(tdbb, transaction->tra_attachment, user_status); tdbb->tdbb_setjmp = (UCHAR *) env; @@ -4524,6 +4603,13 @@ static STATUS commit( } return return_success(tdbb); + + } // try + catch (...) { + dbb = tdbb->tdbb_database; + --dbb->dbb_use_count; + return error(user_status); + } } @@ -4540,7 +4626,7 @@ static STR copy_string(TEXT * ptr, USHORT length) * **************************************/ DBB dbb = get_dbb(); - STR string = (STR) ALLOCPV(type_str, length); + STR string = new(*dbb->dbb_permanent, length) str(); string->str_length = length; MOVE_FAST(ptr, string->str_data, length); @@ -4601,7 +4687,7 @@ static TRA find_transaction(TDBB tdbb, TRA transaction, STATUS error_code) SET_TDBB(tdbb); - if (!transaction || transaction->tra_header.blk_type != (UCHAR) type_tra) + if (!transaction || MemoryPool::blk_type(transaction) != type_tra) ERR_post(gds_bad_trans_handle, 0); for (; transaction; transaction = transaction->tra_sibling) @@ -4632,7 +4718,7 @@ static STATUS error(STATUS * user_status) /* Decrement count of active threads in database */ - if (dbb = tdbb->tdbb_database) { + if ( (dbb = tdbb->tdbb_database) ) { --dbb->dbb_use_count; } @@ -5130,7 +5216,7 @@ static TEXT* get_string_parameter(UCHAR** dpb_ptr, TEXT** opt_ptr) opt = *opt_ptr; dpb = *dpb_ptr; - if (l = *(dpb++)) + if ( (l = *(dpb++)) ) do *opt++ = *dpb++; while (--l); @@ -5219,10 +5305,9 @@ static DBB init(TDBB tdbb, * OPEN. * **************************************/ - DBB dbb; + DBB dbb_; STR string; VEC vector; - struct dbb temp; MUTX_T temp_mutx[DBB_MUTX_max]; WLCK_T temp_wlck[DBB_WLCK_max]; JMP_BUF env; @@ -5259,67 +5344,65 @@ static DBB init(TDBB tdbb, /* Check to see if the database is already actively attached */ - for (dbb = databases; dbb; dbb = dbb->dbb_next) + for (dbb_ = databases; dbb_; dbb_ = dbb_->dbb_next) { - if (!(dbb->dbb_flags & (DBB_bugcheck | DBB_not_in_use)) && + if (!(dbb_->dbb_flags & (DBB_bugcheck | DBB_not_in_use)) && #ifndef SUPERSERVER - !(dbb->dbb_ast_flags & DBB_shutdown && - dbb->dbb_ast_flags & DBB_shutdown_locks) && + !(dbb_->dbb_ast_flags & DBB_shutdown && + dbb_->dbb_ast_flags & DBB_shutdown_locks) && #endif - (string = dbb->dbb_filename) && + (string = dbb_->dbb_filename) && !strcmp(reinterpret_cast(string->str_data), expanded_filename)) { - return (attach_flag) ? dbb : NULL; + return (attach_flag) ? dbb_ : NULL; } } /* Clean up temporary DBB and initialize a SETJMP for error reporting */ - MOVE_CLEAR(&temp, (SLONG) sizeof(struct dbb)); + /* MOVE_CLEAR(&temp, (SLONG) sizeof(struct dbb)); */ THD_MUTEX_INIT_N(temp_mutx, DBB_MUTX_max); V4_RW_LOCK_INIT_N(temp_wlck, DBB_WLCK_max); /* set up the temporary database block with fields that are required for doing the ALL_init() */ - temp.dbb_header.blk_type = type_dbb; - temp.dbb_mutexes = temp_mutx; - temp.dbb_rw_locks = temp_wlck; - - tdbb->tdbb_database = dbb = &temp; tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_status_vector = user_status; - if (SETJMP(env)) - return 0; - ALL_init(); + tdbb->tdbb_database = 0; - tdbb->tdbb_database = dbb = (DBB) ALLOCP(type_dbb); + try { + + JrdMemoryPool* perm = new(*FB_MemoryPool) JrdMemoryPool; + dbb_ = dbb::newDbb(*perm); + //temp.blk_type = type_dbb; + dbb_->dbb_permanent = perm; + dbb_->dbb_mutexes = temp_mutx; + dbb_->dbb_rw_locks = temp_wlck; + tdbb->tdbb_database = dbb_; + + ALL_init(); THD_MUTEX_DESTROY_N(temp_mutx, DBB_MUTX_max); V4_RW_LOCK_DESTROY_N(temp_wlck, DBB_WLCK_max); - MOVE_FAST((UCHAR *) & temp + sizeof(struct blk), - (UCHAR *) dbb + sizeof(struct blk), - sizeof(struct dbb) - sizeof(struct blk)); - - dbb->dbb_next = databases; - databases = dbb; + dbb_->dbb_next = databases; + databases = dbb_; string = - (STR) ALLOCPV(type_str, THREAD_STRUCT_SIZE(MUTX_T, DBB_MUTX_max)); - dbb->dbb_mutexes = (MUTX) THREAD_STRUCT_ALIGN(string->str_data); - THD_MUTEX_INIT_N(dbb->dbb_mutexes, DBB_MUTX_max); + new(*dbb_->dbb_permanent, THREAD_STRUCT_SIZE(MUTX_T, DBB_MUTX_max)) str(); + + dbb_->dbb_mutexes = (MUTX) THREAD_STRUCT_ALIGN(string->str_data); + THD_MUTEX_INIT_N(dbb_->dbb_mutexes, DBB_MUTX_max); string = - (STR) ALLOCPV(type_str, THREAD_STRUCT_SIZE(WLCK_T, DBB_WLCK_max)); - dbb->dbb_rw_locks = (WLCK) THREAD_STRUCT_ALIGN(string->str_data); - V4_RW_LOCK_INIT_N(dbb->dbb_rw_locks, DBB_WLCK_max); - dbb->dbb_internal = vector = (VEC) ALLOCPV(type_vec, irq_MAX); - vector->vec_count = (SSHORT) irq_MAX; - dbb->dbb_dyn_req = vector = (VEC) ALLOCPV(type_vec, drq_MAX); - vector->vec_count = (SSHORT) drq_MAX; - dbb->dbb_flags |= DBB_exclusive; - dbb->dbb_sweep_interval = SWEEP_INTERVAL; + new(*dbb_->dbb_permanent, THREAD_STRUCT_SIZE(WLCK_T, DBB_WLCK_max)) str(); + dbb_->dbb_rw_locks = (WLCK) THREAD_STRUCT_ALIGN(string->str_data); + V4_RW_LOCK_INIT_N(dbb_->dbb_rw_locks, DBB_WLCK_max); + dbb_->dbb_internal = vector = vec::newVector(*dbb_->dbb_permanent, irq_MAX); + dbb_->dbb_dyn_req = vector = vec::newVector(*dbb_->dbb_permanent, drq_MAX); + dbb_->dbb_flags |= DBB_exclusive; + dbb_->dbb_sweep_interval = SWEEP_INTERVAL; /* Initialize a number of subsystems */ @@ -5328,15 +5411,20 @@ static DBB init(TDBB tdbb, #ifdef ISC_DATABASE_ENCRYPTION /* Lookup some external "hooks" */ - if (dbb->dbb_encrypt = ISC_lookup_entrypoint(ENCRYPT_IMAGE, ENCRYPT, NULL)) + if (dbb_->dbb_encrypt = ISC_lookup_entrypoint(ENCRYPT_IMAGE, ENCRYPT, NULL)) { - dbb->dbb_decrypt = ISC_lookup_entrypoint(ENCRYPT_IMAGE, DECRYPT, NULL); + dbb_->dbb_decrypt = ISC_lookup_entrypoint(ENCRYPT_IMAGE, DECRYPT, NULL); } #endif INTL_init(tdbb); - return dbb; + return dbb_; + + } // try + catch (...) { + return 0; + } } @@ -5370,7 +5458,7 @@ static void make_jrn_data(UCHAR* data, } while (--len); } - if (len = db_len) { + if ( (len = db_len) ) { *t++ = JRNW_DB_NAME; *t++ = (UCHAR) db_len; const UCHAR* q = reinterpret_cast(db_name); @@ -5406,11 +5494,7 @@ static STATUS prepare(TDBB tdbb, SET_TDBB(tdbb); - if (SETJMP(env)) { - dbb = tdbb->tdbb_database; - --dbb->dbb_use_count; - return status_vector[1]; - } + try { for (; transaction; transaction = transaction->tra_sibling) { check_database(tdbb, transaction->tra_attachment, status_vector); @@ -5421,6 +5505,13 @@ static STATUS prepare(TDBB tdbb, --dbb->dbb_use_count; } + } // try + catch (...) { + dbb = tdbb->tdbb_database; + --dbb->dbb_use_count; + return status_vector[1]; + } + return SUCCESS; } @@ -5446,7 +5537,8 @@ static void release_attachment(ATT attachment) ATT *ptr; VCL *vector; VEC lock_vector; - LCK *lock, record_lock; + LCK record_lock; + vec::iterator lock; USHORT i; TDBB tdbb = get_thread_data(); @@ -5468,35 +5560,35 @@ static void release_attachment(ATT attachment) for (vector = attachment->att_counts; vector < attachment->att_counts + DBB_max_count; ++vector) if (*vector) - ALL_RELEASE(*vector); + delete *vector; if (attachment->att_working_directory) - ALL_RELEASE(attachment->att_working_directory); + delete attachment->att_working_directory; if (attachment->att_lc_messages) - ALL_RELEASE(attachment->att_lc_messages); + delete attachment->att_lc_messages; /* Release any validation error vector allocated */ if (attachment->att_val_errors) { - ALL_RELEASE(attachment->att_val_errors); + delete attachment->att_val_errors; attachment->att_val_errors = (VCL) 0; } /* Release the persistent locks taken out during the attachment */ - if (lock_vector = attachment->att_relation_locks) + if ( (lock_vector = attachment->att_relation_locks) ) { - for (i = 0, lock = (LCK *) lock_vector->vec_object; - i < lock_vector->vec_count; i++, lock++) + for (i = 0, lock = lock_vector->begin(); + i < lock_vector->count(); i++, lock++) { if (*lock) { - LCK_release(tdbb, *lock); - ALL_RELEASE(*lock); + LCK_release(tdbb, (LCK)(*lock)); + delete *lock; } } - ALL_RELEASE(lock_vector); + delete lock_vector; } for (record_lock = attachment->att_record_locks; record_lock; @@ -5519,12 +5611,12 @@ static void release_attachment(ATT attachment) LCK_fini(tdbb, LCK_OWNER_attachment); /* For the attachment */ if (attachment->att_compatibility_table) - ALL_RELEASE(attachment->att_compatibility_table); + delete attachment->att_compatibility_table; V4_JRD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); V4_JRD_MUTEX_LOCK(databases_mutex); - if (dbb->dbb_header.blk_type != (UCHAR) type_dbb) + if (MemoryPool::blk_type(dbb) != type_dbb) return; /* remove the attachment block from the dbb linked list */ @@ -5557,7 +5649,7 @@ static STATUS return_success(TDBB tdbb) /* Decrement count of active threads in database */ - if (dbb = tdbb->tdbb_database) + if ( (dbb = tdbb->tdbb_database) ) --dbb->dbb_use_count; p = user_status = tdbb->tdbb_status_vector; @@ -5620,20 +5712,25 @@ static BOOLEAN rollback(TDBB tdbb, SET_TDBB(tdbb); - while (transaction = next) { + while ( (transaction = next) ) + { next = transaction->tra_sibling; check_database(tdbb, transaction->tra_attachment, status_vector); - if (SETJMP(env)) { - status_vector = local_status; - dbb = tdbb->tdbb_database; - --dbb->dbb_use_count; - continue; - } + + try { tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_status_vector = status_vector; TRA_rollback(tdbb, transaction, retaining_flag); dbb = tdbb->tdbb_database; --dbb->dbb_use_count; + + } // try + catch (...) { + status_vector = local_status; + dbb = tdbb->tdbb_database; + --dbb->dbb_use_count; + continue; + } } return (status_vector == local_status); @@ -5716,14 +5813,13 @@ static void shutdown_database(DBB dbb, BOOLEAN release_pools) if (dbb->dbb_relations) { VEC vector = dbb->dbb_relations; - REL* ptr = (REL*)vector->vec_object; - const REL* end = ptr + vector->vec_count; + vec::iterator ptr = vector->begin(), end = vector->end(); for (; ptr < end; ++ptr) { - if (*ptr && (*ptr)->rel_file) + if (*ptr && ((REL)(*ptr))->rel_file) { - EXT_fini(*ptr); + EXT_fini((REL)(*ptr)); } } } @@ -6087,17 +6183,20 @@ ULONG JRD_shutdown_all() tdbb->tdbb_setjmp = (UCHAR *) env; tdbb->tdbb_status_vector = user_status; - if (SETJMP(env)) { - if (initialized) + + try { + /* purge_attachment, rollback any open transactions */ + + V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); + purge_attachment(tdbb, user_status, att, TRUE); + V4_JRD_MUTEX_UNLOCK(databases_mutex); + } // try + catch (...) { + if (initialized) { JRD_SS_MUTEX_UNLOCK; + } return error(user_status); } - - /* purge_attachment, rollback any open transactions */ - - V4_JRD_MUTEX_LOCK(dbb->dbb_mutexes + DBB_MUTX_init_fini); - purge_attachment(tdbb, user_status, att, TRUE); - V4_JRD_MUTEX_UNLOCK(databases_mutex); } } } @@ -6171,7 +6270,7 @@ static void purge_attachment(TDBB tdbb, /* If there's a side transaction for db-key scope, get rid of it */ - if (transaction = attachment->att_dbkey_trans) + if ( (transaction = attachment->att_dbkey_trans) ) { attachment->att_dbkey_trans = NULL; if (dbb->dbb_ast_flags & DBB_shutdown || @@ -6197,33 +6296,33 @@ static void purge_attachment(TDBB tdbb, /* If there are still attachments, do a partial shutdown */ - if (dbb->dbb_header.blk_type == (UCHAR) type_dbb) + if (MemoryPool::blk_type(dbb) == type_dbb) { if (dbb->dbb_attachments || (dbb->dbb_flags & DBB_being_opened)) { /* There are still attachments so do a partial shutdown */ - while (request = attachment->att_requests) { + while ( (request = attachment->att_requests) ) { CMP_release(tdbb, request); } - while (class_ = attachment->att_security_classes) { + while ( (class_ = attachment->att_security_classes) ) { SCL_release(class_); } - if (user = attachment->att_user) { - ALL_RELEASE(user); + if ( (user = attachment->att_user) ) { + delete user; } - while (bookmark = attachment->att_bookmarks) { + while ( (bookmark = attachment->att_bookmarks) ) { attachment->att_bookmarks = bookmark->bkm_next; - ALL_RELEASE(bookmark); + delete bookmark; } if (attachment->att_bkm_quick_ref) { - ALL_RELEASE(attachment->att_bkm_quick_ref); + delete attachment->att_bkm_quick_ref; } if (attachment->att_lck_quick_ref) { - ALL_RELEASE(attachment->att_lck_quick_ref); + delete attachment->att_lck_quick_ref; } - ALL_RELEASE(attachment); + delete attachment; } else { diff --git a/src/jrd/jrd.h b/src/jrd/jrd.h index 96de6f8cfd..aa94fa55ee 100644 --- a/src/jrd/jrd.h +++ b/src/jrd/jrd.h @@ -27,6 +27,9 @@ #include "../jrd/gdsassert.h" #include "../jrd/common.h" #include "../jrd/dsc.h" +#include "../jrd/all.h" + +#include "../include/fb_vector.h" #ifdef __cplusplus extern "C" { @@ -45,41 +48,24 @@ extern "C" { #define MAX_PATH_LENGTH 512 -#define BUGCHECK(number) ERR_bugcheck (number) +/* Moved to err_proto.h */ +/*#define BUGCHECK(number) ERR_bugcheck (number) #define CORRUPT(number) ERR_corrupt (number) #define IBERROR(number) ERR_error (number) +*/ -/* Error delivery type */ - -typedef enum err_t { - ERR_jmp, /* longjmp */ - ERR_val, /* value */ - ERR_ref /* reference */ -} ERR_T; - -#define BLKCHK(blk, type) if (((BLK) (blk))->blk_type != (UCHAR) (type)) BUGCHECK (147) +#define BLKCHK(blk, type) if (MemoryPool::blk_type(blk) != (USHORT) (type)) BUGCHECK (147) /* DEV_BLKCHK is used for internal consistency checking - where * the performance hit in production build isn't desired. * (eg: scatter this everywhere) */ #ifdef DEV_BUILD -#define DEV_BLKCHK(blk,type) if (((BLK) (blk)) != NULL) {BLKCHK (blk, type);} +#define DEV_BLKCHK(blk,type) if (blk) {BLKCHK (blk, type);} #else #define DEV_BLKCHK(blk,type) /* nothing */ #endif -#define ALLOCB(type) ALL_alloc (dbb->dbb_bufferpool, type, 0, ERR_jmp) -#define ALLOCBV(type,repeat) ALL_alloc (dbb->dbb_bufferpool, type, repeat, ERR_jmp) -#define ALLOCBR(type) ALL_alloc (dbb->dbb_bufferpool, type, 0, ERR_val) -#define ALLOCBVR(type,repeat) ALL_alloc (dbb->dbb_bufferpool, type, repeat, ERR_val) -#define ALLOCD(type) ALL_alloc (tdbb->tdbb_default, type, 0, ERR_jmp) -#define ALLOCDV(type,repeat) ALL_alloc (tdbb->tdbb_default, type, repeat, ERR_jmp) -#define ALLOCP(type) ALL_alloc (dbb->dbb_permanent, type, 0, ERR_jmp) -#define ALLOCPV(type,repeat) ALL_alloc (dbb->dbb_permanent, type, repeat, ERR_jmp) -#define ALLOCT(type) ALL_alloc (transaction->tra_pool, type, 0, ERR_jmp) -#define ALLOCTV(type,repeat) ALL_alloc (transaction->tra_pool, type, repeat, ERR_jmp) - /* Thread data block / IPC related data blocks */ @@ -90,30 +76,9 @@ typedef enum err_t { #include "../jrd/thd.h" #include "../jrd/isc.h" -/* definition of block types for data allocation */ - -#ifdef __cplusplus -extern "C" { -#endif - - -#define BLKDEF(type, root, tail) type, -enum blk_t { - type_MIN = 0, -#ifndef GATEWAY -#include "../jrd/blk.h" -#else -#include ".._gway/gway/blk.h" -#endif - type_MAX -}; -#undef BLKDEF - -/* Block types */ - -#ifndef INCLUDE_FB_BLK +/* definition of block types for data allocation in JRD */ +#include "../jrd/jrd_blks.h" #include "../include/fb_blk.h" -#endif /* the database block, the topmost block in the metadata @@ -124,10 +89,13 @@ enum blk_t { #else #define HASH_SIZE 101 -typedef struct dbb { - struct blk dbb_header; - struct dbb *dbb_next; /* Next database block in system */ - struct att *dbb_attachments; /* Active attachments */ +class dbb : private pool_alloc +{ +public: + static dbb* newDbb(MemoryPool& p) { return new(p) dbb(p); } + + class dbb *dbb_next; /* Next database block in system */ + class att *dbb_attachments; /* Active attachments */ struct bcb *dbb_bcb; /* Buffer control block */ struct vec *dbb_relations; /* relation vector */ struct vec *dbb_procedures; /* scanned procedures */ @@ -140,8 +108,8 @@ typedef struct dbb { struct lck *dbb_retaining_lock; /* lock for preserving commit retaining snapshot */ struct plc *dbb_connection; /* connection block */ struct pgc *dbb_pcontrol; /* page control */ - struct vcl *dbb_t_pages; /* pages number for transactions */ - struct vcl *dbb_gen_id_pages; /* known pages for gen_id */ + class vcl *dbb_t_pages; /* pages number for transactions */ + class vcl *dbb_gen_id_pages; /* known pages for gen_id */ struct blf *dbb_blob_filters; /* known blob filters */ struct lls *dbb_modules; /* external function/filter modules */ MUTX_T *dbb_mutexes; /* DBB block mutexes */ @@ -162,15 +130,20 @@ typedef struct dbb { USHORT dbb_refresh_ranges; /* active count of refresh ranges */ USHORT dbb_prefetch_sequence; /* sequence to pace frequency of prefetch requests */ USHORT dbb_prefetch_pages; /* prefetch pages per request */ - struct str *dbb_spare_string; /* random buffer */ - struct str *dbb_filename; /* filename string */ + class str *dbb_spare_string; /* random buffer */ + class str *dbb_filename; /* filename string */ #ifdef ISC_DATABASE_ENCRYPTION - struct str *dbb_encrypt_key; /* encryption key */ + class str *dbb_encrypt_key; /* encryption key */ #endif - struct plb *dbb_permanent; - struct plb *dbb_bufferpool; - struct vec *dbb_pools; /* pools */ + JrdMemoryPool* dbb_permanent; + JrdMemoryPool* dbb_bufferpool; + + typedef JrdMemoryPool* pool_ptr; + typedef Firebird::vector pool_vec_type; + + pool_vec_type dbb_pools; /* pools */ + USHORT dbb_next_pool_id; struct vec *dbb_internal; /* internal requests */ struct vec *dbb_dyn_req; /* internal dyn requests */ struct jrn *dbb_journal; /* journal block */ @@ -188,9 +161,9 @@ typedef struct dbb { #ifdef GARBAGE_THREAD EVENT_T dbb_gc_event[1]; /* Event to wake up garbage collector */ #endif - struct att *dbb_update_attachment; /* Attachment with update in process */ - struct btb *dbb_update_que; /* Attachments waiting for update */ - struct btb *dbb_free_btbs; /* Unused btb blocks */ + class att *dbb_update_attachment; /* Attachment with update in process */ + class btb *dbb_update_que; /* Attachments waiting for update */ + class btb *dbb_free_btbs; /* Unused btb blocks */ SLONG dbb_current_memory; SLONG dbb_max_memory; @@ -208,34 +181,44 @@ typedef struct dbb { int (*dbb_decrypt) (); /* External decryption routine */ #endif - struct map *dbb_blob_map; /* mapping of blobs for REPLAY */ + class map *dbb_blob_map; /* mapping of blobs for REPLAY */ struct log *dbb_log; /* log file for REPLAY */ struct vec *dbb_text_objects; /* intl text type descriptions */ struct vec *dbb_charsets; /* intl character set descriptions */ struct wal *dbb_wal; /* WAL handle for WAL API */ struct tpc *dbb_tip_cache; /* cache of latest known state of all transactions in system */ - struct vcl *dbb_pc_transactions; /* active precommitted transactions */ - struct sym *dbb_hash_table[HASH_SIZE]; /* keep this at the end */ -} *DBB; + class vcl *dbb_pc_transactions; /* active precommitted transactions */ + class sym *dbb_hash_table[HASH_SIZE]; /* keep this at the end */ -/* bit values for dbb_flags */ +private: + dbb(MemoryPool& p) + : dbb_pools(10, p, type_dbb) + { + } + dbb(const dbb&); // no impl. + const dbb& operator =(const dbb&) { return *this; } +}; +typedef dbb* DBB; +// +// bit values for dbb_flags +// #define DBB_no_garbage_collect 0x1L #define DBB_damaged 0x2L #define DBB_exclusive 0x4L /* Database is accessed in exclusive mode */ #define DBB_bugcheck 0x8L /* Bugcheck has occurred */ #ifdef GARBAGE_THREAD #define DBB_garbage_collector 0x10L /* garbage collector thread exists */ -#define DBB_gc_active 0x20L /* ... and is actively working. */ -#define DBB_gc_pending 0x40L /* garbage collection requested */ +#define DBB_gc_active 0x20L /* ... and is actively working. */ +#define DBB_gc_pending 0x40L /* garbage collection requested */ #endif #define DBB_force_write 0x80L /* Database is forced write */ -#define DBB_no_reserve 0x100L /* No reserve space for versions */ +#define DBB_no_reserve 0x100L /* No reserve space for versions */ #define DBB_add_log 0x200L /* write ahead log has been added */ #define DBB_delete_log 0x400L /* write ahead log has been deleted */ #define DBB_cache_manager 0x800L /* Shared cache manager */ #define DBB_DB_SQL_dialect_3 0x1000L /* database SQL dialect 3 */ -#define DBB_read_only 0x2000L /* DB is ReadOnly (RO). If not set, DB is RW */ +#define DBB_read_only 0x2000L /* DB is ReadOnly (RO). If not set, DB is RW */ #define DBB_being_opened_read_only 0x4000L /* DB is being opened RO. If unset, opened as RW */ #define DBB_not_in_use 0x8000L /* DBB to be ignored while attaching */ #define DBB_lck_init_done 0x10000L /* LCK_init() called for the database */ @@ -243,22 +226,24 @@ typedef struct dbb { #define DBB_sweep_in_progress 0x40000L /* A database sweep operation is in progress */ #define DBB_security_db 0x80000L /* ISC security database */ #define DBB_sweep_thread_started 0x100000L /* A database sweep thread has been started */ -#define DBB_suspend_bgio 0x200000L /* Suspend I/O by background threads */ +#define DBB_suspend_bgio 0x200000L /* Suspend I/O by background threads */ #define DBB_being_opened 0x400000L /* database is being attached to */ -/* dbb_ast_flags */ - -#define DBB_blocking 0x1L /* Exclusive mode is blocking */ -#define DBB_get_shadows 0x2L /* Signal received to check for new shadows */ -#define DBB_assert_locks 0x4L /* Locks are to be asserted */ -#define DBB_shutdown 0x8L /* Database is shutdown */ -#define DBB_shut_attach 0x10L /* no new attachments accepted */ -#define DBB_shut_tran 0x20L /* no new transactions accepted */ -#define DBB_shut_force 0x40L /* forced shutdown in progress */ -#define DBB_shutdown_locks 0x80L /* Database locks release by shutdown */ - -/* Database attachments */ +// +// dbb_ast_flags +// +#define DBB_blocking 0x1L // Exclusive mode is blocking +#define DBB_get_shadows 0x2L // Signal received to check for new shadows +#define DBB_assert_locks 0x4L // Locks are to be asserted +#define DBB_shutdown 0x8L // Database is shutdown +#define DBB_shut_attach 0x10L // no new attachments accepted +#define DBB_shut_tran 0x20L // no new transactions accepted +#define DBB_shut_force 0x40L // forced shutdown in progress +#define DBB_shutdown_locks 0x80L // Database locks release by shutdown +// +// Database attachments +// #define DBB_read_seq_count 0 #define DBB_read_idx_count 1 #define DBB_update_count 2 @@ -269,37 +254,39 @@ typedef struct dbb { #define DBB_expunge_count 7 #define DBB_max_count 8 -/* Database mutexes and read/write locks */ - -#define DBB_MUTX_init_fini 0 /* During startup and shutdown */ -#define DBB_MUTX_statistics 1 /* Memory size and counts */ -#define DBB_MUTX_replay 2 /* Replay logging */ -#define DBB_MUTX_dyn 3 /* Dynamic ddl */ -#define DBB_MUTX_cache 4 /* Process-private cache management */ -#define DBB_MUTX_clone 5 /* Request cloning */ -#define DBB_MUTX_cmp_clone 6 /* Compiled request cloning */ +// +// Database mutexes and read/write locks +// +#define DBB_MUTX_init_fini 0 // During startup and shutdown +#define DBB_MUTX_statistics 1 // Memory size and counts +#define DBB_MUTX_replay 2 // Replay logging +#define DBB_MUTX_dyn 3 // Dynamic ddl +#define DBB_MUTX_cache 4 // Process-private cache management +#define DBB_MUTX_clone 5 // Request cloning +#define DBB_MUTX_cmp_clone 6 // Compiled request cloning #ifndef NETWARE_386 #define DBB_MUTX_max 7 #else -#define DBB_MUTX_udf 7 /* UDF lookup */ -#define DBB_MUTX_grant_priv 8 /* Generate user privileges */ -#define DBB_MUTX_get_class 9 /* Read a security class */ +#define DBB_MUTX_udf 7 // UDF lookup +#define DBB_MUTX_grant_priv 8 // Generate user privileges +#define DBB_MUTX_get_class 9 // Read a security class #define DBB_MUTX_max 10 #endif -#define DBB_WLCK_pools 0 /* Pool manipulation */ -#define DBB_WLCK_files 1 /* DB and shadow file manipulation */ +#define DBB_WLCK_pools 0 // Pool manipulation +#define DBB_WLCK_files 1 // DB and shadow file manipulation #define DBB_WLCK_max 2 -/* Flags to indicate normal internal requests vs. dyn internal requests */ - +// +// Flags to indicate normal internal requests vs. dyn internal requests +// #define IRQ_REQUESTS 1 #define DYN_REQUESTS 2 - -/* Errors during validation - will be returned on info calls */ - +// +// Errors during validation - will be returned on info calls +// #define VAL_PAG_WRONG_TYPE 0 #define VAL_PAG_CHECKSUM_ERR 1 #define VAL_PAG_DOUBLE_ALLOC 2 @@ -329,57 +316,90 @@ typedef struct dbb { -/* the attachment block; one is created for each attachment - to a database */ +// +// the attachment block; one is created for each attachment to a database +// +class att : public pool_alloc +{ +public: + att() + : att_database(0), + att_next(0), + att_blocking(0), + att_user(0), + att_transactions(0), + att_dbkey_trans(0), + att_requests(0), + att_active_sorts(0), + att_id_lock(0), + att_attachment_id(0), + att_lock_owner_handle(0), + att_event_session(0), + att_security_class(0), + att_security_classes(0), + att_relation_locks(0), + att_bookmarks(0), + att_record_locks(0), + att_bkm_quick_ref(0), + att_lck_quick_ref(0), + att_flags(0), + att_charset(0), + att_lc_messages(0), + att_long_locks(0), + att_compatibility_table(0), + att_val_errors(0), + att_working_directory(0) + { + att_counts[0] = 0; + } -typedef struct att { - struct blk att_header; - struct dbb *att_database; /* Parent databasea block */ - struct att *att_next; /* Next attachment to database */ - struct att *att_blocking; /* Blocking attachment, if any */ - struct usr *att_user; /* User identification */ - struct tra *att_transactions; /* Transactions belonging to attachment */ - struct tra *att_dbkey_trans; /* transaction to control db-key scope */ - struct req *att_requests; /* Requests belonging to attachment */ - struct scb *att_active_sorts; /* Active sorts */ - struct lck *att_id_lock; /* Attachment lock (if any) */ - SLONG att_attachment_id; /* Attachment ID */ - SLONG att_lock_owner_handle; /* Handle for the lock manager */ - SLONG att_event_session; /* Event session id, if any */ - struct scl *att_security_class; /* security class for database */ - struct scl *att_security_classes; /* security classes */ - struct vcl *att_counts[DBB_max_count]; - struct vec *att_relation_locks; /* explicit persistent locks for relations */ - struct bkm *att_bookmarks; /* list of bookmarks taken out using this attachment */ - struct lck *att_record_locks; /* explicit or implicit record locks taken out during attachment */ - struct vec *att_bkm_quick_ref; /* correspondence table of bookmarks */ - struct vec *att_lck_quick_ref; /* correspondence table of locks */ - ULONG att_flags; /* Flags describing the state of the attachment */ - SSHORT att_charset; /* user's charset specified in dpb */ - struct str *att_lc_messages; /* attachment's preference for message natural language */ - struct lck *att_long_locks; /* outstanding two phased locks */ - struct vec *att_compatibility_table; /* hash table of compatible locks */ - struct vcl *att_val_errors; - struct str *att_working_directory; /* Current working directory is cached */ -} *ATT; + class dbb* att_database; // Parent databasea block + att* att_next; // Next attachment to database + att* att_blocking; // Blocking attachment, if any + class usr* att_user; // User identification + struct tra* att_transactions; // Transactions belonging to attachment + struct tra* att_dbkey_trans; // transaction to control db-key scope + struct req* att_requests; // Requests belonging to attachment + struct scb* att_active_sorts; // Active sorts + struct lck* att_id_lock; // Attachment lock (if any) + SLONG att_attachment_id; // Attachment ID + SLONG att_lock_owner_handle; // Handle for the lock manager + SLONG att_event_session; // Event session id, if any + class scl* att_security_class; // security class for database + class scl* att_security_classes; // security classes + class vcl* att_counts[DBB_max_count]; + struct vec* att_relation_locks; // explicit persistent locks for relations + struct bkm* att_bookmarks; // list of bookmarks taken out using this attachment + struct lck* att_record_locks; // explicit or implicit record locks taken out during attachment + struct vec* att_bkm_quick_ref; // correspondence table of bookmarks + struct vec* att_lck_quick_ref; // correspondence table of locks + ULONG att_flags; // Flags describing the state of the attachment + SSHORT att_charset; // user's charset specified in dpb + class str* att_lc_messages; // attachment's preference for message natural language + struct lck* att_long_locks; // outstanding two phased locks + struct vec* att_compatibility_table; // hash table of compatible locks + class vcl* att_val_errors; + class str* att_working_directory; // Current working directory is cached +}; +typedef att* ATT; /* Attachment flags */ -#define ATT_no_cleanup 1 /* Don't expunge, purge, or garbage collect */ -#define ATT_shutdown 2 /* attachment has been shutdown */ -#define ATT_shutdown_notify 4 /* attachment has notified client of shutdown */ -#define ATT_shutdown_manager 8 /* attachment requesting shutdown */ -#define ATT_lck_init_done 16 /* LCK_init() called for the attachment */ -#define ATT_exclusive 32 /* attachment wants exclusive database access */ -#define ATT_attach_pending 64 /* Indicate attachment is only pending */ -#define ATT_exclusive_pending 128 /* Indicate exclusive attachment pending */ -#define ATT_gbak_attachment 256 /* Indicate GBAK attachment */ -#define ATT_security_db 512 /* Indicates an implicit attachment to the security db */ +#define ATT_no_cleanup 1 // Don't expunge, purge, or garbage collect +#define ATT_shutdown 2 // attachment has been shutdown +#define ATT_shutdown_notify 4 // attachment has notified client of shutdown +#define ATT_shutdown_manager 8 // attachment requesting shutdown +#define ATT_lck_init_done 16 // LCK_init() called for the attachment +#define ATT_exclusive 32 // attachment wants exclusive database access +#define ATT_attach_pending 64 // Indicate attachment is only pending +#define ATT_exclusive_pending 128 // Indicate exclusive attachment pending +#define ATT_gbak_attachment 256 // Indicate GBAK attachment +#define ATT_security_db 512 // Indicates an implicit attachment to the security db #ifdef GARBAGE_THREAD -#define ATT_notify_gc 1024 /* Notify garbage collector to expunge, purge .. */ -#define ATT_disable_notify_gc 2048 /* Temporarily perform own garbage collection */ -#define ATT_garbage_collector 4096 /* I'm a garbage collector */ +#define ATT_notify_gc 1024 // Notify garbage collector to expunge, purge .. +#define ATT_disable_notify_gc 2048 // Temporarily perform own garbage collection +#define ATT_garbage_collector 4096 // I'm a garbage collector #define ATT_NO_CLEANUP (ATT_no_cleanup | ATT_notify_gc) #else @@ -387,18 +407,19 @@ typedef struct att { #endif #ifdef CANCEL_OPERATION -#define ATT_cancel_raise 8192 /* Cancel currently running operation */ -#define ATT_cancel_disable 16384 /* Disable cancel operations */ +#define ATT_cancel_raise 8192 // Cancel currently running operation +#define ATT_cancel_disable 16384 // Disable cancel operations #endif -#define ATT_gfix_attachment 32768 /* Indicate a GFIX attachment */ -#define ATT_gstat_attachment 65536 /* Indicate a GSTAT attachment */ +#define ATT_gfix_attachment 32768 // Indicate a GFIX attachment +#define ATT_gstat_attachment 65536 // Indicate a GSTAT attachment /* Procedure block */ -typedef struct prc { - struct blk prc_header; +class prc : public pool_alloc_rpt +{ + public: USHORT prc_id; USHORT prc_flags; USHORT prc_inputs; @@ -411,18 +432,18 @@ typedef struct prc { struct vec *prc_input_fields; /* vector of field blocks */ struct vec *prc_output_fields; /* vector of field blocks */ struct req *prc_request; /* compiled procedure request */ - struct str *prc_security_name; /* pointer to security class name for procedure */ + class str *prc_security_name; /* pointer to security class name for procedure */ USHORT prc_use_count; /* requests compiled with relation */ struct lck *prc_existence_lock; /* existence lock, if any */ - struct str *prc_name; /* pointer to ascic name */ + class str *prc_name; /* pointer to ascic name */ USHORT prc_alter_count; /* No. of times the procedure was altered */ +}; +typedef prc* PRC; -} *PRC; - -#define PRC_scanned 1 /* Field expressions scanned */ +#define PRC_scanned 1 /* Field expressions scanned */ #define PRC_system 2 -#define PRC_obsolete 4 /* Procedure known gonzo */ -#define PRC_being_scanned 8 /* New procedure needs dependencies during scan */ +#define PRC_obsolete 4 /* Procedure known gonzo */ +#define PRC_being_scanned 8 /* New procedure needs dependencies during scan */ #define PRC_blocking 16 /* Blocking someone from dropping procedure */ #define PRC_create 32 /* Newly created */ #define PRC_being_altered 64 /* Procedure is getting altered */ @@ -433,13 +454,15 @@ typedef struct prc { /* Parameter block */ -typedef struct prm { - struct blk prm_header; +class prm : public pool_alloc_rpt +{ + public: USHORT prm_number; struct dsc prm_desc; TEXT *prm_name; /* pointer to asciiz name */ TEXT prm_string[2]; /* one byte for ALLOC and one for the terminating null */ -} *PRM; +}; +typedef prm* PRM; /* Primary dependencies from all foreign references to relation's @@ -463,8 +486,9 @@ typedef struct frgn { in the database, though it is not really filled out until the relation is scanned */ -typedef struct rel { - struct blk rel_header; +class rel : public pool_alloc +{ +public: USHORT rel_id; USHORT rel_flags; USHORT rel_current_fmt; /* Current format number */ @@ -473,11 +497,11 @@ typedef struct rel { TEXT *rel_name; /* pointer to ascii relation name */ struct vec *rel_formats; /* Known record formats */ TEXT *rel_owner_name; /* pointer to ascii owner */ - struct vcl *rel_pages; /* vector of pointer page numbers */ + class vcl *rel_pages; /* vector of pointer page numbers */ struct vec *rel_fields; /* vector of field blocks */ struct rse *rel_view_rse; /* view record select expression */ - struct vcx *rel_view_contexts; /* linked list of view contexts */ + class vcx *rel_view_contexts; /* linked list of view contexts */ TEXT *rel_security_name; /* pointer to security class name for relation */ struct ext *rel_file; /* external file name */ @@ -514,7 +538,8 @@ typedef struct rel { struct vec *rel_post_store; /* Post-operation store trigger */ struct prim rel_primary_dpnds; /* foreign dependencies on this relation's primary key */ struct frgn rel_foreign_refs; /* foreign references to other relations' primary keys */ -} *REL; +}; +typedef rel* REL; #define REL_scanned 1 /* Field expressions scanned (or being scanned) */ #define REL_system 2 @@ -533,9 +558,9 @@ typedef struct rel { /* Field block, one for each field in a scanned relation */ -typedef struct fld +class fld : public pool_alloc_rpt { - struct blk fld_header; + public: struct nod* fld_validation; /* validation clause, if any */ struct nod* fld_not_null; /* if field cannot be NULL */ struct nod* fld_missing_value; /* missing value, if any */ @@ -547,57 +572,114 @@ typedef struct fld CONST TEXT* fld_name; /* Field name */ UCHAR fld_length; /* Field name length */ UCHAR fld_string[2]; /* one byte for ALLOC and one for the terminating null */ -} *FLD; +}; +typedef fld *FLD; /* Index block to cache index information */ -typedef struct idb +class idb { - struct blk idb_header; + public: struct idb* idb_next; struct nod* idb_expression; /* node tree for index expression */ struct req* idb_expression_request; /* request in which index expression is evaluated */ struct dsc idb_expression_desc; /* descriptor for expression result */ struct lck* idb_lock; /* lock to synchronize changes to index */ UCHAR idb_id; -} *IDB; +}; +typedef idb *IDB; /* view context block to cache view aliases */ -typedef struct vcx { - struct blk vcx_header; - struct vcx *vcx_next; - struct str *vcx_context_name; - struct str *vcx_relation_name; +class vcx: public pool_alloc +{ + public: + class vcx *vcx_next; + class str *vcx_context_name; + class str *vcx_relation_name; USHORT vcx_context; -} *VCX; +}; +typedef vcx *VCX; #endif /* general purpose vector */ +template +class vec_base : protected pool_alloc +{ +public: + typedef Firebird::vector::iterator iterator; -typedef struct vec { - struct blk vec_header; - ULONG vec_count; - struct blk *vec_object[1]; -} *VEC; + static vec_base* newVector(MemoryPool& p, int len) + { return new(p) vec_base(p, len); } + static vec_base* newVector(MemoryPool& p, const vec_base& base) + { return new(p) vec_base(p, base); } + + ULONG count() { return vector.size(); } + T& operator[](size_t index) { return vector[index]; } -typedef struct vcl { - struct blk vcl_header; - ULONG vcl_count; - SLONG vcl_long[1]; -} *VCL; + iterator begin() { return vector.begin(); } + iterator end() { return vector.end(); } + + void clear() { vector.clear(); } + void prepend(int n) { vector.insert(vector.begin(), n); } + + T* memPtr() { return (T*)begin(); } + + void resize(size_t n, T val = T()) { vector.resize(n, val); } + + void operator delete(void *mem) { MemoryPool::deallocate(mem); } + +protected: + vec_base(MemoryPool& p, int len) + : vector(len, p, TYPE) {} + vec_base(MemoryPool& p, const vec_base& base) + : vector(p, TYPE) { vector = base.vector; } + +private: + Firebird::vector vector; +}; + +class vec : public vec_base +{ +public: + static vec* newVector(MemoryPool& p, int len) + { return new(p) vec(p, len); } + static vec* newVector(MemoryPool& p, const vec& base) + { return new(p) vec(p, base); } + +private: + vec(MemoryPool& p, int len) : vec_base(p, len) {} + vec(MemoryPool& p, const vec& base) : vec_base(p, base) {} +}; +typedef vec* VEC; + +class vcl : public vec_base +{ +public: + static vcl* newVector(MemoryPool& p, int len) + { return new(p) vcl(p, len); } + static vcl* newVector(MemoryPool& p, const vcl& base) + { return new(p) vcl(p, base); } + +private: + vcl(MemoryPool& p, int len) : vec_base(p, len) {} + vcl(MemoryPool& p, const vcl& base) : vec_base(p, base) {} +}; +typedef vcl* VCL; #define TEST_VECTOR(vector,number) ((vector && number < vector->vec_count) ? \ vector->vec_object [number] : NULL) -/* general purpose queue */ +// +// general purpose queue +// typedef struct que { - struct que *que_forward; - struct que *que_backward; + struct que* que_forward; + struct que* que_backward; } *QUE; @@ -611,27 +693,50 @@ typedef ENUM sym_t { SYM_rel, /* relation block */ SYM_sql, /* SQL request cache block */ SYM_blr /* BLR request cache block */ } SYM_T; -typedef struct sym { - struct blk sym_header; +class sym : public pool_alloc +{ + public: TEXT *sym_string; /* address of asciz string */ /* USHORT sym_length; *//* length of asciz string */ SYM_T sym_type; /* symbol type */ - struct blk *sym_object; /* general pointer to object */ - struct sym *sym_collision; /* collision pointer */ - struct sym *sym_homonym; /* homonym pointer */ -} *SYM; + BLK sym_object; /* general pointer to object */ + sym *sym_collision; /* collision pointer */ + sym *sym_homonym; /* homonym pointer */ +}; +typedef sym *SYM; /* Random string block -- jack of all kludges */ -typedef struct str { - struct blk str_header; +class str : public pool_alloc_rpt +{ +public: USHORT str_length; UCHAR str_data[2]; /* one byte for ALLOC and one for the NULL */ -} *STR; + + static bool extend(str*& s, size_t new_len) + { + gds_assert(s); + MemoryPool* pPool = MemoryPool::blk_pool(s); + gds_assert(pPool); + if (!pPool) { + return false; // runtime safety + } + // TMN: Note that this violates "common sense" and should be fixed. + str* res = new(*pPool, new_len+1) str; + res->str_length = new_len; + memcpy(res->str_data, s->str_data, s->str_length+1); + str* old = s; + s = res; + delete old; + return s != 0; + } +}; +typedef str *STR; -/* Transaction element block */ - +// +// Transaction element block +// typedef struct teb { ATT *teb_database; int teb_tpb_length; @@ -640,11 +745,13 @@ typedef struct teb { /* Blocking Thread Block */ -typedef struct btb { - struct blk btb_header; - struct btb *btb_next; +class btb : public pool_alloc +{ + public: + btb *btb_next; SLONG btb_thread_id; -} *BTB; +}; +typedef btb *BTB; /* Lock levels */ @@ -699,11 +806,11 @@ typedef struct win { typedef struct tdbb { struct thdd tdbb_thd_data; - struct dbb* tdbb_database; - struct att* tdbb_attachment; + dbb* tdbb_database; + att* tdbb_attachment; struct tra* tdbb_transaction; struct req* tdbb_request; - struct plb* tdbb_default; + JrdMemoryPool* tdbb_default; STATUS* tdbb_status_vector; void* tdbb_setjmp; USHORT tdbb_inhibit; /* Inhibit context switch if non-zero */ @@ -767,16 +874,16 @@ extern TDBB gdbb; */ #ifdef DEV_BUILD #define GET_THREAD_DATA (((PLATFORM_GET_THREAD_DATA) && \ - (((THDD)(PLATFORM_GET_THREAD_DATA))->thdd_type == THDD_TYPE_TDBB) && \ + (((THDD)(PLATFORM_GET_THREAD_DATA))->thdd_type == THDD_TYPE_TDBB) && \ (((TDBB)(PLATFORM_GET_THREAD_DATA))->tdbb_database)) \ - ? ((((TDBB)(PLATFORM_GET_THREAD_DATA))->tdbb_database->dbb_header.blk_type == type_dbb) \ + ? ((MemoryPool::blk_type(((TDBB)(PLATFORM_GET_THREAD_DATA))->tdbb_database) == type_dbb) \ ? (PLATFORM_GET_THREAD_DATA) \ : (BUGCHECK (147), (PLATFORM_GET_THREAD_DATA))) \ : (PLATFORM_GET_THREAD_DATA)) -#define CHECK_DBB(dbb) assert ((dbb) && ((dbb)->dbb_header.blk_type == type_dbb)) +#define CHECK_DBB(dbb) assert ((dbb) && (MemoryPool::blk_type(dbb) == type_dbb) && ((dbb)->dbb_permanent->verify_pool())) #define CHECK_TDBB(tdbb) assert ((tdbb) && \ (((THDD)(tdbb))->thdd_type == THDD_TYPE_TDBB) && \ - ((!(tdbb)->tdbb_database)||(tdbb)->tdbb_database->dbb_header.blk_type == type_dbb)) + ((!(tdbb)->tdbb_database)||MemoryPool::blk_type((tdbb)->tdbb_database) == type_dbb)) #else /* PROD_BUILD */ #define GET_THREAD_DATA (PLATFORM_GET_THREAD_DATA) @@ -852,9 +959,6 @@ extern IHNDL internal_db_handles; #endif /* !JRD_MAIN */ -#ifdef __cplusplus -} /* extern "C" */ -#endif #endif /* JRD_JRD_H */ diff --git a/src/jrd/jrd_blks.cpp b/src/jrd/jrd_blks.cpp new file mode 100644 index 0000000000..e6a6402951 --- /dev/null +++ b/src/jrd/jrd_blks.cpp @@ -0,0 +1,40 @@ +#include "../jrd/all.h" + +plb::alloc_info jrd_alloc_info = +{ + jrd_blk_t.type_MIN, + jrd_blk_t.type_MAX, + { + {0, 0}, +#define BLKDEF(type, root, tail) { sizeof (struct root), tail }, +#ifndef GATEWAY +#include "../jrd/blk.h" +#else +#include ".._gway/gway/blk.h" +#endif +#undef BLKDEF + {0, 0} + }, + { + "type_MIN", +#define BLKDEF(type, root, tail) #type, +#ifndef GATEWAY +#include "../jrd/blk.h" +#else +#include ".._gway/gway/blk.h" +#endif +#undef BLKDEF + "type_MAX" + } + +#ifdef SUPERSERVER + , +#define BLKDEF(type, root, tail) 0, + { +#include "../jrd/blk.h" + 0 +#undef BLKDEF + }, + sizeof(jrd_alloc_info.all_block_type_count) +#endif +}; diff --git a/src/jrd/jrd_blks.h b/src/jrd/jrd_blks.h new file mode 100644 index 0000000000..609f423f8e --- /dev/null +++ b/src/jrd/jrd_blks.h @@ -0,0 +1,20 @@ +#ifndef JRD_BLKS_H +#define JRD_BLKS_H + +/* #include "../jrd/all.h" */ + +//extern plb::alloc_info jrd_alloc_info; + +#define BLKDEF(type, root, tail) type, +enum jrd_blk_t { + type_MIN_jrd = 0, +#ifndef GATEWAY +#include "../jrd/blk.h" +#else +#include ".._gway/gway/blk.h" +#endif + type_MAX_jrd +}; +#undef BLKDEF + +#endif // JRD_BLKS_H diff --git a/src/jrd/jrd_proto.h b/src/jrd/jrd_proto.h index 261aa6bb40..297e5244c5 100644 --- a/src/jrd/jrd_proto.h +++ b/src/jrd/jrd_proto.h @@ -25,6 +25,8 @@ #ifndef JRD_JRD_PROTO_H #define JRD_JRD_PROTO_H +#ifndef __cplusplus + /* included for the bid structure */ #ifndef WIN_NT #include "../jrd/blb.h" @@ -35,6 +37,8 @@ #include "../jrd/svc.h" #endif +#endif /* __cplusplus */ + #ifdef __cplusplus extern "C" { #endif diff --git a/src/jrd/jrn.h b/src/jrd/jrn.h index 9fc0387ece..9ac2a68dd5 100644 --- a/src/jrd/jrn.h +++ b/src/jrd/jrn.h @@ -24,6 +24,9 @@ #ifndef _JRD_JRN_H_ #define _JRD_JRN_H_ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + #define MAX_RECORD 9000 #define JOURNAL_VERSION3 3 #define JOURNAL_VERSION4 4 @@ -40,8 +43,9 @@ /* Journal block */ -typedef struct jrn { - struct blk jrn_header; +class jrn : public pool_alloc_rpt +{ + public: STATUS *jrn_status_vector; /* Status vector for errors */ int *jrn_channel; /* Communication channel */ int jrn_iri; /* RMS internal RAB id */ @@ -52,7 +56,8 @@ typedef struct jrn { USHORT jrn_fid[3]; /* VMS file id */ USHORT jrn_did[3]; /* VMS directory id */ TEXT jrn_server[1]; /* Server name */ -} *JRN; +}; +typedef jrn *JRN; /* Journal record types */ @@ -383,14 +388,16 @@ typedef struct jrnda { #define MAX_OLD_FILES 16 #define MAX_LOG_FILES 16 -typedef struct logfiles { - struct blk lg_header; +class logfiles : public pool_alloc_rpt +{ + public: SLONG lg_size; SSHORT lg_sequence; SSHORT lg_partitions; SSHORT lg_flags; TEXT lg_name[2]; -} LGFILE; +}; +typedef logfiles LGFILE; #define LGFILE_SIZE OFFSETA (LGFILE*, lg_name) diff --git a/src/jrd/lck.cpp b/src/jrd/lck.cpp index fd21749948..256aaf5f68 100644 --- a/src/jrd/lck.cpp +++ b/src/jrd/lck.cpp @@ -67,7 +67,7 @@ static BOOLEAN compatible(LCK, LCK, USHORT); static void enqueue(TDBB, LCK, USHORT, SSHORT); static void external_ast(LCK); static LCK find_block(LCK, USHORT); -static USHORT hash(UCHAR *, USHORT); +static USHORT hash_func(UCHAR *, USHORT); static void hash_allocate(LCK); static LCK hash_get_lock(LCK, USHORT *, LCK **); static void hash_insert_lock(LCK); @@ -168,10 +168,16 @@ static CONST UCHAR compatibility[] = { as the logical lock. If we don't have a lock ID, then we better not have a physical lock at any level. + +JMB: As part of the c++ conversion I removed the check for lck block type. + There is no more blk_type field in the lck structure, and some stack allocated + lck's are passed into lock functions, so we can't do the check. + Here is the line I removed from the macro: + (l->blk_type == type_lck) && \ */ #define LCK_CHECK_LOCK(l) (((l) != NULL) && \ - (l->lck_header.blk_type == type_lck) && \ (l->lck_dbb != NULL) && \ + (l->lck_test_field == 666) && \ (l->lck_id || (l->lck_physical == LCK_none))) /* The following check should be part of LCK_CHECK_LOCK, but it fails @@ -731,13 +737,11 @@ int LCK_lock_opt(TDBB tdbb, LCK lock, USHORT level, SSHORT wait) * Assert a lock if the parent is not locked in exclusive mode. * **************************************/ - LCK parent; - DBB dbb; SET_TDBB(tdbb); assert(LCK_CHECK_LOCK(lock)); lock->lck_logical = level; - dbb = lock->lck_dbb; + DBB dbb = lock->lck_dbb; if (dbb->dbb_ast_flags & DBB_assert_locks) { lock->lck_logical = LCK_none; @@ -823,27 +827,25 @@ void LCK_release(TDBB tdbb, LCK lock) * Release an existing lock. * **************************************/ - BTB block; - LCK prior, next; -#ifdef MULTI_THREAD - ATT attachment; - attachment = lock->lck_attachment; +#ifdef MULTI_THREAD + ATT attachment = lock->lck_attachment; #endif SET_TDBB(tdbb); assert(LCK_CHECK_LOCK(lock)); - if (lock->lck_physical != LCK_none) + if (lock->lck_physical != LCK_none) { DEQUEUE(lock); + } lock->lck_physical = lock->lck_logical = LCK_none; lock->lck_id = lock->lck_data = 0; #ifdef MULTI_THREAD - next = lock->lck_next; - prior = lock->lck_prior; + LCK next = lock->lck_next; + LCK prior = lock->lck_prior; if (prior) { assert(prior->lck_next == lock); @@ -1120,7 +1122,7 @@ static LCK find_block(LCK lock, USHORT level) #endif -static USHORT hash(UCHAR * value, USHORT length) +static USHORT hash_func(UCHAR * value, USHORT length) { /************************************** * @@ -1173,10 +1175,9 @@ static void hash_allocate(LCK lock) dbb = lock->lck_dbb; - if (att = lock->lck_attachment) { + if ( (att = lock->lck_attachment) ) { att->att_compatibility_table = - (VEC) ALLOCPV(type_vec, LOCK_HASH_SIZE); - att->att_compatibility_table->vec_count = LOCK_HASH_SIZE; + vec::newVector(*dbb->dbb_permanent, LOCK_HASH_SIZE); } } @@ -1211,21 +1212,23 @@ static LCK hash_get_lock(LCK lock, USHORT * hash_slot, LCK ** prior) if (!att->att_compatibility_table) hash_allocate(lock); - hash_value = hash((UCHAR *) & lock->lck_key, lock->lck_length); + hash_value = hash_func((UCHAR *) & lock->lck_key, lock->lck_length); if (hash_slot) *hash_slot = hash_value; /* if no collisions found, we're done */ - if (!(match = (LCK) att->att_compatibility_table->vec_object[hash_value])) + if (!(match = (LCK) (*att->att_compatibility_table)[hash_value])) return NULL; if (prior) *prior = - (LCK *) & att->att_compatibility_table->vec_object[hash_value]; + (LCK *) & (*att->att_compatibility_table)[hash_value]; /* look for an identical lock */ + assert(LCK_CHECK_LOCK(match)); for (collision = match; collision; collision = collision->lck_collision) { + assert(LCK_CHECK_LOCK(collision)); if (collision->lck_parent && lock->lck_parent && collision->lck_parent->lck_id == lock->lck_parent->lck_id && collision->lck_type == lock->lck_type && @@ -1275,8 +1278,8 @@ static void hash_insert_lock(LCK lock) if (!(identical = hash_get_lock(lock, &hash_slot, 0))) { lock->lck_collision = - (LCK) att->att_compatibility_table->vec_object[hash_slot]; - att->att_compatibility_table->vec_object[hash_slot] = (BLK) lock; + (LCK) (*att->att_compatibility_table)[hash_slot]; + (*att->att_compatibility_table)[hash_slot] = (BLK) lock; return; } @@ -1541,7 +1544,7 @@ static BOOLEAN internal_enqueue( /* look for an identical lock */ - if (match = hash_get_lock(lock, 0, 0)) { + if ( (match = hash_get_lock(lock, 0, 0)) ) { /* if there are incompatible locks for which there are no blocking asts defined, give up */ @@ -1559,7 +1562,7 @@ static BOOLEAN internal_enqueue( convert the lock, otherwise fall through and enqueue a new one */ - if (match = hash_get_lock(lock, 0, 0)) { + if ( (match = hash_get_lock(lock, 0, 0)) ) { /* if a conversion is necessary, update all identical locks to reflect the new physical lock level */ diff --git a/src/jrd/lck.h b/src/jrd/lck.h index 2ebce2a429..443bfacfba 100644 --- a/src/jrd/lck.h +++ b/src/jrd/lck.h @@ -62,32 +62,68 @@ enum lck_owner_t { typedef int (*lck_ast_t)(); -typedef struct lck { - struct blk lck_header; - struct lck *lck_parent; - struct lck *lck_next; /* Next lock in chain owned by dbb */ - struct lck *lck_att_next; /* Next in chain owned by attachment */ - struct lck *lck_prior; - struct lck *lck_collision; /* collisions in compatibility table */ - struct lck *lck_identical; /* identical locks in compatibility table */ - struct dbb *lck_dbb; /* database object is contained in */ - struct blk *lck_object; /* argument to be passed to ast */ - struct blk *lck_owner; /* Logical owner block (transaction, etc.) */ - struct blk *lck_compatible; /* Enter into internal_enqueue() and treat as compatible */ - struct blk *lck_compatible2; /* Sub-level for internal compatibility */ - struct att *lck_attachment; /* Attachment that owns lock */ - struct btb *lck_blocked_threads; /* Threads blocked by lock */ - lck_ast_t lck_ast; /* Blocking AST routine */ - SLONG lck_id; /* Lock id from lock manager */ - SLONG lck_owner_handle; /* Lock owner handle from the lock manager's point of view */ - USHORT lck_count; /* count of locks taken out by attachment */ - SSHORT lck_length; /* Length of lock string */ - UCHAR lck_logical; /* Logical lock level */ - UCHAR lck_physical; /* Physical lock level */ +extern void MP_GDB_print(MemoryPool*); + +class lck : public pool_alloc_rpt +{ +public: + lck() + : lck_test_field(666), + lck_parent(0), + lck_next(0), + lck_att_next(0), + lck_prior(0), + lck_collision(0), + lck_identical(0), + lck_dbb(0), + lck_object(0), + lck_owner(0), + lck_compatible(0), + lck_compatible2(0), + lck_attachment(0), + lck_blocked_threads(0), + lck_ast(0), + lck_id(0), + lck_owner_handle(0), + lck_count(0), + lck_length(0), + lck_logical(0), + lck_physical(0), #ifndef GATEWAY - SLONG lck_data; /* Data associated with a lock */ + lck_data(0) #else - SCHAR lck_reserved; /* Logical level of reserving lock */ + lck_reserved(0) +#endif + { + lck_key.lck_long = 0; + lck_tail[0] = 0; + } + + int lck_test_field; + lck* lck_parent; + lck* lck_next; /* Next lock in chain owned by dbb */ + lck* lck_att_next; /* Next in chain owned by attachment */ + lck* lck_prior; + lck* lck_collision; /* collisions in compatibility table */ + lck* lck_identical; /* identical locks in compatibility table */ + class dbb* lck_dbb; /* database object is contained in */ + class blk* lck_object; /* argument to be passed to ast */ + class blk* lck_owner; /* Logical owner block (transaction, etc.) */ + class blk* lck_compatible; /* Enter into internal_enqueue() and treat as compatible */ + class blk* lck_compatible2; /* Sub-level for internal compatibility */ + struct att* lck_attachment; /* Attachment that owns lock */ + struct btb* lck_blocked_threads; /* Threads blocked by lock */ + lck_ast_t lck_ast; /* Blocking AST routine */ + SLONG lck_id; /* Lock id from lock manager */ + SLONG lck_owner_handle; /* Lock owner handle from the lock manager's point of view */ + USHORT lck_count; /* count of locks taken out by attachment */ + SSHORT lck_length; /* Length of lock string */ + UCHAR lck_logical; /* Logical lock level */ + UCHAR lck_physical; /* Physical lock level */ +#ifndef GATEWAY + SLONG lck_data; /* Data associated with a lock */ +#else + SCHAR lck_reserved; /* Logical level of reserving lock */ #endif enum lck_t lck_type; union { @@ -95,6 +131,7 @@ typedef struct lck { SLONG lck_long; } lck_key; SCHAR lck_tail[1]; /* Makes the allocater happy */ -} *LCK; +}; +typedef lck *LCK; #endif /* _JRD_LCK_H_ */ diff --git a/src/jrd/license.h b/src/jrd/license.h index fcddf9ff68..e350cc5a07 100644 --- a/src/jrd/license.h +++ b/src/jrd/license.h @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: license.h,v 1.2 2001-07-12 05:46:05 bellardo Exp $ + * $Id: license.h,v 1.3 2001-12-24 02:50:51 tamlin Exp $ * Revision 1.5 2000/12/08 16:18:21 fsg * Preliminary changes to get IB_BUILD_NO automatically * increased on commits. diff --git a/src/jrd/lls.h b/src/jrd/lls.h index b7f1857a67..41bef636ab 100644 --- a/src/jrd/lls.h +++ b/src/jrd/lls.h @@ -24,13 +24,18 @@ #ifndef _JRD_LLS_H_ #define _JRD_LLS_H_ -#define LLS_PUSH(object, stack) ALL_push ((struct blk *) object, stack) -#define LLS_POP(stack) ALL_pop (stack) +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" -typedef struct lls { - struct blk lls_header; - struct blk *lls_object; - struct lls *lls_next; -} *LLS; +#define LLS_PUSH(object, stack) (JrdMemoryPool::ALL_push((BLK)object,stack)) +#define LLS_POP(stack) (JrdMemoryPool::ALL_pop(stack)) + +class lls : public pool_alloc +{ + public: + BLK lls_object; + struct lls *lls_next; +}; +typedef lls *LLS; #endif /* _JRD_LLS_H_ */ diff --git a/src/jrd/log.cpp b/src/jrd/log.cpp index 400a00b0dc..6ad013309d 100644 --- a/src/jrd/log.cpp +++ b/src/jrd/log.cpp @@ -652,9 +652,9 @@ static void open_log(TEXT * file_name, SSHORT file_length, SCHAR * mode) if (!log_file) error("can't open log file"); else { - dbb->dbb_log = log = (LOG) ALLOCP(type_log); + dbb->dbb_log = log = new(*dbb->dbb_permanent) log(); log->log_file = log_file; - log->log_string = (STR) ALLOCPV(type_str, LOG_BUFFER_LENGTH); + log->log_string = new(*dbb->dbb_permanent, LOG_BUFFER_LENGTH) str(); log->log_ptr = log->log_buffer = log->log_string->str_data; } #ifdef STACK_REDUCTION diff --git a/src/jrd/log.h b/src/jrd/log.h index 61f1b128f5..f7ff432942 100644 --- a/src/jrd/log.h +++ b/src/jrd/log.h @@ -35,13 +35,15 @@ /* replay log block */ -typedef struct log { - struct blk log_header; +class log : public pool_alloc +{ + public: struct str *log_string; /* string block allocated to hold log buffer */ UCHAR *log_buffer; /* points to beginning of string data */ UCHAR *log_ptr; /* current end of buffer for logging */ void *log_file; /* db-specific file to write */ -} *LOG; +}; +typedef log *LOG; diff --git a/src/jrd/map.cpp b/src/jrd/map.cpp index f6a535ce77..64f088cae8 100644 --- a/src/jrd/map.cpp +++ b/src/jrd/map.cpp @@ -52,11 +52,6 @@ typedef struct msg { #include "../jrd/map_proto.h" -typedef struct vary { - USHORT vary_length; - UCHAR vary_data[]; -} *VARY; - extern double MTH$CVT_D_G(), MTH$CVT_G_D(); static void bugcheck(int); diff --git a/src/jrd/mblr.cpp b/src/jrd/mblr.cpp index 5111b3f7e6..780ac85db8 100644 --- a/src/jrd/mblr.cpp +++ b/src/jrd/mblr.cpp @@ -213,7 +213,7 @@ static int index_def(MET mblr) * Translate a index modify / update / delete. * **************************************/ - int op, result; + int result; result = TRUE; @@ -263,7 +263,7 @@ static int relation_def(MET mblr) * Translate a relation modify / update / delete. * **************************************/ - int op, result; + int result; level = result = TRUE; @@ -306,7 +306,7 @@ static int view_def(MET mblr) * Translate a view modify / update / delete. * **************************************/ - int op, result; + int result; result = TRUE; @@ -508,7 +508,7 @@ static int parse_mblr(MET mblr) * Primary recursive routine to translate mblr. * ***************************************************/ - int op, result, i, save_area; + int op, result, save_area; UCHAR *save_dyn; if (!mblr->met_mblr_length) diff --git a/src/jrd/met.epp b/src/jrd/met.epp index e91d9428d6..7dfd3e6445 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -21,8 +21,13 @@ * Contributor(s): ______________________________________. */ /* -$Id: met.epp,v 1.2 2001-07-29 17:42:22 skywalker Exp $ +$Id: met.epp,v 1.3 2001-12-24 02:50:51 tamlin Exp $ */ +// This MUST be at the top of the file +#ifdef DARWIN +#define _STLP_CCTYPE +#endif + #ifdef SHLIB_DEFS #define LOCAL_SHLIB_DEFS @@ -150,7 +155,6 @@ extern int strlen(); extern int strcmp(); extern char *strcpy(); extern int vsprintf(); -extern int SETJMP(); extern int memcmp(); extern int strncmp(); extern void *memset(); @@ -159,6 +163,13 @@ extern int ib_fprintf(); #endif +#pragma FB_COMPILER_MESSAGE("Remove once we updated gpre") +static inline void gds__vtov(CONST UCHAR* s1, SCHAR* s2, SSHORT val) +{ + gds__vtov(reinterpret_cast(s1), s2, val); +} + + void MET_activate_shadow( TDBB tdbb) { /************************************** @@ -490,7 +501,7 @@ FMT MET_format(TDBB tdbb, register REL relation, USHORT number) VEC formats; FMT format; BLB blob; - DSC *desc; + fmt::fmt_desc_iterator desc; BLK request; USHORT count; @@ -498,8 +509,8 @@ FMT MET_format(TDBB tdbb, register REL relation, USHORT number) dbb = tdbb->tdbb_database; if ((formats = relation->rel_formats) && - (number < formats->vec_count) && - (format = (FMT) formats->vec_object[number])) + (number < formats->count()) && + (format = (FMT) (*formats)[number])) { return format; } @@ -517,12 +528,12 @@ FMT MET_format(TDBB tdbb, register REL relation, USHORT number) } blob = BLB_open(tdbb, dbb->dbb_sys_trans, (BID)&X.RDB$DESCRIPTOR); count = blob->blb_length / sizeof(struct dsc); - format = (FMT) ALLOCPV(type_fmt, count); + format = fmt::newFmt(*dbb->dbb_permanent, count); format->fmt_count = count; - BLB_get_data(tdbb, blob, (UCHAR*)format->fmt_desc, blob->blb_length); + BLB_get_data(tdbb, blob, (UCHAR*)format->fmt_desc.begin(), blob->blb_length); - for (desc = format->fmt_desc + count - 1; - desc >= format->fmt_desc; + for (desc = format->fmt_desc.end() - 1; + desc >= format->fmt_desc.begin(); --desc) { if (desc->dsc_address) @@ -539,15 +550,21 @@ FMT MET_format(TDBB tdbb, register REL relation, USHORT number) } if (!format) { - format = (FMT) ALLOCPV(type_fmt, 0); + format = fmt::newFmt(*dbb->dbb_permanent); } format->fmt_version = number; /* Link the format block into the world */ - formats = ALL_vector(dbb->dbb_permanent, &relation->rel_formats, number); - formats->vec_object[number] = (BLK) format; + formats = relation->rel_formats; + if (!formats) { + formats = vec::newVector(*dbb->dbb_permanent, number+1); + relation->rel_formats = formats; + } else { + formats->resize(number+1); + } + (*formats)[number] = (BLK) format; return format; } @@ -644,16 +661,17 @@ NOD MET_get_dependencies(TDBB tdbb, * **************************************/ DBB dbb; - CSB csb; + CSB csb_; NOD node; BLK handle; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; - csb = (CSB) ALLOCDV(type_csb, 5); - csb->csb_count = 5; - csb->csb_g_flags |= csb_get_dependencies; + csb_ = Csb::newCsb(*tdbb->tdbb_default, 5); + csb_->csb_rpt.resize(5); // vec always allocates one too many + csb_->csb_count = 5; + csb_->csb_g_flags |= csb_get_dependencies; if (blob) { @@ -661,7 +679,7 @@ NOD MET_get_dependencies(TDBB tdbb, relation, (UCHAR*)blob, view_csb, - &csb, + &csb_, request, (BOOLEAN)((type == obj_trigger) ? TRUE : FALSE), 0); @@ -672,7 +690,7 @@ NOD MET_get_dependencies(TDBB tdbb, MET_parse_blob( tdbb, relation, blob_id, - &csb, + &csb_, request, (BOOLEAN)((type == obj_trigger) ? TRUE : FALSE), FALSE); @@ -692,15 +710,15 @@ NOD MET_get_dependencies(TDBB tdbb, CMP_release(tdbb, (REQ)handle); } - store_dependencies(tdbb, csb, object_name, type); + store_dependencies(tdbb, csb_, object_name, type); if (csb_ptr) { - *csb_ptr = csb; + *csb_ptr = csb_; } else { - ALL_release((FRB)csb); + delete csb_; } return node; @@ -724,9 +742,9 @@ FLD MET_get_field(REL relation, USHORT id) if (!relation || !(vector = relation->rel_fields) || - id >= vector->vec_count) return NULL; + id >= vector->count()) return NULL; - return (FLD) vector->vec_object[id]; + return (FLD) (*vector)[id]; } @@ -801,7 +819,7 @@ void MET_get_shadow_files( TDBB tdbb, USHORT deleteVar) int MET_get_walinfo( TDBB tdbb, - LGFILE ** logfiles, ULONG * number, LGFILE ** over_flow) + LGFILE ** logfiles_, ULONG * number, LGFILE ** over_flow) { /************************************** * @@ -825,13 +843,13 @@ int MET_get_walinfo( FOR(REQUEST_HANDLE handle) LOG IN RDB$LOG_FILES SORTED BY LOG.RDB$FILE_SEQUENCE - logfiles[num] = (LGFILE *) ALLOCPV(type_ail, - LGFILE_SIZE + MAX_PATH_LENGTH); - strcpy(logfiles[num]->lg_name, LOG.RDB$FILE_NAME); - logfiles[num]->lg_size = LOG.RDB$FILE_LENGTH; - logfiles[num]->lg_partitions = LOG.RDB$FILE_PARTITIONS; - logfiles[num]->lg_flags = LOG.RDB$FILE_FLAGS; - logfiles[num]->lg_sequence = LOG.RDB$FILE_SEQUENCE; + logfiles_[num] = new(*dbb->dbb_permanent, + LGFILE_SIZE + MAX_PATH_LENGTH) logfiles(); + strcpy(logfiles_[num]->lg_name, LOG.RDB$FILE_NAME); + logfiles_[num]->lg_size = LOG.RDB$FILE_LENGTH; + logfiles_[num]->lg_partitions = LOG.RDB$FILE_PARTITIONS; + logfiles_[num]->lg_flags = LOG.RDB$FILE_FLAGS; + logfiles_[num]->lg_sequence = LOG.RDB$FILE_SEQUENCE; num++; END_FOR; @@ -843,7 +861,7 @@ int MET_get_walinfo( if (num) { - *over_flow = logfiles[num - 1]; + *over_flow = logfiles_[num - 1]; /* The overflow file will be passed separately */ @@ -1057,7 +1075,7 @@ void MET_lookup_exception(TDBB tdbb, **************************************/ DBB dbb; BLK request; - SCHAR *p; + //SCHAR *p; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; @@ -1153,8 +1171,7 @@ int MET_lookup_field(TDBB tdbb, REL relation, CONST TEXT* name) DBB dbb; BLK request; VEC vector; - FLD* field; - FLD* end; + vec::iterator field, end; CONST TEXT* p; CONST TEXT* q; USHORT id; @@ -1165,18 +1182,18 @@ int MET_lookup_field(TDBB tdbb, REL relation, CONST TEXT* name) /* Start by checking field names that we already know */ - if (vector = relation->rel_fields) + if ( (vector = relation->rel_fields) ) { length = strlen(name); - for (field = (FLD*) vector->vec_object, + for (field = vector->begin(), id = 0, - end = field + vector->vec_count; + end = vector->end(); field < end; field++, id++) { if (*field && - (*field)->fld_length == length && - (p = (*field)->fld_name)) + ((FLD)(*field))->fld_length == length && + (p = ((FLD)(*field))->fld_name)) { q = name; while (*p++ == *q) @@ -1235,17 +1252,17 @@ BLF MET_lookup_filter(TDBB tdbb, SSHORT from, SSHORT to) DBB dbb; BLK request; PTR filter; - TEXT *p; + //TEXT *p; MOD module; LLS stack; - BLF blf; + BLF blf_; STR exception_msg; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; filter = NULL; - blf = NULL; + blf_ = NULL; request = (BLK) CMP_find_request(tdbb, irq_r_filters, IRQ_REQUESTS); @@ -1262,22 +1279,22 @@ BLF MET_lookup_filter(TDBB tdbb, SSHORT from, SSHORT to) ISC_EXT_LIB_PATH_ENV); if (filter) { - blf = (BLF) ALLOCP(type_blf); - blf->blf_next = NULL; - blf->blf_from = from; - blf->blf_to = to; - blf->blf_filter = filter; + blf_ = new(*dbb->dbb_permanent) blf(); + blf_->blf_next = NULL; + blf_->blf_from = from; + blf_->blf_to = to; + blf_->blf_filter = filter; exception_msg = - (STR) ALLOCPV(type_str, + new(*dbb->dbb_permanent, strlen(EXCEPTION_MESSAGE) + strlen(X.RDB$FUNCTION_NAME) + strlen(X.RDB$ENTRYPOINT) + - strlen(X.RDB$MODULE_NAME) + 1); + strlen(X.RDB$MODULE_NAME) + 1) str(); sprintf((char*)exception_msg->str_data, EXCEPTION_MESSAGE, X.RDB$FUNCTION_NAME, X.RDB$ENTRYPOINT, X.RDB$MODULE_NAME); - blf->blf_exception_message = exception_msg; + blf_->blf_exception_message = exception_msg; } - if (module = FLU_lookup_module(X.RDB$MODULE_NAME)) + if ( (module = FLU_lookup_module(X.RDB$MODULE_NAME)) ) { /* Register interest in the module by database. */ @@ -1294,7 +1311,7 @@ BLF MET_lookup_filter(TDBB tdbb, SSHORT from, SSHORT to) FLU_unregister_module(module); else { - PLB old_pool; + JrdMemoryPool *old_pool; old_pool = tdbb->tdbb_default; tdbb->tdbb_default = dbb->dbb_permanent; @@ -1307,7 +1324,7 @@ BLF MET_lookup_filter(TDBB tdbb, SSHORT from, SSHORT to) if (!REQUEST(irq_r_filters)) REQUEST(irq_r_filters) = request; - return blf; + return blf_; } @@ -1481,15 +1498,15 @@ int MET_lookup_partner( index_number = 0; if (references->frgn_reference_ids) { - ALL_release((FRB)references->frgn_reference_ids); + delete references->frgn_reference_ids; references->frgn_reference_ids = (VEC) NULL_PTR; } if (references->frgn_relations) { - ALL_release((FRB)references->frgn_relations); + delete references->frgn_relations; references->frgn_relations = (VEC) NULL_PTR; } if (references->frgn_indexes) { - ALL_release((FRB)references->frgn_indexes); + delete references->frgn_indexes; references->frgn_indexes = (VEC) NULL_PTR; } @@ -1511,25 +1528,37 @@ int MET_lookup_partner( if (partner_relation) { - ALL_vector(dbb->dbb_permanent, - &references->frgn_reference_ids, - (USHORT)index_number); + if (!references->frgn_reference_ids) { + references->frgn_reference_ids = + vec::newVector(*dbb->dbb_permanent, + (USHORT)index_number + 1); + } else { + references->frgn_reference_ids->resize((USHORT)index_number + 1); + } - references->frgn_reference_ids->vec_object[index_number] = + (*references->frgn_reference_ids)[index_number] = (BLK) (IDX.RDB$INDEX_ID - 1); - - ALL_vector(dbb->dbb_permanent, - &references->frgn_relations, - (USHORT)index_number); - references->frgn_relations->vec_object[index_number] = + if (!references->frgn_relations) { + references->frgn_relations = + vec::newVector(*dbb->dbb_permanent, + (USHORT)index_number + 1); + } else { + references->frgn_relations->resize((USHORT)index_number + 1); + } + + (*references->frgn_relations)[index_number] = (BLK) partner_relation->rel_id; - ALL_vector(dbb->dbb_permanent, - &references->frgn_indexes, - (USHORT)index_number); + if (!references->frgn_indexes) { + references->frgn_indexes = + vec::newVector(*dbb->dbb_permanent, + (USHORT)index_number + 1); + } else { + references->frgn_indexes->resize((USHORT)index_number + 1); + } - references->frgn_indexes->vec_object[index_number] = + (*references->frgn_indexes)[index_number] = (BLK) (IND.RDB$INDEX_ID - 1); index_number++; @@ -1549,15 +1578,15 @@ int MET_lookup_partner( index_number = 0; if (dependencies->prim_reference_ids) { - ALL_release((FRB)dependencies->prim_reference_ids); + delete dependencies->prim_reference_ids; dependencies->prim_reference_ids = (VEC) NULL_PTR; } if (dependencies->prim_relations) { - ALL_release((FRB)dependencies->prim_relations); + delete dependencies->prim_relations; dependencies->prim_relations = (VEC) NULL_PTR; } if (dependencies->prim_indexes) { - ALL_release((FRB)dependencies->prim_indexes); + delete dependencies->prim_indexes; dependencies->prim_indexes = (VEC) NULL_PTR; } @@ -1583,31 +1612,43 @@ int MET_lookup_partner( IDX.RDB$RELATION_NAME EQ relation->rel_name AND IND.RDB$FOREIGN_KEY EQ IDX.RDB$INDEX_NAME - if (!REQUEST(irq_foreign2)) + if (!REQUEST(irq_foreign2)) { REQUEST(irq_foreign2) = request; - - if (partner_relation = - MET_lookup_relation(tdbb, IND.RDB$RELATION_NAME)) + } + partner_relation = MET_lookup_relation(tdbb, IND.RDB$RELATION_NAME); + if (partner_relation) { - ALL_vector(dbb->dbb_permanent, - &dependencies->prim_reference_ids, - (USHORT)index_number); + if (!dependencies->prim_reference_ids) { + dependencies->prim_reference_ids = + vec::newVector(*dbb->dbb_permanent, + (USHORT)index_number+1); + } else { + dependencies->prim_reference_ids->resize((USHORT)index_number+1); + } - dependencies->prim_reference_ids->vec_object[index_number] = + (*dependencies->prim_reference_ids)[index_number] = (BLK) (IDX.RDB$INDEX_ID - 1); - ALL_vector(dbb->dbb_permanent, - &dependencies->prim_relations, - (USHORT)index_number); + if (!dependencies->prim_relations) { + dependencies->prim_relations = + vec::newVector(*dbb->dbb_permanent, + (USHORT)index_number+1); + } else { + dependencies->prim_relations->resize((USHORT)index_number+1); + } - dependencies->prim_relations->vec_object[index_number] = + (*dependencies->prim_relations)[index_number] = (BLK) partner_relation->rel_id; - ALL_vector(dbb->dbb_permanent, - &dependencies->prim_indexes, - (USHORT)index_number); + if (!dependencies->prim_indexes) { + dependencies->prim_indexes = + vec::newVector(*dbb->dbb_permanent, + (USHORT)index_number+1); + } else { + dependencies->prim_indexes->resize((USHORT)index_number+1); + } - dependencies->prim_indexes->vec_object[index_number] = + (*dependencies->prim_indexes)[index_number] = (BLK) (IND.RDB$INDEX_ID - 1); index_number++; @@ -1659,18 +1700,16 @@ int MET_lookup_partner( if (references->frgn_reference_ids) { for (index_number = 0; - index_number < references->frgn_reference_ids->vec_count; + index_number < references->frgn_reference_ids->count(); index_number++) { - if (idx->idx_id == (UCHAR) references->frgn_reference_ids-> - vec_object[index_number]) + if (idx->idx_id == (UCHAR) (*references->frgn_reference_ids) + [index_number]) { idx->idx_primary_relation = - (USHORT) references->frgn_relations-> - vec_object[index_number]; + (USHORT) (*references->frgn_relations)[index_number]; idx->idx_primary_index = - (UCHAR) references->frgn_indexes-> - vec_object[index_number]; + (UCHAR) (*references->frgn_indexes)[index_number]; return TRUE; } } @@ -1683,11 +1722,11 @@ int MET_lookup_partner( if (dependencies->prim_reference_ids) { for (index_number = 0; - index_number < dependencies->prim_reference_ids->vec_count; + index_number < dependencies->prim_reference_ids->count(); index_number++) { - if (idx->idx_id == (UCHAR) dependencies->prim_reference_ids-> - vec_object[index_number]) + if (idx->idx_id == (UCHAR) (*dependencies->prim_reference_ids) + [index_number]) { idx->idx_foreign_primaries = relation->rel_primary_dpnds.prim_reference_ids; @@ -1721,7 +1760,8 @@ PRC MET_lookup_procedure(TDBB tdbb, SCHAR * name) **************************************/ DBB dbb; BLK request; - PRC procedure, *ptr, *end; + PRC procedure; + vec::iterator ptr, end; VEC procedures; SCHAR *p, *q; @@ -1730,10 +1770,10 @@ PRC MET_lookup_procedure(TDBB tdbb, SCHAR * name) /* See if we already know the relation by name */ - if (procedures = dbb->dbb_procedures) - for (ptr = (PRC *) procedures->vec_object, end = - ptr + procedures->vec_count; ptr < end; ptr++) { - if ((procedure = *ptr) && !(procedure->prc_flags & PRC_obsolete) + if ( (procedures = dbb->dbb_procedures) ) + for (ptr = procedures->begin(), end = procedures->end(); + ptr < end; ptr++) { + if ((procedure = PRC(*ptr))&& !(procedure->prc_flags & PRC_obsolete) && (procedure->prc_flags & PRC_scanned) && !(procedure->prc_flags & PRC_being_scanned) && !(procedure->prc_flags & PRC_being_altered) @@ -1782,7 +1822,8 @@ PRC MET_lookup_procedure_id(TDBB tdbb, **************************************/ DBB dbb; BLK request; - PRC procedure, *ptr, *end; + PRC procedure; + vec::iterator ptr, end; VEC procedures; SET_TDBB(tdbb); @@ -1790,10 +1831,10 @@ PRC MET_lookup_procedure_id(TDBB tdbb, /* See if we already know the relation by name */ - if (procedures = dbb->dbb_procedures) - for (ptr = (PRC *) procedures->vec_object, end = - ptr + procedures->vec_count; ptr < end; ptr++) { - if ((procedure = *ptr) && procedure->prc_id == id + if ( (procedures = dbb->dbb_procedures) ) + for (ptr = procedures->begin(), end = procedures->end(); + ptr < end; ptr++) { + if ((procedure = PRC(*ptr)) && procedure->prc_id == id && !(procedure->prc_flags & PRC_being_scanned) && (procedure->prc_flags & PRC_scanned) && !(procedure->prc_flags & PRC_being_altered) @@ -1842,8 +1883,7 @@ REL MET_lookup_relation(TDBB tdbb, CONST SCHAR* name) VEC relations; REL relation; REL check_relation; - REL* ptr; - REL* end; + vec::iterator ptr, end; SCHAR* p; CONST SCHAR* q; UCHAR length; @@ -1857,10 +1897,9 @@ REL MET_lookup_relation(TDBB tdbb, CONST SCHAR* name) check_relation = NULL; length = strlen(name); - for (ptr = (REL *) relations->vec_object, end = - ptr + relations->vec_count; ptr < end; ptr++) + for (ptr = relations->begin(), end = relations->end(); ptr < end; ptr++) { - if ((relation = *ptr) && + if ((relation = REL(*ptr)) && (relation->rel_length == length) && (!(relation->rel_flags & REL_deleted)) && (p = relation->rel_name)) @@ -1959,7 +1998,7 @@ REL MET_lookup_relation_id(TDBB tdbb, SLONG id, BOOLEAN return_deleted) check_relation = NULL; if ((vector = dbb->dbb_relations) && - (id < vector->vec_count) && (relation = (REL) vector->vec_object[id])) + (id < vector->count()) && (relation = (REL) (*vector)[id])) { if (relation->rel_flags & REL_deleted) { @@ -2044,7 +2083,7 @@ NOD MET_parse_blob(TDBB tdbb, blob = BLB_open(tdbb, dbb->dbb_sys_trans, (BID)blob_id); length = blob->blb_length + 10; - temp = (STR) ALLOCDV(type_str, length); + temp = new(*tdbb->tdbb_default, length) str(); BLB_get_data(tdbb, blob, temp->str_data, length); node = PAR_blr( tdbb, @@ -2056,7 +2095,7 @@ NOD MET_parse_blob(TDBB tdbb, trigger, (USHORT)(ignore_perm ? csb_ignore_perm : 0)); - ALL_release((FRB)temp); + delete temp; return node; } @@ -2081,7 +2120,7 @@ void MET_parse_sys_trigger(TDBB tdbb, REL relation) const TEXT* name; VEC* ptr; REQ request; - PLB old_pool; + JrdMemoryPool *old_pool; USHORT trig_flags; SET_TDBB(tdbb); @@ -2115,16 +2154,16 @@ void MET_parse_sys_trigger(TDBB tdbb, REL relation) relation->rel_flags |= REL_sys_trigs_being_loaded; trigger = NULL; - /* TMN: The cast "(struct trg*)" if a bad lie. Fix later + /* TMN: The cast "(struct trg*)" is a bad lie. Fix later * and remove this comment when it's done. */ - while (trigger = + while ( (trigger = (BLK*)INI_lookup_sys_trigger(relation, (struct trg*)trigger, &blr, &type, &name, - &trig_flags)) + &trig_flags)) ) { switch (type) { case 1: @@ -2156,7 +2195,7 @@ void MET_parse_sys_trigger(TDBB tdbb, REL relation) ((trig_flags & TRG_ignore_perm) ? csb_ignore_perm : 0); old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = ALL_pool(); + tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool; PAR_blr(tdbb, relation, const_cast(blr), @@ -2260,13 +2299,14 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) PRC procedure; VEC vector; LCK lock; - BLK request, request2, *ptr, *end; - CSB csb; + BLK request, request2; + vec::iterator ptr, end; + CSB csb_; PRM parameter; - PLB old_pool; + JrdMemoryPool *old_pool; NOD node; FMT format; - DSC *desc; + fmt::fmt_desc_iterator desc; SSHORT i; USHORT length; JMP_BUF env, *old_env; @@ -2277,12 +2317,11 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) if (!(vector = dbb->dbb_procedures)) { - vector = dbb->dbb_procedures = (VEC) ALLOCPV(type_vec, id + 10); - vector->vec_count = id + 10; + vector = dbb->dbb_procedures = vec::newVector(*dbb->dbb_permanent, id + 10); } - else if (id >= vector->vec_count) + else if (id >= vector->count()) { - vector = (VEC) ALL_extend((BLK*)&dbb->dbb_procedures, id + 10); + vector->resize(id + 10); } #ifdef SUPERSERVER @@ -2304,7 +2343,7 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) #endif /* SUPERSERVER */ - procedure = (PRC) vector->vec_object[id]; + procedure = (PRC) (*vector)[id]; if (procedure) { /* Make sure PRC_being_scanned and PRC_scanned @@ -2346,30 +2385,19 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) if (!procedure) { - procedure = (PRC) ALLOCP(type_prc); + procedure = new(*dbb->dbb_permanent, 0) prc; } + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - procedure->prc_flags &= ~(PRC_being_scanned | PRC_scanned); -#ifdef SUPERSERVER - THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex); -#endif - if (procedure->prc_existence_lock) - { - LCK_release(tdbb, procedure->prc_existence_lock); - } - tdbb->tdbb_setjmp = (UCHAR *) old_env; - ERR_punt(); - } procedure->prc_flags |= (PRC_being_scanned | flags); procedure->prc_id = id; - vector->vec_object[id] = (BLK) procedure; + (*vector)[id] = (BLK) procedure; - procedure->prc_existence_lock = lock = (LCK) ALLOCPV(type_lck, 0); + procedure->prc_existence_lock = lock = new(*dbb->dbb_permanent, 0) lck; lock->lck_parent = dbb->dbb_lock; lock->lck_dbb = dbb; lock->lck_key.lck_long = procedure->prc_id; @@ -2412,18 +2440,25 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) { procedure->prc_flags |= PRC_system; } - if (procedure->prc_inputs = P.RDB$PROCEDURE_INPUTS) + if ( (procedure->prc_inputs = P.RDB$PROCEDURE_INPUTS) ) { - procedure->prc_input_fields = ALL_vector(dbb->dbb_permanent, - &procedure-> - prc_input_fields, - P.RDB$PROCEDURE_INPUTS); + if (!procedure->prc_input_fields) { + procedure->prc_input_fields = + vec::newVector(*dbb->dbb_permanent, + P.RDB$PROCEDURE_INPUTS + 1); + } else { + procedure->prc_input_fields->resize(P.RDB$PROCEDURE_INPUTS + 1); + } } - if (procedure->prc_outputs = P.RDB$PROCEDURE_OUTPUTS) + if ( (procedure->prc_outputs = P.RDB$PROCEDURE_OUTPUTS) ) { - procedure->prc_output_fields = - ALL_vector(dbb->dbb_permanent, &procedure->prc_output_fields, - P.RDB$PROCEDURE_OUTPUTS); + if (!procedure->prc_output_fields) { + procedure->prc_output_fields = + vec::newVector(*dbb->dbb_permanent, + P.RDB$PROCEDURE_OUTPUTS + 1); + } else { + procedure->prc_output_fields->resize(P.RDB$PROCEDURE_OUTPUTS + 1); + } } FOR(REQUEST_HANDLE request2) PA IN RDB$PROCEDURE_PARAMETERS CROSS @@ -2443,9 +2478,9 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) /* should be error if field already exists */ parameter = - (PRM) ALLOCPV(type_prm, name_length(PA.RDB$PARAMETER_NAME)); + new(*dbb->dbb_permanent, name_length(PA.RDB$PARAMETER_NAME)) prm(); parameter->prm_number = PA.RDB$PARAMETER_NUMBER; - vector->vec_object[parameter->prm_number] = (BLK) parameter; + (*vector)[parameter->prm_number] = (BLK) parameter; name_copy(parameter->prm_string, PA.RDB$PARAMETER_NAME); parameter->prm_name = parameter->prm_string; DSC_make_descriptor(¶meter->prm_desc, F.RDB$FIELD_TYPE, @@ -2458,14 +2493,14 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) REQUEST(irq_r_params) = request2; } - if ((vector = procedure->prc_output_fields) && vector->vec_object[0]) + if ((vector = procedure->prc_output_fields) && (*vector)[0]) { format = procedure->prc_format = - (FMT) ALLOCPV(type_fmt, procedure->prc_outputs); + fmt::newFmt(*dbb->dbb_permanent, procedure->prc_outputs); format->fmt_count = procedure->prc_outputs; length = FLAG_BYTES(format->fmt_count); - desc = format->fmt_desc; - for (ptr = vector->vec_object, end = ptr + procedure->prc_outputs; + desc = format->fmt_desc.begin(); + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++, desc++) { parameter = (PRM) * ptr; @@ -2485,14 +2520,15 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) } old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = ALL_pool(); - csb = (CSB) ALLOCDV(type_csb, 5); - csb->csb_count = 5; - parse_procedure_blr(tdbb, procedure, (SLONG*)&P.RDB$PROCEDURE_BLR, &csb); + tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool; + csb_ = Csb::newCsb(*tdbb->tdbb_default, 5); + csb_->csb_rpt.resize(5); // vec always allocates one too many + csb_->csb_count = 5; + parse_procedure_blr(tdbb, procedure, (SLONG*)&P.RDB$PROCEDURE_BLR, &csb_); procedure->prc_request->req_procedure = procedure; - for (i = 0; i < csb->csb_count; i++) + for (i = 0; i < csb_->csb_count; i++) { - if (node = csb->csb_rpt[i].csb_message) + if ( (node = csb_->csb_rpt[i].csb_message) ) { if ((int) node->nod_arg[e_msg_number] == 0) { @@ -2503,7 +2539,7 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) } } } - ALL_release((FRB)csb); + delete csb_; tdbb->tdbb_default = old_pool; END_FOR; @@ -2522,6 +2558,21 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex); #endif tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + procedure->prc_flags &= ~(PRC_being_scanned | PRC_scanned); +#ifdef SUPERSERVER + THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex); +#endif + if (procedure->prc_existence_lock) + { + LCK_release(tdbb, procedure->prc_existence_lock); + } + tdbb->tdbb_setjmp = (UCHAR *) old_env; + ERR_punt(); + } + return procedure; } @@ -2538,27 +2589,27 @@ REL MET_relation(TDBB tdbb, USHORT id) * Find or create a relation block for a given relation id. * **************************************/ - DBB dbb; + register REL relation; - register VEC vector; LCK lock; USHORT major_version, minor_original, max_sys_rel; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; + DBB dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - if (!(vector = dbb->dbb_relations)) + VEC vector = dbb->dbb_relations; + + if (!vector) { - vector = dbb->dbb_relations = (VEC) ALLOCPV(type_vec, id + 10); - vector->vec_count = id + 10; + vector = dbb->dbb_relations = vec::newVector(*dbb->dbb_permanent, id + 10); } - else if (id >= vector->vec_count) + else if (id >= vector->count()) { - vector = (VEC) ALL_extend((BLK*)&dbb->dbb_relations, id + 10); + vector->resize(id + 10); } - if (relation = (REL) vector->vec_object[id]) + if ( (relation = (REL) (*vector)[id]) ) return relation; major_version = (SSHORT) dbb->dbb_ods_version; @@ -2571,14 +2622,14 @@ REL MET_relation(TDBB tdbb, USHORT id) else max_sys_rel = (USHORT) USER_DEF_REL_INIT_ID - 1; - relation = (REL) ALLOCP(type_rel); - vector->vec_object[id] = (BLK) relation; + relation = new(*dbb->dbb_permanent) rel(); + (*vector)[id] = (BLK) relation; relation->rel_id = id; if (relation->rel_id <= max_sys_rel) return relation; - relation->rel_existence_lock = lock = (LCK) ALLOCPV(type_lck, 0); + relation->rel_existence_lock = lock = new(*dbb->dbb_permanent, 0) lck; lock->lck_parent = dbb->dbb_lock; lock->lck_dbb = dbb; lock->lck_key.lck_long = relation->rel_id; @@ -2642,7 +2693,7 @@ void MET_remove_procedure( TDBB tdbb, int id, PRC procedure) if (!(vector = dbb->dbb_procedures)) return; - if (!(procedure = (PRC) vector->vec_object[id])) + if (!(procedure = (PRC) (*vector)[id])) return; } @@ -2650,7 +2701,7 @@ void MET_remove_procedure( TDBB tdbb, int id, PRC procedure) to it by other procedures via pointer to current meta data structure, so don't loose the structure or the pointer. if (!(procedure->prc_flags & PRC_being_altered)) - vector->vec_object [id] = (BLK) NULL_PTR; + (*vector)[id] = (BLK) NULL_PTR; */ /* deallocate all structure which were allocated. The procedure @@ -2659,24 +2710,24 @@ if (!(procedure->prc_flags & PRC_being_altered)) */ if (procedure->prc_existence_lock) - ALL_release((FRB)procedure->prc_existence_lock); + delete procedure->prc_existence_lock; if (procedure->prc_name) - ALL_release((FRB)procedure->prc_name); + delete procedure->prc_name; if (procedure->prc_security_name) - ALL_release((FRB)procedure->prc_security_name); + delete procedure->prc_security_name; /* deallocate input param structures */ if ((procedure->prc_inputs) && (vector = procedure->prc_input_fields)) { for (i = 0; i < procedure->prc_inputs; i++) { - if (vector->vec_object[i]) + if ((*vector)[i]) { - ALL_release((FRB)vector->vec_object[i]); + delete (*vector)[i]; } } - ALL_release((FRB)vector); + delete vector; } /* deallocate output param structures */ @@ -2684,20 +2735,20 @@ if (!(procedure->prc_flags & PRC_being_altered)) if ((procedure->prc_outputs) && (vector = procedure->prc_output_fields)) { for (i = 0; i < procedure->prc_outputs; i++) { - if (vector->vec_object[i]) + if ((*vector)[i]) { - ALL_release((FRB)vector->vec_object[i]); + delete (*vector)[i]; } } - ALL_release((FRB)vector); + delete vector; } if (procedure->prc_format) - ALL_release((FRB)procedure->prc_format); + delete procedure->prc_format; if (!(procedure->prc_flags & PRC_being_altered)) { - ALL_release((FRB)procedure); + delete procedure; } else { @@ -2818,11 +2869,11 @@ void MET_scan_relation( TDBB tdbb, REL relation) VEC vector, triggers[TRIGGER_MAX], tmp_vector; FLD field; BLK request; - CSB csb; + CSB csb_; BLB blob; UCHAR *p, *q, *buffer, temp[256]; STR name, string; - PLB old_pool; + JrdMemoryPool* old_pool; VOLATILE BOOLEAN dependencies, sys_triggers; JMP_BUF env, *old_env; @@ -2869,41 +2920,34 @@ void MET_scan_relation( TDBB tdbb, REL relation) make sure that the error will be caught if the operation is tried again. */ + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - relation->rel_flags &= ~(REL_being_scanned | REL_scanned); - if (dependencies) - relation->rel_flags |= REL_get_dependencies; - if (sys_triggers) - relation->rel_flags |= REL_sys_triggers; -#ifdef SUPERSERVER - THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex); -#endif - tdbb->tdbb_setjmp = (UCHAR *) old_env; - tdbb->tdbb_default = old_pool; - ERR_punt(); - } - /* Since this can be called recursively, find an inactive clone of the request */ request = (BLK) CMP_find_request(tdbb, irq_r_fields, IRQ_REQUESTS); - csb = NULL; + csb_ = NULL; FOR(REQUEST_HANDLE request) REL IN RDB$RELATIONS WITH REL.RDB$RELATION_ID EQ relation->rel_id /* Pick up relation level stuff */ - if (!REQUEST(irq_r_fields)) + if (!REQUEST(irq_r_fields)) { REQUEST(irq_r_fields) = request; + } relation->rel_current_fmt = REL.RDB$FORMAT; - vector = - ALL_vector(dbb->dbb_permanent, &relation->rel_fields, - REL.RDB$FIELD_ID); - if (!REL.RDB$SECURITY_CLASS.NULL) + vector = relation->rel_fields; + if (!vector) { + vector = vec::newVector(*dbb->dbb_permanent, REL.RDB$FIELD_ID + 1); + relation->rel_fields = vector; + } else { + vector->resize(REL.RDB$FIELD_ID + 1); + } + if (!REL.RDB$SECURITY_CLASS.NULL) { relation->rel_security_name = MET_save_name(tdbb, REL.RDB$SECURITY_CLASS); + } if (!relation->rel_name) { relation->rel_name = MET_save_name(tdbb, REL.RDB$RELATION_NAME); relation->rel_length = strlen(relation->rel_name); @@ -2928,7 +2972,7 @@ void MET_scan_relation( TDBB tdbb, REL relation) (CSB) NULL_PTR, (SLONG*)&REL.RDB$VIEW_BLR, (REQ*) NULL_PTR, - &csb, + &csb_, REL.RDB$RELATION_NAME, obj_view); } @@ -2938,7 +2982,7 @@ void MET_scan_relation( TDBB tdbb, REL relation) (RSE) MET_parse_blob(tdbb, relation, (SLONG*)&REL.RDB$VIEW_BLR, - &csb, + &csb_, (REQ*) NULL_PTR, FALSE, FALSE); @@ -2966,7 +3010,7 @@ void MET_scan_relation( TDBB tdbb, REL relation) } else { - string = (STR) ALLOCDV(type_str, blob->blb_max_segment); + string = new(*tdbb->tdbb_default, blob->blb_max_segment) str(); buffer = string->str_data; } @@ -2994,7 +3038,7 @@ void MET_scan_relation( TDBB tdbb, REL relation) && !REL.RDB$DEFAULT_CLASS.NULL) field->fld_security_name = MET_save_name(tdbb, REL.RDB$DEFAULT_CLASS); field_id = n; - field = (FLD) vector->vec_object[field_id]; + field = (FLD) (*vector)[field_id]; array = NULL; break; @@ -3006,12 +3050,12 @@ void MET_scan_relation( TDBB tdbb, REL relation) if (!strcmp((char*)p, (char*)field->fld_name)) break; - name = (STR) ALLOCPV(type_str, length); + name = new(*dbb->dbb_permanent, length) str(); field->fld_name = (TEXT *) name->str_data; } else { - field = (FLD) ALLOCPV(type_fld, length); - vector->vec_object[field_id] = (BLK) field; + field = new(*dbb->dbb_permanent, length) fld(); + (*vector)[field_id] = (BLK) field; field->fld_name = (TEXT *) field->fld_string; } /* @@ -3028,44 +3072,44 @@ void MET_scan_relation( TDBB tdbb, REL relation) case RSR_base_field: field->fld_source = - PAR_make_field(tdbb, csb, view_context, (TEXT*)p); + PAR_make_field(tdbb, csb_, view_context, (TEXT*)p); break; case RSR_computed_blr: field->fld_computation = (dependencies) ? MET_get_dependencies(tdbb, relation, (TEXT*) p, - csb, + csb_, (SLONG*) NULL_PTR, (REQ*) NULL_PTR, (CSB*) NULL_PTR, field->fld_name, obj_computed) : - PAR_blr(tdbb, relation, p, csb, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, + PAR_blr(tdbb, relation, p, csb_, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, 0); break; case RSR_missing_value: field->fld_missing_value = - PAR_blr(tdbb, relation, p, csb, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, + PAR_blr(tdbb, relation, p, csb_, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, 0); break; case RSR_default_value: field->fld_default_value = - PAR_blr(tdbb, relation, p, csb, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, + PAR_blr(tdbb, relation, p, csb_, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, 0); break; case RSR_validation_blr: field->fld_validation = - PAR_blr(tdbb, relation, p, csb, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, + PAR_blr(tdbb, relation, p, csb_, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, csb_validation); break; case RSR_field_not_null: field->fld_not_null = - PAR_blr(tdbb, relation, p, csb, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, + PAR_blr(tdbb, relation, p, csb_, (CSB*) NULL_PTR, (REQ*) NULL_PTR, FALSE, csb_validation); break; @@ -3078,7 +3122,7 @@ void MET_scan_relation( TDBB tdbb, REL relation) break; case RSR_dimensions: - field->fld_array = array = (ARR) ALLOCPV(type_arr, n); + field->fld_array = array = new(*dbb->dbb_permanent, n) arr(); array->arr_desc.ads_dimensions = n; break; @@ -3086,6 +3130,8 @@ void MET_scan_relation( TDBB tdbb, REL relation) if (array) MOVE_FAST(p, &array->arr_desc, length); break; + default: /* Shut up compiler warning */ + break; } } if (field && !field->fld_security_name && !REL.RDB$DEFAULT_CLASS.NULL) @@ -3095,13 +3141,13 @@ void MET_scan_relation( TDBB tdbb, REL relation) } if (buffer != temp) { - ALL_release((FRB)string); + delete string; } END_FOR; - if (csb) + if (csb_) { - ALL_release((FRB)csb); + delete csb_; } /* release any triggers in case of a rescan, but not if the rescan @@ -3150,10 +3196,27 @@ void MET_scan_relation( TDBB tdbb, REL relation) relation->rel_current_format = NULL; tdbb->tdbb_default = old_pool; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + relation->rel_flags &= ~(REL_being_scanned | REL_scanned); + if (dependencies) { + relation->rel_flags |= REL_get_dependencies; + } + if (sys_triggers) { + relation->rel_flags |= REL_sys_triggers; + } +#ifdef SUPERSERVER + THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex); +#endif + tdbb->tdbb_setjmp = (UCHAR *) old_env; + tdbb->tdbb_default = old_pool; + ERR_punt(); + } } -TEXT *MET_trigger_msg(TDBB tdbb, TEXT * name, USHORT number) +TEXT* MET_trigger_msg(TDBB tdbb, TEXT* name, USHORT number) { /************************************** * @@ -3370,7 +3433,7 @@ static void get_trigger( * **************************************/ REQ request; - PLB old_pool; + JrdMemoryPool* old_pool; SET_TDBB(tdbb); @@ -3378,7 +3441,7 @@ static void get_trigger( return; old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = ALL_pool(); + tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool; MET_parse_blob( tdbb, relation, blob_id, @@ -3493,7 +3556,7 @@ static void lookup_view_contexts( TDBB tdbb, REL view) /* allocate a view context block and link it in to the relation block's linked list */ - view_context = (VCX) ALLOCD(type_vcx); + view_context = new(*tdbb->tdbb_default) vcx(); *vcx_ptr = view_context; vcx_ptr = &view_context->vcx_next; @@ -3502,7 +3565,7 @@ static void lookup_view_contexts( TDBB tdbb, REL view) /* allocate a string block for the context name */ length = name_length(V.RDB$CONTEXT_NAME); - alias = (STR) ALLOCDV(type_str, length + 1); + alias = new(*tdbb->tdbb_default, length + 1) str(); V.RDB$CONTEXT_NAME[length] = 0; strcpy((char*)alias->str_data, V.RDB$CONTEXT_NAME); alias->str_length = length; @@ -3512,7 +3575,7 @@ static void lookup_view_contexts( TDBB tdbb, REL view) /* allocate a string block for the relation name */ length = name_length(V.RDB$RELATION_NAME); - alias = (STR) ALLOCDV(type_str, length + 1); + alias = new(*tdbb->tdbb_default, length + 1) str(); V.RDB$RELATION_NAME[length] = 0; strcpy((char*)alias->str_data, V.RDB$RELATION_NAME); alias->str_length = length; @@ -3600,7 +3663,7 @@ static NOD parse_procedure_blr( blob = BLB_open(tdbb, dbb->dbb_sys_trans, (BID)blob_id); length = blob->blb_length + 10; - temp = (STR) ALLOCDV(type_str, length); + temp = new(*tdbb->tdbb_default, length) str(); BLB_get_data(tdbb, blob, temp->str_data, length); (*csb_ptr)->csb_blr = temp->str_data; par_messages(tdbb, temp->str_data, (USHORT) blob->blb_length, procedure, @@ -3608,7 +3671,7 @@ static NOD parse_procedure_blr( node = PAR_blr(tdbb, (REL) NULL_PTR, temp->str_data, (CSB) NULL_PTR, csb_ptr, &procedure->prc_request, FALSE, 0); - ALL_release((FRB)temp); + delete temp; return node; } @@ -3631,9 +3694,9 @@ static BOOLEAN par_messages(TDBB tdbb, * a format (fmt) block. * **************************************/ - UCHAR *end; + //UCHAR *end; + fmt::fmt_desc_iterator desc; FMT format; - DSC *desc; USHORT count, offset, align, msg_number; SSHORT version; @@ -3651,10 +3714,10 @@ static BOOLEAN par_messages(TDBB tdbb, msg_number = BLR_BYTE; count = BLR_BYTE; count += (BLR_BYTE) << 8; - format = (FMT) ALLOCDV(type_fmt, count); + format = fmt::newFmt(*tdbb->tdbb_default, count); format->fmt_count = count; offset = 0; - for (desc = format->fmt_desc; count; --count, ++desc) { + for (desc = format->fmt_desc.begin(); count; --count, ++desc) { align = PAR_desc(csb, desc); if (align) offset = FB_ALIGN(offset, align); @@ -3672,7 +3735,7 @@ static BOOLEAN par_messages(TDBB tdbb, } else { - ALL_release((FRB)format); + delete format; } } @@ -3695,7 +3758,7 @@ void MET_release_triggers( TDBB tdbb, VEC * vector_ptr) * **************************************/ VEC vector; - REQ *ptr, *end; + vec::iterator ptr, end; if (!(vector = *vector_ptr)) @@ -3705,25 +3768,23 @@ void MET_release_triggers( TDBB tdbb, VEC * vector_ptr) *vector_ptr = NULL; - for (ptr = (REQ *) vector->vec_object, end = ptr + vector->vec_count; - ptr < end; ptr++) + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) { - if (*ptr && CMP_clone_active(*ptr)) + if (*ptr && CMP_clone_active((REQ)(*ptr))) { return; } } - for (ptr = (REQ *) vector->vec_object, end = ptr + vector->vec_count; - ptr < end; ptr++) + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) { if (*ptr) { - CMP_release(tdbb, *ptr); + CMP_release(tdbb, (REQ)(*ptr)); } } - ALL_release((FRB)vector); + delete vector; } @@ -3861,7 +3922,7 @@ static STR save_name(TDBB tdbb, CONST TEXT* name) dbb = tdbb->tdbb_database; l = name_length(name); - string = (STR) ALLOCPV(type_str, l); + string = new(*dbb->dbb_permanent, l) str(); string->str_length = l; p = (TEXT *) string->str_data; @@ -3888,13 +3949,18 @@ static void save_trigger_request(DBB dbb, VEC * ptr, REQ request) * Get trigger. * **************************************/ - VEC vector; - USHORT n; - n = (*ptr) ? (*ptr)->vec_count : 0; - vector = ALL_vector(dbb->dbb_permanent, ptr, n); + USHORT n = (*ptr) ? (*ptr)->count() : 0; + VEC vector = *ptr; - vector->vec_object[n] = (BLK) request; + if (!vector) { + vector = vec::newVector(*dbb->dbb_permanent, n + 1); + *ptr = vector; + } else { + vector->resize(n + 1); + } + + (*vector)[n] = (BLK) request; } @@ -3973,15 +4039,14 @@ static void store_dependencies(TDBB tdbb, fld_id = (SSHORT) field_node->nod_arg[0]; if (relation) { - if (field = MET_get_field(relation, fld_id)) + if ( (field = MET_get_field(relation, fld_id)) ) { field_name = field->fld_name; } else if (procedure) { field = - (FLD) procedure->prc_output_fields-> - vec_object[fld_id]; + (FLD) (*procedure->prc_output_fields)[fld_id]; } } } diff --git a/src/jrd/met.h b/src/jrd/met.h index 01512111a4..6cfa6fdad5 100644 --- a/src/jrd/met.h +++ b/src/jrd/met.h @@ -54,8 +54,9 @@ typedef enum rsr_t { /* Temporary field block */ -typedef struct tfb { - struct blk tfb_header; +class tfb : public pool_alloc +{ + public: struct tfb *tfb_next; /* next block in chain */ USHORT tfb_id; /* id of field in relation */ USHORT tfb_flags; @@ -64,7 +65,8 @@ typedef struct tfb { XDSC tfb_ext_desc; /* external descriptor */ STR tfb_name; /* name of field in relation */ #endif -} *TFB; +}; +typedef tfb *TFB; #define TFB_computed 1 #define TFB_array 2 diff --git a/src/jrd/met_proto.h b/src/jrd/met_proto.h index 12b4a36ad5..da95eb0fa5 100644 --- a/src/jrd/met_proto.h +++ b/src/jrd/met_proto.h @@ -43,8 +43,8 @@ SCHAR *MET_exact_name(TEXT *); struct fmt *MET_format(TDBB, register struct rel *, USHORT); BOOLEAN MET_get_char_subtype(TDBB, SSHORT *, UCHAR *, USHORT); struct nod *MET_get_dependencies(TDBB, struct rel*, TEXT*, - struct csb*, SLONG[2], struct req**, - struct csb **, CONST TEXT*, USHORT); + class Csb*, SLONG[2], struct req**, + class Csb **, CONST TEXT*, USHORT); struct fld *MET_get_field(struct rel *, USHORT); void MET_get_shadow_files(TDBB, USHORT); int MET_get_walinfo(TDBB, struct logfiles **, ULONG *, @@ -64,7 +64,7 @@ struct prc *MET_lookup_procedure(TDBB, SCHAR *); struct prc *MET_lookup_procedure_id(TDBB, SSHORT, BOOLEAN, USHORT); struct rel *MET_lookup_relation(TDBB, CONST SCHAR*); struct rel *MET_lookup_relation_id(TDBB, SLONG, BOOLEAN); -struct nod *MET_parse_blob(TDBB, struct rel *, SLONG[2], struct csb **, +struct nod *MET_parse_blob(TDBB, struct rel *, SLONG[2], class Csb **, struct req **, BOOLEAN, BOOLEAN); void MET_parse_sys_trigger(TDBB, struct rel *); int MET_post_existence(TDBB, struct rel *); diff --git a/src/jrd/misc.cpp b/src/jrd/misc.cpp index 7d69eed611..024e38d7bc 100644 --- a/src/jrd/misc.cpp +++ b/src/jrd/misc.cpp @@ -21,12 +21,7 @@ * Contributor(s): ______________________________________. */ -#ifdef N -#include "firebird.h"ETWARE_386 -#include -#include -#endif - +#include "firebird.h" #include "../jrd/ib_stdio.h" #include #include "../jrd/common.h" diff --git a/src/jrd/msg.h b/src/jrd/msg.h index e268e45995..b5d8c05ac2 100644 --- a/src/jrd/msg.h +++ b/src/jrd/msg.h @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: msg.h,v 1.1.1.1 2001-05-23 13:26:22 tamlin Exp $ +$Id: msg.h,v 1.2 2001-12-24 02:50:51 tamlin Exp $ */ #ifndef _JRD_MSG_H_ diff --git a/src/jrd/nav.cpp b/src/jrd/nav.cpp index d7a6a38fac..de0cf5eb0d 100644 --- a/src/jrd/nav.cpp +++ b/src/jrd/nav.cpp @@ -612,7 +612,7 @@ BOOLEAN NAV_get_record( RNG_add_page(window.win_page); #endif next = (BTN) page->btr_nodes; - if (expanded_page = window.win_expanded_buffer) + if ( (expanded_page = window.win_expanded_buffer) ) expanded_next = (BTX) expanded_page->exp_nodes; page_changed = TRUE; @@ -674,7 +674,7 @@ BOOLEAN NAV_get_record( /* Build the current key value from the prefix and current node data. */ if (expanded_node) { - if (l = BTN_LENGTH(node) + BTN_PREFIX(node)) { + if ( (l = BTN_LENGTH(node) + BTN_PREFIX(node)) ) { p = key.key_data; q = expanded_node->btx_data; do @@ -684,7 +684,7 @@ BOOLEAN NAV_get_record( } else { - if (l = BTN_LENGTH(node)) { + if ( (l = BTN_LENGTH(node)) ){ p = key.key_data + BTN_PREFIX(node); q = BTN_DATA(node); do @@ -923,7 +923,7 @@ static SSHORT compare_keys( string2 = key2->key_data; length2 = key2->key_length; - if (l = MIN(length1, length2)) + if ( (l = MIN(length1, length2)) ) do if (*string1++ != *string2++) return (string1[-1] < string2[-1]) ? -1 : 1; @@ -1115,11 +1115,8 @@ static BOOLEAN find_dbkey(RSB rsb, ULONG record_number) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - CCH_RELEASE(tdbb, &window); - tdbb->tdbb_setjmp = (UCHAR *) old_env; - LONGJMP(old_env, -1); - } + + try { /* loop through the equivalent values of the given key, looking for a record which matches the passed dbkey */ @@ -1152,6 +1149,13 @@ static BOOLEAN find_dbkey(RSB rsb, ULONG record_number) return FALSE; } } + + } // try + catch (...) { + CCH_RELEASE(tdbb, &window); + tdbb->tdbb_setjmp = (UCHAR *) old_env; + Firebird::status_longjmp_error::raise(-1); + } } #endif @@ -1250,11 +1254,8 @@ static BOOLEAN find_record( old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - CCH_RELEASE(tdbb, &window); - tdbb->tdbb_setjmp = (UCHAR *) old_env; - LONGJMP(old_env, -1); - } + + try { /* loop through the equivalent values of the given key, finding a valid record if possible; for RSE_get_last, save the last @@ -1265,7 +1266,8 @@ static BOOLEAN find_record( BTR_find_page() and BTR_find_leaf(), then proceeding backwards to find a valid record -deej */ - for (;;) { + for (;;) + { rpb->rpb_number = BTR_get_quad(BTN_NUMBER(node)); /* if we have gone past the search key value, stop looking */ @@ -1343,6 +1345,13 @@ static BOOLEAN find_record( node = BTR_next_node(node, &expanded_node); } + + } // try + catch (...) { + CCH_RELEASE(tdbb, &window); + tdbb->tdbb_setjmp = (UCHAR *) old_env; + Firebird::status_longjmp_error::raise(-1); + } } #endif @@ -1443,7 +1452,7 @@ static BOOLEAN find_saved_node( /* maintain the running key value and compare it with the stored value */ - if (l = BTN_LENGTH(node)) { + if ( (l = BTN_LENGTH(node)) ) { p = key.key_data + BTN_PREFIX(node); q = BTN_DATA(node); do @@ -1624,13 +1633,16 @@ static BOOLEAN get_record( KEY value; JMP_BUF env, *old_env; USHORT old_att_flags; - BOOLEAN result; tdbb = GET_THREAD_DATA; request = tdbb->tdbb_request; idx = (IDX *) ((SCHAR *) impure + (SLONG) rsb->rsb_arg[RSB_NAV_idx_offset]); + BOOLEAN result; + + try { + if (inhibit_cleanup) { /* Inhibit garbage collection & other housekeeping - * to prevent a deadlock when we visit the record. @@ -1639,20 +1651,10 @@ static BOOLEAN get_record( */ old_att_flags = - static_cast < USHORT > - (tdbb->tdbb_attachment->att_flags & ATT_no_cleanup); + static_cast(tdbb->tdbb_attachment->att_flags & ATT_no_cleanup); old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - /* Cleanup the HACK should there be an error */ - tdbb->tdbb_attachment->att_flags &= ~ATT_no_cleanup; - tdbb->tdbb_attachment->att_flags |= - (old_att_flags & ATT_no_cleanup); - tdbb->tdbb_setjmp = (UCHAR *) old_env; - LONGJMP(reinterpret_cast < jmp_buf & >(old_env), -1); - } - tdbb->tdbb_attachment->att_flags |= ATT_no_cleanup; /* HACK */ } @@ -1662,12 +1664,14 @@ static BOOLEAN get_record( impure->irsb_flags &= ~(irsb_bof | irsb_eof); - result = VIO_get(tdbb, - rpb, - rsb, - request->req_transaction, - reinterpret_cast < blk * >(request->req_pool)); - if (result) { + result = + VIO_get(tdbb, + rpb, + rsb, + request->req_transaction, + reinterpret_cast(request->req_pool)); + if (result) + { BTR_key(tdbb, rpb->rpb_relation, rpb->rpb_record, @@ -1675,9 +1679,9 @@ static BOOLEAN get_record( struct idx *>((SCHAR *) impure + (SLONG) rsb->rsb_arg[RSB_NAV_idx_offset]), &value); - if (compare_keys(idx, key->key_data, key->key_length, &value, FALSE)) + if (compare_keys(idx, key->key_data, key->key_length, &value, FALSE)) { result = FALSE; - else { + } else { /* the successful retrieval of a record means we are no longer on a crack */ @@ -1689,8 +1693,9 @@ static BOOLEAN get_record( } } - if (!result) + if (!result) { RSE_MARK_CRACK(tdbb, rsb, irsb_crack); + } if (inhibit_cleanup) { tdbb->tdbb_attachment->att_flags &= ~ATT_no_cleanup; @@ -1698,6 +1703,16 @@ static BOOLEAN get_record( tdbb->tdbb_setjmp = (UCHAR *) old_env; } + } // try + catch (...) { + /* Cleanup the HACK should there be an error */ + tdbb->tdbb_attachment->att_flags &= ~ATT_no_cleanup; + tdbb->tdbb_attachment->att_flags |= + (old_att_flags & ATT_no_cleanup); + tdbb->tdbb_setjmp = (UCHAR *) old_env; + Firebird::status_longjmp_error::raise(-1); + } + return result; } @@ -1741,7 +1756,7 @@ static BTN nav_open( IRB retrieval; KEY lower, upper, *limit_ptr; BTR page; - EXP expanded_page; + //EXP expanded_page; BTN node; NOD retrieval_node; IDX *idx; diff --git a/src/jrd/nav_proto.h b/src/jrd/nav_proto.h index 15bfc8b2ea..da6e8bc1b0 100644 --- a/src/jrd/nav_proto.h +++ b/src/jrd/nav_proto.h @@ -29,14 +29,14 @@ #ifdef SCROLLABLE_CURSORS extern struct exp *NAV_expand_index(register struct win *, struct irsb_nav *); #endif -extern BOOLEAN NAV_get_record(struct rsb *, struct irsb_nav *, struct rpb *, +extern BOOLEAN NAV_get_record(class Rsb *, struct irsb_nav *, struct rpb *, enum rse_get_mode); #ifdef PC_ENGINE -extern BOOLEAN NAV_find_record(struct rsb *, USHORT, USHORT, struct nod *); -extern void NAV_get_bookmark(struct rsb *, struct irsb_nav *, struct bkm *); -extern BOOLEAN NAV_reset_position(struct rsb *, struct rpb *); -extern BOOLEAN NAV_set_bookmark(struct rsb *, struct irsb_nav *, struct rpb *, +extern BOOLEAN NAV_find_record(class Rsb *, USHORT, USHORT, struct nod *); +extern void NAV_get_bookmark(class Rsb *, struct irsb_nav *, struct bkm *); +extern BOOLEAN NAV_reset_position(class Rsb *, struct rpb *); +extern BOOLEAN NAV_set_bookmark(class Rsb *, struct irsb_nav *, struct rpb *, struct bkm *); #endif diff --git a/src/jrd/netware.cpp b/src/jrd/netware.cpp index a8f91d33de..39ac183f17 100644 --- a/src/jrd/netware.cpp +++ b/src/jrd/netware.cpp @@ -626,7 +626,7 @@ static FIL dfs_setup_file(dbb, file_name, file_length, desc) ULONG len; /* Allocate file block and copy file name string */ - file = (FIL) ALLOCPV(type_fil, file_length + 1); + file = new(*dbb->dbb_permanent, file_length + 1) fil(); file->fil_desc = desc; file->fil_length = file_length; file->fil_max_page = -1; @@ -667,7 +667,7 @@ static FIL dfs_setup_file(dbb, file_name, file_length, desc) l = p - lock_string; - dbb->dbb_lock = lock = (LCK) ALLOCPV(type_lck, l); + dbb->dbb_lock = lock = new(*dbb->dbb_permanent, l) lck(); lock->lck_type = LCK_database; lock->lck_owner_handle = LCK_get_owner_handle(NULL_TDBB, lock->lck_type); lock->lck_object = (BLK) dbb; diff --git a/src/jrd/old.cpp b/src/jrd/old.cpp index 19f151856e..61588a3a90 100644 --- a/src/jrd/old.cpp +++ b/src/jrd/old.cpp @@ -184,7 +184,7 @@ ULONG start_seqno, USHORT start_file, USHORT num_files, SCHAR ** files) /* dump all 'in use' pages in database. */ - temp_page = (PIP) ALL_malloc(dbb->dbb_page_size, ERR_jmp); + temp_page = (PIP) MemoryPool::malloc_from_system(dbb->dbb_page_size); pgc = dbb->dbb_pcontrol; @@ -220,7 +220,7 @@ ULONG start_seqno, USHORT start_file, USHORT num_files, SCHAR ** files) break; } - ALL_free(reinterpret_cast < char *>(temp_page)); + MemoryPool::free_from_system(temp_page); if (last_page) { file_seqno = OLD_handle->old_file_seqno; @@ -506,15 +506,15 @@ static void old_fini(OLD * OLD_handle, USHORT code) /* write a OLD_EOD record */ - if (old = *OLD_handle) { + if ( (old = *OLD_handle) ) { if (old->old_fd > 0) { if (close_cur_file(old, code) == FAILURE) return; } - ALL_free(reinterpret_cast < char *>(old->old_block->ob_hdr)); - ALL_free(reinterpret_cast < char *>(old->old_block)); - ALL_free(reinterpret_cast < char *>(old)); + MemoryPool::free_from_system(old->old_block->ob_hdr); + MemoryPool::free_from_system(old->old_block); + MemoryPool::free_from_system(old); } *OLD_handle = NULL; @@ -548,13 +548,13 @@ SSHORT rec_size, ULONG log_seqno, ULONG log_offset, ULONG log_p_offset) if (*OLD_handle != NULL) return FAILURE; - *OLD_handle = old = (OLD) ALL_malloc(sizeof(struct old), ERR_jmp); + *OLD_handle = old = (OLD) MemoryPool::malloc_from_system(sizeof(struct old)); MOVE_CLEAR(old, sizeof(struct old)); - old->old_block = (OLDBLK) ALL_malloc(sizeof(struct oldblk), ERR_jmp); + old->old_block = (OLDBLK) MemoryPool::malloc_from_system(sizeof(struct oldblk)); MOVE_CLEAR(old->old_block, sizeof(struct oldblk)); - old->old_block->ob_hdr = (OLD_HDR) ALL_malloc(MAX_OLDBUFLEN, ERR_jmp); + old->old_block->ob_hdr = (OLD_HDR) MemoryPool::malloc_from_system(MAX_OLDBUFLEN); MOVE_CLEAR(old->old_block->ob_hdr, MAX_OLDBUFLEN); old->old_dump_id = dump_id; diff --git a/src/jrd/opt.cpp b/src/jrd/opt.cpp index 1993527794..9de0d6be12 100644 --- a/src/jrd/opt.cpp +++ b/src/jrd/opt.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: opt.cpp,v 1.2 2001-07-29 17:42:22 skywalker Exp $ +$Id: opt.cpp,v 1.3 2001-12-24 02:50:51 tamlin Exp $ */ #include "firebird.h" @@ -237,8 +237,8 @@ BOOLEAN OPT_access_path(REQ request, if (!vector) return FALSE; - for (i = vector->vec_count - 1; i >= 0; i--) { - rsb = (RSB) vector->vec_object[i]; + for (i = vector->count() - 1; i >= 0; i--) { + rsb = (RSB) (*vector)[i]; if (rsb && !dump_rsb(request, rsb, &buffer, &buffer_length)) break; } @@ -267,7 +267,7 @@ RSB OPT_compile(TDBB tdbb, * **************************************/ DBB dbb; - OPT opt; + OPT opt_; IDX *idx; RIV river; NOD node, *ptr, *end, sort, project, aggregate; @@ -329,9 +329,9 @@ RSB OPT_compile(TDBB tdbb, (UCHAR *) ALLOC_LIB_MEMORY((DWORD) (sizeof(UCHAR) * MAX_STREAMS)); local_streams = (UCHAR *) ALLOC_LIB_MEMORY((DWORD) (sizeof(UCHAR) * MAX_STREAMS)); - opt = (OPT) ALLOC_LIB_MEMORY((DWORD) (sizeof(struct opt))); + opt_ = (OPT) ALLOC_LIB_MEMORY((DWORD) (sizeof(Opt))); if (streams == NULL || beds == NULL || key_streams == NULL || - local_streams == NULL || opt == NULL) { + local_streams == NULL || opt_ == NULL) { if (local_streams != NULL) FREE_LIB_MEMORY(local_streams); if (key_streams != NULL) @@ -340,47 +340,30 @@ RSB OPT_compile(TDBB tdbb, FREE_LIB_MEMORY(beds); if (streams != NULL) FREE_LIB_MEMORY(streams); - if (opt != NULL) - FREE_LIB_MEMORY(opt); + if (opt_ != NULL) + FREE_LIB_MEMORY(opt_); ERR_post(isc_virmemexh, 0); } /* clear block and set block type */ - MOVE_CLEAR(opt, sizeof(struct opt)); - ((BLK) opt)->blk_type = type_opt; + MOVE_CLEAR(opt_, sizeof(Opt)); + ((BLK) opt_)->blk_type = type_opt; #else - opt = (OPT) ALLOCP(type_opt); + opt_ = new(*dbb->dbb_permanent) Opt(); #endif old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - for (i = 0; i < streams[0]; i++) { - stream = streams[i + 1]; - if (csb->csb_rpt[stream].csb_idx_allocation) - ALL_RELEASE(csb->csb_rpt[stream].csb_idx_allocation); - csb->csb_rpt[stream].csb_idx_allocation = 0; - } -#ifdef STACK_REDUCTION - FREE_LIB_MEMORY(local_streams); - FREE_LIB_MEMORY(key_streams); - FREE_LIB_MEMORY(beds); - FREE_LIB_MEMORY(streams); - FREE_LIB_MEMORY(opt); -#else - ALL_RELEASE(opt); -#endif - ERR_punt(); - } - opt->opt_csb = csb; + try { + + opt_->opt_csb = csb; if (rse->nod_flags & rse_stream) - opt->opt_g_flags |= opt_g_stream; + opt_->opt_g_flags |= opt_g_stream; beds[0] = streams[0] = key_streams[0] = 0; conjunct_stack = rivers_stack = NULL; @@ -415,7 +398,8 @@ RSB OPT_compile(TDBB tdbb, record source blocks for all streams */ for (ptr = rse->rse_relation, end = ptr + rse->rse_count; ptr < end; - ptr++) { + ptr++) + { node = *ptr; /* find the stream number and place it at the end of the beds array @@ -436,18 +420,18 @@ RSB OPT_compile(TDBB tdbb, i = (SSHORT) key_streams[0]; compute_dbkey_streams(csb, node, key_streams); rsb = - gen_union(tdbb, opt, node, key_streams + i + 1, + gen_union(tdbb, opt_, node, key_streams + i + 1, (USHORT) (key_streams[0] - i)); local_streams[++local_streams[0]] = (UCHAR) node->nod_arg[e_uni_stream]; } else if (node->nod_type == nod_aggregate) { - rsb = gen_aggregate(tdbb, opt, node); + rsb = gen_aggregate(tdbb, opt_, node); local_streams[++local_streams[0]] = (UCHAR) node->nod_arg[e_agg_stream]; } else if (node->nod_type == nod_procedure) { - rsb = gen_procedure(tdbb, opt, node); + rsb = gen_procedure(tdbb, opt_, node); local_streams[++local_streams[0]] = (UCHAR) node->nod_arg[e_prc_stream]; } @@ -466,12 +450,12 @@ RSB OPT_compile(TDBB tdbb, if (rsb) { i = local_streams[0]; - river = (RIV) ALLOCDV(type_riv, i); + river = new(*tdbb->tdbb_default, i) riv(); river->riv_count = (UCHAR) i; river->riv_rsb = rsb; MOVE_FAST(local_streams + 1, river->riv_streams, i); - set_made_river(opt, river); - set_inactive(opt, river); + set_made_river(opt_, river); + set_inactive(opt_, river); LLS_PUSH(river, &rivers_stack); continue; } @@ -518,17 +502,17 @@ RSB OPT_compile(TDBB tdbb, /* first fill out the conjuncts at the end of opt */ - opt->opt_count = (SSHORT) conjunct_count; + opt_->opt_count = (SSHORT) conjunct_count; /* Check if size of optimizer block exceeded. */ - if (opt->opt_count > MAX_CONJUNCTS) + if (opt_->opt_count > MAX_CONJUNCTS) ERR_post(isc_optimizer_blk_exc, 0); /* Msg442: size of optimizer block exceeded */ for (i = 0; i < conjunct_count; i++) { - opt->opt_rpt[i].opt_conjunct = node = (NOD) LLS_POP(&conjunct_stack); - compute_dependencies(node, opt->opt_rpt[i].opt_dependencies); + opt_->opt_rpt[i].opt_conjunct = node = (NOD) LLS_POP(&conjunct_stack); + compute_dependencies(node, opt_->opt_rpt[i].opt_dependencies); } /* Store the conjuncts from the parent rse. But don't fiddle with @@ -536,13 +520,13 @@ RSB OPT_compile(TDBB tdbb, for (; parent_stack && conjunct_count < MAX_CONJUNCTS; parent_stack = parent_stack->lls_next, conjunct_count++) { - opt->opt_rpt[conjunct_count].opt_conjunct = node = + opt_->opt_rpt[conjunct_count].opt_conjunct = node = (NOD) parent_stack->lls_object; compute_dependencies(node, - opt->opt_rpt[conjunct_count].opt_dependencies); + opt_->opt_rpt[conjunct_count].opt_dependencies); } - opt->opt_parent_count = (SSHORT) conjunct_count; + opt_->opt_parent_count = (SSHORT) conjunct_count; /* Check if size of optimizer block exceeded. */ @@ -560,23 +544,23 @@ RSB OPT_compile(TDBB tdbb, /* outer joins require some extra processing */ if (rse->rse_jointype != blr_inner) - rsb = gen_outer(tdbb, opt, rse, rivers_stack, &sort, &project); + rsb = gen_outer(tdbb, opt_, rse, rivers_stack, &sort, &project); else { /* attempt to form joins in decreasing order of desirability */ - gen_join(tdbb, opt, streams, &rivers_stack, &sort, &project, + gen_join(tdbb, opt_, streams, &rivers_stack, &sort, &project, rse->rse_plan); /* If there are multiple rivers, try some sort/merging */ while (rivers_stack->lls_next - && gen_sort_merge(tdbb, opt, &rivers_stack)); + && gen_sort_merge(tdbb, opt_, &rivers_stack)); - rsb = make_cross(tdbb, opt, rivers_stack); + rsb = make_cross(tdbb, opt_, rivers_stack); /* Pick up any residual boolean that may have fallen thru the cracks */ - rsb = gen_residual_boolean(tdbb, opt, rsb); + rsb = gen_residual_boolean(tdbb, opt_, rsb); } /* if the aggregate was not optimized via an index, get rid of the @@ -608,25 +592,25 @@ RSB OPT_compile(TDBB tdbb, /* Handle project clause, if present. */ if (project) - rsb = gen_sort(tdbb, opt, beds, key_streams, rsb, project, TRUE); + rsb = gen_sort(tdbb, opt_, beds, key_streams, rsb, project, TRUE); /* Handle sort clause if present */ if (sort) - rsb = gen_sort(tdbb, opt, beds, key_streams, rsb, sort, FALSE); + rsb = gen_sort(tdbb, opt_, beds, key_streams, rsb, sort, FALSE); } /* If there's a FIRST n clause, handle it */ if (rse->rse_first) - rsb = gen_first(tdbb, opt, rsb, rse->rse_first); + rsb = gen_first(tdbb, opt_, rsb, rse->rse_first); /* release memory allocated for index descriptions */ for (i = 0; i < streams[0]; i++) { stream = streams[i + 1]; if (csb->csb_rpt[stream].csb_idx_allocation) - ALL_RELEASE(csb->csb_rpt[stream].csb_idx_allocation); + delete csb->csb_rpt[stream].csb_idx_allocation; csb->csb_rpt[stream].csb_idx_allocation = 0; } @@ -637,10 +621,10 @@ RSB OPT_compile(TDBB tdbb, FREE_LIB_MEMORY(key_streams); FREE_LIB_MEMORY(beds); FREE_LIB_MEMORY(streams); - FREE_LIB_MEMORY(opt); + FREE_LIB_MEMORY(opt_); #else - ALL_RELEASE(opt); + delete opt_; #endif @@ -653,11 +637,33 @@ RSB OPT_compile(TDBB tdbb, #endif tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + for (i = 0; i < streams[0]; i++) { + stream = streams[i + 1]; + if (csb->csb_rpt[stream].csb_idx_allocation) + delete csb->csb_rpt[stream].csb_idx_allocation; + csb->csb_rpt[stream].csb_idx_allocation = 0; + } +#ifdef STACK_REDUCTION + FREE_LIB_MEMORY(local_streams); + FREE_LIB_MEMORY(key_streams); + FREE_LIB_MEMORY(beds); + FREE_LIB_MEMORY(streams); + FREE_LIB_MEMORY(opt_); +#else + delete opt_; +#endif + ERR_punt(); + } + return rsb; } -NOD OPT_make_dbkey(register OPT opt, NOD boolean, USHORT stream) +NOD OPT_make_dbkey(register OPT opt_, NOD boolean, USHORT stream) { /************************************** * @@ -682,7 +688,7 @@ NOD OPT_make_dbkey(register OPT opt, NOD boolean, USHORT stream) tdbb = GET_THREAD_DATA; - DEV_BLKCHK(opt, type_opt); + DEV_BLKCHK(opt_, type_opt); DEV_BLKCHK(boolean, type_nod); /* If this isn't an equality, it isn't even interesting */ @@ -706,7 +712,7 @@ NOD OPT_make_dbkey(register OPT opt, NOD boolean, USHORT stream) /* If the value isn't computable, this has been a waste of time */ - csb = opt->opt_csb; + csb = opt_->opt_csb; if (!computable(csb, value, stream, FALSE)) return NULL; @@ -736,7 +742,7 @@ NOD OPT_make_dbkey(register OPT opt, NOD boolean, USHORT stream) } -NOD OPT_make_index(TDBB tdbb, OPT opt, REL relation, IDX * idx) +NOD OPT_make_index(TDBB tdbb, OPT opt_, REL relation, IDX * idx) { /************************************** * @@ -750,16 +756,16 @@ NOD OPT_make_index(TDBB tdbb, OPT opt, REL relation, IDX * idx) **************************************/ IRB retrieval; NOD node, *lower, *upper, *end_node; - opt::opt_repeat * tail, *end; + Opt::opt_repeat * tail, *end; SET_TDBB(tdbb); - DEV_BLKCHK(opt, type_opt); + DEV_BLKCHK(opt_, type_opt); DEV_BLKCHK(relation, type_rel); /* Allocate both a index retrieval node and block. */ - node = make_index_node(tdbb, relation, opt->opt_csb, idx); + node = make_index_node(tdbb, relation, opt_->opt_csb, idx); retrieval = (IRB) node->nod_arg[e_idx_retrieval]; retrieval->irb_relation = relation; @@ -767,19 +773,19 @@ NOD OPT_make_index(TDBB tdbb, OPT opt, REL relation, IDX * idx) lower = retrieval->irb_value; upper = retrieval->irb_value + idx->idx_count; - end = opt->opt_rpt + idx->idx_count; + end = opt_->opt_rpt + idx->idx_count; if (idx->idx_flags & idx_descending) { - for (tail = opt->opt_rpt; tail->opt_lower && tail < end; tail++) + for (tail = opt_->opt_rpt; tail->opt_lower && tail < end; tail++) *upper++ = tail->opt_lower; - for (tail = opt->opt_rpt; tail->opt_upper && tail < end; tail++) + for (tail = opt_->opt_rpt; tail->opt_upper && tail < end; tail++) *lower++ = tail->opt_upper; retrieval->irb_generic |= irb_descending; } else { - for (tail = opt->opt_rpt; tail->opt_lower && tail < end; tail++) + for (tail = opt_->opt_rpt; tail->opt_lower && tail < end; tail++) *lower++ = tail->opt_lower; - for (tail = opt->opt_rpt; tail->opt_upper && tail < end; tail++) + for (tail = opt_->opt_rpt; tail->opt_upper && tail < end; tail++) *upper++ = tail->opt_upper; } @@ -844,7 +850,7 @@ int OPT_match_index(OPT opt, USHORT stream, IDX * idx) register CSB csb; NOD node; USHORT n; - register opt::opt_repeat * tail, *opt_end; + register Opt::opt_repeat * tail, *opt_end; tdbb = GET_THREAD_DATA; DEV_BLKCHK(opt, type_opt); @@ -923,7 +929,7 @@ void OPT_set_index(TDBB tdbb, /* set up a dummy optimizer block just for the purposes of the set index, to pass information to subroutines */ - opt = (OPT) ALLOCP(type_opt); + opt = new(*dbb->dbb_permanent) Opt(); opt->opt_g_flags |= opt_g_stream; /* generate a new rsb for the retrieval, making sure to @@ -1002,18 +1008,18 @@ void OPT_set_index(TDBB tdbb, request, and replace the old with the new */ vector = request->req_fors; - for (i = 0; i < vector->vec_count; i++) - if (vector->vec_object[i] == (BLK) old_rsb) { - vector->vec_object[i] = (BLK) new_rsb; + for (i = 0; i < vector->count(); i++) + if ((*vector)[i] == (BLK) old_rsb) { + (*vector)[i] = (BLK) new_rsb; break; } /* release unneeded blocks */ - ALL_RELEASE(opt); + delete opt; if (index_node) - ALL_RELEASE(index_node); - ALL_RELEASE(old_rsb); + delete index_node; + delete old_rsb; *rsb_ptr = new_rsb; } @@ -1128,7 +1134,7 @@ static BOOLEAN check_relationship(OPT opt, USHORT position, USHORT stream) **************************************/ IRL relationship; USHORT n; - opt::opt_repeat * tail, *end; + Opt::opt_repeat * tail, *end; DEV_BLKCHK(opt, type_opt); @@ -1314,7 +1320,7 @@ static void clear_bounds(OPT opt, IDX * idx) * indices. * **************************************/ - register opt::opt_repeat * tail, *opt_end; + register Opt::opt_repeat * tail, *opt_end; DEV_BLKCHK(opt, type_opt); @@ -1545,7 +1551,7 @@ static void compute_dependencies(NOD node, ULONG * dependencies) case nod_total: case nod_count: case nod_from: - if (sub = node->nod_arg[e_stat_default]) + if ( (sub = node->nod_arg[e_stat_default]) ) compute_dependencies(sub, dependencies); rse = (RSE) node->nod_arg[e_stat_rse]; value = node->nod_arg[e_stat_value]; @@ -1562,18 +1568,18 @@ static void compute_dependencies(NOD node, ULONG * dependencies) /* Node is a record selection expression. Groan. Ugh. Yuck. */ - if (sub = rse->rse_first) + if ( (sub = rse->rse_first) ) compute_dependencies(sub, dependencies); /* Check sub-expressions */ - if (sub = rse->rse_boolean) + if ( (sub = rse->rse_boolean) ) compute_dependencies(sub, dependencies); - if (sub = rse->rse_sorted) + if ( (sub = rse->rse_sorted) ) compute_dependencies(sub, dependencies); - if (sub = rse->rse_projection) + if ( (sub = rse->rse_projection) ) compute_dependencies(sub, dependencies); /* Check value expression, if any */ @@ -1807,7 +1813,7 @@ static USHORT distribute_equalities(LLS * org_stack, CSB csb) count++; } else - ALL_RELEASE(boolean); + delete boolean; } } @@ -1971,7 +1977,7 @@ static BOOLEAN dump_rsb(REQ request, name = NULL; relation = rsb->rsb_relation; - if (alias = rsb->rsb_alias) { + if ( (alias = rsb->rsb_alias) ) { length = alias->str_length; name = (SCHAR *) alias->str_data; } @@ -2145,6 +2151,8 @@ static BOOLEAN dump_rsb(REQ request, (request, rsb->rsb_arg[RSB_LEFT_inner], &buffer, buffer_length)) return FALSE; break; + default: /* Shut up compiler warnings */ + break; } /* dump out the next rsb */ @@ -2188,7 +2196,7 @@ static BOOLEAN estimate_cost(TDBB tdbb, SSHORT n; ULONG inactivities[OPT_BITS]; double s, selectivity, cardinality, index_selectivity; - register opt::opt_repeat * tail, *opt_end; + register Opt::opt_repeat * tail, *opt_end; csb_repeat *csb_tail; DEV_BLKCHK(opt, type_opt); @@ -2452,7 +2460,7 @@ static void find_best(TDBB tdbb, USHORT flag_vector[MAX_STREAMS], *fv; BOOLEAN done; IRL relationship; - opt::opt_repeat * tail, *opt_end, *order_end, *stream_data; + Opt::opt_repeat * tail, *opt_end, *order_end, *stream_data; SET_TDBB(tdbb); DEV_BLKCHK(opt, type_opt); DEV_BLKCHK(plan_node, type_nod); @@ -2633,7 +2641,7 @@ static NOD find_dbkey(NOD dbkey, USHORT stream, SLONG * position) else if (dbkey->nod_type == nod_concatenate) for (ptr = dbkey->nod_arg, end = ptr + dbkey->nod_count; ptr < end; ptr++) - if (dbkey_temp = find_dbkey(*ptr, stream, position)) + if ( (dbkey_temp = find_dbkey(*ptr, stream, position)) ) return dbkey_temp; return NULL; } @@ -2676,7 +2684,7 @@ static USHORT find_order(TDBB tdbb, (double) 1); #ifdef OPT_DEBUG if (opt_debug_flag >= DEBUG_BEST) { - opt::opt_repeat * order_end, *tail; + Opt::opt_repeat * order_end, *tail; order_end = opt->opt_rpt + opt->opt_best_count; ib_fprintf(opt_debug_file, "find_order() -- best_count: %2.2d, best_streams: ", @@ -2747,6 +2755,8 @@ static void find_rsbs(RSB rsb, LLS * stream_list, LLS * rsb_list) ptr < end; ptr += 2) find_rsbs(*ptr, stream_list, rsb_list); break; + default: /* Shut up compiler warnings */ + break; } find_rsbs(rsb->rsb_next, stream_list, rsb_list); @@ -2838,7 +2848,7 @@ static BOOLEAN form_river(TDBB tdbb, CSB csb; RIV river; UCHAR *stream, *end_stream, *t2; - opt::opt_repeat * tail, *opt_end; + Opt::opt_repeat * tail, *opt_end; DEV_BLKCHK(opt, type_opt); DEV_BLKCHK(*river_stack, type_lls); if (sort_clause) @@ -2849,7 +2859,7 @@ static BOOLEAN form_river(TDBB tdbb, SET_TDBB(tdbb); csb = opt->opt_csb; /* Allocate a river block and move the best order into it */ - river = (RIV) ALLOCDV(type_riv, count); + river = new(*tdbb->tdbb_default, count) riv(); LLS_PUSH(river, river_stack); river->riv_count = (UCHAR) count; if (count == 1) { @@ -2857,7 +2867,7 @@ static BOOLEAN form_river(TDBB tdbb, ptr = &river->riv_rsb; } else { - river->riv_rsb = rsb = (RSB) ALLOCDV(type_rsb, count); + river->riv_rsb = rsb = new(*tdbb->tdbb_default, count) Rsb(); rsb->rsb_type = rsb_cross; rsb->rsb_count = count; rsb->rsb_impure = CMP_impure(csb, sizeof(struct irsb)); @@ -2952,7 +2962,7 @@ static RSB gen_aggregate(TDBB tdbb, OPT opt, NOD node) /* allocate and optimize the record source block */ - rsb = (RSB) ALLOCDV(type_rsb, 1); + rsb = new(*tdbb->tdbb_default, 1) Rsb(); rsb->rsb_type = rsb_aggregate; rsb->rsb_stream = (UCHAR) node->nod_arg[e_agg_stream]; rsb->rsb_format = csb->csb_rpt[rsb->rsb_stream].csb_format; @@ -3043,7 +3053,7 @@ static RSB gen_boolean(TDBB tdbb, register OPT opt, RSB prior_rsb, NOD node) DEV_BLKCHK(prior_rsb, type_rsb); SET_TDBB(tdbb); csb = opt->opt_csb; - rsb = (RSB) ALLOCDV(type_rsb, 1); + rsb = new(*tdbb->tdbb_default, 1) Rsb(); rsb->rsb_count = 1; rsb->rsb_type = rsb_boolean; rsb->rsb_next = prior_rsb; @@ -3073,7 +3083,7 @@ static RSB gen_first(TDBB tdbb, register OPT opt, RSB prior_rsb, NOD node) DEV_BLKCHK(node, type_nod); SET_TDBB(tdbb); csb = opt->opt_csb; - rsb = (RSB) ALLOCDV(type_rsb, 1); + rsb = new(*tdbb->tdbb_default, 1) Rsb(); rsb->rsb_count = 1; rsb->rsb_type = rsb_first; rsb->rsb_next = prior_rsb; @@ -3108,7 +3118,7 @@ static void gen_join(TDBB tdbb, RIV river; UCHAR temp[MAX_STREAMS], *stream, *end_stream, *t2; IRL relationship; - opt::opt_repeat * tail; + Opt::opt_repeat * tail; csb_repeat *csb_tail, *csb_tail2; USHORT count; DEV_BLKCHK(opt, type_opt); @@ -3136,7 +3146,7 @@ static void gen_join(TDBB tdbb, relation) * dbb->dbb_page_size / format->fmt_length;} - river = (RIV) ALLOCDV(type_riv, 1); + river = new(*tdbb->tdbb_default, 1) riv(); river->riv_count = 1; river->riv_rsb = gen_retrieval(tdbb, opt, streams[1], sort_clause, project_clause, @@ -3175,7 +3185,7 @@ static void gen_join(TDBB tdbb, if (*t2 != *stream) { csb_tail2 = &csb->csb_rpt[*t2]; csb_tail2->csb_flags |= csb_active; - if (relationship = indexed_relationship(tdbb, opt, *t2)) { + if ( (relationship = indexed_relationship(tdbb, opt, *t2)) ) { relationship->irl_next = tail->opt_relationships; tail->opt_relationships = relationship; relationship->irl_stream = *t2; @@ -3349,7 +3359,7 @@ static RSB gen_nav_rsb(TDBB tdbb, DEV_BLKCHK(alias, type_str); SET_TDBB(tdbb); key_length = ROUNDUP(BTR_key_length(relation, idx), sizeof(SLONG)); - rsb = (RSB) ALLOCDV(type_rsb, RSB_NAV_count); + rsb = new(*tdbb->tdbb_default, RSB_NAV_count) Rsb(); rsb->rsb_type = rsb_navigate; rsb->rsb_relation = relation; rsb->rsb_stream = (UCHAR) stream; @@ -3465,7 +3475,7 @@ static RSB gen_outer(TDBB tdbb, stream_i.stream_rsb = gen_residual_boolean(tdbb, opt, stream_i.stream_rsb); /* Allocate and fill in the rsb */ - rsb = (RSB) ALLOCDV(type_rsb, RSB_LEFT_count); + rsb = new(*tdbb->tdbb_default, RSB_LEFT_count) Rsb(); rsb->rsb_type = rsb_left_cross; rsb->rsb_count = 2; rsb->rsb_impure = CMP_impure(opt->opt_csb, sizeof(struct irsb)); @@ -3508,7 +3518,7 @@ static RSB gen_procedure(TDBB tdbb, OPT opt, NOD node) SET_TDBB(tdbb); csb = opt->opt_csb; procedure = (PRC) node->nod_arg[e_prc_procedure]; - rsb = (RSB) ALLOCDV(type_rsb, RSB_PRC_count); + rsb = new(*tdbb->tdbb_default, RSB_PRC_count) Rsb(); rsb->rsb_type = rsb_procedure; rsb->rsb_stream = (UCHAR) node->nod_arg[e_prc_stream]; rsb->rsb_procedure = procedure; @@ -3535,7 +3545,7 @@ static RSB gen_residual_boolean(TDBB tdbb, register OPT opt, RSB prior_rsb) * **************************************/ NOD node, boolean; - register opt::opt_repeat * tail, *opt_end; + register Opt::opt_repeat * tail, *opt_end; SET_TDBB(tdbb); DEV_BLKCHK(opt, type_opt); DEV_BLKCHK(prior_rsb, type_rsb); @@ -3582,7 +3592,7 @@ static RSB gen_retrieval(TDBB tdbb, NOD node, opt_boolean, inversion; USHORT segments; SSHORT i; - register opt::opt_repeat * tail, *opt_end, *idx_tail, *idx_end; + register Opt::opt_repeat * tail, *opt_end, *idx_tail, *idx_end; csb_repeat *csb_tail; BOOLEAN full = FALSE; SET_TDBB(tdbb); @@ -3704,9 +3714,9 @@ static RSB gen_retrieval(TDBB tdbb, if (!rsb) { if (sort_ptr && *sort_ptr) { - if (rsb = + if ( (rsb = gen_navigation(tdbb, opt, stream, relation, alias, - idx, sort_ptr)) continue; + idx, sort_ptr)) ) continue; } /* for now, make sure that we only map a DISTINCT to an index if they contain @@ -3831,14 +3841,14 @@ static RSB gen_rsb(TDBB tdbb, } else { if (inversion) { - rsb = (RSB) ALLOCDV(type_rsb, 1); + rsb = new(*tdbb->tdbb_default, 1) Rsb(); rsb->rsb_type = rsb_indexed; rsb->rsb_count = 1; size = sizeof(struct irsb_index); rsb->rsb_arg[0] = (RSB) inversion; } else { - rsb = (RSB) ALLOCDV(type_rsb, 0); + rsb = new(*tdbb->tdbb_default, 0) Rsb(); rsb->rsb_type = rsb_sequential; size = sizeof(struct irsb); if (boolean) @@ -3899,7 +3909,7 @@ static RSB gen_sort(TDBB tdbb, DSC *desc, descriptor; FMT format; LLS id_stack, stream_stack; - smb::smb_repeat * map_item; + smb_repeat * map_item; DEV_BLKCHK(opt, type_opt); DEV_BLKCHK(prior_rsb, type_rsb); DEV_BLKCHK(sort, type_nod); @@ -3951,9 +3961,9 @@ static RSB gen_sort(TDBB tdbb, end. */ count = items + - (sizeof(SKD) * 2 * sort->nod_count + sizeof(smb::smb_repeat) - - 1) / sizeof(smb::smb_repeat); - map = (SMB) ALLOCDV(type_smb, count); + (sizeof(SKD) * 2 * sort->nod_count + sizeof(smb_repeat) - + 1) / sizeof(smb_repeat); + map = new(*tdbb->tdbb_default, count) smb(); map->smb_keys = sort->nod_count * 2; map->smb_count = items; if (project_flag) @@ -4114,7 +4124,7 @@ static RSB gen_sort(TDBB tdbb, /* That was most unpleasant. Never the less, it's done (except for the debugging). All that remains is to build the record source block for the sort. */ - rsb = (RSB) ALLOCDV(type_rsb, 1); + rsb = new(*tdbb->tdbb_default, 1) Rsb(); rsb->rsb_type = rsb_sort; rsb->rsb_next = prior_rsb; rsb->rsb_arg[0] = (RSB) map; @@ -4151,7 +4161,7 @@ static BOOLEAN gen_sort_merge(TDBB tdbb, OPT opt, LLS * org_rivers) **selected_class, *last_class, node, node1, node2, sort, *ptr; RSB rsb, merge_rsb; RSB *rsb_tail; - opt::opt_repeat * tail, *end; + Opt::opt_repeat * tail, *end; DEV_BLKCHK(opt, type_opt); DEV_BLKCHK(*org_rivers, type_lls); SET_TDBB(tdbb); @@ -4164,8 +4174,8 @@ static BOOLEAN gen_sort_merge(TDBB tdbb, OPT opt, LLS * org_rivers) river1->riv_number = cnt++; } - scratch = (VEC) ALLOCPV(type_vec, opt->opt_count * cnt); - classes = (NOD *) scratch->vec_object; + scratch = vec::newVector(*dbb->dbb_permanent, opt->opt_count * cnt); + classes = (NOD *) scratch->begin(); /* Compute equivalence classes among streams. This involves finding groups of streams joined by field equalities. */ last_class = classes; @@ -4229,14 +4239,14 @@ static BOOLEAN gen_sort_merge(TDBB tdbb, OPT opt, LLS * org_rivers) } if (!river_cnt) { - ALL_RELEASE(scratch); + delete scratch; return FALSE; } *selected_class = NULL; class_cnt = selected_class - selected_classes; /* Build a sort stream */ - merge_rsb = (RSB) ALLOCDV(type_rsb, river_cnt * 2); + merge_rsb = new(*tdbb->tdbb_default, river_cnt * 2) Rsb(); merge_rsb->rsb_count = river_cnt; merge_rsb->rsb_type = rsb_merge; merge_rsb->rsb_impure = CMP_impure(opt->opt_csb, @@ -4253,7 +4263,7 @@ static BOOLEAN gen_sort_merge(TDBB tdbb, OPT opt, LLS * org_rivers) if (!(TEST_DEP_BIT(selected_rivers, river1->riv_number))) continue; stream_cnt += river1->riv_count; - sort = (NOD) ALLOCDV(type_nod, class_cnt * 2); + sort = new(*tdbb->tdbb_default, class_cnt * 2) nod(); sort->nod_type = nod_sort; sort->nod_count = class_cnt; for (selected_class = selected_classes, ptr = sort->nod_arg; @@ -4268,7 +4278,7 @@ static BOOLEAN gen_sort_merge(TDBB tdbb, OPT opt, LLS * org_rivers) /* Finally, merge selected rivers into a single river, and rebuild original river stack */ - river1 = (RIV) ALLOCDV(type_riv, stream_cnt); + river1 = new(*tdbb->tdbb_default, stream_cnt) riv(); river1->riv_count = (UCHAR) stream_cnt; river1->riv_rsb = merge_rsb; stream = river1->riv_streams; @@ -4301,7 +4311,7 @@ static BOOLEAN gen_sort_merge(TDBB tdbb, OPT opt, LLS * org_rivers) river1->riv_rsb = gen_boolean(tdbb, opt, river1->riv_rsb, node); set_inactive(opt, river1); *org_rivers = stack1; - ALL_RELEASE(scratch); + delete scratch; return TRUE; } @@ -4330,7 +4340,7 @@ static RSB gen_union(TDBB tdbb, clauses = union_node->nod_arg[e_uni_clauses]; count = clauses->nod_count; csb = opt->opt_csb; - rsb = (RSB) ALLOCDV(type_rsb, count + nstreams + 1); + rsb = new(*tdbb->tdbb_default, count + nstreams + 1) Rsb(); rsb->rsb_type = rsb_union; rsb->rsb_count = count; rsb->rsb_stream = (UCHAR) union_node->nod_arg[e_uni_stream]; @@ -4364,11 +4374,11 @@ static void get_inactivities(CSB csb, ULONG * dependencies) * **************************************/ USHORT n; - csb_repeat *tail, *end; + Csb::rpt_itr tail, end; DEV_BLKCHK(csb, type_csb); for (n = 0; n < OPT_BITS; n++) dependencies[n] = (ULONG) - 1; - for (tail = csb->csb_rpt, end = tail + csb->csb_n_stream, n = 0; + for (tail = csb->csb_rpt.begin(), end = tail + csb->csb_n_stream, n = 0; tail < end; n++, tail++) if (tail->csb_flags & csb_active) CLEAR_DEP_BIT(dependencies, n); @@ -4397,7 +4407,7 @@ static IRL indexed_relationship(TDBB tdbb, OPT opt, USHORT stream) NOD node; IRL relationship; USHORT i; - register opt::opt_repeat * tail, *opt_end; + register Opt::opt_repeat * tail, *opt_end; csb_repeat *csb_tail; DEV_BLKCHK(opt, type_opt); SET_TDBB(tdbb); @@ -4426,7 +4436,7 @@ static IRL indexed_relationship(TDBB tdbb, OPT opt, USHORT stream) tail = opt->opt_rpt; if (tail->opt_lower || tail->opt_upper) { if (!relationship) - relationship = (IRL) ALLOCD(type_irl); + relationship = new(*tdbb->tdbb_default) irl(); if (idx->idx_flags & idx_unique) { relationship->irl_unique = TRUE; break; @@ -4481,7 +4491,7 @@ static STR make_alias(TDBB tdbb, CSB csb, csb_repeat * base_tail) /* allocate a string block to hold the concatenated alias */ - alias = (STR) ALLOCDV(type_str, alias_length); + alias = new(*tdbb->tdbb_default, alias_length) str(); alias->str_length = alias_length - 1; /* now concatenate the individual aliases into the string block, beginning at the end and copying back to the beginning */ @@ -4567,7 +4577,7 @@ static RSB make_cross(TDBB tdbb, OPT opt, LLS stack) } csb = opt->opt_csb; - rsb = (RSB) ALLOCDV(type_rsb, count); + rsb = new(*tdbb->tdbb_default, count) Rsb(); rsb->rsb_type = rsb_cross; rsb->rsb_count = count; rsb->rsb_impure = CMP_impure(csb, sizeof(struct irsb)); @@ -4611,7 +4621,7 @@ static NOD make_index_node(TDBB tdbb, REL relation, CSB csb, IDX * idx) node = PAR_make_node(tdbb, e_idx_length); node->nod_type = nod_index; node->nod_count = 0; - retrieval = (IRB) ALLOCDV(type_irb, idx->idx_count * 2); + retrieval = new(*tdbb->tdbb_default, idx->idx_count * 2) irb(); node->nod_arg[e_idx_retrieval] = (NOD) retrieval; retrieval->irb_index = idx->idx_id; MOVE_FAST(idx, &retrieval->irb_desc, sizeof(retrieval->irb_desc)); @@ -4715,13 +4725,13 @@ static NOD make_inversion(TDBB tdbb, (inversion = make_inversion(tdbb, opt, boolean->nod_arg[0], stream))) return NULL; - if (inversion2 = + if ( (inversion2 = make_inversion(tdbb, opt, boolean->nod_arg[1], - stream)) return compose(&inversion, inversion2, + stream)) ) return compose(&inversion, inversion2, nod_bit_or); if (inversion->nod_type == nod_index) - ALL_RELEASE(inversion->nod_arg[e_idx_retrieval]); - ALL_RELEASE(inversion); + delete inversion->nod_arg[e_idx_retrieval]; + delete inversion; return NULL; } @@ -4938,7 +4948,7 @@ static void mark_indices(csb_repeat * csb_tail, SSHORT relation_id) return; /* find out how many indices were specified; if there were none, this is a sequential retrieval */ - if (access_type = plan->nod_arg[e_retrieve_access_type]) + if ( (access_type = plan->nod_arg[e_retrieve_access_type]) ) plan_count = access_type->nod_count; /* go through each of the indices and mark it unusable for indexed retrieval unless it was specifically mentioned @@ -4987,7 +4997,7 @@ static SSHORT match_index(TDBB tdbb, **************************************/ NOD match, value; SSHORT i, forward, count; - opt::opt_repeat * ptr; + Opt::opt_repeat * ptr; DEV_BLKCHK(opt, type_opt); DEV_BLKCHK(boolean, type_nod); SET_TDBB(tdbb); @@ -5078,6 +5088,8 @@ static SSHORT match_index(TDBB tdbb, ptr->opt_lower = value; ptr->opt_match = boolean; break; + default: /* Shut up compiler warnings */ + break; } } @@ -5294,7 +5306,7 @@ static void print_order(OPT opt, * Functional description * **************************************/ - opt::opt_repeat * tail, *order_end; + Opt::opt_repeat * tail, *order_end; DEV_BLKCHK(opt, type_opt); order_end = opt->opt_rpt + position; ib_fprintf(opt_debug_file, "print_order() -- position %2.2d: ", position); diff --git a/src/jrd/opt_proto.h b/src/jrd/opt_proto.h index 787083116d..a023fe735b 100644 --- a/src/jrd/opt_proto.h +++ b/src/jrd/opt_proto.h @@ -31,14 +31,14 @@ extern BOOLEAN OPT_access_path(struct req *, SCHAR *, SSHORT, USHORT *); -extern struct rsb *OPT_compile(TDBB, register struct csb *, +extern class Rsb *OPT_compile(TDBB, register class Csb *, register struct rse *, struct lls *); extern struct nod *OPT_make_dbkey(register struct opt *, struct nod *, USHORT); extern struct nod *OPT_make_index(TDBB, struct opt *, struct rel *, struct idx *); extern int OPT_match_index(struct opt *, USHORT, struct idx *); -extern void OPT_set_index(TDBB, struct req *, struct rsb **, struct rel *, +extern void OPT_set_index(TDBB, struct req *, class Rsb **, struct rel *, struct idx *); #endif /* _JRD_OPT_PROTO_H_ */ diff --git a/src/jrd/os2.cpp b/src/jrd/os2.cpp index a0927d1030..eaec19c530 100644 --- a/src/jrd/os2.cpp +++ b/src/jrd/os2.cpp @@ -597,7 +597,7 @@ static FIL setup_file( /* Allocate file block and copy file name string */ - file = (FIL) ALLOCPV(type_fil, file_length + 1); + file = new(*dbb->dbb_permanent, file_length + 1) fil(); file->fil_desc = desc; file->fil_length = file_length; file->fil_max_page = -1; @@ -612,7 +612,7 @@ static FIL setup_file( /* Build unique lock string for file and construct lock block */ - dbb->dbb_lock = lock = (LCK) ALLOCPV(type_lck, file_length); + dbb->dbb_lock = lock = new(*dbb->dbb_permanent, file_length) lck(); lock->lck_type = LCK_database; lock->lck_owner_handle = LCK_get_owner_handle(NULL_TDBB, lock->lck_type); lock->lck_object = (BLK) dbb; diff --git a/src/jrd/pag.cpp b/src/jrd/pag.cpp index c0b71737fd..92836d8972 100644 --- a/src/jrd/pag.cpp +++ b/src/jrd/pag.cpp @@ -318,7 +318,7 @@ int PAG_add_clump( if (entry_p[1] == len) { entry_p += 2; r = entry; - if (l = len) { + if ( (l = len) ) { if (must_write) CCH_MARK_MUST_WRITE(tdbb, &window); else @@ -657,7 +657,7 @@ PAG PAG_allocate(register WIN * window) CCH_precedence(tdbb, window, pip_window.win_page); #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) - ib_printf("\tPAG_allocate: allocated page %d\n", + ib_printf("\tPAG_allocate: allocated page %"SLONGFORMAT"\n", window->win_page); #endif return new_page; @@ -740,7 +740,7 @@ SLONG PAG_attachment_id(void) /* Take out lock on attachment id */ - lock = attachment->att_id_lock = (LCK) ALLOCPV(type_lck, sizeof(SLONG)); + lock = attachment->att_id_lock = new(*dbb->dbb_permanent, sizeof(SLONG)) lck(); lock->lck_type = LCK_attachment; lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type); lock->lck_parent = dbb->dbb_lock; @@ -1033,18 +1033,14 @@ void PAG_header(TEXT * file_name, USHORT file_length) and unit of transfer is a multiple of physical disk sector for raw disk access. */ - temp_buffer = ALL_malloc((SLONG) 2 * MIN_PAGE_SIZE, ERR_jmp); + temp_buffer = (SCHAR*)MemoryPool::malloc_from_system((SLONG) 2 * MIN_PAGE_SIZE); temp_page = (SCHAR *) (((U_IPTR) temp_buffer + MIN_PAGE_SIZE - 1) & ~((U_IPTR) MIN_PAGE_SIZE - 1)); old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (temp_buffer) - ALL_free(temp_buffer); - ERR_punt(); - } + + try { header = (HDR) temp_page; PIO_header(dbb, temp_page, MIN_PAGE_SIZE); @@ -1108,9 +1104,8 @@ if (header->hdr_implementation && header->hdr_implementation != CLASS) dbb->dbb_flags |= DBB_DB_SQL_dialect_3; relation = MET_relation(tdbb, 0); - relation->rel_pages = vector = (VCL) ALLOCPV(type_vcl, 1); - vector->vcl_count = 1; - vector->vcl_long[0] = header->hdr_PAGES; + relation->rel_pages = vector = vcl::newVector(*dbb->dbb_permanent, 1); + (*vector)[0] = header->hdr_PAGES; dbb->dbb_page_size = header->hdr_page_size; dbb->dbb_page_buffers = header->hdr_page_buffers; @@ -1154,8 +1149,17 @@ if (header->hdr_implementation && header->hdr_implementation != CLASS) dbb->dbb_ast_flags |= DBB_shutdown; if (temp_buffer) - ALL_free(temp_buffer); + MemoryPool::free_from_system(temp_buffer); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (temp_buffer) { + MemoryPool::free_from_system(temp_buffer); + } + ERR_punt(); + } } @@ -1179,7 +1183,7 @@ void PAG_init(void) dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - dbb->dbb_pcontrol = control = (PGC) ALLOCP(type_pgc); + dbb->dbb_pcontrol = control = new(*dbb->dbb_permanent) pgc(); control->pgc_bytes = dbb->dbb_page_size - OFFSETA(PIP, pip_bits); control->pgc_ppp = control->pgc_bytes * 8; control->pgc_tpt = @@ -1254,19 +1258,15 @@ void PAG_init2(USHORT shadow_number) and set up to release it in case of error. Align the temporary page buffer for raw disk access. */ - temp_buffer = - ALL_malloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE, ERR_jmp); + temp_buffer = (SCHAR*) + MemoryPool::malloc_from_system((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE); temp_page = (SCHAR *) (((U_IPTR) temp_buffer + MIN_PAGE_SIZE - 1) & ~((U_IPTR) MIN_PAGE_SIZE - 1)); old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (temp_buffer) - ALL_free(temp_buffer); - ERR_punt(); - } + + try { file = dbb->dbb_file; if (shadow_number) { @@ -1284,7 +1284,8 @@ void PAG_init2(USHORT shadow_number) /* Loop thru files and header pages until everything is open */ - for (;;) { + for (;;) + { file_name = NULL; window.win_page = file->fil_min_page; do { @@ -1365,9 +1366,19 @@ void PAG_init2(USHORT shadow_number) file->fil_sequence = sequence++; } - if (temp_buffer) - ALL_free(temp_buffer); + if (temp_buffer) { + MemoryPool::free_from_system(temp_buffer); + } tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (temp_buffer) { + MemoryPool::free_from_system(temp_buffer); + } + ERR_punt(); + } } @@ -1501,7 +1512,7 @@ void PAG_release_page(SLONG number, SLONG prior_page) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) - ib_printf("\tPAG_release_page: about to release page %d\n", number); + ib_printf("\tPAG_release_page: about to release page %"SLONGFORMAT"\n", number); #endif control = dbb->dbb_pcontrol; diff --git a/src/jrd/pag.h b/src/jrd/pag.h index 9238d90daa..ff63ffdd16 100644 --- a/src/jrd/pag.h +++ b/src/jrd/pag.h @@ -34,17 +34,22 @@ #ifndef _JRD_PAG_H_ #define _JRD_PAG_H_ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + /* Page control block -- used by PAG to keep track of critical constants */ -typedef struct pgc { - struct blk pgc_header; +class pgc : public pool_alloc +{ + public: SLONG pgc_high_water; /* Lowest PIP with space */ SLONG pgc_ppp; /* Pages per pip */ SLONG pgc_pip; /* First pointer page */ ULONG pgc_bytes; /* Number of bytes of bit in PIP */ ULONG pgc_tpt; /* Transactions per TIP */ ULONG pgc_gpg; /* Generators per generator page */ -} *PGC; +}; +typedef pgc *PGC; #endif /* _JRD_PAG_H_ */ diff --git a/src/jrd/par.cpp b/src/jrd/par.cpp index 9e4570e68d..fdfb33e4d2 100644 --- a/src/jrd/par.cpp +++ b/src/jrd/par.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: par.cpp,v 1.3 2001-07-29 17:42:22 skywalker Exp $ +$Id: par.cpp,v 1.4 2001-12-24 02:50:52 tamlin Exp $ */ #include "firebird.h" @@ -137,7 +137,7 @@ NOD PAR_blr(TDBB tdbb, CSB csb; NOD node; SSHORT version, stream, count; - csb_repeat *t1, *t2, *end; + csb_repeat *t1, *t2; SET_TDBB(tdbb); @@ -145,7 +145,7 @@ NOD PAR_blr(TDBB tdbb, count = 5; if (view_csb) count += view_csb->csb_count; - csb = (CSB) ALLOCDV(type_csb, count); + csb = Csb::newCsb(*tdbb->tdbb_default, count); csb->csb_count = count; csb->csb_g_flags |= flags; } @@ -174,12 +174,12 @@ NOD PAR_blr(TDBB tdbb, csb->csb_running = csb->csb_blr = blr; if (view_csb) { - t1 = view_csb->csb_rpt; - end = t1 + view_csb->csb_n_stream; - for (stream = 0; t1 < end; t1++, stream++) { + Csb::rpt_itr ptr = view_csb->csb_rpt.begin(); + Csb::rpt_itr end = ptr + view_csb->csb_n_stream; + for (stream = 0; ptr != end; ++ptr, ++stream) { t2 = CMP_csb_element(&csb, stream); - t2->csb_relation = t1->csb_relation; - t2->csb_stream = t1->csb_stream; + t2->csb_relation = ptr->csb_relation; + t2->csb_stream = ptr->csb_stream; } csb->csb_n_stream = view_csb->csb_n_stream; } @@ -207,7 +207,7 @@ NOD PAR_blr(TDBB tdbb, if (csb_ptr) *csb_ptr = csb; else - ALL_RELEASE(csb); + delete csb; return node; } @@ -361,7 +361,7 @@ NOD PAR_gen_field(TDBB tdbb, USHORT stream, USHORT id) SET_TDBB(tdbb); - node = (NOD) ALLOCDV(type_nod, e_fld_length); + node = new(*tdbb->tdbb_default, e_fld_length) nod(); node->nod_type = nod_field; node->nod_arg[e_fld_id] = (NOD) (SLONG) id; node->nod_arg[e_fld_stream] = (NOD) (SLONG) stream; @@ -427,7 +427,7 @@ NOD PAR_make_field(TDBB tdbb, CSB csb, USHORT context, TEXT * base_field) temp_node = PAR_gen_field(tdbb, stream, id); - if (field = (FLD) temp_rel->rel_fields->vec_object[id]) { + if ( (field = (FLD) (*temp_rel->rel_fields)[id]) ) { if (field->fld_default_value && field->fld_not_null) temp_node->nod_arg[e_fld_default_value] = field->fld_default_value; @@ -487,7 +487,7 @@ NOD PAR_make_node(TDBB tdbb, int size) SET_TDBB(tdbb); - node = (NOD) ALLOCDV(type_nod, size); + node = new(*tdbb->tdbb_default, size) nod(); node->nod_count = size; return node; @@ -512,8 +512,9 @@ CSB PAR_parse(TDBB tdbb, UCHAR* blr, USHORT internal_flag) SET_TDBB(tdbb); - csb = (CSB) ALLOCDV(type_csb, 5); + csb = Csb::newCsb(*tdbb->tdbb_default, 5); csb->csb_count = 5; + csb->csb_rpt.resize(5); // vec always allocates one too many csb->csb_running = csb->csb_blr = blr; version = *csb->csb_running++; if (internal_flag) @@ -614,7 +615,7 @@ static void error(CSB csb, ...) /* Pick up remaining args */ - while (*p++ = type = va_arg(args, int)) + while ( (*p++ = type = va_arg(args, int)) ) switch (type) { case gds_arg_gds: *p++ = (STATUS) va_arg(args, STATUS); @@ -666,11 +667,12 @@ static SSHORT find_proc_field(PRC procedure, TEXT * name) * **************************************/ VEC list; - BLK *ptr, *end; + vec::iterator ptr, end; PRM param; + // JMB: Is there a reason we are skipping the last element in the array? list = procedure->prc_output_fields; - for (ptr = list->vec_object, end = ptr + list->vec_count - 1; ptr < end; + for (ptr = list->begin(), end = list->end() - 1; ptr < end; ptr++) { param = (PRM) * ptr; if (!strcmp(name, param->prm_name)) @@ -734,7 +736,7 @@ static NOD par_cast(TDBB tdbb, CSB * csb) node = PAR_make_node(tdbb, e_cast_length); node->nod_count = count_table[blr_cast]; - format = (FMT) ALLOCDV(type_fmt, 1); + format = fmt::newFmt(*tdbb->tdbb_default, 1); format->fmt_count = 1; node->nod_arg[e_cast_fmt] = (NOD) format; @@ -770,7 +772,7 @@ static XCP par_condition(TDBB tdbb, CSB * csb) /* allocate a node to represent the conditions list */ - exception_list = (XCP) ALLOCDV(type_xcp, 1); + exception_list = new(*tdbb->tdbb_default, 1) xcp(); exception_list->xcp_count = 1; code_type = BLR_BYTE; switch (code_type) { @@ -837,7 +839,7 @@ static XCP par_conditions(TDBB tdbb, CSB * csb) /* allocate a node to represent the conditions list */ n = BLR_WORD; - exception_list = (XCP) ALLOCDV(type_xcp, n); + exception_list = new(*tdbb->tdbb_default, n) xcp(); exception_list->xcp_count = n; for (i = 0; i < n; i++) { code_type = BLR_BYTE; @@ -964,7 +966,7 @@ static void par_dependency( node->nod_arg[e_dep_field] = field_node = PAR_make_node(tdbb, 1); field_node->nod_type = nod_literal; length = strlen(field_name); - string = (STR) ALLOCDV(type_str, length); + string = new(*tdbb->tdbb_default, length) str(); string->str_length = length; strcpy(reinterpret_cast < char *>(string->str_data), field_name); field_node->nod_arg[0] = (NOD) string->str_data; @@ -1198,8 +1200,8 @@ static NOD par_field(TDBB tdbb, CSB * csb, SSHORT operator_) node->nod_flags |= flags; if (is_column == TRUE) { - if (temp_rel = (*csb)->csb_rpt[stream].csb_relation) { - if (field = (FLD) temp_rel->rel_fields->vec_object[id]) { + if ( (temp_rel = (*csb)->csb_rpt[stream].csb_relation) ) { + if ( (field = (FLD) (*temp_rel->rel_fields)[id]) ) { if (field->fld_default_value && field->fld_not_null) node->nod_arg[e_fld_default_value] = field->fld_default_value; @@ -1360,7 +1362,7 @@ static NOD par_literal(TDBB tdbb, register CSB * csb) default: assert(FALSE); case dtype_text: - if (count = l) + if ( (count = l) ) do *p++ = *q++; while (--count); @@ -1429,7 +1431,7 @@ static NOD par_message(TDBB tdbb, CSB * csb) **************************************/ NOD node; FMT format; - DSC *desc, *end; + fmt::fmt_desc_iterator desc, end; USHORT n, alignment; ULONG offset; csb_repeat *tail; @@ -1451,12 +1453,12 @@ static NOD par_message(TDBB tdbb, CSB * csb) out the format block */ n = BLR_WORD; - format = (FMT) ALLOCDV(type_fmt, n); + format = fmt::newFmt(*tdbb->tdbb_default, n); node->nod_arg[e_msg_format] = (NOD) format; format->fmt_count = n; offset = 0; - for (desc = format->fmt_desc, end = desc + n; desc < end; desc++) { + for (desc = format->fmt_desc.begin(), end = desc + n; desc < end; desc++) { alignment = PAR_desc(csb, desc); if (alignment) offset = FB_ALIGN(offset, alignment); @@ -1535,7 +1537,7 @@ static USHORT par_name(CSB * csb, TEXT * string) **************************************/ USHORT count, l; - if (count = l = BLR_BYTE) + if ( (count = l = BLR_BYTE) ) do *string++ = BLR_BYTE; while (--l); @@ -1902,7 +1904,7 @@ static NOD par_relation( id = BLR_WORD; if (operator_ == blr_rid2) { length = BLR_PEEK; - alias_string = (STR) ALLOCDV(type_str, length + 1); + alias_string = new(*tdbb->tdbb_default, length + 1) str(); alias_string->str_length = length; par_name(csb, reinterpret_cast < char *>(alias_string->str_data)); } @@ -1914,8 +1916,8 @@ static NOD par_relation( #else /* To use rid, the relation slot must already have been filled in */ - if (id >= dbb->dbb_relations->vec_count - || !dbb->dbb_relations->vec_object[id]) + if (id >= dbb->dbb_relations->count() + || !(*dbb->dbb_relations)[id]) error(*csb, gds_ctxnotdef, 0); relation = MET_relation(tdbb, id); #endif @@ -1924,7 +1926,7 @@ static NOD par_relation( par_name(csb, name); if (operator_ == blr_relation2) { length = BLR_PEEK; - alias_string = (STR) ALLOCDV(type_str, length + 1); + alias_string = new(*tdbb->tdbb_default, length + 1) str(); alias_string->str_length = length; par_name(csb, reinterpret_cast < char *>(alias_string->str_data)); } @@ -2236,7 +2238,7 @@ static NOD parse(TDBB tdbb, register CSB * csb, USHORT expected) the node and set its count. This saves an enormous amount of repetitive code. */ - if (n = length_table[operator_]) { + if ( (n = length_table[operator_]) ) { node = PAR_make_node(tdbb, n); node->nod_count = count_table[operator_]; arg = node->nod_arg; @@ -2510,9 +2512,17 @@ static NOD parse(TDBB tdbb, register CSB * csb, USHORT expected) n = BLR_WORD; node->nod_arg[e_dcl_id] = (NOD) (SLONG) n; PAR_desc(csb, (DSC *) (node->nod_arg + e_dcl_desc)); - vector = - ALL_vector(tdbb->tdbb_default, &(*csb)->csb_variables, n); - vector->vec_object[n] = (BLK) node; + vector = (*csb)->csb_variables; + if (!vector) + { + vector = (*csb)->csb_variables = + vec::newVector(*tdbb->tdbb_default, n + 1); + } + if (n >= vector->count()) + { + vector->resize(n + 1); + } + (*vector)[n] = (BLK) node; } break; @@ -2523,9 +2533,9 @@ static NOD parse(TDBB tdbb, register CSB * csb, USHORT expected) n = BLR_WORD; node->nod_arg[e_var_id] = (NOD) (SLONG) n; if (!(vector = (*csb)->csb_variables) || - n >= vector->vec_count || + n >= vector->count() || !(node->nod_arg[e_var_variable] = - (NOD) vector->vec_object[n])) syntax_error(*csb, + (NOD) (*vector)[n])) syntax_error(*csb, "variable identifier"); } break; @@ -2897,7 +2907,7 @@ static void warning(CSB csb, ...) /* Pick up remaining args */ - while (*p++ = type = va_arg(args, int)) + while ( (*p++ = type = va_arg(args, int)) ) switch (type) { case gds_arg_gds: *p++ = (STATUS) va_arg(args, STATUS); diff --git a/src/jrd/par_proto.h b/src/jrd/par_proto.h index b5e972a578..12ed0c0d8b 100644 --- a/src/jrd/par_proto.h +++ b/src/jrd/par_proto.h @@ -28,14 +28,14 @@ extern "C" { #endif -struct nod *PAR_blr(TDBB, struct rel *, UCHAR *, struct csb *, struct csb **, +struct nod *PAR_blr(TDBB, struct rel *, UCHAR *, class Csb *, class Csb **, struct req **, BOOLEAN, USHORT); -int PAR_desc(struct csb **, struct dsc *); +int PAR_desc(class Csb **, struct dsc *); struct nod *PAR_gen_field(TDBB, USHORT, USHORT); -struct nod *PAR_make_field(TDBB, struct csb *, USHORT, TEXT *); +struct nod *PAR_make_field(TDBB, class Csb *, USHORT, TEXT *); struct nod *PAR_make_list(TDBB, struct lls *); struct nod *PAR_make_node(TDBB, int); -struct csb *PAR_parse(TDBB, UCHAR *, USHORT); +class Csb *PAR_parse(TDBB, UCHAR *, USHORT); SLONG PAR_symbol_to_gdscode(SCHAR *); #ifdef __cplusplus diff --git a/src/jrd/pcmet.epp b/src/jrd/pcmet.epp index 6086a91246..994a1502fa 100644 --- a/src/jrd/pcmet.epp +++ b/src/jrd/pcmet.epp @@ -136,7 +136,7 @@ int PCMET_expression_index( for the expression index */ default_pool = tdbb->tdbb_default; - tdbb->tdbb_default = new_pool = ALL_pool(); + tdbb->tdbb_default = new_pool = ALL_pool(&jrd_alloc_info); MET_scan_relation(tdbb, relation); if (!IDX.RDB$EXPRESSION_BLR.NULL) @@ -249,7 +249,7 @@ void PCMET_lookup_index( REL relation, IDX * idx) with the index block in the "permanent" metadata cache */ old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = ALL_pool(); + tdbb->tdbb_default = ALL_pool(&jrd_alloc_info); idx->idx_expression = MET_parse_blob(tdbb, relation, &IDX.RDB$EXPRESSION_BLR, &csb, &idx->idx_expression_request, FALSE, FALSE); diff --git a/src/jrd/perf.cpp b/src/jrd/perf.cpp index 601ae255e0..0c8914e409 100644 --- a/src/jrd/perf.cpp +++ b/src/jrd/perf.cpp @@ -92,7 +92,7 @@ extern clock_t times(); #endif -API_ROUTINE int perf_format( +int API_ROUTINE perf_format( PERF * before, PERF * after, SCHAR * string, SCHAR * buffer, SSHORT * buf_len) diff --git a/src/jrd/pio.h b/src/jrd/pio.h index 850897a9dd..24eb7d2d7f 100644 --- a/src/jrd/pio.h +++ b/src/jrd/pio.h @@ -24,10 +24,14 @@ #ifndef _JRD_PIO_H_ #define _JRD_PIO_H_ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + #ifdef UNIX -typedef struct fil { - struct blk fil_header; +class fil : public pool_alloc_rpt +{ + public: struct fil *fil_next; /* Next file in database */ ULONG fil_min_page; /* Minimum page number in file */ ULONG fil_max_page; /* Maximum page number in file */ @@ -39,15 +43,17 @@ typedef struct fil { MUTX_T fil_mutex[1]; USHORT fil_length; /* Length of expanded file name */ SCHAR fil_string[1]; /* Expanded file name */ -} *FIL; +}; +typedef fil *FIL; #endif #ifdef VMS -typedef struct fil { - struct blk fil_header; +class fil : public pool_alloc_rpt +{ + public: struct fil *fil_next; /* Next file in database */ ULONG fil_min_page; /* Minimum page number in file */ ULONG fil_max_page; /* Maximum page number in file */ @@ -61,14 +67,16 @@ typedef struct fil { USHORT fil_fid[3]; /* File id */ USHORT fil_did[3]; /* Directory id */ SCHAR fil_string[1]; /* Expanded file name */ -} *FIL; +}; +tyepdef fil *FIL; #endif #if (defined PC_PLATFORM) && !(defined NETWARE_386) -typedef struct fil { - struct blk fil_header; +class fil : public pool_alloc_rpt +{ + public: struct fil *fil_next; /* Next file in database */ ULONG fil_min_page; /* Minimum page number in file */ ULONG fil_max_page; /* Maximum page number in file */ @@ -80,15 +88,17 @@ typedef struct fil { MUTX_T fil_mutex[1]; USHORT fil_length; /* Length of expanded file name */ SCHAR fil_string[1]; /* Expanded file name */ -} *FIL; +}; +typedef fil *FIL; #endif #ifdef NETWARE_386 -typedef struct fil { - struct blk fil_header; +class fil : public pool_alloc_rpt +{ + public: struct fil *fil_next; /* Next file in database */ ULONG fil_min_page; /* Minimum page number in file */ ULONG fil_max_page; /* Maximum page number in file */ @@ -107,7 +117,8 @@ typedef struct fil { int dfs_last_block; int dfs_volume; SCHAR *dfs_buffer; -} *FIL; +}; +typedef fil *FIL; #endif @@ -116,8 +127,9 @@ typedef struct fil { #define MAX_FILE_IO 32 /* Maximum "allocated" overlapped I/O events */ #endif -typedef struct fil { - struct blk fil_header; +class fil : public pool_alloc_rpt +{ + public: struct fil *fil_next; /* Next file in database */ ULONG fil_min_page; /* Minimum page number in file */ ULONG fil_max_page; /* Maximum page number in file */ @@ -134,7 +146,8 @@ typedef struct fil { USHORT fil_flags; USHORT fil_length; /* Length of expanded file name */ SCHAR fil_string[1]; /* Expanded file name */ -} *FIL; +}; +typedef fil *FIL; #endif diff --git a/src/jrd/pwd.cpp b/src/jrd/pwd.cpp index 20e1f210c7..d2e1da6673 100644 --- a/src/jrd/pwd.cpp +++ b/src/jrd/pwd.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: pwd.cpp,v 1.3 2001-07-29 17:42:22 skywalker Exp $ +$Id: pwd.cpp,v 1.4 2001-12-24 02:50:52 tamlin Exp $ */ #include "firebird.h" @@ -322,7 +322,6 @@ static BOOLEAN open_user_db(isc_db_handle* uihandle, SLONG* status) TEXT user_info_name[MAX_PATH_LENGTH]; isc_db_handle uinfo; /* database handle */ IHNDL ihandle; - SCHAR* p; SCHAR* dpb; SCHAR dpb_buffer[256]; SSHORT dpb_len; diff --git a/src/jrd/pwd.h b/src/jrd/pwd.h index fa0d303a8d..bdb9622827 100644 --- a/src/jrd/pwd.h +++ b/src/jrd/pwd.h @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: pwd.h,v 1.2 2001-07-12 05:46:05 bellardo Exp $ +$Id: pwd.h,v 1.3 2001-12-24 02:50:52 tamlin Exp $ */ #ifndef _JRD_PWD_H_ diff --git a/src/jrd/pwd_proto.h b/src/jrd/pwd_proto.h index b9d481f93f..2beb570bc8 100644 --- a/src/jrd/pwd_proto.h +++ b/src/jrd/pwd_proto.h @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: pwd_proto.h,v 1.1.1.1 2001-05-23 13:26:23 tamlin Exp $ + * $Id: pwd_proto.h,v 1.2 2001-12-24 02:50:52 tamlin Exp $ */ #ifndef _JRD_PWD_PROTO_H_ diff --git a/src/jrd/qatest.cpp b/src/jrd/qatest.cpp index 5c8a2fefa3..3e781cba8a 100644 --- a/src/jrd/qatest.cpp +++ b/src/jrd/qatest.cpp @@ -227,7 +227,7 @@ int QATEST_entrypoint(ULONG * function, void *arg1, void *arg2, void *arg3) sprintf(filename, "Unknown QATEST_entrypoint #%lu", /* TXNN */ *function); THREAD_ENTER; - ERR_post(gds__random, + ERR_post(gds_random, gds_arg_string, ERR_cstring((TEXT *) filename), 0); THREAD_EXIT; return 0; diff --git a/src/jrd/rec.cpp b/src/jrd/rec.cpp index a3e58e1325..babfddb2a6 100644 --- a/src/jrd/rec.cpp +++ b/src/jrd/rec.cpp @@ -190,7 +190,7 @@ static void apply_data(DPG page, JRND * record) /* Process clumps */ - for (clump = NULL; clump = next_clump(record, clump);) { + for (clump = NULL; (clump = next_clump(record, clump));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, JRNP_SIZE); if (temp.jrnp_type != JRNP_DATA_SEGMENT) @@ -286,8 +286,8 @@ static void apply_header(HDR page, JRND * record) JRNDA temp1; for (clump = NULL; - clump = - (JRNDH *) next_clump(record, reinterpret_cast < jrnp * >(clump));) { + (clump = + (JRNDH *) next_clump(record, reinterpret_cast < jrnp * >(clump)));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, JRNDH_SIZE); if (temp.jrndh_type == JRNP_DB_HEADER) { @@ -339,8 +339,8 @@ static void apply_ids(PPG page, JRND * record) SLONG *ptr; for (clump = NULL; - clump = - (JRNG *) next_clump(record, reinterpret_cast < jrnp * >(clump));) { + (clump = + (JRNG *) next_clump(record, reinterpret_cast < jrnp * >(clump)));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, JRNG_SIZE); if (temp.jrng_type != JRNP_GENERATOR) @@ -371,8 +371,8 @@ static void apply_index(BTR page, JRND * record) BTN node, next; for (clump = NULL; - clump = - (JRNB *) next_clump(record, reinterpret_cast < jrnp * >(clump));) { + (clump = + (JRNB *) next_clump(record, reinterpret_cast < jrnp * >(clump)));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, JRNB_SIZE); switch (temp.jrnb_type) { @@ -386,7 +386,7 @@ static void apply_index(BTR page, JRND * record) delta = temp.jrnb_delta; p = (UCHAR *) page + page->btr_length; q = p + delta; - if (l = page->btr_length - temp.jrnb_offset) + if ( (l = page->btr_length - temp.jrnb_offset) ) do *--q = *--p; while (--l); @@ -396,7 +396,7 @@ static void apply_index(BTR page, JRND * record) p = (UCHAR *) page + temp.jrnb_offset; q = clump->jrnb_data; - if (l = temp.jrnb_length) + if ( (l = temp.jrnb_length) ) MOVE_FAST(q, p, l); page->btr_length += delta; @@ -411,7 +411,7 @@ static void apply_index(BTR page, JRND * record) p = (UCHAR *) page; q = (UCHAR *) clump->jrnb_data; - if (l = temp.jrnb_length) + if ( (l = temp.jrnb_length) ) MOVE_FAST(q, p, l); break; @@ -442,7 +442,7 @@ static void apply_index(BTR page, JRND * record) /* Compute length of rest of bucket and move it down. */ - if (l = page->btr_length - (q - (UCHAR *) page)) + if ( (l = page->btr_length - (q - (UCHAR *) page)) ) do *p++ = *q++; while (--l); @@ -479,8 +479,8 @@ static void apply_log(LIP page, JRND * record) JRNL temp, *clump; for (clump = NULL; - clump = - (JRNL *) next_clump(record, reinterpret_cast < jrnp * >(clump));) { + (clump = + (JRNL *) next_clump(record, reinterpret_cast < jrnp * >(clump)));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, JRNL_SIZE); page->log_flags = temp.jrnl_flags; @@ -508,8 +508,8 @@ static void apply_pip(PIP page, JRND * record) USHORT byte; for (clump = NULL; - clump = - (JRNA *) next_clump(record, reinterpret_cast < jrnp * >(clump));) { + (clump = + (JRNA *) next_clump(record, reinterpret_cast < jrnp * >(clump)));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, sizeof(struct jrna)); if (temp.jrna_type != JRNP_PIP) @@ -542,7 +542,7 @@ static void apply_pointer(PPG page, JRND * record) JRNP temp, *clump; SLONG longword; - for (clump = NULL; clump = next_clump(record, clump);) { + for (clump = NULL; (clump = next_clump(record, clump));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, JRNP_SIZE); if (temp.jrnp_type != JRNP_POINTER_SLOT) @@ -575,8 +575,8 @@ static void apply_root(IRT page, JRND * record) JRNRP temp, *clump; for (clump = NULL; - clump = - (JRNRP *) next_clump(record, reinterpret_cast < jrnp * >(clump));) { + (clump = + (JRNRP *) next_clump(record, reinterpret_cast < jrnp * >(clump)));) { MOVE_FAST((SCHAR *) clump, (SCHAR *) & temp, JRNRP_SIZE); if (temp.jrnrp_type != JRNP_ROOT_PAGE) @@ -1054,7 +1054,7 @@ USHORT activate_shadow, SLONG * timestamp, SLONG page_no, PAG page) else if (!WALRS_handle) ERR_post(gds_wal_failure, 0); - string = (STR) ALLOCPV(type_str, MAX_WALBUFLEN); + string = new(*dbb->dbb_permanent, MAX_WALBUFLEN) str(); wal_buff = (UCHAR *) string->str_data; while (TRUE) { @@ -1069,7 +1069,7 @@ USHORT activate_shadow, SLONG * timestamp, SLONG page_no, PAG page) else if (ret_val != SUCCESS) { WALR_close(tdbb->tdbb_status_vector, reinterpret_cast < walrs ** >(&WALRS_handle)); - ALL_release(reinterpret_cast < frb * >(string)); + delete string; ERR_punt(); } @@ -1107,5 +1107,5 @@ USHORT activate_shadow, SLONG * timestamp, SLONG page_no, PAG page) WALR_close(tdbb->tdbb_status_vector, reinterpret_cast < walrs ** >(&WALRS_handle)); - ALL_release(reinterpret_cast < frb * >(string)); + delete string; } diff --git a/src/jrd/req.h b/src/jrd/req.h index 43788a29d7..5aab743790 100644 --- a/src/jrd/req.h +++ b/src/jrd/req.h @@ -24,6 +24,11 @@ #ifndef _JRD_REQ_H_ #define _JRD_REQ_H_ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + +#include + /* record parameter block */ typedef struct rpb { @@ -99,8 +104,9 @@ typedef struct rpb { /* Record block (holds data, remember data?) */ -typedef struct rec { - struct blk rec_header; +class rec : public pool_alloc_rpt +{ + public: struct fmt *rec_format; /* what the data looks like */ struct lls *rec_precedence; /* stack of higher precedence pages */ USHORT rec_length; /* how much there is */ @@ -108,7 +114,8 @@ typedef struct rec { SLONG rec_number; /* original rpb number - used for undoing multiple updates */ double rec_dummy; /* this is to force next field to a double boundary */ UCHAR rec_data[1]; /* THIS VARIABLE MUST BE ALIGNED ON A DOUBLE BOUNDARY */ -} *REC; +}; +typedef rec *REC; #define REC_same_tx 1 /* record inserted/updated and deleted by same tx */ #define REC_gc_active 2 /* relation garbage collect record block in use */ @@ -116,34 +123,37 @@ typedef struct rec { /* save rpb block */ -typedef struct srpb { - struct blk srpb_header; +class srpb : public pool_alloc +{ + public: struct rpb srpb_rpb[1]; /* record parameter blocks */ -} *SRPB; +}; +typedef srpb *SRPB; /* request block */ -typedef struct req { - struct blk req_header; - ATT req_attachment; /* database attachment */ - USHORT req_count; /* number of streams */ - USHORT req_incarnation; /* incarnation number */ - ULONG req_impure_size; /* size of impure area */ - struct plb *req_pool; - struct vec *req_sub_requests; /* vector of sub-requests */ - struct tra *req_transaction; - struct req *req_request; /* next request in dbb */ - struct acc *req_access; /* Access items to be checked */ - struct vec *req_variables; /* Vector of variables, if any */ - struct rsc *req_resources; /* Resources (relations and indices) */ - struct nod *req_message; /* Current message for send/receive */ +class req : public pool_alloc_rpt +{ +public: + ATT req_attachment; // database attachment + USHORT req_count; // number of streams + USHORT req_incarnation; // incarnation number + ULONG req_impure_size; // size of impure area + JrdMemoryPool* req_pool; + struct vec* req_sub_requests; // vector of sub-requests + struct tra* req_transaction; + req* req_request; /* next request in dbb */ + struct acc* req_access; /* Access items to be checked */ + struct vec* req_variables; /* Vector of variables, if any */ + class Rsc* req_resources; /* Resources (relations and indices) */ + struct nod* req_message; /* Current message for send/receive */ #ifdef SCROLLABLE_CURSORS struct nod *req_async_message; /* Asynchronous message (used in scrolling) */ #endif - struct vec *req_refresh_ranges; /* Vector of refresh_ranges */ - struct rng *req_begin_ranges; /* Vector of refresh_ranges */ - struct prc *req_procedure; /* procedure, if any */ - TEXT *req_trg_name; /* name of request (trigger), if any */ + struct vec* req_refresh_ranges; /* Vector of refresh_ranges */ + struct rng* req_begin_ranges; /* Vector of refresh_ranges */ + struct prc* req_procedure; /* procedure, if any */ + TEXT* req_trg_name; /* name of request (trigger), if any */ USHORT req_length; /* message length for send/receive */ USHORT req_nmsgs; /* number of message types */ USHORT req_mmsg; /* highest message type */ @@ -155,10 +165,10 @@ typedef struct req { ULONG req_records_updated; /* count of records updated by request */ ULONG req_records_deleted; /* count of records deleted by request */ - struct nod *req_top_node; /* top of execution tree */ - struct nod *req_next; /* next node for execution */ - struct vec *req_fors; /* Vector of for loops, if any */ - struct vec *req_invariants; /* Vector of invariant nodes, if any */ + struct nod* req_top_node; /* top of execution tree */ + struct nod* req_next; /* next node for execution */ + struct vec* req_fors; /* Vector of for loops, if any */ + struct vec* req_invariants; /* Vector of invariant nodes, if any */ USHORT req_label; /* label for leave */ ULONG req_flags; /* misc request flags */ struct sav *req_proc_sav_point; /* procedure savepoint list */ @@ -166,10 +176,17 @@ typedef struct req { ENUM req_s { req_evaluate, - req_return, req_receive, req_send, req_proceed, req_sync, req_unwind} req_operation; /* operation for next node */ + req_return, + req_receive, + req_send, + req_proceed, + req_sync, + req_unwind + } req_operation; /* operation for next node */ - struct rpb req_rpb[1]; /* record parameter blocks */ -} *REQ; + rpb req_rpb[1]; /* record parameter blocks */ +}; +typedef req *REQ; #define REQ_SIZE (sizeof (struct req) - sizeof (((REQ) 0)->req_rpb[0])) @@ -226,33 +243,36 @@ enum rsc_s { rsc_index }; -typedef struct rsc { - struct blk rsc_header; - struct rsc *rsc_next; /* Next resource in request */ +class Rsc : public pool_alloc +{ + public: + class Rsc *rsc_next; /* Next resource in request */ struct rel *rsc_rel; /* Relation block */ struct prc *rsc_prc; /* Relation block */ USHORT rsc_id; /* Id of parent */ enum rsc_s rsc_type; -} *RSC; +}; +typedef Rsc *RSC; /* Index lock block */ -typedef struct idl +class idl : public pool_alloc { - struct blk idl_header; + public: struct idl* idl_next; /* Next index lock block for relation */ struct lck* idl_lock; /* Lock block */ struct rel* idl_relation; /* Parent relation */ USHORT idl_id; /* Index id */ USHORT idl_count; /* Use count */ -} *IDL; +}; +typedef idl *IDL; /* Access items */ -typedef struct acc +class acc : public pool_alloc { - struct blk acc_header; + public: struct acc* acc_next; #ifndef GATEWAY TEXT* acc_security_name; /* WRITTEN into by SCL_get_class() */ @@ -265,6 +285,7 @@ typedef struct acc CONST TEXT* acc_name; CONST TEXT* acc_type; USHORT acc_mask; -} *ACC; +}; +typedef acc *ACC; #endif /* _JRD_REQ_H_ */ diff --git a/src/jrd/rlck.cpp b/src/jrd/rlck.cpp index db4ea820a8..f1eca41c4d 100644 --- a/src/jrd/rlck.cpp +++ b/src/jrd/rlck.cpp @@ -41,7 +41,7 @@ #include "../jrd/vio_proto.h" static LCK allocate_record_lock(TRA, RPB *); -static LCK allocate_relation_lock(PLB, REL); +static LCK allocate_relation_lock(MemoryPool*, REL); static LCK attachment_relation_lock(REL); static void drop_record_lock(LCK); static LCK find_record_lock(RPB *); @@ -300,7 +300,7 @@ LCK RLCK_record_locking(REL relation) tdbb = GET_THREAD_DATA; dbb = GET_DBB; - lock = (LCK) ALLOCPV(type_lck, sizeof(SLONG)); + lock = new(*dbb->dbb_permanent, sizeof(SLONG)) lck(); lock->lck_parent = dbb->dbb_lock; lock->lck_dbb = dbb; lock->lck_attachment = tdbb->tdbb_attachment; @@ -377,20 +377,19 @@ void RLCK_release_locks(ATT attachment) * **************************************/ VEC vector; - LCK lock, *lptr, *lend; + LCK lock; + vec::iterator *lptr, *lend; /* unlock all explicit relation locks */ if (vector = attachment->att_relation_locks) - for (lptr = (LCK *) vector->vec_object, lend = - lptr + vector->vec_count; lptr < lend; lptr++) - if (lock = *lptr) + for (lptr = vector->begin(), lend = vector->end(); lptr < lend; lptr++) + if (lock = ((LCK)(*lptr)) ) RLCK_unlock_relation(0, (REL) lock->lck_object); /* unlock all explicit record locks */ while (lock = attachment->att_record_locks) RLCK_unlock_record(lock, 0); /* clear the vector of user locks */ if (vector = attachment->att_lck_quick_ref) - for (lptr = (LCK *) vector->vec_object, lend = - lptr + vector->vec_count; lptr < lend; lptr++) + for (lptr = vector->begin(), lend = vector->end(); lptr < lend; lptr++) *lptr = NULL; } #endif @@ -470,20 +469,25 @@ void RLCK_shutdown_attachment(ATT attachment) * and relation locks. This runs at AST level. * **************************************/ - VEC lock_vector; - LCK *lock, record_lock; - USHORT i; - TDBB tdbb; - tdbb = GET_THREAD_DATA; + + vec::iterator lock; + + TDBB tdbb = GET_THREAD_DATA; /* Release child record locks before parent relation locks */ - for (record_lock = attachment->att_record_locks; record_lock; - record_lock = record_lock->lck_att_next) + for (LCK record_lock = attachment->att_record_locks; + record_lock; + record_lock = record_lock->lck_att_next) + { LCK_release(tdbb, record_lock); - if (lock_vector = attachment->att_relation_locks) - for (i = 0, lock = (LCK *) - lock_vector->vec_object; i < lock_vector->vec_count; i++, lock++) - if (*lock) - LCK_release(tdbb, *lock); + } + VEC lock_vector = attachment->att_relation_locks; + if (lock_vector) { + for (lock = lock_vector->begin(); lock != lock_vector->end(); ++lock) { + if (*lock) { + LCK_release(tdbb, (LCK)(*lock)); + } + } + } } @@ -501,15 +505,15 @@ void RLCK_shutdown_database(DBB dbb) * at AST level. * **************************************/ - REL relation, *ptr, *end; + REL relation; + vec::iterator ptr, end; VEC vector; TDBB tdbb; tdbb = GET_THREAD_DATA; if (!(vector = dbb->dbb_relations)) return; - for (ptr = (REL *) vector->vec_object, end = - ptr + vector->vec_count; ptr < end; ptr++) - if (relation = *ptr) { + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) + if ( (relation = ((REL)(*ptr)) ) ) { if (relation->rel_record_locking) LCK_release(tdbb, relation->rel_record_locking); if (relation->rel_interest_lock) @@ -551,7 +555,7 @@ void RLCK_signal_refresh(TRA transaction) /* allocate a local lock */ - local_lock = (LCK) ALLOCPV(type_lck, sizeof(SLONG)); + local_lock = new(*dbb->dbb_permanent, sizeof(SLONG)) lck(); local_lock->lck_dbb = dbb; local_lock->lck_attachment = tdbb->tdbb_attachment; local_lock->lck_length = sizeof(SLONG); @@ -560,8 +564,8 @@ void RLCK_signal_refresh(TRA transaction) LCK_get_owner_handle(tdbb, local_lock->lck_type); local_lock->lck_parent = dbb->dbb_lock; local_lock->lck_compatible = (BLK) tdbb->tdbb_attachment; - for (i = 0; i < vector->vec_count; i++) { - lock = (LCK *) (vector->vec_object[i]); + for (i = 0; i < vector->count(); i++) { + lock = (LCK *) ((*vector)[i]); if (lock) { relation = (REL) lock->lck_object; local_lock->lck_key.lck_long = relation->rel_id; @@ -592,13 +596,17 @@ LCK RLCK_transaction_relation_lock(TRA transaction, REL relation) LCK lock; VEC vector; if ((vector = transaction->tra_relation_locks) && - (relation->rel_id < vector->vec_count) && - (lock = (LCK) vector->vec_object[relation->rel_id])) + (relation->rel_id < vector->count()) && + (lock = (LCK) (*vector)[relation->rel_id])) return lock; - vector = - ALL_vector(transaction->tra_pool, - &transaction->tra_relation_locks, relation->rel_id); - if (lock = (LCK) vector->vec_object[relation->rel_id]) + if (!vector) + vector = transaction->tra_relation_locks = + vec::newVector(*transaction->tra_pool, relation->rel_id + 1); + + if (vector->count() < (relation->rel_id + 1) ) + vector->resize(relation->rel_id + 1); + + if ( (lock = (LCK) (*vector)[relation->rel_id]) ) return lock; lock = allocate_relation_lock(transaction->tra_pool, relation); lock->lck_owner = (BLK) transaction; @@ -607,7 +615,7 @@ LCK RLCK_transaction_relation_lock(TRA transaction, REL relation) that relation locks are incompatible with locks taken out by other transactions, if a transaction is specified */ lock->lck_compatible2 = (BLK) transaction; - vector->vec_object[relation->rel_id] = (BLK) lock; + (*vector)[relation->rel_id] = (BLK) lock; return lock; } @@ -738,13 +746,13 @@ void RLCK_unlock_relation(LCK lock, REL relation) return; if (relation) { id = relation->rel_id; - if (id >= vector->vec_count) + if (id >= vector->count()) return; - lock = (LCK) vector->vec_object[id]; + lock = (LCK) (*vector)[id]; } else - for (id = 0; id < vector->vec_count; id++) - if (lock == (LCK) vector->vec_object[id]) + for (id = 0; id < vector->count(); id++) + if (lock == (LCK) (*vector)[id]) break; if (!lock) return; @@ -758,7 +766,7 @@ void RLCK_unlock_relation(LCK lock, REL relation) LCK_release(tdbb, lock); ALL_release(lock); - vector->vec_object[id] = NULL; + (*vector)[id] = NULL; } #endif @@ -789,7 +797,7 @@ static LCK allocate_record_lock(TRA transaction, RPB * rpb) if (!rpb->rpb_record) ERR_post(gds_no_cur_rec, 0); /* allocate a lock block for the record lock */ - lock = (LCK) ALLOCPV(type_lck, sizeof(SLONG)); + lock = new(*dbb->dbb_permanent, sizeof(SLONG)) lck(); lock->lck_dbb = dbb; lock->lck_attachment = attachment; lock->lck_object = (BLK) dbb; @@ -825,7 +833,7 @@ static LCK allocate_record_lock(TRA transaction, RPB * rpb) #endif -static LCK allocate_relation_lock(PLB pool, REL relation) +static LCK allocate_relation_lock(MemoryPool* pool, REL relation) { /************************************** * @@ -842,7 +850,7 @@ static LCK allocate_relation_lock(PLB pool, REL relation) LCK lock; tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; - lock = (LCK) ALL_alloc(pool, type_lck, sizeof(SLONG), ERR_jmp); + lock = new(*pool, sizeof(SLONG)) lck(); lock->lck_dbb = dbb; lock->lck_attachment = tdbb->tdbb_attachment; lock->lck_length = sizeof(SLONG); @@ -882,17 +890,24 @@ static LCK attachment_relation_lock(REL relation) dbb = tdbb->tdbb_database; attachment = tdbb->tdbb_attachment; if ((vector = attachment->att_relation_locks) && - (relation->rel_id < vector->vec_count) && - (lock = (LCK) vector->vec_object[relation->rel_id])) + (relation->rel_id < vector->count()) && + (lock = (LCK) (*vector)[relation->rel_id])) return lock; - vector = - ALL_vector(dbb->dbb_permanent, &attachment->att_relation_locks, - relation->rel_id); - if (lock = (LCK) vector->vec_object[relation->rel_id]) + vector = attachment->att_relation_locks; + if (!vector) + { + vector = attachment->att_relation_locks = + vec::newVector(*dbb->dbb_permanent, relation->rel_id + 1); + } + if (relation->rel_id >= vector->count()) + { + vector->resize(relation->rel_id + 1); + } + if ( (lock = (LCK) (*vector)[relation->rel_id]) ) return lock; lock = allocate_relation_lock(dbb->dbb_permanent, relation); lock->lck_owner = (BLK) attachment; - vector->vec_object[relation->rel_id] = (BLK) lock; + (*vector)[relation->rel_id] = (BLK) lock; return lock; } diff --git a/src/jrd/rng.cpp b/src/jrd/rng.cpp index e2324d0ed1..7b41de0b58 100644 --- a/src/jrd/rng.cpp +++ b/src/jrd/rng.cpp @@ -424,7 +424,7 @@ DSC *RNG_begin(NOD node, VLU impure) /* allocate the range block and move the event name into it */ - refresh_range = (RNG) ALLOCDV(type_rng, p - event_name + 1); + refresh_range = new(*tdbb->tdbb_default, p - event_name + 1) rng(); refresh_range->rng_event_length = p - event_name; strcpy(refresh_range->rng_event, event_name); diff --git a/src/jrd/rng.h b/src/jrd/rng.h index 0709c73656..0369a92ab8 100644 --- a/src/jrd/rng.h +++ b/src/jrd/rng.h @@ -27,8 +27,9 @@ /* refresh range block used to store info about a particular set of records in a refresh range */ -typedef struct rng { - struct blk rng_header; +class rng : public pool_alloc_rpt +{ + public: struct rng *rng_next; /* next in list of ranges being created */ struct att *rng_attachment; /* attachment that owns range */ struct rng *rng_lck_next; /* next in list of ranges interested in a lock */ @@ -45,7 +46,8 @@ typedef struct rng { USHORT rng_flags; /* see flags below */ USHORT rng_event_length; /* length of event name */ UCHAR rng_event[1]; /* event name to post */ -} *RNG; +}; +typedef rng *RNG; #define RNG_posted 1 /* range has already been posted */ diff --git a/src/jrd/rse.cpp b/src/jrd/rse.cpp index 756a4fe692..6e22adbcc3 100644 --- a/src/jrd/rse.cpp +++ b/src/jrd/rse.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: rse.cpp,v 1.3 2001-07-29 17:42:22 skywalker Exp $ +$Id: rse.cpp,v 1.4 2001-12-24 02:50:52 tamlin Exp $ */ #include "firebird.h" @@ -492,7 +492,7 @@ BOOLEAN RSE_get_record(TDBB tdbb, RSB rsb, RSE_GET_MODE mode) count = (request->req_flags & req_count_records) != 0; request->req_flags &= ~req_count_records; - if (result = get_record(tdbb, rsb, NULL, mode)) + if ( (result = get_record(tdbb, rsb, NULL, mode)) ) if (count) request->req_records_selected++; @@ -602,11 +602,11 @@ void RSE_mark_crack(TDBB tdbb, RSB rsb, USHORT flags) if (flags) { rpb = &request->req_rpb[rsb->rsb_stream]; if (rpb->rpb_record) { - ALL_release(rpb->rpb_record); + delete rpb->rpb_record; rpb->rpb_record = NULL; } if (rpb->rpb_copy) { - ALL_release(rpb->rpb_copy); + delete rpb->rpb_copy; rpb->rpb_copy = NULL; } } @@ -1004,17 +1004,17 @@ static void close_merge(TDBB tdbb, RSB rsb, IRSB_MRG impure) if one exists. */ mfb = &tail->irsb_mrg_file; - if (sfb = mfb->mfb_sfb) { + if ( (sfb = mfb->mfb_sfb) ) { if (sfb->sfb_file_name) { close(sfb->sfb_file); unlink(sfb->sfb_file_name); - ALL_free(sfb->sfb_file_name); + MemoryPool::free_from_system(sfb->sfb_file_name); } - ALL_free(reinterpret_cast < char *>(sfb)); + delete sfb; mfb->mfb_sfb = 0; } if (mfb->mfb_block_data) { - ALL_sys_free(reinterpret_cast < char *>(mfb->mfb_block_data)); + MemoryPool::free_from_system(mfb->mfb_block_data); mfb->mfb_block_data = 0; } } @@ -1040,7 +1040,7 @@ static void close_procedure(TDBB tdbb, RSB rsb) request = tdbb->tdbb_request; impure = (IRSB_PROCEDURE) ((UCHAR *) request + rsb->rsb_impure); - if (proc_request = impure->irsb_req_handle) { + if ( (proc_request = impure->irsb_req_handle) ) { /* bug #7884: at this point the transaction could already have been released, so null it out so as not to dereference it */ @@ -1052,7 +1052,7 @@ static void close_procedure(TDBB tdbb, RSB rsb) } if (impure->irsb_message) { - ALL_release((FRB) impure->irsb_message); + delete impure->irsb_message; impure->irsb_message = NULL; } } @@ -1092,7 +1092,7 @@ static SSHORT compare(TDBB tdbb, NOD node1, NOD node2) } else if (request->req_flags & req_null) return 1; - if (result = MOV_compare(desc1, desc2)) + if ( (result = MOV_compare(desc1, desc2)) ) return result; } @@ -1429,9 +1429,9 @@ static BOOLEAN fetch_left(TDBB tdbb, RSB rsb, IRSB impure) if (!get_record(tdbb, full, NULL, RSE_get_forward)) return FALSE; RSE_open(tdbb, rsb->rsb_arg[RSB_LEFT_outer]); - while (found = + while ( (found = get_record(tdbb, rsb->rsb_arg[RSB_LEFT_outer], NULL, - RSE_get_forward)) + RSE_get_forward)) ) if ( (!rsb->rsb_arg[RSB_LEFT_boolean] || EVL_boolean(tdbb, @@ -1777,7 +1777,7 @@ static BOOLEAN get_merge_join( mfb = &tail->irsb_mrg_file; key_length = map->smb_key_length * sizeof(ULONG); if (key_length > sizeof(key)) - first_data = (UCHAR *) ALL_malloc(key_length, ERR_jmp); + first_data = (UCHAR *) MemoryPool::malloc_from_system(key_length); else first_data = (UCHAR *) key; MOVE_FASTER(get_merge_data(tdbb, mfb, 0), first_data, key_length); @@ -1794,7 +1794,7 @@ static BOOLEAN get_merge_join( } if (first_data != (UCHAR *) key) - ALL_free(first_data); + MemoryPool::free_from_system(first_data); if (mfb->mfb_current_block) write_merge_block(tdbb, mfb, mfb->mfb_current_block); } @@ -1920,8 +1920,8 @@ static BOOLEAN get_merge_join(TDBB tdbb, RSB rsb, IRSB_MRG impure) for (ptr = rsb->rsb_arg, tail = impure->irsb_mrg_rpt; ptr < end; ptr += 2, tail++) if (highest_ptr != ptr) - while (result = - compare(tdbb, (NOD) highest_ptr[1], (NOD) ptr[1])) { + while ( (result = + compare(tdbb, (NOD) highest_ptr[1], (NOD) ptr[1])) ) { if (result < 0) { highest_ptr = ptr; goto recycle; @@ -1952,7 +1952,7 @@ static BOOLEAN get_merge_join(TDBB tdbb, RSB rsb, IRSB_MRG impure) mfb = &tail->irsb_mrg_file; key_length = map->smb_key_length * sizeof(ULONG); if (key_length > sizeof(key)) - first_data = (UCHAR *) ALL_malloc(key_length, ERR_jmp); + first_data = (UCHAR *) MemoryPool::malloc_from_system(key_length); else first_data = (UCHAR *) key; MOVE_FASTER(get_merge_data(tdbb, mfb, 0), first_data, key_length); @@ -1969,7 +1969,7 @@ static BOOLEAN get_merge_join(TDBB tdbb, RSB rsb, IRSB_MRG impure) } if (first_data != (UCHAR *) key) - ALL_free(reinterpret_cast < char *>(first_data)); + MemoryPool::free_from_system(first_data); if (mfb->mfb_current_block) write_merge_block(tdbb, mfb, mfb->mfb_current_block); } @@ -2112,7 +2112,7 @@ static BOOLEAN get_procedure(TDBB tdbb, if (!impure->irsb_message) { size = msg_format->fmt_length + ALIGNMENT; - impure->irsb_message = (STR) ALLOCDV(type_str, size); + impure->irsb_message = new(*tdbb->tdbb_default, size) str(); impure->irsb_message->str_length = size; } om = @@ -2122,7 +2122,7 @@ static BOOLEAN get_procedure(TDBB tdbb, if (!rpb->rpb_record) { record = rpb->rpb_record = - (REC) ALLOCDV(type_rec, rec_format->fmt_length); + new(*tdbb->tdbb_default, rec_format->fmt_length) rec(); record->rec_format = rec_format; record->rec_length = rec_format->fmt_length; } @@ -2265,7 +2265,7 @@ static BOOLEAN get_record(TDBB tdbb, SBM *bitmap; int result = FALSE; - if (bitmap = ((IRSB_INDEX) impure)->irsb_bitmap) + if ( (bitmap = ((IRSB_INDEX) impure)->irsb_bitmap) ) { while (SBM_next(*bitmap, &rpb->rpb_number, mode)) { @@ -2664,9 +2664,9 @@ static BOOLEAN get_record(TDBB tdbb, break; case rsb_aggregate: - if (impure->irsb_count = EVL_group(tdbb, (BLK) rsb->rsb_next, + if ( (impure->irsb_count = EVL_group(tdbb, (BLK) rsb->rsb_next, (NOD) rsb->rsb_arg[0], - impure->irsb_count)) break; + impure->irsb_count)) ) break; return FALSE; #ifndef GATEWAY @@ -2900,7 +2900,7 @@ static void map_sort_data(REQ request, SMB map, UCHAR * data) RPB *rpb; NOD node; REC record; - smb::smb_repeat * item, *end_item; + smb_repeat * item, *end_item; end_item = map->smb_rpt + map->smb_count; @@ -2993,7 +2993,7 @@ static void open_merge(TDBB tdbb, RSB rsb, IRSB_MRG impure) if (!mfb->mfb_block_data) mfb->mfb_block_data = reinterpret_cast < - UCHAR * >(ALL_sys_alloc(mfb->mfb_block_size, ERR_jmp)); + UCHAR * >(MemoryPool::malloc_from_system(mfb->mfb_block_size)); } } @@ -3028,7 +3028,7 @@ static void open_procedure(TDBB tdbb, RSB rsb, IRSB_PROCEDURE impure) rpb = request->req_rpb + rsb->rsb_stream; if (rpb->rpb_record) { - ALL_release((FRB) rpb->rpb_record); + delete rpb->rpb_record; rpb->rpb_record = NULL; } @@ -3085,7 +3085,7 @@ static void open_sort(TDBB tdbb, RSB rsb, IRSB_SORT impure) int records; SSHORT stream; SCB handle; - smb::smb_repeat * item, *end_item; + smb_repeat * item, *end_item; SET_TDBB(tdbb); request = tdbb->tdbb_request; @@ -3326,7 +3326,7 @@ static void pop_rpbs(REQ request, RSB rsb) { SSHORT i, streams[128]; SMB map; - smb::smb_repeat * item, *end_item; + smb_repeat * item, *end_item; map = (SMB) rsb->rsb_arg[0]; for (i = 0; i < (SSHORT) request->req_count; i++) @@ -3347,7 +3347,7 @@ static void pop_rpbs(REQ request, RSB rsb) SSHORT i, streams[128]; SMB map; RSB sort_rsb, *ptr, *end; - smb::smb_repeat * item, *end_item; + smb_repeat * item, *end_item; irsb_mrg::irsb_mrg_repeat * tail; for (i = 0; i < (SSHORT) request->req_count; i++) @@ -3439,7 +3439,7 @@ static void push_rpbs(TDBB tdbb, REQ request, RSB rsb) { SSHORT i, streams[128]; SMB map; - smb::smb_repeat * item, *end_item; + smb_repeat * item, *end_item; map = (SMB) rsb->rsb_arg[0]; for (i = 0; i < (SSHORT) request->req_count; i++) @@ -3460,7 +3460,7 @@ static void push_rpbs(TDBB tdbb, REQ request, RSB rsb) SSHORT i, streams[128]; SMB map; RSB sort_rsb, *ptr, *end; - smb::smb_repeat * item, *end_item; + smb_repeat * item, *end_item; irsb_mrg::irsb_mrg_repeat * tail; for (i = 0; i < (SSHORT) request->req_count; i++) @@ -3589,10 +3589,10 @@ static void restore_record(RPB * rpb) MOVE_FAST(rpb_copy->srpb_rpb, rpb, sizeof(struct rpb)); rpb->rpb_record = record; - ALL_release((FRB) rec_copy); + delete rec_copy; } if (rpb_copy) - ALL_release((FRB) rpb_copy); + delete rpb_copy; rpb->rpb_copy = NULL; } @@ -3680,18 +3680,18 @@ static void save_record(TDBB tdbb, RPB * rpb) SET_TDBB(tdbb); - if (record = rpb->rpb_record) { + if ( (record = rpb->rpb_record) ) { size = record->rec_length; - if (rpb_copy = rpb->rpb_copy) { - if (rec_copy = rpb_copy->srpb_rpb->rpb_record) - ALL_release((FRB) rec_copy); + if ( (rpb_copy = rpb->rpb_copy) ) { + if ( (rec_copy = rpb_copy->srpb_rpb->rpb_record) ) + delete rec_copy; } else - rpb->rpb_copy = rpb_copy = (SRPB) ALLOCDV(type_srpb, 0); + rpb->rpb_copy = rpb_copy = new(*tdbb->tdbb_default) srpb(); MOVE_FAST(rpb, rpb_copy->srpb_rpb, sizeof(struct rpb)); rpb_copy->srpb_rpb->rpb_record = rec_copy = - (REC) ALLOCDV(type_rec, size); + new(*tdbb->tdbb_default, size) rec(); rec_copy->rec_length = size; rec_copy->rec_format = record->rec_format; @@ -3743,27 +3743,25 @@ static void write_merge_block(TDBB tdbb, MFB mfb, ULONG block) * the file doesn't exist, by all means, create one. * **************************************/ - SFB sfb; + SFB sfb_; - if (!(sfb = mfb->mfb_sfb)) { - sfb = mfb->mfb_sfb = - (SFB) ALL_malloc((ULONG) sizeof(struct sfb), ERR_jmp); - MOVE_CLEAR(sfb, sizeof(struct sfb)); + if (!(sfb_ = mfb->mfb_sfb)) { + sfb_ = mfb->mfb_sfb = new(*FB_MemoryPool) sfb; } - if (!sfb->sfb_file_name) { + if (!sfb_->sfb_file_name) { TEXT file_name[128]; - sfb->sfb_file = (int) gds__temp_file(FALSE, SCRATCH, file_name); - if (sfb->sfb_file == -1) - SORT_error(tdbb->tdbb_status_vector, sfb, "open", isc_io_error, + sfb_->sfb_file = (int) gds__temp_file(FALSE, SCRATCH, file_name); + if (sfb_->sfb_file == -1) + SORT_error(tdbb->tdbb_status_vector, sfb_, "open", isc_io_error, errno); - sfb->sfb_file_name = - ALL_malloc((ULONG) (strlen(file_name) + 1), ERR_jmp); - strcpy(sfb->sfb_file_name, file_name); + sfb_->sfb_file_name = (SCHAR*) + MemoryPool::malloc_from_system((ULONG) (strlen(file_name) + 1)); + strcpy(sfb_->sfb_file_name, file_name); } SORT_write_block(tdbb->tdbb_status_vector, - sfb, + sfb_, mfb->mfb_block_size * block, mfb->mfb_block_data, mfb->mfb_block_size); } diff --git a/src/jrd/rse.h b/src/jrd/rse.h index 93ac70f7f0..46e5517b7c 100644 --- a/src/jrd/rse.h +++ b/src/jrd/rse.h @@ -24,6 +24,11 @@ #ifndef _JRD_RSE_H_ #define _JRD_RSE_H_ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + +#include + #include "../jrd/dsc.h" /* Record Source Block (RSB) types */ @@ -44,8 +49,9 @@ rsb_once /* (Gateway only) */ } RSB_T; /* Record Source Block */ -typedef struct rsb { - struct blk rsb_header; +class Rsb : public pool_alloc_rpt +{ + public: RSB_T rsb_type; /* type of rsb */ UCHAR rsb_stream; /* stream, if appropriate */ USHORT rsb_count; /* number of sub arguments */ @@ -53,14 +59,15 @@ typedef struct rsb { ULONG rsb_impure; /* offset to impure area */ ULONG rsb_cardinality; /* estimated cardinality of stream */ ULONG rsb_record_count; /* count of records returned from rsb (not candidate records processed) */ - struct rsb *rsb_next; /* next rsb, if appropriate */ + struct Rsb *rsb_next; /* next rsb, if appropriate */ struct rel *rsb_relation; /* relation, if appropriate */ struct str *rsb_alias; /* SQL alias for relation */ struct prc *rsb_procedure; /* procedure, if appropriate */ struct fmt *rsb_format; /* format, if appropriate */ struct nod *rsb_any_boolean; /* any/all boolean */ - struct rsb *rsb_arg[1]; -} *RSB; + Rsb* rsb_arg[1]; +}; +typedef Rsb *RSB; /* bits for the rsb_flags field */ @@ -203,23 +210,26 @@ typedef struct irsb_nav { /* Sort map block */ - -typedef struct smb { - struct blk smb_header; - USHORT smb_keys; /* Number of keys */ - USHORT smb_count; /* Total number of fields */ - USHORT smb_length; /* Sort record length */ - USHORT smb_key_length; /* Key length in longwords */ - struct skd *smb_key_desc; /* Address of key descriptors */ - USHORT smb_flags; /* Misc sort flags */ struct smb_repeat { DSC smb_desc; /* Relative descriptor */ USHORT smb_flag_offset; /* Offset of missing flag */ USHORT smb_stream; /* Stream for field id */ SSHORT smb_field_id; /* Id for field (-1 if dbkey) */ struct nod *smb_node; /* Expression node */ - } smb_rpt[1]; -} *SMB; + }; + +class smb : public pool_alloc_rpt +{ +public: + USHORT smb_keys; /* Number of keys */ + USHORT smb_count; /* Total number of fields */ + USHORT smb_length; /* Sort record length */ + USHORT smb_key_length; /* Key length in longwords */ + struct skd *smb_key_desc; /* Address of key descriptors */ + USHORT smb_flags; /* Misc sort flags */ + smb_repeat smb_rpt[1]; +}; +typedef smb *SMB; /* values for smb_field_id */ @@ -236,12 +246,14 @@ typedef struct smb { Indexed relationships block (IRL) holds information about potential join orders */ -typedef struct irl { - struct blk irl_header; +class irl : public pool_alloc +{ + public: struct irl *irl_next; /* Next irl block for stream */ USHORT irl_stream; /* Stream reachable by relation */ USHORT irl_unique; /* Is this stream reachable by unique index? */ -} *IRL; +}; +typedef irl *IRL; /* Types of simulated joins (Gateway only) */ @@ -252,12 +264,14 @@ typedef struct irl { /* Simulated relationships block holds information about potential joins (Gateway only) */ -typedef struct srl { - struct blk srl_header; +class srl : public pool_alloc +{ + public: struct srl *srl_next; /* Next srl block for stream */ USHORT srl_stream; /* Stream reachable by join */ USHORT srl_type; /* Simulated join type */ -} *SRL; +}; +typedef srl *SRL; /* the maximum number of opt items is the maximum @@ -272,10 +286,10 @@ typedef struct srl { #define OPT_BITS (MAX_OPT_ITEMS/32) /* General optimizer block */ - -typedef struct opt { - struct blk opt_header; - struct csb *opt_csb; /* Compiler scratch block */ +class Opt : public pool_alloc +{ + public: + class Csb *opt_csb; /* Compiler scratch block */ SLONG opt_combinations; /* Number of partial orders considered */ double opt_best_cost; /* Cost of best join order */ SSHORT opt_count; /* Number of conjuncts */ @@ -298,8 +312,11 @@ typedef struct opt { USHORT opt_best_stream; /* stream in best join order seen so far */ USHORT opt_flags; USHORT opt_stream; /* Stream in position of join order */ - } opt_rpt[MAX_OPT_ITEMS]; -} *OPT; + }; + + struct opt_repeat opt_rpt[MAX_OPT_ITEMS]; +}; +typedef Opt *OPT; /* stream-dependent bits used in opt_flags */ @@ -314,21 +331,24 @@ typedef struct opt { /* River block -- used to hold temporary information about a group of streams */ -typedef struct riv { - struct blk riv_header; - struct rsb *riv_rsb; /* Record source block for river */ +class riv : public pool_alloc_rpt +{ + public: + struct Rsb *riv_rsb; /* Record source block for river */ USHORT riv_number; /* Temporary number for river */ UCHAR riv_count; /* Count of streams */ UCHAR riv_streams[1]; /* Actual streams */ -} *RIV; +}; +typedef riv *RIV; /* bookmark block, used to hold information about the current position within an index; a pointer to this block is passed to the user as a handle to facilitate returning to this position */ -typedef struct bkm { - struct blk bkm_header; +class bkm : public pool_alloc_rpt +{ + public: struct bkm *bkm_next; struct dsc bkm_desc; /* bookmark descriptor describing the bookmark handle */ ULONG bkm_handle; /* bookmark handle containing pointer to this block */ @@ -340,7 +360,8 @@ typedef struct bkm { USHORT bkm_flags; /* flag values indicated below */ struct dsc bkm_key_desc; /* descriptor containing current key value */ UCHAR bkm_key_data[1]; /* current key value */ -} *BKM; +}; +typedef bkm *BKM; #define bkm_bof 1 #define bkm_eof 2 diff --git a/src/jrd/rse_proto.h b/src/jrd/rse_proto.h index b44699d4b1..5abe7bd54f 100644 --- a/src/jrd/rse_proto.h +++ b/src/jrd/rse_proto.h @@ -27,21 +27,21 @@ #include "../jrd/jrd.h" #include "../jrd/rse.h" -extern void RSE_close(TDBB, register struct rsb *); +extern void RSE_close(TDBB, register class Rsb *); #ifdef PC_ENGINE -extern BOOLEAN RSE_find_dbkey(TDBB, struct rsb *, struct nod *, struct nod *); -extern BOOLEAN RSE_find_record(TDBB, struct rsb *, USHORT, USHORT, +extern BOOLEAN RSE_find_dbkey(TDBB, class Rsb *, struct nod *, struct nod *); +extern BOOLEAN RSE_find_record(TDBB, class Rsb *, USHORT, USHORT, struct nod *); #endif -extern BOOLEAN RSE_get_record(TDBB, struct rsb *, enum rse_get_mode); +extern BOOLEAN RSE_get_record(TDBB, class Rsb *, enum rse_get_mode); #ifdef PC_ENGINE -extern struct bkm *RSE_get_bookmark(TDBB, struct rsb *); -extern void RSE_mark_crack(TDBB, struct rsb *, USHORT); +extern struct bkm *RSE_get_bookmark(TDBB, class Rsb *); +extern void RSE_mark_crack(TDBB, class Rsb *, USHORT); #endif -extern void RSE_open(TDBB, register struct rsb *); +extern void RSE_open(TDBB, register class Rsb *); #ifdef PC_ENGINE -extern BOOLEAN RSE_reset_position(TDBB, struct rsb *, struct rpb *); -extern BOOLEAN RSE_set_bookmark(TDBB, struct rsb *, struct rpb *, +extern BOOLEAN RSE_reset_position(TDBB, class Rsb *, struct rpb *); +extern BOOLEAN RSE_set_bookmark(TDBB, class Rsb *, struct rpb *, struct bkm *); #endif diff --git a/src/jrd/sbm.cpp b/src/jrd/sbm.cpp index fe90a4b21a..c818315633 100644 --- a/src/jrd/sbm.cpp +++ b/src/jrd/sbm.cpp @@ -90,10 +90,11 @@ SBM *SBM_and(register SBM * bitmap1, register SBM * bitmap2) } if (map1->sbm_type == SBM_ROOT) { - SBM *bucket1, *bucket2, *end_buckets, *result_bucket, temp; + sbm::iterator bucket1, bucket2, end_buckets; + SBM *result_bucket, temp; - bucket1 = (SBM *) map1->sbm_segments; - bucket2 = (SBM *) map2->sbm_segments; + bucket1 = map1->sbm_segments.begin(); + bucket2 = map2->sbm_segments.begin(); end_buckets = bucket1 + map1->sbm_high_water + 1; for (; bucket1 < end_buckets; bucket1++, bucket2++) @@ -102,41 +103,42 @@ SBM *SBM_and(register SBM * bitmap1, register SBM * bitmap2) *bucket2 = *bucket1; *bucket1 = NULL; } - else if (!(result_bucket = SBM_and(bucket1, bucket2))) { - bucket_reset(*bucket1); + else if (!(result_bucket = + SBM_and((SBM*)bucket1, (SBM*)bucket2))) { + bucket_reset((SBM)*bucket1); *bucket1 = NULL; } - else if (result_bucket == bucket2) { - temp = *bucket2; + else if (result_bucket == (SBM*) bucket2) { + temp = (SBM)*bucket2; *bucket2 = *bucket1; - *bucket1 = temp; + *bucket1 = (BMS)temp; } } } else { - BMS *segment1, *segment2, *end_segments; - PLB pool; + sbm::iterator segment1, segment2, end_segments; + JrdMemoryPool *pool; register BUNCH *b1, *b2; SSHORT j; /* AND the bitmaps segment-wise. If each bucket has a segment is a given position, AND the segment bit-wise. */ - segment1 = map1->sbm_segments; - segment2 = map2->sbm_segments; + segment1 = map1->sbm_segments.begin(); + segment2 = map2->sbm_segments.begin(); end_segments = segment1 + map1->sbm_high_water + 1; for (; segment1 < end_segments; segment1++, segment2++) if (*segment1) { if (!*segment2) { - pool = (*segment1)->bms_pool; - (*segment1)->bms_next = pool->plb_segments; + pool = ((BMS)(*segment1))->bms_pool; + ((BMS)(*segment1))->bms_next = pool->plb_segments; pool->plb_segments = *segment1; *segment1 = NULL; continue; } - b1 = (*segment1)->bms_bits; - b2 = (*segment2)->bms_bits; + b1 = ((BMS)(*segment1))->bms_bits; + b2 = ((BMS)(*segment2))->bms_bits; for (j = 0; j < BUNCH_SEGMENT; j++) *b1++ &= *b2++; } @@ -261,16 +263,16 @@ void SBM_dump(IB_FILE * f, SBM bitmap1) continue; } if (in_range) - ib_fprintf(f, "-%d", last_bit); + ib_fprintf(f, "-%"SLONGFORMAT, last_bit); if ((++counter % 8) == 0) ib_fprintf(f, "\n"); - ib_fprintf(f, " %d", bit1); + ib_fprintf(f, " %"SLONGFORMAT, bit1); last_bit = bit1; in_range = FALSE; } if (in_range) - ib_fprintf(f, "-%d", last_bit); + ib_fprintf(f, "-%"SLONGFORMAT, last_bit); ib_fprintf(f, "\n"); } #endif @@ -340,7 +342,21 @@ void SBM_init(void) * **************************************/ - SBM_max_tail = ALL_tail(type_sbm); + /* JMB: + * There is no more ALL_tail function to call, so the following line: + * SBM_max_tail = plb::ALL_tail(type_sbm); + * gets removed. But what do we set SBM_max_tail to? We need to know + * how it it used. Here is the scoop: + * When extending a bitmap, if the needed capacity is less then SBM_max_tail + * we _double_ the current size until we have enough capacity. + * If the needed size is greator then SBM_max_tail we increase capacity + * to 5 more than needed, instead of doubling. + * + * The bottom line is SBM_max_tail is not a max, it is just a threashold + * the allocation scheme changes around. The FB1 value is kept for + * a lack of a better value. + */ + SBM_max_tail = ((MAX_USHORT - 32 - sizeof(sbm)) / sizeof(class bms*)) + 1; } @@ -427,7 +443,7 @@ int SBM_next(register SBM bitmap, SLONG * number, RSE_GET_MODE mode) /* recursively find the next bit set within this bucket */ - if (bucket = (SBM) bitmap->sbm_segments[slot]) { + if ( (bucket = (SBM) bitmap->sbm_segments[slot]) ) { if (SBM_next(bucket, &relative, mode)) { *number = ((SLONG) slot << BUCKET_BITS) + relative; return TRUE; @@ -466,7 +482,7 @@ int SBM_next(register SBM bitmap, SLONG * number, RSE_GET_MODE mode) register BMS segment; BUNCH test; SSHORT bit, bunch; - PLB pool; + JrdMemoryPool *pool; /* -1 signifies beginning of bucket in either direction, so adjust the actual number as appropriate */ @@ -505,9 +521,9 @@ int SBM_next(register SBM bitmap, SLONG * number, RSE_GET_MODE mode) if (mode == RSE_get_forward) { for (; slot <= (SLONG) bitmap->sbm_high_water; slot++, bunch = 0, bit = 0) { - if (segment = bitmap->sbm_segments[slot]) { + if ( (segment = bitmap->sbm_segments[slot]) ) { for (; bunch < BUNCH_SEGMENT; bunch++, bit = 0) - if (test = segment->bms_bits[bunch]) + if ( (test = segment->bms_bits[bunch]) ) for (; bit < BITS_BUNCH; bit++) if (test & (1 << bit)) { *number = ((SLONG) slot << SEGMENT_BITS) + @@ -537,9 +553,9 @@ int SBM_next(register SBM bitmap, SLONG * number, RSE_GET_MODE mode) else if (mode == RSE_get_backward) { for (; slot >= 0; slot--, bunch = BUNCH_SEGMENT - 1, bit = BITS_BUNCH - 1) - if (segment = bitmap->sbm_segments[slot]) + if ( (segment = bitmap->sbm_segments[slot]) ) for (; bunch >= 0; bunch--, bit = BITS_BUNCH - 1) - if (test = segment->bms_bits[bunch]) + if ( (test = segment->bms_bits[bunch]) ) for (; bit >= 0; bit--) if (test & (1 << bit)) { *number = ((SLONG) slot << SEGMENT_BITS) + @@ -628,8 +644,8 @@ SBM *SBM_or(register SBM * bitmap1, register SBM * bitmap2) SBM *bucket1, *bucket2, *end_buckets; SBM temp; - bucket1 = (SBM *) map1->sbm_segments; - bucket2 = (SBM *) map2->sbm_segments; + bucket1 = (SBM *) map1->sbm_segments.begin(); + bucket2 = (SBM *) map2->sbm_segments.begin(); end_buckets = bucket2 + map2->sbm_high_water + 1; for (; bucket2 < end_buckets; bucket1++, bucket2++) { @@ -647,14 +663,14 @@ SBM *SBM_or(register SBM * bitmap1, register SBM * bitmap2) } } else { - BMS *segment1, *segment2, *end_segments; + sbm::iterator segment1, segment2, end_segments; register BUNCH *b1, *b2; USHORT j; /* Both bitmaps exist. Form the bitwise union in the first bitmap */ - segment1 = map1->sbm_segments; - segment2 = map2->sbm_segments; + segment1 = map1->sbm_segments.begin(); + segment2 = map2->sbm_segments.begin(); end_segments = segment2 + map2->sbm_high_water + 1; for (; segment2 < end_segments; segment1++, segment2++) { @@ -665,8 +681,8 @@ SBM *SBM_or(register SBM * bitmap1, register SBM * bitmap2) *segment2 = NULL; continue; } - b1 = (*segment1)->bms_bits; - b2 = (*segment2)->bms_bits; + b1 = ((BMS)(*segment1))->bms_bits; + b2 = ((BMS)(*segment2))->bms_bits; for (j = 0; j < BUNCH_SEGMENT; j++) *b1++ |= *b2++; } @@ -693,7 +709,7 @@ void SBM_release(SBM bitmap) return; SBM_reset(&bitmap); - ALL_RELEASE(bitmap); + delete bitmap; } @@ -710,16 +726,16 @@ void SBM_reset(SBM * bitmap) * vector, just the segments. * **************************************/ - SBM *tail, vector, bucket; + sbm::iterator tail; + SBM vector, bucket; register USHORT i; - PLB pool; if (!(vector = *bitmap) || vector->sbm_state == SBM_EMPTY) return; - for (i = 0, tail = (SBM *) vector->sbm_segments; i < vector->sbm_count; + for (i = 0, tail = vector->sbm_segments.begin(); i < vector->sbm_count; i++, tail++) - if (bucket = *tail) { + if ( (bucket = (SBM)*tail) ) { bucket_reset(bucket); *tail = NULL; } @@ -748,7 +764,7 @@ void SBM_set(TDBB tdbb, SBM * bitmap, SLONG number) SET_TDBB(tdbb); if (!(vector = *bitmap)) { - *bitmap = vector = (SBM) ALLOCDV(type_sbm, 5); + *bitmap = vector = new(*tdbb->tdbb_default) sbm(*tdbb->tdbb_default, 5); vector->sbm_type = SBM_ROOT; vector->sbm_count = 5; vector->sbm_state = SBM_SINGULAR; @@ -782,17 +798,19 @@ void SBM_set(TDBB tdbb, SBM * bitmap, SLONG number) if (end > SBM_max_tail) end = SBM_max_tail; } - vector = (SBM) ALL_extend((BLK *) bitmap, end); + //vector = (SBM) plb::ALL_extend((BLK *) bitmap, end); + vector->sbm_segments.resize(end); vector->sbm_count = end; } /* Get bucket */ if (!(bucket = (SBM) vector->sbm_segments[slot])) { - if (bucket = tdbb->tdbb_default->plb_buckets) + if ( (bucket = tdbb->tdbb_default->plb_buckets) ) tdbb->tdbb_default->plb_buckets = bucket->sbm_next; else { - bucket = (SBM) ALLOCDV(type_sbm, BUNCH_BUCKET); + bucket = new(*tdbb->tdbb_default) + sbm(*tdbb->tdbb_default, BUNCH_BUCKET); bucket->sbm_pool = tdbb->tdbb_default; } clear_bucket(bucket); @@ -820,12 +838,12 @@ void SBM_set(TDBB tdbb, SBM * bitmap, SLONG number) /* Get segment */ if (!(segment = vector->sbm_segments[slot])) { - if (segment = tdbb->tdbb_default->plb_segments) { + if ( (segment = tdbb->tdbb_default->plb_segments) ) { tdbb->tdbb_default->plb_segments = segment->bms_next; clear_segment(segment); } else { - segment = (BMS) ALLOCD(type_bms); + segment = new(*tdbb->tdbb_default) bms(); segment->bms_pool = tdbb->tdbb_default; } vector->sbm_segments[slot] = segment; @@ -935,8 +953,10 @@ SLONG SBM_size(SBM * bitmap) * used for this sparce bitmap) * **************************************/ - SBM *tail, vector, bucket; - BMS *node, segment; + sbm::iterator tail; + SBM vector, bucket; + sbm::iterator node; + BMS segment; USHORT i, j; SLONG count; @@ -948,11 +968,11 @@ SLONG SBM_size(SBM * bitmap) return 1; /* only the the root sbm is allocated */ count = 1; /* one for the root sbm */ - for (i = 0, tail = (SBM *) vector->sbm_segments; i < vector->sbm_count; + for (i = 0, tail = vector->sbm_segments.begin(); i < vector->sbm_count; i++, tail++) { - bucket = *tail; + bucket = (SBM)*tail; if (bucket) { - for (j = 0, node = bucket->sbm_segments; + for (j = 0, node = bucket->sbm_segments.begin(); j < (USHORT) BUNCH_BUCKET; j++, node++) { segment = *node; if (segment) @@ -979,15 +999,17 @@ static void bucket_reset(register SBM bucket) * Reset a bucket and all its segments.. * **************************************/ - BMS *node, segment; + sbm::iterator node; + BMS segment; SSHORT i; - PLB pool; + JrdMemoryPool *pool; if (!bucket) return; - for (i = 0, node = bucket->sbm_segments; i < BUNCH_BUCKET; i++, node++) - if (segment = *node) { + for (i = 0, node = bucket->sbm_segments.begin(); + i < BUNCH_BUCKET; i++, node++) + if ( (segment = *node) ) { pool = segment->bms_pool; segment->bms_next = pool->plb_segments; pool->plb_segments = segment; @@ -1012,7 +1034,7 @@ static void clear_bucket(register SBM bucket) * Clear out a bit map bucket. * **************************************/ - register BMS *p; + sbm::iterator p; register SSHORT l; bucket->sbm_next = NULL; @@ -1022,7 +1044,7 @@ static void clear_bucket(register SBM bucket) bucket->sbm_used = 0; bucket->sbm_high_water = 0; bucket->sbm_number = 0; - p = bucket->sbm_segments; + p = bucket->sbm_segments.begin(); l = BUNCH_BUCKET; do { diff --git a/src/jrd/sbm.h b/src/jrd/sbm.h index 1505112512..f01797bfff 100644 --- a/src/jrd/sbm.h +++ b/src/jrd/sbm.h @@ -21,8 +21,12 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_SBM_H_ -#define _JRD_SBM_H_ +#ifndef JRD_SBM_H +#define JRD_SBM_H + +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" +#include "../include/fb_vector.h" #if (defined PC_PLATFORM && !defined NETWARE_386) #define BUNCH_BITS 4 @@ -33,27 +37,37 @@ #endif #define SEGMENT_BITS 10 -#define BITS_BUNCH (1 << BUNCH_BITS) +#define BITS_BUNCH (1 << BUNCH_BITS) #define BITS_SEGMENT (1 << SEGMENT_BITS) #define BUNCH_SEGMENT BITS_SEGMENT / BITS_BUNCH -#define BUCKET_BITS 15 +#define BUCKET_BITS 15 #define BUNCH_BUCKET (1 << (BUCKET_BITS - SEGMENT_BITS)) -/* Sparse bit map */ +// Sparse bit map -typedef struct sbm { - struct blk sbm_header; - struct sbm *sbm_next; - struct plb *sbm_pool; - UCHAR sbm_state; /* State of bitmap */ - UCHAR sbm_type; /* Root or bucket */ - USHORT sbm_count; /* Slots allocated */ - USHORT sbm_used; /* Slots used */ - USHORT sbm_high_water; /* Maximum slot used */ - SLONG sbm_number; /* Value when singular */ - struct bms *sbm_segments[1]; -} *SBM; +class sbm : public pool_alloc +{ + public: + sbm(MemoryPool& p, int len) + : sbm_segments(len, p, type_sbm) + { + } + + sbm* sbm_next; + JrdMemoryPool* sbm_pool; + UCHAR sbm_state; // State of bitmap + UCHAR sbm_type; // Root or bucket + USHORT sbm_count; // Slots allocated + USHORT sbm_used; // Slots used + USHORT sbm_high_water; // Maximum slot used + SLONG sbm_number; // Value when singular + typedef Firebird::vector vector_type; + typedef vector_type::iterator iterator; + + vector_type sbm_segments; +}; +typedef sbm* SBM; /* States */ @@ -68,13 +82,15 @@ typedef struct sbm { /* Bit map segment */ -typedef struct bms { - struct blk bms_header; - struct bms *bms_next; - struct plb *bms_pool; - SSHORT bms_min; /* Minimum bit set in segment */ - SSHORT bms_max; /* Maximum bit set in segment */ - BUNCH bms_bits[BUNCH_SEGMENT]; -} *BMS; +class bms : public pool_alloc +{ +public: + bms* bms_next; + JrdMemoryPool* bms_pool; + SSHORT bms_min; // Minimum bit set in segment + SSHORT bms_max; // Maximum bit set in segment + BUNCH bms_bits[BUNCH_SEGMENT]; +}; +typedef bms* BMS; -#endif /* _JRD_SBM_H_ */ +#endif // JRD_SBM_H diff --git a/src/jrd/scl.epp b/src/jrd/scl.epp index d9fb3bac1c..8c950d6bdd 100644 --- a/src/jrd/scl.epp +++ b/src/jrd/scl.epp @@ -21,6 +21,12 @@ * Contributor(s): ______________________________________. */ +// This MUST be at the top of the file +#ifdef DARWIN +#define _STLP_CCTYPE +#endif + + #include "firebird.h" #include #include @@ -51,6 +57,7 @@ #include "../jrd/grant_proto.h" #include "../jrd/scl_proto.h" #include "../jrd/thd_proto.h" +#include "../include/fb_exception.h" #ifdef VMS #define UIC_BASE 8 @@ -86,18 +93,18 @@ typedef struct { static CONST P_NAMES p_names[] = { - SCL_protect, priv_protect, "protect", - SCL_control, priv_control, "control", - SCL_delete, priv_delete, "delete", - SCL_sql_insert, priv_sql_insert, "insert/write", - SCL_sql_update, priv_sql_update, "update/write", - SCL_sql_delete, priv_sql_delete, "delete/write", - SCL_write, priv_write, "write", - SCL_read, priv_read, "read/select", - SCL_grant, priv_grant, "grant", - SCL_sql_references, priv_sql_references, "references", - SCL_execute, priv_execute, "execute", - 0, 0, "" + { SCL_protect, priv_protect, "protect" }, + { SCL_control, priv_control, "control" }, + { SCL_delete, priv_delete, "delete" }, + { SCL_sql_insert, priv_sql_insert, "insert/write" }, + { SCL_sql_update, priv_sql_update, "update/write" }, + { SCL_sql_delete, priv_sql_delete, "delete/write" }, + { SCL_write, priv_write, "write" }, + { SCL_read, priv_read, "read/select" }, + { SCL_grant, priv_grant, "grant" }, + { SCL_sql_references, priv_sql_references, "references" }, + { SCL_execute, priv_execute, "execute" }, + { 0, 0, "" } }; @@ -241,15 +248,10 @@ void SCL_check_index( TDBB tdbb, TEXT * index_name, USHORT mask) /* set up the setjmp mechanism, so that we can release the request in case of error in SCL_check_access */ + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR*) old_env; - if (request) - CMP_release(tdbb, (REQ) request); - LONGJMP(*(JMP_BUF*)&tdbb->tdbb_setjmp, (int) tdbb->tdbb_status_vector[1]); - } - /* check if the field used in the index has the appropriate permission. If the field in question does not have a security class @@ -279,6 +281,16 @@ void SCL_check_index( TDBB tdbb, TEXT * index_name, USHORT mask) CMP_release(tdbb, (REQ) request); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + tdbb->tdbb_setjmp = (UCHAR*) old_env; + if (request) { + CMP_release(tdbb, (REQ) request); + } +// LONGJMP(*(JMP_BUF*)&tdbb->tdbb_setjmp, (int) tdbb->tdbb_status_vector[1]); + Firebird::status_longjmp_error::raise(tdbb->tdbb_status_vector[1]); + } } @@ -446,10 +458,10 @@ SCL SCL_get_class(/* INOUT */ TEXT* string) /* Class isn't known. So make up a new security class block */ - s_class = (SCL) ALLOCPV(type_scl, p - name); + s_class = new(*dbb->dbb_permanent, p - name) scl(); p = name; q = s_class->scl_name; - while (*q++ = *p++) + while ( (*q++ = *p++) ) ; s_class->scl_flags = (USHORT) compute_access(tdbb, s_class, (REL)NULL_PTR, (TEXT*)NULL_PTR, (TEXT*)NULL_PTR); @@ -461,7 +473,7 @@ SCL SCL_get_class(/* INOUT */ TEXT* string) return s_class; } - ALL_release((FRB) s_class); + delete s_class; return NULL; } @@ -505,7 +517,7 @@ int SCL_get_mask(CONST TEXT* relation_name, CONST TEXT* field_name) (relation = MET_lookup_relation(tdbb, relation_name))) { MET_scan_relation(tdbb, relation); - if (s_class = SCL_get_class(relation->rel_security_name)) + if ( (s_class = SCL_get_class(relation->rel_security_name)) ) { access &= s_class->scl_flags; } @@ -627,7 +639,7 @@ void SCL_init(BOOLEAN create, { if (strlen(name) != 0) { - for (p = login_name, q = name; *p++ = UPPER7(*q); q++) + for (p = login_name, q = name; (*p++ = UPPER7(*q)); q++) { ; } @@ -665,7 +677,7 @@ void SCL_init(BOOLEAN create, length = strlen(name) + strlen(role_name) + strlen(project) + strlen(organization) + 4; /* for the terminating nulls */ - tdbb->tdbb_attachment->att_user = user = (USR) ALLOCPV(type_usr, length); + tdbb->tdbb_attachment->att_user = user = new(*dbb->dbb_permanent, length) usr(); p = user->usr_data; user->usr_user_name = save_string(name, &p); user->usr_project_name = save_string(project, &p); @@ -816,7 +828,7 @@ void SCL_release( SCL s_class) } } - ALL_release((FRB) s_class); + delete s_class; } @@ -838,7 +850,7 @@ static BOOLEAN check_hex(CONST TEXT* acl, USHORT number) int n; n = 0; - if (l = *acl++) + if ( (l = *acl++) ) { do { @@ -874,7 +886,7 @@ static BOOLEAN check_number(CONST TEXT* acl, USHORT number) int n; n = 0; - if (l = *acl++) + if ( (l = *acl++) ) { do { n = n * UIC_BASE + *acl++ - '0'; @@ -925,21 +937,15 @@ static BOOLEAN check_user_group(CONST TEXT* acl, tdbb = GET_THREAD_DATA; dbb = tdbb->tdbb_database; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (buffer) - ALL_release((FRB) buffer); - LONGJMP(*(JMP_BUF*)&tdbb->tdbb_setjmp, (int) tdbb->tdbb_status_vector[1]); - } - - buffer = (STR) ALLOCPV(type_str, *length_ptr); + buffer = new(*dbb->dbb_permanent, *length_ptr) str(); n = 0; - if (l = *acl++) + if ( (l = *acl++) ) { if (isdigit(*acl)) { /* this is a group id */ @@ -964,8 +970,17 @@ static BOOLEAN check_user_group(CONST TEXT* acl, } } - ALL_release((FRB) buffer); + delete buffer; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + delete buffer; +// LONGJMP(*(JMP_BUF*)&tdbb->tdbb_setjmp, (int) tdbb->tdbb_status_vector[1]); + Firebird::status_longjmp_error::raise(tdbb->tdbb_status_vector[1]); + } + return (n != number); } @@ -998,7 +1013,7 @@ static BOOLEAN check_string(CONST TEXT* acl, CONST TEXT* string) /* JPN: Since Kanji User names are not allowed, No need to fix this UPPER loop. */ - if (l = *acl++) + if ( (l = *acl++) ) { do { c1 = *acl++; @@ -1045,18 +1060,13 @@ static SLONG compute_access(TDBB tdbb, privileges = SCL_scanned; + try { + old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) - { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (str_buffer) - ALL_release((FRB) str_buffer); - LONGJMP(*(JMP_BUF*)&tdbb->tdbb_setjmp, (int) tdbb->tdbb_status_vector[1]); - } /* Get some space that's not off the stack */ - str_buffer = (STR) ALLOCPV(type_str, BLOB_BUFFER_SIZE); + str_buffer = new(*dbb->dbb_permanent, BLOB_BUFFER_SIZE) str(); buffer = (TEXT*) str_buffer->str_data; @@ -1084,7 +1094,8 @@ static SLONG compute_access(TDBB tdbb, { ULONG old_offset = (ULONG) (acl - buffer); length += BLOB_BUFFER_SIZE; - (void) ALL_extend((BLK *) & str_buffer, length); + // TMN: Cast away volatile + str::extend(const_cast(str_buffer), length); buffer = (TEXT*) str_buffer->str_data; acl = buffer + old_offset; } @@ -1110,9 +1121,18 @@ static SLONG compute_access(TDBB tdbb, REQUEST(irq_l_security) = request; - ALL_release((FRB) str_buffer); + delete str_buffer; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + delete str_buffer; +// LONGJMP(*(JMP_BUF*)&tdbb->tdbb_setjmp, (int) tdbb->tdbb_status_vector[1]); + Firebird::status_longjmp_error::raise(tdbb->tdbb_status_vector[1]); + } + return privileges; } @@ -1137,7 +1157,7 @@ static TEXT *save_string(TEXT* string, TEXT** ptr) start = p = *ptr; - while (*p++ = *string++) + while ( (*p++ = *string++) ) ; *ptr = p; @@ -1171,7 +1191,7 @@ static SLONG walk_acl(TDBB tdbb, TEXT c; TEXT* p; TEXT* role_name; - BOOLEAN is_member = FALSE; + //BOOLEAN is_member = FALSE; VOLATILE BLK request; DBB dbb; @@ -1204,13 +1224,13 @@ static SLONG walk_acl(TDBB tdbb, return -1 & ~SCL_corrupt; } - while (c = *acl++) + while ( (c = *acl++) ) { switch (c) { case ACL_id_list: hit = TRUE; - while (c = *acl++) + while ( (c = *acl++) ) { switch (c) { @@ -1246,7 +1266,7 @@ static SLONG walk_acl(TDBB tdbb, { TEXT login_name[129], *p, *q; for (p = login_name, q = user.usr_user_name; - *p++ = UPPER7(*q); q++); + (*p++ = UPPER7(*q)); q++); hit = FALSE; request = (BLK)CMP_find_request(tdbb, irq_get_role_mem, IRQ_REQUESTS); @@ -1320,7 +1340,7 @@ static SLONG walk_acl(TDBB tdbb, case ACL_priv_list: if (hit) { - while (c = *acl++) + while ( (c = *acl++) ) switch (c) { case priv_control: privilege |= SCL_control; diff --git a/src/jrd/scl.h b/src/jrd/scl.h index 7d2bffc7d7..dbf174bf04 100644 --- a/src/jrd/scl.h +++ b/src/jrd/scl.h @@ -27,17 +27,22 @@ /* Security class definition */ #ifndef GATEWAY -typedef struct scl { - struct blk scl_header; - struct scl *scl_next; /* Next security class in system */ +class scl : public pool_alloc_rpt +{ + public: + scl *scl_next; /* Next security class in system */ USHORT scl_flags; /* Access permissions */ TEXT scl_name[2]; -} *SCL; +}; +typedef scl *SCL; + #else -typedef struct scl { - struct blk scl_header; +class scl : public pool_alloc +{ + public: struct sbm *scl_flags; /* Access permissions */ -} *SCL; +}; +typedef scl *SCL; #endif #define SCL_read 1 /* Read access */ @@ -59,8 +64,9 @@ typedef struct scl { /* information about the user */ -typedef struct usr { - struct blk usr_header; +class usr : public pool_alloc_rpt +{ + public: TEXT *usr_user_name; /* User name */ TEXT *usr_sql_role_name; /* Role name */ TEXT *usr_project_name; /* Project name */ @@ -77,7 +83,8 @@ typedef struct usr { SLONG usr_dbms_uid; /* Number of user as defined by DBMS */ #endif TEXT usr_data[2]; -} *USR; +}; +typedef usr *USR; #define USR_locksmith 1 /* User has great karma */ #define USR_dba 2 /* User has DBA privileges */ diff --git a/src/jrd/sdl.h b/src/jrd/sdl.h index d1a3668d78..79cf16b0b9 100644 --- a/src/jrd/sdl.h +++ b/src/jrd/sdl.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_SDL_H_ -#define _JRD_SDL_H_ +#ifndef JRD_SDL_H +#define JRD_SDL_H typedef struct sdl_info { USHORT sdl_info_fid; @@ -45,4 +45,4 @@ typedef struct slice { SLONG slice_count; } *SLICE; -#endif /* _JRD_SDL_H_ */ +#endif /* JRD_SDL_H */ diff --git a/src/jrd/sdl_proto.h b/src/jrd/sdl_proto.h index 4c1843a777..4e1a2470a1 100644 --- a/src/jrd/sdl_proto.h +++ b/src/jrd/sdl_proto.h @@ -21,8 +21,12 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_SDL_PROTO_H_ -#define _JRD_SDL_PROTO_H_ +#ifndef JRD_SDL_PROTO_H +#define JRD_SDL_PROTO_H + +#ifdef __cplusplus +extern "C" { +#endif extern SLONG DLL_EXPORT SDL_compute_subscript(STATUS *, struct ads *, USHORT, SLONG *); @@ -33,4 +37,8 @@ extern int DLL_EXPORT SDL_walk(STATUS *, UCHAR *, USHORT, UCHAR *, struct ads *, SLONG *, FPTR_VOID, struct slice *); -#endif /* _JRD_SDL_PROTO_H_ */ +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* JRD_SDL_PROTO_H */ diff --git a/src/jrd/sdw.cpp b/src/jrd/sdw.cpp index e1ba8f17fa..3f5c3fba52 100644 --- a/src/jrd/sdw.cpp +++ b/src/jrd/sdw.cpp @@ -122,30 +122,32 @@ int SDW_add_file(TEXT * file_name, SLONG start, USHORT shadow_number) * Return the sequence number for the new file. * **************************************/ - TDBB tdbb; - DBB dbb; + FIL shadow_file, next, file; SDW shadow; struct bdb temp_bdb; HDR header; SLONG sequence; SCHAR *spare_buffer = NULL, *spare_page; - JMP_BUF env, *old_env; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; /* Find the file to be extended */ for (shadow = dbb->dbb_shadow; shadow; shadow = shadow->sdw_next) + { if ((shadow->sdw_number == shadow_number) && - !(shadow->sdw_flags & (SDW_IGNORE | SDW_rollover))) { + !(shadow->sdw_flags & (SDW_IGNORE | SDW_rollover))) + { shadow_file = shadow->sdw_file; break; } + } - if (!shadow) + if (!shadow) { return 0; + } /* find the last file in the list, open the new file */ @@ -166,19 +168,13 @@ int SDW_add_file(TEXT * file_name, SLONG start, USHORT shadow_number) and set up to release it in case of error. Align the spare page buffer for raw disk access. */ - spare_buffer = - ALL_malloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE, ERR_jmp); + spare_buffer = (SCHAR*) + MemoryPool::malloc_from_system((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE); spare_page = (SCHAR *) (((U_IPTR) spare_buffer + MIN_PAGE_SIZE - 1) & ~((U_IPTR) MIN_PAGE_SIZE - 1)); - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (spare_buffer) - ALL_free(spare_buffer); - ERR_punt(); - } + + try { /* create the header using the spare_buffer */ @@ -196,11 +192,14 @@ int SDW_add_file(TEXT * file_name, SLONG start, USHORT shadow_number) temp_bdb.bdb_dbb = dbb; temp_bdb.bdb_buffer = (PAG) header; header->hdr_header.pag_checksum = CCH_checksum(&temp_bdb); - if (!PIO_write - (shadow_file, &temp_bdb, reinterpret_cast < pag * >(header), 0)) { - if (spare_buffer) - ALL_free(spare_buffer); - tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (!PIO_write( shadow_file, + &temp_bdb, + reinterpret_cast(header), + 0)) + { + if (spare_buffer) { + MemoryPool::free_from_system(spare_buffer); + } return 0; } next->fil_fudge = 1; @@ -225,9 +224,9 @@ else === ************************/ /** Tempeorarly reverting the change ------- Sudesh 07/07/95 *******/ - if (shadow_file == file) + if (shadow_file == file) { copy_header(); - else { + } else { --start; header->hdr_data[0] = HDR_end; header->hdr_end = HDR_SIZE; @@ -240,23 +239,37 @@ else file->fil_fudge = 0; temp_bdb.bdb_page = file->fil_min_page; header->hdr_header.pag_checksum = CCH_checksum(&temp_bdb); - if (!PIO_write - (shadow_file, &temp_bdb, reinterpret_cast < pag * >(header), 0)) { - if (spare_buffer) - ALL_free(spare_buffer); - tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (!PIO_write( shadow_file, + &temp_bdb, + reinterpret_cast(header), + 0)) + { + if (spare_buffer) { + MemoryPool::free_from_system(spare_buffer); + } return 0; } - if (file->fil_min_page) + if (file->fil_min_page) { file->fil_fudge = 1; + } } - if (file->fil_min_page) + if (file->fil_min_page) { file->fil_fudge = 1; + } + + if (spare_buffer) { + MemoryPool::free_from_system(spare_buffer); + } + + } // try + catch (...) { + if (spare_buffer) { + MemoryPool::free_from_system(spare_buffer); + } + ERR_punt(); + } - if (spare_buffer) - ALL_free(spare_buffer); - tdbb->tdbb_setjmp = (UCHAR *) old_env; return sequence; } @@ -275,7 +288,7 @@ void SDW_check(void) * **************************************/ SDW shadow, next_shadow; - BOOLEAN start_conditional = TRUE; + //BOOLEAN start_conditional = TRUE; TDBB tdbb; DBB dbb; LCK lock; @@ -309,7 +322,7 @@ void SDW_check(void) } if (SDW_check_conditional()) { if (SDW_lck_update((SLONG) 0)) { - lock = (LCK) ALLOCPV(type_lck, sizeof(SLONG)); + lock = new(*dbb->dbb_permanent, sizeof(SLONG)) lck(); lock->lck_dbb = dbb; lock->lck_attachment = tdbb->tdbb_attachment; lock->lck_length = sizeof(SLONG); @@ -326,7 +339,7 @@ void SDW_check(void) SDW_dump_pages(); LCK_release(tdbb, lock); } - ALL_release(reinterpret_cast < frb * >(lock)); + delete lock; } } } @@ -583,7 +596,7 @@ void SDW_init(USHORT activate, USHORT delete_, SBM sbm_rec) /* set up the lock block for synchronizing addition of new shadows */ key_length = sizeof(header->hdr_shadow_count); - dbb->dbb_shadow_lock = lock = (LCK) ALLOCPV(type_lck, key_length); + dbb->dbb_shadow_lock = lock = new(*dbb->dbb_permanent, key_length) lck(); lock->lck_type = LCK_shadow; lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type); lock->lck_parent = dbb->dbb_lock; @@ -760,7 +773,7 @@ BOOLEAN SDW_rollover_to_shadow(FIL file, BOOLEAN inAst) update_lock = &temp_lock; MOVE_CLEAR(update_lock, sizeof(struct lck)); - update_lock->lck_header.blk_type = type_lck; + //update_lock->blk_type = type_lck; update_lock->lck_dbb = dbb; update_lock->lck_attachment = tdbb->tdbb_attachment; update_lock->lck_length = sizeof(SLONG); @@ -814,9 +827,9 @@ BOOLEAN SDW_rollover_to_shadow(FIL file, BOOLEAN inAst) PIO_close(dbb->dbb_file); - while (file = dbb->dbb_file) { + while ( (file = dbb->dbb_file) ) { dbb->dbb_file = file->fil_next; - ALL_release(reinterpret_cast < frb * >(file)); + delete file; } /* point the main database file at the file of the first shadow @@ -835,7 +848,7 @@ BOOLEAN SDW_rollover_to_shadow(FIL file, BOOLEAN inAst) successfull updating LCK_data we will be the only one doing so */ if (!inAst) { - if (start_conditional = SDW_check_conditional()) { + if ( (start_conditional = SDW_check_conditional()) ) { sdw_update_flags = (SDW_rollover | SDW_conditional); LCK_write_data(shadow_lock, sdw_update_flags); } @@ -844,7 +857,7 @@ BOOLEAN SDW_rollover_to_shadow(FIL file, BOOLEAN inAst) SDW_notify(); LCK_write_data(shadow_lock, (SLONG) 0); LCK_release(tdbb, shadow_lock); - ALL_release(reinterpret_cast < frb * >(shadow_lock)); + delete shadow_lock; dbb->dbb_shadow_lock = 0; LCK_release(tdbb, update_lock); if (start_conditional && !inAst) { @@ -887,10 +900,10 @@ void SDW_shutdown_shadow(SDW shadow) if (shadow) { PIO_close(shadow->sdw_file); - for (free = shadow->sdw_file; file = free->fil_next; free = file) - ALL_release(reinterpret_cast < frb * >(free)); - ALL_release(reinterpret_cast < frb * >(free)); - ALL_release(reinterpret_cast < frb * >(shadow)); + for (free = shadow->sdw_file; (file = free->fil_next); free = file) + delete free; + delete free; + delete shadow; } } @@ -919,7 +932,6 @@ void SDW_start( SCHAR expanded_name[MAX_PATH_LENGTH]; UCHAR *p; FIL dbb_file, shadow_file = 0; - JMP_BUF env, *old_env; WIN window; HDR database_header, shadow_header; VOLATILE USHORT header_fetched = 0; @@ -960,46 +972,25 @@ void SDW_start( shadow = NULL; spare_buffer = - (SLONG *) ALL_malloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE, - ERR_jmp); + (SLONG *) MemoryPool::malloc_from_system((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE); spare_page = reinterpret_cast < SLONG * >((SCHAR *) (((U_IPTR) spare_buffer + MIN_PAGE_SIZE - 1) & ~((U_IPTR) MIN_PAGE_SIZE - 1))); - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (header_fetched) - CCH_RELEASE(tdbb, &window); - if (shadow_file) { - PIO_close(shadow_file); - ALL_release(reinterpret_cast < frb * >(shadow_file)); - } - if (spare_buffer) - ALL_free(reinterpret_cast < char *>(spare_buffer)); - if (file_flags & FILE_manual && !delete_) - ERR_post(gds_shadow_missing, gds_arg_number, - (SLONG) shadow_number, 0); - else { - MET_delete_shadow(tdbb, shadow_number); - gds__log - ("shadow %s deleted from database %s due to unavailability on attach", - expanded_name, dbb_file->fil_string); - } - return; - } + try { shadow_file = PIO_open(dbb, expanded_name, expanded_length, FALSE, 0, file_name, length); - if (dbb->dbb_flags & DBB_force_write) + if (dbb->dbb_flags & DBB_force_write) { PIO_force_write(shadow_file, TRUE); + } - if (!(file_flags & FILE_conditional)) { + if (!(file_flags & FILE_conditional)) + { /* make some sanity checks on the database and shadow header pages: 1. make sure that the proper database filename is accessing this shadow 2. make sure the database and shadow are in sync by checking the creation time/transaction id @@ -1056,15 +1047,41 @@ void SDW_start( dumped (except for the cases when it isn't) */ shadow = allocate_shadow(shadow_file, shadow_number, file_flags); - if (!(file_flags & FILE_conditional)) + if (!(file_flags & FILE_conditional)) { shadow->sdw_flags |= SDW_dumped; + } /* get the ancillary files and reset the error environment */ PAG_init2(shadow_number); - if (spare_buffer) - ALL_free(reinterpret_cast < char *>(spare_buffer)); - tdbb->tdbb_setjmp = (UCHAR *) old_env; + if (spare_buffer) { + MemoryPool::free_from_system(spare_buffer); + } + + } // try + catch (...) { + if (header_fetched) { + CCH_RELEASE(tdbb, &window); + } + if (shadow_file) { + PIO_close(shadow_file); + delete shadow_file; + } + if (spare_buffer) { + MemoryPool::free_from_system(spare_buffer); + } + if (file_flags & FILE_manual && !delete_) { + ERR_post(gds_shadow_missing, gds_arg_number, + (SLONG) shadow_number, 0); + } + else + { + MET_delete_shadow(tdbb, shadow_number); + gds__log + ("shadow %s deleted from database %s due to unavailability on attach", + expanded_name, dbb_file->fil_string); + } + } } @@ -1182,7 +1199,7 @@ static SDW allocate_shadow( dbb = GET_DBB; - shadow = (SDW) ALLOCP(type_sdw); + shadow = new(*dbb->dbb_permanent) sdw(); shadow->sdw_file = shadow_file; shadow->sdw_number = shadow_number; if (file_flags & FILE_manual) @@ -1223,26 +1240,18 @@ static BOOLEAN check_for_file(SCHAR * name, USHORT length) * Return TRUE if it is there. * **************************************/ - TDBB tdbb; - DBB dbb; - JMP_BUF env, *old_env; - FIL temp_file; - tdbb = GET_THREAD_DATA; - dbb = tdbb->tdbb_database; + TDBB tdbb = GET_THREAD_DATA; + DBB dbb = tdbb->tdbb_database; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; + try { + FIL temp_file = PIO_open(dbb, name, length, FALSE, 0, name, length); + PIO_close(temp_file); + } // try + catch (...) { return FALSE; } - temp_file = PIO_open(dbb, name, length, FALSE, 0, name, length); - PIO_close(temp_file); - - tdbb->tdbb_setjmp = (UCHAR *) old_env; return TRUE; } @@ -1350,9 +1359,9 @@ static void update_dbb_to_sdw(DBB dbb) PIO_close(dbb->dbb_file); - while (file = dbb->dbb_file) { + while ( (file = dbb->dbb_file) ) { dbb->dbb_file = file->fil_next; - ALL_release(reinterpret_cast < frb * >(file)); + delete file; } dbb->dbb_file = shadow->sdw_file; diff --git a/src/jrd/sdw.h b/src/jrd/sdw.h index e800a228a7..a2de9e8559 100644 --- a/src/jrd/sdw.h +++ b/src/jrd/sdw.h @@ -24,15 +24,20 @@ #ifndef _JRD_SDW_H_ #define _JRD_SDW_H_ +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + /* Shadowing block */ -typedef struct sdw { - struct blk sdw_header; +class sdw : public pool_alloc +{ + public: struct sdw *sdw_next; /* next in linked list */ struct fil *sdw_file; /* Stack of shadow files */ USHORT sdw_number; /* number of shadow */ USHORT sdw_flags; -} *SDW; +}; +typedef sdw *SDW; #define SDW_dumped 1 /* bit set when file has been copied */ #define SDW_shutdown 2 /* stop shadowing on next cache flush */ diff --git a/src/jrd/shdef.h b/src/jrd/shdef.h index 70c3372ee0..ceb576bbd1 100644 --- a/src/jrd/shdef.h +++ b/src/jrd/shdef.h @@ -108,13 +108,11 @@ typedef unsigned int mode_t; #define ctime (*_libgds_ctime) #define atol (*_libgds_atol) -extern int setjmp(); extern int sprintf(); extern int strlen(); extern int strcmp(); extern SCHAR *strcpy(); extern void exit(); -extern void longjmp(); extern IB_FILE _iob[]; extern int abort(); extern void *memset(); diff --git a/src/jrd/shut.cpp b/src/jrd/shut.cpp index 5dc3293ee0..c91bfc6552 100644 --- a/src/jrd/shut.cpp +++ b/src/jrd/shut.cpp @@ -120,7 +120,6 @@ BOOLEAN SHUT_database(DBB dbb, SSHORT flag, SSHORT delay) ATT attachment; WIN window; HDR header; - SDATA data; SSHORT timeout, exclusive; JMP_BUF env, *old_env; @@ -130,20 +129,22 @@ BOOLEAN SHUT_database(DBB dbb, SSHORT flag, SSHORT delay) /* Only platform's user locksmith can shutdown or bring online a database. */ - if (!attachment->att_user->usr_flags & (USR_locksmith | USR_owner)) +#pragma FB_COMPILER_MESSAGE("Locksmith?!") + +// if (!attachment->att_user->usr_flags & (USR_locksmith | USR_owner)) { + if (!(attachment->att_user->usr_flags & (USR_locksmith | USR_owner))) { return FALSE; + } old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; - } + try { /* If shutdown flag is zero then bring database online */ - if (!flag) { + if (!flag) + { /* Clear shutdown flag on database header page */ window.win_page = HEADER_PAGE; @@ -185,13 +186,19 @@ BOOLEAN SHUT_database(DBB dbb, SSHORT flag, SSHORT delay) exclusive = FALSE; for (timeout = delay; timeout >= 0; timeout -= SHUT_WAIT_TIME) + { if ((exclusive = notify_shutdown(dbb, flag, timeout)) || !(dbb->dbb_ast_flags & (DBB_shut_attach | DBB_shut_tran | - DBB_shut_force))) break; + DBB_shut_force))) + { + break; + } + } if (!exclusive && (timeout > 0 || flag & (gds_dpb_shut_attachment | - gds_dpb_shut_transaction))) { + gds_dpb_shut_transaction))) + { notify_shutdown(dbb, 0, 0); /* Tell everyone we're giving up */ SHUT_blocking_ast(dbb); attachment->att_flags &= ~ATT_shutdown_manager; @@ -209,8 +216,10 @@ BOOLEAN SHUT_database(DBB dbb, SSHORT flag, SSHORT delay) dbb->dbb_ast_flags |= DBB_shutdown; - if (!exclusive && flag & gds_dpb_shut_force) + if (!exclusive && flag & gds_dpb_shut_force) { + // TMN: Ugly counting! while (!notify_shutdown(dbb, flag, 0)); + } ++dbb->dbb_use_count; dbb->dbb_ast_flags &= ~(DBB_shut_force | DBB_shut_attach | DBB_shut_tran); @@ -223,6 +232,13 @@ BOOLEAN SHUT_database(DBB dbb, SSHORT flag, SSHORT delay) CCH_release_exclusive(tdbb); tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + return FALSE; + } + return TRUE; } @@ -260,11 +276,9 @@ static BOOLEAN notify_shutdown(DBB dbb, SSHORT flag, SSHORT delay) * flags and delay via lock data. * **************************************/ - SDATA data; - ATT attachment; - TDBB tdbb; - tdbb = GET_THREAD_DATA; + TDBB tdbb = GET_THREAD_DATA; + SDATA data; data.data_items.flag = flag; data.data_items.delay = delay; @@ -273,15 +287,19 @@ static BOOLEAN notify_shutdown(DBB dbb, SSHORT flag, SSHORT delay) /* Send blocking ASTs to database users */ - if (CCH_exclusive(tdbb, LCK_PW, ((SSHORT) - SHUT_WAIT_TIME)) && flag) + if (CCH_exclusive(tdbb, LCK_PW, ((SSHORT) - SHUT_WAIT_TIME)) && flag) { return shutdown_locks(dbb); - else if ((flag & gds_dpb_shut_force) && !delay) + } + if ((flag & gds_dpb_shut_force) && !delay) { return shutdown_locks(dbb); - else if ((flag & gds_dpb_shut_transaction) - && !(TRA_active_transactions(tdbb, dbb))) + } + if ((flag & gds_dpb_shut_transaction) && + !(TRA_active_transactions(tdbb, dbb))) + { return TRUE; - else - return FALSE; + } + + return FALSE; } diff --git a/src/jrd/smp.h b/src/jrd/smp.h new file mode 100644 index 0000000000..1fcfd4f765 --- /dev/null +++ b/src/jrd/smp.h @@ -0,0 +1,14 @@ +#ifndef _JRD_SMP_H_ +#define _JRD_SMP_H_ + +class SmpLock +{ + public: + SmpLock() {} + virtual ~SmpLock() {} + + virtual void aquire(void) = 0; + virtual void release(void) = 0; +}; + +#endif diff --git a/src/jrd/smp_impl.h b/src/jrd/smp_impl.h new file mode 100644 index 0000000000..d2893f9955 --- /dev/null +++ b/src/jrd/smp_impl.h @@ -0,0 +1,20 @@ +#ifndef _JRD_SMP_IMPL_H_ +#define _JRD_SMP_IMPL_H_ + +#include "../jrd/smp.h" +#include "../jrd/thd.h" + +class V4Mutex : public SmpLock +{ + public: + V4Mutex() { V4_MUTEX_INIT(&mutex); } + ~V4Mutex() { V4_MUTEX_DESTROY(&mutex); } + + virtual void aquire(void) { V4_MUTEX_LOCK(&mutex); } + virtual void release(void) { V4_MUTEX_UNLOCK(&mutex); } + + private: + MUTX mutex; +}; + +#endif diff --git a/src/jrd/sort.cpp b/src/jrd/sort.cpp index ffa5ba0673..3cd5062e7c 100644 --- a/src/jrd/sort.cpp +++ b/src/jrd/sort.cpp @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: sort.cpp,v 1.3 2001-07-29 17:42:22 skywalker Exp $ + * $Id: sort.cpp,v 1.4 2001-12-24 02:50:52 tamlin Exp $ */ #include "firebird.h" @@ -102,13 +102,13 @@ extern double MTH$CVT_D_G(), MTH$CVT_G_D(); (big endian) patforms, making the following CONST caused a core on the Intel Platforms, while Solaris was working fine. */ static ULONG low_key[] = { 0, 0, 0, 0, 0, 0 }, high_key[] = { - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; + ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, + ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, + ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, + ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, + ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, + ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, + ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX, ULONG_MAX}; #ifdef SCROLLABLE_CURSORS @@ -118,7 +118,7 @@ static void diddle_key(UCHAR *, SCB, USHORT); static SORT_RECORD *get_merge(MRG, SCB); #endif -static UCHAR *alloc(SCB, ULONG); +static UCHAR *sort_alloc(SCB, ULONG); static void error_memory(SCB); static ULONG find_file_space(SCB, ULONG, SFB *); static void free_file_space(SCB, SFB, ULONG, ULONG); @@ -573,7 +573,7 @@ void SORT_fini(SCB scb, ATT att) /* -- Morgan Schweers (mrs) */ if (rval == TRUE) - ALL_free(reinterpret_cast < char *>(scb)); + MemoryPool::free_from_system(scb); } @@ -701,7 +701,7 @@ void SORT_get(STATUS * status_vector, SCB scb, ULONG ** record_address) break; } scb->scb_records--; - if (record = *scb->scb_next_pointer++) + if ( (record = *scb->scb_next_pointer++) ) break; } else @@ -746,10 +746,11 @@ SCB SORT_init(STATUS * status_vector, longword, and add a longword to a pointer back to the pointer slot. */ - scb = (SCB) ALL_malloc((SLONG) SCB_LEN(keys), ERR_val); + try { + scb = (SCB) MemoryPool::malloc_from_system((SLONG) SCB_LEN(keys)); + } catch(...) { /* FREE: scb is freed by SORT_fini(), called by higher level cleanup */ /* FREE: or later in this module in error cases */ - if (!scb) { *status_vector++ = gds_arg_gds; *status_vector++ = gds_sort_mem_err; *status_vector = gds_arg_end; @@ -777,34 +778,32 @@ SCB SORT_init(STATUS * status_vector, ROUNDUP(p->skd_offset + p->skd_length, sizeof(SLONG)) >> SHIFTLONG; /* Next, try to allocate a "big block". How big? Big enough! */ + try { + #ifdef DEBUG_MERGE + /* To debug the merge algorithm, force the in-memory pool to be VERY small */ + scb->scb_size_memory = 2000; + scb->scb_memory = + (SORTP *) MemoryPool::malloc_from_system((SLONG) scb->scb_size_memory); + /* FREE: scb_memory is freed by local_fini() */ + #else + /* Try to get a big chunk of memory, if we can't try smaller and + smaller chunks until we can get the memory. If we get down to + too small a chunk - punt and report not enough memory. */ -#ifdef DEBUG_MERGE -/* To debug the merge algorithm, force the in-memory pool to be VERY small */ - scb->scb_size_memory = 2000; - scb->scb_memory = - (SORTP *) ALL_malloc((SLONG) scb->scb_size_memory, ERR_val); - /* FREE: scb_memory is freed by local_fini() */ -#else -/* Try to get a big chunk of memory, if we can't try smaller and - smaller chunks until we can get the memory. If we get down to - too small a chunk - punt and report not enough memory. */ - - for (scb->scb_size_memory = MAX_SORT_BUFFER_SIZE;; - scb->scb_size_memory -= 5000) if (scb->scb_size_memory < 10000) - break; - else if (scb->scb_memory = - (SORTP *) ALL_sys_alloc((SLONG) scb->scb_size_memory, - ERR_val)) + for (scb->scb_size_memory = MAX_SORT_BUFFER_SIZE;; + scb->scb_size_memory -= 5000) if (scb->scb_size_memory < 10000) + break; + else if ( (scb->scb_memory = + (SORTP *) MemoryPool::malloc_from_system((SLONG) scb->scb_size_memory)) ) /* FREE: scb_memory is freed by local_fini() */ - break; -#endif /* DEBUG_MERGE */ - - if (!scb->scb_memory) { + break; + #endif /* DEBUG_MERGE */ + } catch(...) { *status_vector++ = gds_arg_gds; *status_vector++ = gds_sort_mem_err; /* Msg356: sort error: not enough memory */ *status_vector = gds_arg_end; - ALL_free(reinterpret_cast < char *>(scb)); + MemoryPool::free_from_system(scb); return NULL; } @@ -1066,20 +1065,20 @@ int SORT_sort(STATUS * status_vector, SCB scb) for (run_count = 0, run = scb->scb_runs; run; run = run->run_next) { if (run->run_buff_alloc) { - ALL_free(reinterpret_cast < char *>(run->run_buffer)); + MemoryPool::free_from_system(run->run_buffer); run->run_buff_alloc = 0; } ++run_count; } - if ((run_count * sizeof(RMH)) > sizeof(streams_local)) - streams = - (RMH *) ALL_malloc((SLONG) run_count * sizeof(RMH), ERR_val); + try { + if ((run_count * sizeof(RMH)) > sizeof(streams_local)) + streams = + (RMH *) MemoryPool::malloc_from_system((SLONG) run_count * sizeof(RMH)); /* FREE: streams is freed later in this routine */ - else - streams = streams_local; - - if (!streams) { + else + streams = streams_local; + } catch(...) { *status_vector++ = gds_arg_gds; *status_vector++ = gds_sort_mem_err; *status_vector = gds_arg_end; @@ -1096,14 +1095,14 @@ int SORT_sort(STATUS * status_vector, SCB scb) */ if (count > 1) { assert(!scb->scb_merge_pool); /* shouldn't have a pool */ - scb->scb_merge_pool = - (MRG) ALL_malloc((SLONG) (count - 1) * sizeof(struct mrg), - ERR_val); + try { + scb->scb_merge_pool = + (MRG) MemoryPool::malloc_from_system((SLONG) (count - 1)*sizeof(struct mrg)); /* FREE: smb_merge_pool freed in local_fini() when the scb is released */ - merge_pool = scb->scb_merge_pool; - if (!merge_pool) { - ALL_free(reinterpret_cast < char *>(streams)); + merge_pool = scb->scb_merge_pool; + } catch(...) { + MemoryPool::free_from_system(streams); *status_vector++ = gds_arg_gds; *status_vector++ = gds_sort_mem_err; *status_vector = gds_arg_end; @@ -1158,7 +1157,7 @@ int SORT_sort(STATUS * status_vector, SCB scb) } if (streams != streams_local) - ALL_free(reinterpret_cast < char *>(streams)); + MemoryPool::free_from_system(streams); buffer = (SORTP *) scb->scb_first_pointer; merge->mrg_header.rmh_parent = NULL; scb->scb_merge = merge; @@ -1192,10 +1191,11 @@ int SORT_sort(STATUS * status_vector, SCB scb) allocating enough for the merge space plus a link */ for (; run; run = run->run_next) { - run->run_buffer = - (ULONG *) ALL_malloc((SLONG) (size * sizeof(ULONG)), ERR_val); - /* FREE: smb_merge_space freed in local_fini() when the scb is released */ - if (!run->run_buffer) { + try { + run->run_buffer = + (ULONG *) MemoryPool::malloc_from_system((SLONG) (size * sizeof(ULONG))); + /* FREE: smb_merge_space freed in local_fini() when the scb is released */ + } catch(...) { *status_vector++ = gds_arg_gds; *status_vector++ = gds_sort_mem_err; *status_vector = gds_arg_end; @@ -1278,7 +1278,7 @@ ULONG SORT_write_block(STATUS * status_vector, } -static UCHAR *alloc(SCB scb, ULONG size) +static UCHAR *sort_alloc(SCB scb, ULONG size) { /************************************** * @@ -1311,15 +1311,18 @@ static UCHAR *alloc(SCB scb, ULONG size) * 1994-October-11 David Schnepper * **************************************/ - UCHAR *block; + UCHAR* block = 0; - if (! - (block = - reinterpret_cast < UCHAR * >(ALL_malloc((SLONG) size, ERR_val)))) + try { + block = + reinterpret_cast(MemoryPool::malloc_from_system((SLONG) size)); /* FREE: caller responsible for freeing */ - { - error_memory(scb); - return NULL; + } catch(...) { + if (!block) + { + error_memory(scb); + return NULL; + } } memset(block, 0, size); @@ -1466,8 +1469,8 @@ static void diddle_key(UCHAR * record, SCB scb, USHORT direction) * **************************************/ register BLOB_PTR *p; - UCHAR c1, c2, fill_char, *fill_pos; - USHORT complement, n, w, l, fill; + UCHAR c1, fill_char, *fill_pos; + USHORT complement, n, l, fill; USHORT HUGE_PTR *wp; SSHORT longs, flag; SORTP *lwp; @@ -1476,6 +1479,9 @@ static void diddle_key(UCHAR * record, SCB scb, USHORT direction) #ifdef VMS double *dp; #endif +#ifndef IEEE + USHORT w; +#endif for (key = scb->scb_description, end = key + scb->scb_keys; key < end; key++) { @@ -1730,8 +1736,8 @@ static ULONG find_file_space(SCB scb, ULONG size, SFB * ret_sfb) /* Search through the available space in the work file list. */ - for (sfb_ptr = &scb->scb_sfb; sfb = *sfb_ptr; sfb_ptr = &sfb->sfb_next) { - for (ptr = &sfb->sfb_file_space; space = *ptr; + for (sfb_ptr = &scb->scb_sfb; (sfb = *sfb_ptr); sfb_ptr = &sfb->sfb_next) { + for (ptr = &sfb->sfb_file_space; (space = *ptr); ptr = &(*ptr)->wfs_next) { /* if this is smaller than our previous best, use it */ @@ -1757,7 +1763,7 @@ static ULONG find_file_space(SCB scb, ULONG size, SFB * ret_sfb) and return. */ if (!sfb || !DLS_get_temp_space(size, sfb)) { - sfb = (SFB) alloc(scb, (ULONG) sizeof(struct sfb)); + sfb = (SFB) sort_alloc(scb, (ULONG) sizeof(struct sfb)); /* FREE: scb_sfb chain is freed in local_fini() */ if (last_sfb) @@ -1783,7 +1789,7 @@ static ULONG find_file_space(SCB scb, ULONG size, SFB * ret_sfb) This is released during local_fini(). */ sfb->sfb_file_name = - (TEXT *) alloc(scb, (ULONG) (strlen(file_name) + 1)); + (TEXT *) sort_alloc(scb, (ULONG) (strlen(file_name) + 1)); /* FREE: sfb_file_name is freed in local_fini() */ strcpy(sfb->sfb_file_name, file_name); @@ -1843,7 +1849,7 @@ static void free_file_space(SCB scb, SFB sfb, ULONG position, ULONG size) /* Search through work file space blocks looking for an adjacent block. */ - for (ptr = &sfb->sfb_file_space; space = *ptr; ptr = &space->wfs_next) { + for (ptr = &sfb->sfb_file_space; (space = *ptr); ptr = &space->wfs_next) { if (end >= space->wfs_position) break; } @@ -1880,10 +1886,10 @@ static void free_file_space(SCB scb, SFB sfb, ULONG position, ULONG size) /* Block didn't seem to append nicely to an existing block */ - if (space = sfb->sfb_free_wfs) + if ( (space = sfb->sfb_free_wfs) ) sfb->sfb_free_wfs = space->wfs_next; else - space = (WFS) alloc(scb, (ULONG) sizeof(struct wfs)); + space = (WFS) sort_alloc(scb, (ULONG) sizeof(struct wfs)); /* FREE: wfs_next chain is freed in local_fini() */ space->wfs_next = *ptr; @@ -2068,7 +2074,7 @@ static SORT_RECORD *get_merge(MRG merge, SCB scb merge = (MRG) merge->mrg_stream_b; continue; } - else if (record = merge->mrg_record_a) { + else if ( (record = merge->mrg_record_a) ) { merge->mrg_record_a = (SORT_RECORD *) NULL; merge = merge->mrg_header.rmh_parent; continue; @@ -2186,7 +2192,6 @@ static BOOLEAN local_fini(SCB scb, ATT att) **************************************/ WFS space; RUN run; - UCHAR *p; SFB sfb; ULONG **merge_buf; BOOLEAN found_it = TRUE; @@ -2220,7 +2225,7 @@ static BOOLEAN local_fini(SCB scb, ATT att) /* Loop through the sfb list and close work files. */ - while (sfb = scb->scb_sfb) { + while ( (sfb = scb->scb_sfb) ) { scb->scb_sfb = sfb->sfb_next; DLS_put_temp_space(sfb); @@ -2228,28 +2233,28 @@ static BOOLEAN local_fini(SCB scb, ATT att) if (sfb->sfb_file_name) { unlink(sfb->sfb_file_name); - ALL_free(sfb->sfb_file_name); + MemoryPool::free_from_system(sfb->sfb_file_name); sfb->sfb_file_name = NULL; } - while (space = sfb->sfb_free_wfs) { + while ( (space = sfb->sfb_free_wfs) ) { sfb->sfb_free_wfs = space->wfs_next; - ALL_free(reinterpret_cast < char *>(space)); + MemoryPool::free_from_system(space); } - while (space = sfb->sfb_file_space) { + while ( (space = sfb->sfb_file_space) ) { sfb->sfb_file_space = space->wfs_next; - ALL_free(reinterpret_cast < char *>(space)); + MemoryPool::free_from_system(space); } - ALL_free(reinterpret_cast < char *>(sfb)); + MemoryPool::free_from_system(sfb); } /* get rid of extra merge space */ - while (merge_buf = (ULONG **) scb->scb_merge_space) { + while ( (merge_buf = (ULONG **) scb->scb_merge_space) ) { scb->scb_merge_space = *merge_buf; - ALL_free(reinterpret_cast < char *>(merge_buf)); + MemoryPool::free_from_system(merge_buf); } /* If runs are allocated and not in the big block, release them. Then release @@ -2257,31 +2262,31 @@ static BOOLEAN local_fini(SCB scb, ATT att) if (scb->scb_memory) { #ifdef DEBUG_MERGE - ALL_free(scb->scb_memory); + MemoryPool::free_from_system(scb->scb_memory); #else - ALL_sys_free(reinterpret_cast < char *>(scb->scb_memory)); + MemoryPool::free_from_system(scb->scb_memory); #endif scb->scb_memory = NULL; } /* Clean up the runs that were used */ - while (run = scb->scb_runs) { + while ( (run = scb->scb_runs) ) { scb->scb_runs = run->run_next; if (run->run_buff_alloc) - ALL_free(reinterpret_cast < char *>(run->run_buffer)); - ALL_free(reinterpret_cast < char *>(run)); + MemoryPool::free_from_system(run->run_buffer); + MemoryPool::free_from_system(run); } /* Clean up the free runs also */ - while (run = scb->scb_free_runs) { + while ( (run = scb->scb_free_runs) ) { scb->scb_free_runs = run->run_next; if (run->run_buff_alloc) - ALL_free(reinterpret_cast < char *>(run->run_buffer)); - ALL_free(reinterpret_cast < char *>(run)); + MemoryPool::free_from_system(run->run_buffer); + MemoryPool::free_from_system(run); } if (scb->scb_merge_pool) { - ALL_free(reinterpret_cast < char *>(scb->scb_merge_pool)); + MemoryPool::free_from_system(scb->scb_merge_pool); scb->scb_merge_pool = NULL; } @@ -2340,11 +2345,14 @@ static void merge_runs(SCB scb, USHORT n) if (!size) { if (!run->run_buff_alloc) { - run->run_buffer = - (ULONG *) ALL_malloc((SLONG) rec_size * 2, ERR_val); - /* FREE: smb_merge_space freed in local_fini() when scb released */ - if (!run->run_buffer) - error_memory(scb); + try { + run->run_buffer = + (ULONG *) MemoryPool::malloc_from_system((SLONG) rec_size * 2); + } catch (...) { + /* FREE: smb_merge_space freed in local_fini() when scb released */ + if (!run->run_buffer) + error_memory(scb); + } run->run_buff_alloc = 1; } run->run_end_buffer = @@ -2409,7 +2417,7 @@ static void merge_runs(SCB scb, USHORT n) #ifdef SCROLLABLE_CURSORS while (p = get_merge(merge, scb, RSE_get_forward)) #else - while (p = get_merge(merge, scb)) + while ( (p = get_merge(merge, scb)) ) #endif { if (q >= (SORT_RECORD *) temp_run.run_end_buffer) { @@ -2431,7 +2439,7 @@ static void merge_runs(SCB scb, USHORT n) /* Write the tail of the new run and return any unused space. */ - if (size = (BLOB_PTR *) q - (BLOB_PTR *) temp_run.run_buffer) + if ( (size = (BLOB_PTR *) q - (BLOB_PTR *) temp_run.run_buffer) ) seek = SORT_write_block(scb->scb_status_vector, temp_run.run_sfb, seek, (UCHAR *) temp_run.run_buffer, size); @@ -2467,7 +2475,7 @@ static void merge_runs(SCB scb, USHORT n) scb->scb_free_runs = run->run_next; if (run->run_buff_alloc) { - ALL_free(reinterpret_cast < char *>(run->run_buffer)); + MemoryPool::free_from_system(run->run_buffer); run->run_buff_alloc = 0; } temp_run.run_header.rmh_type = TYPE_RUN; @@ -2654,7 +2662,7 @@ static ULONG order(SCB scb) register SORT_RECORD *output; register SORT_PTR *lower_limit; SORT_RECORD **ptr; - SORTP *buffer; + SORTP* buffer = 0; SSHORT length; #ifndef STACK_EFFICIENT ULONG temp[1024]; @@ -2669,22 +2677,22 @@ static ULONG order(SCB scb) sort_record * >(scb->scb_last_record)); + try { #ifdef STACK_EFFICIENT buffer = - (ULONG *) ALL_malloc((SLONG) (scb->scb_longs * sizeof(ULONG)), - ERR_val); + (ULONG *) MemoryPool::malloc_from_system((SLONG) (scb->scb_longs * sizeof(ULONG))); #else if ((scb->scb_longs * sizeof(ULONG)) > sizeof(temp)) buffer = - (ULONG *) ALL_malloc((SLONG) (scb->scb_longs * sizeof(ULONG)), - ERR_val); + (ULONG *) MemoryPool::malloc_from_system((SLONG) (scb->scb_longs*sizeof(ULONG))); /* FREE: buffer is freed later in this routine */ else buffer = temp; #endif /* STACK_EFFICIENT */ - - if (!buffer) - error_memory(scb); + } catch(...) { + if (!buffer) + error_memory(scb); + } /* Check out the engine */ @@ -2769,7 +2777,7 @@ static ULONG order(SCB scb) if (buffer != temp) #endif if (buffer != NULL) - ALL_free(reinterpret_cast < char *>(buffer)); + MemoryPool::free_from_system(buffer); return (((SORTP *) output) - ((SORTP *) scb->scb_last_record)) / (scb->scb_longs - @@ -2793,12 +2801,12 @@ static void put_run(SCB scb) * **************************************/ RUN run; - ULONG n, records; + //ULONG n, records; - if (run = scb->scb_free_runs) + if ( (run = scb->scb_free_runs) ) scb->scb_free_runs = run->run_next; else { - run = (RUN) alloc(scb, (ULONG) sizeof(struct run)); + run = (RUN) sort_alloc(scb, (ULONG) sizeof(struct run)); /* FREE: run will be either on the scb_runs or scb_free_runs list, * which are freed in local_fini() */ } @@ -2929,7 +2937,7 @@ static void sort(SCB scb) q++; tl--; } - if ((p - *i) >= scb->scb_key_length) { + if ( ((p - *i) >= scb->scb_key_length) ) { #ifdef SCROLLABLE_CURSORS SORT_diddle_key((UCHAR *) * i, scb, FALSE); SORT_diddle_key((UCHAR *) * j, scb, FALSE); diff --git a/src/jrd/sort.h b/src/jrd/sort.h index 3fb89c76bc..62efaaee40 100644 --- a/src/jrd/sort.h +++ b/src/jrd/sort.h @@ -27,6 +27,10 @@ #include "../jrd/common.h" #include "../jrd/fil.h" +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + + #ifdef __cplusplus extern "C" { #endif @@ -275,7 +279,7 @@ typedef struct scb void *scb_dup_callback_arg; /* Duplicate handling callback arg */ struct dls *scb_dls; struct mrg *scb_merge_pool; /* ALLOC: pool of mrg blocks */ - struct att *scb_attachment; /* back pointer to attachment */ + class att *scb_attachment; /* back pointer to attachment */ SKD scb_description[1]; } *SCB; diff --git a/src/jrd/sqz.cpp b/src/jrd/sqz.cpp index 978e6335c9..ea856d90e9 100644 --- a/src/jrd/sqz.cpp +++ b/src/jrd/sqz.cpp @@ -422,7 +422,7 @@ USHORT SQZ_length(TDBB tdbb, SCHAR* data, int length, DCC dcc) end = &data[length]; length = 0; - while (count = end - data) + while ( (count = end - data) ) { start = data; @@ -455,7 +455,7 @@ USHORT SQZ_length(TDBB tdbb, SCHAR* data, int length, DCC dcc) if (control == end_control) { dcc->dcc_end = control; - if (dcc->dcc_next = tdbb->tdbb_default->plb_dccs) + if ( (dcc->dcc_next = tdbb->tdbb_default->plb_dccs) ) { dcc = dcc->dcc_next; tdbb->tdbb_default->plb_dccs = dcc->dcc_next; @@ -464,7 +464,7 @@ USHORT SQZ_length(TDBB tdbb, SCHAR* data, int length, DCC dcc) } else { - dcc->dcc_next = (DCC) ALLOCD(type_dcc); + dcc->dcc_next = new(*tdbb->tdbb_default) Dcc(); dcc = dcc->dcc_next; dcc->dcc_pool = tdbb->tdbb_default; } @@ -493,7 +493,7 @@ USHORT SQZ_length(TDBB tdbb, SCHAR* data, int length, DCC dcc) if (control == end_control) { dcc->dcc_end = control; - if (dcc->dcc_next = tdbb->tdbb_default->plb_dccs) + if ( (dcc->dcc_next = tdbb->tdbb_default->plb_dccs) ) { dcc = dcc->dcc_next; tdbb->tdbb_default->plb_dccs = dcc->dcc_next; @@ -502,7 +502,7 @@ USHORT SQZ_length(TDBB tdbb, SCHAR* data, int length, DCC dcc) } else { - dcc->dcc_next = (DCC) ALLOCD(type_dcc); + dcc->dcc_next = new(*tdbb->tdbb_default) Dcc(); dcc = dcc->dcc_next; dcc->dcc_pool = tdbb->tdbb_default; } diff --git a/src/jrd/sqz.h b/src/jrd/sqz.h index 40aa3de0f1..bbbd4736f3 100644 --- a/src/jrd/sqz.h +++ b/src/jrd/sqz.h @@ -24,12 +24,17 @@ #ifndef _JRD_SQZ_H_ #define _JRD_SQZ_H_ -typedef struct dcc { - struct blk dcc_header; - struct plb *dcc_pool; - struct dcc *dcc_next; /* Next block if overflow */ +#include "../jrd/all.h" +#include "../include/fb_blk.h" + +class Dcc : public pool_alloc +{ + public: + JrdMemoryPool *dcc_pool; + class Dcc *dcc_next; /* Next block if overflow */ SCHAR *dcc_end; /* End of control string */ SCHAR dcc_string[128]; -} *DCC; +}; +typedef Dcc *DCC; #endif /* _JRD_SQZ_H_ */ diff --git a/src/jrd/sqz_proto.h b/src/jrd/sqz_proto.h index 451775eabb..bdd17f814a 100644 --- a/src/jrd/sqz_proto.h +++ b/src/jrd/sqz_proto.h @@ -32,12 +32,12 @@ extern "C" { #endif extern USHORT SQZ_apply_differences(struct rec*, SCHAR*, SCHAR*); -extern USHORT SQZ_compress(struct dcc*, const SCHAR*, SCHAR*, int); -extern USHORT SQZ_compress_length(struct dcc*, SCHAR*, int); +extern USHORT SQZ_compress(class Dcc*, const SCHAR*, SCHAR*, int); +extern USHORT SQZ_compress_length(class Dcc*, SCHAR*, int); extern SCHAR* SQZ_decompress(const SCHAR*, USHORT, SCHAR*, const SCHAR*); extern USHORT SQZ_differences(SCHAR*, USHORT, SCHAR*, USHORT, SCHAR*, int); -extern void SQZ_fast(struct dcc*, SCHAR*, SCHAR*); -extern USHORT SQZ_length(TDBB, SCHAR*, int, struct dcc*); +extern void SQZ_fast(class Dcc*, SCHAR*, SCHAR*); +extern USHORT SQZ_length(TDBB, SCHAR*, int, class Dcc*); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/jrd/stats.epp b/src/jrd/stats.epp index 85e0599b13..9bbb678eb4 100644 --- a/src/jrd/stats.epp +++ b/src/jrd/stats.epp @@ -46,18 +46,18 @@ typedef struct stats { } *STATS; static STATS expand_stats(); -static print_line(); +static int print_line(); static SCHAR info_request[] = { - gds__info_read_seq_count, - gds__info_read_idx_count, - gds__info_insert_count, - gds__info_update_count, - gds__info_delete_count, - gds__info_backout_count, - gds__info_purge_count, - gds__info_expunge_count, - gds__info_end + gds_info_read_seq_count, + gds_info_read_idx_count, + gds_info_insert_count, + gds_info_update_count, + gds_info_delete_count, + gds_info_backout_count, + gds_info_purge_count, + gds_info_expunge_count, + gds_info_end }; static SCHAR *headers[] = { @@ -75,10 +75,7 @@ static int *database_handle; static int *request_handle; -stats_analyze(before, after, callback, arg) - STATS before, after; - int (*callback) (); - SCHAR *arg; +int stats_analyze(STATS before, STATS after, int(*callback)(), SCHAR *arg) { /************************************** * @@ -118,10 +115,7 @@ stats_analyze(before, after, callback, arg) } -stats_fetch(status_vector, db_handle, stats_ptr) - SLONG *status_vector; - int **db_handle; - STATS *stats_ptr; +int stats_fetch(SLONG *status_vector, int **db_handle, STATS *stats_ptr) { /************************************** * @@ -200,10 +194,7 @@ stats_fetch(status_vector, db_handle, stats_ptr) } -stats_print(db_handle, tr_handle, before, after) - int **db_handle; - int **tr_handle; - STATS before, after; +int stats_print(int **db_handle, int **tr_handle, STATS before, STATS after) { /************************************** * @@ -223,12 +214,11 @@ stats_print(db_handle, tr_handle, before, after) gds__trans = *tr_handle; init = 0; stats_analyze(before, after, print_line, &init); + return 0; } -static STATS expand_stats(ptr, count) - STATS *ptr; - SSHORT count; +static STATS expand_stats(STATS *ptr, SSHORT count) { /************************************** * @@ -271,12 +261,8 @@ static STATS expand_stats(ptr, count) } -static get_counts(status_vector, info, length, stats_ptr, item) - STATUS *status_vector; - SCHAR *info; - SSHORT length; - STATS *stats_ptr; - SSHORT item; +static int get_counts(STATUS *status_vector, SCHAR *info, SSHORT length, + STATS *stats_ptr, SSHORT item) { /************************************** * @@ -310,12 +296,8 @@ static get_counts(status_vector, info, length, stats_ptr, item) } -static print_line(arg, relation_id, count, headers, counts) - SCHAR *arg; - SSHORT relation_id; - SSHORT count; - SCHAR **headers; - SLONG *counts; +static int print_line(SCHAR *arg, SSHORT relation_id, SSHORT count, + SCHAR **headers, SLONG *counts) { /************************************** * @@ -348,12 +330,11 @@ static print_line(arg, relation_id, count, headers, counts) ib_printf("\n"); end_for; + return 0; } -static zap_longs(ptr, count) - SLONG *ptr; - SSHORT count; +static int zap_longs(SLONG *ptr, SSHORT count) { /************************************** * @@ -370,4 +351,6 @@ static zap_longs(ptr, count) do *ptr++ = 0; while (--count); + + return 0; } diff --git a/src/jrd/svc.cpp b/src/jrd/svc.cpp index 351cd57112..33fa1ff043 100644 --- a/src/jrd/svc.cpp +++ b/src/jrd/svc.cpp @@ -53,6 +53,7 @@ #include "../jrd/enc_proto.h" #include "../utilities/gsecswi.h" #include "../utilities/dbaswi.h" +#include "../common/memory/allocators.h" #ifdef SERVER_SHUTDOWN #include "../jrd/jrd_proto.h" #endif @@ -159,9 +160,6 @@ *status++ = isc_arg_end; } -extern "C" { - - /* Option block for service parameter block */ typedef struct spb { @@ -252,18 +250,18 @@ static SLONG SVC_locksem; static SLONG SVC_locksig; static struct ipccfg SVC_hdrtbl[] = { - ISCCFG_CONN_TIMEOUT, 0, &SVC_conn_timeout, 0, 0, - ISCCFG_DBCACHE, 0, &SVC_dbcache, 0, 0, - ISCCFG_DEADLOCK, 0, &SVC_deadlock, 0, 0, - ISCCFG_DUMMY_INTRVL, 0, &SVC_dummy_intrvl, 0, 0, - ISCCFG_LOCKSPIN, 0, &SVC_lockspin, 0, 0, - ISCCFG_LOCKHASH, 0, &SVC_lockhash, 0, 0, - ISCCFG_EVNTMEM, 0, &SVC_evntmem, 0, 0, - ISCCFG_LOCKORDER, 0, &SVC_lockorder, 0, 0, - ISCCFG_ANYLOCKMEM, 0, &SVC_anylockmem, 0, 0, - ISCCFG_ANYLOCKSEM, 0, &SVC_locksem, 0, 0, - ISCCFG_ANYLOCKSIG, 0, &SVC_locksig, 0, 0, - NULL, 0, NULL, 0, 0 + { ISCCFG_CONN_TIMEOUT, 0, &SVC_conn_timeout, 0, 0 }, + { ISCCFG_DBCACHE, 0, &SVC_dbcache, 0, 0 }, + { ISCCFG_DEADLOCK, 0, &SVC_deadlock, 0, 0 }, + { ISCCFG_DUMMY_INTRVL, 0, &SVC_dummy_intrvl, 0, 0 }, + { ISCCFG_LOCKSPIN, 0, &SVC_lockspin, 0, 0 }, + { ISCCFG_LOCKHASH, 0, &SVC_lockhash, 0, 0 }, + { ISCCFG_EVNTMEM, 0, &SVC_evntmem, 0, 0 }, + { ISCCFG_LOCKORDER, 0, &SVC_lockorder, 0, 0 }, + { ISCCFG_ANYLOCKMEM, 0, &SVC_anylockmem, 0, 0 }, + { ISCCFG_ANYLOCKSEM, 0, &SVC_locksem, 0, 0 }, + { ISCCFG_ANYLOCKSIG, 0, &SVC_locksig, 0, 0 }, + { NULL, 0, NULL, 0, 0 } }; #endif /* WIN_NT */ @@ -276,12 +274,12 @@ static BOOLEAN svc_initialized = FALSE, thd_initialized = FALSE; /* Service Functions */ #ifdef SUPERSERVER -extern int main_gbak(); -extern int main_gfix(); +extern int main_gbak(SVC service); +extern int main_gfix(SVC service); extern int main_wal_print(); extern int main_lock_print(); -extern int main_gstat(); -extern int main_gsec(); +extern int main_gstat(SVC service); +extern int main_gsec(SVC service); #define MAIN_GBAK main_gbak #define MAIN_GFIX main_gfix @@ -319,61 +317,61 @@ static const serv services[] = #if !(defined LINUX || defined FREEBSD || defined NETBSD) #ifndef NETWARE386 #ifdef WIN_NT - isc_action_max, "print_cache", "-svc", "bin/ibcachpr", NULL, 0, - isc_action_max, "print_locks", "-svc", "bin/iblockpr", NULL, 0, - isc_action_max, "start_cache", "-svc", "bin/ibcache", NULL, 0, + { isc_action_max, "print_cache", "-svc", "bin/ibcachpr", NULL, 0 }, + { isc_action_max, "print_locks", "-svc", "bin/iblockpr", NULL, 0 }, + { isc_action_max, "start_cache", "-svc", "bin/ibcache", NULL, 0 }, #else - isc_action_max, "print_cache", "-svc", "bin/gds_cache_print", NULL, 0, - isc_action_max, "print_locks", "-svc", "bin/gds_lock_print", NULL, 0, - isc_action_max, "start_cache", "-svc", "bin/gds_cache_manager", NULL, 0, + { isc_action_max, "print_cache", "-svc", "bin/gds_cache_print", NULL, 0 }, + { isc_action_max, "print_locks", "-svc", "bin/gds_lock_print", NULL, 0 }, + { isc_action_max, "start_cache", "-svc", "bin/gds_cache_manager", NULL, 0 }, #endif /* WIN_NT */ - isc_action_max, "analyze_database", "-svc", "bin/gstat", NULL, 0, - isc_action_max, "backup", "-svc -b", "bin/gbak", reinterpret_cast(MAIN_GBAK), 0, - isc_action_max, "create", "-svc -c", "bin/gbak", reinterpret_cast(MAIN_GBAK), 0, - isc_action_max, "restore", "-svc -r", "bin/gbak", reinterpret_cast(MAIN_GBAK), 0, - isc_action_max, "gdef", "-svc", "bin/gdef", NULL, 0, - isc_action_max, "gsec", "-svc", "bin/gsec", NULL, 0, - isc_action_max, "disable_journal", "-svc -disable", "bin/gjrn", NULL, 0, - isc_action_max, "dump_journal", "-svc -online_dump", "bin/gjrn", NULL, 0, - isc_action_max, "enable_journal", "-svc -enable", "bin/gjrn", NULL, 0, - isc_action_max, "monitor_journal", "-svc -console", "bin/gjrn", NULL, 0, - isc_action_max, "query_server", NULL, NULL, NULL, 0, - isc_action_max, "start_journal", "-svc -server", "bin/gjrn", NULL, 0, - isc_action_max, "stop_cache", "-svc -shut -cache", "bin/gfix", NULL, 0, - isc_action_max, "stop_journal", "-svc -console", "bin/gjrn", NULL, 0, + { isc_action_max, "analyze_database", "-svc", "bin/gstat", NULL, 0 }, + { isc_action_max, "backup", "-svc -b", "bin/gbak", reinterpret_cast(MAIN_GBAK), 0 }, + { isc_action_max, "create", "-svc -c", "bin/gbak", reinterpret_cast(MAIN_GBAK), 0 }, + { isc_action_max, "restore", "-svc -r", "bin/gbak", reinterpret_cast(MAIN_GBAK), 0 }, + { isc_action_max, "gdef", "-svc", "bin/gdef", NULL, 0 }, + { isc_action_max, "gsec", "-svc", "bin/gsec", NULL, 0 }, + { isc_action_max, "disable_journal", "-svc -disable", "bin/gjrn", NULL, 0 }, + { isc_action_max, "dump_journal", "-svc -online_dump", "bin/gjrn", NULL, 0 }, + { isc_action_max, "enable_journal", "-svc -enable", "bin/gjrn", NULL, 0 }, + { isc_action_max, "monitor_journal", "-svc -console", "bin/gjrn", NULL, 0 }, + { isc_action_max, "query_server", NULL, NULL, NULL, 0 }, + { isc_action_max, "start_journal", "-svc -server", "bin/gjrn", NULL, 0 }, + { isc_action_max, "stop_cache", "-svc -shut -cache", "bin/gfix", NULL, 0 }, + { isc_action_max, "stop_journal", "-svc -console", "bin/gjrn", NULL, 0 }, #else - isc_action_max, "analyze_database", "-svc", NULL, reinterpret_cast(MAIN_GSTAT), 0, - isc_action_max, "backup", "-svc -b", NULL, reinterpret_cast(MAIN_GSTAT), 0, - isc_action_max, "create", "-svc -c", NULL, reinterpret_cast(MAIN_GBAK), 0, - isc_action_max, "restore", "-svc -r", NULL, reinterpret_cast(MAIN_GBAK), 0, - isc_action_max, "gdef", "-svc", NULL, NULL, 0, - isc_action_max, "gsec", "-svc", NULL, NULL, 0, - isc_action_max, "print_wal", "-svc", NULL, reinterpret_cast(MAIN_WAL_PRINT), 0, - isc_action_max, "print_locks", "-svc", NULL, reinterpret_cast(MAIN_LOCK_PRINT), 0, + { isc_action_max, "analyze_database", "-svc", NULL, reinterpret_cast(MAIN_GSTAT), 0 }, + { isc_action_max, "backup", "-svc -b", NULL, reinterpret_cast(MAIN_GSTAT), 0 }, + { isc_action_max, "create", "-svc -c", NULL, reinterpret_cast(MAIN_GBAK), 0 }, + { isc_action_max, "restore", "-svc -r", NULL, reinterpret_cast(MAIN_GBAK), 0 }, + { isc_action_max, "gdef", "-svc", NULL, NULL, 0 }, + { isc_action_max, "gsec", "-svc", NULL, NULL, 0 }, + { isc_action_max, "print_wal", "-svc", NULL, reinterpret_cast(MAIN_WAL_PRINT), 0 }, + { isc_action_max, "print_locks", "-svc", NULL, reinterpret_cast(MAIN_LOCK_PRINT), 0 }, #endif /* NETWARE */ - isc_action_max, "anonymous", NULL, NULL, NULL, 0, + { isc_action_max, "anonymous", NULL, NULL, NULL, 0 }, /* NEW VERSION 2 calls, the name field MUST be different from those names above */ - isc_action_max, "service_mgr", NULL, NULL, NULL, 0, - isc_action_svc_backup, "Backup Database", NULL, "bin/gbak", reinterpret_cast(MAIN_GBAK), 0, - isc_action_svc_restore, "Restore Database", NULL, "bin/gbak", reinterpret_cast(MAIN_GBAK), 0, - isc_action_svc_repair, "Repair Database", NULL, "bin/gfix", reinterpret_cast(MAIN_GFIX), 0, - isc_action_svc_add_user, "Add User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0, - isc_action_svc_delete_user, "Delete User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0, - isc_action_svc_modify_user, "Modify User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0, - isc_action_svc_display_user, "Display User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0, - isc_action_svc_properties, "Database Properties", NULL, "bin/gfix", reinterpret_cast(MAIN_GFIX), 0, - isc_action_svc_lock_stats, "Lock Stats", NULL, NULL, reinterpret_cast(TEST_THREAD), 0, - isc_action_svc_db_stats, "Database Stats", NULL, NULL, reinterpret_cast(MAIN_GSTAT), 0, - isc_action_svc_get_ib_log, "Get Log File", NULL, NULL, reinterpret_cast(SVC_read_ib_log), 0, + { isc_action_max, "service_mgr", NULL, NULL, NULL, 0 }, + { isc_action_svc_backup, "Backup Database", NULL, "bin/gbak", reinterpret_cast(MAIN_GBAK), 0 }, + { isc_action_svc_restore, "Restore Database", NULL, "bin/gbak", reinterpret_cast(MAIN_GBAK), 0 }, + { isc_action_svc_repair, "Repair Database", NULL, "bin/gfix", reinterpret_cast(MAIN_GFIX), 0 }, + { isc_action_svc_add_user, "Add User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0 }, + { isc_action_svc_delete_user, "Delete User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0 }, + { isc_action_svc_modify_user, "Modify User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0 }, + { isc_action_svc_display_user, "Display User", NULL, "bin/gsec", reinterpret_cast(MAIN_GSEC), 0 }, + { isc_action_svc_properties, "Database Properties", NULL, "bin/gfix", reinterpret_cast(MAIN_GFIX), 0 }, + { isc_action_svc_lock_stats, "Lock Stats", NULL, NULL, reinterpret_cast(TEST_THREAD), 0 }, + { isc_action_svc_db_stats, "Database Stats", NULL, NULL, reinterpret_cast(MAIN_GSTAT), 0 }, + { isc_action_svc_get_ib_log, "Get Log File", NULL, NULL, reinterpret_cast(SVC_read_ib_log), 0 }, /* actions with no names are undocumented */ - isc_action_svc_set_config, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0, - isc_action_svc_default_config, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0, - isc_action_svc_set_env, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0, - isc_action_svc_set_env_lock, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0, - isc_action_svc_set_env_msg, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0, - 0, NULL, NULL, NULL, NULL, 0 + { isc_action_svc_set_config, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0 }, + { isc_action_svc_default_config, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0 }, + { isc_action_svc_set_env, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0 }, + { isc_action_svc_set_env_lock, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0 }, + { isc_action_svc_set_env_msg, NULL, NULL, NULL, reinterpret_cast(TEST_THREAD), 0 }, + { 0, NULL, NULL, NULL, NULL, 0 } }; #else /* LINUX: disallow services API for 6.0 Linux Classic */ isc_action_max, "anonymous", NULL, NULL, NULL, 0, @@ -459,9 +457,13 @@ extern int statistics(); #endif -SVC SVC_attach( - USHORT service_length, - TEXT * service_name, USHORT spb_length, SCHAR * spb) +extern "C" { + + +SVC SVC_attach(USHORT service_length, + TEXT* service_name, + USHORT spb_length, + SCHAR* spb) { /************************************** * @@ -473,19 +475,18 @@ SVC SVC_attach( * Connect to an Interbase service. * **************************************/ - TDBB tdbb; + CONST struct serv *serv; TEXT misc_buf[512]; - TEXT *switches, *misc; #ifndef SUPERSERVER TEXT service_path[MAXPATHLEN]; #endif SPB options; TEXT name[129] /*, project[33] */ ; - int id, group, node_id; - USHORT len, user_flag; - SVC service; - JMP_BUF env, *old_env; + int id = 0; + int group; + int node_id; + USHORT user_flag; /* If the service name begins with a slash, ignore it. */ @@ -498,8 +499,9 @@ SVC SVC_attach( strncpy(misc_buf, service_name, (int) service_length); misc_buf[service_length] = 0; } - else + else { strcpy(misc_buf, service_name); + } /* Find the service by looking for an exact match. */ @@ -517,73 +519,75 @@ SVC SVC_attach( 0); #endif - tdbb = GET_THREAD_DATA; + TDBB tdbb = GET_THREAD_DATA; /* If anything goes wrong, we want to be able to free any memory that may have been allocated. */ - misc = switches = NULL; - service = NULL; + TEXT* switches = 0; + TEXT* misc = 0; + SVC service = 0; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if ((misc != NULL) && (misc != misc_buf)) - gds__free((SLONG *) misc); - if ((switches != NULL)) - gds__free((SLONG *) switches); - if ((service != NULL) && (service->svc_status != NULL)) - gds__free((SLONG *) service->svc_status); - if (service != NULL) - gds__free((SLONG *) service); - ERR_punt(); - } + try { /* Process the service parameter block. */ - if (spb_length > sizeof(misc_buf)) + if (spb_length > sizeof(misc_buf)) { misc = (TEXT *) gds__alloc((SLONG) spb_length); - else + if (!misc) { + ERR_post(isc_virmemexh, 0); + } + } else { misc = misc_buf; -/* FREE: by SETJMP handler */ - if (!misc) /* NOMEM: */ - ERR_post(isc_virmemexh, 0); - get_options(reinterpret_cast < UCHAR * >(spb), spb_length, misc, - &options); + } + + get_options(reinterpret_cast(spb), spb_length, misc, &options); /* Perhaps checkout the user in the security database. */ - if (!strcmp(serv->serv_name, "anonymous")) + if (!strcmp(serv->serv_name, "anonymous")) { user_flag = SVC_user_none; - else { + } else { if (!options.spb_user_name) - ERR_post(isc_service_att_err, isc_arg_gds, isc_svcnouser, 0); /* user name and password are required - while attaching to the services - manager */ + { + // user name and password are required while + // attaching to the services manager + ERR_post(isc_service_att_err, isc_arg_gds, isc_svcnouser, 0); + } if (options.spb_user_name || id == -1) - PWD_verify_user(name, options.spb_user_name, options.spb_password, - options.spb_password_enc, &id, &group, &node_id); + { + PWD_verify_user(name, + options.spb_user_name, + options.spb_password, + options.spb_password_enc, + &id, + &group, + &node_id); + } /* Check that the validated user has the authority to access this service */ - if (STRICMP(options.spb_user_name, SYSDBA_USER_NAME)) + if (STRICMP(options.spb_user_name, SYSDBA_USER_NAME)) { user_flag = SVC_user_any; - else + } else { user_flag = SVC_user_dba | SVC_user_any; + } } /* Allocate a buffer for the service switches, if any. Then move them in. */ - len = ((serv->serv_std_switches) ? strlen(serv->serv_std_switches) : 0) + + USHORT len = ((serv->serv_std_switches) ? strlen(serv->serv_std_switches) : 0) + ((options.spb_command_line) ? strlen(options.spb_command_line) : 0) + 1; if (len > 1) + { if ((switches = (TEXT *) gds__alloc((SLONG) len)) == NULL) + { /* FREE: by SETJMP handler */ ERR_post(isc_virmemexh, 0); + } + } if (switches) *switches = 0; @@ -597,7 +601,8 @@ SVC SVC_attach( /* Services operate outside of the context of databases. Therefore we cannot use the JRD allocator. */ - service = (SVC) gds__alloc((SLONG) (sizeof(struct svc))); +// service = (SVC) gds__alloc((SLONG) (sizeof(struct svc))); + service = new(*FB_MemoryPool) svc; /* FREE: by SETJMP handler */ if (!service) ERR_post(isc_virmemexh, 0); @@ -613,9 +618,9 @@ SVC SVC_attach( memset((void *) service->svc_status, 0, ISC_STATUS_LENGTH * sizeof(STATUS)); - service->svc_header.blk_type = type_svc; - service->svc_header.blk_pool_id = 0; - service->svc_header.blk_length = 0; + //service->blk_type = type_svc; + //service->blk_pool_id = 0; + //service->blk_length = 0; service->svc_service = serv; service->svc_resp_buf = service->svc_resp_ptr = NULL; service->svc_resp_buf_len = service->svc_resp_len = 0; @@ -640,18 +645,16 @@ SVC SVC_attach( * decrypt function). */ if (options.spb_password) { - UCHAR *p, *s = - reinterpret_cast < UCHAR * >(service->svc_enc_password); - int l; - - p = (UCHAR *) ENC_crypt(options.spb_password, PASSWORD_SALT) + 2; - l = strlen((char *) p); + UCHAR* s = reinterpret_cast(service->svc_enc_password); + UCHAR* p = (UCHAR *) ENC_crypt(options.spb_password, PASSWORD_SALT) + 2; + int l = strlen((char *) p); MOVE_FASTER(p, s, l); service->svc_enc_password[l] = 0; } - if (options.spb_password_enc) + if (options.spb_password_enc) { strcpy(service->svc_enc_password, options.spb_password_enc); + } /* If an executable is defined for the service, try to fork a new process. * Only do this if we are working with a version 1 service */ @@ -683,9 +686,27 @@ SVC SVC_attach( #endif } - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (misc != misc_buf) + if (misc != misc_buf) { gds__free((SLONG *) misc); + } + + } // try + catch (...) { + if (misc && misc != misc_buf) { + gds__free((SLONG *) misc); + } + if (switches) { + gds__free((SLONG *) switches); + } + if (service) { + if (service->svc_status) { + gds__free((SLONG *) service->svc_status); + } +// gds__free((SLONG *) service); + delete service; + } + ERR_punt(); + } return service; } @@ -836,7 +857,6 @@ void SVC_putc(SVC service, UCHAR ch) **************************************/ SCHAR item, *items, *end_items, *end; char buffer[256]; - UCHAR dbbuf[1024]; USHORT l, length, version, get_flags; STATUS *status; USHORT timeout; @@ -930,13 +950,14 @@ void SVC_putc(SVC service, UCHAR ch) #ifdef SERVER_SHUTDOWN case isc_info_svc_svr_db_info: { + UCHAR dbbuf[1024]; USHORT num_dbs = 0, num = 0; USHORT num_att = 0; TEXT *ptr, *ptr2; *info++ = item; ptr = - JRD_num_attachments(reinterpret_cast < char *>(dbbuf), + JRD_num_attachments(reinterpret_cast(dbbuf), sizeof(dbbuf), JRD_info_dbnames, &num_att, &num_dbs); /* Move the number of attachments into the info buffer */ @@ -1241,7 +1262,7 @@ void SVC_putc(SVC service, UCHAR ch) break; case isc_info_svc_response_more: - if (l = length = service->svc_resp_len) + if ( (l = length = service->svc_resp_len) ) length = MIN(end - (info + 4), l); if (! (info = @@ -1355,8 +1376,6 @@ void SVC_query(SVC service, SCHAR item, *items, *end_items, *end, *p, *q; UCHAR buffer[256]; USHORT l, length, version, get_flags; - USHORT num_att = 0; - USHORT num_dbs = 0; USHORT timeout; THREAD_EXIT; @@ -1420,24 +1439,30 @@ void SVC_query(SVC service, #ifdef SERVER_SHUTDOWN case isc_info_svc_svr_db_info: - JRD_num_attachments(NULL, 0, 0, &num_att, &num_dbs); - length = INF_convert(num_att, reinterpret_cast < char *>(buffer)); - if (! - (info = - INF_put_item(item, length, - reinterpret_cast < char *>(buffer), info, - end))) { - THREAD_ENTER; - return; - } - length = INF_convert(num_dbs, reinterpret_cast < char *>(buffer)); - if (! - (info = - INF_put_item(item, length, - reinterpret_cast < char *>(buffer), info, - end))) { - THREAD_ENTER; - return; + { + USHORT num_att = 0; + USHORT num_dbs = 0; + JRD_num_attachments(NULL, 0, 0, &num_att, &num_dbs); + length = INF_convert(num_att, reinterpret_cast < char *>(buffer)); + info = INF_put_item(item, + length, + reinterpret_cast(buffer), + info, + end); + if (!info) { + THREAD_ENTER; + return; + } + length = INF_convert(num_dbs, reinterpret_cast < char *>(buffer)); + info = INF_put_item(item, + length, + reinterpret_cast(buffer), + info, + end); + if (!info) { + THREAD_ENTER; + return; + } } break; @@ -1751,7 +1776,7 @@ void SVC_query(SVC service, break; case isc_info_svc_response_more: - if (l = length = service->svc_resp_len) + if ( (l = length = service->svc_resp_len) ) length = MIN(end - (info + 4), l); if (!(info = INF_put_item(item, length, @@ -1844,9 +1869,7 @@ void *SVC_start(SVC service, USHORT spb_length, SCHAR * spb) TDBB tdbb; CONST struct serv *serv; USHORT svc_id; - JMP_BUF env, *old_env; - USHORT argc; - TEXT **arg, *p, *q, *tmp_ptr = NULL; + TEXT* tmp_ptr = NULL; USHORT opt_switch_len = 0; BOOLEAN flag_spb_options = FALSE; #ifndef SUPERSERVER @@ -1907,17 +1930,7 @@ void *SVC_start(SVC service, USHORT spb_length, SCHAR * spb) tdbb = GET_THREAD_DATA; - old_env = (JMP_BUF *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; - - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (service->svc_switches != NULL) - gds__free((SLONG *) service->svc_switches); - if (service != NULL) - gds__free((SLONG *) service); - ERR_punt(); - } + try { /* Only need to add username and password information to those calls which need * to make a database connection @@ -2018,7 +2031,12 @@ void *SVC_start(SVC service, USHORT spb_length, SCHAR * spb) #else /* Break up the command line into individual arguments. */ - if (service->svc_switches) { + if (service->svc_switches) + { + USHORT argc; + TEXT* p; + TEXT* q; + TEXT** arg; for (argc = 2, p = service->svc_switches; *p;) { if (*p == ' ') { argc++; @@ -2048,7 +2066,7 @@ void *SVC_start(SVC service, USHORT spb_length, SCHAR * spb) if (!arg) /* NOMEM: */ ERR_post(isc_virmemexh, 0); - *arg++ = reinterpret_cast < TEXT * >(serv->serv_thd); + *arg++ = (TEXT *)(serv->serv_thd); p = q = service->svc_switches; while (*q == ' ') @@ -2131,8 +2149,15 @@ void *SVC_start(SVC service, USHORT spb_length, SCHAR * spb) * from waiting infinitely if the client goes away */ while (!(service->svc_flags & SVC_detached)) { - if (ISC_event_wait - (1, &evnt_ptr, &count, 60 * 1000, (FPTR_VOID) 0, 0)) continue; + if (ISC_event_wait(1, + &evnt_ptr, + &count, + 60 * 1000, + (FPTR_VOID) 0, + 0)) + { + continue; + } else; /* the event was posted */ break; } @@ -2141,15 +2166,29 @@ void *SVC_start(SVC service, USHORT spb_length, SCHAR * spb) THREAD_ENTER; } else - ERR_post(isc_svcnotdef, isc_arg_string, - SVC_err_string(const_cast < char *>(serv->serv_name), - strlen(serv->serv_name)), 0); + { + ERR_post(isc_svcnotdef, + isc_arg_string, + SVC_err_string(const_cast(serv->serv_name), + strlen(serv->serv_name)), + 0); + } #endif /* SUPERSERVER */ + } // try + catch (...) { + if (service->svc_switches) { + gds__free((SLONG *) service->svc_switches); + } + if (service) { +// gds__free((SLONG *) service); + delete service; + } + ERR_punt(); + } - tdbb->tdbb_setjmp = (UCHAR *) old_env; - return reinterpret_cast < void *>(reserved); + return reinterpret_cast(reserved); } @@ -2198,10 +2237,10 @@ void SVC_read_ib_log(SVC service) #ifdef SUPERSERVER *status++ = isc_sys_request; if (!file) { - SVC_STATUS_ARG(status, isc_arg_string, "ib_fopen"); + SVC_STATUS_ARG(status, isc_arg_string, (void*)"ib_fopen"); } else { - SVC_STATUS_ARG(status, isc_arg_string, "ib_fgets"); + SVC_STATUS_ARG(status, isc_arg_string, (void*)"ib_fgets"); } *status++ = SYS_ARG; *status++ = errno; @@ -2226,9 +2265,12 @@ void SVC_read_ib_log(SVC service) } -static void get_options( - UCHAR * spb, - USHORT spb_length, TEXT * scratch, SPB * options) +} // extern "C" + +static void get_options(UCHAR* spb, + USHORT spb_length, + TEXT* scratch, + SPB* options) { /************************************** * @@ -2307,7 +2349,7 @@ static TEXT *get_string_parameter(UCHAR ** spb_ptr, TEXT ** opt_ptr) opt = *opt_ptr; spb = *spb_ptr; - if (l = *spb++) + if ( (l = *spb++) ) do *opt++ = *spb++; while (--l); @@ -2879,7 +2921,7 @@ static void service_fork(void (*service_executable) (), SVC service) if (!arg) /* NOMEM: */ ERR_post(isc_virmemexh, 0); - *arg++ = reinterpret_cast < TEXT * >(service_executable); + *arg++ = (TEXT *)(service_executable); /* Break up the command line into individual arguments. */ @@ -3208,7 +3250,7 @@ static void service_get( #endif #endif int c; - USHORT timed_out; + //USHORT timed_out; SCHAR *buf; SSHORT iter = 0; int errno_save; @@ -3353,7 +3395,8 @@ void SVC_cleanup(SVC service) if (service->svc_status != NULL) gds__free((SLONG *) service->svc_status); - gds__free((SLONG *) service); +// gds__free((SLONG *) service); + delete service; } @@ -3481,7 +3524,8 @@ static USHORT process_switches( USHORT len, total; TEXT *p, *sw; ISC_USHORT svc_action; - BOOLEAN found = FALSE, lic_key = FALSE, lic_id = FALSE; + BOOLEAN found = FALSE; + //BOOLEAN lic_key = FALSE, lic_id = FALSE; if (spb_length == 0) return 0; @@ -3892,5 +3936,3 @@ void test_cmd(USHORT spb_length, SCHAR * spb, TEXT ** switches) } #endif - -} // extern "C" diff --git a/src/jrd/svc.h b/src/jrd/svc.h index 40b554aaf8..29ebe18cee 100644 --- a/src/jrd/svc.h +++ b/src/jrd/svc.h @@ -23,12 +23,25 @@ #ifndef JRD_SVC_H #define JRD_SVC_H + +// TMN: To be removed once the C++ conversion is completed +#ifdef INCLUDE_OLD_FB_BLK +#error You can not include both old_fb_blk.h and this file +#endif + #include "../jrd/pwd.h" #include "../jrd/isc.h" #include "../jrd/svc_undoc.h" #include "../jrd/svc_proto.h" #include "../jrd/isc_s_proto.h" + +#ifndef JRD_IBASE_H #include "../jrd/ibase.h" /* needed for the C++ version of SVC_STATUS_ARG */ +#endif + +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" + #ifdef __cplusplus extern "C" { @@ -98,7 +111,7 @@ extern "C" { #ifdef __cplusplus -inline SVC_STATUS_ARG(STATUS * &status, USHORT type, void *value) +inline void SVC_STATUS_ARG(STATUS*& status, USHORT type, void* value) { if (value) { @@ -111,8 +124,8 @@ inline SVC_STATUS_ARG(STATUS * &status, USHORT type, void *value) case isc_arg_string: *status++ = type; *status++ = (STATUS) - SVC_err_string(reinterpret_cast < char *>(value), - strlen(static_cast < const char *>(value))); + SVC_err_string(reinterpret_cast(value), + strlen(reinterpret_cast(value))); break; default: break; @@ -138,7 +151,7 @@ inline SVC_STATUS_ARG(STATUS * &status, USHORT type, void *value) #endif /* __cplusplus */ -#endif +#endif /* SUPERSERVER */ #define CK_SPACE_FOR_NUMERIC {{if ((info + 1 + sizeof (ULONG)) > end) \ @@ -150,9 +163,9 @@ inline SVC_STATUS_ARG(STATUS * &status, USHORT type, void *value) }}} /* Service manager block */ -typedef struct svc +class svc : public pool_alloc { - struct blk svc_header; +public: SLONG svc_handle; /* "handle" of process/thread running service */ STATUS* svc_status; /* status vector for svc_handle */ void* svc_input; /* input to service */ @@ -176,7 +189,8 @@ typedef struct svc TEXT svc_enc_password[MAX_PASSWORD_ENC_LENGTH]; TEXT svc_reserved[1]; TEXT* svc_switches; -} *SVC; +}; +typedef svc *SVC; typedef struct serv { diff --git a/src/jrd/svc_proto.h b/src/jrd/svc_proto.h index 5aa3eec467..e851936aa6 100644 --- a/src/jrd/svc_proto.h +++ b/src/jrd/svc_proto.h @@ -28,16 +28,16 @@ extern "C" { #endif -extern struct svc *SVC_attach(USHORT, TEXT *, USHORT, SCHAR *); -extern void SVC_cleanup(struct svc *); -extern void SVC_detach(struct svc *); -extern void SVC_fprintf(struct svc *, const SCHAR *, ...); -extern void SVC_putc(struct svc*, UCHAR); -extern void SVC_query(struct svc*, USHORT, SCHAR*, USHORT, SCHAR*, USHORT, SCHAR*); -extern STATUS SVC_query2(struct svc*, struct tdbb*, USHORT, SCHAR *, USHORT, SCHAR*, USHORT, SCHAR*); -extern void *SVC_start(struct svc*, USHORT, SCHAR*); -extern void SVC_finish(struct svc*, USHORT); -extern void SVC_read_ib_log(struct svc*); +extern class svc *SVC_attach(USHORT, TEXT *, USHORT, SCHAR *); +extern void SVC_cleanup(class svc *); +extern void SVC_detach(class svc *); +extern void SVC_fprintf(class svc *, const SCHAR *, ...); +extern void SVC_putc(class svc*, UCHAR); +extern void SVC_query(class svc*, USHORT, SCHAR*, USHORT, SCHAR*, USHORT, SCHAR*); +extern STATUS SVC_query2(class svc*, struct tdbb*, USHORT, SCHAR *, USHORT, SCHAR*, USHORT, SCHAR*); +extern void *SVC_start(class svc*, USHORT, SCHAR*); +extern void SVC_finish(class svc*, USHORT); +extern void SVC_read_ib_log(class svc*); extern TEXT *SVC_err_string(TEXT*, USHORT); #ifdef SERVER_SHUTDOWN diff --git a/src/jrd/sym.cpp b/src/jrd/sym.cpp index eb6a0f79f7..f603b1f465 100644 --- a/src/jrd/sym.cpp +++ b/src/jrd/sym.cpp @@ -35,7 +35,7 @@ extern "C" { -static SSHORT hash(register SCHAR *); +static SSHORT hash_func(register SCHAR *); void SYM_insert(register SYM symbol) @@ -56,7 +56,7 @@ void SYM_insert(register SYM symbol) dbb = GET_DBB; - h = hash(symbol->sym_string); + h = hash_func(symbol->sym_string); for (old = dbb->dbb_hash_table[h]; old; old = old->sym_collision) if (!strcmp(symbol->sym_string, old->sym_string)) { @@ -87,7 +87,7 @@ SYM SYM_lookup(register TEXT * string) dbb = GET_DBB; - for (symbol = dbb->dbb_hash_table[hash(string)]; symbol; + for (symbol = dbb->dbb_hash_table[hash_func(string)]; symbol; symbol = symbol->sym_collision) if (!strcmp(string, symbol->sym_string)) return symbol; @@ -113,11 +113,11 @@ void SYM_remove(register SYM symbol) dbb = GET_DBB; - h = hash(symbol->sym_string); + h = hash_func(symbol->sym_string); for (next = &dbb->dbb_hash_table[h]; *next; next = &(*next)->sym_collision) if (symbol == *next) - if (homonym = symbol->sym_homonym) { + if ( (homonym = symbol->sym_homonym) ) { homonym->sym_collision = symbol->sym_collision; *next = homonym; return; @@ -137,7 +137,7 @@ void SYM_remove(register SYM symbol) } -static SSHORT hash(register SCHAR * string) +static SSHORT hash_func(register SCHAR * string) { /************************************** * @@ -157,7 +157,7 @@ static SSHORT hash(register SCHAR * string) value = 0; - while (c = *string++) + while ( (c = *string++) ) value = (value << 1) + UPPER7(c); return ((value >= 0) ? value : -value) % HASH_SIZE; diff --git a/src/jrd/thd.cpp b/src/jrd/thd.cpp index 993cc4cf4d..89442545c8 100644 --- a/src/jrd/thd.cpp +++ b/src/jrd/thd.cpp @@ -461,7 +461,7 @@ int THD_mutex_destroy(MUTX_T * mutex) #else - return pthread_mutex_destroy(mutex); + return pthread_mutex_destroy(&mutex->mutx_mutex); #endif /* HP10 */ @@ -493,7 +493,7 @@ int THD_mutex_init(MUTX_T * mutex) #else - return pthread_mutex_init(mutex, NULL); + return pthread_mutex_init(&mutex->mutx_mutex, NULL); #endif /* HP10 */ } @@ -524,7 +524,7 @@ int THD_mutex_lock(MUTX_T * mutex) #else - return pthread_mutex_lock(mutex); + return pthread_mutex_lock(&mutex->mutx_mutex); #endif /* HP10 */ } @@ -555,7 +555,7 @@ int THD_mutex_unlock(MUTX_T * mutex) #else - return pthread_mutex_unlock(mutex); + return pthread_mutex_unlock(&mutex->mutx_mutex); #endif /* HP10 */ } @@ -2059,7 +2059,7 @@ static int thread_start( pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); #endif - state = pthread_create(&thread, &pattr, routine, arg); + state = pthread_create(&thread, &pattr, (void*(*)(void*))routine, arg); pthread_attr_destroy(&pattr); return state; diff --git a/src/jrd/thd.h b/src/jrd/thd.h index 94e822e973..caf034ab46 100644 --- a/src/jrd/thd.h +++ b/src/jrd/thd.h @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: thd.h,v 1.2 2001-07-12 05:46:05 bellardo Exp $ +$Id: thd.h,v 1.3 2001-12-24 02:50:52 tamlin Exp $ */ #ifndef _JRD_THD_H_ diff --git a/src/jrd/thd_win32.cpp b/src/jrd/thd_win32.cpp index c5e811913a..dd278b1e98 100644 --- a/src/jrd/thd_win32.cpp +++ b/src/jrd/thd_win32.cpp @@ -522,7 +522,10 @@ static unsigned int __stdcall win32_thread_start_thunk(void* p) { const thunk_thread_start_t* pArg = reinterpret_cast(p); - return (unsigned int) ((*pArg->pfn)(pArg->arg)); + int (*pfn)(void*) = pArg->pfn; + void* arg = pArg->arg; + free(p); + return (unsigned int) ((*pfn)(arg)); } #endif @@ -556,18 +559,28 @@ static int thread_start(FPTR_INT_VOID_PTR routine, * CreateThread() can lead to memory leaks caused by C-runtime library. * Advanced Windows by Richter pg. # 109. */ +#if 0 #pragma FB_COMPILER_MESSAGE("Fix! Bad, bad, bad function ptr type cast!!!") - thunk_thread_start_t thread_start_arg = - { - routine, - arg - }; + + thunk_thread_start_t* thread_start_arg = + (thunk_thread_start_t*)malloc(sizeof(thunk_thread_start_t)); + thread_start_arg->pfn = routine; + thread_start_arg->arg = arg; unsigned long real_handle = _beginthreadex(NULL, 0, &win32_thread_start_thunk, - &thread_start_arg, + thread_start_arg, create, reinterpret_cast(&thread_id)); +#else + unsigned long real_handle = _beginthreadex(NULL, + 0, + reinterpret_cast(routine), + arg, + create, + reinterpret_cast(&thread_id)); +#endif + if (!real_handle) { return GetLastError(); } diff --git a/src/jrd/time.h b/src/jrd/time.h index 68b27285fd..b4d6fa85ad 100644 --- a/src/jrd/time.h +++ b/src/jrd/time.h @@ -28,6 +28,9 @@ #ifdef HAVE_TIME_H #include +#ifdef DARWIN +#include +#endif #endif #ifdef HAVE_SYS_TIME_H diff --git a/src/jrd/tpc.cpp b/src/jrd/tpc.cpp index a3e1762ef2..2ffa2a1128 100644 --- a/src/jrd/tpc.cpp +++ b/src/jrd/tpc.cpp @@ -240,7 +240,7 @@ int TPC_snapshot_state(TDBB tdbb, SLONG number) then we know it is still active */ MOVE_CLEAR(&temp_lock, sizeof(struct lck)); - temp_lock.lck_header.blk_type = type_lck; + //temp_lock.blk_type = type_lck; temp_lock.lck_dbb = dbb; temp_lock.lck_type = LCK_tra; temp_lock.lck_owner_handle = @@ -305,11 +305,11 @@ void TPC_update_cache(TDBB tdbb, TIP tip_page, SLONG sequence) any tip cache pages we can release--this is cheaper and easier than finding out when a TIP page is dropped */ - while (tip_cache = dbb->dbb_tip_cache) + while ( (tip_cache = dbb->dbb_tip_cache) ) if (dbb->dbb_oldest_transaction >= tip_cache->tpc_base + trans_per_tip) { dbb->dbb_tip_cache = tip_cache->tpc_next; - ALL_release(reinterpret_cast < frb * >(tip_cache)); + delete tip_cache; } else break; @@ -356,7 +356,7 @@ static TPC allocate_tpc(TDBB tdbb, ULONG base) /* allocate a TIP cache block with enough room for all desired transactions */ - tip_cache = (TPC) ALLOCPV(type_tpc, trans_per_tip / 4); + tip_cache = new(*dbb->dbb_permanent, trans_per_tip / 4) tpc(); tip_cache->tpc_base = base; return tip_cache; diff --git a/src/jrd/tpc.h b/src/jrd/tpc.h index a97637fa91..a40c79d627 100644 --- a/src/jrd/tpc.h +++ b/src/jrd/tpc.h @@ -24,11 +24,13 @@ #ifndef _JRD_TPC_H_ #define _JRD_TPC_H_ -typedef struct tpc { - struct blk tpc_header; +class tpc : public pool_alloc_rpt +{ + public: struct tpc *tpc_next; SLONG tpc_base; /* id of first transaction in this block */ UCHAR tpc_transactions[1]; /* two bits per transaction */ -} *TPC; +}; +typedef tpc *TPC; #endif /* _JRD_TPC_H_ */ diff --git a/src/jrd/tra.cpp b/src/jrd/tra.cpp index 0f17224455..0769700303 100644 --- a/src/jrd/tra.cpp +++ b/src/jrd/tra.cpp @@ -175,14 +175,14 @@ BOOLEAN TRA_active_transactions(TDBB tdbb, DBB dbb) base = oldest & ~TRA_MASK; - trans = (TRA) ALLOCPV(type_tra, (number - base + TRA_MASK) / 4); + trans = new(*dbb->dbb_permanent, (number - base + TRA_MASK) / 4) tra(); /* Build transaction bitmap to scan for active transactions. */ TRA_get_inventory(tdbb, trans->tra_transactions, base, number); MOVE_CLEAR(&temp_lock, sizeof(struct lck)); - temp_lock.lck_header.blk_type = type_lck; + temp_lock.blk_type = type_lck; temp_lock.lck_dbb = dbb; temp_lock.lck_object = (BLK) trans; temp_lock.lck_type = LCK_tra; @@ -198,14 +198,14 @@ BOOLEAN TRA_active_transactions(TDBB tdbb, DBB dbb) if (state == tra_active) { temp_lock.lck_key.lck_long = active; if (!LCK_lock_non_blocking(tdbb, &temp_lock, LCK_read, FALSE)) { - ALL_release(trans); + delete trans; return TRUE; } LCK_release(tdbb, &temp_lock); } } - ALL_release(trans); + delete trans; return FALSE; #endif } @@ -505,13 +505,11 @@ void TRA_extend_tip(TDBB tdbb, ULONG sequence, WIN * precedence_window) /* Link into internal data structures */ if (!(vector = dbb->dbb_t_pages)) - vector = (VCL) ALLOCPV(type_vcl, sequence + 1); - else if (sequence >= vector->vcl_count) - vector = - (VCL) ALL_extend(reinterpret_cast < blk ** >(&dbb->dbb_t_pages), - sequence + 1); + vector = vcl::newVector(*dbb->dbb_permanent, sequence + 1); + else if (sequence >= vector->count()) + vector->resize(sequence + 1); - vector->vcl_long[sequence] = window.win_page; + (*vector)[sequence] = window.win_page; /* Write into pages relation */ @@ -602,7 +600,7 @@ void TRA_get_inventory(TDBB tdbb, UCHAR * bit_vector, ULONG base, ULONG top) /* move the first page into the bit vector */ - if (p = bit_vector) { + if ( (p = bit_vector) ) { l = base % trans_per_tip; q = tip->tip_transactions + TRANS_OFFSET(l); l = TRANS_OFFSET(MIN((top + TRA_MASK - base), trans_per_tip - l)); @@ -748,7 +746,7 @@ void TRA_init(TDBB tdbb) dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - dbb->dbb_sys_trans = trans = (TRA) ALLOCPV(type_tra, 0); + dbb->dbb_sys_trans = trans = new(*dbb->dbb_permanent, 0) tra(); trans->tra_flags |= TRA_system | TRA_ignore_limbo; trans->tra_pool = dbb->dbb_permanent; } @@ -824,7 +822,7 @@ void TRA_post_resources(TDBB tdbb, TRA transaction, RSC resources) * **************************************/ RSC rsc, tra_rsc, new_rsc; - PLB old_pool; + JrdMemoryPool *old_pool; SET_TDBB(tdbb); @@ -837,7 +835,7 @@ void TRA_post_resources(TDBB tdbb, TRA transaction, RSC resources) tra_rsc = tra_rsc->rsc_next) if (rsc->rsc_id == tra_rsc->rsc_id) break; if (!tra_rsc) { - new_rsc = (RSC) ALLOCD(type_rsc); + new_rsc = new(*tdbb->tdbb_default) Rsc(); new_rsc->rsc_next = transaction->tra_resources; transaction->tra_resources = new_rsc; new_rsc->rsc_id = rsc->rsc_id; @@ -860,6 +858,8 @@ void TRA_post_resources(TDBB tdbb, TRA transaction, RSC resources) } #endif break; + default: /* Shut up compiler warning */ + break; } } } @@ -885,7 +885,8 @@ BOOLEAN TRA_precommited(TDBB tdbb, SLONG old_number, SLONG new_number) * the vector. * **************************************/ - SLONG *p, *end, *zp; + vcl::iterator p, end; + SLONG *zp; VCL vector; DBB dbb; @@ -896,12 +897,11 @@ BOOLEAN TRA_precommited(TDBB tdbb, SLONG old_number, SLONG new_number) if (!(vector = dbb->dbb_pc_transactions)) { if (old_number == new_number) return FALSE; - vector = dbb->dbb_pc_transactions = (VCL) ALLOCPV(type_vcl, 1); - vector->vcl_count = 1; + vector = dbb->dbb_pc_transactions = vcl::newVector(*dbb->dbb_permanent, 1); } zp = 0; - for (p = vector->vcl_long, end = p + vector->vcl_count; p < end; p++) { + for (p = vector->begin(), end = vector->end(); p < end; p++) { if (*p == old_number) return (*p = new_number) ? TRUE : FALSE; if (!zp && !*p) @@ -913,11 +913,8 @@ BOOLEAN TRA_precommited(TDBB tdbb, SLONG old_number, SLONG new_number) if (zp) *zp = new_number; else { - vector = - (VCL) ALL_extend(reinterpret_cast < - blk ** >(&dbb->dbb_pc_transactions), - vector->vcl_count + 1); - vector->vcl_long[vector->vcl_count - 1] = new_number; + vector->resize(vector->count() + 1); + (*vector)[vector->count() - 1] = new_number; } return TRUE; @@ -1026,8 +1023,8 @@ TRA TRA_reconnect(TDBB tdbb, UCHAR * id, USHORT length) ERR_post(isc_read_only_database, 0); - tdbb->tdbb_default = ALL_pool(); - trans = (TRA) ALLOCDV(type_tra, 0); + tdbb->tdbb_default = new(*dbb->dbb_permanent) JrdMemoryPool; + trans = new(*tdbb->tdbb_default, 0) tra(); trans->tra_pool = tdbb->tdbb_default; trans->tra_number = gds__vax_integer(id, length); trans->tra_flags |= TRA_prepared | TRA_reconnected | TRA_write; @@ -1049,7 +1046,7 @@ TRA TRA_reconnect(TDBB tdbb, UCHAR * id, USHORT length) } number = trans->tra_number; - ALL_rlpool(trans->tra_pool); + delete trans->tra_pool; gds__msg_lookup(0, JRD_BUGCHK, message, sizeof(text), text, &flags); @@ -1081,11 +1078,11 @@ void TRA_release_transaction(TDBB tdbb, TRA transaction) * **************************************/ VEC vector; - LCK *lock; + vec::iterator lock; TRA *ptr; RSC rsc; USHORT i; - PLB tra_pool; + JrdMemoryPool *tra_pool; SET_TDBB(tdbb); @@ -1112,11 +1109,11 @@ void TRA_release_transaction(TDBB tdbb, TRA transaction) /* Release the locks associated with the transaction */ - if (vector = transaction->tra_relation_locks) - for (i = 0, lock = (LCK *) vector->vec_object; i < vector->vec_count; + if ( (vector = transaction->tra_relation_locks) ) + for (i = 0, lock = vector->begin(); i < vector->count(); i++, lock++) if (*lock) - LCK_release(tdbb, *lock); + LCK_release(tdbb, (LCK)*lock); ++transaction->tra_use_count; if (transaction->tra_lock) @@ -1140,8 +1137,8 @@ void TRA_release_transaction(TDBB tdbb, TRA transaction) /* Release the transaction pool. */ - if (tra_pool = transaction->tra_pool) - ALL_rlpool(tra_pool); + if ( (tra_pool = transaction->tra_pool) ) + delete tra_pool; } @@ -1179,7 +1176,8 @@ void TRA_rollback(TDBB tdbb, TRA transaction, USHORT retaining_flag) this transaction's work and mark it committed in the TIP page instead (avoids a need for a database sweep). */ - if (transaction->tra_save_point) { + if (transaction->tra_save_point) + { if (!(transaction->tra_save_point->sav_flags & SAV_trans_level)) BUGCHECK(287); /* Too many savepoints */ @@ -1188,17 +1186,8 @@ void TRA_rollback(TDBB tdbb, TRA transaction, USHORT retaining_flag) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - /* Prevent a bugcheck in TRA_set_state to cause a loop */ - tdbb->tdbb_setjmp = (UCHAR *) old_env; - /* Clear the error because the rollback will succeed. */ - tdbb->tdbb_status_vector[0] = gds_arg_gds; - tdbb->tdbb_status_vector[1] = 0; - tdbb->tdbb_status_vector[2] = gds_arg_end; - TRA_set_state(tdbb, transaction, transaction->tra_number, - tra_dead); - } - else { + try { + /* In an attempt to avoid deadlocks, clear the precedence by writing all dirty buffers for this transaction. */ @@ -1223,6 +1212,16 @@ void TRA_rollback(TDBB tdbb, TRA transaction, USHORT retaining_flag) tdbb->tdbb_setjmp = (UCHAR *) old_env; } + catch (...) { + /* Prevent a bugcheck in TRA_set_state to cause a loop */ + tdbb->tdbb_setjmp = (UCHAR *) old_env; + /* Clear the error because the rollback will succeed. */ + tdbb->tdbb_status_vector[0] = gds_arg_gds; + tdbb->tdbb_status_vector[1] = 0; + tdbb->tdbb_status_vector[2] = gds_arg_end; + TRA_set_state(tdbb, transaction, transaction->tra_number, + tra_dead); + } } else { /* Set the state on the inventory page to be dead */ @@ -1365,7 +1364,7 @@ void TRA_shutdown_attachment(TDBB tdbb, ATT attachment) **************************************/ TRA transaction; VEC vector; - LCK *lock; + vec::iterator lock; USHORT i; SET_TDBB(tdbb); @@ -1374,11 +1373,11 @@ void TRA_shutdown_attachment(TDBB tdbb, ATT attachment) transaction = transaction->tra_next) { /* Release the relation locks associated with the transaction */ - if (vector = transaction->tra_relation_locks) - for (i = 0, lock = (LCK *) vector->vec_object; - i < vector->vec_count; i++, lock++) + if ( (vector = transaction->tra_relation_locks) ) + for (i = 0, lock = vector->begin(); + i < vector->count(); i++, lock++) if (*lock) - LCK_release(tdbb, *lock); + LCK_release(tdbb, (LCK)*lock); /* Release transaction lock itself */ @@ -1490,8 +1489,8 @@ TRA TRA_start(TDBB tdbb, int tpb_length, SCHAR * tpb) transaction block first, sieze relation locks, the go ahead and make up the real transaction block. */ - tdbb->tdbb_default = ALL_pool(); - temp = (TRA) ALLOCDV(type_tra, 0); + tdbb->tdbb_default = new(*dbb->dbb_permanent) JrdMemoryPool; + temp = new(*tdbb->tdbb_default, 0) tra; temp->tra_pool = tdbb->tdbb_default; transaction_options(tdbb, temp, reinterpret_cast < UCHAR * >(tpb), tpb_length); @@ -1539,12 +1538,12 @@ TRA TRA_start(TDBB tdbb, int tpb_length, SCHAR * tpb) base = oldest & ~TRA_MASK; if (temp->tra_flags & TRA_read_committed) - trans = (TRA) ALLOCDV(type_tra, 0); + trans = new(*tdbb->tdbb_default, 0) tra; else { - trans = (TRA) ALLOCDV(type_tra, (number - base + TRA_MASK) / 4); + trans = new(*tdbb->tdbb_default, (number - base + TRA_MASK) / 4) tra; } #else - trans = (TRA) ALLOCDV(type_tra, 0); + trans = new(*tdbb->tdbb_default) tra(); #endif trans->tra_pool = temp->tra_pool; @@ -1554,7 +1553,7 @@ TRA TRA_start(TDBB tdbb, int tpb_length, SCHAR * tpb) trans->tra_top = number; trans->tra_oldest = oldest; trans->tra_oldest_active = active; - ALL_release(reinterpret_cast < frb * >(temp)); + delete temp; #ifndef GATEWAY trans->tra_lock = lock; @@ -1577,7 +1576,7 @@ TRA TRA_start(TDBB tdbb, int tpb_length, SCHAR * tpb) if (!(dbb->dbb_flags & DBB_read_only)) CCH_RELEASE(tdbb, &window); #endif - ALL_release(reinterpret_cast < frb * >(trans)); + delete trans; ERR_post(gds_lock_conflict, 0); } @@ -1616,8 +1615,7 @@ TRA TRA_start(TDBB tdbb, int tpb_length, SCHAR * tpb) more complicated by the fact that existing transaction may have oldest actives older than they are. */ - MOVE_CLEAR(&temp_lock, sizeof(struct lck)); - temp_lock.lck_header.blk_type = type_lck; + //MOVE_CLEAR(&temp_lock, sizeof(struct lck)); // Taken care of in lck constructor. temp_lock.lck_dbb = dbb; temp_lock.lck_object = (BLK) trans; temp_lock.lck_type = LCK_tra; @@ -1781,7 +1779,7 @@ TRA TRA_start(TDBB tdbb, int tpb_length, SCHAR * tpb) trans->tra_flags & TRA_read_committed) { TRA_set_state(tdbb, trans, trans->tra_number, tra_committed); LCK_release(tdbb, trans->tra_lock); - ALL_release(reinterpret_cast < frb * >(trans->tra_lock)); + delete trans->tra_lock; trans->tra_lock = 0; trans->tra_flags |= TRA_precommitted; } @@ -1858,7 +1856,7 @@ int TRA_sweep(TDBB tdbb, TRA trans) /* fill out a lock block, zeroing it out first */ MOVE_CLEAR(&temp_lock, sizeof(struct lck)); - temp_lock.lck_header.blk_type = type_lck; + //temp_lock.blk_type = type_lck; temp_lock.lck_dbb = dbb; temp_lock.lck_object = (BLK) trans; temp_lock.lck_type = LCK_sweep; @@ -1884,16 +1882,8 @@ int TRA_sweep(TDBB tdbb, TRA trans) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - if (!SETJMP(env)) - if (!trans) - TRA_commit(tdbb, transaction, FALSE); - LCK_release(tdbb, &temp_lock); - dbb->dbb_flags &= ~DBB_sweep_in_progress; - tdbb->tdbb_setjmp = (UCHAR *) old_env; - tdbb->tdbb_flags &= ~TDBB_sweeper; - return FALSE; - } + + try { /* Identify ourselves as a sweeper thread. This accomplishes two goals: 1) Sweep transaction is started "precommitted" @@ -1989,6 +1979,23 @@ int TRA_sweep(TDBB tdbb, TRA trans) tdbb->tdbb_setjmp = (UCHAR *) old_env; tdbb->tdbb_flags &= ~TDBB_sweeper; + } // try + catch (...) { + try { + if (!trans) + { + TRA_commit(tdbb, transaction, FALSE); + } + } + catch (...) { + LCK_release(tdbb, &temp_lock); + dbb->dbb_flags &= ~DBB_sweep_in_progress; + tdbb->tdbb_setjmp = (UCHAR *) old_env; + tdbb->tdbb_flags &= ~TDBB_sweeper; + return FALSE; + } + } + return TRUE; } #endif @@ -2012,7 +2019,7 @@ LCK TRA_transaction_lock(TDBB tdbb, BLK object) SET_TDBB(tdbb); dbb = tdbb->tdbb_database; - lock = (LCK) ALLOCDV(type_lck, sizeof(SLONG)); + lock = new(*tdbb->tdbb_default, sizeof(SLONG)) lck(); lock->lck_type = LCK_tra; lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type); lock->lck_length = sizeof(SLONG); @@ -2084,7 +2091,7 @@ int TRA_wait(TDBB tdbb, TRA trans, SLONG number, USHORT wait) if (wait) { MOVE_CLEAR(&temp_lock, sizeof(struct lck)); - temp_lock.lck_header.blk_type = (UCHAR) type_lck; + //temp_lock.blk_type = (UCHAR) type_lck; temp_lock.lck_dbb = dbb; temp_lock.lck_type = LCK_tra; temp_lock.lck_owner_handle = @@ -2247,7 +2254,7 @@ static HDR bump_transaction_id(TDBB tdbb, WIN * window) /* If this is the first transaction on a TIP, allocate the TIP now. */ - if (new_tip = ((number == 1) + if ( (new_tip = ((number == 1)) || ((number % dbb->dbb_pcontrol->pgc_tpt) == 0))) TRA_extend_tip(tdbb, (ULONG) (number / dbb->dbb_pcontrol->pgc_tpt), window); @@ -2330,7 +2337,7 @@ static void compute_oldest_retaining( /* Get a commit retaining lock, if not present. */ if (!(lock = dbb->dbb_retaining_lock)) { - lock = (LCK) ALLOCPV(type_lck, sizeof(SLONG)); + lock = new(*dbb->dbb_permanent, sizeof(SLONG)) lck(); lock->lck_dbb = dbb; lock->lck_type = LCK_retaining; lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type); @@ -2384,7 +2391,7 @@ static void compute_oldest_retaining( /* fill out a lock block, zeroing it out first */ MOVE_CLEAR(&temp_lock, sizeof(struct lck)); - temp_lock.lck_header.blk_type = type_lck; + temp_lock.blk_type = type_lck; temp_lock.lck_dbb = dbb; temp_lock.lck_type = LCK_tra; temp_lock.lck_owner_handle = @@ -2571,13 +2578,13 @@ static SLONG inventory_page(TDBB tdbb, int sequence) CHECK_DBB(dbb); window.win_flags = 0; - while (!(vector = dbb->dbb_t_pages) || sequence >= vector->vcl_count) { + while (!(vector = dbb->dbb_t_pages) || sequence >= vector->count()) { DPM_scan_pages(tdbb); - if ((vector = dbb->dbb_t_pages) && sequence < vector->vcl_count) + if ((vector = dbb->dbb_t_pages) && sequence < vector->count()) break; - if (!vector || !vector->vcl_long) + if (!vector) BUGCHECK(165); /* msg 165 cannot find tip page */ - window.win_page = vector->vcl_long[vector->vcl_count - 1]; + window.win_page = (*vector)[vector->count() - 1]; tip = (TIP) CCH_FETCH(tdbb, &window, LCK_read, pag_transactions); next = tip->tip_next; CCH_RELEASE(tdbb, &window); @@ -2585,11 +2592,11 @@ static SLONG inventory_page(TDBB tdbb, int sequence) BUGCHECK(165); /* msg 165 cannot find tip page */ tip = (TIP) CCH_FETCH(tdbb, &window, LCK_read, pag_transactions); /* Type check it */ CCH_RELEASE(tdbb, &window); - DPM_pages(tdbb, 0, pag_transactions, vector->vcl_count, + DPM_pages(tdbb, 0, pag_transactions, vector->count(), window.win_page); } - return vector->vcl_long[sequence]; + return (*vector)[sequence]; } #endif @@ -2670,9 +2677,9 @@ static void restart_requests(TDBB tdbb, TRA trans) /* now take care of any other request levels; start at level 1 since level 0 was just handled */ - if (vector = request->req_sub_requests) - for (level = 1; level < vector->vec_count; level++) - if ((clone = (REQ) vector->vec_object[level]) && + if ( (vector = request->req_sub_requests) ) + for (level = 1; level < vector->count(); level++) + if ((clone = (REQ) (*vector)[level]) && clone->req_transaction) { EXE_unwind(tdbb, clone); EXE_start(tdbb, clone, trans); @@ -2734,7 +2741,7 @@ static void retain_context(TDBB tdbb, TRA transaction, USHORT commit) } #endif - if (old_lock = transaction->tra_lock) { + if ( (old_lock = transaction->tra_lock) ) { new_lock = TRA_transaction_lock(tdbb, reinterpret_cast < blk * >(transaction)); @@ -2790,7 +2797,7 @@ static void retain_context(TDBB tdbb, TRA transaction, USHORT commit) LCK_release(tdbb, old_lock); transaction->tra_lock = new_lock; --transaction->tra_use_count; - ALL_release(reinterpret_cast < frb * >(old_lock)); + delete old_lock; } /* Perform any post commit work OR delete entries from deferred list */ @@ -2849,15 +2856,13 @@ static BOOLEAN start_sweeper(TDBB tdbb, DBB dbb) SET_TDBB(tdbb); - - /* fill out the lock block */ - struct lck temp_lock = { 0 }; - temp_lock.lck_header.blk_type = type_lck; - temp_lock.lck_dbb = dbb; - temp_lock.lck_type = LCK_sweep; - temp_lock.lck_owner_handle = LCK_get_owner_handle(tdbb, temp_lock.lck_type); - temp_lock.lck_parent = dbb->dbb_lock; - temp_lock.lck_length = sizeof(SLONG); + // fill out the lock block + lck temp_lock; + temp_lock.lck_dbb = dbb; + temp_lock.lck_type = LCK_sweep; + temp_lock.lck_owner_handle = LCK_get_owner_handle(tdbb, temp_lock.lck_type); + temp_lock.lck_parent = dbb->dbb_lock; + temp_lock.lck_length = sizeof(SLONG); if (!LCK_lock(tdbb, &temp_lock, LCK_EX, FALSE)) { @@ -2893,7 +2898,7 @@ static BOOLEAN start_sweeper(TDBB tdbb, DBB dbb) } -static void THREAD_ROUTINE sweep_database(UCHAR * database) +static void THREAD_ROUTINE sweep_database(UCHAR* database) { /************************************** * @@ -3074,7 +3079,7 @@ static void transaction_options( case gds_tpb_lock_write: case gds_tpb_lock_read: p = reinterpret_cast < UCHAR * >(name); - if (l = *tpb++) { + if ( (l = *tpb++) ) { if (l >= sizeof(name)) { gds__msg_lookup(0, DYN_MSG_FAC, 159, sizeof(text), text, &flags); @@ -3138,14 +3143,14 @@ static void transaction_options( id = 0; - for (; id < vector->vec_count; id++) { - if (!(lock = (LCK) vector->vec_object[id])) + for (; id < vector->count(); id++) { + if (!(lock = (LCK) (*vector)[id])) continue; level = lock->lck_logical; if (level == LCK_none || LCK_lock_non_blocking(tdbb, lock, level, wait)) continue; for (l = 0; l < id; l++) - if (lock = (LCK) vector->vec_object[l]) { + if ( (lock = (LCK) (*vector)[l]) ) { level = lock->lck_logical; LCK_release(tdbb, lock); lock->lck_logical = level; diff --git a/src/jrd/tra.h b/src/jrd/tra.h index a5f4d399de..99f6da2aef 100644 --- a/src/jrd/tra.h +++ b/src/jrd/tra.h @@ -29,16 +29,14 @@ * to define the types this header usus. */ -#ifdef __cplusplus -extern "C" { -#endif - +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" /* Transaction block */ -typedef struct tra +class tra : public pool_alloc_rpt { - struct blk tra_header; + public: struct att *tra_attachment; /* database attachment */ SLONG tra_number; /* transaction number */ SLONG tra_top; /* highest transaction in snapshot */ @@ -47,8 +45,8 @@ typedef struct tra gargage-collected by this tx */ struct tra *tra_next; /* next transaction in database */ struct tra *tra_sibling; /* next transaction in group */ - struct plb *tra_pool; /* pool for transaction */ - struct blb *tra_blobs; /* Linked list of active blobs */ + JrdMemoryPool* tra_pool; /* pool for transaction */ + class blb *tra_blobs; /* Linked list of active blobs */ struct arr *tra_arrays; /* Linked list of active arrays */ struct lck *tra_lock; /* lock for transaction */ struct vec *tra_relation_locks; /* locks for relations */ @@ -61,10 +59,11 @@ typedef struct tra SLONG tra_range_id; /* unique id of cache range within transaction */ #endif struct dfw *tra_deferred_work; /* work deferred to commit time */ - struct rsc *tra_resources; /* resource existence list */ + class Rsc *tra_resources; /* resource existence list */ UCHAR tra_use_count; /* use count for safe AST delivery */ UCHAR tra_transactions[1]; -} *TRA; +}; +typedef tra *TRA; #define TRA_system 1L /* system transaction */ #define TRA_update 2L /* update is permitted */ @@ -120,15 +119,17 @@ typedef struct tra #define MAX_TRA_NUMBER (~(1L << (BITS_PER_LONG - 1))) /* Savepoint block */ -typedef struct sav { - struct blk sav_header; +class sav : public pool_alloc +{ + public: struct vct *sav_verb_actions; /* verb action list */ struct vct *sav_verb_free; /* free verb action block */ USHORT sav_verb_count; /* Active verb count */ SLONG sav_number; /* save point number */ struct sav *sav_next; USHORT sav_flags; -} *SAV; +}; +typedef sav *SAV; /* Savepoint block flags. */ @@ -172,8 +173,9 @@ ENUM dfw_t { dfw_delete_procedure, dfw_delete_prm, dfw_delete_exception, dfw_unlink_file}; -typedef struct dfw { - struct blk dfw_header; +class dfw : public pool_alloc_rpt +{ + public: ENUM dfw_t dfw_type; /* type of work deferred */ struct dfw *dfw_next; /* next block in transaction */ struct lck *dfw_lock; /* relation creation lock */ @@ -182,22 +184,21 @@ typedef struct dfw { USHORT dfw_id; /* object id, if appropriate */ USHORT dfw_count; /* count of block posts */ SCHAR dfw_name[2]; /* name of object */ -} *DFW; +}; +typedef dfw *DFW; /* Verb actions */ -typedef struct vct { - struct blk vct_header; +class vct : public pool_alloc +{ + public: struct vct *vct_next; /* Next action within verb */ struct rel *vct_relation; /* Relation involved */ struct sbm *vct_records; /* Record involved */ struct sbm *vct_undo; /* Record involved that have to be replaced */ struct lls *vct_data; /* Data for undo records */ -} *VCT; +}; +typedef vct *VCT; -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif /* JRD_TRA_H */ diff --git a/src/jrd/tra_proto.h b/src/jrd/tra_proto.h index 6f4736ed25..a81de21bef 100644 --- a/src/jrd/tra_proto.h +++ b/src/jrd/tra_proto.h @@ -39,7 +39,7 @@ extern void TRA_header_write(TDBB, struct dbb *, SLONG); extern void TRA_init(TDBB); extern void TRA_invalidate(struct dbb *, ULONG); extern void TRA_link_transaction(TDBB, struct tra *); -extern void TRA_post_resources(TDBB, struct tra *, struct rsc *); +extern void TRA_post_resources(TDBB, struct tra *, class Rsc *); extern BOOLEAN TRA_precommited(TDBB, SLONG, SLONG); extern void TRA_prepare(TDBB, struct tra *, USHORT, UCHAR *); extern struct tra *TRA_reconnect(TDBB, UCHAR *, USHORT); diff --git a/src/jrd/trig.h b/src/jrd/trig.h index caf3ec0823..83d74f233d 100644 --- a/src/jrd/trig.h +++ b/src/jrd/trig.h @@ -78,15 +78,15 @@ typedef struct gen static CONST GEN generators[] = { - "RDB$SECURITY_CLASS", 0, - "SQL$DEFAULT", 0, - "RDB$PROCEDURES", 0, - "RDB$EXCEPTIONS", 0, - "RDB$CONSTRAINT_NAME", 0, - "RDB$FIELD_NAME", 0, - "RDB$INDEX_NAME", 0, - "RDB$TRIGGER_NAME", 0, - 0, 0 + { "RDB$SECURITY_CLASS", 0 }, + { "SQL$DEFAULT", 0 }, + { "RDB$PROCEDURES", 0 }, + { "RDB$EXCEPTIONS", 0 }, + { "RDB$CONSTRAINT_NAME", 0 }, + { "RDB$FIELD_NAME", 0 }, + { "RDB$INDEX_NAME", 0 }, + { "RDB$TRIGGER_NAME", 0 }, + { 0, 0 } }; diff --git a/src/jrd/unix.cpp b/src/jrd/unix.cpp index e9be623be7..a6df20bb02 100644 --- a/src/jrd/unix.cpp +++ b/src/jrd/unix.cpp @@ -974,7 +974,7 @@ static FIL setup_file( /* Allocate file block and copy file name string */ - file = (FIL) ALLOCPV(type_fil, file_length + 1); + file = new(*dbb->dbb_permanent, file_length + 1) fil(); file->fil_desc = desc; file->fil_length = file_length; file->fil_max_page = -1; @@ -1008,7 +1008,7 @@ static FIL setup_file( l = p - lock_string; - dbb->dbb_lock = lock = (LCK) ALLOCPV(type_lck, l); + dbb->dbb_lock = lock = new(*dbb->dbb_permanent, l) lck(); lock->lck_type = LCK_database; lock->lck_owner_handle = LCK_get_owner_handle(NULL_TDBB, lock->lck_type); lock->lck_object = (BLK) dbb; diff --git a/src/jrd/val.cpp b/src/jrd/val.cpp index 87be8346cb..0942d8a229 100644 --- a/src/jrd/val.cpp +++ b/src/jrd/val.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: val.c + * MODULE: val.cpp * DESCRIPTION: Validation and garbage collection * * The contents of this file are subject to the Interbase Public @@ -689,7 +689,7 @@ BOOLEAN VAL_validate(TDBB tdbb, USHORT switches) * **************************************/ struct vdr control; - PLB val_pool, old_pool; + JrdMemoryPool *val_pool, *old_pool; ATT att; USHORT i; DBB dbb; @@ -701,18 +701,12 @@ BOOLEAN VAL_validate(TDBB tdbb, USHORT switches) DEBUG old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - if (val_pool) - ALL_rlpool(val_pool); - tdbb->tdbb_default = old_pool; - tdbb->tdbb_flags &= ~TDBB_sweeper; - tdbb->tdbb_setjmp = (UCHAR *) old_env; - return FALSE; - } + + try { old_pool = tdbb->tdbb_default; val_pool = 0; - tdbb->tdbb_default = val_pool = ALL_pool(); + tdbb->tdbb_default = val_pool = new(*dbb->dbb_permanent) JrdMemoryPool; control.vdr_page_bitmap = NULL; control.vdr_flags = 0; @@ -734,12 +728,11 @@ BOOLEAN VAL_validate(TDBB tdbb, USHORT switches) /* initialize validate errors */ if (!att->att_val_errors) { - att->att_val_errors = (VCL) ALLOCPV(type_vcl, VAL_MAX_ERROR); - att->att_val_errors->vcl_count = VAL_MAX_ERROR; + att->att_val_errors = vcl::newVector(*dbb->dbb_permanent, VAL_MAX_ERROR); } else { for (i = 0; i < VAL_MAX_ERROR; i++) - att->att_val_errors->vcl_long[i] = 0; + (*att->att_val_errors)[i] = 0; } tdbb->tdbb_flags |= TDBB_sweeper; @@ -750,13 +743,23 @@ BOOLEAN VAL_validate(TDBB tdbb, USHORT switches) garbage_collect(tdbb, &control); CCH_flush(tdbb, (USHORT) FLUSH_FINI, 0); - ALL_rlpool(val_pool); + delete val_pool; tdbb->tdbb_default = old_pool; tdbb->tdbb_flags &= ~TDBB_sweeper; tdbb->tdbb_setjmp = (UCHAR *) old_env; + + } // try + catch (...) { + delete val_pool; + tdbb->tdbb_default = old_pool; + tdbb->tdbb_flags &= ~TDBB_sweeper; + tdbb->tdbb_setjmp = (UCHAR *) old_env; + return FALSE; + } + return TRUE; } - + static RTN corrupt(TDBB tdbb, VDR control, USHORT err_code, REL relation, ...) { /************************************** @@ -778,8 +781,8 @@ static RTN corrupt(TDBB tdbb, VDR control, USHORT err_code, REL relation, ...) SET_TDBB(tdbb); att = tdbb->tdbb_attachment; - if (err_code < att->att_val_errors->vcl_count) - att->att_val_errors->vcl_long[err_code]++; + if (err_code < att->att_val_errors->count()) + (*att->att_val_errors)[err_code]++; string = msg_table[err_code]; @@ -1097,7 +1100,7 @@ static RTN walk_chain(TDBB tdbb, SLONG page_number; USHORT line_number, delta_flag; dpg::dpg_repeat * line; - USHORT counter = 0; + //USHORT counter = 0; SET_TDBB(tdbb); @@ -1172,12 +1175,12 @@ static void walk_database(TDBB tdbb, VDR control) (void) walk_tip(tdbb, control, page->hdr_next_transaction); walk_generators(tdbb, control); - for (i = 0; (vector = dbb->dbb_relations) && i < vector->vec_count; i++) { + for (i = 0; (vector = dbb->dbb_relations) && i < vector->count(); i++) { #ifdef VAL_VERBOSE if (i >= 32 /* rel_MAX */ ) VAL_debug_level = 2; #endif - if (relation = (REL) vector->vec_object[i]) + if ( (relation = (REL) (*vector)[i]) ) (void) walk_relation(tdbb, control, relation); } @@ -1331,14 +1334,14 @@ static void walk_generators(TDBB tdbb, VDR control) WIN window; VCL vector; PPG page; - SLONG *ptr, *end; + vcl::iterator ptr, end; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; CHECK_DBB(dbb); - if (vector = dbb->dbb_gen_id_pages) - for (ptr = vector->vcl_long, end = ptr + vector->vcl_count; ptr < end; + if ( (vector = dbb->dbb_gen_id_pages) ) + for (ptr = vector->begin(), end = vector->end(); ptr < end; ptr++) if (*ptr) { #ifdef VAL_VERBOSE @@ -1670,13 +1673,13 @@ static RTN walk_pointer_page( TDBB tdbb, VCL vector = relation->rel_pages; - if (!vector || sequence >= static_cast(vector->vcl_count)) { + if (!vector || sequence >= static_cast(vector->count())) { return corrupt(tdbb, control, VAL_P_PAGE_LOST, relation, sequence); } fetch_page( tdbb, control, - vector->vcl_long[sequence], + (*vector)[sequence], pag_pointer, &window, &page); @@ -1685,7 +1688,7 @@ static RTN walk_pointer_page( TDBB tdbb, if (VAL_debug_level) ib_fprintf(ib_stdout, "walk_pointer_page: page %d relation %d sequence %d\n", - vector->vcl_long[sequence], relation->rel_id, sequence); + (*vector)[sequence], relation->rel_id, sequence); #endif /* Give the page a quick once over */ @@ -1718,8 +1721,8 @@ static RTN walk_pointer_page( TDBB tdbb, /* Make sure the "next" pointer agrees with the pages relation */ - if (++sequence >= static_cast(vector->vcl_count) || - (page->ppg_next && page->ppg_next != vector->vcl_long[sequence])) + if (++sequence >= static_cast(vector->count()) || + (page->ppg_next && page->ppg_next != (*vector)[sequence])) { CCH_RELEASE(tdbb, &window); return corrupt( tdbb, @@ -1878,7 +1881,8 @@ static RTN walk_record(TDBB tdbb, return rtn_ok; } - + + static RTN walk_relation(TDBB tdbb, VDR control, REL relation) { /************************************** @@ -1891,35 +1895,12 @@ static RTN walk_relation(TDBB tdbb, VDR control, REL relation) * Walk all pages associated with a given relation. * **************************************/ - int *old_env, ret; - JMP_BUF env; - SLONG sequence; SET_TDBB(tdbb); - old_env = (int *) tdbb->tdbb_setjmp; - tdbb->tdbb_setjmp = (UCHAR *) env; + try { -/* If we get an error for any reason, at least say where we were */ - - ret = SETJMP(env); - - if (ret) { - TEXT s[64], *msg; - tdbb->tdbb_setjmp = (UCHAR *) old_env; - msg = (relation->rel_name) ? - (TEXT*)"bugcheck during scan of table %d (%s)" : - (TEXT*)"bugcheck during scan of table %d"; - sprintf(s, msg, relation->rel_id, relation->rel_name); - gds__log(s); -#ifdef VAL_VERBOSE - if (VAL_debug_level) - ib_fprintf(ib_stdout, "LOG:\t%s\n", s); -#endif - ERR_punt(); - } - -/* If relation hasn't been scanned, do so now */ + // If relation hasn't been scanned, do so now if (!(relation->rel_flags & REL_scanned) || (relation->rel_flags & REL_being_scanned)) @@ -1935,7 +1916,6 @@ static RTN walk_relation(TDBB tdbb, VDR control, REL relation) /* If it's a view or external file, skip this */ if (relation->rel_view_rse || relation->rel_file) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; return rtn_ok; } @@ -1947,23 +1927,21 @@ static RTN walk_relation(TDBB tdbb, VDR control, REL relation) control->vdr_rel_chain_counter = 0; SBM_reset(&control->vdr_rel_records); } - for (sequence = 0; TRUE; sequence++) { + for (SLONG sequence = 0; TRUE; sequence++) { RTN result; result = walk_pointer_page(tdbb, control, relation, sequence); - if (result == rtn_eof) + if (result == rtn_eof) { break; + } if (result != rtn_ok) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; return result; } - }; + } - tdbb->tdbb_setjmp = (UCHAR *) old_env; - -/* Walk indices for the relation */ + // Walk indices for the relation (void) walk_root(tdbb, control, relation); -/* See if the counts of backversions match */ + // See if the counts of backversions match if (control && (control->vdr_flags & vdr_records) && (control->vdr_rel_backversion_counter != control->vdr_rel_chain_counter)) @@ -1976,9 +1954,25 @@ static RTN walk_relation(TDBB tdbb, VDR control, REL relation) control-> vdr_rel_chain_counter); } + } // try + catch (...) { + TEXT s[64]; + TEXT* msg = (relation->rel_name) ? + (TEXT*)"bugcheck during scan of table %d (%s)" : + (TEXT*)"bugcheck during scan of table %d"; + sprintf(s, msg, relation->rel_id, relation->rel_name); + gds__log(s); +#ifdef VAL_VERBOSE + if (VAL_debug_level) + ib_fprintf(ib_stdout, "LOG:\t%s\n", s); +#endif + ERR_punt(); + } + return rtn_ok; } - + + static RTN walk_root(TDBB tdbb, VDR control, REL relation) { /************************************** @@ -2007,7 +2001,7 @@ static RTN walk_root(TDBB tdbb, VDR control, REL relation) &page); for (i = 0; i < page->irt_count; i++) - if (page_number = page->irt_rpt[i].irt_root) + if ( (page_number = page->irt_rpt[i].irt_root) ) (void) walk_index(tdbb, control, relation, page_number, i); CCH_RELEASE(tdbb, &window); @@ -2045,7 +2039,7 @@ static RTN walk_tip(TDBB tdbb, VDR control, SLONG transaction) pages = transaction / dbb->dbb_pcontrol->pgc_tpt; for (sequence = 0; sequence <= pages; sequence++) { - if (!vector->vcl_long[sequence] || sequence >= vector->vcl_count) { + if (!(*vector)[sequence] || sequence >= vector->count()) { corrupt(tdbb, control, VAL_TIP_LOST_SEQUENCE, 0, sequence); if (!(control->vdr_flags & vdr_repair)) continue; @@ -2054,7 +2048,7 @@ static RTN walk_tip(TDBB tdbb, VDR control, SLONG transaction) } fetch_page( tdbb, control, - vector->vcl_long[sequence], + (*vector)[sequence], pag_transactions, &window, &page); @@ -2062,9 +2056,9 @@ static RTN walk_tip(TDBB tdbb, VDR control, SLONG transaction) #ifdef VAL_VERBOSE if (VAL_debug_level) ib_fprintf(ib_stdout, "walk_tip: page %d next %d\n", - vector->vcl_long[sequence], page->tip_next); + (*vector)[sequence], page->tip_next); #endif - if (page->tip_next && page->tip_next != vector->vcl_long[sequence + 1]) + if (page->tip_next && page->tip_next != (*vector)[sequence + 1]) { corrupt(tdbb, control, VAL_TIP_CONFUSED, 0, sequence); } diff --git a/src/jrd/val.h b/src/jrd/val.h index 2de9366f57..90a26c9842 100644 --- a/src/jrd/val.h +++ b/src/jrd/val.h @@ -24,11 +24,11 @@ #ifndef _JRD_VAL_H_ #define _JRD_VAL_H_ -#include "../jrd/dsc.h" +#include "../jrd/jrd_blks.h" +#include "../include/fb_blk.h" +#include "../include/fb_vector.h" -#ifdef __cplusplus -extern "C" { -#endif +#include "../jrd/dsc.h" #ifdef GATEWAY @@ -56,8 +56,16 @@ extern "C" { #endif #ifndef REQUESTER -typedef struct fmt { - struct blk fmt_header; +class fmt : public pool_alloc +{ +public: + fmt(MemoryPool& p, int len) + : fmt_desc(len, p, type_fmt) + { + } + static fmt* newFmt(MemoryPool& p, int len = 0) + { return new(p) fmt(p, len); } + USHORT fmt_length; USHORT fmt_count; USHORT fmt_version; @@ -69,19 +77,18 @@ typedef struct fmt { THIS FIELD INSURES THAT A PC_PLATFORM DATABASE IS IDENTICAL TO ONE ON Windows/NT. */ #endif - struct dsc fmt_desc[1]; + Firebird::vector fmt_desc; + typedef Firebird::vector::iterator fmt_desc_iterator; #ifdef GATEWAY - struct xdsc fmt_ext_desc[1]; + Firebird::vector fmt_ext_desc[1]; #endif -} *FMT; +}; +typedef fmt *FMT; #endif /* REQUESTER */ #define MAX_FORMAT_SIZE 65535 -typedef struct vary { - USHORT vary_length; - UCHAR vary_string[1]; -} VARY; +typedef vary VARY; /* A macro to define a local vary stack variable of a given length Usage: VARY_STRING(5) my_var; */ @@ -96,8 +103,14 @@ typedef ENUM { FUN_reference, FUN_descriptor, FUN_blob_struct, FUN_scalar_array} FUN_T; -typedef struct fun { - struct blk fun_header; +struct fun_repeat { + DSC fun_desc; /* Datatype info */ + FUN_T fun_mechanism; /* Passing mechanism */ +}; + +class fun : public pool_alloc_rpt +{ + public: STR fun_exception_message; /* message containing the exception error message */ struct fun *fun_homonym; /* Homonym functions */ struct sym *fun_symbol; /* Symbol block */ @@ -107,11 +120,9 @@ typedef struct fun { USHORT fun_return_arg; /* Return argument */ USHORT fun_type; /* Type of function */ ULONG fun_temp_length; /* Temporary space required */ - struct fun_repeat { - DSC fun_desc; /* Datatype info */ - FUN_T fun_mechanism; /* Passing mechanism */ - } fun_rpt[1]; -} *FUN; + fun_repeat fun_rpt[1]; +}; +typedef fun *FUN; #define FUN_value 0 #define FUN_boolean 1 @@ -155,7 +166,8 @@ typedef struct ads { SLONG ads_length; /* Length of "vector" element */ SLONG ads_lower; /* Lower bound */ SLONG ads_upper; /* Upper bound */ - } ads_rpt[1]; + }; + struct ads_repeat ads_rpt[1]; } *ADS; #define ADS_VERSION_1 1 @@ -166,23 +178,21 @@ typedef struct ads { #endif #ifndef REQUESTER -typedef struct arr { - struct blk arr_header; - UCHAR *arr_data; /* Data block, if allocated */ - struct blb *arr_blob; /* Blob for data access */ - struct tra *arr_transaction; /* Parent transaction block */ - struct arr *arr_next; /* Next array in transaction */ - struct req *arr_request; /* request */ - SLONG arr_effective_length; /* Length of array instance */ - USHORT arr_desc_length; /* Length of array descriptor */ - struct ads arr_desc; /* Array descriptor */ -} *ARR; +class arr : public pool_alloc_rpt +{ + public: + UCHAR* arr_data; /* Data block, if allocated */ + class blb* arr_blob; /* Blob for data access */ + struct tra* arr_transaction; /* Parent transaction block */ + struct arr* arr_next; /* Next array in transaction */ + struct req* arr_request; /* request */ + SLONG arr_effective_length; /* Length of array instance */ + USHORT arr_desc_length; /* Length of array descriptor */ + struct ads arr_desc; /* Array descriptor */ +}; +typedef arr *ARR; #endif /* REQUESTER */ -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif /* _JRD_VAL_H_ */ diff --git a/src/jrd/vio.cpp b/src/jrd/vio.cpp index 31a9a67d69..4df0174535 100644 --- a/src/jrd/vio.cpp +++ b/src/jrd/vio.cpp @@ -82,7 +82,7 @@ static void bump_count(TDBB, USHORT, REL); static void check_class(TDBB, TRA, RPB *, RPB *, USHORT); static void check_control(TDBB); static BOOLEAN check_user(TDBB, DSC *); -static void delete_(TDBB, RPB *, SLONG, struct plb *); +static void delete_(TDBB, RPB *, SLONG, JrdMemoryPool *); static UCHAR *delete_tail(TDBB, RPB *, SLONG, UCHAR *, UCHAR *); static void expunge(TDBB, RPB *, TRA, SLONG); static void garbage_collect(TDBB, RPB *, SLONG, LLS); @@ -164,7 +164,7 @@ void VIO_backout(TDBB tdbb, RPB * rpb, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("VIO_backout (rpb %d, transaction %d)\n", rpb->rpb_number, + ib_printf("VIO_backout (rpb %"SLONGFORMAT", transaction %"SLONGFORMAT")\n", rpb->rpb_number, transaction ? transaction->tra_number : 0); #endif @@ -186,7 +186,7 @@ void VIO_backout(TDBB tdbb, RPB * rpb, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", temp.rpb_page, temp.rpb_line, temp.rpb_transaction, temp.rpb_flags, temp.rpb_b_page, temp.rpb_b_line, temp.rpb_f_page, temp.rpb_f_line); @@ -342,7 +342,7 @@ void VIO_backout(TDBB tdbb, RPB * rpb, TRA transaction) LLS_POP(&going); while (staying) - ALL_release(reinterpret_cast < frb * >(LLS_POP(&staying))); + delete LLS_POP(&staying); /* Return relation garbage collect record blocks to vector. */ @@ -385,12 +385,12 @@ int VIO_chase_record_version( #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) ib_printf - ("VIO_chase_record_version (rpb %d, transaction %d, pool %d)\n", + ("VIO_chase_record_version (rpb %"SLONGFORMAT", transaction %"SLONGFORMAT", pool %p)\n", rpb->rpb_number, transaction ? transaction->tra_number : 0, - pool ? ((PLB) pool)->plb_pool_id : 0); + pool ); if (debug_flag > DEBUG_TRACE_ALL_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -440,7 +440,7 @@ int VIO_chase_record_version( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" chase record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" chase record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -521,7 +521,7 @@ int VIO_chase_record_version( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record's transaction (%d) is dead (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is dead (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif #ifdef GARBAGE_THREAD @@ -591,7 +591,7 @@ int VIO_chase_record_version( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record's transaction (%d) is in limbo (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is in limbo (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif @@ -605,7 +605,7 @@ int VIO_chase_record_version( #ifdef VIO_DEBUG if ((debug_flag > DEBUG_READS_INFO) && (state == tra_active)) ib_printf - (" record's transaction (%d) is active (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is active (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif @@ -691,7 +691,7 @@ int VIO_chase_record_version( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record's transaction (%d) is us (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is us (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif @@ -708,7 +708,7 @@ int VIO_chase_record_version( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record's transaction (%d) is committed (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is committed (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif @@ -902,13 +902,13 @@ void VIO_data(TDBB tdbb, register RPB * rpb, BLK pool) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) { - ib_printf("VIO_data (rpb %d, pool %d)\n", + ib_printf("VIO_data (rpb %"SLONGFORMAT", pool %p)\n", rpb->rpb_number, - pool ? ((PLB) pool)->plb_pool_id : 0); + pool); } if (debug_flag > DEBUG_READS_INFO) { - ib_printf(" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + ib_printf(" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, @@ -921,7 +921,7 @@ void VIO_data(TDBB tdbb, register RPB * rpb, BLK pool) the format block and set up the record block. This is a performance optimization. */ - REC record = VIO_record(tdbb, rpb, 0, reinterpret_cast < plb * >(pool)); + REC record = VIO_record(tdbb, rpb, 0, (JrdMemoryPool*) pool); FMT format = record->rec_format; /* If the record is a delta version, start with data from prior record. */ @@ -1034,12 +1034,12 @@ void VIO_erase(TDBB tdbb, RPB * rpb, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) { - ib_printf("VIO_erase (rpb %d, transaction %d)\n", rpb->rpb_number, + ib_printf("VIO_erase (rpb %"SLONGFORMAT", transaction %"SLONGFORMAT")\n", rpb->rpb_number, transaction->tra_number); } if (debug_flag > DEBUG_WRITES_INFO) { - ib_printf(" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + ib_printf(" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -1138,7 +1138,7 @@ void VIO_erase(TDBB tdbb, RPB * rpb, TRA transaction) EVL_field(0, rpb->rpb_record, f_idx_relation, &desc); SCL_check_relation(&desc, SCL_control); EVL_field(0, rpb->rpb_record, f_idx_id, &desc2); - if (id = MOV_get_long(&desc2, 0)) { + if ( (id = MOV_get_long(&desc2, 0)) ) { if (EVL_field(0, rpb->rpb_record, f_idx_exp_blr, &desc2)) { DFW_post_work(transaction, dfw_delete_expression_index, @@ -1157,7 +1157,7 @@ void VIO_erase(TDBB tdbb, RPB * rpb, TRA transaction) DFW_post_work(transaction, dfw_update_format, &desc, 0); EVL_field(0, rpb->rpb_record, f_rfr_fname, &desc2); MOV_get_metadata_ptr(&desc, &relation_name); - if (r2 = MET_lookup_relation(tdbb, relation_name)) + if ( (r2 = MET_lookup_relation(tdbb, relation_name)) ) { DFW_post_work(transaction, dfw_delete_rfr, &desc2, r2->rel_id); @@ -1171,7 +1171,7 @@ void VIO_erase(TDBB tdbb, RPB * rpb, TRA transaction) SCL_check_procedure(&desc, SCL_control); EVL_field(0, rpb->rpb_record, f_prm_name, &desc2); MOV_get_metadata_ptr(&desc, &procedure_name); - if (procedure = MET_lookup_procedure(tdbb, procedure_name)) + if ( (procedure = MET_lookup_procedure(tdbb, procedure_name)) ) { DFW_post_work(transaction, dfw_delete_prm, &desc2, procedure->prc_id); @@ -1236,6 +1236,8 @@ void VIO_erase(TDBB tdbb, RPB * rpb, TRA transaction) case rel_log: DFW_post_work(transaction, dfw_delete_log, 0, 0); break; + default: /* Shut up compiler warnings */ + break; } } @@ -1372,12 +1374,12 @@ int VIO_garbage_collect(TDBB tdbb, RPB * rpb, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE) { - ib_printf("VIO_garbage_collect (rpb %d, transaction %d)\n", + ib_printf("VIO_garbage_collect (rpb %"SLONGFORMAT", transaction %"SLONGFORMAT")\n", rpb->rpb_number, transaction ? transaction->tra_number : 0); } if (debug_flag > DEBUG_TRACE_INFO) { - ib_printf(" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + ib_printf(" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -1475,7 +1477,8 @@ REC VIO_gc_record(TDBB tdbb, REL relation) **************************************/ DBB dbb; VEC vector; - REC record, *rec_ptr, *end; + REC record; + vec::iterator rec_ptr, end; RPB rpb; USHORT slot; @@ -1490,15 +1493,15 @@ REC VIO_gc_record(TDBB tdbb, REL relation) /* Allocate a vector of garbage collect record blocks for relation. */ if (!(vector = relation->rel_gc_rec)) { - vector = ALL_vector(dbb->dbb_permanent, &relation->rel_gc_rec, 0); + vector = relation->rel_gc_rec = vec::newVector(*dbb->dbb_permanent, 1); } /* Set the active flag on an inactive garbage collect record block and return it. */ - for (rec_ptr = (REC *) vector->vec_object, end = - rec_ptr + vector->vec_count; rec_ptr < end; rec_ptr++) - if ((record = *rec_ptr) && !(record->rec_flags & REC_gc_active)) { + for (rec_ptr = vector->begin(), end = + vector->end(); rec_ptr != end; ++rec_ptr) + if ((record = *(REC*)rec_ptr) && !(record->rec_flags & REC_gc_active)) { record->rec_flags |= REC_gc_active; /* V4_MUTEX_UNLOCK (&relation->rel_mutex); */ return record; @@ -1514,11 +1517,10 @@ REC VIO_gc_record(TDBB tdbb, REL relation) /* Insert the new record block into the last slot of the vector. */ - slot = vector->vec_count - 1; - if (vector->vec_object[slot]) - vector = - ALL_vector(dbb->dbb_permanent, &relation->rel_gc_rec, ++slot); - vector->vec_object[slot] = (BLK) record; + slot = vector->count() - 1; + if ((*vector)[slot]) + vector->resize((++slot) + 1); + (*vector)[slot] = (BLK) record; /* V4_MUTEX_UNLOCK (&relation->rel_mutex); */ return record; @@ -1543,9 +1545,9 @@ int VIO_get(TDBB tdbb, RPB * rpb, RSB rsb, TRA transaction, BLK pool) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS) - ib_printf("VIO_get (rpb %d, transaction %d, pool %d)\n", + ib_printf("VIO_get (rpb %"SLONGFORMAT", transaction %d, pool %p)\n", rpb->rpb_number, transaction ? transaction->tra_number : 0, - pool ? ((PLB) pool)->plb_pool_id : 0); + pool); #endif /* Fetch data page from a modify/erase input stream with a write @@ -1566,7 +1568,7 @@ int VIO_get(TDBB tdbb, RPB * rpb, RSB rsb, TRA transaction, BLK pool) #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -1609,9 +1611,9 @@ int VIO_get_current( #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE) - ib_printf("VIO_get_current (rpb %d, transaction %d, pool %d)\n", + ib_printf("VIO_get_current (rpb %"SLONGFORMAT", transaction %d, pool %p)\n", rpb->rpb_number, transaction ? transaction->tra_number : 0, - pool ? ((PLB) pool)->plb_pool_id : 0); + pool ); #endif while (TRUE) { @@ -1623,7 +1625,7 @@ int VIO_get_current( #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -1852,12 +1854,12 @@ void VIO_modify(TDBB tdbb, RPB * org_rpb, RPB * new_rpb, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("VIO_modify (org_rpb %d, new_rpb %d, transaction %d)\n", + ib_printf("VIO_modify (org_rpb %"SLONGFORMAT", new_rpb %"SLONGFORMAT", transaction %d)\n", org_rpb->rpb_number, new_rpb->rpb_number, transaction ? transaction->tra_number : 0); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" old record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" old record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", org_rpb->rpb_page, org_rpb->rpb_line, org_rpb->rpb_transaction, org_rpb->rpb_flags, org_rpb->rpb_b_page, org_rpb->rpb_b_line, org_rpb->rpb_f_page, org_rpb->rpb_f_line); @@ -1978,6 +1980,8 @@ void VIO_modify(TDBB tdbb, RPB * org_rpb, RPB * new_rpb, TRA transaction) EVL_field(0, org_rpb->rpb_record, f_trg_name, &desc1); DFW_post_work(transaction, dfw_modify_trigger, &desc1, 0); break; + default: + break; } /* We're almost ready to go. To modify the record, we must first @@ -2058,12 +2062,12 @@ BOOLEAN VIO_next_record(TDBB tdbb, #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE) - ib_printf("VIO_next_record (rpb %d, transaction %d, pool %d)\n", + ib_printf("VIO_next_record (rpb %"SLONGFORMAT", transaction %d, pool %p)\n", rpb->rpb_number, transaction ? transaction->tra_number : 0, - pool ? ((PLB) pool)->plb_pool_id : 0); + pool); if (debug_flag > DEBUG_TRACE_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -2085,7 +2089,7 @@ BOOLEAN VIO_next_record(TDBB tdbb, #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - ("VIO_next_record got record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + ("VIO_next_record got record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -2097,7 +2101,7 @@ BOOLEAN VIO_next_record(TDBB tdbb, } -REC VIO_record(TDBB tdbb, register RPB * rpb, FMT format, struct plb * pool) +REC VIO_record(TDBB tdbb, register RPB * rpb, FMT format, JrdMemoryPool *pool) { /************************************** * @@ -2118,9 +2122,9 @@ REC VIO_record(TDBB tdbb, register RPB * rpb, FMT format, struct plb * pool) #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE) - ib_printf("VIO_record (rpb %d, format %d, pool %d)\n", + ib_printf("VIO_record (rpb %"SLONGFORMAT", format %d, pool %p)\n", rpb->rpb_number, format ? format->fmt_version : 0, - pool ? ((PLB) pool)->plb_pool_id : 0); + pool); #endif /* If format wasn't given, look one up */ @@ -2131,8 +2135,7 @@ REC VIO_record(TDBB tdbb, register RPB * rpb, FMT format, struct plb * pool) if (!(record = rpb->rpb_record)) { if (!pool) pool = dbb->dbb_permanent; - record = rpb->rpb_record = - (REC) ALL_alloc(pool, type_rec, format->fmt_length, ERR_jmp); + record = rpb->rpb_record = new(*pool, format->fmt_length) rec; record->rec_length = format->fmt_length; } else if (record->rec_length < format->fmt_length) { @@ -2142,10 +2145,12 @@ REC VIO_record(TDBB tdbb, register RPB * rpb, FMT format, struct plb * pool) replace_gc_record(rpb->rpb_relation, &rpb->rpb_record, format->fmt_length); else - record = - (REC) ALL_extend(reinterpret_cast < - blk ** >(&rpb->rpb_record), - format->fmt_length); + { + record = new(*MemoryPool::blk_pool(record), format->fmt_length) rec; + memcpy(record, rpb->rpb_record, sizeof(rec) + sizeof(SCHAR)*rpb->rpb_record->rec_length); + delete rpb->rpb_record; + rpb->rpb_record = record; + } record->rec_length = format->fmt_length; if (rpb->rpb_prior == old) @@ -2179,10 +2184,10 @@ void VIO_start_save_point(TDBB tdbb, TRA transaction) SET_TDBB(tdbb); - if (sav_point = transaction->tra_save_free) + if ( (sav_point = transaction->tra_save_free) ) transaction->tra_save_free = sav_point->sav_next; else - sav_point = (SAV) ALLOCT(type_sav); + sav_point = new(*transaction->tra_pool) sav(); sav_point->sav_number = ++transaction->tra_save_point_number; sav_point->sav_next = transaction->tra_save_point; @@ -2212,7 +2217,7 @@ void VIO_store(TDBB tdbb, RPB * rpb, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("VIO_store (rpb %d, transaction %d)\n", rpb->rpb_number, + ib_printf("VIO_store (rpb %"SLONGFORMAT", transaction %d)\n", rpb->rpb_number, transaction ? transaction->tra_number : 0); #endif @@ -2299,6 +2304,8 @@ void VIO_store(TDBB tdbb, RPB * rpb, TRA transaction) case rel_log: DFW_post_work(transaction, dfw_create_log, 0, 0); break; + default: /* Shut up compiler warnings */ + break; } rpb->rpb_b_page = 0; @@ -2312,7 +2319,7 @@ void VIO_store(TDBB tdbb, RPB * rpb, TRA transaction) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -2370,21 +2377,11 @@ BOOLEAN VIO_sweep(TDBB tdbb, TRA transaction) old_env = (JMP_BUF *) tdbb->tdbb_setjmp; tdbb->tdbb_setjmp = (UCHAR *) env; - if (SETJMP(env)) { - tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (rpb.rpb_record) - ALL_release(reinterpret_cast < frb * >(rpb.rpb_record)); - if (relation) { - if (relation->rel_sweep_count) - --relation->rel_sweep_count; - if (relation->rel_scan_count) - --relation->rel_scan_count; - } - ERR_punt(); - } - for (i = 1; (vector = dbb->dbb_relations) && i < vector->vec_count; i++) - if ((relation = (REL) vector->vec_object[i]) && relation->rel_pages && + try { + + for (i = 1; (vector = dbb->dbb_relations) && i < vector->count(); i++) + if ((relation = (REL) (*vector)[i]) && relation->rel_pages && !(relation->rel_flags & (REL_deleted | REL_deleting))) { rpb.rpb_relation = relation; rpb.rpb_number = -1; @@ -2406,8 +2403,25 @@ BOOLEAN VIO_sweep(TDBB tdbb, TRA transaction) } tdbb->tdbb_setjmp = (UCHAR *) old_env; - if (rpb.rpb_record) - ALL_release(reinterpret_cast < frb * >(rpb.rpb_record)); + if (rpb.rpb_record) { + delete rpb.rpb_record; + } + + } // try + catch (...) { + tdbb->tdbb_setjmp = (UCHAR *) old_env; + delete rpb.rpb_record; + if (relation) + { + if (relation->rel_sweep_count) { + --relation->rel_sweep_count; + } + if (relation->rel_scan_count) { + --relation->rel_scan_count; + } + } + ERR_punt(); + } return TRUE; } @@ -2442,7 +2456,7 @@ void VIO_verb_cleanup(TDBB tdbb, TRA transaction) LLS stack; SAV sav_point; BOOLEAN same_tx = FALSE; - struct plb *old_pool; + JrdMemoryPool *old_pool; SLONG savep_size; SET_TDBB(tdbb); @@ -2497,7 +2511,7 @@ void VIO_verb_cleanup(TDBB tdbb, TRA transaction) } } - while (action = sav_point->sav_verb_actions) { + while ( (action = sav_point->sav_verb_actions) ) { sav_point->sav_verb_actions = action->vct_next; relation = action->vct_relation; if (sav_point->sav_verb_count || transaction->tra_save_point) { @@ -2643,14 +2657,13 @@ void VIO_verb_cleanup(TDBB tdbb, TRA transaction) } if (rpb.rpb_record) - ALL_release(reinterpret_cast < frb * >(rpb.rpb_record)); + delete rpb.rpb_record; } SBM_reset(&action->vct_records); SBM_reset(&action->vct_undo); while (action->vct_data) - ALL_release(reinterpret_cast < - frb * >(LLS_POP(&action->vct_data))); + delete LLS_POP(&action->vct_data); action->vct_next = sav_point->sav_verb_free; sav_point->sav_verb_free = action; @@ -2765,15 +2778,10 @@ static void bump_count(TDBB tdbb, USHORT count_id, REL relation) relation_id = relation->rel_id; ptr = tdbb->tdbb_attachment->att_counts + count_id; - if (!(vector = *ptr) || relation_id >= vector->vcl_count) - vector = - reinterpret_cast < - vcl * - >(ALL_vector - (dbb->dbb_permanent, reinterpret_cast < vec ** >(ptr), - relation_id)); + if (!(vector = *ptr) || relation_id >= vector->count()) + vector = *ptr = vcl::newVector(*dbb->dbb_permanent, relation_id + 1); - ++vector->vcl_long[relation_id]; + ++((*vector)[relation_id]); } @@ -2868,7 +2876,7 @@ static BOOLEAN check_user(TDBB tdbb, DSC * desc) } -static void delete_(TDBB tdbb, RPB * rpb, SLONG prior_page, struct plb *pool) +static void delete_(TDBB tdbb, RPB * rpb, SLONG prior_page, JrdMemoryPool *pool) { /************************************** * @@ -2891,12 +2899,12 @@ static void delete_(TDBB tdbb, RPB * rpb, SLONG prior_page, struct plb *pool) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("delete_ (rpb %d, prior_page %ld, pool %d)\n", + ib_printf("delete_ (rpb %"SLONGFORMAT", prior_page %ld, pool %p)\n", rpb->rpb_number, prior_page, - (pool) ? pool->plb_pool_id : 0); + pool); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" delete_ record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" delete_ record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -2907,7 +2915,7 @@ static void delete_(TDBB tdbb, RPB * rpb, SLONG prior_page, struct plb *pool) } else { record = VIO_record(tdbb, rpb, 0, pool); - if (prior = rpb->rpb_prior) { + if ( (prior = rpb->rpb_prior) ) { tail = differences; tail_end = differences + sizeof(differences); if (prior != record) @@ -2960,11 +2968,11 @@ static UCHAR *delete_tail( #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) ib_printf - ("delete_tail (rpb %d, prior_page %ld, tail %x, tail_end %x)\n", + ("delete_tail (rpb %"SLONGFORMAT", prior_page %ld, tail %x, tail_end %x)\n", rpb->rpb_number, prior_page, tail, tail_end); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" tail of record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" tail of record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -3016,7 +3024,7 @@ static void expunge(TDBB tdbb, RPB * rpb, TRA transaction, SLONG prior_page) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("expunge (rpb %d, transaction %d, prior_page %d)\n", + ib_printf("expunge (rpb %"SLONGFORMAT", transaction %d, prior_page %"SLONGFORMAT")\n", rpb->rpb_number, transaction ? transaction->tra_number : 0, prior_page); #endif @@ -3031,7 +3039,7 @@ static void expunge(TDBB tdbb, RPB * rpb, TRA transaction, SLONG prior_page) #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" expunge record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" expunge record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -3086,11 +3094,11 @@ static void garbage_collect( #ifdef VIO_DEBUG if (debug_flag > DEBUG_WRITES) - ib_printf("garbage_collect (rpb %d, prior_page %d, staying)\n", + ib_printf("garbage_collect (rpb %"SLONGFORMAT", prior_page %"SLONGFORMAT", staying)\n", rpb->rpb_number, prior_page); if (debug_flag > DEBUG_WRITES_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -3123,7 +3131,7 @@ static void garbage_collect( IDX_garbage_collect(tdbb, rpb, going, staying); while (going) - ALL_release(reinterpret_cast < frb * >(LLS_POP(&going))); + delete LLS_POP(&going); } @@ -3170,7 +3178,7 @@ static void garbage_collect_idx( LLS_POP(&going); while (staying) - ALL_release(reinterpret_cast < frb * >(LLS_POP(&staying))); + delete LLS_POP(&staying); } @@ -3227,13 +3235,11 @@ static void THREAD_ROUTINE garbage_collector(DBB dbb) /* Surrender if resources to start up aren't available. */ - if (SETJMP(env)) { - goto gc_exit; - } + try { /* Pseudo attachment needed for lock owner identification. */ - tdbb->tdbb_attachment = (ATT) ALLOCP(type_att); + tdbb->tdbb_attachment = new(*dbb->dbb_permanent) att(); tdbb->tdbb_attachment->att_database = dbb; tdbb->tdbb_attachment->att_flags = ATT_garbage_collector; @@ -3246,14 +3252,13 @@ static void THREAD_ROUTINE garbage_collector(DBB dbb) dbb->dbb_flags |= DBB_garbage_collector; ISC_event_post(gc_event); - if (SETJMP(env)) { - /* Perfunctory error reporting -- got any better ideas ? */ - - gds__log_status(dbb->dbb_file->fil_string, status_vector); - if (relation && relation->rel_sweep_count) - --relation->rel_sweep_count; + } // try + catch (...) { + goto gc_exit; } + try { + /* Initialize status vector after logging error. */ MOVE_CLEAR(status_vector, sizeof(status_vector)); @@ -3261,7 +3266,8 @@ static void THREAD_ROUTINE garbage_collector(DBB dbb) /* The garbage collector flag is cleared to request the thread to finish up and exit. */ - while (dbb->dbb_flags & DBB_garbage_collector) { + while (dbb->dbb_flags & DBB_garbage_collector) + { count = ISC_event_clear(gc_event); dbb->dbb_flags |= DBB_gc_active; found = FALSE; @@ -3304,9 +3310,9 @@ static void THREAD_ROUTINE garbage_collector(DBB dbb) Express interest in the relation to prevent it from being deleted out from under us while garbage collection is in-progress. */ - for (id = 0; (vector = dbb->dbb_relations) && id < vector->vec_count; + for (id = 0; (vector = dbb->dbb_relations) && id < vector->count(); id++) - if ((relation = (REL) vector->vec_object[id]) + if ((relation = (REL) (*vector)[id]) && relation->rel_gc_bitmap != 0 && !(relation->rel_flags & (REL_deleted | REL_deleting))) { ++relation->rel_sweep_count; @@ -3422,15 +3428,15 @@ static void THREAD_ROUTINE garbage_collector(DBB dbb) } } - gc_exit: +gc_exit: if (rpb.rpb_record) - ALL_release(reinterpret_cast < frb * >(rpb.rpb_record)); /* Possibly allocated from permanent pool. */ + delete rpb.rpb_record; /* Possibly allocated from permanent pool. */ if (transaction) TRA_commit(tdbb, transaction, FALSE); if (tdbb->tdbb_attachment) { LCK_fini(tdbb, LCK_OWNER_attachment); - ALL_release(reinterpret_cast < frb * >(tdbb->tdbb_attachment)); + delete tdbb->tdbb_attachment; } dbb->dbb_flags &= ~(DBB_garbage_collector | DBB_gc_active | DBB_gc_pending); @@ -3439,6 +3445,16 @@ static void THREAD_ROUTINE garbage_collector(DBB dbb) RESTORE_THREAD_DATA; THREAD_EXIT; + + } // try + catch (...) { + /* Perfunctory error reporting -- got any better ideas ? */ + + gds__log_status(dbb->dbb_file->fil_string, status_vector); + if (relation && relation->rel_sweep_count) { + --relation->rel_sweep_count; + } + } } #endif @@ -3458,10 +3474,10 @@ static SAV get_free_save_point_block(TRA transaction) **************************************/ SAV sav_point; - if (sav_point = transaction->tra_save_free) + if ( (sav_point = transaction->tra_save_free) ) transaction->tra_save_free = sav_point->sav_next; else - sav_point = (SAV) ALLOCT(type_sav); + sav_point = new(*transaction->tra_pool) sav(); return sav_point; } @@ -3507,7 +3523,7 @@ static void list_staying(TDBB tdbb, RPB * rpb, LLS * staying) /* If the entire record disappeared, then there is nothing staying. */ if (!DPM_fetch(tdbb, &temp, LCK_read)) { while (*staying) - ALL_release(reinterpret_cast < frb * >(LLS_POP(staying))); + delete LLS_POP(staying); return; } @@ -3518,7 +3534,7 @@ static void list_staying(TDBB tdbb, RPB * rpb, LLS * staying) temp.rpb_b_line != rpb->rpb_b_line || temp.rpb_flags != rpb->rpb_flags) { while (*staying) - ALL_release(reinterpret_cast < frb * >(LLS_POP(staying))); + delete LLS_POP(staying); next_page = temp.rpb_page; next_line = temp.rpb_line; max_depth = 0; @@ -3575,7 +3591,7 @@ static void list_staying(TDBB tdbb, RPB * rpb, LLS * staying) in 'staying' that have already been garbage collected. */ while (depth < max_depth--) if (*staying) - ALL_release(reinterpret_cast < frb * >(LLS_POP(staying))); + delete LLS_POP(staying); } @@ -3598,7 +3614,7 @@ static void notify_garbage_collector(TDBB tdbb, RPB * rpb) **************************************/ DBB dbb; REL relation; - PLB old_pool; + JrdMemoryPool *old_pool; SLONG dp_sequence; dbb = tdbb->tdbb_database; @@ -3660,16 +3676,16 @@ static void prepare_update( #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) { ib_printf - ("prepare_update (transaction %d, commit_tid read %ld, rpb %d, ", + ("prepare_update (transaction %"SLONGFORMAT", commit_tid read %ld, rpb %"SLONGFORMAT", ", transaction ? transaction->tra_number : 0, commit_tid_read, rpb ? rpb->rpb_number : 0); - ib_printf(" temp_rpb %d, new_rpb %d, stack)\n", + ib_printf(" temp_rpb %"SLONGFORMAT", new_rpb %"SLONGFORMAT", stack)\n", temp ? temp->rpb_number : 0, new_rpb ? new_rpb->rpb_number : 0); } if (debug_flag > DEBUG_TRACE_ALL_INFO) ib_printf - (" old record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d, prior %d\n", + (" old record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d, prior %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_prior); @@ -3785,7 +3801,7 @@ static void prepare_update( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record's transaction (%d) is committed (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is committed (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif if (rpb->rpb_flags & rpb_deleted) { @@ -3831,7 +3847,7 @@ static void prepare_update( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO && state == tra_us) ib_printf - (" record's transaction (%d) is us (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is us (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif @@ -3874,7 +3890,7 @@ static void prepare_update( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) { ib_printf - (" record's transaction (%d) is %s (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is %s (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, (state == tra_active) ? "active" : "limbo", transaction->tra_number); @@ -3945,7 +3961,7 @@ static void prepare_update( #ifdef VIO_DEBUG if (debug_flag > DEBUG_READS_INFO) ib_printf - (" record's transaction (%d) is dead (my TID - %d)\n", + (" record's transaction (%"SLONGFORMAT") is dead (my TID - %"SLONGFORMAT")\n", rpb->rpb_transaction, transaction->tra_number); #endif CCH_RELEASE(tdbb, &rpb->rpb_window); @@ -3991,10 +4007,10 @@ static BOOLEAN purge(TDBB tdbb, RPB * rpb) #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) - ib_printf("purge (rpb %d)\n", rpb->rpb_number); + ib_printf("purge (rpb %"SLONGFORMAT")\n", rpb->rpb_number); if (debug_flag > DEBUG_TRACE_ALL_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line); @@ -4061,20 +4077,22 @@ static REC replace_gc_record(REL relation, REC * gc_record, USHORT length) * **************************************/ VEC vector; - REC *rec_ptr, *end; + REC temp; + vec::iterator rec_ptr, end; /* V4_MUTEX_LOCK (&relation->rel_mutex); */ vector = relation->rel_gc_rec; - for (rec_ptr = (REC *) vector->vec_object, end = - rec_ptr + vector->vec_count; rec_ptr < end; ++rec_ptr) + for (rec_ptr = vector->begin(), end = vector->end(); rec_ptr < end; + ++rec_ptr) if (*rec_ptr == *gc_record) { - *rec_ptr = - (REC) ALL_extend(reinterpret_cast < blk ** >(gc_record), - length); + temp = new(*MemoryPool::blk_pool(*gc_record), length) rec; + memcpy(temp, *rec_ptr, sizeof(rec) + sizeof(SCHAR)*(*gc_record)->rec_length); + delete *rec_ptr; + *rec_ptr = temp; /* V4_MUTEX_UNLOCK (&relation->rel_mutex); */ - return *rec_ptr; + return (REC)*rec_ptr; } /* V4_MUTEX_UNLOCK (&relation->rel_mutex); */ @@ -4103,11 +4121,11 @@ static void replace_record( #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) - ib_printf("replace_record (rpb %d, stack, transaction %d)\n", + ib_printf("replace_record (rpb %"SLONGFORMAT", stack, transaction %"SLONGFORMAT")\n", rpb->rpb_number, transaction ? transaction->tra_number : 0); if (debug_flag > DEBUG_TRACE_ALL_INFO) ib_printf - (" record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d, prior %d\n", + (" record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d, prior %d\n", rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction, rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, rpb->rpb_f_page, rpb->rpb_f_line, rpb->rpb_prior); @@ -4215,12 +4233,12 @@ static void update_in_place( #ifdef VIO_DEBUG if (debug_flag > DEBUG_TRACE_ALL) ib_printf - ("update_in_place (transaction %d, org_rpb %d, new_rpb %d)\n", + ("update_in_place (transaction %d, org_rpb %"SLONGFORMAT", new_rpb %d)\n", transaction ? transaction->tra_number : 0, org_rpb->rpb_number, new_rpb ? new_rpb->rpb_number : 0); if (debug_flag > DEBUG_TRACE_ALL_INFO) ib_printf - (" old record %d:%d, rpb_trans %d, flags %d, back %d:%d, fragment %d:%d\n", + (" old record %"SLONGFORMAT":%d, rpb_trans %"SLONGFORMAT", flags %d, back %"SLONGFORMAT":%d, fragment %"SLONGFORMAT":%d\n", org_rpb->rpb_page, org_rpb->rpb_line, org_rpb->rpb_transaction, org_rpb->rpb_flags, org_rpb->rpb_b_page, org_rpb->rpb_b_line, org_rpb->rpb_f_page, org_rpb->rpb_f_line); @@ -4236,7 +4254,7 @@ static void update_in_place( with an old "complete" record, update in placement, then delete the old delta record */ - if (prior = org_rpb->rpb_prior) { + if ( (prior = org_rpb->rpb_prior) ) { temp2 = *org_rpb; temp2.rpb_record = VIO_gc_record(tdbb, relation); temp2.rpb_page = org_rpb->rpb_b_page; @@ -4303,7 +4321,7 @@ static void update_in_place( LLS_POP(&staying); while (staying) - ALL_release(reinterpret_cast < frb * >(LLS_POP(&staying))); + delete LLS_POP(&staying); } if (prior) { @@ -4345,7 +4363,7 @@ static void verb_post( * **************************************/ VCT action; - struct plb *old_pool; + JrdMemoryPool *old_pool; REC data, record; UCHAR *p, *q, *end; LLS stack; @@ -4363,10 +4381,10 @@ static void verb_post( break; if (!action) { - if (action = transaction->tra_save_point->sav_verb_free) + if ( (action = transaction->tra_save_point->sav_verb_free) ) transaction->tra_save_point->sav_verb_free = action->vct_next; else - action = (VCT) ALLOCD(type_vct); + action = new(*tdbb->tdbb_default) vct(); action->vct_next = transaction->tra_save_point->sav_verb_actions; transaction->tra_save_point->sav_verb_actions = action; action->vct_relation = rpb->rpb_relation; @@ -4379,7 +4397,7 @@ static void verb_post( savepoint hasn't seen this record before. */ SBM_set(tdbb, &action->vct_undo, rpb->rpb_number); - data = (REC) ALLOCDV(type_rec, old_data->rec_length); + data = new(*tdbb->tdbb_default, old_data->rec_length) rec(); data->rec_number = rpb->rpb_number; data->rec_length = old_data->rec_length; data->rec_format = old_data->rec_format; @@ -4395,7 +4413,7 @@ static void verb_post( and this savepoint hasn't seen this record before. */ SBM_set(tdbb, &action->vct_undo, rpb->rpb_number); - data = (REC) ALLOCDV(type_rec, FUDGE); + data = new(*tdbb->tdbb_default, 1) rec; data->rec_number = rpb->rpb_number; data->rec_length = 0; if (new_ver) @@ -4424,7 +4442,7 @@ static void verb_post( undo data. */ SBM_set(tdbb, &action->vct_undo, rpb->rpb_number); - data = (REC) ALLOCDV(type_rec, FUDGE); + data = new(*tdbb->tdbb_default, 1) rec(); data->rec_number = rpb->rpb_number; data->rec_length = 0; data->rec_flags |= (REC_same_tx | REC_new_version); diff --git a/src/jrd/vio_proto.h b/src/jrd/vio_proto.h index 8db5a2606f..1ca930fed1 100644 --- a/src/jrd/vio_proto.h +++ b/src/jrd/vio_proto.h @@ -29,7 +29,7 @@ extern "C" { #endif extern void VIO_backout(TDBB, struct rpb *, struct tra *); -extern int VIO_chase_record_version(TDBB, struct rpb *, struct rsb *, +extern int VIO_chase_record_version(TDBB, struct rpb *, class Rsb *, struct tra *, struct blk *); #ifdef PC_ENGINE extern int VIO_check_if_updated(TDBB, struct rpb *); @@ -41,7 +41,7 @@ extern void VIO_fini(TDBB); #endif extern int VIO_garbage_collect(TDBB, struct rpb *, struct tra *); extern struct rec *VIO_gc_record(TDBB, struct rel *); -extern int VIO_get(TDBB, struct rpb *, struct rsb *, struct tra *, +extern int VIO_get(TDBB, struct rpb *, class Rsb *, struct tra *, struct blk *); extern int VIO_get_current(TDBB, struct rpb *, struct tra *, struct blk *, USHORT); @@ -50,10 +50,10 @@ extern void VIO_init(TDBB); #endif extern void VIO_merge_proc_sav_points(TDBB, struct tra *, struct sav **); extern void VIO_modify(TDBB, struct rpb *, struct rpb *, struct tra *); -extern BOOLEAN VIO_next_record(TDBB, struct rpb *, struct rsb *, struct tra *, +extern BOOLEAN VIO_next_record(TDBB, struct rpb *, class Rsb *, struct tra *, struct blk *, BOOLEAN, BOOLEAN); extern struct rec *VIO_record(TDBB, register struct rpb *, struct fmt *, - struct plb *); + JrdMemoryPool *); extern void VIO_start_save_point(TDBB, struct tra *); extern void VIO_store(TDBB, struct rpb *, struct tra *); extern BOOLEAN VIO_sweep(TDBB, struct tra *); diff --git a/src/jrd/vms.cpp b/src/jrd/vms.cpp index 5f8946c0ed..64bb798683 100644 --- a/src/jrd/vms.cpp +++ b/src/jrd/vms.cpp @@ -827,7 +827,7 @@ static FIL setup_file( /* Allocate file block and move in file name */ - file = ALLOCPV(type_fil, file_length + 1); + file = new(dbb->dbb_permanent, file_length + 1) fil(); file->fil_desc = chan; file->fil_length = file_length; file->fil_max_page = -1; @@ -875,7 +875,7 @@ static FIL setup_file( while (--l); l = p - lock_id; - dbb->dbb_lock = lock = ALLOCPV(type_lck, l); + dbb->dbb_lock = lock = new(dbb->dbb_permanent, l) lck(); lock->lck_type = LCK_database; lock->lck_owner_handle = LCK_get_owner_handle(NULL_TDBB, lock->lck_type); lock->lck_object = dbb; diff --git a/src/jrd/why.c b/src/jrd/why.c index 59c70205c1..f067ac04a5 100644 --- a/src/jrd/why.c +++ b/src/jrd/why.c @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: why.c,v 1.3 2001-07-29 17:42:23 skywalker Exp $ +$Id: why.c,v 1.4 2001-12-24 02:50:52 tamlin Exp $ */ #include "firebird.h" @@ -595,7 +595,7 @@ static CONST_IMAGE IMAGE images[] = {"GDS_A", GDS_A_PATH}, {"GDS_B", GDS_B_PATH}, {"GDS_C", GDS_C_PATH}, - {"GDS_D", GDS_D_PATH} + {"GDS_D", GDS_D_PATH}, #endif #ifdef IPSERV #ifndef XNET diff --git a/src/jrd/windows.cpp b/src/jrd/windows.cpp index 4f0ce664a4..7abe57457e 100644 --- a/src/jrd/windows.cpp +++ b/src/jrd/windows.cpp @@ -665,7 +665,7 @@ static FIL setup_file( /* Allocate file block and copy file name string */ - file = (FIL) ALLOCPV(type_fil, file_length + 1); + file = new(dbb->dbb_permanent, file_length + 1) fil(); file->fil_desc = desc; file->fil_length = file_length; file->fil_max_page = -1; @@ -687,7 +687,7 @@ static FIL setup_file( l = file_length; lock_string = file_name; - dbb->dbb_lock = lock = (LCK) ALLOCPV(type_lck, l); + dbb->dbb_lock = lock = new(dbb->dbb_permanent, l) lck(); lock->lck_type = LCK_database; lock->lck_owner_handle = LCK_get_owner_handle(NULL_TDBB, lock->lck_type); lock->lck_object = (BLK) dbb; diff --git a/src/jrd/winnt.cpp b/src/jrd/winnt.cpp index a5cd637c7e..2dbcc00ea4 100644 --- a/src/jrd/winnt.cpp +++ b/src/jrd/winnt.cpp @@ -22,7 +22,14 @@ * 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" * conditionals, as the engine now fully supports * readonly databases. - * 02 Nov 2001: Mike Nordell - Synch with FB1 changes. + * + * 02-Nov-2001 Mike Nordell: Synch with FB1 changes. + * + * 17-Oct-2001 Mike Nordell: Non-shared file access + * + * 20-Nov-2001 Ann Harrison: Make page count work on db with forced write + * + * 21-Nov-2001 Ann Harrison: Allow read sharing so gstat works */ #ifdef _MSC_VER @@ -57,9 +64,6 @@ #include -extern "C" { - - #ifdef TEXT #undef TEXT #endif @@ -77,6 +81,8 @@ extern "C" { #ifdef SUPERSERVER_V2 static void release_io_event(FIL, OVERLAPPED *); #endif +static ULONG get_number_of_pages(FIL, USHORT); +static bool MaybeCloseFile(SLONG *); static FIL seek_file(FIL, BDB, STATUS *, OVERLAPPED *, OVERLAPPED **); static FIL setup_file(DBB, TEXT *, USHORT, HANDLE); static BOOLEAN nt_error(TEXT *, FIL, STATUS, STATUS *); @@ -84,13 +90,12 @@ static BOOLEAN nt_error(TEXT *, FIL, STATUS, STATUS *); static USHORT ostype; #ifdef SUPERSERVER_V2 -static const DWORD g_dwShareFlags = 0; /* no sharing */ +static const DWORD g_dwShareFlags = FILE_SHARE_READ; // no write sharing static const DWORD g_dwExtraFlags = FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING | FILE_FLAG_RANDOM_ACCESS; #elif SUPERSERVER -/* TMN: Disable file sharing */ -static const DWORD g_dwShareFlags = 0; /* no sharing */ +static const DWORD g_dwShareFlags = FILE_SHARE_READ; // no write sharing static const DWORD g_dwExtraFlags = FILE_FLAG_RANDOM_ACCESS; #else static const DWORD g_dwShareFlags = FILE_SHARE_READ | FILE_SHARE_WRITE; @@ -98,18 +103,7 @@ static const DWORD g_dwExtraFlags = FILE_FLAG_RANDOM_ACCESS; #endif -/* A little helper function to clean up closing of file handles. */ -static bool MaybeCloseFile(SLONG* pFile) -{ - if (pFile && (HANDLE)*pFile != INVALID_HANDLE_VALUE) - { - CloseHandle((HANDLE)*pFile); - *pFile = (SLONG) INVALID_HANDLE_VALUE; - return true; - } - return false; -} - +extern "C" { /************************************** @@ -460,29 +454,6 @@ void PIO_header(DBB dbb, SCHAR * address, int length) -/************************************** - * - * Compute number of pages in file, based only on file size. - * - **************************************/ -static ULONG private_PIO_get_number_of_pages(FIL file, USHORT pagesize) -{ - HANDLE hFile = (HANDLE) file->fil_desc; - DWORD dwFileSizeLow; - DWORD dwFileSizeHigh; - ULONGLONG ullFileSize; - - dwFileSizeLow = GetFileSize(hFile, &dwFileSizeHigh); - - if (dwFileSizeLow == -1) { - nt_error("GetFileSize", file, isc_io_access_err, 0); - } - - ullFileSize = (((ULONGLONG) dwFileSizeHigh) << 32) + dwFileSizeLow; - return (ULONG) ((ullFileSize + pagesize - 1) / pagesize); -} - - /************************************** * * Compute last physically allocated page of database. @@ -491,13 +462,12 @@ static ULONG private_PIO_get_number_of_pages(FIL file, USHORT pagesize) SLONG PIO_max_alloc(DBB dbb) { FIL file = dbb->dbb_file; - ULONG nPages; while (file->fil_next) { file = file->fil_next; } - nPages = private_PIO_get_number_of_pages(file, dbb->dbb_page_size); + ULONG nPages = get_number_of_pages(file, dbb->dbb_page_size); return file->fil_min_page - file->fil_fudge + nPages; } @@ -518,8 +488,7 @@ SLONG PIO_act_alloc(DBB dbb) ** in each file **/ for (file = dbb->dbb_file; file != NULL; file = file->fil_next) { - tot_pages += - private_PIO_get_number_of_pages(file, dbb->dbb_page_size); + tot_pages += get_number_of_pages(file, dbb->dbb_page_size); } return tot_pages; @@ -635,14 +604,20 @@ int PIO_read(FIL file, BDB bdb, PAG page, STATUS * status_vector) file->fil_force_write_desc : file->fil_desc); #ifdef ISC_DATABASE_ENCRYPTION - if (dbb->dbb_encrypt_key) { + if (dbb->dbb_encrypt_key) + { SLONG spare_buffer[MAX_PAGE_SIZE / sizeof(SLONG)]; - if (!ReadFile - (desc, spare_buffer, size, &actual_length, overlapped_ptr) - || actual_length != size) { - if (ostype == OS_CHICAGO) + if (!ReadFile(desc, + spare_buffer, + size, + &actual_length, + overlapped_ptr) + || actual_length != size) + { + if (ostype == OS_CHICAGO) { THD_MUTEX_UNLOCK(file->fil_mutex); + } return nt_error("ReadFile", file, isc_io_read_err, status_vector); } @@ -692,11 +667,12 @@ int PIO_read(FIL file, BDB bdb, PAG page, STATUS * status_vector) #ifdef SUPERSERVER_V2 -int PIO_read_ahead( - DBB dbb, - SLONG start_page, - SCHAR * buffer, - SLONG pages, PIOB piob, STATUS * status_vector) +int PIO_read_ahead(DBB dbb, + SLONG start_page, + SCHAR* buffer, + SLONG pages, + PIOB piob, + STATUS* status_vector) { /************************************** * @@ -733,9 +709,10 @@ int PIO_read_ahead( bdb.bdb_dbb = dbb; bdb.bdb_page = start_page; - file = - seek_file(dbb->dbb_file, &bdb, status_vector, overlapped_ptr, - &overlapped_ptr); + file = seek_file(dbb->dbb_file, + &bdb, status_vector, + overlapped_ptr, + &overlapped_ptr); if (!file) { return FALSE; } @@ -754,11 +731,16 @@ int PIO_read_ahead( desc = (HANDLE) ((file->fil_flags & FIL_force_write) ? file->fil_force_write_desc : file->fil_desc); - if (ReadFile - (desc, buffer, segmented_length, &actual_length, overlapped_ptr) - && actual_length == segmented_length) { - if (piob && !pages) + if (ReadFile( desc, + buffer, + segmented_length, + &actual_length, + overlapped_ptr) && + actual_length == segmented_length) + { + if (piob && !pages) { piob->piob_flags = PIOB_success; + } } else if (piob && !pages) { piob->piob_flags = PIOB_pending; @@ -766,12 +748,15 @@ int PIO_read_ahead( piob->piob_file = file; piob->piob_io_length = segmented_length; } - else - if (!GetOverlappedResult - (desc, overlapped_ptr, &actual_length, TRUE) - || actual_length != segmented_length) { - if (piob) - piob->piob_flags = PIOB_error; + else if (!GetOverlappedResult( desc, + overlapped_ptr, + &actual_length, + TRUE) || + actual_length != segmented_length) + { + if (piob) { + piob->piob_flags = PIOB_error; + } release_io_event(file, overlapped_ptr); return nt_error("GetOverlappedResult", file, isc_io_read_err, status_vector); @@ -837,20 +822,20 @@ int PIO_write(FIL file, BDB bdb, PAG page, STATUS* status_vector) * Write a data page. * **************************************/ - DBB dbb; - DWORD size, actual_length; - HANDLE desc; + + DWORD actual_length; OVERLAPPED overlapped, *overlapped_ptr; - dbb = bdb->bdb_dbb; - size = dbb->dbb_page_size; + DBB dbb = bdb->bdb_dbb; + DWORD size = dbb->dbb_page_size; - if (! - (file = - seek_file(file, bdb, status_vector, &overlapped, - &overlapped_ptr))) return FALSE; + file = seek_file(file, bdb, status_vector, &overlapped, + &overlapped_ptr); + if (!file) { + return FALSE; + } - desc = (HANDLE) ((file->fil_flags & FIL_force_write) ? + HANDLE desc = (HANDLE) ((file->fil_flags & FIL_force_write) ? file->fil_force_write_desc : file->fil_desc); #ifdef ISC_DATABASE_ENCRYPTION @@ -860,11 +845,12 @@ int PIO_write(FIL file, BDB bdb, PAG page, STATUS* status_vector) (*dbb->dbb_encrypt) (dbb->dbb_encrypt_key->str_data, page, size, spare_buffer); - if (!WriteFile - (desc, spare_buffer, size, &actual_length, overlapped_ptr) - || actual_length != size) { - if (ostype == OS_CHICAGO) + if (!WriteFile(desc, spare_buffer, size, &actual_length, overlapped_ptr) + || actual_length != size) + { + if (ostype == OS_CHICAGO) { THD_MUTEX_UNLOCK(file->fil_mutex); + } return nt_error("WriteFile", file, isc_io_write_err, status_vector); } @@ -899,13 +885,40 @@ int PIO_write(FIL file, BDB bdb, PAG page, STATUS* status_vector) release_io_event(file, overlapped_ptr); #endif - if (ostype == OS_CHICAGO) + if (ostype == OS_CHICAGO) { THD_MUTEX_UNLOCK(file->fil_mutex); + } return TRUE; } +} // extern "C" + + +/************************************** + * + * Compute number of pages in file, based only on file size. + * + **************************************/ +static ULONG get_number_of_pages(FIL file, USHORT pagesize) +{ + HANDLE hFile = (HANDLE) file->fil_desc; + DWORD dwFileSizeLow; + DWORD dwFileSizeHigh; + ULONGLONG ullFileSize; + + dwFileSizeLow = GetFileSize(hFile, &dwFileSizeHigh); + + if (dwFileSizeLow == -1) { + nt_error("GetFileSize", file, isc_io_access_err, 0); + } + + ullFileSize = (((ULONGLONG) dwFileSizeHigh) << 32) + dwFileSizeLow; + return (ULONG) ((ullFileSize + pagesize - 1) / pagesize); +} + + #ifdef SUPERSERVER_V2 static void release_io_event(FIL file, OVERLAPPED* overlapped) { @@ -963,10 +976,6 @@ static FIL seek_file(FIL file, HANDLE desc; LARGE_INTEGER liOffset; -#ifdef SUPERSERVER_V2 - USHORT i; -#endif - dbb = bdb->bdb_dbb; page = bdb->bdb_page; @@ -1009,7 +1018,7 @@ static FIL seek_file(FIL file, #ifdef SUPERSERVER_V2 THD_MUTEX_LOCK(file->fil_mutex); - for (i = 0; i < MAX_FILE_IO; i++) { + for (USHORT i = 0; i < MAX_FILE_IO; i++) { if (overlapped->hEvent = (HANDLE) file->fil_io_events[i]) { file->fil_io_events[i] = 0; break; @@ -1052,10 +1061,10 @@ static FIL setup_file(DBB dbb, /* Allocate file block and copy file name string */ - file = (FIL) ALLOCPV(type_fil, file_length + 1); - file->fil_desc = reinterpret_cast < long >(desc); + file = new(*dbb->dbb_permanent, file_length + 1) fil; + file->fil_desc = reinterpret_cast(desc); file->fil_force_write_desc = - reinterpret_cast < long >(INVALID_HANDLE_VALUE); + reinterpret_cast(INVALID_HANDLE_VALUE); file->fil_length = file_length; file->fil_max_page = -1; MOVE_FAST(file_name, file->fil_string, file_length); @@ -1070,7 +1079,7 @@ static FIL setup_file(DBB dbb, /* Set a local variable that indicates whether we're running under Windows/NT or Chicago */ - ostype = ISC_is_WinNT()? OS_WINDOWS_NT : OS_CHICAGO; + ostype = ISC_is_WinNT() ? OS_WINDOWS_NT : OS_CHICAGO; /* Build unique lock string for file and construct lock block */ @@ -1097,13 +1106,13 @@ static FIL setup_file(DBB dbb, l = p - lock_string; - dbb->dbb_lock = lock = (LCK) ALLOCPV(type_lck, l); + dbb->dbb_lock = lock = new(*dbb->dbb_permanent, l) lck; lock->lck_type = LCK_database; lock->lck_owner_handle = LCK_get_owner_handle(NULL_TDBB, lock->lck_type); - lock->lck_object = reinterpret_cast < blk * >(dbb); + lock->lck_object = reinterpret_cast(dbb); lock->lck_length = l; lock->lck_dbb = dbb; - lock->lck_ast = reinterpret_cast < int (*) () > (CCH_down_grade_dbb); + lock->lck_ast = reinterpret_cast (CCH_down_grade_dbb); MOVE_FAST(lock_string, lock->lck_key.lck_string, l); /* Try to get an exclusive lock on database. If this fails, insist @@ -1120,6 +1129,27 @@ static FIL setup_file(DBB dbb, return file; } +static bool MaybeCloseFile(SLONG* pFile) +{ +/************************************** + * + * M a y b e C l o s e F i l e + * + ************************************** + * + * Functional description + * If the file is open, close it. + * + **************************************/ + + if (pFile && (HANDLE)*pFile != INVALID_HANDLE_VALUE) + { + CloseHandle((HANDLE)*pFile); + *pFile = (SLONG) INVALID_HANDLE_VALUE; + return true; + } + return false; +} static BOOLEAN nt_error(TEXT* string, FIL file, @@ -1161,6 +1191,3 @@ static BOOLEAN nt_error(TEXT* string, return TRUE; } - - -} // extern "C" diff --git a/src/jrd/y-valve.cpp b/src/jrd/y-valve.cpp new file mode 100644 index 0000000000..17d2982047 --- /dev/null +++ b/src/jrd/y-valve.cpp @@ -0,0 +1,6273 @@ +/* + * PROGRAM: JRD Access Method + * MODULE: why.c + * DESCRIPTION: Universal Y-valve + * + * The contents of this file are subject to the Interbase Public + * License Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy + * of the License at http://www.Inprise.com/IPL.html + * + * Software distributed under the License is distributed on an + * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express + * or implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code was created by Inprise Corporation + * and its predecessors. Portions created by Inprise Corporation are + * Copyright (C) Inprise Corporation. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + */ +/* +$Id: y-valve.cpp,v 1.1 2001-12-24 02:50:52 tamlin Exp $ +*/ + +#include "firebird.h" + +#include +#include +#include +#include "../jrd/common.h" +#include + +#ifdef DEV_BUILD +#include "../jrd/ib_stdio.h" +#include +#endif + +#ifndef assert +#define assert(x) +#endif + +#include "gen/codes.h" +#include "../jrd/msg_encode.h" +#include "gen/msg_facs.h" +#include "../jrd/acl.h" +#include "../jrd/inf.h" +#include "../jrd/thd.h" +#include "../jrd/isc.h" +#include "../jrd/fil.h" + +/* includes specific for DSQL */ + +#include "../dsql/sqlda.h" + +/* end DSQL-specific includes */ + +#include "../jrd/flu_proto.h" +#include "../jrd/gds_proto.h" +#include "../jrd/isc_proto.h" +#include "../jrd/isc_f_proto.h" +#ifndef REQUESTER +#include "../jrd/isc_i_proto.h" +#include "../jrd/isc_s_proto.h" +#include "../jrd/sch_proto.h" +#endif +#include "../jrd/thd_proto.h" +#include "../jrd/utl_proto.h" +#include "../dsql/dsql_proto.h" +#include "../dsql/prepa_proto.h" +#include "../dsql/utld_proto.h" + +#ifdef UNIX +#include +#include +#if !(defined SEEK_END && defined F_OK) +#include +#endif +#endif + +#ifdef WIN_NT +#include +#ifdef TEXT +#undef TEXT +#endif +#define TEXT SCHAR +#endif + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +#ifndef F_OK +#define F_OK 0 +#endif + +#ifndef F_TLOCK +#define F_TLOCK 2 +#endif + +#ifdef SHLIB_DEFS +#define lockf (*_libgds_lockf) +#define _assert (*_libgds__assert) +#define strchr (*_libgds_strchr) +#define access (*_libgds_access) + +extern int lockf(); +extern void _assert(); +extern SCHAR *strchr(); +extern int access(); +#endif + +#define IO_RETRY 20 + +#ifdef DEV_BUILD +#define CHECK_STATUS(v) check_status_vector(v, !SUCCESS) +#define CHECK_STATUS_SUCCESS(v) check_status_vector(v, SUCCESS) +#endif + +#ifndef CHECK_STATUS +#define CHECK_STATUS(v) /* nothing */ +#define CHECK_STATUS_SUCCESS(v) /* nothing */ +#endif + +#define INIT_STATUS(vector) vector [0] = gds_arg_gds;\ + vector [1] = SUCCESS;\ + vector [2] = gds_arg_end + +#define CHECK_HANDLE(blk, blk_type, code) if (!(blk) || (blk)->type != blk_type) \ + return bad_handle (user_status, code) + +#define NULL_CHECK(ptr, code, type) if (*ptr) return bad_handle (user_status, code) +#define GET_STATUS { if (!(status = user_status)) status = local; INIT_STATUS(status); } +#define RETURN_SUCCESS { subsystem_exit(); CHECK_STATUS_SUCCESS (status); return SUCCESS; } + +#ifdef REQUESTER +#define NO_LOCAL_DSQL +#endif + +#ifdef PIPE_CLIENT +#define NO_LOCAL_DSQL +#define THREAD_ENTER +#define THREAD_EXIT +#endif + +#ifdef SUPERCLIENT +#define NO_LOCAL_DSQL +#endif + +#if defined (SERVER_SHUTDOWN) && !defined (SUPERCLIENT) && !defined (REQUESTER) +static BOOLEAN shutdown_flag = FALSE; +#endif /* SERVER_SHUTDOWN && !SUPERCLIENT && !REQUESTER */ + +//typedef STATUS(*PTR) (); +typedef STATUS(*PTR) (...); + +typedef struct hndl +{ + UCHAR type; + UCHAR flags; + USHORT implementation; + int* handle; + struct hndl* parent; + struct hndl* next; + struct hndl* requests; + struct hndl* statements; + struct hndl* blobs; + struct hndl** user_handle; + struct clean* cleanup; + TEXT* db_path; +} *HNDL, *REQ, *DBB, *TRA, *BLB, *ATT, *STMT, *SVC; + +#define HANDLE_invalid 0 +#define HANDLE_database 1 +#define HANDLE_transaction 2 +#define HANDLE_request 3 +#define HANDLE_blob 4 +#define HANDLE_statement 5 +#define HANDLE_service 6 + +#define HANDLE_TRANSACTION_limbo 1 +#define HANDLE_BLOB_filter 2 /* Blob is locally filtered */ +#define HANDLE_STATEMENT_local 4 /* Process DSQL statement locally */ + +/* Database cleanup handlers */ + +typedef struct clean +{ + struct clean* clean_next; + void (*clean_routine)(TRA, SLONG); + SLONG clean_arg; +} *CLEAN; + +/* Transaction element block */ + +typedef struct teb +{ + ATT *teb_database; + int teb_tpb_length; + UCHAR *teb_tpb; +} TEB; + +#include "../jrd/why_proto.h" + +extern "C" { + +static SCHAR *alloc(SLONG); +static HNDL allocate_handle(int, int *, int); +static STATUS bad_handle(STATUS *, STATUS); +#ifdef DEV_BUILD +static void check_status_vector(STATUS *, STATUS); +#endif +static STATUS error(STATUS *, STATUS *); +static STATUS error2(STATUS *, STATUS *); +static void event_ast(UCHAR *, USHORT, UCHAR *); +static void exit_handler(EVENT); +static TRA find_transaction(DBB, TRA); +static void free_block(void*); +static int get_database_info(STATUS *, TRA, UCHAR **); +static PTR get_entrypoint(int, int); +static SCHAR *get_sqlda_buffer(SCHAR *, USHORT, XSQLDA *, USHORT, USHORT *); +static STATUS get_transaction_info(STATUS *, TRA, UCHAR **); +static void init_paths(void); +static void iterative_sql_info(STATUS *, STMT *, SSHORT, SCHAR *, SSHORT, + SCHAR *, USHORT, XSQLDA *); +//static STATUS no_entrypoint(STATUS *); +static STATUS no_entrypoint(...); +static STATUS open_blob(STATUS *, ATT *, TRA *, BLB *, SLONG *, USHORT, + UCHAR *, SSHORT, SSHORT); +static STATUS open_marker_file(STATUS *, TEXT *, TEXT *); +static STATUS prepare(STATUS *, TRA); +static void release_dsql_support(DASUP); +static void release_handle(HNDL); +static void save_error_string(STATUS *); +static void subsystem_enter(void); +static void subsystem_exit(void); + +#ifndef REQUESTER +static EVENT_T why_event[1]; +static SSHORT why_initialized = 0; +#endif +static SLONG why_enabled = 0; + +/* subsystem_usage is used to count how many active ATTACHMENTs are + * running though the why valve. For the first active attachment + * request we reset the InterBase FPE handler. + * This counter is incremented for each ATTACH DATABASE, ATTACH SERVER, + * or CREATE DATABASE. This counter is decremented for each + * DETACH DATABASE, DETACH SERVER, or DROP DATABASE. + * + * A client-only API call, isc_reset_fpe() also controls the re-setting of + * the FPE handler. + * isc_reset_fpe (0); (default) + * Initialize the FPE handler the first time the gds + * library is made active. + * isc_reset_fpe (1); + * Initialize the FPE handler the NEXT time an API call is + * invoked. + * isc_reset_fpe (2); + * Revert to InterBase pre-V4.1.0 behavior, reset the FPE + * handler on every API call. + */ + +#define FPE_RESET_INIT_ONLY 0x0 /* Don't reset FPE after init */ +#define FPE_RESET_NEXT_API_CALL 0x1 /* Reset FPE on next gds call */ +#define FPE_RESET_ALL_API_CALL 0x2 /* Reset FPE on all gds call */ + +#if !(defined REQUESTER || defined PIPE_CLIENT || defined SUPERCLIENT || defined SUPERSERVER) +extern ULONG isc_enter_count; +static ULONG subsystem_usage = 0; +static USHORT subsystem_FPE_reset = FPE_RESET_INIT_ONLY; +#define SUBSYSTEM_USAGE_INCR subsystem_usage++ +#define SUBSYSTEM_USAGE_DECR subsystem_usage-- +#endif + +#ifndef SUBSYSTEM_USAGE_INCR +#define SUBSYSTEM_USAGE_INCR /* nothing */ +#define SUBSYSTEM_USAGE_DECR /* nothing */ +#endif + +#ifdef UNIX +static TEXT marker_failures[1024]; +static TEXT *marker_failures_ptr = marker_failures; +#endif + +/* + * Global array to store string from the status vector in + * save_error_string. + */ + +#define MAXERRORSTRINGLENGTH 250 +static TEXT glbstr1[MAXERRORSTRINGLENGTH]; +static CONST TEXT glbunknown[10] = ""; + +#ifdef VMS +#define CALL(proc, handle) (*get_entrypoint(proc, handle)) +#else +#define CALL(proc, handle) (get_entrypoint(proc, handle)) +#endif + + +#define GDS_ATTACH_DATABASE isc_attach_database +#define GDS_BLOB_INFO isc_blob_info +#define GDS_CANCEL_BLOB isc_cancel_blob +#define GDS_CANCEL_EVENTS isc_cancel_events +#define GDS_CANCEL_OPERATION gds__cancel_operation +#define GDS_CLOSE_BLOB isc_close_blob +#define GDS_COMMIT isc_commit_transaction +#define GDS_COMMIT_RETAINING isc_commit_retaining +#define GDS_COMPILE isc_compile_request +#define GDS_COMPILE2 isc_compile_request2 +#define GDS_CREATE_BLOB isc_create_blob +#define GDS_CREATE_BLOB2 isc_create_blob2 +#define GDS_CREATE_DATABASE isc_create_database +#define GDS_DATABASE_INFO isc_database_info +#define GDS_DDL isc_ddl +#define GDS_DETACH isc_detach_database +#define GDS_DROP_DATABASE isc_drop_database +#define GDS_EVENT_WAIT gds__event_wait +#define GDS_GET_SEGMENT isc_get_segment +#define GDS_GET_SLICE isc_get_slice +#define GDS_OPEN_BLOB isc_open_blob +#define GDS_OPEN_BLOB2 isc_open_blob2 +#define GDS_PREPARE isc_prepare_transaction +#define GDS_PREPARE2 isc_prepare_transaction2 +#define GDS_PUT_SEGMENT isc_put_segment +#define GDS_PUT_SLICE isc_put_slice +#define GDS_QUE_EVENTS isc_que_events +#define GDS_RECONNECT isc_reconnect_transaction +#define GDS_RECEIVE isc_receive + +#ifdef SCROLLABLE_CURSORS +#define GDS_RECEIVE2 isc_receive2 +#endif + +#define GDS_RELEASE_REQUEST isc_release_request +#define GDS_REQUEST_INFO isc_request_info +#define GDS_ROLLBACK isc_rollback_transaction +#define GDS_ROLLBACK_RETAINING isc_rollback_retaining +#define GDS_SEEK_BLOB isc_seek_blob +#define GDS_SEND isc_send +#define GDS_START_AND_SEND isc_start_and_send +#define GDS_START isc_start_request +#define GDS_START_MULTIPLE isc_start_multiple +#define GDS_START_TRANSACTION isc_start_transaction +#define GDS_TRANSACT_REQUEST isc_transact_request +#define GDS_TRANSACTION_INFO isc_transaction_info +#define GDS_UNWIND isc_unwind_request + +#define GDS_DSQL_ALLOCATE isc_dsql_allocate_statement +#define GDS_DSQL_ALLOC isc_dsql_alloc_statement +#define GDS_DSQL_ALLOC2 isc_dsql_alloc_statement2 +#define GDS_DSQL_EXECUTE isc_dsql_execute +#define GDS_DSQL_EXECUTE2 isc_dsql_execute2 +#define GDS_DSQL_EXECUTE_M isc_dsql_execute_m +#define GDS_DSQL_EXECUTE2_M isc_dsql_execute2_m +#define GDS_DSQL_EXECUTE_IMMED isc_dsql_execute_immediate +#define GDS_DSQL_EXECUTE_IMM_M isc_dsql_execute_immediate_m +#define GDS_DSQL_EXEC_IMMED isc_dsql_exec_immediate +#define GDS_DSQL_EXEC_IMMED2 isc_dsql_exec_immed2 +#define GDS_DSQL_EXEC_IMM_M isc_dsql_exec_immediate_m +#define GDS_DSQL_EXEC_IMM2_M isc_dsql_exec_immed2_m +#define GDS_DSQL_EXEC_IMM3_M isc_dsql_exec_immed3_m +#define GDS_DSQL_FETCH isc_dsql_fetch +#define GDS_DSQL_FETCH2 isc_dsql_fetch2 +#define GDS_DSQL_FETCH_M isc_dsql_fetch_m +#define GDS_DSQL_FETCH2_M isc_dsql_fetch2_m +#define GDS_DSQL_FREE isc_dsql_free_statement +#define GDS_DSQL_INSERT isc_dsql_insert +#define GDS_DSQL_INSERT_M isc_dsql_insert_m +#define GDS_DSQL_PREPARE isc_dsql_prepare +#define GDS_DSQL_PREPARE_M isc_dsql_prepare_m +#define GDS_DSQL_SET_CURSOR isc_dsql_set_cursor_name +#define GDS_DSQL_SQL_INFO isc_dsql_sql_info + +#define GDS_SERVICE_ATTACH isc_service_attach +#define GDS_SERVICE_DETACH isc_service_detach +#define GDS_SERVICE_QUERY isc_service_query +#define GDS_SERVICE_START isc_service_start + +/***************************************************** + * IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT + * + * The order in which these defines appear MUST match + * the order in which the entrypoint appears in + * source/jrd/entry.h. Failure to do so will result in + * much frustration + ******************************************************/ + +#define PROC_ATTACH_DATABASE 0 +#define PROC_BLOB_INFO 1 +#define PROC_CANCEL_BLOB 2 +#define PROC_CLOSE_BLOB 3 +#define PROC_COMMIT 4 +#define PROC_COMPILE 5 +#define PROC_CREATE_BLOB 6 +#define PROC_CREATE_DATABASE 7 +#define PROC_DATABASE_INFO 8 +#define PROC_DETACH 9 +#define PROC_GET_SEGMENT 10 +#define PROC_OPEN_BLOB 11 +#define PROC_PREPARE 12 +#define PROC_PUT_SEGMENT 13 +#define PROC_RECONNECT 14 +#define PROC_RECEIVE 15 +#define PROC_RELEASE_REQUEST 16 +#define PROC_REQUEST_INFO 17 +#define PROC_ROLLBACK 18 +#define PROC_SEND 19 +#define PROC_START_AND_SEND 20 +#define PROC_START 21 +#define PROC_START_MULTIPLE 22 +#define PROC_START_TRANSACTION 23 +#define PROC_TRANSACTION_INFO 24 +#define PROC_UNWIND 25 +#define PROC_COMMIT_RETAINING 26 +#define PROC_QUE_EVENTS 27 +#define PROC_CANCEL_EVENTS 28 +#define PROC_DDL 29 +#define PROC_OPEN_BLOB2 30 +#define PROC_CREATE_BLOB2 31 +#define PROC_GET_SLICE 32 +#define PROC_PUT_SLICE 33 +#define PROC_SEEK_BLOB 34 +#define PROC_TRANSACT_REQUEST 35 +#define PROC_DROP_DATABASE 36 + +#define PROC_DSQL_ALLOCATE 37 +#define PROC_DSQL_EXECUTE 38 +#define PROC_DSQL_EXECUTE2 39 +#define PROC_DSQL_EXEC_IMMED 40 +#define PROC_DSQL_EXEC_IMMED2 41 +#define PROC_DSQL_FETCH 42 +#define PROC_DSQL_FREE 43 +#define PROC_DSQL_INSERT 44 +#define PROC_DSQL_PREPARE 45 +#define PROC_DSQL_SET_CURSOR 46 +#define PROC_DSQL_SQL_INFO 47 + +#define PROC_SERVICE_ATTACH 48 +#define PROC_SERVICE_DETACH 49 +#define PROC_SERVICE_QUERY 50 +#define PROC_SERVICE_START 51 + +#define PROC_ROLLBACK_RETAINING 52 +#define PROC_CANCEL_OPERATION 53 + +#define PROC_count 54 + +typedef struct +{ + TEXT *name; + PTR address; +} ENTRY; + +typedef struct +{ + TEXT *name; + TEXT *path; +} IMAGE; + +#ifdef INITIALIZE_PATHS +#define CONST_IMAGE /* nothing */ +#else +#define CONST_IMAGE CONST +#endif + + + +#ifdef PIPE_CLIENT + +/* Define simple table for pipe server client-side */ + +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe, win,winipi) extern STATUS pipe(), bridge_pipe(); +#include "../jrd/entry.h" + +static CONST_IMAGE IMAGE images[] = +{ + "PIPE", "PIPE", /* Pipe interface */ + "PIPE5", "PIPE5" /* Pipe interface bridge to V3 */ +}; + +#else + +/* Define complicated table for multi-subsystem world */ + +#ifdef VMS +#define V3 +#define RDB +#endif + +#if (defined UNIX) && \ + !(defined SUPERCLIENT || defined SUPERSERVER || defined DECOSF || defined NCR3000 || defined DG_X86 || defined linux || defined FREEBSD || defined NETBSD || defined AIX_PPC || defined DARWIN /* platforms without a V3 bridge */) +#ifndef PIPE_SERVER_YVALUE +#define PIPE_BRIDGE_TO_V3 +#endif +#endif + +#ifdef PIPE_BRIDGE_TO_V3 +#if !(defined HM300 || defined BACKEND) && \ + (defined hpux || defined sgi /* platforms with a shared V3 bridge */) +#undef PIPE_BRIDGE_TO_V3 +#define V3 +#define V3_PATH "lib/bridge5" +#define GDS_A_PATH "lib/gds_1" +#define GDS_B_PATH "lib/gds_2" +#define GDS_C_PATH "lib/gds_3" +#define GDS_D_PATH "lib/gds_4" +#define INITIALIZE_PATHS +#endif +#endif + +#ifndef V3_PATH +#define V3_PATH "GDSSHR5" +#endif + +#ifndef GDS_A_PATH +#define GDS_A_PATH "GDS_A" +#define GDS_B_PATH "GDS_B" +#define GDS_C_PATH "GDS_C" +#define GDS_D_PATH "GDS_D" +#endif + +#ifdef INITIALIZE_PATHS +static SSHORT paths_initialized = 0; +#endif + + + +#ifdef CSI +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) extern STATUS rem(), cur(), csi(); +#else +#ifdef SUPERCLIENT +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) extern STATUS rem(); +#else +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) extern STATUS rem(), cur(); +#endif +#endif +#include "../jrd/entry.h" + +#ifdef RDB +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) extern STATUS rdb(); +#include "../jrd/entry.h" +#endif + +#ifdef PIPE_BRIDGE_TO_V3 +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) extern STATUS bridge_pipe(); +#include "../jrd/entry.h" +#endif + +#ifdef ALTPIPE +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) extern STATUS pipe(); +#include "../jrd/entry.h" +#endif + +#ifdef IPSERV +#ifndef XNET +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) extern STATUS winipi(); +#include "../jrd/entry.h" +#endif +#endif + +static CONST_IMAGE IMAGE images[] = +{ +#ifdef WINDOWS_ONLY + {"REMOTE", "REMOTE.DLL"}, + {"STACK", "STACK.DLL"} +#else + + {"REMINT", "REMINT"}, /* Remote */ + +#ifdef CSI + {"CSI", "CSI"}, /* Central server interface */ +#endif + +#ifdef ALTPIPE + {"GDSPIPE", "ALTPIPE"}, /* Alternate pipe interface */ +#endif + +#ifndef REQUESTER +#ifndef SUPERCLIENT + {"GDSSHR", "GDSSHR"}, /* Primary access method */ +#endif +#endif + +#ifdef V3 + {"GDSSHR5", V3_PATH}, /* Previous access method */ +#endif + +#ifdef PIPE_BRIDGE_TO_V3 + {"PIPE5", "PIPE5"}, /* Pipe interface bridge to V3 */ +#endif + +#ifdef RDB + {"GDSRDB", "GDSRDB"}, /* Rdb Interface */ +#endif + +#ifndef PC_PLATFORM + {"GDS_A", GDS_A_PATH}, + {"GDS_B", GDS_B_PATH}, + {"GDS_C", GDS_C_PATH}, + {"GDS_D", GDS_D_PATH}, +#endif +#ifdef IPSERV +#ifndef XNET + {"WINIPI", "WINIPI"}, +#endif +#endif + +#endif /* WINDOWS_ONLY */ +}; +#endif + + +#define SUBSYSTEMS sizeof (images) / (sizeof (IMAGE)) + +static CONST ENTRY entrypoints[PROC_count * SUBSYSTEMS] = +{ +#ifdef PIPE_CLIENT + +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, pipe}, +#include "../jrd/entry.h" + +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, bridge_pipe}, +#include "../jrd/entry.h" + +#else + +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, rem}, +#include "../jrd/entry.h" + +#ifdef CSI +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, csi}, +#include "../jrd/entry.h" +#endif + +#ifdef ALTPIPE +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, pipe}, +#include "../jrd/entry.h" +#endif + +#ifdef WINDOWS_ONLY +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {win, NULL}, +#include "../jrd/entry.h" +#else +#ifndef REQUESTER +#ifndef SUPERCLIENT +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, cur}, +#include "../jrd/entry.h" +#endif +#endif +#endif /* WINDOWS_ONLY */ + +#ifdef V3 +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {bridge, NULL}, +#include "../jrd/entry.h" +#endif + +#ifdef PIPE_BRIDGE_TO_V3 +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, bridge_pipe}, +#include "../jrd/entry.h" +#endif + +#ifdef RDB +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, rdb}, +#include "../jrd/entry.h" +#endif + +#ifdef IPSERV +#ifndef XNET +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) {NULL, winipi}, +#include "../jrd/entry.h" +#endif +#endif + +#endif +}; + +static CONST TEXT *generic[] = { +#define ENTRYPOINT(gen,cur,bridge,rem,os2_rem,csi,rdb,pipe,bridge_pipe,win,winipi) gen, +#include "../jrd/entry.h" +}; + + +/* Information items for two phase commit */ + +static CONST UCHAR prepare_tr_info[] = +{ + gds__info_tra_id, + gds__info_end +}; + +/* Information items for DSQL prepare */ + +static CONST SCHAR sql_prepare_info[] = +{ + gds__info_sql_select, + gds__info_sql_describe_vars, + gds__info_sql_sqlda_seq, + gds__info_sql_type, + gds__info_sql_sub_type, + gds__info_sql_scale, + gds__info_sql_length, + gds__info_sql_field, + gds__info_sql_relation, + gds__info_sql_owner, + gds__info_sql_alias, + gds__info_sql_describe_end +}; + +/* Information items for SQL info */ + +static CONST SCHAR describe_select_info[] = +{ + gds__info_sql_select, + gds__info_sql_describe_vars, + gds__info_sql_sqlda_seq, + gds__info_sql_type, + gds__info_sql_sub_type, + gds__info_sql_scale, + gds__info_sql_length, + gds__info_sql_field, + gds__info_sql_relation, + gds__info_sql_owner, + gds__info_sql_alias, + gds__info_sql_describe_end +}; + +static CONST SCHAR describe_bind_info[] = +{ + gds__info_sql_bind, + gds__info_sql_describe_vars, + gds__info_sql_sqlda_seq, + gds__info_sql_type, + gds__info_sql_sub_type, + gds__info_sql_scale, + gds__info_sql_length, + gds__info_sql_field, + gds__info_sql_relation, + gds__info_sql_owner, + gds__info_sql_alias, + gds__info_sql_describe_end +}; + + +STATUS API_ROUTINE GDS_ATTACH_DATABASE(STATUS* user_status, + SSHORT GDS_VAL(file_length), + TEXT* file_name, + ATT* handle, + SSHORT GDS_VAL(dpb_length), + SCHAR* dpb) +{ +/************************************** + * + * g d s _ $ a t t a c h _ d a t a b a s e + * + ************************************** + * + * Functional description + * Attach a database through the first subsystem + * that recognizes it. + * + **************************************/ + STATUS local[20], *status, *ptr, temp[20]; + USHORT n, length, org_length, temp_length; + DBB database; + SCHAR *current_dpb_ptr, *last_dpb_ptr; +#ifdef STACK_EFFICIENT + TEXT *expanded_filename, *temp_filebuf; +#else + TEXT expanded_filename[MAXPATHLEN], temp_filebuf[MAXPATHLEN]; +#endif + TEXT *p, *q, *temp_filename; +#if defined(UNIX) && !defined(PIPE_CLIENT) + TEXT single_user[5]; +#endif + + GET_STATUS; + +#if defined(DEBUG_GDS_ALLOC) && defined(WINDOWS_ONLY) + gds_alloc_report(ALLOC_mark_current | ALLOC_silent, __FILE__, __LINE__); +#endif + + NULL_CHECK(handle, isc_bad_db_handle, HANDLE_database); + if (!file_name) + { + status[0] = isc_arg_gds; + status[1] = isc_bad_db_format; + status[2] = isc_arg_string; + status[3] = (STATUS) ""; + status[4] = isc_arg_end; + return error2(status, local); + } + + if (GDS_VAL(dpb_length) > 0 && !dpb) + { + status[0] = isc_arg_gds; + status[1] = isc_bad_dpb_form; + status[2] = isc_arg_end; + return error2(status, local); + } + +#if defined (SERVER_SHUTDOWN) && !defined (SUPERCLIENT) && !defined (REQUESTER) + if (shutdown_flag) + { + status[0] = isc_arg_gds; + status[1] = isc_shutwarn; + status[2] = isc_arg_end; + return error2(status, local); + } +#endif /* SERVER_SHUTDOWN && !SUPERCLIENT && !REQUESTER */ + + subsystem_enter(); + SUBSYSTEM_USAGE_INCR; + +#ifdef STACK_EFFICIENT + expanded_filename = + (TEXT *) gds__alloc((SLONG) (sizeof(TEXT) * MAXPATHLEN)); + if (!expanded_filename) + { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + SUBSYSTEM_USAGE_DECR; + return error(status, local); + } + temp_filebuf = (TEXT *) gds__alloc((SLONG) (sizeof(TEXT) * MAXPATHLEN)); + if (!temp_filebuf) + { + gds__free((SLONG *) expanded_filename); + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + SUBSYSTEM_USAGE_DECR; + return error(status, local); + } +#endif + temp_filename = temp_filebuf; + + ptr = status; + + org_length = GDS_VAL(file_length); + + if (org_length) + { + p = file_name + org_length - 1; + while (*p == ' ') + { + p--; + } + org_length = p - file_name + 1; + } + +/* copy the file name to a temp buffer, since some of the following + utilities can modify it */ + + temp_length = org_length ? org_length : strlen(file_name); + memcpy(temp_filename, file_name, temp_length); + temp_filename[temp_length] = '\0'; + + if (isc_set_path(temp_filename, org_length, expanded_filename)) + { + temp_filename = expanded_filename; + org_length = strlen(temp_filename); + } + else + { + ISC_expand_filename(temp_filename, org_length, expanded_filename); + } + + current_dpb_ptr = dpb; + +#ifdef UNIX +/* added so that only the pipe_server goes in here */ +#ifndef PIPE_CLIENT + single_user[0] = 0; + if (open_marker_file(status, expanded_filename, single_user)) + { + SUBSYSTEM_USAGE_DECR; + return error(status, local); + } + + if (single_user[0]) { + isc_set_single_user((UCHAR**)¤t_dpb_ptr, &dpb_length, single_user); + } +#endif +#endif + +/* Special handling of dpb pointers to handle multiple extends of the dpb */ + last_dpb_ptr = current_dpb_ptr; + isc_set_login((UCHAR**)¤t_dpb_ptr, &dpb_length); + if ((current_dpb_ptr != last_dpb_ptr) && (last_dpb_ptr != dpb)) + gds__free((SLONG *) last_dpb_ptr); + + for (n = 0; n < SUBSYSTEMS; n++) + { + if (why_enabled && !(why_enabled & (1 << n))) + { + continue; + } + if (!CALL(PROC_ATTACH_DATABASE, n) (ptr, + org_length, + temp_filename, + handle, + GDS_VAL(dpb_length), + current_dpb_ptr, + expanded_filename)) + { + length = strlen(expanded_filename); + database = (DBB) allocate_handle(n, (int*)*handle, HANDLE_database); + if (database) + { + database->db_path = (TEXT*) alloc((SLONG) (length + 1)); + } + if (!database || !database->db_path) + { + /* No memory. Make a half-hearted to detach and get out. */ + + if (database) + release_handle(database); + CALL(PROC_DETACH, n) (ptr, handle); + *handle = (ATT)NULL_PTR; + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + break; + } + + *handle = database; + p = database->db_path; + for (q = expanded_filename; length; length--) + { + *p++ = *q++; + } + *p = 0; + + if (current_dpb_ptr != dpb) { + gds__free((SLONG *) current_dpb_ptr); + } + +#ifdef STACK_EFFICIENT + gds__free((SLONG *) expanded_filename); + gds__free((SLONG *) temp_filebuf); +#endif + database->cleanup = NULL; + status[0] = isc_arg_gds; + status[1] = 0; + + /* Check to make sure that status[2] is not a warning. If it is, then + * the rest of the vector should be untouched. If it is not, then make + * this element isc_arg_end + * + * This cleanup is done to remove any erroneous errors from trying multiple + * protocols for a database attach + */ + if (status[2] != isc_arg_warning) { + status[2] = isc_arg_end; + } + + subsystem_exit(); + CHECK_STATUS_SUCCESS(status); + return status[1]; + } + if (ptr[1] != isc_unavailable) { + ptr = temp; + } + } + + if (current_dpb_ptr != dpb) { + gds__free((SLONG *) current_dpb_ptr); + } + +#ifdef STACK_EFFICIENT + gds__free((SLONG *) expanded_filename); + gds__free((SLONG *) temp_filebuf); +#endif + + SUBSYSTEM_USAGE_DECR; + return error(status, local); +} + + +STATUS API_ROUTINE GDS_BLOB_INFO(STATUS* user_status, + BLB* blob_handle, + SSHORT GDS_VAL(item_length), + SCHAR* items, + SSHORT GDS_VAL(buffer_length), + SCHAR* buffer) +{ +/************************************** + * + * g d s _ $ b l o b _ i n f o + * + ************************************** + * + * Functional description + * Provide information on blob object. + * + **************************************/ + STATUS local[20], *status; + BLB blob; + + GET_STATUS; + blob = *blob_handle; + CHECK_HANDLE(blob, HANDLE_blob, isc_bad_segstr_handle); + subsystem_enter(); + + CALL(PROC_BLOB_INFO, blob->implementation) (status, + &blob->handle, + GDS_VAL(item_length), + items, + GDS_VAL(buffer_length), + buffer); + + if (status[1]) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_CANCEL_BLOB(STATUS * user_status, BLB * blob_handle) +{ +/************************************** + * + * g d s _ $ c a n c e l _ b l o b + * + ************************************** + * + * Functional description + * Abort a partially completed blob. + * + **************************************/ + STATUS local[20], *status; + BLB blob, *ptr; + ATT dbb; + + if (!*blob_handle) { + if (user_status) { + user_status[0] = gds_arg_gds; + user_status[1] = 0; + user_status[2] = gds_arg_end; + CHECK_STATUS_SUCCESS(user_status); + } + return SUCCESS; + } + + GET_STATUS; + blob = *blob_handle; + CHECK_HANDLE(blob, HANDLE_blob, isc_bad_segstr_handle); + subsystem_enter(); + + if (CALL(PROC_CANCEL_BLOB, blob->implementation) (status, &blob->handle)) + return error(status, local); + +/* Get rid of connections to database */ + + dbb = blob->parent; + + for (ptr = &dbb->blobs; *ptr; ptr = &(*ptr)->next) + if (*ptr == blob) { + *ptr = blob->next; + break; + } + + release_handle(blob); + *blob_handle = NULL; + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_CANCEL_EVENTS(STATUS * user_status, + ATT * handle, SLONG * id) +{ +/************************************** + * + * g d s _ $ c a n c e l _ e v e n t s + * + ************************************** + * + * Functional description + * Try to cancel an event. + * + **************************************/ + STATUS local[20], *status; + ATT database; + + GET_STATUS; + database = *handle; + CHECK_HANDLE(database, HANDLE_database, isc_bad_db_handle); + subsystem_enter(); + + if (CALL(PROC_CANCEL_EVENTS, database->implementation) (status, + &database->handle, + id)) + return error(status, local); + + RETURN_SUCCESS; +} + + +#ifdef CANCEL_OPERATION +STATUS API_ROUTINE GDS_CANCEL_OPERATION(STATUS * user_status, + ATT * handle, USHORT option) +{ +/************************************** + * + * g d s _ $ c a n c e l _ o p e r a t i o n + * + ************************************** + * + * Functional description + * Try to cancel an operation. + * + **************************************/ + STATUS local[20], *status; + ATT database; + + GET_STATUS; + database = *handle; + CHECK_HANDLE(database, HANDLE_database, isc_bad_db_handle); + subsystem_enter(); + + if (CALL(PROC_CANCEL_OPERATION, database->implementation) (status, + &database-> + handle, + option)) return + error(status, local); + + RETURN_SUCCESS; +} +#endif + + +STATUS API_ROUTINE GDS_CLOSE_BLOB(STATUS * user_status, BLB * blob_handle) +{ +/************************************** + * + * g d s _ $ c l o s e _ b l o b + * + ************************************** + * + * Functional description + * Abort a partially completed blob. + * + **************************************/ + STATUS local[20], *status; + BLB blob, *ptr; + ATT dbb; + + GET_STATUS; + blob = *blob_handle; + CHECK_HANDLE(blob, HANDLE_blob, isc_bad_segstr_handle); + subsystem_enter(); + + CALL(PROC_CLOSE_BLOB, blob->implementation) (status, &blob->handle); + + if (status[1]) + return error(status, local); + +/* Get rid of connections to database */ + + dbb = blob->parent; + + for (ptr = &dbb->blobs; *ptr; ptr = &(*ptr)->next) + if (*ptr == blob) { + *ptr = blob->next; + break; + } + + release_handle(blob); + *blob_handle = NULL; + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_COMMIT(STATUS * user_status, TRA * tra_handle) +{ +/************************************** + * + * g d s _ $ c o m m i t + * + ************************************** + * + * Functional description + * Commit a transaction. + * + **************************************/ + STATUS local[20], *status; + TRA transaction, sub; + CLEAN clean; + + GET_STATUS; + transaction = *tra_handle; + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + +/* Handle single transaction case */ + + if (transaction->implementation != SUBSYSTEMS) { + if (CALL(PROC_COMMIT, transaction->implementation) (status, + &transaction-> + handle)) return + error(status, local); + } + else { + /* Handle two phase commit. Start by putting everybody into + limbo. If anybody fails, punt */ + + if (!(transaction->flags & HANDLE_TRANSACTION_limbo)) + if (prepare(status, transaction)) + return error(status, local); + + /* Everybody is in limbo, now commit everybody. + In theory, this can't fail */ + + for (sub = transaction->next; sub; sub = sub->next) + if (CALL(PROC_COMMIT, sub->implementation) (status, &sub->handle)) + return error(status, local); + } + + subsystem_exit(); + +/* Call the associated cleanup handlers */ + + while (clean = transaction->cleanup) { + transaction->cleanup = clean->clean_next; + (*clean->clean_routine) (transaction, clean->clean_arg); + free_block(clean); + } + + while (sub = transaction) { + transaction = sub->next; + release_handle(sub); + } + *tra_handle = NULL; + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_COMMIT_RETAINING(STATUS * user_status, + TRA * tra_handle) +{ +/************************************** + * + * g d s _ $ c o m m i t _ r e t a i n i n g + * + ************************************** + * + * Functional description + * Do a commit retaining. + * + * N.B., the transaction cleanup handlers are NOT + * called here since, conceptually, the transaction + * is still running. + * + **************************************/ + STATUS local[20], *status; + TRA transaction, sub; + + GET_STATUS; + transaction = *tra_handle; + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + for (sub = transaction; sub; sub = sub->next) + if (sub->implementation != SUBSYSTEMS && + CALL(PROC_COMMIT_RETAINING, sub->implementation) (status, + &sub->handle)) + return error(status, local); + + transaction->flags |= HANDLE_TRANSACTION_limbo; + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_COMPILE(STATUS * user_status, + ATT * db_handle, + REQ * req_handle, + USHORT GDS_VAL(blr_length), SCHAR * blr) +{ +/************************************** + * + * g d s _ $ c o m p i l e + * + ************************************** + * + * Functional description + * + **************************************/ + STATUS local[20], *status; + ATT dbb; + REQ request; + + GET_STATUS; + NULL_CHECK(req_handle, isc_bad_req_handle, HANDLE_request); + dbb = *db_handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + subsystem_enter(); + + if (CALL(PROC_COMPILE, dbb->implementation) (status, + &dbb->handle, + req_handle, + GDS_VAL(blr_length), + blr)) + return error(status, local); + + request = allocate_handle(dbb->implementation, (int*)*req_handle, HANDLE_request); + if (!request) { + /* No memory. Make a half-hearted attempt to release request. */ + + CALL(PROC_RELEASE_REQUEST, dbb->implementation) (status, req_handle); + *req_handle = (REQ)NULL_PTR; + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error(status, local); + } + + *req_handle = request; + request->parent = dbb; + request->next = dbb->requests; + dbb->requests = request; + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_COMPILE2(STATUS * user_status, + ATT * db_handle, + REQ * req_handle, + USHORT GDS_VAL(blr_length), SCHAR * blr) +{ +/************************************** + * + * g d s _ $ c o m p i l e 2 + * + ************************************** + * + * Functional description + * + **************************************/ + + if (GDS_COMPILE(user_status, db_handle, req_handle, blr_length, blr)) + /* Note: if user_status == NULL then GDS_COMPILE handled it */ + return user_status[1]; + + (*req_handle)->user_handle = req_handle; + + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_CREATE_BLOB(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + BLB * blob_handle, SLONG * blob_id) +{ +/************************************** + * + * g d s _ $ c r e a t e _ b l o b + * + ************************************** + * + * Functional description + * Open an existing blob. + * + **************************************/ + + return open_blob(user_status, db_handle, tra_handle, blob_handle, blob_id, + 0, (UCHAR*) NULL_PTR, PROC_CREATE_BLOB, PROC_CREATE_BLOB2); +} + + +STATUS API_ROUTINE GDS_CREATE_BLOB2(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + BLB * blob_handle, + SLONG * blob_id, + SSHORT GDS_VAL(bpb_length), UCHAR * bpb) +{ +/************************************** + * + * g d s _ $ c r e a t e _ b l o b 2 + * + ************************************** + * + * Functional description + * Open an existing blob. + * + **************************************/ + + return open_blob(user_status, db_handle, tra_handle, blob_handle, blob_id, + GDS_VAL(bpb_length), bpb, PROC_CREATE_BLOB, + PROC_CREATE_BLOB2); +} + + + +STATUS API_ROUTINE GDS_CREATE_DATABASE(STATUS * user_status, + USHORT GDS_VAL(file_length), + TEXT * file_name, + ATT * handle, + USHORT GDS_VAL(dpb_length), + UCHAR * dpb, USHORT GDS_VAL(db_type)) +{ +/************************************** + * + * g d s _ $ c r e a t e _ d a t a b a s e + * + ************************************** + * + * Functional description + * Create a nice, squeaky clean database, uncorrupted by user data. + * + **************************************/ + STATUS local[20], *status, temp[20], *ptr; + USHORT n, length, org_length, temp_length; + DBB database; +#ifdef STACK_EFFICIENT + TEXT *expanded_filename, *temp_filebuf; +#else + TEXT expanded_filename[MAXPATHLEN], temp_filebuf[MAXPATHLEN]; +#endif + TEXT *p, *q, *temp_filename; + UCHAR *current_dpb_ptr, *last_dpb_ptr; +#ifdef UNIX + TEXT single_user[5]; +#endif + + GET_STATUS; + NULL_CHECK(handle, isc_bad_db_handle, HANDLE_database); + if (!file_name) + { + status[0] = isc_arg_gds; + status[1] = isc_bad_db_format; + status[2] = isc_arg_string; + status[3] = (STATUS) ""; + status[4] = isc_arg_end; + return error2(status, local); + } + + if (dpb_length > 0 && !dpb) + { + status[0] = isc_arg_gds; + status[1] = isc_bad_dpb_form; + status[2] = isc_arg_end; + return error2(status, local); + } + +#if defined (SERVER_SHUTDOWN) && !defined (SUPERCLIENT) && !defined (REQUESTER) + if (shutdown_flag) + { + status[0] = isc_arg_gds; + status[1] = isc_shutwarn; + status[2] = isc_arg_end; + return error2(status, local); + } +#endif /* SERVER_SHUTDOWN && !SUPERCLIENT && !REQUESTER */ + + subsystem_enter(); + SUBSYSTEM_USAGE_INCR; + +#ifdef STACK_EFFICIENT + expanded_filename = (TEXT*)gds__alloc((SLONG) (sizeof(TEXT) * MAXPATHLEN)); + if (!expanded_filename) + { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + SUBSYSTEM_USAGE_DECR; + return error(status, local); + } + temp_filebuf = (TEXT *) gds__alloc((SLONG) (sizeof(TEXT) * MAXPATHLEN)); + if (!temp_filebuf) + { + gds__free((SLONG *) expanded_filename); + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + SUBSYSTEM_USAGE_DECR; + return error(status, local); + } +#endif + temp_filename = temp_filebuf; + + ptr = status; + + org_length = file_length; + + if (org_length) + { + p = file_name + org_length - 1; + while (*p == ' ') + p--; + org_length = p - file_name + 1; + } + +/* copy the file name to a temp buffer, since some of the following + utilities can modify it */ + + if (org_length) + temp_length = org_length; + else + temp_length = strlen(file_name); + memcpy(temp_filename, file_name, temp_length); + temp_filename[temp_length] = '\0'; + + if (isc_set_path(temp_filename, org_length, expanded_filename)) + { + temp_filename = expanded_filename; + org_length = strlen(temp_filename); + } + else + ISC_expand_filename(temp_filename, org_length, expanded_filename); + + current_dpb_ptr = dpb; + +#ifdef UNIX + single_user[0] = 0; + if (open_marker_file(status, expanded_filename, single_user)) + { + SUBSYSTEM_USAGE_DECR; + return error(status, local); + } + + if (single_user[0]) + isc_set_single_user(¤t_dpb_ptr, (SSHORT*)&dpb_length, single_user); +#endif + +/* Special handling of dpb pointers to handle multiple extends of the dpb */ + last_dpb_ptr = current_dpb_ptr; + isc_set_login(¤t_dpb_ptr, (SSHORT*)&dpb_length); + if ((current_dpb_ptr != last_dpb_ptr) && (last_dpb_ptr != dpb)) + gds__free(last_dpb_ptr); + + for (n = 0; n < SUBSYSTEMS; n++) + { + if (why_enabled && !(why_enabled & (1 << n))) + continue; + if (!CALL(PROC_CREATE_DATABASE, n) ( + ptr, + org_length, + temp_filename, + handle, + GDS_VAL(dpb_length), + current_dpb_ptr, + 0, + expanded_filename)) + { + length = org_length; + if (!length) { + length = strlen(temp_filename); + } + database = allocate_handle(n, (int*) *handle, HANDLE_database); + if (database) + { + database->db_path = (TEXT *) alloc((SLONG) (length + 1)); + } + if (!database || !database->db_path) + { + /* No memory. Make a half-hearted to drop database. The + database was successfully created but the user wouldn't + be able to tell. */ + + if (database) + release_handle(database); + CALL(PROC_DROP_DATABASE, n) (ptr, handle); + *handle = (ATT)NULL_PTR; + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + break; + } + + assert(database); + assert(database->db_path); + + *handle = database; + p = database->db_path; + for (q = temp_filename; length; length--) + *p++ = *q++; + *p = 0; + + if (current_dpb_ptr != dpb) + gds__free((SLONG *) current_dpb_ptr); +#ifdef STACK_EFFICIENT + gds__free((SLONG *) expanded_filename); + gds__free((SLONG *) temp_filebuf); +#endif + database->cleanup = NULL; + status[0] = isc_arg_gds; + status[1] = 0; + if (status[2] != isc_arg_warning) + status[2] = isc_arg_end; + subsystem_exit(); + CHECK_STATUS_SUCCESS(status); + return status[1]; + } + if (ptr[1] != isc_unavailable) + ptr = temp; + } + + if (current_dpb_ptr != dpb) + gds__free((SLONG *) current_dpb_ptr); +#ifdef STACK_EFFICIENT + gds__free((SLONG *) expanded_filename); + gds__free((SLONG *) temp_filebuf); +#endif + + SUBSYSTEM_USAGE_DECR; + return error(status, local); +} + + +STATUS API_ROUTINE gds__database_cleanup(STATUS * user_status, + ATT * handle, + void (*routine) (), SLONG arg) +{ +/************************************** + * + * g d s _ $ d a t a b a s e _ c l e a n u p + * + ************************************** + * + * Functional description + * Register a database specific cleanup handler. + * + **************************************/ + STATUS local[20], *status; + ATT database; + CLEAN clean; + + GET_STATUS; + database = *handle; + CHECK_HANDLE(database, HANDLE_database, isc_bad_db_handle); + + if (!(clean = (CLEAN) alloc((SLONG) sizeof(struct clean)))) { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error2(status, local); + } + + clean->clean_next = database->cleanup; + database->cleanup = clean; + clean->clean_routine = (void(*)(HNDL, long))(routine); + clean->clean_arg = arg; + + status[0] = gds_arg_gds; + status[1] = 0; + status[2] = gds_arg_end; + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DATABASE_INFO(STATUS * user_status, + ATT * handle, + SSHORT GDS_VAL(item_length), + SCHAR * items, + SSHORT GDS_VAL(buffer_length), + SCHAR * buffer) +{ +/************************************** + * + * g d s _ $ d a t a b a s e _ i n f o + * + ************************************** + * + * Functional description + * Provide information on database object. + * + **************************************/ + STATUS local[20], *status; + ATT database; + + GET_STATUS; + database = *handle; + CHECK_HANDLE(database, HANDLE_database, isc_bad_db_handle); + subsystem_enter(); + + if (CALL(PROC_DATABASE_INFO, database->implementation) (status, + &database->handle, + GDS_VAL + (item_length), + items, + GDS_VAL + (buffer_length), + buffer)) return + error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_DDL(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT GDS_VAL(length), UCHAR * ddl) +{ +/************************************** + * + * g d s _ $ d d l + * + ************************************** + * + * Functional description + * Do meta-data update. + * + **************************************/ + STATUS local[20], *status; + ATT database; + TRA transaction; + +#if !defined(PIPE_CLIENT) && !defined(SUPERCLIENT) + TEXT *image; + PTR entrypoint; +#endif + + GET_STATUS; + database = *db_handle; + CHECK_HANDLE(database, HANDLE_database, isc_bad_db_handle); + transaction = find_transaction(database, *tra_handle); + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + if (get_entrypoint(PROC_DDL, database->implementation) != no_entrypoint) + { + if (!CALL(PROC_DDL, database->implementation) (status, + &database->handle, + &transaction->handle, + GDS_VAL(length), + ddl)) + { + RETURN_SUCCESS; + } + if (status[1] != isc_unavailable) + { + return error(status, local); + } + } + + subsystem_exit(); + +/* Assume that we won't find an entrypoint to call. */ + + no_entrypoint(status); + +#ifndef PIPE_CLIENT +#ifndef SUPERCLIENT + if ((image = images[database->implementation].path) != NULL && + ((entrypoint = (PTR) ISC_lookup_entrypoint(image, "DYN_ddl", NULL)) != + NULL || + FALSE) && + !((*entrypoint) (status, db_handle, tra_handle, length, ddl))) { + CHECK_STATUS_SUCCESS(status); + return SUCCESS; + } +#endif +#endif + + return error2(status, local); +} + + +STATUS API_ROUTINE GDS_DETACH(STATUS * user_status, ATT * handle) +{ +/************************************** + * + * g d s _ $ d e t a c h + * + ************************************** + * + * Functional description + * Close down a database. + * + **************************************/ + STATUS local[20], *status; + ATT dbb; + REQ request; + STMT statement; + BLB blob; + CLEAN clean; + + GET_STATUS; + + dbb = *handle; + +#ifdef WIN_NT +/* This code was added to fix an IDAPI problem where our DLL exit handler + * was getting called before theirs. Our exit handler frees the attachment + * but does not NULL the handle. Their exit handler trys to detach, causing + * a GPF. + * We should check with IDAPI periodically to see if we still need this. + */ + if (IsBadReadPtr(dbb, sizeof(ATT))) + return bad_handle(user_status, isc_bad_db_handle); +#endif /* WIN_NT */ + + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + +#ifdef SUPERSERVER + +/* Drop all DSQL statements to reclaim DSQL memory pools. */ + + while (statement = dbb->statements) { + if (!statement->user_handle) + statement->user_handle = &statement; + + if (GDS_DSQL_FREE(status, statement->user_handle, DSQL_drop)) + return error2(status, local); + } +#endif + + subsystem_enter(); + + if (CALL(PROC_DETACH, dbb->implementation) (status, &dbb->handle)) + return error(status, local); + +/* Release associated request handles */ + + if (dbb->db_path) + free_block(dbb->db_path); + + while (request = dbb->requests) { + dbb->requests = request->next; + if (request->user_handle) + *request->user_handle = NULL; + release_handle(request); + } + +#ifndef SUPERSERVER + while (statement = dbb->statements) { + dbb->statements = statement->next; + if (statement->user_handle) { + *statement->user_handle = NULL; + } + release_dsql_support((DASUP)statement->requests); + release_handle(statement); + } +#endif + + while (blob = dbb->blobs) { + dbb->blobs = blob->next; + if (blob->user_handle) + *blob->user_handle = NULL; + release_handle(blob); + } + + SUBSYSTEM_USAGE_DECR; + subsystem_exit(); + +/* Call the associated cleanup handlers */ + + while (clean = dbb->cleanup) { + dbb->cleanup = clean->clean_next; + (*clean->clean_routine) ((HNDL)handle, clean->clean_arg); + free_block(clean); + } + + release_handle(dbb); + *handle = NULL; + +#if defined(DEBUG_GDS_ALLOC) && defined(WINDOWS_ONLY) + gds_alloc_report(0L, __FILE__, __LINE__); +#endif + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +int API_ROUTINE gds__disable_subsystem(TEXT * subsystem) +{ +/************************************** + * + * g d s _ $ d i s a b l e _ s u b s y s t e m + * + ************************************** + * + * Functional description + * Disable access to a specific subsystem. If no subsystem + * has been explicitly disabled, all are available. + * + **************************************/ + CONST_IMAGE IMAGE* sys; + CONST_IMAGE IMAGE* end; + + for (sys = images, end = sys + SUBSYSTEMS; sys < end; sys++) + { + if (!strcmp(sys->name, subsystem)) { + if (!why_enabled) + why_enabled = ~why_enabled; + why_enabled &= ~(1 << (sys - images)); + return TRUE; + } + } + + return FALSE; +} + + +STATUS API_ROUTINE GDS_DROP_DATABASE(STATUS * user_status, ATT * handle) +{ +/************************************** + * + * i s c _ d r o p _ d a t a b a s e + * + ************************************** + * + * Functional description + * Close down a database and then purge it. + * + **************************************/ + STATUS local[20], *status; + ATT dbb; + REQ request; + STMT statement; + BLB blob; + CLEAN clean; + + GET_STATUS; + dbb = *handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + +#ifdef SUPERSERVER + +/* Drop all DSQL statements to reclaim DSQL memory pools. */ + + while (statement = dbb->statements) { + if (!statement->user_handle) + statement->user_handle = &statement; + + if (GDS_DSQL_FREE(status, statement->user_handle, DSQL_drop)) + return error2(status, local); + } +#endif + + subsystem_enter(); + + (CALL(PROC_DROP_DATABASE, dbb->implementation) (status, &dbb->handle)); + + if (status[1] && (status[1] != isc_drdb_completed_with_errs)) + return error(status, local); + +/* Release associated request handles */ + + if (dbb->db_path) + free_block(dbb->db_path); + + while (request = dbb->requests) { + dbb->requests = request->next; + if (request->user_handle) + *request->user_handle = NULL; + release_handle(request); + } + +#ifndef SUPERSERVER + while (statement = dbb->statements) { + dbb->statements = statement->next; + if (statement->user_handle) + *statement->user_handle = NULL; + release_dsql_support((DASUP)statement->requests); + release_handle(statement); + } +#endif + + while (blob = dbb->blobs) { + dbb->blobs = blob->next; + if (blob->user_handle) + *blob->user_handle = NULL; + release_handle(blob); + } + + SUBSYSTEM_USAGE_DECR; + subsystem_exit(); + +/* Call the associated cleanup handlers */ + + while ((clean = dbb->cleanup) != NULL) { + dbb->cleanup = clean->clean_next; + (*clean->clean_routine) ((HNDL) handle, clean->clean_arg); + free_block(clean); + } + + release_handle(dbb); + *handle = NULL; + + if (status[1]) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_ALLOC(STATUS * user_status, + ATT * db_handle, STMT * stmt_handle) +{ +/************************************** + * + * i s c _ d s q l _ a l l o c _ s t a t e m e n t + * + **************************************/ + + return GDS_DSQL_ALLOCATE(user_status, db_handle, stmt_handle); +} + + +STATUS API_ROUTINE GDS_DSQL_ALLOC2(STATUS * user_status, + ATT * db_handle, STMT * stmt_handle) +{ +/************************************** + * + * i s c _ d s q l _ a l l o c _ s t a t e m e n t 2 + * + ************************************** + * + * Functional description + * Allocate a statement handle. + * + **************************************/ + + if (GDS_DSQL_ALLOCATE(user_status, db_handle, stmt_handle)) + return user_status[1]; + + (*stmt_handle)->user_handle = stmt_handle; + + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_ALLOCATE(STATUS * user_status, + ATT * db_handle, STMT * stmt_handle) +{ +/************************************** + * + * i s c _ d s q l _ a l l o c a t e _ s t a t e m e n t + * + ************************************** + * + * Functional description + * Allocate a statement handle. + * + **************************************/ + STATUS s, *status, local[20]; + STMT statement; + ATT dbb; + UCHAR flag; + PTR entry; + + GET_STATUS; + +/* check the statement handle to make sure it's NULL and then initialize it. */ + + NULL_CHECK(stmt_handle, isc_bad_stmt_handle, HANDLE_statement); + dbb = *db_handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + +/* Attempt to have the implementation which processed the database attach + process the allocate statement. This may not be feasible (e.g., the + server doesn't support remote DSQL because it's the wrong version or + something) in which case, execute the functionality locally (and hence + remotely through the original Y-valve). */ + + s = isc_unavailable; + entry = get_entrypoint(PROC_DSQL_ALLOCATE, dbb->implementation); + if (entry != no_entrypoint) { + subsystem_enter(); + s = (*entry) (status, &dbb->handle, stmt_handle); + subsystem_exit(); + } + flag = 0; +#ifndef NO_LOCAL_DSQL + if (s == isc_unavailable) { + /* if the entry point didn't exist or if the routine said the server + didn't support the protocol... do it locally */ + + flag = HANDLE_STATEMENT_local; + + subsystem_enter(); + s = dsql8_allocate_statement(status, (int**)db_handle, (dsql_req**)stmt_handle); + subsystem_exit(); + } +#endif + + if (status[1]) + return error2(status, local); + + statement = + allocate_handle(dbb->implementation, (int*)*stmt_handle, HANDLE_statement); + + if (!statement) { + /* No memory. Make a half-hearted attempt to drop statement. */ + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (flag & HANDLE_STATEMENT_local) + dsql8_free_statement(status, (dsql_req**)stmt_handle, DSQL_drop); + else +#endif + CALL(PROC_DSQL_FREE, dbb->implementation) (status, stmt_handle, + DSQL_drop); + + subsystem_exit(); + + *stmt_handle = (STMT)NULL_PTR; + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error2(status, local); + } + + *stmt_handle = statement; + statement->parent = dbb; + statement->next = dbb->statements; + dbb->statements = statement; + statement->flags = flag; + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE isc_dsql_describe(STATUS * user_status, + STMT * stmt_handle, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ d e s c r i b e + * + ************************************** + * + * Functional description + * Describe output parameters for a prepared statement. + * + **************************************/ + STATUS *status, local[20]; + USHORT buffer_len; +#ifdef STACK_EFFICIENT + SCHAR *buffer, local_buffer[1]; +#else + SCHAR *buffer, local_buffer[512]; +#endif /* STACK_EFFICIENT */ + + GET_STATUS; + CHECK_HANDLE(*stmt_handle, HANDLE_statement, isc_bad_stmt_handle); + + if (!(buffer = get_sqlda_buffer(local_buffer, sizeof(local_buffer), sqlda, + dialect, &buffer_len))) { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error2(status, local); + } + + if (!GDS_DSQL_SQL_INFO( status, + stmt_handle, + sizeof(describe_select_info), + (SCHAR*)describe_select_info, + buffer_len, + buffer)) + { + iterative_sql_info( status, + stmt_handle, + sizeof(describe_select_info), + (SCHAR*)describe_select_info, + buffer_len, + buffer, + dialect, + sqlda); + } + + if (buffer != local_buffer) { + free_block(buffer); + } + + if (status[1]) { + return error2(status, local); + } + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE isc_dsql_describe_bind(STATUS * user_status, + STMT * stmt_handle, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ d e s c r i b e _ b i n d + * + ************************************** + * + * Functional description + * Describe input parameters for a prepared statement. + * + **************************************/ + STATUS *status, local[20]; + USHORT buffer_len; +#ifdef STACK_EFFICIENT + SCHAR *buffer, local_buffer[1]; +#else + SCHAR *buffer, local_buffer[512]; +#endif /* STACK_EFFICIENT */ + + GET_STATUS; + CHECK_HANDLE(*stmt_handle, HANDLE_statement, isc_bad_stmt_handle); + + if (!(buffer = get_sqlda_buffer(local_buffer, sizeof(local_buffer), sqlda, + dialect, &buffer_len))) { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error2(status, local); + } + + if (!GDS_DSQL_SQL_INFO( status, + stmt_handle, + sizeof(describe_bind_info), + (SCHAR*)describe_bind_info, + buffer_len, + buffer)) + { + iterative_sql_info( status, + stmt_handle, + sizeof(describe_bind_info), + (SCHAR*)describe_bind_info, + buffer_len, + buffer, + dialect, + sqlda); + } + + if (buffer != local_buffer) { + free_block(buffer); + } + + if (status[1]) { + return error2(status, local); + } + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_EXECUTE(STATUS * user_status, + TRA * tra_handle, + STMT * stmt_handle, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ e x e c u t e + * + ************************************** + * + * Functional description + * Execute a non-SELECT dynamic SQL statement. + * + **************************************/ + + return GDS_DSQL_EXECUTE2(user_status, tra_handle, stmt_handle, dialect, + sqlda, NULL); +} + + +STATUS API_ROUTINE GDS_DSQL_EXECUTE2(STATUS * user_status, + TRA * tra_handle, + STMT * stmt_handle, + USHORT dialect, + XSQLDA * in_sqlda, XSQLDA * out_sqlda) +{ +/************************************** + * + * i s c _ d s q l _ e x e c u t e 2 + * + ************************************** + * + * Functional description + * Execute a non-SELECT dynamic SQL statement. + * + **************************************/ + STATUS *status, local[20]; + STMT statement; + USHORT in_blr_length, in_msg_type, in_msg_length, + out_blr_length, out_msg_type, out_msg_length; + DASUP dasup; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + if (*tra_handle) + CHECK_HANDLE(*tra_handle, HANDLE_transaction, isc_bad_trans_handle); + + if (!(dasup = (DASUP) statement->requests)) + return bad_handle(user_status, isc_unprepared_stmt); + + if (UTLD_parse_sqlda(status, dasup, &in_blr_length, &in_msg_type, + &in_msg_length, dialect, in_sqlda, + DASUP_CLAUSE_bind)) return error2(status, local); + if (UTLD_parse_sqlda + (status, dasup, &out_blr_length, &out_msg_type, &out_msg_length, + dialect, out_sqlda, DASUP_CLAUSE_select)) + return error2(status, local); + + if (GDS_DSQL_EXECUTE2_M(status, tra_handle, stmt_handle, + in_blr_length, + dasup->dasup_clauses[DASUP_CLAUSE_bind].dasup_blr, + in_msg_type, in_msg_length, + dasup->dasup_clauses[DASUP_CLAUSE_bind].dasup_msg, + out_blr_length, + dasup->dasup_clauses[DASUP_CLAUSE_select]. + dasup_blr, out_msg_type, out_msg_length, + dasup->dasup_clauses[DASUP_CLAUSE_select]. + dasup_msg)) return error2(status, local); + + if (UTLD_parse_sqlda(status, dasup, NULL, NULL, NULL, + dialect, out_sqlda, DASUP_CLAUSE_select)) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_EXECUTE_M(STATUS * user_status, + TRA * tra_handle, + STMT * stmt_handle, + USHORT blr_length, + SCHAR * blr, + USHORT msg_type, + USHORT msg_length, SCHAR * msg) +{ +/************************************** + * + * i s c _ d s q l _ e x e c u t e _ m + * + ************************************** + * + * Functional description + * Execute a non-SELECT dynamic SQL statement. + * + **************************************/ + + return GDS_DSQL_EXECUTE2_M(user_status, tra_handle, stmt_handle, + blr_length, blr, msg_type, msg_length, msg, + 0, NULL, 0, 0, NULL); +} + + +STATUS API_ROUTINE GDS_DSQL_EXECUTE2_M(STATUS * user_status, + TRA * tra_handle, + STMT * stmt_handle, + USHORT in_blr_length, + SCHAR * in_blr, + USHORT in_msg_type, + USHORT in_msg_length, + SCHAR * in_msg, + USHORT out_blr_length, + SCHAR * out_blr, + USHORT out_msg_type, + USHORT out_msg_length, SCHAR * out_msg) +{ +/************************************** + * + * i s c _ d s q l _ e x e c u t e 2 _ m + * + ************************************** + * + * Functional description + * Execute a non-SELECT dynamic SQL statement. + * + **************************************/ + STATUS *status, local[20]; + STMT statement; + TRA transaction, handle = NULL; + PTR entry; + CLEAN clean; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + if (transaction = *tra_handle) + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) { + subsystem_enter(); + dsql8_execute(status, (void**)tra_handle, (dsql_req**)&statement->handle, + in_blr_length, (UCHAR*) in_blr, in_msg_type, in_msg_length, + (UCHAR*) in_msg, out_blr_length, (UCHAR*) out_blr, out_msg_type, + out_msg_length, (UCHAR*) out_msg); + subsystem_exit(); + } + else +#endif + { + if (transaction) { + handle = find_transaction(statement->parent, transaction); + CHECK_HANDLE(handle, HANDLE_transaction, isc_bad_trans_handle); + handle = (HNDL)handle->handle; + } + subsystem_enter(); + entry = get_entrypoint(PROC_DSQL_EXECUTE2, statement->implementation); + if (entry != no_entrypoint && + (*entry) (status, + &handle, + &statement->handle, + in_blr_length, + in_blr, + in_msg_type, + in_msg_length, + in_msg, + out_blr_length, + out_blr, + out_msg_type, + out_msg_length, out_msg) != isc_unavailable); + else if (!out_blr_length && !out_msg_type && !out_msg_length) + CALL(PROC_DSQL_EXECUTE, statement->implementation) (status, + &handle, + &statement-> + handle, + in_blr_length, + in_blr, + in_msg_type, + in_msg_length, + in_msg); + else + no_entrypoint(status); + subsystem_exit(); + + if (!status[1]) + { + if (transaction && !handle) { + /* Call the associated cleanup handlers */ + + while (clean = transaction->cleanup) { + transaction->cleanup = clean->clean_next; + (*clean->clean_routine) (transaction, clean->clean_arg); + free_block(clean); + } + + release_handle(transaction); + *tra_handle = NULL; + } + else if (!transaction && handle) + { + *tra_handle = allocate_handle( statement->implementation, + (int*)handle, + HANDLE_transaction); + if (*tra_handle) { + (*tra_handle)->parent = statement->parent; + } else { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + } + } + } + } + + if (status[1]) { + return error2(status, local); + } + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_EXEC_IMMED(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT length, + SCHAR * string, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ e x e c _ i m m e d + * + ************************************** + * + * Functional description + * + **************************************/ + + return GDS_DSQL_EXECUTE_IMMED(user_status, + db_handle, tra_handle, length, string, + dialect, sqlda); +} + + +STATUS API_ROUTINE GDS_DSQL_EXECUTE_IMMED(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT length, + SCHAR * string, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ e x e c u t e _ i m m e d i a t e + * + ************************************** + * + * Functional description + * Prepare a statement for execution. + * + **************************************/ + + return GDS_DSQL_EXEC_IMMED2(user_status, + db_handle, tra_handle, length, string, + dialect, sqlda, NULL); +} + + +STATUS API_ROUTINE GDS_DSQL_EXEC_IMMED2(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT length, + SCHAR * string, + USHORT dialect, + XSQLDA * in_sqlda, XSQLDA * out_sqlda) +{ +/************************************** + * + * i s c _ d s q l _ e x e c _ i m m e d 2 + * + ************************************** + * + * Functional description + * Prepare a statement for execution. + * + **************************************/ + STATUS s, *status, local[20]; + USHORT in_blr_length, in_msg_type, in_msg_length, + out_blr_length, out_msg_type, out_msg_length; + struct dasup dasup; + + GET_STATUS; + + if (*db_handle) + CHECK_HANDLE(*db_handle, HANDLE_database, isc_bad_db_handle); + if (*tra_handle) + CHECK_HANDLE(*tra_handle, HANDLE_transaction, isc_bad_trans_handle); + + memset(&dasup, 0, sizeof(struct dasup)); + if (UTLD_parse_sqlda(status, &dasup, &in_blr_length, &in_msg_type, + &in_msg_length, dialect, in_sqlda, + DASUP_CLAUSE_bind)) return error2(status, local); + if (UTLD_parse_sqlda + (status, &dasup, &out_blr_length, &out_msg_type, &out_msg_length, + dialect, out_sqlda, DASUP_CLAUSE_select)) + return error2(status, local); + + if (!(s = GDS_DSQL_EXEC_IMM2_M(status, db_handle, tra_handle, + length, string, dialect, + in_blr_length, + dasup.dasup_clauses[DASUP_CLAUSE_bind]. + dasup_blr, in_msg_type, in_msg_length, + dasup.dasup_clauses[DASUP_CLAUSE_bind]. + dasup_msg, out_blr_length, + dasup.dasup_clauses[DASUP_CLAUSE_select]. + dasup_blr, out_msg_type, out_msg_length, + dasup.dasup_clauses[DASUP_CLAUSE_select]. + dasup_msg))) s = + UTLD_parse_sqlda(status, &dasup, NULL, NULL, NULL, dialect, + out_sqlda, DASUP_CLAUSE_select); + + if (dasup.dasup_clauses[DASUP_CLAUSE_bind].dasup_blr) + gds__free((SLONG *) + (dasup.dasup_clauses[DASUP_CLAUSE_bind].dasup_blr)); + if (dasup.dasup_clauses[DASUP_CLAUSE_bind].dasup_msg) + gds__free((SLONG *) + (dasup.dasup_clauses[DASUP_CLAUSE_bind].dasup_msg)); + if (dasup.dasup_clauses[DASUP_CLAUSE_select].dasup_blr) + gds__free((SLONG *) + (dasup.dasup_clauses[DASUP_CLAUSE_select].dasup_blr)); + if (dasup.dasup_clauses[DASUP_CLAUSE_select].dasup_msg) + gds__free((SLONG *) + (dasup.dasup_clauses[DASUP_CLAUSE_select].dasup_msg)); + + CHECK_STATUS(status); + return s; +} + + +STATUS API_ROUTINE GDS_DSQL_EXEC_IMM_M(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT length, + SCHAR * string, + USHORT dialect, + USHORT blr_length, + USHORT msg_type, + USHORT msg_length, + SCHAR * blr, SCHAR * msg) +{ +/************************************** + * + * i s c _ d s q l _ e x e c _ i m m e d _ m + * + ************************************** + * + * Functional description + * + **************************************/ + + return GDS_DSQL_EXECUTE_IMM_M(user_status, db_handle, tra_handle, + length, string, dialect, blr_length, blr, + msg_type, msg_length, msg); +} + + +STATUS API_ROUTINE GDS_DSQL_EXECUTE_IMM_M(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT length, + SCHAR * string, + USHORT dialect, + USHORT blr_length, + SCHAR * blr, + USHORT msg_type, + USHORT msg_length, SCHAR * msg) +{ +/************************************** + * + * i s c _ d s q l _ e x e c u t e _ i m m e d i a t e _ m + * + ************************************** + * + * Functional description + * Prepare a statement for execution. + * + **************************************/ + + return GDS_DSQL_EXEC_IMM2_M(user_status, db_handle, tra_handle, + length, string, dialect, blr_length, blr, + msg_type, msg_length, msg, 0, NULL, 0, 0, + NULL); +} + + +STATUS API_ROUTINE GDS_DSQL_EXEC_IMM2_M(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT length, + SCHAR * string, + USHORT dialect, + USHORT in_blr_length, + SCHAR * in_blr, + USHORT in_msg_type, + USHORT in_msg_length, + SCHAR * in_msg, + USHORT out_blr_length, + SCHAR * out_blr, + USHORT out_msg_type, + USHORT out_msg_length, + SCHAR * out_msg) +{ +/************************************** + * + * i s c _ d s q l _ e x e c _ i m m 2 _ m + * + ************************************** + * + * Functional description + * Prepare a statement for execution. + * + **************************************/ + TRA crdb_trans_handle; + STATUS temp_status[20]; + STATUS local[20], *status, *s; + BOOLEAN stmt_eaten; + SCHAR buffer[16]; + SCHAR ch; + BOOLEAN ret_v3_error; + + GET_STATUS; + + if (PREPARSE_execute( status, + (SLONG**)db_handle, + (SLONG**)tra_handle, + length, + string, + &stmt_eaten, + dialect)) + { + if (status[1]) + return error2(status, local); + + crdb_trans_handle = NULL; + if (GDS_START_TRANSACTION(status, &crdb_trans_handle, 1, + db_handle, 0, (SCHAR *) 0)) { + save_error_string(status); + GDS_DROP_DATABASE(temp_status, db_handle); + *db_handle = NULL; + return error2(status, local); + } + + ret_v3_error = FALSE; + if (!stmt_eaten) { + /* Check if against < 4.0 database */ + + ch = gds__info_base_level; + if (!GDS_DATABASE_INFO(status, db_handle, 1, &ch, sizeof(buffer), + buffer)) { + if ((buffer[0] != gds__info_base_level) || (buffer[4] > 3)) + GDS_DSQL_EXEC_IMM3_M(status, db_handle, + &crdb_trans_handle, length, string, + dialect, in_blr_length, in_blr, + in_msg_type, in_msg_length, in_msg, + out_blr_length, out_blr, + out_msg_type, out_msg_length, + out_msg); + else + ret_v3_error = TRUE; + } + } + + if (status[1]) { + GDS_ROLLBACK(temp_status, &crdb_trans_handle); + save_error_string(status); + GDS_DROP_DATABASE(temp_status, db_handle); + *db_handle = NULL; + return error2(status, local); + } + else { + if (GDS_COMMIT(status, &crdb_trans_handle)) { + GDS_ROLLBACK(temp_status, &crdb_trans_handle); + save_error_string(status); + GDS_DROP_DATABASE(temp_status, db_handle); + *db_handle = NULL; + return error2(status, local); + } + } + + if (ret_v3_error) { + s = status; + *s++ = isc_arg_gds; + *s++ = isc_srvr_version_too_old; + *s = isc_arg_end; + return error2(status, local); + } + CHECK_STATUS_SUCCESS(status); + return SUCCESS; + } + else + return GDS_DSQL_EXEC_IMM3_M(user_status, db_handle, tra_handle, + length, string, dialect, + in_blr_length, in_blr, in_msg_type, + in_msg_length, in_msg, out_blr_length, + out_blr, out_msg_type, out_msg_length, + out_msg); +} + + +STATUS API_ROUTINE GDS_DSQL_EXEC_IMM3_M(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT length, + SCHAR * string, + USHORT dialect, + USHORT in_blr_length, + SCHAR * in_blr, + USHORT in_msg_type, + USHORT in_msg_length, + SCHAR * in_msg, + USHORT out_blr_length, + SCHAR * out_blr, + USHORT out_msg_type, + USHORT out_msg_length, + SCHAR * out_msg) +{ +/************************************** + * + * i s c _ d s q l _ e x e c _ i m m 3 _ m + * + ************************************** + * + * Functional description + * Prepare a statement for execution. + * + **************************************/ + STATUS s, *status, local[20]; + ATT dbb; + TRA transaction, handle = NULL; + PTR entry; + CLEAN clean; + +/* If we haven't been initialized yet, do it now */ + + GET_STATUS; + + dbb = *db_handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + if (transaction = *tra_handle) { + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + handle = find_transaction(dbb, transaction); + CHECK_HANDLE(handle, HANDLE_transaction, isc_bad_trans_handle); + handle = (HNDL) handle->handle; + } + +/* Attempt to have the implementation which processed the database attach + process the prepare statement. This may not be feasible (e.g., the + server doesn't support remote DSQL because it's the wrong version or + something) in which case, execute the functionality locally (and hence + remotely through the original Y-valve). */ + + s = isc_unavailable; + entry = get_entrypoint(PROC_DSQL_EXEC_IMMED2, dbb->implementation); + if (entry != no_entrypoint) { + subsystem_enter(); + s = (*entry) (status, + &dbb->handle, + &handle, + length, + string, + dialect, + in_blr_length, + in_blr, + in_msg_type, + in_msg_length, + in_msg, + out_blr_length, + out_blr, out_msg_type, out_msg_length, out_msg); + subsystem_exit(); + } + + if (s == isc_unavailable && !out_msg_length) { + entry = get_entrypoint(PROC_DSQL_EXEC_IMMED, dbb->implementation); + if (entry != no_entrypoint) + { + subsystem_enter(); + s = (*entry) (status, + &dbb->handle, + &handle, + length, + string, + dialect, + in_blr_length, + in_blr, in_msg_type, in_msg_length, in_msg); + subsystem_exit(); + } + } + + if (s != isc_unavailable && !status[1]) + if (transaction && !handle) { + /* Call the associated cleanup handlers */ + + while (clean = transaction->cleanup) { + transaction->cleanup = clean->clean_next; + (*clean->clean_routine) (transaction, clean->clean_arg); + free_block(clean); + } + + release_handle(transaction); + *tra_handle = NULL; + } + else if (!transaction && handle) { + if (*tra_handle = + allocate_handle(dbb->implementation, (int*)handle, + HANDLE_transaction)) + (*tra_handle)->parent = dbb; + else { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error2(status, local); + } + } + +#ifndef NO_LOCAL_DSQL + if (s == isc_unavailable) { + /* if the entry point didn't exist or if the routine said the server + didn't support the protocol... do it locally */ + + subsystem_enter(); + dsql8_execute_immediate(status, (int**)db_handle, (int**)tra_handle, + length, string, dialect, + in_blr_length, (UCHAR*) in_blr, in_msg_type, + in_msg_length, (UCHAR*) in_msg, out_blr_length, + (UCHAR*) out_blr, out_msg_type, out_msg_length, + (UCHAR*) out_msg); + subsystem_exit(); + } +#endif + + if (status[1]) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_FETCH(STATUS * user_status, + STMT * stmt_handle, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ f e t c h + * + ************************************** + * + * Functional description + * Fetch next record from a dynamic SQL cursor + * + **************************************/ + STATUS s, *status, local[20]; + STMT statement; + USHORT blr_length, msg_type, msg_length; + DASUP dasup; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + if (!sqlda) { + status[0] = isc_arg_gds; + status[1] = isc_dsql_sqlda_err; + status[2] = isc_arg_end; + return error2(status, local); + } + + if (!(dasup = (DASUP) statement->requests)) + return bad_handle(user_status, isc_unprepared_stmt); + + if (UTLD_parse_sqlda(status, dasup, &blr_length, &msg_type, &msg_length, + dialect, sqlda, DASUP_CLAUSE_select)) + return error2(status, local); + + if ((s = GDS_DSQL_FETCH_M(status, stmt_handle, blr_length, + dasup->dasup_clauses[DASUP_CLAUSE_select]. + dasup_blr, 0, msg_length, + dasup->dasup_clauses[DASUP_CLAUSE_select]. + dasup_msg)) && s != 101) { + CHECK_STATUS(status); + return s; + } + + if (UTLD_parse_sqlda(status, dasup, NULL, NULL, NULL, + dialect, sqlda, DASUP_CLAUSE_select)) + return error2(status, local); + + CHECK_STATUS(status); + return s; +} + + +#ifdef SCROLLABLE_CURSORS +STATUS API_ROUTINE GDS_DSQL_FETCH2(STATUS * user_status, + STMT * stmt_handle, + USHORT dialect, + XSQLDA * sqlda, + USHORT direction, SLONG offset) +{ +/************************************** + * + * i s c _ d s q l _ f e t c h 2 + * + ************************************** + * + * Functional description + * Fetch next record from a dynamic SQL cursor + * + **************************************/ + STATUS s, *status, local[20]; + STMT statement; + USHORT blr_length, msg_type, msg_length; + DASUP dasup; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + if (!(dasup = (DASUP) statement->requests)) + return bad_handle(user_status, isc_unprepared_stmt); + + if (UTLD_parse_sqlda(status, dasup, &blr_length, &msg_type, &msg_length, + dialect, sqlda, DASUP_CLAUSE_select)) + return error2(status, local); + + if ((s = GDS_DSQL_FETCH2_M(status, stmt_handle, blr_length, + dasup->dasup_clauses[DASUP_CLAUSE_select]. + dasup_blr, 0, msg_length, + dasup->dasup_clauses[DASUP_CLAUSE_select]. + dasup_msg, direction, offset)) && s != 101) { + CHECK_STATUS(status); + return s; + } + + if (UTLD_parse_sqlda(status, dasup, NULL, NULL, NULL, + dialect, sqlda, DASUP_CLAUSE_select)) + return error2(status, local); + + CHECK_STATUS(status); + return s; +} +#endif + + +STATUS API_ROUTINE GDS_DSQL_FETCH_M(STATUS * user_status, + STMT * stmt_handle, + USHORT blr_length, + SCHAR * blr, + USHORT msg_type, + USHORT msg_length, SCHAR * msg) +{ +/************************************** + * + * i s c _ d s q l _ f e t c h _ m + * + ************************************** + * + * Functional description + * Fetch next record from a dynamic SQL cursor + * + **************************************/ + STATUS s, *status, local[20]; + STMT statement; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) + s = dsql8_fetch(status, + (dsql_req**)&statement->handle, blr_length, (UCHAR*)blr, msg_type, + msg_length, (UCHAR*)msg +#ifdef SCROLLABLE_CURSORS + , (USHORT) 0, (ULONG) 1); +#else + ); +#endif + else +#endif + s = CALL(PROC_DSQL_FETCH, statement->implementation) (status, + &statement-> + handle, + blr_length, blr, + msg_type, + msg_length, msg +#ifdef SCROLLABLE_CURSORS + , + (USHORT) 0, + (ULONG) 1); +#else + ); +#endif + + subsystem_exit(); + + CHECK_STATUS(status); + if (s == 100 || s == 101) + return s; + else if (s) + return error2(status, local); + + return SUCCESS; +} + + +#ifdef SCROLLABLE_CURSORS +STATUS API_ROUTINE GDS_DSQL_FETCH2_M(STATUS * user_status, + STMT * stmt_handle, + USHORT blr_length, + SCHAR * blr, + USHORT msg_type, + USHORT msg_length, + SCHAR * msg, + USHORT direction, SLONG offset) +{ +/************************************** + * + * i s c _ d s q l _ f e t c h 2 _ m + * + ************************************** + * + * Functional description + * Fetch next record from a dynamic SQL cursor + * + **************************************/ + STATUS s, *status, local[20]; + STMT statement; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) + s = dsql8_fetch(status, + &statement->handle, blr_length, blr, msg_type, + msg_length, msg, direction, offset); + else +#endif + s = CALL(PROC_DSQL_FETCH, statement->implementation) (status, + &statement-> + handle, + blr_length, blr, + msg_type, + msg_length, msg, + direction, + offset); + + subsystem_exit(); + + CHECK_STATUS(status); + if (s == 100 || s == 101) + return s; + else if (s) + return error2(status, local); + + return SUCCESS; +} +#endif + + +STATUS API_ROUTINE GDS_DSQL_FREE(STATUS * user_status, + STMT * stmt_handle, USHORT option) +{ +/***************************************** + * + * i s c _ d s q l _ f r e e _ s t a t e m e n t + * + ***************************************** + * + * Functional Description + * release request for an sql statement + * + *****************************************/ + STATUS *status, local[20]; + STMT statement; + DBB dbb, *ptr; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) + dsql8_free_statement(status, (dsql_req**)&statement->handle, option); + else +#endif + CALL(PROC_DSQL_FREE, statement->implementation) (status, + &statement->handle, + option); + + subsystem_exit(); + + if (status[1]) + return error2(status, local); + +/* Release the handle and any request hanging off of it. */ + + if (option & DSQL_drop) { + /* Get rid of connections to database */ + + dbb = statement->parent; + for (ptr = &dbb->statements; *ptr; ptr = &(*ptr)->next) + if (*ptr == statement) { + *ptr = statement->next; + break; + } + + release_dsql_support((DASUP)statement->requests); + release_handle(statement); + *stmt_handle = NULL; + } + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_INSERT(STATUS * user_status, + STMT * stmt_handle, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ i n s e r t + * + ************************************** + * + * Functional description + * Insert next record into a dynamic SQL cursor + * + **************************************/ + STATUS *status, local[20]; + STMT statement; + USHORT blr_length, msg_type, msg_length; + DASUP dasup; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + if (!(dasup = (DASUP) statement->requests)) + return bad_handle(user_status, isc_unprepared_stmt); + + if (UTLD_parse_sqlda(status, dasup, &blr_length, &msg_type, &msg_length, + dialect, sqlda, DASUP_CLAUSE_bind)) + return error2(status, local); + + return GDS_DSQL_INSERT_M(status, stmt_handle, blr_length, + dasup->dasup_clauses[DASUP_CLAUSE_bind]. + dasup_blr, 0, msg_length, + dasup->dasup_clauses[DASUP_CLAUSE_bind]. + dasup_msg); +} + + +STATUS API_ROUTINE GDS_DSQL_INSERT_M(STATUS * user_status, + STMT * stmt_handle, + USHORT blr_length, + SCHAR * blr, + USHORT msg_type, + USHORT msg_length, SCHAR * msg) +{ +/************************************** + * + * i s c _ d s q l _ i n s e r t _ m + * + ************************************** + * + * Functional description + * Insert next record into a dynamic SQL cursor + * + **************************************/ + STATUS s, *status, local[20]; + STMT statement; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) + s = dsql8_insert(status, + (dsql_req**) &statement->handle, blr_length, (UCHAR*)blr, msg_type, + msg_length, (UCHAR*)msg); + else +#endif + s = CALL(PROC_DSQL_INSERT, statement->implementation) (status, + &statement-> + handle, + blr_length, + blr, msg_type, + msg_length, + msg); + + subsystem_exit(); + + if (s) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_PREPARE(STATUS * user_status, + TRA * tra_handle, + STMT * stmt_handle, + USHORT length, + SCHAR * string, + USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i s c _ d s q l _ p r e p a r e + * + ************************************** + * + * Functional description + * Prepare a statement for execution. + * + **************************************/ + STATUS *status, local[20]; + USHORT buffer_len; +#ifdef STACK_EFFICIENT + SCHAR *buffer, local_buffer[1]; +#else + SCHAR *buffer, local_buffer[BUFFER_MEDIUM]; +#endif /* STACK_EFFICIENT */ + DASUP dasup; + + GET_STATUS; + CHECK_HANDLE(*stmt_handle, HANDLE_statement, isc_bad_stmt_handle); + if (*tra_handle) + CHECK_HANDLE(*tra_handle, HANDLE_transaction, isc_bad_trans_handle); + + if (!(buffer = get_sqlda_buffer(local_buffer, sizeof(local_buffer), sqlda, + dialect, &buffer_len))) { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error2(status, local); + } + + if (!GDS_DSQL_PREPARE_M(status, + tra_handle, + stmt_handle, + length, + string, + dialect, + sizeof(sql_prepare_info), + (SCHAR*) sql_prepare_info, + buffer_len, + buffer)) + { + release_dsql_support((DASUP)(*stmt_handle)->requests); + + if (!(dasup = (DASUP) alloc((SLONG) sizeof(struct dasup)))) { + (*stmt_handle)->requests = (HNDL) NULL_PTR; + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + } + else { + (*stmt_handle)->requests = (HNDL) dasup; + dasup->dasup_dialect = dialect; + + iterative_sql_info(status, stmt_handle, sizeof(sql_prepare_info), + (SCHAR*)sql_prepare_info, buffer_len, buffer, dialect, + sqlda); + } + } + + if (buffer != local_buffer) + free_block(buffer); + + if (status[1]) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_PREPARE_M(STATUS * user_status, + TRA * tra_handle, + STMT * stmt_handle, + USHORT length, + SCHAR * string, + USHORT dialect, + USHORT GDS_VAL(item_length), + SCHAR * items, + USHORT GDS_VAL(buffer_length), + SCHAR * buffer) +{ +/************************************** + * + * i s c _ d s q l _ p r e p a r e _ m + * + ************************************** + * + * Functional description + * Prepare a statement for execution. + * + **************************************/ + STATUS *status, local[20]; + STMT statement; + TRA handle = NULL, transaction; + + GET_STATUS; + + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + if (transaction = *tra_handle) { + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + handle = find_transaction(statement->parent, transaction); + CHECK_HANDLE(handle, HANDLE_transaction, isc_bad_trans_handle); + handle = (HNDL) handle->handle; + } + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) + dsql8_prepare(status, (void**) tra_handle, (dsql_req**) &statement->handle, + length, string, dialect, item_length, (UCHAR*) items, + buffer_length, (UCHAR*) buffer); + else +#endif + { + CALL(PROC_DSQL_PREPARE, statement->implementation) (status, + &handle, + (dsql_req**)&statement-> + handle, length, + string, dialect, + item_length, + items, + buffer_length, + buffer); + } + + subsystem_exit(); + + if (status[1]) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_SET_CURSOR(STATUS * user_status, + STMT * stmt_handle, + SCHAR * cursor, USHORT type) +{ +/************************************** + * + * i s c _ d s q l _ s e t _ c u r s o r + * + ************************************** + * + * Functional description + * Set a cursor name for a dynamic request. + * + **************************************/ + STATUS *status, local[20]; + STMT statement; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) + dsql8_set_cursor(status, (dsql_req**) &statement->handle, cursor, type); + else +#endif + CALL(PROC_DSQL_SET_CURSOR, statement->implementation) (status, + &statement-> + handle, cursor, + type); + + subsystem_exit(); + + if (status[1]) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_DSQL_SQL_INFO(STATUS * user_status, + STMT * stmt_handle, + SSHORT GDS_VAL(item_length), + SCHAR * items, + SSHORT GDS_VAL(buffer_length), + SCHAR * buffer) +{ +/************************************** + * + * i s c _ d s q l _ s q l _ i n f o + * + ************************************** + * + * Functional description + * Provide information on sql statement. + * + **************************************/ + STATUS local[20], *status; + STMT statement; + + GET_STATUS; + statement = *stmt_handle; + CHECK_HANDLE(statement, HANDLE_statement, isc_bad_stmt_handle); + + subsystem_enter(); + +#ifndef NO_LOCAL_DSQL + if (statement->flags & HANDLE_STATEMENT_local) + dsql8_sql_info(status, (dsql_req**) &statement->handle, item_length, items, + buffer_length, buffer); + else +#endif + CALL(PROC_DSQL_SQL_INFO, statement->implementation) (status, + &statement-> + handle, + item_length, + items, + buffer_length, + buffer); + + subsystem_exit(); + + if (status[1]) + return error2(status, local); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +int API_ROUTINE gds__enable_subsystem(TEXT * subsystem) +{ +/************************************** + * + * g d s _ $ e n a b l e _ s u b s y s t e m + * + ************************************** + * + * Functional description + * Enable access to a specific subsystem. If no subsystem + * has been explicitly enabled, all are available. + * + **************************************/ + IMAGE *sys, *end; + + for (sys = (IMAGE*)images, end = sys + SUBSYSTEMS; sys < end; sys++) + if (!strcmp(sys->name, subsystem)) { + if (!~why_enabled) + why_enabled = 0; + why_enabled |= (1 << (sys - images)); + return TRUE; + } + + return FALSE; +} + + +#ifndef REQUESTER +STATUS API_ROUTINE GDS_EVENT_WAIT(STATUS * user_status, + ATT * handle, + USHORT GDS_VAL(length), + UCHAR * events, UCHAR * buffer) +{ +/************************************** + * + * g d s _ $ e v e n t _ w a i t + * + ************************************** + * + * Functional description + * Que request for event notification. + * + **************************************/ + STATUS local[20], *status; + SLONG value, id; + EVENT event_ptr; + + GET_STATUS; + + if (!why_initialized) { + gds__register_cleanup(exit_handler, why_event); + why_initialized = TRUE; + ISC_event_init(why_event, 0, 0); + } + + value = ISC_event_clear(why_event); + + if (GDS_QUE_EVENTS + (status, handle, &id, length, events, (void (*)())event_ast, + buffer)) return error2(status, local); + + event_ptr = why_event; + ISC_event_wait(1, &event_ptr, &value, -1, (FPTR_VOID) NULL_PTR, NULL_PTR); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} +#endif + + +STATUS API_ROUTINE GDS_GET_SEGMENT(STATUS * user_status, + BLB * blob_handle, + USHORT * length, + USHORT GDS_VAL(buffer_length), + UCHAR * buffer) +{ +/************************************** + * + * g d s _ $ g e t _ s e g m e n t + * + ************************************** + * + * Functional description + * Abort a partially completed blob. + * + **************************************/ + STATUS local[20], *status, code; + BLB blob; + + GET_STATUS; + blob = *blob_handle; + CHECK_HANDLE(blob, HANDLE_blob, isc_bad_segstr_handle); + subsystem_enter(); + + code = CALL(PROC_GET_SEGMENT, blob->implementation) (status, + &blob->handle, + length, + GDS_VAL + (buffer_length), + buffer); + + if (code) { + if (code == isc_segstr_eof || code == isc_segment) { + subsystem_exit(); + CHECK_STATUS(status); + return code; + } + return error(status, local); + } + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_GET_SLICE(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + SLONG * array_id, + USHORT GDS_VAL(sdl_length), + UCHAR * sdl, + USHORT GDS_VAL(param_length), + UCHAR * param, + SLONG GDS_VAL(slice_length), + UCHAR * slice, SLONG * return_length) +{ +/************************************** + * + * g d s _ $ g e t _ s l i c e + * + ************************************** + * + * Functional description + * Snatch a slice of an array. + * + **************************************/ + STATUS local[20], *status; + ATT dbb; + TRA transaction; + + GET_STATUS; + dbb = *db_handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + transaction = find_transaction(dbb, *tra_handle); + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + if (CALL(PROC_GET_SLICE, dbb->implementation) (status, + &dbb->handle, + &transaction->handle, + array_id, + GDS_VAL(sdl_length), + sdl, + GDS_VAL(param_length), + param, + GDS_VAL(slice_length), + slice, + return_length)) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS gds__handle_cleanup(STATUS * user_status, HNDL * user_handle) +{ +/************************************** + * + * g d s _ $ h a n d l e _ c l e a n u p + * + ************************************** + * + * Functional description + * Clean up a dangling y-valve handle. + * + **************************************/ + STATUS local[20], *status; + HNDL handle; + TRA transaction, sub; + CLEAN clean; + + GET_STATUS; + + if (!(handle = *user_handle)) { + status[0] = isc_arg_gds; + status[1] = isc_bad_db_handle; + status[2] = isc_arg_end; + return error2(status, local); + } + + switch (handle->type) { + case HANDLE_transaction: + + /* Call the associated cleanup handlers */ + + transaction = (TRA) handle; + while (clean = transaction->cleanup) { + transaction->cleanup = clean->clean_next; + (*clean->clean_routine) (transaction, clean->clean_arg); + free_block(clean); + } + while (sub = transaction) { + transaction = sub->next; + release_handle(sub); + } + break; + + default: + status[0] = isc_arg_gds; + status[1] = isc_bad_db_handle; + status[2] = isc_arg_end; + return error2(status, local); + } + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_OPEN_BLOB(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + BLB * blob_handle, SLONG * blob_id) +{ +/************************************** + * + * g d s _ $ o p e n _ b l o b + * + ************************************** + * + * Functional description + * Open an existing blob. + * + **************************************/ + + return open_blob(user_status, db_handle, tra_handle, blob_handle, blob_id, + 0, (UCHAR*) NULL_PTR, PROC_OPEN_BLOB, PROC_OPEN_BLOB2); +} + + +STATUS API_ROUTINE GDS_OPEN_BLOB2(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + BLB * blob_handle, + SLONG * blob_id, + SSHORT GDS_VAL(bpb_length), UCHAR * bpb) +{ +/************************************** + * + * g d s _ $ o p e n _ b l o b 2 + * + ************************************** + * + * Functional description + * Open an existing blob (extended edition). + * + **************************************/ + + return open_blob(user_status, db_handle, tra_handle, blob_handle, blob_id, + GDS_VAL(bpb_length), bpb, PROC_OPEN_BLOB, + PROC_OPEN_BLOB2); +} + + +STATUS API_ROUTINE GDS_PREPARE(STATUS * user_status, TRA * tra_handle) +{ +/************************************** + * + * g d s _ $ p r e p a r e + * + ************************************** + * + * Functional description + * Prepare a transaction for commit. First phase of a two + * phase commit. + * + **************************************/ + return GDS_PREPARE2(user_status, tra_handle, 0, (UCHAR*) NULL_PTR); +} + + +STATUS API_ROUTINE GDS_PREPARE2(STATUS * user_status, + TRA * tra_handle, + USHORT GDS_VAL(msg_length), UCHAR * msg) +{ +/************************************** + * + * g d s _ $ p r e p a r e 2 + * + ************************************** + * + * Functional description + * Prepare a transaction for commit. First phase of a two + * phase commit. + * + **************************************/ + STATUS local[20], *status; + TRA transaction, sub; + + GET_STATUS; + transaction = *tra_handle; + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + for (sub = transaction; sub; sub = sub->next) + if (sub->implementation != SUBSYSTEMS && + CALL(PROC_PREPARE, sub->implementation) (status, + &sub->handle, + GDS_VAL(msg_length), + msg)) + return error(status, local); + + transaction->flags |= HANDLE_TRANSACTION_limbo; + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_PUT_SEGMENT(STATUS * user_status, + BLB * blob_handle, + USHORT GDS_VAL(buffer_length), + UCHAR * buffer) +{ +/************************************** + * + * g d s _ $ p u t _ s e g m e n t + * + ************************************** + * + * Functional description + * Abort a partially completed blob. + * + **************************************/ + STATUS local[20], *status; + BLB blob; + + GET_STATUS; + blob = *blob_handle; + CHECK_HANDLE(blob, HANDLE_blob, isc_bad_segstr_handle); + subsystem_enter(); + + if (CALL(PROC_PUT_SEGMENT, blob->implementation) (status, + &blob->handle, + GDS_VAL(buffer_length), + buffer)) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_PUT_SLICE(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + SLONG * array_id, + USHORT GDS_VAL(sdl_length), + UCHAR * sdl, + USHORT GDS_VAL(param_length), + UCHAR * param, + SLONG GDS_VAL(slice_length), UCHAR * slice) +{ +/************************************** + * + * g d s _ $ p u t _ s l i c e + * + ************************************** + * + * Functional description + * Snatch a slice of an array. + * + **************************************/ + STATUS local[20], *status; + ATT dbb; + TRA transaction; + + GET_STATUS; + dbb = *db_handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + transaction = find_transaction(dbb, *tra_handle); + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + if (CALL(PROC_PUT_SLICE, dbb->implementation) (status, + &dbb->handle, + &transaction->handle, + array_id, + GDS_VAL(sdl_length), + sdl, + GDS_VAL(param_length), + param, + GDS_VAL(slice_length), + slice)) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_QUE_EVENTS(STATUS * user_status, + ATT * handle, + SLONG * id, + USHORT GDS_VAL(length), + UCHAR * events, + FPTR_VOID ast, void *arg) +{ +/************************************** + * + * g d s _ $ q u e _ e v e n t s + * + ************************************** + * + * Functional description + * Que request for event notification. + * + **************************************/ + STATUS local[20], *status; + ATT database; + + GET_STATUS; + database = *handle; + CHECK_HANDLE(database, HANDLE_database, isc_bad_db_handle); + subsystem_enter(); + + if (CALL(PROC_QUE_EVENTS, database->implementation) (status, + &database->handle, + id, + GDS_VAL(length), + events, + GDS_VAL(ast), + arg)) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_RECEIVE(STATUS * user_status, + REQ * req_handle, + USHORT GDS_VAL(msg_type), + USHORT GDS_VAL(msg_length), + SCHAR * msg, SSHORT GDS_VAL(level)) +{ +/************************************** + * + * g d s _ $ r e c e i v e + * + ************************************** + * + * Functional description + * Get a record from the host program. + * + **************************************/ + +#ifdef SCROLLABLE_CURSORS + return GDS_RECEIVE2(user_status, req_handle, msg_type, msg_length, + msg, level, (USHORT) blr_continue, /* means continue in same direction as before */ + (ULONG) 1); +#else + STATUS local[20], *status; + REQ request; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + subsystem_enter(); + + if (CALL(PROC_RECEIVE, request->implementation) (status, + &request->handle, + GDS_VAL(msg_type), + GDS_VAL(msg_length), + msg, + GDS_VAL(level))) + return error(status, local); + + RETURN_SUCCESS; +#endif +} + + +#ifdef SCROLLABLE_CURSORS +STATUS API_ROUTINE GDS_RECEIVE2(STATUS * user_status, + REQ * req_handle, + USHORT GDS_VAL(msg_type), + USHORT GDS_VAL(msg_length), + SCHAR * msg, + SSHORT GDS_VAL(level), + USHORT direction, ULONG offset) +{ +/************************************** + * + * i s c _ r e c e i v e 2 + * + ************************************** + * + * Functional description + * Scroll through the request output stream, + * then get a record from the host program. + * + **************************************/ + STATUS local[20], *status; + REQ request; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + subsystem_enter(); + + if (CALL(PROC_RECEIVE, request->implementation) (status, + &request->handle, + GDS_VAL(msg_type), + GDS_VAL(msg_length), + msg, + GDS_VAL(level), + direction, + offset)) + return error(status, local); + + RETURN_SUCCESS; +} +#endif + + +STATUS API_ROUTINE GDS_RECONNECT(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + SSHORT GDS_VAL(length), UCHAR * id) +{ +/************************************** + * + * g d s _ $ r e c o n n e c t + * + ************************************** + * + * Functional description + * Connect to a transaction in limbo. + * + **************************************/ + STATUS local[20], *status; + ATT database; + + GET_STATUS; + NULL_CHECK(tra_handle, isc_bad_trans_handle, HANDLE_transaction); + database = *db_handle; + CHECK_HANDLE(database, HANDLE_database, isc_bad_db_handle); + subsystem_enter(); + + if (CALL(PROC_RECONNECT, database->implementation) (status, + &database->handle, + tra_handle, + GDS_VAL(length), + id)) + return error(status, local); + + *tra_handle = allocate_handle( database->implementation, + (int*)*tra_handle, + HANDLE_transaction); + if (*tra_handle) { + (*tra_handle)->parent = database; + } else { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error(status, local); + } + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_RELEASE_REQUEST(STATUS * user_status, REQ * req_handle) +{ +/************************************** + * + * g d s _ $ r e l e a s e _ r e q u e s t + * + ************************************** + * + * Functional description + * Release a request. + * + **************************************/ + STATUS local[20], *status; + REQ request, *ptr; + DBB dbb; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + subsystem_enter(); + + if (CALL(PROC_RELEASE_REQUEST, request->implementation) (status, + &request-> + handle)) return + error(status, local); + +/* Get rid of connections to database */ + + dbb = request->parent; + + for (ptr = &dbb->requests; *ptr; ptr = &(*ptr)->next) + if (*ptr == request) { + *ptr = request->next; + break; + } + + release_handle(request); + *req_handle = NULL; + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_REQUEST_INFO(STATUS * user_status, + REQ * req_handle, + SSHORT GDS_VAL(level), + SSHORT GDS_VAL(item_length), + SCHAR * items, + SSHORT GDS_VAL(buffer_length), + SCHAR * buffer) +{ +/************************************** + * + * g d s _ $ r e q u e s t _ i n f o + * + ************************************** + * + * Functional description + * Provide information on blob object. + * + **************************************/ + STATUS local[20], *status; + REQ request; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + subsystem_enter(); + + if (CALL(PROC_REQUEST_INFO, request->implementation) (status, + &request->handle, + GDS_VAL(level), + GDS_VAL + (item_length), + items, + GDS_VAL + (buffer_length), + buffer)) return + error(status, local); + + RETURN_SUCCESS; +} + + +SLONG API_ROUTINE isc_reset_fpe(USHORT fpe_status) +{ +/************************************** + * + * i s c _ r e s e t _ f p e + * + ************************************** + * + * Functional description + * API to be used to tell InterBase to reset it's + * FPE handler - eg: client has an FPE of it's own + * and just changed it. + * + * Returns + * Prior setting of the FPE reset flag + * + **************************************/ +#if !(defined REQUESTER || defined PIPE_CLIENT || defined SUPERCLIENT || defined SUPERSERVER) + SLONG prior; + prior = (SLONG) subsystem_FPE_reset; + switch (fpe_status) { + case FPE_RESET_INIT_ONLY: + subsystem_FPE_reset = fpe_status; + break; + case FPE_RESET_NEXT_API_CALL: + subsystem_FPE_reset = fpe_status; + break; + case FPE_RESET_ALL_API_CALL: + subsystem_FPE_reset = fpe_status; + break; + default: + break; + } + return prior; +#else + return FPE_RESET_INIT_ONLY; +#endif +} + + +STATUS API_ROUTINE GDS_ROLLBACK_RETAINING(STATUS * user_status, + TRA * tra_handle) +{ +/************************************** + * + * i s c _ r o l l b a c k _ r e t a i n i n g + * + ************************************** + * + * Functional description + * Abort a transaction, but keep all cursors open. + * + **************************************/ + STATUS local[20], *status; + TRA transaction, sub; + + GET_STATUS; + transaction = *tra_handle; + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + for (sub = transaction; sub; sub = sub->next) + if (sub->implementation != SUBSYSTEMS && + CALL(PROC_ROLLBACK_RETAINING, sub->implementation) (status, + &sub->handle)) + return error(status, local); + + transaction->flags |= HANDLE_TRANSACTION_limbo; + + RETURN_SUCCESS; +} +STATUS API_ROUTINE GDS_ROLLBACK(STATUS * user_status, TRA * tra_handle) +{ +/************************************** + * + * g d s _ $ r o l l b a c k + * + ************************************** + * + * Functional description + * Abort a transaction. + * + **************************************/ + STATUS local[20], *status; + TRA transaction, sub; + CLEAN clean; + + GET_STATUS; + transaction = *tra_handle; + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + for (sub = transaction; sub; sub = sub->next) + if (sub->implementation != SUBSYSTEMS && + CALL(PROC_ROLLBACK, sub->implementation) (status, &sub->handle)) + return error(status, local); + + subsystem_exit(); + +/* Call the associated cleanup handlers */ + + while (clean = transaction->cleanup) { + transaction->cleanup = clean->clean_next; + (*clean->clean_routine) (transaction, clean->clean_arg); + free_block(clean); + } + + while (sub = transaction) { + transaction = sub->next; + release_handle(sub); + } + *tra_handle = NULL; + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_SEEK_BLOB(STATUS * user_status, + BLB * blob_handle, + SSHORT GDS_VAL(mode), + SLONG GDS_VAL(offset), SLONG * result) +{ +/************************************** + * + * g d s _ $ s e e k _ b l o b + * + ************************************** + * + * Functional description + * Seek a blob. + * + **************************************/ + STATUS local[20], *status; + BLB blob; + + GET_STATUS; + blob = *blob_handle; + CHECK_HANDLE(blob, HANDLE_blob, isc_bad_segstr_handle); + subsystem_enter(); + +/*** +if (blob->flags & HANDLE_BLOB_filter) + { + subsystem_exit(); + BLF_close_blob (status, &blob->handle); + subsystem_enter(); + } +else +***/ + CALL(PROC_SEEK_BLOB, blob->implementation) (status, + &blob->handle, + GDS_VAL(mode), + GDS_VAL(offset), result); + + if (status[1]) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_SEND(STATUS * user_status, + REQ * req_handle, + USHORT GDS_VAL(msg_type), + USHORT GDS_VAL(msg_length), + SCHAR * msg, SSHORT GDS_VAL(level)) +{ +/************************************** + * + * g d s _ $ s e n d + * + ************************************** + * + * Functional description + * Get a record from the host program. + * + **************************************/ + STATUS local[20], *status; + REQ request; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + subsystem_enter(); + + if (CALL(PROC_SEND, request->implementation) (status, + &request->handle, + GDS_VAL(msg_type), + GDS_VAL(msg_length), + msg, + GDS_VAL(level))) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_SERVICE_ATTACH(STATUS * user_status, + USHORT service_length, + TEXT * service_name, + SVC * handle, + USHORT spb_length, SCHAR * spb) +{ +/************************************** + * + * i s c _ s e r v i c e _ a t t a c h + * + ************************************** + * + * Functional description + * Attach a service through the first subsystem + * that recognizes it. + * + **************************************/ + STATUS local[20], *status, *ptr, temp[20]; + USHORT n, org_length; + SVC service; + TEXT *p; + + GET_STATUS; + NULL_CHECK(handle, isc_bad_svc_handle, HANDLE_service); + + if (!service_name) { + status[0] = isc_arg_gds; + status[1] = isc_service_att_err; + status[2] = isc_arg_gds; + status[3] = isc_svc_name_missing; + status[4] = isc_arg_end; + return error2(status, local); + } + + if (GDS_VAL(spb_length) > 0 && !spb) { + status[0] = isc_arg_gds; + status[1] = isc_bad_spb_form; + status[2] = isc_arg_end; + return error2(status, local); + } + +#if defined (SERVER_SHUTDOWN) && !defined (SUPERCLIENT) && !defined (REQUESTER) + if (shutdown_flag) { + status[0] = isc_arg_gds; + status[1] = isc_shutwarn; + status[2] = isc_arg_end; + return error2(status, local); + } +#endif /* SERVER_SHUTDOWN && !SUPERCLIENT && !REQUESTER */ + + subsystem_enter(); + SUBSYSTEM_USAGE_INCR; + + ptr = status; + + org_length = service_length; + + if (org_length) { + p = service_name + org_length - 1; + while (*p == ' ') + p--; + org_length = p - service_name + 1; + } + + for (n = 0; n < SUBSYSTEMS; n++) { + if (why_enabled && !(why_enabled & (1 << n))) + continue; + if (!CALL(PROC_SERVICE_ATTACH, n) (ptr, + org_length, + service_name, + handle, spb_length, spb)) + { + service = allocate_handle(n, (int*)*handle, HANDLE_service); + if (!service) + { + /* No memory. Make a half-hearted attempt to detach service. */ + + CALL(PROC_SERVICE_DETACH, n) (ptr, handle); + *handle = (SVC) NULL_PTR; + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + break; + } + + *handle = service; + service->cleanup = NULL; + status[0] = isc_arg_gds; + status[1] = 0; + if (status[2] != isc_arg_warning) + status[2] = isc_arg_end; + subsystem_exit(); + CHECK_STATUS_SUCCESS(status); + return status[1]; + } + if (ptr[1] != isc_unavailable) + ptr = temp; + } + + SUBSYSTEM_USAGE_DECR; + if (status[1] == isc_unavailable) + status[1] = isc_service_att_err; + return error(status, local); +} + + +STATUS API_ROUTINE GDS_SERVICE_DETACH(STATUS * user_status, SVC * handle) +{ +/************************************** + * + * i s c _ s e r v i c e _ d e t a c h + * + ************************************** + * + * Functional description + * Close down a service. + * + **************************************/ + STATUS local[20], *status; + SVC service; + CLEAN clean; + + GET_STATUS; + service = *handle; + CHECK_HANDLE(service, HANDLE_service, isc_bad_svc_handle); + subsystem_enter(); + + if (CALL(PROC_SERVICE_DETACH, service->implementation) (status, + &service->handle)) + return error(status, local); + + SUBSYSTEM_USAGE_DECR; + subsystem_exit(); + +/* Call the associated cleanup handlers */ + + while ((clean = service->cleanup) != NULL) { + service->cleanup = clean->clean_next; + (*clean->clean_routine) ((HNDL) handle, clean->clean_arg); + free_block(clean); + } + + release_handle(service); + *handle = NULL; + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_SERVICE_QUERY(STATUS * user_status, + SVC * handle, + ULONG * reserved, + USHORT send_item_length, + SCHAR * send_items, + USHORT recv_item_length, + SCHAR * recv_items, + USHORT buffer_length, SCHAR * buffer) +{ +/************************************** + * + * i s c _ s e r v i c e _ q u e r y + * + ************************************** + * + * Functional description + * Provide information on service object. + * + * NOTE: The parameter RESERVED must not be used + * for any purpose as there are networking issues + * involved (as with any handle that goes over the + * network). This parameter will be implemented at + * a later date. + **************************************/ + STATUS local[20], *status; + SVC service; + + GET_STATUS; + service = *handle; + CHECK_HANDLE(service, HANDLE_service, isc_bad_svc_handle); + subsystem_enter(); + + if (CALL(PROC_SERVICE_QUERY, service->implementation) (status, &service->handle, 0, /* reserved */ + send_item_length, + send_items, + recv_item_length, + recv_items, + buffer_length, + buffer)) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_SERVICE_START(STATUS * user_status, + SVC * handle, + ULONG * reserved, + USHORT spb_length, SCHAR * spb) +{ +/************************************** + * + * i s c _ s e r v i c e _ s t a r t + * + ************************************** + * + * Functional description + * Starts a service thread + * + * NOTE: The parameter RESERVED must not be used + * for any purpose as there are networking issues + * involved (as with any handle that goes over the + * network). This parameter will be implemented at + * a later date. + **************************************/ + STATUS local[20], *status; + SVC service; + + GET_STATUS; + service = *handle; + CHECK_HANDLE(service, HANDLE_service, isc_bad_svc_handle); + subsystem_enter(); + + if (CALL(PROC_SERVICE_START, service->implementation) (status, + &service->handle, + NULL, + spb_length, spb)) { + return error(status, local); + } + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_START_AND_SEND(STATUS * user_status, + REQ * req_handle, + TRA * tra_handle, + USHORT GDS_VAL(msg_type), + USHORT GDS_VAL(msg_length), + SCHAR * msg, SSHORT GDS_VAL(level)) +{ +/************************************** + * + * g d s _ $ s t a r t _ a n d _ s e n d + * + ************************************** + * + * Functional description + * Get a record from the host program. + * + **************************************/ + STATUS local[20], *status; + REQ request; + TRA transaction; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + transaction = find_transaction(request->parent, *tra_handle); + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + if (CALL(PROC_START_AND_SEND, request->implementation) (status, + &request->handle, + &transaction-> + handle, + GDS_VAL(msg_type), + GDS_VAL + (msg_length), msg, + GDS_VAL(level))) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_START(STATUS * user_status, + register REQ * req_handle, + register TRA * tra_handle, SSHORT GDS_VAL(level)) +{ +/************************************** + * + * g d s _ $ s t a r t + * + ************************************** + * + * Functional description + * Get a record from the host program. + * + **************************************/ + STATUS local[20], *status; + REQ request; + TRA transaction; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + transaction = find_transaction(request->parent, *tra_handle); + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + if (CALL(PROC_START, request->implementation) (status, + &request->handle, + &transaction->handle, + GDS_VAL(level))) + return error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_START_MULTIPLE(STATUS * user_status, + TRA * tra_handle, + USHORT GDS_VAL(count), TEB * vector) +{ +/************************************** + * + * g d s _ $ s t a r t _ m u l t i p l e + * + ************************************** + * + * Functional description + * Start a transaction. + * + **************************************/ + STATUS local[20], *status, temp[20], *s; + TRA transaction, sub, *ptr; + DBB database; + USHORT n; + + GET_STATUS; + NULL_CHECK(tra_handle, isc_bad_trans_handle, HANDLE_transaction); + transaction = NULL; + subsystem_enter(); + + for (n = 0, ptr = &transaction; n < GDS_VAL(count); + n++, ptr = &(*ptr)->next, vector++) { + database = *vector->teb_database; + if (!database || database->type != HANDLE_database) { + s = status; + *s++ = isc_arg_gds; + *s++ = isc_bad_db_handle; + *s = isc_arg_end; + return error(status, local); + } + if (CALL(PROC_START_TRANSACTION, database->implementation) (status, + ptr, + 1, + &database-> + handle, + vector-> + teb_tpb_length, + vector-> + teb_tpb)) + { + while (sub = transaction) { + transaction = sub->next; + CALL(PROC_ROLLBACK, sub->implementation) (temp, &sub->handle); + release_handle(sub); + } + return error(status, local); + } + + sub = allocate_handle( database->implementation, + (int*)*ptr, + HANDLE_transaction); + if (!sub) + { + /* No memory. Make a half-hearted attempt to rollback all sub-transactions. */ + + CALL(PROC_ROLLBACK, database->implementation) (temp, ptr); + *ptr = (TRA) NULL_PTR; + while (sub = transaction) { + transaction = sub->next; + CALL(PROC_ROLLBACK, sub->implementation) (temp, &sub->handle); + release_handle(sub); + } + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error(status, local); + } + + sub->parent = database; + *ptr = sub; + } + + if (transaction->next) + { + sub = allocate_handle(SUBSYSTEMS, (int*) NULL_PTR, HANDLE_transaction); + if (!sub) + { + /* No memory. Make a half-hearted attempt to rollback all sub-transactions. */ + + while (sub = transaction) { + transaction = sub->next; + CALL(PROC_ROLLBACK, sub->implementation) (temp, &sub->handle); + release_handle(sub); + } + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error(status, local); + } + + sub->next = transaction; + *tra_handle = sub; + } + else + *tra_handle = transaction; + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE_VARARG GDS_START_TRANSACTION(STATUS * user_status, + TRA * tra_handle, + SSHORT count, ...) +{ +/************************************** + * + * g d s _ $ s t a r t _ t r a n s a c t i o n + * + ************************************** + * + * Functional description + * Start a transaction. + * + **************************************/ + TEB tebs[16], *teb, *end; + STATUS status; + va_list ptr; + + if (GDS_VAL(count) <= sizeof(tebs) / sizeof(struct teb)) + teb = tebs; + else + teb = (TEB *) alloc((SLONG) (sizeof(struct teb) * GDS_VAL(count))); + + if (!teb) { + user_status[0] = isc_arg_gds; + user_status[1] = status = isc_virmemexh; + user_status[2] = isc_arg_end; + return status; + } + + end = teb + GDS_VAL(count); + VA_START(ptr, count); + + for (; teb < end; teb++) { + teb->teb_database = va_arg(ptr, ATT *); + teb->teb_tpb_length = va_arg(ptr, int); + teb->teb_tpb = va_arg(ptr, UCHAR *); + } + + teb = end - GDS_VAL(count); + + status = GDS_START_MULTIPLE(user_status, tra_handle, count, teb); + + if (teb != tebs) + free_block(teb); + + return status; +} + + +STATUS API_ROUTINE GDS_TRANSACT_REQUEST(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + USHORT blr_length, + SCHAR * blr, + USHORT in_msg_length, + SCHAR * in_msg, + USHORT out_msg_length, + SCHAR * out_msg) +{ +/************************************** + * + * i s c _ t r a n s a c t _ r e q u e s t + * + ************************************** + * + * Functional description + * Execute a procedure. + * + **************************************/ + STATUS local[20], *status; + ATT dbb; + TRA transaction; + + GET_STATUS; + dbb = *db_handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + transaction = *tra_handle; + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + if (CALL(PROC_TRANSACT_REQUEST, dbb->implementation) (status, + &dbb->handle, + &transaction-> + handle, blr_length, + blr, in_msg_length, + in_msg, + out_msg_length, + out_msg)) return + error(status, local); + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE gds__transaction_cleanup(STATUS * user_status, + TRA * tra_handle, + void (*routine) (), SLONG arg) +{ +/************************************** + * + * g d s _ $ t r a n s a c t i o n _ c l e a n u p + * + ************************************** + * + * Functional description + * Register a transaction specific cleanup handler. + * + **************************************/ + STATUS local[20], *status, *s; + TRA transaction; + CLEAN clean; + + GET_STATUS; + transaction = *tra_handle; + if (!transaction || transaction->type != HANDLE_transaction) { + s = status; + *s++ = isc_arg_gds; + *s++ = isc_bad_db_handle; + *s = isc_arg_end; + return error2(status, local); + } + +/* Only add the cleanup handler if the transaction doesn't already know + about it. */ + + for (clean = transaction->cleanup; clean; clean = clean->clean_next) + { + if (((void (*)())clean->clean_routine) == routine && clean->clean_arg == arg) + { + break; + } + } + + if (!clean) + { + if (clean = (CLEAN) alloc((SLONG) sizeof(struct clean))) + { +#ifdef DEBUG_GDS_ALLOC + /* If client doesn't commit/rollback/detach + or drop, this could be left unfreed. */ + + gds_alloc_flag_unfreed((void *) clean); +#endif + clean->clean_next = transaction->cleanup; + transaction->cleanup = clean; + clean->clean_routine = (void (*)(HNDL, long))routine; + clean->clean_arg = arg; + } + else { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + return error2(status, local); + } + } + + status[0] = gds_arg_gds; + status[1] = SUCCESS; + status[2] = gds_arg_end; + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +STATUS API_ROUTINE GDS_TRANSACTION_INFO(STATUS * user_status, + TRA * tra_handle, + SSHORT GDS_VAL(item_length), + SCHAR * items, + SSHORT GDS_VAL(buffer_length), + SCHAR * buffer) +{ +/************************************** + * + * g d s _ $ t r a n s a c t i o n _ i n f o + * + ************************************** + * + * Functional description + * Provide information on transaction object. + * + **************************************/ + STATUS local[20], *status; + TRA transaction, sub; + SCHAR *ptr, *end; + SSHORT buffer_len, item_len; + + GET_STATUS; + transaction = *tra_handle; + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + if (transaction->implementation != SUBSYSTEMS) { + if (CALL(PROC_TRANSACTION_INFO, transaction->implementation) (status, + &transaction-> + handle, + GDS_VAL + (item_length), + items, + GDS_VAL + (buffer_length), + buffer)) + return error(status, local); + } + else { + item_len = GDS_VAL(item_length); + buffer_len = GDS_VAL(buffer_length); + for (sub = transaction->next; sub; sub = sub->next) { + if (CALL(PROC_TRANSACTION_INFO, sub->implementation) (status, + &sub-> + handle, + item_len, + items, + buffer_len, + buffer)) + return error(status, local); + + ptr = buffer; + end = buffer + buffer_len; + while (ptr < end && *ptr == gds__info_tra_id) + ptr += 3 + gds__vax_integer((UCHAR*)(ptr + 1), 2); + + if (ptr >= end || *ptr != gds__info_end) { + RETURN_SUCCESS; + } + + buffer_len = end - ptr; + buffer = ptr; + } + } + + RETURN_SUCCESS; +} + + +STATUS API_ROUTINE GDS_UNWIND(STATUS * user_status, + REQ * req_handle, SSHORT GDS_VAL(level)) +{ +/************************************** + * + * g d s _ $ u n w i n d + * + ************************************** + * + * Functional description + * Unwind a running request. This is potentially nasty since it can be called + * asynchronously. + * + **************************************/ + STATUS local[20], *status; + REQ request; + + GET_STATUS; + request = *req_handle; + CHECK_HANDLE(request, HANDLE_request, isc_bad_req_handle); + subsystem_enter(); + + if (CALL(PROC_UNWIND, request->implementation) (status, + &request->handle, + GDS_VAL(level))) + return error(status, local); + + RETURN_SUCCESS; +} + + +static SCHAR *alloc(SLONG length) +{ +/************************************** + * + * a l l o c + * + ************************************** + * + * Functional description + * Allocate some memory. + * + **************************************/ + SCHAR *block; + + if (block = (SCHAR *) gds__alloc((SLONG) (sizeof(SCHAR) * length))) + memset(block, 0, length); + return block; +} + + +static HNDL allocate_handle(int implementation, + int* real_handle, + int handle_type) +{ +/************************************** + * + * a l l o c a t e _ h a n d l e + * + ************************************** + * + * Functional description + * Allocate an indirect handle. + * + **************************************/ + HNDL handle; + + if (handle = (HNDL) alloc((SLONG) sizeof(struct hndl))) + { + handle->implementation = implementation; + handle->handle = real_handle; + handle->type = handle_type; + +#ifdef DEBUG_GDS_ALLOC +/* As the memory for the handle is handed back to the client, InterBase + * cannot free the memory unless the client returns to us. As a result, + * the memory allocator might try to report this as unfreed, but it + * ain't our fault. So flag it to make the allocator be happy. + */ + gds_alloc_flag_unfreed((void *) handle); +#endif + } + + return handle; +} + + +static STATUS bad_handle(STATUS * user_status, STATUS code) +{ +/************************************** + * + * b a d _ h a n d l e + * + ************************************** + * + * Functional description + * Generate an error for a bad handle. + * + **************************************/ + STATUS *s, *status, local[20]; + + GET_STATUS; + s = status; + *s++ = isc_arg_gds; + *s++ = code; + *s = isc_arg_end; + + return error2(status, local); +} + + +#ifdef DEV_BUILD +static void check_status_vector(STATUS * status, STATUS expected) + { +/************************************** + * + * c h e c k _ s t a t u s _ v e c t o r + * + ************************************** + * + * Functional description + * Validate that a status vector looks valid. + * + **************************************/ + + STATUS *s, code; + ULONG length; + +#ifdef WINDOWS_ONLY +#define SV_MSG(x) { ib_fprintf (ib_stderr, "%s %d check_status_vector: %s\n", __FILE__, __LINE__, (x)); } +#else +#define SV_MSG(x) { ib_fprintf (ib_stderr, "%s %d check_status_vector: %s\n", __FILE__, __LINE__, (x)); BREAKPOINT (__LINE__); } +#endif + + s = status; + if (!s) { + SV_MSG("Invalid status vector"); + return; + } + + if (*s != gds_arg_gds) { + SV_MSG("Must start with gds_arg_gds"); + return; + } + +/* Vector [2] could either end the vector, or start a warning + in either case the status vector is a success */ + if ((expected == SUCCESS) + && (s[1] != SUCCESS + || (s[2] != gds_arg_end && s[2] != gds_arg_gds + && s[2] != + isc_arg_warning))) SV_MSG("Success vector expected"); + + while (*s != gds_arg_end) { + code = *s++; + switch (code) { + case isc_arg_warning: + case gds_arg_gds: + /* The next element must either be 0 (indicating no error) or a + * valid isc error message, let's check */ + if (*s && (*s & ISC_MASK) != ISC_MASK) { + if (code == isc_arg_warning) { + SV_MSG("warning code not a valid ISC message"); + } + else { + SV_MSG("error code not a valid ISC message"); + } + } + + /* If the error code is valid, then I better be able to retrieve a + * proper facility code from it ... let's find out */ + if (*s && (*s & ISC_MASK) == ISC_MASK) { + struct _facilities *facs; + int fac_code; + BOOLEAN found = 0; + + facs = (_facilities*) facilities; + fac_code = GET_FACILITY(*s); + while (facs->facility) { + if (facs->fac_code == fac_code) { + found = 1; + break; + } + facs++; + } + if (!found) + if (code == isc_arg_warning) { + SV_MSG + ("warning code does not contain a valid facility"); + } + else { + SV_MSG + ("error code does not contain a valid facility"); + } + } + s++; + break; + + case gds_arg_interpreted: + case gds_arg_string: + length = strlen((char *) *s); + /* This check is heuristic, not deterministic */ + if (length > 1024 - 1) + SV_MSG("suspect length value"); + if (*((UCHAR *) * s) == 0xCB) + SV_MSG("string in freed memory"); + s++; + break; + + case gds_arg_cstring: + length = (ULONG) * s; + s++; + /* This check is heuristic, not deterministic */ + /* Note: This can never happen anyway, as the length is coming + from a byte value */ + if (length > 1024 - 1) + SV_MSG("suspect length value"); + if (*((UCHAR *) * s) == 0xCB) + SV_MSG("string in freed memory"); + s++; + break; + + case gds_arg_number: + case gds_arg_vms: + case gds_arg_unix: + case gds_arg_domain: + case gds_arg_dos: + case gds_arg_mpexl: + case gds_arg_mpexl_ipc: + case gds_arg_next_mach: + case gds_arg_netware: + case gds_arg_win32: + s++; + break; + + default: + SV_MSG("invalid status code"); + return; + } + if ((s - status) >= 20) + SV_MSG("vector too long"); + } + +#undef SV_MSG + +} +#endif + + +static STATUS error(STATUS * user_status, STATUS * local) +{ +/************************************** + * + * e r r o r + * + ************************************** + * + * Functional description + * An error returned has been trapped. If the user specified + * a status vector, return a status code. Otherwise print the + * error code(s) and abort. + * + **************************************/ + + subsystem_exit(); + + return error2(user_status, local); +} + + +static STATUS error2(STATUS * user_status, STATUS * local) +{ +/************************************** + * + * e r r o r 2 + * + ************************************** + * + * Functional description + * An error returned has been trapped. If the user specified + * a status vector, return a status code. Otherwise print the + * error code(s) and abort. + * + **************************************/ + + CHECK_STATUS(user_status); + +#ifdef SUPERSERVER + return user_status[1]; +#else + if (user_status != local) + return user_status[1]; + + gds__print_status(user_status); + exit((int) user_status[1]); + + return SUCCESS; +#endif +} + + +#ifndef REQUESTER +static void event_ast(UCHAR * buffer, USHORT length, UCHAR * items) +{ +/************************************** + * + * e v e n t _ a s t + * + ************************************** + * + * Functional description + * We're had an event complete. + * + **************************************/ + + while (length--) + *buffer++ = *items++; + ISC_event_post(why_event); +} +#endif + + +#ifndef REQUESTER +static void exit_handler(EVENT why_event) +{ +/************************************** + * + * e x i t _ h a n d l e r + * + ************************************** + * + * Functional description + * Cleanup shared image. + * + **************************************/ + +#ifdef WIN_NT + CloseHandle((void *) why_event->event_handle); +#endif + + why_initialized = FALSE; + why_enabled = 0; +#if !(defined REQUESTER || defined PIPE_CLIENT || defined SUPERCLIENT || defined SUPERSERVER) + isc_enter_count = 0; + subsystem_usage = 0; + subsystem_FPE_reset = FPE_RESET_INIT_ONLY; +#endif +} +#endif + + +static TRA find_transaction(DBB dbb, TRA transaction) +{ +/************************************** + * + * f i n d _ t r a n s a c t i o n + * + ************************************** + * + * Functional description + * Find the element of a possible multiple database transaction + * that corresponds to the current database. + * + **************************************/ + + for (; transaction; transaction = transaction->next) + if (transaction->parent == dbb) + return transaction; + + return NULL; +} + + +static void free_block(void* block) +{ +/************************************** + * + * f r e e _ b l o c k + * + ************************************** + * + * Functional description + * Release some memory. + * + **************************************/ + + gds__free((SLONG *) block); +} + + +static int get_database_info(STATUS * status, TRA transaction, UCHAR ** ptr) +{ +/************************************** + * + * g e t _ d a t a b a s e _ i n f o + * + ************************************** + * + * Functional description + * Get the full database pathname + * and put it in the transaction + * description record. + * + **************************************/ + UCHAR *p, *q; + DBB database; + + p = *ptr; + + database = transaction->parent; + q = (UCHAR *) database->db_path; + *p++ = TDR_DATABASE_PATH; + *p++ = (UCHAR) strlen((SCHAR *) q); + while (*q) + *p++ = *q++; + + *ptr = p; + + return SUCCESS; +} + + +static PTR get_entrypoint(int proc, int implementation) +{ +/************************************** + * + * g e t _ e n t r y p o i n t + * + ************************************** + * + * Functional description + * Lookup entrypoint for procedure. + * + **************************************/ + + ENTRY *ent; + PTR entrypoint; + +#if !defined(PIPE_CLIENT) && !defined(SUPERCLIENT) + TEXT *image, *name; +#endif + + ent = (ENTRY*)entrypoints + implementation * PROC_count + proc; + entrypoint = ent->address; + + if (entrypoint) + { + return entrypoint; + } + +#ifndef PIPE_CLIENT +#ifndef SUPERCLIENT +#ifdef INITIALIZE_PATHS + if (!paths_initialized) + { + paths_initialized = TRUE; + init_paths(); + } +#endif + + image = images[implementation].path; + name = ent->name; + if (!name) + { + name = (TEXT*) generic[proc]; + } + + if (image && name) + { + entrypoint = (PTR) ISC_lookup_entrypoint(image, name, NULL); + if (entrypoint) + { + ent->address = entrypoint; + return entrypoint; + } + } +#endif +#endif + + return &no_entrypoint; +} + + +static SCHAR *get_sqlda_buffer(SCHAR * buffer, + USHORT local_buffer_length, + XSQLDA * sqlda, + USHORT dialect, USHORT * buffer_length) +{ +/************************************** + * + * g e t _ s q l d a _ b u f f e r + * + ************************************** + * + * Functional description + * Get a buffer that is large enough to store + * the info items relating to an SQLDA. + * + **************************************/ + USHORT n_variables; + SLONG length; + USHORT sql_dialect; + +/* If dialect / 10 == 0, then it has not been combined with the + parser version for a prepare statement. If it has been combined, then + the dialect needs to be pulled out to compare to DIALECT_xsqlda +*/ + + if ((sql_dialect = dialect / 10) == 0) + sql_dialect = dialect; + + if (!sqlda) + n_variables = 0; + else if (sql_dialect >= DIALECT_xsqlda) + n_variables = sqlda->sqln; + else + n_variables = ((SQLDA *) sqlda)->sqln; + + length = 32 + n_variables * 172; + *buffer_length = (USHORT)((length > 65500L) ? 65500L : length); + if (*buffer_length > local_buffer_length) + buffer = alloc((SLONG) * buffer_length); + + return buffer; +} + + +static STATUS get_transaction_info(STATUS * status, + TRA transaction, UCHAR ** ptr) +{ +/************************************** + * + * g e t _ t r a n s a c t i o n _ i n f o + * + ************************************** + * + * Functional description + * Put a transaction's id into the transaction + * description record. + * + **************************************/ + UCHAR *p, *q, buffer[16]; + USHORT length; + + p = *ptr; + + if (CALL(PROC_TRANSACTION_INFO, transaction->implementation) (status, + &transaction-> + handle, + sizeof + (prepare_tr_info), + prepare_tr_info, + sizeof + (buffer), + buffer)) { + CHECK_STATUS(status); + return status[1]; + } + + q = buffer + 3; + *p++ = TDR_TRANSACTION_ID; + + length = (USHORT)gds__vax_integer(buffer + 1, 2); + *p++ = length; + if (length) { + do { + *p++ = *q++; + } while (--length); + } + + *ptr = p; + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +static void iterative_sql_info(STATUS * user_status, + STMT * stmt_handle, + SSHORT item_length, + SCHAR * items, + SSHORT buffer_length, + SCHAR * buffer, USHORT dialect, XSQLDA * sqlda) +{ +/************************************** + * + * i t e r a t i v e _ s q l _ i n f o + * + ************************************** + * + * Functional description + * Turn an sql info buffer into an SQLDA. If the info + * buffer was incomplete, make another request, beginning + * where the previous info call left off. + * + **************************************/ + USHORT last_index; + SCHAR new_items[32], *p; + + while (UTLD_parse_sql_info( user_status, + dialect, + buffer, + sqlda, + &last_index) && last_index) + { + p = new_items; + *p++ = gds__info_sql_sqlda_start; + *p++ = 2; + *p++ = last_index; + *p++ = last_index >> 8; + memcpy(p, items, (int) item_length); + p += item_length; + if (GDS_DSQL_SQL_INFO( user_status, + stmt_handle, + (SSHORT) (p - new_items), + new_items, + buffer_length, + buffer)) + { + break; + } + } +} + + +#ifdef INITIALIZE_PATHS +static void init_paths(void) +{ +/************************************** + * + * i n i t _ p a t h s + * + ************************************** + * + * Functional description + * Initialize the paths to use in dynamically + * looking up entrypoints. + * + **************************************/ + USHORT n; + IMAGE *sys; +#ifdef STACK_EFFICIENT + TEXT *path; +#else + TEXT path[MAXPATHLEN]; +#endif /* STACK_EFFICIENT */ + +#ifdef STACK_EFFICIENT + if (path = (TEXT *) gds__alloc((SLONG) (sizeof(TEXT) * MAXPATHLEN))) +/* if we fail don't try to do the remainder of the function since*/ +/* we will probably die a horrible death in gds_prefix */ +#endif /* STACK_EFFICIENT */ + for (n = 0, sys = images; n < SUBSYSTEMS; n++, sys++) + if (sys->path) { + gds__prefix(path, sys->path); + sys->path = alloc((SLONG) (strlen(path) + 1)); + strcpy(sys->path, path); + } +#ifdef STACK_EFFICIENT + if (path) + gds__free((SLONG *) path); +#endif /* STACK_EFFICIENT */ +} +#endif + + +static STATUS open_blob(STATUS * user_status, + ATT * db_handle, + TRA * tra_handle, + BLB * blob_handle, + SLONG * blob_id, + USHORT bpb_length, + UCHAR * bpb, SSHORT proc, SSHORT proc2) +{ +/************************************** + * + * o p e n _ b l o b + * + ************************************** + * + * Functional description + * Open an existing blob (extended edition). + * + **************************************/ + STATUS local[20], *status; + TRA transaction; + ATT dbb; + BLB blob; + SSHORT from, to; + USHORT flags; + + GET_STATUS; + NULL_CHECK(blob_handle, isc_bad_segstr_handle, HANDLE_blob); + + dbb = *db_handle; + CHECK_HANDLE(dbb, HANDLE_database, isc_bad_db_handle); + transaction = find_transaction(dbb, *tra_handle); + CHECK_HANDLE(transaction, HANDLE_transaction, isc_bad_trans_handle); + subsystem_enter(); + + flags = 0; + gds__parse_bpb(bpb_length, bpb, (USHORT*)&from, (USHORT*)&to); + + if (get_entrypoint(proc2, dbb->implementation) != no_entrypoint && + CALL(proc2, dbb->implementation) (status, + &dbb->handle, + &transaction->handle, + blob_handle, + blob_id, + bpb_length, + bpb) != isc_unavailable) flags = 0; + else if (!to || from == to) + CALL(proc, dbb->implementation) (status, + &dbb->handle, + &transaction->handle, + blob_handle, blob_id); + + if (status[1]) { + return error(status, local); + } + + blob = allocate_handle(dbb->implementation, (int*)*blob_handle, HANDLE_blob); + if (!blob) + { + /* No memory. Make a half-hearted attempt to cancel the blob. */ + + CALL(PROC_CANCEL_BLOB, dbb->implementation) (status, blob_handle); + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + *blob_handle = (BLB) NULL_PTR; + return error(status, local); + } + + *blob_handle = blob; + blob->flags |= flags; + blob->parent = dbb; + blob->next = dbb->blobs; + dbb->blobs = blob; + + RETURN_SUCCESS; +} + + +#ifdef UNIX +static STATUS open_marker_file(STATUS * status, + TEXT * expanded_filename, TEXT * single_user) +{ +/************************************* + * + * o p e n _ m a r k e r _ f i l e + * + ************************************* + * + * Functional description + * Try to open a marker file. If one is + * found, open it, read the absolute path + * to the NFS mounted database, lockf() + * the marker file to ensure single user + * access to the db and write the open marker + * file descriptor into the marker file so + * that the file can be closed in + * close_marker_file located in unix.c. + * Return FAILURE if a marker file exists + * but something goes wrong. Return SUCCESS + * otherwise. + * + *************************************/ + int fd, length, i, j; + TEXT marker_filename[MAXPATHLEN], marker_contents[MAXPATHLEN], + fildes_str[5], *p; + TEXT *err_routine, buffer[80]; + SLONG bytes, size; + +/* Create the marker file name and see if it exists. If not, + don't sweat it. */ + + strcpy(marker_filename, expanded_filename); + strcat(marker_filename, "_m"); + if (access(marker_filename, F_OK)) /* Marker file doesn't exist. */ + return SUCCESS; + +/* Ensure that writes are ok on the marker file for lockf(). */ + + if (!access(marker_filename, W_OK)) { + for (i = 0; i < IO_RETRY; i++) { + if ((fd = open(marker_filename, O_RDWR)) == -1) { + sprintf(buffer, + "Couldn't open marker file %s\n", marker_filename); + gds__log(buffer); + err_routine = "open"; + break; + } + + /* Place an advisory lock on the marker file. */ + #ifdef DARWIN + if (flock(fd, LOCK_EX ) != -1) { + #else + if (lockf(fd, F_TLOCK, 0) != -1) { + #endif + size = sizeof(marker_contents); + for (j = 0; j < IO_RETRY; j++) { + if ((bytes = read(fd, marker_contents, size)) != -1) + break; + + if ((bytes == -1) && (!SYSCALL_INTERRUPTED(errno))) { + err_routine = "read"; + close(fd); + fd = -1; + } + } /* for (j < IO_RETRY ) */ + + p = strchr(marker_contents, '\n'); + *p = 0; + if (strcmp(expanded_filename, marker_contents)) + close(fd); + else { + sprintf(fildes_str, "%d\n", fd); + strcpy(single_user, "YES"); + size = strlen(fildes_str); + for (j = 0; j < IO_RETRY; j++) { + if (lseek(fd, LSEEK_OFFSET_CAST 0L, SEEK_END) == -1) { + err_routine = "lseek"; + close(fd); + fd = -1; + } + + if ((bytes = write(fd, fildes_str, size)) == size) + break; + + if ((bytes == -1) && (!SYSCALL_INTERRUPTED(errno))) { + err_routine = "write"; + close(fd); + fd = -1; + } + } /* for (j < IO_RETRY ) */ + } + } + else + { /* Else couldn't lockf(). */ + + sprintf(buffer, + "Marker file %s already opened by another user\n", + marker_filename); + gds__log(buffer); + close(fd); + fd = -1; + } + + if (!SYSCALL_INTERRUPTED(errno)) + { + break; + } + } /* for (i < IO_RETRY ) */ + } /* if (access (...)) */ + else + { /* Else the marker file exists, but can't write to it. */ + + sprintf(buffer, + "Must have write permission on marker file %s\n", + marker_filename); + gds__log(buffer); + err_routine = "access"; + fd = -1; + } + + if (fd != -1) + return SUCCESS; + +/* The following code saves the name of the offending marker + file in a (sort of) permanent location. It is totally specific + because this is the only dynamic string being returned in + a status vector in this entire module. Since the marker + feature will almost never be used, it's not worth saving the + information in a more general way. */ + + if (marker_failures_ptr + strlen(marker_filename) + 1 > + marker_failures + sizeof(marker_failures) - 1) + marker_failures_ptr = marker_failures; + + *status++ = isc_arg_gds; + *status++ = isc_io_error; + *status++ = isc_arg_string; + *status++ = (STATUS) err_routine; + *status++ = isc_arg_string; + *status++ = (STATUS) marker_failures_ptr; + *status++ = isc_arg_unix; + *status++ = errno; + *status = isc_arg_end; + + strcpy(marker_failures_ptr, marker_filename); + marker_failures_ptr += strlen(marker_filename) + 1; + + return FAILURE; +} +#endif + + +static STATUS no_entrypoint(STATUS * user_status) +{ +/************************************** + * + * n o _ e n t r y p o i n t + * + ************************************** + * + * Functional description + * No_entrypoint is called if there is not entrypoint for a given routine. + * + **************************************/ + + *user_status++ = isc_arg_gds; + *user_status++ = isc_unavailable; + *user_status = isc_arg_end; + + return isc_unavailable; +} + + +static STATUS prepare(STATUS * status, TRA transaction) +{ +/************************************** + * + * p r e p a r e + * + ************************************** + * + * Functional description + * Perform the first phase of a two-phase commit + * for a multi-database transaction. + * + **************************************/ + TRA sub; + UCHAR *p, *description; +#ifdef PC_PLATFORM + UCHAR tdr_buffer[256]; +#else + UCHAR tdr_buffer[1024]; +#endif + USHORT length = 0; + + for (sub = transaction->next; sub; sub = sub->next) + length += 256; + + description = + (length > + sizeof(tdr_buffer)) ? (UCHAR *) gds__alloc((SLONG) length) : + tdr_buffer; + +/* build a transaction description record containing + the host site and database/transaction + information for the target databases. */ + + if (!(p = description)) { + status[0] = isc_arg_gds; + status[1] = isc_virmemexh; + status[2] = isc_arg_end; + CHECK_STATUS(status); + return status[1]; + } + *p++ = TDR_VERSION; + + ISC_get_host((TEXT*)(p + 2), length - 16); + *p++ = TDR_HOST_SITE; + *p = (UCHAR) strlen((SCHAR *) p + 1); + + while (*++p); + +/* Get database and transaction stuff for each sub-transaction */ + + for (sub = transaction->next; sub; sub = sub->next) { + get_database_info(status, sub, &p); + get_transaction_info(status, sub, &p); + } + +/* So far so good -- prepare each sub-transaction */ + + length = p - description; + + for (sub = transaction->next; sub; sub = sub->next) + if (CALL(PROC_PREPARE, sub->implementation) (status, + &sub->handle, + length, description)) + { + if (description != tdr_buffer) { + free_block(description); + } + CHECK_STATUS(status); + return status[1]; + } + + if (description != tdr_buffer) + free_block(description); + + CHECK_STATUS_SUCCESS(status); + return SUCCESS; +} + + +static void why_priv_gds__free_if_set(void* pMem) +{ + if (pMem) { + gds__free(pMem); + } +} + +static void release_dsql_support(DASUP dasup) +{ +/************************************** + * + * r e l e a s e _ d s q l _ s u p p o r t + * + ************************************** + * + * Functional description + * Release some memory. + * + **************************************/ + + struct dasup::dasup_clause* pClauses; + + if (!dasup) { + return; + } + + /* for C++, add "dasup::" before "dasup_clause" */ + pClauses = dasup->dasup_clauses; + + why_priv_gds__free_if_set(pClauses[DASUP_CLAUSE_bind].dasup_blr); + why_priv_gds__free_if_set(pClauses[DASUP_CLAUSE_select].dasup_blr); + why_priv_gds__free_if_set(pClauses[DASUP_CLAUSE_bind].dasup_msg); + why_priv_gds__free_if_set(pClauses[DASUP_CLAUSE_select].dasup_msg); + free_block(dasup); +} + + +static void release_handle(HNDL handle) +{ +/************************************** + * + * r e l e a s e _ h a n d l e + * + ************************************** + * + * Functional description + * Release unused and unloved handle. + * + **************************************/ + + handle->type = HANDLE_invalid; + free_block(handle); +} + + +static void save_error_string(STATUS * status) +{ +/************************************** + * + * s a v e _ e r r o r _ s t r i n g + * + ************************************** + * + * Functional description + * This is need because there are cases + * where the memory allocated for strings + * in the status vector is freed prior to + * surfacing them to the user. This is an + * attempt to save off 1 string to surface to + * the user. Any other strings will be set to + * a standard string. + * + **************************************/ + TEXT *p; + ULONG l, len; + + assert(status != NULL); + + p = glbstr1; + len = sizeof(glbstr1) - 1; + + while (*status != isc_arg_end) + { + switch (*status++) + { + case isc_arg_cstring: + l = (ULONG) * status; + if (l < len) + { + status++; /* Length is unchanged */ + /* + * This strncpy should really be a memcpy + */ + strncpy(p, (char*) * status, l); + *status++ = (STATUS) p; /* string in static memory */ + p += l; + len -= l; + } + else { + *status++ = (STATUS) strlen(glbunknown); + *status++ = (STATUS) glbunknown; + } + break; + + case isc_arg_interpreted: + case isc_arg_string: + l = (ULONG) strlen((char *) * status) + 1; + if (l < len) + { + strncpy(p, (char *) * status, l); + *status++ = (STATUS) p; /* string in static memory */ + p += l; + len -= l; + } + else + { + *status++ = (STATUS) glbunknown; + } + break; + + default: + assert(FALSE); + case isc_arg_gds: + case isc_arg_number: + case isc_arg_vms: + case isc_arg_unix: + case isc_arg_domain: + case isc_arg_dos: + case isc_arg_mpexl: + case isc_arg_mpexl_ipc: + case isc_arg_next_mach: + case isc_arg_netware: + case isc_arg_win32: + status++; /* Skip parameter */ + break; + } + } +} + + +static void subsystem_enter(void) +{ +/************************************** + * + * s u b s y s t e m _ e n t e r + * + ************************************** + * + * Functional description + * Enter subsystem. + * + **************************************/ + + THREAD_ENTER; +#if !(defined REQUESTER || defined PIPE_CLIENT || defined SUPERCLIENT || defined SUPERSERVER) + isc_enter_count++; + if (subsystem_usage == 0 || + (subsystem_FPE_reset & + (FPE_RESET_NEXT_API_CALL | FPE_RESET_ALL_API_CALL))) + { + ISC_enter(); + subsystem_FPE_reset &= ~FPE_RESET_NEXT_API_CALL; + } +#endif + +#ifdef DEBUG_FPE_HANDLING + { +/* It's difficult to make a FPE to occur inside the engine - for debugging + * just force one to occur every-so-often. */ + static ULONG counter = 0; + if (((counter++) % 10) == 0) + { + ib_fprintf(ib_stderr, "Forcing FPE to occur within engine\n"); + (void) kill(getpid(), SIGFPE); + } + } +#endif /* DEBUG_FPE_HANDLING */ +} + + +static void subsystem_exit(void) +{ +/************************************** + * + * s u b s y s t e m _ e x i t + * + ************************************** + * + * Functional description + * Exit subsystem. + * + **************************************/ + +#if !(defined REQUESTER || defined PIPE_CLIENT || defined SUPERCLIENT || defined SUPERSERVER) + if (subsystem_usage == 0 || + (subsystem_FPE_reset & + (FPE_RESET_NEXT_API_CALL | FPE_RESET_ALL_API_CALL))) + { + ISC_exit(); + } + isc_enter_count--; +#endif + THREAD_EXIT; +} + + +#if defined (SERVER_SHUTDOWN) && !defined (SUPERCLIENT) && !defined (REQUESTER) +BOOLEAN WHY_set_shutdown(BOOLEAN flag) +{ +/************************************** + * + * W H Y _ s e t _ s h u t d o w n + * + ************************************** + * + * Functional description + * Set shutdown_flag to either TRUE or FALSE. + * TRUE = accept new connections + * FALSE= refuse new connections + * Returns the prior state of the flag (server). + * + **************************************/ + + BOOLEAN old_flag; + old_flag = shutdown_flag; + shutdown_flag = flag; + return old_flag; +} + +BOOLEAN WHY_get_shutdown() +{ +/************************************** + * + * W H Y _ g e t _ s h u t d o w n + * + ************************************** + * + * Functional description + * Returns the current value of shutdown_flag. + * + **************************************/ + + return shutdown_flag; +} +#endif /* SERVER_SHUTDOWN && !SUPERCLIENT && !REQUESTER */ + + +} // extern "C" \ No newline at end of file diff --git a/src/lock/lock.cpp b/src/lock/lock.cpp index 123fa0b3b2..cb775f101f 100644 --- a/src/lock/lock.cpp +++ b/src/lock/lock.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: lock.cpp,v 1.3 2001-07-29 23:43:22 skywalker Exp $ +$Id: lock.cpp,v 1.4 2001-12-24 02:50:52 tamlin Exp $ */ #include "firebird.h" diff --git a/src/lock/print.cpp b/src/lock/print.cpp index 729e2d036f..f3371e2c46 100644 --- a/src/lock/print.cpp +++ b/src/lock/print.cpp @@ -62,7 +62,7 @@ #ifdef NETWARE_386 #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../jrd/svc.h" #include "../jrd/svc_proto.h" diff --git a/src/make.defaults b/src/make.defaults new file mode 100644 index 0000000000..5633797959 --- /dev/null +++ b/src/make.defaults @@ -0,0 +1,187 @@ +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# Alternatively, the contents of this file may be used under the +# terms of the GNU General Public License Version 2 or later (the +# "GPL"), in which case the provisions of the GPL are applicable +# instead of those above. You may obtain a copy of the Licence at +# http://www.gnu.org/copyleft/gpl.html +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Relevant for more details. +# +# This file was created by members of the firebird development team. +# All individual contributions remain the Copyright (C) of those +# individuals. Contributors to this file are either listed here or +# can be obtained from a CVS history command. +# +# All rights reserved. +# +# Created by: Mark O'Donohue +# +# Contributor(s): +# +# +# $Id: make.defaults,v 1.1 2001-12-24 02:50:47 tamlin Exp $ +# + + +#_____________________________________________________________________________ + + + +# This file contains default values that are used by the build process do not +# change these here, but override them in the platform specific file +# prefix.xxx where xxx is the platform name using the form SH := bash +# see the readme file with the Makefile.in files for more details. + + + +#_____________________________________________________________________________ + + +RealFirebirdPath = $(shell cd $(FIREBIRD); pwd) + + +FirebirdInstallPrefix = /usr/local/firebird +CpuType=powerpc +FirebirdVersion=2.0.0 +PackageVersion=0a.Dev1 + + +ArchType=classic +ifeq ($(ArchType),classic) + ArchPrefix=CS +else + ArchPrefix=SS +endif + +SharedLibraryName=libgds.so.2.0.0 +SharedLibrarySoName=libgds.so.2 +SharedLibraryBaseName=libgds.so + + + +# Default programs and tools to be used in the build process + +SH= sh -c +RM= rm -f +CHMOD= chmod +CHMOD_6= chmod 666 +CHMOD_7= chmod 777 +CHMOD_S7= chmod 06777 +MV= mv -f +TOUCH= touch +CP= cp +ECHO= echo +QUIET_ECHO= @echo +CD= cd +CAT= cat +AR= ar crsu +LN= ln -s +RANLIB= ranlib + +# Default extensions + +ARCH_EXT= .a +EXEC_EXT= +# FSG 1.Dez.2000 +#SHRLIB_EXT= .so + + +#_____________________________________________________________________________ + + +# From jrd + +JRD_BOOT= $(LIB)/jrd_boot.a + + + +LIBGDS_SO = $(LIB)/$(SharedLibraryName) +LIBGDS_SO_X_LNK = $(LIB)/$(SharedLibrarySoName) +LIBGDS_SO_LNK = $(LIB)/$(SharedLibraryBaseName) + +LIBGDS_A = $(LIB)/libgds.a + + +ifdef UseSharedLibraries + LIBGDS_LA = $(LIBGDS_SO) + LIBGDS_DEP = +# LIBGDS_LINK = $(LIBGDS_SO) + LIBGDS_LINK = + LINK_LIBS := -L$(LIB) -lgds $(LINK_LIBS) + +# LIBGDS_LINK_OPTIONS = -soname libgds.so -rpath /usr/lib +# LIBGDS_LINK_OPTIONS = -Wl,-soname,$(SharedLibrarySoName) -Wl,-rpath,$(FirebirdInstallPrefix)/lib + LIBGDS_LINK_OPTIONS = -Wl,-soname,$(SharedLibrarySoName) -Wl,-rpath,/usr/lib +else + LIBGDS_LA = $(LIBGDS_A) + LIBGDS_DEP = $(LIBGDS_LA) + LIBGDS_LINK = + LIBGDS_LINK_OPTIONS = +endif + + + + +# From utilities +CREATE_DB = $(BIN)/create_db$(EXEC_EXT) +GDS_DROP = $(BIN)/gds_drop$(EXEC_EXT) +GSTAT = $(BIN)/gstat$(EXEC_EXT) +GSEC = $(BIN)/gsec$(EXEC_EXT) +GDS_REBUILD = $(BIN)/gds_rebuild$(EXEC_EXT) +GDS_RELAY = $(BIN)/gds_relay$(EXEC_EXT) +GDS_INSTALL = $(BIN)/gds_install$(EXEC_EXT) +GDS_INSTALL = $(BIN)/gds_install_service$(EXEC_EXT) +IBGUARD = $(BIN)/ibguard$(EXEC_EXT) +IBMGR_BIN = $(BIN)/ibmgr.bin$(EXEC_EXT) +ISC_GDB = $(FIREBIRD)/isc4.gdb +ISC_GBAK = $(BIN)/isc4.gbak + +# From qli +QLI = $(BIN)/qli$(EXEC_EXT) + +# From isql +ISQL = $(BIN)/isql$(EXEC_EXT) +MUISQL = $(BIN)/muisql$(EXEC_EXT) + +# From burp +GBAK_STATIC = $(BIN)/gbak_static$(EXEC_EXT) +GBAK = $(BIN)/gbak$(EXEC_EXT) + +# From gpre +# (gpre current is a link to one of the others) +GPRE_BOOT = $(BIN)/gpre_boot$(EXEC_EXT) +GPRE_STATIC = $(BIN)/gpre_static$(EXEC_EXT) +GPRE = $(BIN)/gpre$(EXEC_EXT) +GPRE_CURRENT = $(BIN)/gpre_current$(EXEC_EXT) + + +# From msgs +CHECK_MESSAGES = $(BIN)/check_messages$(EXEC_EXT) +BUILD_FILE = $(BIN)/build_file$(EXEC_EXT) +INTERBASE_MSG = $(FIREBIRD)/interbase.msg + +ENTER_MESSAGES = $(BIN)/enter_messages$(EXEC_EXT) +MODIFY_MESSAGES = $(BIN)/modify_messages$(EXEC_EXT) +CHANGE_MESSAGES = $(BIN)/change_messages$(EXEC_EXT) + +fr_FR_MSG = $(FIREBIRD)/fr_FR.msg +de_DE_MSG = $(FIREBIRD)/de_DE.msg +ja_JA_MSG = $(FIREBIRD)/ja_JA.msg + + +# From intl +LIBGDSINTL_LA = $(FIREBIRD)/intl/libgdsintl.so + + + + + + + diff --git a/src/make.new/Makefile.in.alice b/src/make.new/Makefile.in.alice index 724b129474..7cc652ab36 100644 --- a/src/make.new/Makefile.in.alice +++ b/src/make.new/Makefile.in.alice @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.alice,v 1.5 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.alice,v 1.6 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.burp b/src/make.new/Makefile.in.burp index a60cc7c480..60aafac047 100644 --- a/src/make.new/Makefile.in.burp +++ b/src/make.new/Makefile.in.burp @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.burp,v 1.5 2001-08-21 09:41:00 skywalker Exp $ +# $Id: Makefile.in.burp,v 1.6 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.client b/src/make.new/Makefile.in.client index 2122d5b69e..ddc2f0ede7 100644 --- a/src/make.new/Makefile.in.client +++ b/src/make.new/Makefile.in.client @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.client,v 1.1 2001-07-29 23:43:23 skywalker Exp $ +# $Id: Makefile.in.client,v 1.2 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.dsql b/src/make.new/Makefile.in.dsql index 9e18f15188..9d9b8cc21a 100644 --- a/src/make.new/Makefile.in.dsql +++ b/src/make.new/Makefile.in.dsql @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.dsql,v 1.4 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.dsql,v 1.5 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.dudley b/src/make.new/Makefile.in.dudley index 4a7b6c57ad..501935fd4c 100644 --- a/src/make.new/Makefile.in.dudley +++ b/src/make.new/Makefile.in.dudley @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.dudley,v 1.5 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.dudley,v 1.6 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.example5 b/src/make.new/Makefile.in.example5 index 9b381b027e..62b8a5e25f 100644 --- a/src/make.new/Makefile.in.example5 +++ b/src/make.new/Makefile.in.example5 @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.example5,v 1.2 2001-08-07 02:15:26 bellardo Exp $ +# $Id: Makefile.in.example5,v 1.3 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.extlib b/src/make.new/Makefile.in.extlib index 435fbf669e..71bb5f4948 100644 --- a/src/make.new/Makefile.in.extlib +++ b/src/make.new/Makefile.in.extlib @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.extlib,v 1.3 2001-10-17 22:48:01 bellardo Exp $ +# $Id: Makefile.in.extlib,v 1.4 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.fbutil b/src/make.new/Makefile.in.fbutil index 55825a06f1..2b8b9e47ae 100755 --- a/src/make.new/Makefile.in.fbutil +++ b/src/make.new/Makefile.in.fbutil @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.fbutil,v 1.6 2001-08-27 15:29:18 skywalker Exp $ +# $Id: Makefile.in.fbutil,v 1.7 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.firebird b/src/make.new/Makefile.in.firebird index ea56526493..746ce72d95 100644 --- a/src/make.new/Makefile.in.firebird +++ b/src/make.new/Makefile.in.firebird @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.firebird,v 1.10 2001-08-27 15:29:18 skywalker Exp $ +# $Id: Makefile.in.firebird,v 1.11 2001-12-24 02:50:52 tamlin Exp $ # ROOT=.. diff --git a/src/make.new/Makefile.in.gpre b/src/make.new/Makefile.in.gpre index 067534d201..1ad0b01098 100644 --- a/src/make.new/Makefile.in.gpre +++ b/src/make.new/Makefile.in.gpre @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.gpre,v 1.7 2001-08-21 09:41:00 skywalker Exp $ +# $Id: Makefile.in.gpre,v 1.8 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.install b/src/make.new/Makefile.in.install index f025f5d0d6..00813321e6 100644 --- a/src/make.new/Makefile.in.install +++ b/src/make.new/Makefile.in.install @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.install,v 1.1 2001-08-27 15:29:18 skywalker Exp $ +# $Id: Makefile.in.install,v 1.2 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.intl b/src/make.new/Makefile.in.intl index cd007a0127..527d99db03 100644 --- a/src/make.new/Makefile.in.intl +++ b/src/make.new/Makefile.in.intl @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.intl,v 1.5 2001-10-17 22:48:01 bellardo Exp $ +# $Id: Makefile.in.intl,v 1.6 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.isql b/src/make.new/Makefile.in.isql index be49f9681d..d47e5d41e5 100644 --- a/src/make.new/Makefile.in.isql +++ b/src/make.new/Makefile.in.isql @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.isql,v 1.4 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.isql,v 1.5 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.jrd b/src/make.new/Makefile.in.jrd index de014460db..acdbbcc816 100644 --- a/src/make.new/Makefile.in.jrd +++ b/src/make.new/Makefile.in.jrd @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.jrd,v 1.8 2001-08-27 15:29:18 skywalker Exp $ +# $Id: Makefile.in.jrd,v 1.9 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.lock b/src/make.new/Makefile.in.lock index 082cd7cf7f..7058c702f2 100644 --- a/src/make.new/Makefile.in.lock +++ b/src/make.new/Makefile.in.lock @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.lock,v 1.6 2001-08-21 09:41:00 skywalker Exp $ +# $Id: Makefile.in.lock,v 1.7 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.msgs b/src/make.new/Makefile.in.msgs index a374e33cd8..c0abdc94ad 100644 --- a/src/make.new/Makefile.in.msgs +++ b/src/make.new/Makefile.in.msgs @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.msgs,v 1.5 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.msgs,v 1.6 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.pipe b/src/make.new/Makefile.in.pipe index a015caef6c..812e230010 100644 --- a/src/make.new/Makefile.in.pipe +++ b/src/make.new/Makefile.in.pipe @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.pipe,v 1.4 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.pipe,v 1.5 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.qli b/src/make.new/Makefile.in.qli index 28125b8adb..d53dde3cf4 100644 --- a/src/make.new/Makefile.in.qli +++ b/src/make.new/Makefile.in.qli @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.qli,v 1.4 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.qli,v 1.5 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.refDatabases b/src/make.new/Makefile.in.refDatabases index c4b808de37..a97d714487 100644 --- a/src/make.new/Makefile.in.refDatabases +++ b/src/make.new/Makefile.in.refDatabases @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.refDatabases,v 1.2 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.refDatabases,v 1.3 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.remote b/src/make.new/Makefile.in.remote index e0ad221706..9d0459ed9e 100644 --- a/src/make.new/Makefile.in.remote +++ b/src/make.new/Makefile.in.remote @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.remote,v 1.5 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.remote,v 1.6 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.utilities b/src/make.new/Makefile.in.utilities index e681796322..675f4be029 100644 --- a/src/make.new/Makefile.in.utilities +++ b/src/make.new/Makefile.in.utilities @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.utilities,v 1.7 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.utilities,v 1.8 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/Makefile.in.wal b/src/make.new/Makefile.in.wal index a0d5a7d424..84ad075156 100644 --- a/src/make.new/Makefile.in.wal +++ b/src/make.new/Makefile.in.wal @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.wal,v 1.4 2001-08-13 08:14:38 skywalker Exp $ +# $Id: Makefile.in.wal,v 1.5 2001-12-24 02:50:52 tamlin Exp $ # ROOT=../.. diff --git a/src/make.new/make.defaults b/src/make.new/make.defaults index fd7c2731e4..768eef535f 100755 --- a/src/make.new/make.defaults +++ b/src/make.new/make.defaults @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: make.defaults,v 1.9 2001-08-27 15:29:18 skywalker Exp $ +# $Id: make.defaults,v 1.10 2001-12-24 02:50:52 tamlin Exp $ # diff --git a/src/make.new/make.rules b/src/make.new/make.rules index e4695833d2..d121f81456 100644 --- a/src/make.new/make.rules +++ b/src/make.new/make.rules @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: make.rules,v 1.11 2001-10-17 22:48:01 bellardo Exp $ +# $Id: make.rules,v 1.12 2001-12-24 02:50:52 tamlin Exp $ # #____________________________________________________________________________ diff --git a/src/make.new/make.shared.variables b/src/make.new/make.shared.variables index 6160d919d1..1eec1a015e 100644 --- a/src/make.new/make.shared.variables +++ b/src/make.new/make.shared.variables @@ -23,7 +23,7 @@ JRD_Sources= ail.cpp all.cpp alt.cpp bookmark.cpp blb.cpp blob_filter.cpp btr.cp event.cpp evl.cpp exe.cpp ext.cpp filters.cpp flu.cpp fun.cpp functions.cpp \ gds.cpp grant.cpp idx.cpp inf.cpp ini.cpp intl.cpp inuse.cpp \ isc.cpp isc_file.cpp isc_ipc.cpp isc_sync.cpp \ - jrd.cpp jrn.cpp lck.cpp llio.cpp log.cpp met.cpp \ + jrd.cpp jrn.cpp lck.cpp llio.cpp log.cpp met.cpp memory_pool.cpp \ misc.cpp mov.cpp nav.cpp old.cpp opt.cpp pag.cpp par.cpp pcmet.cpp \ perf.cpp pwd.cpp rec.cpp rlck.cpp \ rng.cpp rse.cpp sbm.cpp sch.cpp scl.cpp \ diff --git a/src/make.new/prefix.darwin b/src/make.new/prefix.darwin index ab171e77c7..1393ed22b4 100644 --- a/src/make.new/prefix.darwin +++ b/src/make.new/prefix.darwin @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # Start of file prefix.darwin: $(VERSION) @PLATFORM@ -#$Id: prefix.darwin,v 1.6 2001-10-18 21:31:45 bellardo Exp $ +#$Id: prefix.darwin,v 1.7 2001-12-24 02:50:52 tamlin Exp $ #_____________________________________________________________________________ diff --git a/src/make.new/prefix.linux b/src/make.new/prefix.linux index 9b72500a95..2594490b59 100644 --- a/src/make.new/prefix.linux +++ b/src/make.new/prefix.linux @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # Start of file prefix.linux: $(VERSION) $(PLATFORM) -#$Id: prefix.linux,v 1.1 2001-07-29 23:43:23 skywalker Exp $ +#$Id: prefix.linux,v 1.2 2001-12-24 02:50:52 tamlin Exp $ #Revision 1.6 2000/12/01 11:20:31 fsg #Added SHRLIB_EXT to prefix.linux diff --git a/src/make.platform b/src/make.platform new file mode 100644 index 0000000000..c221e60617 --- /dev/null +++ b/src/make.platform @@ -0,0 +1,253 @@ +# The contents of this file are subject to the Interbase Public +# License Version 1.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy +# of the License at http://www.Inprise.com/IPL.html +# +# Software distributed under the License is distributed on an +# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express +# or implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code was created by Inprise Corporation +# and its predecessors. Portions created by Inprise Corporation are +# +# Copyright (C) 2000 Inprise Corporation +# All Rights Reserved. +# Contributor(s): ______________________________________. +# Start of file prefix.darwin: $(VERSION) DARWIN +#$Id: make.platform,v 1.1 2001-12-24 02:50:47 tamlin Exp $ + + +#_____________________________________________________________________________ +# +# John I've added these here since I copied them from within the makefiles +# to this spot. Just to show where they came from. +# Most of this stuff would need to go at the end of the include file here. +# and not at the beginning. +# MOD 26-July-2001 + + +# Adding to LINK_LIBS to add the framework thing. + + + +# adding another dependancy onto the includes target + + +# End add by me MOD 26-July-2001 +#______________________________________________________________________________ + +# use the following to define conditional DEV/PROD compile + +ifdef IsProdTypeBuild + DEBUG_Sources= nodebug.cpp + CFLAGS:= -O3 -DPROD_BUILD $(CFLAGS) + +else + #DEBUG_Sources= grammar.c dbg.cpp dbt.cpp dmp.cpp + DEBUG_Sources= nodebug.cpp + CFLAGS:= -ggdb -DDEV_BUILD $(CFLAGS) +endif + + + +FBFW_PREFIX= Firebird2 +FW_NAME= $(FBFW_PREFIX).framework +FW_PATH= $(FIREBIRD) +FB_FRAMEWORK= $(FW_PATH)/$(FW_NAME) +FW_VERS= 1.1.0 +FW_COMPAT_VERS= 1.0.0 +PHASE2_SHLIB_PATH= unset INTERBASE; export DYLD_FRAMEWORK_PATH=$(FIREBIRD); +POST_BUILD_TARGET= darwin_framework +SS_POST_BUILD_TARGET= ss_darwin_framework + +DEBUG_OBJECTS= $($(VERSION)_DEBUG_OBJECTS) +SHRLIB_DIR= $($(VERSION)_SHRLIB_DIR) +SHRLIB_EXT= .dylib +VERSION_FLAG= $($(VERSION)_VERSION_FLAG) +CFLAGS_COMMON= $($(VERSION)_CFLAGS) -w -F$(FW_PATH) +#CFLAGS= $(CFLAGS_COMMON) $(SUPER_FLAG) +PIC_J_CFLAGS= $(CFLAGS_COMMON) -DPIPE_IS_SHRLIB -dynamic -fno-common +SPECIAL_OBJECTS= j +UDF_LINK_CMD= libtool +UDF_CFLAGS= -dynamic -fno-common +UDF_LFLAGS= -dynamic +UDF_SHRLIBS= -lcc_dynamic -framework System + +#NOTE: PIC_J_CFLAGS is special CFLAGS used to build PIPD_IS_SHRLIB modules +# to workaround the Solaris threading problems with signals + + +#NOTE: -Xt is ANSI C transition mode (default) +# -DBDS_COMP is for BSD Compatibility package and is used in + +ACCESS_METHOD= gdslib.dylib pipe +BACKEND_BRIDGE_MISC= $(OBJS)/pipe/head5.o $(OBJS)/pipe/allp.o +BIN_PATH= /usr/isc/bin +BRIDGE_MISC= $(OBJS)/pipe/head5.o $(OBJS)/pipe/allp.o +CHMOD_VAL= 666 +CURSES_LIB= +DSQL_P_OBJS= dsql_p_objects +FORM_OBJECTS= form.o +FORM_TRN_OBJECTS= form_trn.o +FUNCTIONS= functions.bin +FUNCSHR= $(OBJS)/firebird/lib/gdsf.so +DROP_LINK= $(GDS_LINK) +GDS_LINK= $(GDSSHR_LINK) +GDS_PYXIS= gds_pyxis.a +GDSLIB_BACKEND= $(OBJS)/firebird/lib/gds_b.a +GDSLIB_LINK= -L$(OBJS)/jrd -lgds_b +#LINK_OPTS= -F$(FW_PATH) -framework $(FBFW_PREFIX) +#SS_LINK_OPTS= -F$(FW_PATH) +GPRE_BOOT_LINK_OPTS= +PLATFORM_INSTALLER= darwin_installer +SUPER_PLATFORM_INSTALLER= super_darwin_installer + +GDSSHR_DEST= $(OBJS)/firebird/lib/gds.dylib +GDSSHR= gds.dylib +#LINUX_GDSSHR= $(GDSSHR) +GDSSHR_LINK= -F$(FW_PATH) -framework $(FBFW_PREFIX) +#GDSSHR_LINK= $(SHRLIB_DIR) -lgds_pyxis +#PIPE_GDSSHR= $(OBJS)/firebird/lib/gds.so.0 +#PIPE_GDSSHR_LINK= $(SHRLIB_DIR) -lgds_pyxis +PIPE_GDSSHR_LINK= $(SHRLIB_DIR) +HLPDIR= $(SOURCE)/qli/ +HOSTNAME= `hostname | cut -d'.' -f1` +INCLUDES= include_so include_so_ada include_darwin +INTL= intl + +INTL_CFLAGS= -bundle $(CFLAGS) +INTL_LD_LINE= cc -bundle -o gdsintl -F$(OBJS)/firebird -framework $(FBFW_PREFIX) +INTL_PIC_FLAGS= -bundle $(PIC_FLAGS) +INTL_TARGET= intl_shr_objs +IO_OBJECTS= unix.o +IO_P_OBJECTS= unix.bin +JRD_MISC_OBJECTS= +JRD_J_MISC_OBJECTS= +#JRD_P_MISC_OBJECTS= $(OBJS)/jrd/nodebug.bin +JRD_P_MISC_OBJECTS= +LANG_OBJECTS= ada.o ftn.o cob.o +LANGUAGES= cc cxx ada microfocus_cob make16 gdl1 +LD_LIBS= -lcc_dynamic +LD_LIBS_J= +LD_OPTS= -dylib +LOCK_JRD_MISC= +LOCK_MANAGER= +MARION_DB= -d source/marion.gdb +MUISQL= muisql +#MUISQL_MU_LIB= -L /usr/gds.$(HOSTNAME)/qa_tools/lib -lmu +MUISQL_MU_LIB= -L /usr/gds.$(HOSTNAME)/qa_tools/lib -lmu +MUISQL_LINK_OPTS= $(MUISQL_MU_LIB) $(PIPE_GDSSHR_LINK) +PIC_FLAGS= $(CFLAGS) -dynamic -fno-common +PIPE= gds.a gds_pipe +REG_HELP= isc_ins_hlp.dat +REMOTE_GDSSHR= $(GDSSHR) +REMOTE_GDSSHR_LINK= $(SERVER_LINK) +REMOTE_P_OBJS= rem_p_objects +SCREEN_LIBS= +SERVER_LINK= $(GDSSHR_LINK) +SETUP_ISC= ISC_USER=sysdba; ISC_PASSWORD=masterkey; export ISC_USER ISC_PASSWORD; +#SPECIAL_OPT= $(SOURCE)/special_opt +SPECIAL_OPT= +NETWORK_LIB= +SOCKET_LIB= +THREAD_LIB= -lpthread +SUN_FUNCSHR= $(FUNCSHR) +DARWIN_SUPER_GDSSHR= $(OBJS)/firebird/lib/gds.dylib.1 +SUPER_CLIENT_GDSSHR= $(DARWIN_SUPER_GDSSHR) +SUPER_BACKEND= $(OBJS)/jrd/gds_ss.a +SUPER_LINK= -L$(OBJS)/jrd -lgds_ss -framework System -framework Foundation +SUPER_SERVER= +UTILITIES= +WAL_P_OBJS= wal_p_objects + +SU_EXEC= $(SOURCE)/su_exec.sh + + +SUPER_SERVER_DEST= $(OBJS)/firebird/bin/ibserver +INET_SERVER_DEST= $(OBJS)/firebird/bin/gds_inet_server +DNET_SERVER_DEST= $(OBJS)/firebird/bin/gds_dnet_server +AMBX_SERVER_DEST= $(OBJS)/firebird/bin/gds_server +INET_LIB_DEST= $(OBJS)/firebird/lib/gds_inet_server.a +DNET_LIB_DEST= $(OBJS)/firebird/lib/gds_dnet_server.a + + +MSG_INSTALL_CMD= $(CP) $(OBJS)/firebird/interbase.msg $(FB_FRAMEWORK)/Resources/English.lproj +CARBONCORE_DIR_FLAG= -F/System/Library/Frameworks/CoreServices.framework/Frameworks +DARWIN_COREFOUNDATION_LINK= -framework CoreFoundation +DARWIN_FOUNDATION_LINK= -framework Foundation + +# Options for linking the FB shared library. +LIBGDS_SO := $(LIB)/libgds.dylib +LIB_LINK := libtool +LIBGDS_LINK_OPTIONS := -dynamic -install_name \ + $(FW_NAME)/Versions/A/$(FBFW_PREFIX) \ + -current_version $(FW_VERS) \ + -compatibility_version $(FW_COMPAT_VERS) \ + -framework System -framework CoreFoundation \ + -lstdc++ -lcc_dynamic + +LIB_LINK_OPTIONS := -dynamic + +# The routines used for IO. Darwin uses the unix routines. +IO_Sources= unix.cpp + +# Add in the platform specific link options +LINK_LIBS := $(DARWIN_COREFOUNDATION_LINK) +STATICLINK_LIBS := $(LINK_LIBS) +LINK_OPTS := $(DARWIN_COREFOUNDATION_LINK) + + +# We need to over ride some of the defaults set in make.defaults +AR= ar cru + +# Define our own rules to over ride those in make.rules +CFLAGS := -I/Users/john/Desktop/STLport-1115/stlport $(CARBONCORE_DIR_FLAG) $(CFLAGS) + +# If we don't define CXXFLAGS again, our changes to CFLAGS won't take effect +# for CXXFLAGS +CXXFLAGS:= $(CXXFLAGS) $(CFLAGS) + + +# Set up the link line to work with the framework. +ifdef UseSharedLibraries + LIBGDS_LINK = -F$(FIREBIRD) -framework $(FBFW_PREFIX) +endif + + +# Set DYLD_FRAMEWORK_PATH to point to the framework we are building. + +export DYLD_FRAMEWORK_PATH +DYLD_FRAMEWORK_PATH := $(FIREBIRD) + + + +# The target to generate our psuedo framework for use when compiling. +../gen/firebird/lib/stub.dylib: + cc -c -o ../gen/firebird/lib/stub.o ../macosx_build/firebird_test/stub.c + libtool -dynamic -o ../gen/firebird/lib/stub.dylib -install_name Firebird2.framework/Versions/A/Firebird2 ../gen/firebird/lib/stub.o + +firebird: darwin_pseudo_fw +darwin_pseudo_fw: ../gen/firebird/lib/stub.dylib + $(RM) -rf $(FB_FRAMEWORK) + mkdir -p $(FB_FRAMEWORK)/Versions/A/Resources/English.lproj/var + ln -s Versions/Current/$(FBFW_PREFIX) $(FB_FRAMEWORK)/$(FBFW_PREFIX) + ln -s Versions/Current/Resources $(FB_FRAMEWORK)/Resources + ln -s Versions/Current/Headers $(FB_FRAMEWORK)/Headers + ln -s A $(FB_FRAMEWORK)/Versions/Current + sed "s/__VERSION__/0.0.boot/g" $(SRC_ROOT)/install/arch-specific/darwin/FrameworkInfo.plist > $(FB_FRAMEWORK)/Resources/Info.plist + ln -s ../../../include $(FB_FRAMEWORK)/Versions/A/Headers + ln -s ../../../lib/stub.dylib $(FB_FRAMEWORK)/Versions/A/$(FBFW_PREFIX) + ln -s ../../../../../../interbase.msg \ + $(FB_FRAMEWORK)/Versions/A/Resources/English.lproj/var/interbase.msg + ln -s ../../../../../../bin \ + $(FB_FRAMEWORK)/Versions/A/Resources/English.lproj/var/bin + ln -s ../../../../../../intl \ + $(FB_FRAMEWORK)/Versions/A/Resources/English.lproj/var/intl + ln -s ../../../../../../isc4.gdb \ + $(FB_FRAMEWORK)/Versions/A/Resources/English.lproj/var/isc4.gdb + ln -s ../../../../../../help \ + $(FB_FRAMEWORK)/Versions/A/Resources/English.lproj/var/help + + +# End of file prefix.darwin: $(VERSION) $(PLATFORM) diff --git a/src/make.rules b/src/make.rules new file mode 100644 index 0000000000..18a8159ebe --- /dev/null +++ b/src/make.rules @@ -0,0 +1,266 @@ +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# Alternatively, the contents of this file may be used under the +# terms of the GNU General Public License Version 2 or later (the +# "GPL"), in which case the provisions of the GPL are applicable +# instead of those above. You may obtain a copy of the Licence at +# http://www.gnu.org/copyleft/gpl.html +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Relevant for more details. +# +# This file was created by members of the firebird development team. +# All individual contributions remain the Copyright (C) of those +# individuals. Contributors to this file are either listed here or +# can be obtained from a CVS history command. +# +# All rights reserved. +# +# Created by: Mark O'Donohue +# +# Contributor(s): +# +# +# $Id: make.rules,v 1.1 2001-12-24 02:50:47 tamlin Exp $ +# + +#____________________________________________________________________________ + +# Currently I set these manually but they should be set automatically +# from the ./configure installation time + +UseSharedLibraries = Yes # If empty then we build static linked exe's + # which are useful for debugging. + # This variable is used to determined flags for + # libtool/ar/ld we define the gds.a/so library name + # in LIBGDS_LA and in Makefile.in.jrd where we do the + # creation of the libgds.a/so library. + +#UseLibToolForLink = Yes # Currently we do not use it - but may in the future + +#IsProdTypeBuild = Yes # If this is defined then we are building a production + # release with debug and optimization + + +#____________________________________________________________________________ + + +GEN_ROOT=$(ROOT)/gen +SRC_ROOT=$(ROOT)/src + +LIB=$(GEN_ROOT)/firebird/lib +BIN=$(GEN_ROOT)/firebird/bin + +# This picks up the current directory and maps it to the equivalent module +# in the src and gen area. + +ModuleName:=$(notdir $(CURDIR)) +SRC=$(SRC_ROOT)/$(ModuleName) +OBJ=$(GEN_ROOT)/$(ModuleName) +DEP=$(OBJ) + +GEN_SRC=$(OBJ) + + # This one is not so widely used at the momement. + # but I would like it to become so. + + +FIREBIRD=$(GEN_ROOT)/firebird +INTERBASE=$(FIREBIRD) + +export INTERBASE +export FIREBIRD + +# I would like to remove this one. +SOURCE=$(ROOT)/src + +CFLAGS:= $(CFLAGS) -g -pipe -MMD -p -fPIC -Wall -I$(ROOT)/src -I$(ROOT)/src/include + +CXXFLAGS:= $(CXXFLAGS) $(CFLAGS) + +#CC = libtool cc +#CXX = libtool c++ + +CC = cc +CXX = c++ + + + +# Most of the libraries and programs are linked using the dynamic linker +# We default to using the dynamic linker and have a special link macros for +# using the static linker. +# +# Also libtool looks like the future in cross platform shared object compile +# and linking, but unfortunately it does not yet work for us, as a +# libtool gcc -o $(BIN)/fred fred.o libzzz.la +# command will generate incorrect relative addresses in the wrapper script in +# $(BIN)/fred as it required the exe file fred to be in the directory from +# which the command is run from. +# One other issue is that libtool puts a -DPIC onto the compile line. While +# nice it conflicts with a struct in the file qli/format.h +# MOD 26-July-2001. + + + + +ifdef UseLibToolForLink + + + LIB_LINK= libtool cc + STATICLIB_LINK = libtool cc -all-static + LIB_LINK_OPTIONS = -version-info 0:0:0 -release 1.5.0.0 -rpath /usr/lib + + EXE_LINK = libtool cc + STATICEXE_LINK = libtool cc -all-static +else + + LIB_LINK= g++ -shared + STATICLIB_LINK= ar cruvs +# LIB_LINK_OPTIONS = -soname libgds.so -rpath /usr/lib +# LIB_LINK_OPTIONS = -soname libgds.so.2 -rpath /usr/lib + LIB_LINK_OPTIONS = + +# EXE_LINK = g++ +# STATICEXE_LINK = g++ + EXE_LINK = c++ + STATICEXE_LINK = c++ +endif + + + + +LINK_OPTIONS= + +ReadlineLibs = -lreadline -ltermcap +LINK_LIBS= -lm -lstdc++ $(ReadlineLibs) -lc -ldl -lcrypt +STATICLINK_LIBS = -lm -lstdc++ $(ReadlineLibs) -lc -ldl -lcrypt + +#LINK_LIBS= -L$(LIB) -lgds -lm -lc -ldl -lcrypt +# -lgcc + + +# These should no longer be required but I've left here +# in case someone needs to know what they were + +#STATICLIBTOOL= libtool gcc -static +#STATIC_LINK_OPTIONS= -static +#STATIC_LINK_LIBS= -lm -lc -mieee-fp -ldl -lcrypt +#SHLIB_LINK_OPTIONS = -shared + + +ifdef IsProdTypeBuild + CXXFLAGS:= -O3 -m486 -DPROD_BUILD $(CXXFLAGS) + +else + CXXFLAGS:= -ggdb -DDEV_BUILD $(CXXFLAGS) +endif + + +# Here we have definitions for using the preprocessor. + +# The GPRE_FLAGS is overwritten in Makefile.in.jrd Makefile.in.gpre and +# since they do something extra to allow the boot build to work. +# +# One other point is that sometimes a failure in compile with gpre does not +# result in an error being generated. The generated source file still +# compiles and throws the make off the path. +# +# This bit of code is part of unfinished bit to let make determine if +# gpre gpre_static or gpre_boot should be used based on which ones exist. +# +# testgpre = $(shell if [ -f $(GPRE) ]; then; echo $(GPRE); else; echo ""; fi) +#test1: +# echo $(testgpre) + + +GPRE_FLAGS= -r -m -z -n + +.SUFFIXES: .c .e .epp .cpp + +.e.c: + $(GPRE_CURRENT) $(GPRE_FLAGS) $< $@ + + +.epp.cpp: + $(GPRE_CURRENT) $(GPRE_FLAGS) $< $@ + + + +.SUFFIXES: .lo .o .cpp .c + +.c.o: + $(CC) -c $(CFLAGS) $(CXX_INCLUDE_DIRS) $(VERSION_FLAG) $< + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(CXX_INCLUDE_DIRS) $(VERSION_FLAG) $< + +#.c.lo: +# $(CC) -c $(PIC_FLAGS) $(CFLAGS) $(CXX_INCLUDE_DIRS) $(VERSION_FLAG) -o $*.lo $< +# +#.cpp.lo: +# $(CXX) -c $(PIC_FLAGS) $(CXXFLAGS) $(CXX_INCLUDE_DIRS) $(VERSION_FLAG) -o $*.lo $< +# + + +$(OBJ)/%.o:: $(SRC)/%.c + $(CC) $(CXXFLAGS) -c $(firstword $<) -o $@ + @$(move-dep) + +$(OBJ)/%.o: $(SRC)/%.cpp + $(CXX) $(CXXFLAGS) -c $(firstword $<) -o $@ + @$(move-dep) + +$(OBJ)/%.lo: $(SRC)/%.cpp + @$(move-dep) + +#$(OBJ)/% +#.epp.cpp: +# $(GPRE_STATIC) $(GPRE_FLAGS) $< + +$(OBJ)/%.o: $(DEP)/%.d + +.SUFFIXES: .epp .e + +# Just write out a line making the .cpp file dependant on the .d file +# since the .d file was just created then it will force a compile of the +# .cpp files + +$(DEP)/%.d:: $(SRC)/%.c + @echo "need to rebuild $^" + echo $(OBJ)/$(*).o " : FORCE" > $@ +# touch $^ + +$(DEP)/%.d:: $(SRC)/%.epp + @echo "need to rebuild $^" + echo $(OBJ)/$(*).o " : FORCE" > $@ +# touch $^ + +$(DEP)/%.d:: $(SRC)/%.cpp + @echo "need to rebuild $^" + echo $(OBJ)/$(*).o " : FORCE" > $@ +# touch $^ + + +# code to move the dependancy files from the current directory + +# (a # is used to delimit the sed substitute command since a "/" +# gets in trouble with directory path names) + +define move-dep + if [ -f $(*F).d ]; \ + then \ + sed -e '1 s#$(@F)#$(OBJ)\/$(@F)#' $(*F).d > tmp.d; \ + mv tmp.d $(OBJ)/$(*F).d; \ + rm $(*F).d; \ + touch $@; \ + fi +endef + + + + diff --git a/src/make.shared.variables b/src/make.shared.variables new file mode 100644 index 0000000000..1eec1a015e --- /dev/null +++ b/src/make.shared.variables @@ -0,0 +1,170 @@ + + +#________________________________________________________________________ +# +# jrd + +# to get at the database. why.cpp is the normal one whybk.cpp is the one +# compiled with a BACKEND flag, it seems to be (from a quick look at +# the code) to allow the use of another library to talk to data from +# and earlier version data file. (Good way to achieve back portability) +# In the current builds only why.cpp is used, to build using whybk.cpp you +# will need to look at what is contained in the original makefiles. + +WHY_Sources = why.c +WHY_BACKEND_Sources= whybk.c + + +# why.c does the switch to determine the actual implementation to use +JRD_Sources= ail.cpp all.cpp alt.cpp bookmark.cpp blb.cpp blob_filter.cpp btr.cpp builtin.cpp \ + cch.cpp cmp.cpp cvt.cpp cvt2.cpp \ + dfw.cpp divorce.cpp dls.cpp dpm.cpp dsc.cpp dyn.cpp dyn_def.cpp dyn_del.cpp \ + dyn_mod.cpp dyn_util.cpp enc.cpp err.cpp iberr.cpp \ + event.cpp evl.cpp exe.cpp ext.cpp filters.cpp flu.cpp fun.cpp functions.cpp \ + gds.cpp grant.cpp idx.cpp inf.cpp ini.cpp intl.cpp inuse.cpp \ + isc.cpp isc_file.cpp isc_ipc.cpp isc_sync.cpp \ + jrd.cpp jrn.cpp lck.cpp llio.cpp log.cpp met.cpp memory_pool.cpp \ + misc.cpp mov.cpp nav.cpp old.cpp opt.cpp pag.cpp par.cpp pcmet.cpp \ + perf.cpp pwd.cpp rec.cpp rlck.cpp \ + rng.cpp rse.cpp sbm.cpp sch.cpp scl.cpp \ + sdl.cpp sdw.cpp shut.cpp sort.cpp sqz.cpp status.cpp svc.cpp sym.cpp thd.cpp tpc.cpp \ + tra.cpp utl.cpp val.cpp vio.cpp \ + $(IO_Sources) $(DEBUG_Sources) $(WHY_Sources) + +JRD_ObjectsX = $(JRD_Sources:%.cpp=$(GEN_ROOT)/jrd/%.o) +JRD_Objects = $(JRD_ObjectsX:%.c=$(GEN_ROOT)/jrd/%.o) # One extra rule for why.c + +JRD_SharedObjects = $(JRD_Objects:.o=.lo) + + +# If your platform needs these then you may need +# to include something like. +# JRD_P_Sources := $(subst, flu.lo, , $(JRD_P_Sources)) + + + +#________________________________________________________________________ +# +# dsql + +DSQL_Sources= alld.cpp array.cpp blob.cpp ddl.cpp dsql.cpp \ + errd.cpp gen.cpp hsh.cpp make.cpp metd.cpp \ + movd.cpp parse.cpp pass1.cpp preparse.cpp \ + user_dsql.cpp utld.cpp + +DSQL_Objects=$(DSQL_Sources:%.cpp=$(GEN_ROOT)/dsql/%.o) +DSQL_SharedObjects=$(DSQL_Objects:.o=.lo) + + +#________________________________________________________________________ +# +# lock + + +LOCK_Sources = lock.cpp + +LOCK_Objects = $(LOCK_Sources:%.cpp=$(GEN_ROOT)/lock/%.o) +LOCK_SharedObjects = $(LOCK_Objects:.o=.lo) + + +#________________________________________________________________________ +# +# remote + +REMOTE_Sources= allr.cpp inet.cpp merge.cpp parser.cpp protocol.cpp remote.cpp \ + $(NET_Sources) +INTERFACE_Sources= interface.cpp $(REMOTE_Sources) + + +INTERFACE_Objects =$(INTERFACE_Sources:%.cpp=$(GEN_ROOT)/remote/%.o) +INTERFACE_SharedObjects =$(INTERFACE_Objects:.o=.lo) + + + +#________________________________________________________________________ +# +# pipe + +PIPE_Sources= head5.cpp allp.cpp + +PIPE_Objects = $(PIPE_Sources:%.cpp=$(GEN_ROOT)/pipe/%.o) +PIPE_SharedObjects = $(PIPE_Objects:.o=.lo) + + + +#________________________________________________________________________ +# +# intl + +# none currently. + + +#________________________________________________________________________ +# +# wal + +WAL_Sources= wal.cpp walc.cpp walf.cpp walr.cpp wstatus.cpp walw.cpp + +WAL_Objects = $(WAL_Sources:%.cpp=$(GEN_ROOT)/wal/%.o) +WAL_SharedObjects = $(WAL_Objects:.o=.lo) + +#________________________________________________________________________ +# +# gpre + +GPRELIB_Sources = pretty.cpp +GPRELIB_P_Sources = $(GPRELIB_Sources) + +GPRELIB_Objects = $(GPRELIB_Sources:%.cpp=$(GEN_ROOT)/gpre/%.o) +GPRELIB_SharedObjects = $(GPRELIB_Objects:.o=.lo) + + +#________________________________________________________________________ +# +# utilities + +SECURITY_Sources=security.cpp + +SECURITY_Objects = $(SECURITY_Sources:%.cpp=$(GEN_ROOT)/utilities/%.o) +SECURITY_SharedObjects = $(SECURITY_Objects:.o=.lo) + + +#________________________________________________________________________ +# +# fbutil + +FBUTIL_Sources=FirebirdConfig.cpp FirebirdConfigFile.cpp + +FBUTIL_Objects = $(FBUTIL_Sources:%.cpp=$(GEN_ROOT)/fbutil/%.o) +FBUTIL_SharedObjects = $(FBUTIL_Objects:.o=.lo) + + + + +#________________________________________________________________________ +# + +# These are the lists of object/shared object files that will go into libgds.a +# and libgds.so. + +GDSLIB_Objects = $(JRD_Objects) \ + $(DSQL_Objects) \ + $(LOCK_Objects) \ + $(INTERFACE_Objects) \ + $(PIPE_Objects) \ + $(WAL_Objects) \ + $(GPRELIB_Objects) \ + $(SECURITY_Objects) \ + $(FBUTIL_Objects) + +# Notice that $(SECURITY_Objects) are missing, because that file can't be +# compiled until later in the build process. + +BOOT_GDSLIB_Objects = $(JRD_Objects) \ + $(DSQL_Objects) \ + $(LOCK_Objects) \ + $(INTERFACE_Objects) \ + $(PIPE_Objects) \ + $(WAL_Objects) \ + $(GPRELIB_Objects) \ + $(FBUTIL_Objects) diff --git a/src/makefiles/bind_gds.aix_ppc b/src/makefiles/bind_gds.aix_ppc index 8e2eabbe82..e174a71d19 100644 --- a/src/makefiles/bind_gds.aix_ppc +++ b/src/makefiles/bind_gds.aix_ppc @@ -16,7 +16,7 @@ * Contributor(s): * Tom Coleman tmcsys (AIX for C bind expects * comments) * -* $Id: bind_gds.aix_ppc,v 1.1 2001-07-12 06:32:03 bellardo Exp $ +* $Id: bind_gds.aix_ppc,v 1.2 2001-12-24 02:50:52 tamlin Exp $ * gds__alloc gds__attach_database diff --git a/src/makefiles/bind_gds_s.im b/src/makefiles/bind_gds_s.im index d418d510ad..d91abdfb5c 100644 --- a/src/makefiles/bind_gds_s.im +++ b/src/makefiles/bind_gds_s.im @@ -14,7 +14,7 @@ # # All Rights Reserved. # Contributor(s): ______________________________________. -# $Id: bind_gds_s.im,v 1.1 2001-07-12 06:32:03 bellardo Exp $ +# $Id: bind_gds_s.im,v 1.2 2001-12-24 02:50:52 tamlin Exp $ #ident "InterBase V4.0 shared library" #address .text 0x03800000 #address .data 0x03c00000 diff --git a/src/makefiles/bind_gds_s.sco b/src/makefiles/bind_gds_s.sco index 39c61407f4..42d2b915e1 100644 --- a/src/makefiles/bind_gds_s.sco +++ b/src/makefiles/bind_gds_s.sco @@ -14,7 +14,7 @@ # # All Rights Reserved. # Contributor(s): ______________________________________. -# $Id: bind_gds_s.sco,v 1.1 2001-07-12 06:32:03 bellardo Exp $ +# $Id: bind_gds_s.sco,v 1.2 2001-12-24 02:50:52 tamlin Exp $ #ident "InterBase V4.0 shared library" #address .text 0xa4800000 #address .data 0xa4c00000 diff --git a/src/makefiles/bind_gdsintl.aix_ppc b/src/makefiles/bind_gdsintl.aix_ppc index 4de1c60580..bda10e46ae 100644 --- a/src/makefiles/bind_gdsintl.aix_ppc +++ b/src/makefiles/bind_gdsintl.aix_ppc @@ -16,6 +16,6 @@ * Contributor(s): * Tom Coleman tmcsys (AIX for C bind expects * comments) * -* $Id: bind_gdsintl.aix_ppc,v 1.1 2001-07-12 06:32:03 bellardo Exp $ +* $Id: bind_gdsintl.aix_ppc,v 1.2 2001-12-24 02:50:52 tamlin Exp $ * LD_lookup diff --git a/src/makefiles/boot.sfx.interbase b/src/makefiles/boot.sfx.interbase index 5098b780e9..f169161c45 100644 --- a/src/makefiles/boot.sfx.interbase +++ b/src/makefiles/boot.sfx.interbase @@ -18,7 +18,7 @@ # # Tom Coleman TMC Systems # -# $Id: boot.sfx.interbase,v 1.1 2001-07-12 06:32:03 bellardo Exp $ +# $Id: boot.sfx.interbase,v 1.2 2001-12-24 02:50:52 tamlin Exp $ #== WARNING ============================================================== diff --git a/src/makefiles/buildRefDatabases b/src/makefiles/buildRefDatabases index c2bedfbfd3..d22f2e9be5 100755 --- a/src/makefiles/buildRefDatabases +++ b/src/makefiles/buildRefDatabases @@ -1,6 +1,6 @@ #!/bin/sh -# $Id: buildRefDatabases,v 1.1 2001-07-12 06:32:03 bellardo Exp $ +# $Id: buildRefDatabases,v 1.2 2001-12-24 02:50:52 tamlin Exp $ # This file builds the reference databases for both the boot build # and the normal builds. diff --git a/src/makefiles/prefix.darwin b/src/makefiles/prefix.darwin index af285a173d..343d22d7b5 100644 --- a/src/makefiles/prefix.darwin +++ b/src/makefiles/prefix.darwin @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # Start of file prefix.darwin: $(VERSION) @PLATFORM@ -#$Id: prefix.darwin,v 1.2 2001-07-12 20:07:45 bellardo Exp $ +#$Id: prefix.darwin,v 1.3 2001-12-24 02:50:52 tamlin Exp $ .SUFFIXES: .bin .o .cpp .c .cpp.o: diff --git a/src/makefiles/prefix.freebsd b/src/makefiles/prefix.freebsd index d2d3426ba9..2118b26f73 100644 --- a/src/makefiles/prefix.freebsd +++ b/src/makefiles/prefix.freebsd @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # Start of file prefix.freebsd: $(VERSION) $(PLATFORM) -#$Id: prefix.freebsd,v 1.1 2001-07-12 06:32:04 bellardo Exp $ +#$Id: prefix.freebsd,v 1.2 2001-12-24 02:50:52 tamlin Exp $ .SUFFIXES: .c .e .e.c: diff --git a/src/makefiles/prefix.linux b/src/makefiles/prefix.linux index 8cc5369822..99201c65bb 100644 --- a/src/makefiles/prefix.linux +++ b/src/makefiles/prefix.linux @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # Start of file prefix.linux: $(VERSION) $(PLATFORM) -#$Id: prefix.linux,v 1.1 2001-07-12 06:32:04 bellardo Exp $ +#$Id: prefix.linux,v 1.2 2001-12-24 02:50:52 tamlin Exp $ #Revision 1.6 2000/12/01 11:20:31 fsg #Added SHRLIB_EXT to prefix.linux # diff --git a/src/makefiles/prefix.netbsd b/src/makefiles/prefix.netbsd index b3029c045f..a47f93bb5d 100644 --- a/src/makefiles/prefix.netbsd +++ b/src/makefiles/prefix.netbsd @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # Start of file prefix.netbsd: $(VERSION) $(PLATFORM) -#$Id: prefix.netbsd,v 1.1 2001-07-12 06:32:04 bellardo Exp $ +#$Id: prefix.netbsd,v 1.2 2001-12-24 02:50:52 tamlin Exp $ .SUFFIXES: .c .e .e.c: diff --git a/src/makefiles/prefix.solx86 b/src/makefiles/prefix.solx86 index efb5986cfc..eda2b4cbc1 100644 --- a/src/makefiles/prefix.solx86 +++ b/src/makefiles/prefix.solx86 @@ -18,7 +18,7 @@ # # Use SOLX86 to identify x86 version of Solaris. Neil McCalden # -# $Id: prefix.solx86,v 1.1 2001-07-12 06:32:04 bellardo Exp $ +# $Id: prefix.solx86,v 1.2 2001-12-24 02:50:52 tamlin Exp $ # # Start of file prefix.solaris X 86 : $(VERSION) $(PLATFORM) .SUFFIXES: .c .e diff --git a/src/makefiles/sfx.jrd b/src/makefiles/sfx.jrd index 2a8874f4ae..f88fbd3425 100644 --- a/src/makefiles/sfx.jrd +++ b/src/makefiles/sfx.jrd @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # -# $Id: sfx.jrd,v 1.1 2001-07-12 06:32:04 bellardo Exp $ +# $Id: sfx.jrd,v 1.2 2001-12-24 02:50:52 tamlin Exp $ # @SET_MAKE@ SOURCE= source diff --git a/src/makefiles/sfx.pipe b/src/makefiles/sfx.pipe index e1f2aeb2a5..0fc363f055 100644 --- a/src/makefiles/sfx.pipe +++ b/src/makefiles/sfx.pipe @@ -15,7 +15,7 @@ # All Rights Reserved. # Contributor(s): ______________________________________. # -# $Id: sfx.pipe,v 1.1 2001-07-12 06:32:04 bellardo Exp $ +# $Id: sfx.pipe,v 1.2 2001-12-24 02:50:52 tamlin Exp $ # SOURCE= source OBJS= objs diff --git a/src/misc/fb_boilerplate.h b/src/misc/fb_boilerplate.h index 0b1b692208..26baa65952 100644 --- a/src/misc/fb_boilerplate.h +++ b/src/misc/fb_boilerplate.h @@ -28,6 +28,6 @@ * Mark O'Donohue * * - * $Id: fb_boilerplate.h,v 1.1 2001-07-29 23:43:23 skywalker Exp $ + * $Id: fb_boilerplate.h,v 1.2 2001-12-24 02:50:52 tamlin Exp $ * */ diff --git a/src/pipe/head.cpp b/src/pipe/head.cpp index b7815814c9..40f3b34a86 100644 --- a/src/pipe/head.cpp +++ b/src/pipe/head.cpp @@ -22,7 +22,7 @@ * Solaris x86 changes - Konstantin Kuznetsov, Neil McCalden */ - /* $Id: head.cpp,v 1.3 2001-07-29 23:43:23 skywalker Exp $ */ + /* $Id: head.cpp,v 1.4 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" #include "../jrd/ib_stdio.h" diff --git a/src/pipe/pipe.h b/src/pipe/pipe.h index 7481a71dc3..02e67531cd 100644 --- a/src/pipe/pipe.h +++ b/src/pipe/pipe.h @@ -113,7 +113,7 @@ typedef int *HANDLE; /* Block types */ #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif /* Block types */ diff --git a/src/qli/all.cpp b/src/qli/all.cpp index 0c872aa375..7c72c34171 100644 --- a/src/qli/all.cpp +++ b/src/qli/all.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: all.cpp,v 1.3 2001-07-29 23:43:23 skywalker Exp $ +$Id: all.cpp,v 1.4 2001-12-24 02:50:53 tamlin Exp $ */ /*************************************************** diff --git a/src/qli/dtr.cpp b/src/qli/dtr.cpp index 89a58034ec..ef18a3567f 100644 --- a/src/qli/dtr.cpp +++ b/src/qli/dtr.cpp @@ -49,6 +49,7 @@ #include "../qli/parse_proto.h" #include "../jrd/gds_proto.h" #include "../jrd/perf_proto.h" +#include "../include/fb_exception.h" #ifdef VMS #define STARTUP_FILE "QLI_STARTUP" @@ -285,18 +286,18 @@ int CLIB_ROUTINE main( int argc, char **argv) FALSE); #endif - for (got_started = 0; !got_started;) { + for (got_started = 0; !got_started;) + { got_started = 1; - if (setjmp(env)) { - /* try again */ - - got_started = 0; - ERRQ_pending(); - } - else { + try { QLI_env = env; PAR_token(); } + catch (...) { + /* try again */ + got_started = 0; + ERRQ_pending(); + } } memset(QLI_env, 0, sizeof(QLI_env)); QLI_error = NULL; @@ -370,7 +371,6 @@ static USHORT process_statement( USHORT flush_flag) DBB dbb; PERF statistics; TEXT buffer[512], report[256], *p; - int status; jmp_buf env; /* Clear database active flags in preparation for a new statement */ @@ -396,12 +396,7 @@ static USHORT process_statement( USHORT flush_flag) /* Enable error unwinding and enable the unwinding environment */ - status = setjmp(env); - - if (status) { - GEN_release(); - return status; - } + try { QLI_env = env; @@ -500,8 +495,11 @@ static USHORT process_statement( USHORT flush_flag) EXEC_top((nod*) execution_tree); if (QLI_statistics) + { for (dbb = QLI_databases; dbb; dbb = dbb->dbb_next) - if (dbb->dbb_flags & DBB_active) { + { + if (dbb->dbb_flags & DBB_active) + { #ifndef PC_PLATFORM ERRQ_msg_get(505, report); /* Msg505 " reads = !r writes = !w fetches = !f marks = !m\n" */ @@ -514,12 +512,20 @@ static USHORT process_statement( USHORT flush_flag) ERRQ_msg_put(26, dbb->dbb_filename, buffer, NULL, NULL, NULL); /* Msg26 Statistics for database %s %s */ QLI_skip_line = TRUE; } + } + } /* Release resources associated with the request */ GEN_release(); return FALSE; + + } // try + catch (const Firebird::status_longjmp_error& e) { + GEN_release(); + return e.value(); + } } diff --git a/src/qli/dtr.h b/src/qli/dtr.h index ff6e3f5f55..0087b1c038 100644 --- a/src/qli/dtr.h +++ b/src/qli/dtr.h @@ -52,7 +52,7 @@ ENUM blk_t /* Block types */ #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif typedef struct vec { diff --git a/src/qli/err.cpp b/src/qli/err.cpp index 0c628528a0..2fc7080983 100644 --- a/src/qli/err.cpp +++ b/src/qli/err.cpp @@ -94,8 +94,9 @@ void ERRQ_database_error( DBB dbb, STATUS * status_vector) if (dbb && dbb->dbb_handle && status_vector[1] == gds__io_error) ERRQ_msg_put(458, dbb->dbb_filename, NULL, NULL, NULL, NULL); /* Msg458 ** connection to database %s lost ** */ - if (QLI_env) - longjmp((jmp_buf) QLI_env, -1); + if (QLI_env) { + Firebird::status_longjmp_error::raise(-1); + } } @@ -121,7 +122,7 @@ void ERRQ_error( ERRQ_error_format(number, arg1, arg2, arg3, arg4, arg5); if (QLI_env) - longjmp((jmp_buf) QLI_env, -1); + Firebird::status_longjmp_error::raise(-1); else { ERRQ_pending(); ERRQ_exit(FINI_ERROR); diff --git a/src/qli/eval.cpp b/src/qli/eval.cpp index b0bae5bbd5..a18e4174b0 100644 --- a/src/qli/eval.cpp +++ b/src/qli/eval.cpp @@ -41,11 +41,6 @@ #include "../jrd/gds_proto.h" #include "../jrd/utl_proto.h" -typedef struct vary { - USHORT vary_length; - TEXT vary_string[1]; -} VARY; - extern USHORT QLI_prompt_count, QLI_reprompt; extern USHORT sw_forms; diff --git a/src/qli/exe.cpp b/src/qli/exe.cpp index d300563f63..718ee1b813 100644 --- a/src/qli/exe.cpp +++ b/src/qli/exe.cpp @@ -58,11 +58,6 @@ extern jmp_buf QLI_env; extern USHORT QLI_prompt_count, QLI_reprompt; -typedef struct vary { - USHORT vary_length; - UCHAR vary_string[1]; -} VARY; - static DSC *assignment(NOD, DSC *, NOD, NOD, PAR); static void commit_retaining(NOD); static int copy_blob(NOD, PAR); @@ -504,10 +499,11 @@ void EXEC_top( NOD node) } -static DSC *assignment( - NOD from_node, - DSC * to_desc, - NOD validation, NOD initial, PAR parameter) +static DSC *assignment( NOD from_node, + DSC* to_desc, + NOD validation, + NOD initial, + PAR parameter) { /************************************** * @@ -525,7 +521,6 @@ static DSC *assignment( MSG message; USHORT l, *missing_flag, trash; jmp_buf old_env; - int status; jmp_buf env; old_env = QLI_env; @@ -539,17 +534,7 @@ static DSC *assignment( (USHORT *) (message->msg_buffer + parameter->par_offset); } - status = setjmp(env); - - if (status) - if (QLI_abort || !QLI_prompt_count) { - QLI_env = old_env; - longjmp(QLI_env, status); - } - else { - QLI_reprompt = TRUE; - QLI_prompt_count = 0; - } + try { #if (defined JPN_EUC || defined JPN_SJIS) if (from_node->nod_type == nod_edit_blob) { @@ -562,28 +547,43 @@ static DSC *assignment( QLI_env = env; from_desc = EVAL_value(from_node); - if (from_desc->dsc_missing & DSC_initial) + if (from_desc->dsc_missing & DSC_initial) { from_desc = EVAL_value(initial); + } /* If there is a value present, do any assignment; otherwise null fill */ if (*missing_flag = to_desc->dsc_missing = from_desc->dsc_missing) { p = from_desc->dsc_address; - if (l = from_desc->dsc_length) - do + if (l = from_desc->dsc_length) { + do { *p++ = 0; - while (--l); + } while (--l); + } } - else + else { MOVQ_move(from_desc, to_desc); + } - if (validation && EVAL_boolean(validation) <= 0) + if (validation && EVAL_boolean(validation) <= 0) { IBERROR(39); /* Msg39 field validation error */ + } QLI_reprompt = FALSE; QLI_env = old_env; return from_desc; + + } // try + catch (...) { + if (QLI_abort || !QLI_prompt_count) { + QLI_env = old_env; + throw; + } + + QLI_reprompt = TRUE; + QLI_prompt_count = 0; + } } @@ -1006,7 +1006,6 @@ static void execute_output( NOD node) **************************************/ PRT print; jmp_buf old_env; - int status; jmp_buf env; print = (PRT) node->nod_arg[e_out_print]; @@ -1017,20 +1016,22 @@ static void execute_output( NOD node) old_env = QLI_env; QLI_env = env; - status = setjmp(QLI_env); - - if (status) { - if (print->prt_file) - ib_fclose((IB_FILE *) print->prt_file); - QLI_env = old_env; - longjmp(QLI_env, status); - } + try { /* Finally, execute the query */ EXEC_execute(node->nod_arg[e_out_statement]); QLI_env = old_env; ib_fclose((IB_FILE *) print->prt_file); + + } // try + catch (...) { + if (print->prt_file) { + ib_fclose((IB_FILE *) print->prt_file); + } + QLI_env = old_env; + throw; + } } diff --git a/src/qli/gener.cpp b/src/qli/gener.cpp index 5dfa346fb9..02df7be879 100644 --- a/src/qli/gener.cpp +++ b/src/qli/gener.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: gener.cpp,v 1.3 2001-07-29 23:43:23 skywalker Exp $ +$Id: gener.cpp,v 1.4 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" diff --git a/src/qli/mov.cpp b/src/qli/mov.cpp index bebeaf8a29..d8bd6f2bbc 100644 --- a/src/qli/mov.cpp +++ b/src/qli/mov.cpp @@ -52,11 +52,6 @@ #define MOVQ_terminate MOVP_terminate #endif -typedef struct vary { - USHORT vary_length; - TEXT vary_string[1]; -} VARY; - #include "../qli/mov_proto.h" static void date_error(TEXT *, USHORT); diff --git a/src/remote/allr.cpp b/src/remote/allr.cpp index b7395a7501..f30abe7ff5 100644 --- a/src/remote/allr.cpp +++ b/src/remote/allr.cpp @@ -95,7 +95,7 @@ UCHAR* DLL_EXPORT ALLR_alloc(ULONG size) *status_vector = gds_arg_end; } - LONGJMP(*trdb->trdb_setjmp, gds_virmemexh); + Firebird::status_longjmp_error::raise(gds_virmemexh); return NULL; /* compiler silencer */ } @@ -138,7 +138,7 @@ BLK DLL_EXPORT ALLR_block(UCHAR type, ULONG count) } } - LONGJMP(*trdb->trdb_setjmp, gds_bug_check); + Firebird::status_longjmp_error::raise(gds_bug_check); } // Compute block length, recasting count to make sure the calculation diff --git a/src/remote/decne_proto.h b/src/remote/decne_proto.h deleted file mode 100644 index fdadb8b7d7..0000000000 --- a/src/remote/decne_proto.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * PROGRAM: JRD Remote Interface/Server - * MODULE: decne_proto.h - * DESCRIPTION: Prototpe header file for decnet.c - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy - * of the License at http://www.Inprise.com/IPL.html - * - * Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express - * or implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#ifndef _REMOTE_DECNE_PROTO_H_ -#define _REMOTE_DECNE_PROTO_H_ - -extern PORT DECNET_analyze (UCHAR *, SSHORT *, STATUS *, SSHORT); -extern PORT DECNET_connect (UCHAR *, struct packet *, STATUS *, int); - -#endif /* _REMOTE_DECNE_PROTO_H */ diff --git a/src/remote/decnet.cpp b/src/remote/decnet.cpp deleted file mode 100644 index 56963c68d9..0000000000 --- a/src/remote/decnet.cpp +++ /dev/null @@ -1,1242 +0,0 @@ -/* - * PROGRAM: JRD Remote Interface/Server - * MODULE: decnet.c - * DESCRIPTION: DECnet Communications module for VMS - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy - * of the License at http://www.Inprise.com/IPL.html - * - * Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express - * or implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#include "firebird.h" -#include descrip -#include iodef -#include nfbdef -#include msgdef - -#include "../jrd/ib_stdio.h" -#include "../remote/remote.h" -#include "../jrd/gds.h" -#include "../jrd/thd.h" -#include "../remote/decne_proto.h" -#include "../remote/remot_proto.h" -#include "../jrd/isc_proto.h" -#include "../jrd/sch_proto.h" - -#define OBJECT_NUMBER 128 -#define OBJECT_NAME "" -#define SERVER_NAME "ISC_SERVER" - -#define EVENT_FLAG 15 -#define MAX_DATA 1450 -#define BUFFER_SIZE MAX_DATA -#define MAX_SEQUENCE 256 - -typedef struct mbxmsg { - SSHORT msgtype; - SSHORT unit; - SCHAR name_count; - SCHAR name[1]; -} *MBXMSG; - -static int accept_connection(PORT, P_CNCT *); -static int accept_link(PORT, MBXMSG); -static PORT active_port(PORT); -static PORT alloc_port(PORT); -static PORT aux_connect(PORT, PACKET *, XDR_INT(*)()); -static PORT aux_request(PORT, PACKET *); -static void cleanup_port(PORT); -static int dnet_create(XDR *, PORT, UCHAR *, USHORT, enum xdr_op); -static XDR_INT dnet_destroy(XDR *); -static int dnet_endofrecord(XDR *, bool_t); -static int dnet_error(PORT, UCHAR *, int); -static bool_t dnet_getbytes(XDR *, SCHAR *, int); -static bool_t dnet_getlong(XDR *, SLONG *); -static u_int dnet_getpostn(XDR *); -static caddr_t dnet_inline(XDR *, u_int); -static bool_t dnet_putbytes(XDR *, SCHAR *, int); -static bool_t dnet_putlong(XDR *, SLONG *); -static bool_t dnet_read(XDR *); -static bool_t dnet_setpostn(XDR *, u_int); -static bool_t dnet_write(XDR *, bool_t); -static void disconnect(PORT); -static int packet_receive(PORT, UCHAR *, SSHORT, SSHORT *); -static int packet_send(PORT, UCHAR *, SSHORT); -static int process_connect(PORT); -static PORT receive(PORT, PACKET *); -static int send_full(PORT, PACKET *); -static int send_partial(PORT, PACKET *); -static int start_read(PORT, UCHAR *, SSHORT); -static void wait(USHORT *); -static int wait_and_test(PORT, TEXT *, int); - -static xdr_t::xdr_ops dnet_ops = { - dnet_getlong, - dnet_putlong, - dnet_getbytes, - dnet_putbytes, - dnet_getpostn, - dnet_setpostn, - dnet_inline, - dnet_destroy -}; - -static struct { - SCHAR nfb_type; - SLONG nfb_value; -} null_nfb = { -NFB$C_DECLNAME, 0}, nfb = { -NFB$C_DECLOBJ, OBJECT_NUMBER}; - -static SLONG maxmsg = 128, bufquo = 128; -static request_count; - - -PORT DECNET_analyze( - UCHAR * file_name; - SSHORT * file_length, - STATUS * status_vector; SSHORT uv_flag; { -/************************************** - * - * D E C N E T _ a n a l y z e - * - ************************************** - * - * Functional description - * Determine whether the file name has a "external!name". If so, - * establish an external connection to the node. - * - * If a connection is established, return a port block, otherwise - * return NULL. - * - **************************************/ -RDB rdb; -PORT port; -PACKET * packet; -P_CNCT * connect; -P_ATCH * attach; -SSHORT length, user_length; -UCHAR node_name[128], *p, *q, user_id[200], c; -TEXT buffer[64]; int local_status[20]; p_cnct::p_cnct_repeat * protocol; -/* Analyze the file name to see if a remote connection is required. If not, - quietly (sic) return. */ -/* Pick up node if, if present */ -p = node_name; -q = file_name; length = *file_length; while (q[0] != ':' || q[1] != ':') { -if (--length < 0 || p >= node_name + sizeof(node_name) - 1) -return NULL; c = *q++; *p++ = UPPER(c);} - -q += 2; *p = 0; length -= 2; *file_length = length; if (length) -do -*file_name++ = *q++; while (--length); *file_name = 0; -/* We need to establish a connection to a remote server. Allocate the necessary - blocks and get ready to go. */ -rdb = ALLOC(type_rdb); packet = &rdb->rdb_packet; -/* Pick up some user identification information */ -user_id[0] = CNCT_user; -p = user_id + 2; -ISC_get_user(p, 0, 0, 0, 0, 0, 0); -user_id[1] = (UCHAR) strlen(p); for (; *p; p++) -if (*p >= 'A' && *p <= 'Z') -* p = *p - 'A' + 'a'; -*p++ = CNCT_host; -p++; ISC_get_host(p, 64); p[-1] = (UCHAR) strlen((SCHAR *) p); for (; *p; p++) -if (*p >= 'A' && *p <= 'Z') -* p = *p - 'A' + 'a'; if (uv_flag) { -*p++ = CNCT_user_verification; *p++ = 0;} - -user_length = p - user_id; -/* Establish connection to server */ -connect = &packet->p_cnct; -packet->p_operation = op_connect; -connect->p_cnct_operation = op_attach; -connect->p_cnct_cversion = CONNECT_VERSION2; -connect->p_cnct_client = ARCHITECTURE; -connect->p_cnct_file.cstr_length = *file_length; -connect->p_cnct_file.cstr_address = file_name; -/* Note: prior to V3.1E a recievers could not in truth handle more - then 5 protocol descriptions, so we try them in chunks of 5 or less */ -/* If we want user verification, we can't speak anything less that version 7 */ -#ifdef SCROLLABLE_CURSORS -connect->p_cnct_count = 4; -#else -connect->p_cnct_count = 2; -#endif -connect->p_cnct_user_id.cstr_length = user_length; -connect->p_cnct_user_id.cstr_address = user_id; -protocol = connect->p_cnct_versions; -protocol->p_cnct_version = PROTOCOL_VERSION8; -protocol->p_cnct_architecture = arch_generic; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 2; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION8; -protocol->p_cnct_architecture = ARCHITECTURE; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; protocol->p_cnct_weight = 3; -#ifdef SCROLLABLE_CURSORS -++protocol; -protocol->p_cnct_version = PROTOCOL_SCROLLABLE_CURSORS; -protocol->p_cnct_architecture = arch_generic; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 4; -++protocol; -protocol->p_cnct_version = PROTOCOL_SCROLLABLE_CURSORS; -protocol->p_cnct_architecture = ARCHITECTURE; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; protocol->p_cnct_weight = 5; -#endif -/* If we can't talk to a server, punt. Let somebody else generate - an error. */ -if (!(port = DECNET_connect(node_name, packet, status_vector, 0))) { -ALLR_release(rdb); return NULL;} - -/* Get response packet from server. */ - -rdb->rdb_port = port; -port->port_context = rdb; -port->receive(packet); -if (packet->p_operation == op_reject && !uv_flag) { -disconnect(port); -packet->p_operation = op_connect; -connect->p_cnct_operation = op_attach; -connect->p_cnct_cversion = CONNECT_VERSION2; -connect->p_cnct_client = ARCHITECTURE; -connect->p_cnct_file.cstr_length = *file_length; -connect->p_cnct_file.cstr_address = file_name; -/* try again with next set of known protocols */ -connect->p_cnct_count = 5; -connect->p_cnct_user_id.cstr_length = user_length; -connect->p_cnct_user_id.cstr_address = user_id; -protocol = connect->p_cnct_versions; -protocol->p_cnct_version = PROTOCOL_VERSION5; -protocol->p_cnct_architecture = ARCHITECTURE; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_out_of_band; -protocol->p_cnct_weight = 2; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION6; -protocol->p_cnct_architecture = arch_generic; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 3; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION6; -protocol->p_cnct_architecture = ARCHITECTURE; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 4; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION7; -protocol->p_cnct_architecture = arch_generic; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 5; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION7; -protocol->p_cnct_architecture = ARCHITECTURE; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 6; -if (!(port = DECNET_connect(node_name, packet, status_vector, 0))) { -ALLR_release(rdb); return NULL;} - -/* Get response packet from server. */ - -rdb->rdb_port = port; -port->port_context = rdb; -port->receive(packet); -} - -if (packet->p_operation == op_reject && !uv_flag) { -disconnect(port); -packet->p_operation = op_connect; -connect->p_cnct_operation = op_attach; -connect->p_cnct_cversion = CONNECT_VERSION2; -connect->p_cnct_client = ARCHITECTURE; -connect->p_cnct_file.cstr_length = *file_length; -connect->p_cnct_file.cstr_address = file_name; -/* try again with next set of known protocols */ -connect->p_cnct_count = 4; -connect->p_cnct_user_id.cstr_length = user_length; -connect->p_cnct_user_id.cstr_address = user_id; -protocol = connect->p_cnct_versions; -protocol->p_cnct_version = PROTOCOL_VERSION3; -protocol->p_cnct_architecture = arch_generic; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 2; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION3; -protocol->p_cnct_architecture = ARCHITECTURE; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 3; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION4; -protocol->p_cnct_architecture = arch_generic; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 4; -++protocol; -protocol->p_cnct_version = PROTOCOL_VERSION4; -protocol->p_cnct_architecture = ARCHITECTURE; -protocol->p_cnct_min_type = ptype_rpc; -protocol->p_cnct_max_type = ptype_batch_send; -protocol->p_cnct_weight = 5; -if (!(port = DECNET_connect(node_name, packet, status_vector, 0))) { -ALLR_release(rdb); return NULL;} - -/* Get response packet from server. */ - -rdb->rdb_port = port; -port->port_context = rdb; -port->receive(packet); -} - -if (packet->p_operation != op_accept) { -*status_vector++ = gds_arg_gds; -*status_vector++ = gds__connect_reject; -*status_vector++ = 0; disconnect(port); return NULL;} - -port->port_protocol = packet->p_acpt.p_acpt_version; -/* once we've decided on a protocol, concatenate the version - string to reflect it... */ -sprintf(buffer, "%s/P%d", port->port_version->str_data, port->port_protocol); -ALLR_free(port->port_version); -port->port_version = REMOTE_make_string(buffer); -if (packet->p_acpt.p_acpt_architecture == ARCHITECTURE) -port->port_flags |= PORT_symmetric; -if (packet->p_acpt.p_acpt_type == ptype_rpc) -port->port_flags |= PORT_rpc; -if (packet->p_acpt.p_acpt_type != ptype_out_of_band) -port->port_flags |= PORT_no_oob; return port;} - - -PORT DECNET_connect(UCHAR * name, - PACKET * packet, STATUS * status_vector, int flags) { -/************************************** - * - * D E C N E T _ c o n n e c t - * - ************************************** - * - * Functional description - * Establish half of a communication link. If a connect packet is given, - * the connection is on behalf of a remote interface. Other the connect - * is for a server process. - * - **************************************/ -TEXT * p, *object_name, host[128], string[128]; -int *s, status, n, l, object_number; -USHORT channel, mbx_channel, iosb[4]; -PORT port; -struct dsc$descriptor_s desc, nfb_desc; -port = alloc_port(NULL); -port->port_status_vector = status_vector; -s = status_vector; *s++ = gds_arg_gds; *s = 0; -/* Handle debug protocol - if one is specified, we go by name else by OBJECT_NUMBER */ -if (name) { -strcpy(host, name); for (p = host; *p;) -if (*p++ == '/') { -p[-1] = 0; name = host; break;} -object_name = p; object_number = (*object_name) ? 0 : OBJECT_NUMBER;} - -/* Handle outgoing connections */ - -if (packet) { -sprintf(string, "%s::\"%d=%s\"", name, object_number, object_name); -ISC_make_desc(string, &desc, 0); -status = sys$assign(&desc, &channel, NULL, NULL); if (!(status & 1)) { -dnet_error(port, "sys$assign", status); return NULL;} -port->port_handle = channel; send_full(port, packet); return port;} - -/* Now handle incoming connections. Handle single client case first */ - -if (!(flags & SRVR_multi_client)) { -ISC_make_desc("SYS$NET", &desc, 0); -status = sys$assign(&desc, &channel, NULL, NULL); if (!(status & 1)) { -dnet_error(port, "sys$assign", status); return NULL;} -port->port_server_flags |= SRVR_server; -port->port_handle = channel; return port;} - -/* We're supposed to be a multi-client server -- take our best shot */ - -ISC_make_desc("_NET:", &desc, 0); -status = lib$asn_wth_mbx(&desc, &maxmsg, &bufquo, &channel, &mbx_channel); -if (!(status & 1)) { -dnet_error(port, "lib$asn_wth_mbx", status); return NULL;} - -ISC_make_desc(&nfb, &nfb_desc, sizeof(nfb)); status = sys$qio(EVENT_FLAG, /* Event flag */ - channel, /* Channel */ - IO$_ACPCONTROL, /* Function */ - port->port_iosb, /* IO status block */ - gds__completion_ast, /* AST address */ - iosb, /* AST parameter */ - &nfb_desc, /* P1 (buffer) */ - NULL, /* P2 (length) */ - NULL, /* P3 (virtual block) */ - NULL, NULL, - NULL); -if (!wait_and_test(port, "qio/acpcontrol", status)) -return NULL; port->port_server_flags |= SRVR_server | SRVR_multi_client; -port->port_handle = mbx_channel; port->port_channel = channel; -if (!start_read(port, port->port_buffer, maxmsg)) -return NULL; return port;} - - -static int accept_connection(PORT port, P_CNCT * connect) { -/************************************** - * - * a c c e p t _ c o n n e c t i o n - * - ************************************** - * - * Functional description - * Accept an incoming request for connection. This is purely a lower - * level handshaking function, and does not constitute the server - * response for protocol selection. - * - **************************************/ - -return TRUE;} - - -static int accept_link(PORT port, MBXMSG msg) { -/************************************** - * - * a c c e p t _ l i n k - * - ************************************** - * - * Functional description - * Accept a new logical link. Return new channel number - * or NULL. - * - **************************************/ -TEXT * p, stuff[32]; -PORT new_port; -int status; -USHORT channel, iosb[4]; -struct dsc$descriptor_s desc; -ISC_make_desc("_NET:", &desc, 0); -status = sys$assign(&desc, &channel, NULL, NULL); if (!(status & 1)) -return dnet_error(port, "sys$assign", status); -p = msg->name + msg->name_count; -desc.dsc$w_length = *p; desc.dsc$a_pointer = p + 1; -status = sys$qio(EVENT_FLAG, /* Event flag */ - channel, /* Channel */ - IO$_ACCESS, /* Function */ - iosb, /* IO status block */ - gds__completion_ast, /* AST address */ - NULL, /* AST parameter */ - NULL, /* P1 (buffer) */ - &desc, /* P2 (length) */ - NULL, /* P3 (virtual block) */ - NULL, - NULL, - NULL); -if (status & 1) { -wait(iosb); status = iosb[0];} - -if (!(status & 1)) -return dnet_error(port, "sys$assign", status); return channel;} - - -static PORT active_port(PORT port) { -/************************************** - * - * a c t i v e _ p o r t - * - ************************************** - * - * Functional description - * Return the address of an active port (i.e. read complete) - * or NULL (nothing complete). - * - **************************************/ - -if (port->port_iosb[0]) -return port; for (port = port->port_clients; port; port = port->port_next) -if (port->port_iosb[0]) -return port; return NULL;} - - -static PORT alloc_port(PORT parent) { -/************************************** - * - * a l l o c _ p o r t - * - ************************************** - * - * Functional description - * Allocate a port block, link it in to parent (if there is a parent), - * and initialize input and output XDR streams. - * - **************************************/ -UCHAR * message; -PORT port; -USHORT l; -UCHAR buffer[256]; -l = (parent && (parent->port_server_flags & SRVR_multi_client)) ? -BUFFER_SIZE * 3 : BUFFER_SIZE * 2; -port = ALLOCV(type_port, l); -port->port_type = port_decnet; -port->port_state = state_pending; -ISC_get_host(buffer, sizeof(buffer)); -port->port_host = REMOTE_make_string(buffer); -sprintf(buffer, "DECnet (%s)", port->port_host->str_data); -port->port_version = REMOTE_make_string(buffer); if (parent) { -port->port_parent = parent; -port->port_next = parent->port_clients; -parent->port_clients = port; -port->port_handle = parent->port_handle; -port->port_server = parent->port_server; -port->port_server_flags = parent->port_server_flags;} - -message = port->port_buffer; -port->port_accept = &accept_connection; -port->port_disconnect = &disconnect; -port->port_receive_packet = &receive; -port->port_send_packet = &send_full; -port->port_send_partial = &send_partial; -port->port_connect = aux_connect; -port->port_request = aux_request; -port->port_buff_size = BUFFER_SIZE; -dnet_create(&port->port_send, port, - &port->port_buffer[BUFFER_SIZE], BUFFER_SIZE, - XDR_ENCODE); -dnet_create(&port->port_receive, port, port->port_buffer, 0, - XDR_DECODE); return port;} - - -static PORT aux_connect(PORT port, PACKET * packet, XDR_INT(*ast) ()) { -/************************************** - * - * a u x _ c o n n e c t - * - ************************************** - * - * Functional description - * Try to establish an alternative connection. Somebody has already - * done a successfull connect request ("packet" contains the response). - * - **************************************/ -P_RESP * response; -P_REQ * request; -MBXMSG msg; -int n, l, arg, status; -USHORT channel; -PORT new_port; UCHAR buffer[128], *p; struct dsc$descriptor_s desc; -/* If this is a server, we're got an auxiliary connection. Accept it */ -if (port->port_server_flags) { -if (!start_read(port, buffer, sizeof(buffer))) -return NULL; if (!wait_and_test(port, "qio/readvblk", 1)) -return NULL; -channel = accept_link(port, buffer); -sys$dassgn(port->port_channel); -if (!channel) -return NULL; -port->port_handle = channel; -port->port_flags |= PORT_async; port->port_iosb[0] = 0; return port;} - -port->port_async = new_port = alloc_port(port->port_parent); -new_port->port_flags |= PORT_async; -response = &packet->p_resp; -request = &packet->p_req; -ISC_make_desc(response->p_resp_data.cstr_address, &desc, - response->p_resp_data.cstr_length); -status = sys$assign(&desc, &channel, NULL, NULL); if (!(status & 1)) { -dnet_error(port, "sys$assign", status); return NULL;} - -new_port->port_handle = channel; -new_port->port_flags = port->port_flags & PORT_no_oob; return new_port;} - - -static PORT aux_request(PORT port, PACKET * packet) { -/************************************** - * - * a u x _ r e q u e s t - * - ************************************** - * - * Functional description - * A remote interface has requested the server prepare an auxiliary - * connection; the server calls aux_request to set up the connection. - * - **************************************/ -PORT parent, new_port; -P_RESP * response; -int n, length, status, pid; -USHORT channel, mbx_channel; -TEXT task_name[32], *ncb; -struct dsc$descriptor_s desc, nfb_desc; -ISC_make_desc("_NET:", &desc, 0); -status = lib$asn_wth_mbx(&desc, &maxmsg, &bufquo, &channel, &mbx_channel); -if (!(status & 1)) { -dnet_error(port, "sys$assign", status); return NULL;} - -port->port_async = new_port = alloc_port(port->port_parent); -new_port->port_server_flags = port->port_server_flags; -new_port->port_handle = mbx_channel; -new_port->port_channel = channel; -new_port->port_flags = port->port_flags & PORT_no_oob; -pid = getpid(); -ncb = new_port->port_buffer; -sprintf(task_name, "ISC_%X_%d", pid, ++request_count); -sprintf(ncb, "%s::\"TASK=%s\"", port->port_host->str_data, task_name); -ISC_make_desc(task_name, &desc, 0); -ISC_make_desc(&null_nfb, &nfb_desc, sizeof(null_nfb)); status = sys$qio(EVENT_FLAG, /* Event flag */ - channel, /* Channel */ - IO$_ACPCONTROL, /* Function */ - new_port->port_iosb, /* IO status block */ - gds__completion_ast, /* AST address */ - NULL, /* AST parameter */ - &nfb_desc, /* P1 (buffer) */ - &desc, /* P2 (length) */ - NULL, /* P3 (virtual block) */ - NULL, - NULL, - NULL); -if (!wait_and_test(new_port, "qio/acpcontrol", status)) -return NULL; response = &packet->p_resp; -response->p_resp_data.cstr_address = ncb; -response->p_resp_data.cstr_length = strlen(ncb); return new_port;} - - -static dnet_create(XDR * xdrs, - PORT port, - UCHAR * buffer, USHORT length, enum xdr_op x_op) { -/************************************** - * - * d n e t _ c r e a t e - * - ************************************** - * - * Functional description - * Initialize an XDR stream for Apollo mailboxes. - * - **************************************/ - -xdrs->x_public = port; -xdrs->x_base = xdrs->x_private = buffer; -xdrs->x_handy = length; -xdrs->x_ops = &dnet_ops; xdrs->x_op = x_op; return TRUE;} - - -static XDR_INT dnet_destroy(XDR * xdrs) { -/************************************** - * - * d n e t _ d e s t r o y - * - ************************************** - * - * Functional description - * Destroy a stream. A no-op. - * - **************************************/ -} - - -static int dnet_endofrecord(XDR * xdrs, bool_t flushnow) { -/************************************** - * - * d n e t _ e n d o f r e c o r d - * - ************************************** - * - * Functional description - * Write out the rest of a record. - * - **************************************/ - -return dnet_write(xdrs, flushnow);} - - -static int dnet_error(PORT port, UCHAR * operation, int status) { -/************************************** - * - * d n e t _ e r r o r - * - ************************************** - * - * Functional description - * An I/O error has occurred. If a status vector is present, - * generate an error return. In any case, return NULL, which - * is used to indicate and error. - * - **************************************/ -RDB rdb; -int *status_vector; -port->port_flags |= PORT_broken; -port->port_state = state_broken; -if (rdb = port->port_context) status_vector = rdb->rdb_status_vector; -else -status_vector = port->port_status_vector; if (status_vector) { -*status_vector++ = gds_arg_gds; -*status_vector++ = gds__io_error; -*status_vector++ = gds_arg_string; -*status_vector++ = operation; -*status_vector++ = gds_arg_string; -*status_vector++ = "DECnet connection"; if (status) { -*status_vector++ = gds_arg_vms; *status_vector++ = status;} -*status_vector++ = 0;} - -return NULL;} - - -static bool_t dnet_getbytes(XDR * xdrs, SCHAR * buff, int count) { -/************************************** - * - * d n e t _ g e t b y t e s - * - ************************************** - * - * Functional description - * Get a bunch of bytes from a memory stream if it fits. - * - **************************************/ -SLONG bytecount = count; -/* Use memcpy to optimize bulk transfers. */ -while (bytecount > sizeof(GDS_QUAD)) { -if (xdrs->x_handy >= bytecount) { -memcpy(buff, xdrs->x_private, bytecount); -xdrs->x_private += bytecount; xdrs->x_handy -= bytecount; return TRUE;} -else -{ -if (xdrs->x_handy > 0) { -memcpy(buff, xdrs->x_private, xdrs->x_handy); -xdrs->x_private += xdrs->x_handy; -buff += xdrs->x_handy; bytecount -= xdrs->x_handy; xdrs->x_handy = 0;} -if (!dnet_read(xdrs)) -return FALSE;} -} - -/* Scalar values and bulk transfer remainder fall thru - to be moved byte-by-byte to avoid memcpy setup costs. */ - -if (!bytecount) -return TRUE; if (bytecount && xdrs->x_handy >= bytecount) { -xdrs->x_handy -= bytecount; -do -*buff++ = *xdrs->x_private++; while (--bytecount); return TRUE;} - -while (--bytecount >= 0) { -if (!xdrs->x_handy && !dnet_read(xdrs)) -return FALSE; *buff++ = *xdrs->x_private++; --xdrs->x_handy;} - -return TRUE;} - - -static bool_t dnet_getlong(XDR * xdrs, SLONG * lp) { -/************************************** - * - * d n e t _ g e t l o n g - * - ************************************** - * - * Functional description - * Fetch a longword into a memory stream if it fits. - * - **************************************/ -SLONG l; if (!(*xdrs->x_ops->x_getbytes) (xdrs, &l, 4)) -return FALSE; *lp = ntohl(l); return TRUE;} - - -static u_int dnet_getpostn(XDR * xdrs) { -/************************************** - * - * d n e t _ g e t p o s t n - * - ************************************** - * - * Functional description - * Get the current position (which is also current length) from stream. - * - **************************************/ - -return xdrs->x_private - xdrs->x_base;} - - -static caddr_t dnet_inline(XDR * xdrs, u_int bytecount) { -/************************************** - * - * d n e t _ i n l i n e - * - ************************************** - * - * Functional description - * Return a pointer to somewhere in the buffer. - * - **************************************/ - -if (bytecount > xdrs->x_handy) -return FALSE; return xdrs->x_base + bytecount;} - - -static bool_t dnet_putbytes(XDR * xdrs, SCHAR * buff, int count) { -/************************************** - * - * d n e t _ p u t b y t e s - * - ************************************** - * - * Functional description - * Put a bunch of bytes to a memory stream if it fits. - * - **************************************/ -SLONG bytecount = count; -/* Use memcpy to optimize bulk transfers. */ -while (bytecount > sizeof(GDS_QUAD)) { -if (xdrs->x_handy >= bytecount) { -memcpy(xdrs->x_private, buff, bytecount); -xdrs->x_private += bytecount; xdrs->x_handy -= bytecount; return TRUE;} -else -{ -if (xdrs->x_handy > 0) { -memcpy(xdrs->x_private, buff, xdrs->x_handy); -xdrs->x_private += xdrs->x_handy; -buff += xdrs->x_handy; bytecount -= xdrs->x_handy; xdrs->x_handy = 0;} -if (!dnet_write(xdrs)) -return FALSE;} -} - -/* Scalar values and bulk transfer remainder fall thru - to be moved byte-by-byte to avoid memcpy setup costs. */ - -if (!bytecount) -return TRUE; if (bytecount && xdrs->x_handy >= bytecount) { -xdrs->x_handy -= bytecount; -do -*xdrs->x_private++ = *buff++; while (--bytecount); return TRUE;} - -while (--bytecount >= 0) { -if (xdrs->x_handy <= 0 && !dnet_write(xdrs)) -return FALSE; --xdrs->x_handy; *xdrs->x_private++ = *buff++;} - -return TRUE;} - - -static bool_t dnet_putlong(XDR * xdrs, SLONG * lp) { -/************************************** - * - * d n e t _ p u t l o n g - * - ************************************** - * - * Functional description - * Fetch a longword into a memory stream if it fits. - * - **************************************/ -SLONG l; l = htonl(*lp); return (*xdrs->x_ops->x_putbytes) (xdrs, &l, 4);} - - -static bool_t dnet_read(XDR * xdrs) { -/************************************** - * - * d n e t _ r e a d - * - ************************************** - * - * Functional description - * Read a buffer full of data. If we receive a bad packet, - * send the moral equivalent of a NAK and retry. ACK all - * partial packets. Don't ACK the last packet -- the next - * message sent will handle this. - * - **************************************/ -PORT port; -SSHORT length; -UCHAR * p, *end; -port = xdrs->x_public; p = xdrs->x_base; end = p + BUFFER_SIZE; -/* If buffer is not completely empty, slide down what what's left */ -if (xdrs->x_handy > 0) { -memmove(p, xdrs->x_private, xdrs->x_handy); p += xdrs->x_handy;} - -/* If an ACK is pending, do an ACK. The alternative is deadlock. */ - -/* -if (port->port_flags & PORT_pend_ack) - if (!packet_send (port, NULL, 0)) - return FALSE; -*/ - -while (TRUE) { -length = end - p; if (!packet_receive(port, p, length, &length)) { -return FALSE; if (!packet_send(port, NULL, 0)) -return FALSE; continue;} -if (length >= 0) { -p += length; break;} -p -= length; if (!packet_send(port, NULL, 0)) -return FALSE;} - -port->port_flags |= PORT_pend_ack; -xdrs->x_handy = p - xdrs->x_base; xdrs->x_private = xdrs->x_base; return TRUE;} - - -static bool_t dnet_setpostn(XDR * xdrs, u_int bytecount) { -/************************************** - * - * d n e t _ s e t p o s t n - * - ************************************** - * - * Functional description - * Set the current position (which is also current length) from stream. - * - **************************************/ - -if (bytecount > xdrs->x_handy) -return FALSE; xdrs->x_private = xdrs->x_base + bytecount; return TRUE;} - - -static bool_t dnet_write(XDR * xdrs, bool_t end_flag) { -/************************************** - * - * d n e t _ w r i t e - * - ************************************** - * - * Functional description - * Write a buffer fulll of data. If the end_flag isn't set, indicate - * that the buffer is a fragment, and reset the XDR for another buffer - * load. - * - **************************************/ -UCHAR aux_buffer[BUFFER_SIZE], *p; -UCHAR buffer[BUFFER_SIZE]; PORT port; SSHORT l, length, l2; -/* Encode the data portion of the packet */ -port = xdrs->x_public; p = xdrs->x_base; length = xdrs->x_private - p; -/* Send data in manageable hunks. If a packet is partial, indicate - that with a negative length. A positive length marks the end. */ -p = xdrs->x_base; while (length) { -port->port_misc1 = (port->port_misc1 + 1) % MAX_SEQUENCE; -l = MIN(length, MAX_DATA); length -= l; while (TRUE) { -if (!packet_send(port, p, (length) ? -l : l)) -return FALSE; -/* - if (packet_receive (port, aux_buffer, sizeof (aux_buffer), &l2)) - */ -break;} -p += l;} - -xdrs->x_private = xdrs->x_base; xdrs->x_handy = BUFFER_SIZE; return TRUE; -/* If the other end has not piggy-backed the next packet, we're done. */ -if (!l2) -return TRUE; -/* We've got a piggy-backed response. If the packet is partial, - send an ACK for part we did receive. */ -p = aux_buffer; while (l2 < 0) { -if (!packet_send(port, NULL, 0)) -return FALSE; -p -= l2; -length = aux_buffer + sizeof(aux_buffer) - p; -if (!packet_receive(port, p, length, &l2)) { -p += l2; continue;} -} - -length = p - aux_buffer + l2; -/* Now we're got a encode glump ready to stuff into the read buffer. - Unfortunately, if we just add it to the read buffer, we will shortly - overflow the buffer. To avoid this, "scrumpf down" the active bits - in the read buffer, then add out stuff at the end. */ -xdrs = &port->port_receive; -p = xdrs->x_base; -if (xdrs->x_handy && p != xdrs->x_private) -memmove(p, xdrs->x_private, xdrs->x_handy); -p += xdrs->x_handy; xdrs->x_private = xdrs->x_base; -/* -xdrs->x_handy += JAP_decode (aux_buffer, length, p); -*/ -port->port_flags |= PORT_pend_ack; return TRUE;} - - -static void disconnect(PORT port) { -/************************************** - * - * d i s c o n n e c t - * - ************************************** - * - * Functional description - * Break a remote connection. - * - **************************************/ -PORT parent, *ptr; -/* If this is a sub-port, unlink it from it's parent */ -if (parent = port->port_parent) { -if (port->port_async) { -disconnect(port->port_async); port->port_async = NULL;} -for (ptr = &parent->port_clients; *ptr; ptr = &(*ptr)->port_next) -if (*ptr == port) { -*ptr = port->port_next; if (ptr == &parent->port_clients) -parent->port_next = *ptr; break;} -} -else -if (port->port_async) { -#ifdef MULTI_THREAD -port->port_async->port_flags |= PORT_disconnect; -#else -disconnect(port->port_async); port->port_async = NULL; -#endif -} - -sys$dassgn(port->port_handle); cleanup_port(port);} -^L static void cleanup_port(PORT port) { -/************************************** - * - * c l e a n u p _ p o r t - * - ************************************** - * - * Functional description - * Walk through the port structure freeing - * allocated memory and then free the port. - * - **************************************/ - -if (port->port_version) -ALLR_free((UCHAR *) port->port_version); if (port->port_host) -ALLR_free((UCHAR *) port->port_host); -#ifdef DEBUG_XDR_MEMORY -if (port->port_packet_vector) -ALLR_free((UCHAR *) port->port_packet_vector); -#endif -ALLR_release((UCHAR *) port); return;} - - -static int packet_receive(PORT port, - UCHAR * buffer, - SSHORT buffer_length, SSHORT * length) { -/************************************** - * - * p a c k e t _ r e c e i v e - * - ************************************** - * - * Functional description - * Receive a packet and pass on it's goodness. If it's good, - * return TRUE and the reported length of the packet, and update - * the receive sequence number. If it's bad, return FALSE. If it's - * a duplicate message, just ignore it. - * - **************************************/ -UCHAR c, aux_buffer[1024], *p; USHORT l, n; int status, flags; -/* If this is a multi-client case, as the message has already been - received, there is nothing to do */ -flags = port->port_flags; if (port->port_server_flags & SRVR_multi_client) { -while (!(status = port->port_iosb[0])) -wait(port->port_iosb); if (status & 1) { -l = port->port_iosb[1]; -p = port->port_buffer + 2 * BUFFER_SIZE; -memcpy(buffer, p, l); -*length = l; start_read(port, p, BUFFER_SIZE); return TRUE;} -} -else -{ -if (!start_read(port, buffer, buffer_length)) -return NULL; wait(port->port_iosb); status = port->port_iosb[0];} - -if (!(status & 1)) { -if (flags & PORT_async) -return FALSE; return dnet_error(port, "sys$qio/io$_readvblk", status);} - -*length = port->port_iosb[1]; return TRUE;} - - -static int packet_send(PORT port, UCHAR * data, SSHORT length) { -/************************************** - * - * p a c k e t _ s e n d - * - ************************************** - * - * Functional description - * Send some data on it's way. - * - **************************************/ -int status; SSHORT iosb[4]; status = sys$qio(EVENT_FLAG, /* Event flag */ - port->port_handle, /* Channel */ - IO$_WRITEVBLK, /* Function */ - iosb, /* IO status block */ - gds__completion_ast, /* AST address */ - NULL, /* AST parameter */ - data, /* P1 (buffer) */ - length, /* P2 (length) */ - NULL, /* P3 (virtual block) */ - NULL, NULL, NULL); -if (status & 1) { -wait(iosb); status = iosb[0];} - -if (!(status & 1)) -return dnet_error(port, "sys$qio/io$_writevblk", status); -port->port_flags &= ~PORT_pend_ack; return TRUE;} - - -static int process_connect(PORT port) { -/************************************** - * - * p r o c e s s _ c o n n e c t - * - ************************************** - * - * Functional description - * We've got a message on the mailbox. Find out - * what's up and doing something appropriate. - * - **************************************/ -MBXMSG msg; -PORT new_port; -int status; -USHORT channel, iosb[4]; -msg = (MSG) port->port_buffer; switch (msg->msgtype) { -case MSG$_CONNECT: -if (!(channel = accept_link(port, msg))) -return NULL; -new_port = alloc_port(port); -new_port->port_handle = channel; -start_read(new_port, new_port->port_buffer + 2 * BUFFER_SIZE, BUFFER_SIZE); -break;} - -start_read(port, port->port_buffer, maxmsg);} - - -static PORT receive(PORT port, PACKET * packet) { -/************************************** - * - * r e c e i v e - * - ************************************** - * - * Functional description - * Receive a message from a port or clients of a port. If the process - * is a server and a connection request comes in, generate a new port - * block for the client. - * - **************************************/ -PORT active; int status; USHORT iosb[4]; -/* Single client case is MUCH easier */ -if (!(port->port_server_flags & SRVR_multi_client)) { -if (!xdr_protocol(&port->port_receive, packet)) -return NULL; return port;} - -/* Worry about multi-client case */ - -for (;;) { -if (!(active = active_port(port))) { -THREAD_EXIT; gds__thread_wait(active_port, port); THREAD_ENTER; continue;} -if (active != port) { -if (!xdr_protocol(&active->port_receive, packet)) -packet->p_operation = op_exit; return active;} -process_connect(port);} - -return NULL;} - - -static int send_full(PORT port, PACKET * packet) { -/************************************** - * - * s e n d _ f u l l - * - ************************************** - * - * Functional description - * Send a packet across a port to another process. - * - **************************************/ - -if (!xdr_protocol(&port->port_send, packet)) -return FALSE; return dnet_endofrecord(&port->port_send, TRUE);} - - -static int send_partial(PORT port, PACKET * packet) { -/************************************** - * - * s e n d _ p a r t i a l - * - ************************************** - * - * Functional description - * Send a packet across a port to another process. - * - **************************************/ - -return xdr_protocol(&port->port_send, packet);} - - -static int start_read(PORT port, UCHAR * buffer, SSHORT buffer_length) { -/************************************** - * - * s t a r t _ r e a d - * - ************************************** - * - * Functional description - * Start an asynchronous read on a port. - * - **************************************/ -int status; status = sys$qio(EVENT_FLAG, /* Event flag */ - port->port_handle, /* Channel */ - IO$_READVBLK, /* Function */ - port->port_iosb, /* IO status block */ - gds__completion_ast, /* AST address */ - NULL, /* AST parameter */ - buffer, /* P1 (buffer) */ - buffer_length, /* P2 (length) */ - NULL, /* P3 (virtual block) */ - NULL, NULL, NULL); if (!(status & 1)) { -if (port->port_flags & PORT_async) -return FALSE; return dnet_error(port, "sys$qio/io$_readvblk", status);} - -return TRUE;} - - -static void wait(USHORT * iosb) { -/************************************** - * - * w a i t - * - ************************************** - * - * Functional description - * Wait for something to happen. - * - **************************************/ - -if (iosb[0]) -return; THREAD_EXIT; ISC_wait(iosb, EVENT_FLAG); THREAD_ENTER;} - - -static int wait_and_test(PORT port, TEXT * string, int status) { -/************************************** - * - * w a i t _ a n d _ t e s t - * - ************************************** - * - * Functional description - * Do status checking and waiting associated with a QIO. If - * anything fails, issue error and return FALSE/NULL. - * - **************************************/ - -if (status & 1) { -wait(port->port_iosb); status = port->port_iosb[0];} - -if (!(status & 1)) -return dnet_error(port, string, status); return TRUE;} diff --git a/src/remote/decnet_server.cpp b/src/remote/decnet_server.cpp deleted file mode 100644 index 06e24feb72..0000000000 --- a/src/remote/decnet_server.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * PROGRAM: JRD Remote Interface/Server - * MODULE: DECNET_server.c - * DESCRIPTION: DECNET server for VMS - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy - * of the License at http://www.Inprise.com/IPL.html - * - * Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express - * or implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#include "firebird.h" -#include "../jrd/common.h" -#include "../jrd/license.h" -#include "../jrd/thd.h" -#include "../remote/remote.h" -#include "../remote/decne_proto.h" -#include "../remote/serve_proto.h" -#include "../jrd/gds_proto.h" - - -int main( int argc, char **argv) -{ -/************************************** - * - * m a i n - * - ************************************** - * - * Functional description - * Run an asyncronous server. - * - **************************************/ - int *port; - int debug, flag, channel, standalone, multi_threaded; - STATUS status_vector[20]; - TEXT c, *p, **end, protocol[128]; - SLONG debug_value; - - argc = VMS_parse(&argv, argc); - end = argc + argv; - argv++; - debug = standalone = flag = FALSE; - channel = 0; - protocol[0] = 0; - multi_threaded = FALSE; - - while (argv < end) { - p = *argv++; - if (*p++ = '-') - while (c = *p++) - switch (UPPER(c)) { - case 'D': - flag |= SRVR_debug; - debug = standalone = TRUE; - break; - - case 'M': - flag |= SRVR_multi_client; - standalone = TRUE; - break; - - case 'S': - standalone = TRUE; - break; - - case 'I': - standalone = FALSE; - break; - - case 'T': - multi_threaded = TRUE; - break; - - case 'U': - multi_threaded = FALSE; - break; - - case 'P': - sprintf(protocol, "/%s", *argv++); - break; - - case 'Z': - ib_printf("Interbase DECnet server version %s\n", - GDS_VERSION); - exit(FINI_OK); - } - } - - THREAD_ENTER; - port = DECNET_connect(protocol, NULL, status_vector, flag); - THREAD_EXIT; - - if (!port) { - gds__print_status(status_vector); - exit(FINI_ERROR); - } - - if (multi_threaded) - SRVR_multi_thread(port, flag); - else - SRVR_main(port, flag); - - exit(FINI_OK); -} diff --git a/src/remote/dnet.cpp b/src/remote/dnet.cpp deleted file mode 100644 index de342dfe6c..0000000000 --- a/src/remote/dnet.cpp +++ /dev/null @@ -1,1512 +0,0 @@ -/* - * PROGRAM: JRD Remote Interface/Server - * MODULE: dnet.c - * DESCRIPTION: DECnet Communications module for ULTRIX - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy - * of the License at http://www.Inprise.com/IPL.html - * - * Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express - * or implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#include "firebird.h" -#include -#include -#include -#include -#include "../jrd/ib_stdio.h" -#include -#include "../jrd/gds.h" -#include -#include -#include "../remote/remote.h" -#include "../remote/dnet_proto.h" -#include "../remote/remot_proto.h" -#include "../jrd/isc_proto.h" - -#define OBJECT_NUMBER 128 -#define OBJECT_NAME "#128" - -#define MAX_DATA 1450 -#define BUFFER_SIZE MAX_DATA -#define MAX_SEQUENCE 256 - -extern int errno; - -static int accept_connection(PORT, P_CNCT *); -static PORT alloc_port(PORT); -static PORT aux_connect(PORT, PACKET *, XDR_INT(*)()); -static PORT aux_request(PORT, PACKET *); -static void cleanup_port(PORT); -static int check_host(PORT); -static void disconnect(PORT); -static XDR_INT dnet_destroy(XDR *); -static int dnet_error(PORT, TEXT *, int); -static bool_t dnet_getbytes(XDR *, SCHAR *, int); -static bool_t dnet_getlong(XDR *, SLONG *); -static u_int dnet_getpostn(XDR *); -static void dnet_handler(PORT); -static caddr_t dnet_inline(XDR *, u_int); -static bool_t dnet_putbytes(XDR *, SCHAR *, int); -static bool_t dnet_putlong(XDR *, SLONG *); -static bool_t dnet_read(XDR *); -static bool_t dnet_setpostn(XDR *, u_int); -static bool_t dnet_write(XDR *, bool_t); -static int packet_receive(PORT, UCHAR *, SSHORT, SSHORT *); -static int packet_send(PORT, UCHAR *, SSHORT); -static PORT receive(PORT, PACKET *); -static int send_full(PORT, PACKET *); -static int send_partial(PORT, PACKET *); -static int xdrdnet_create(XDR *, PORT, UCHAR *, USHORT, enum xdr_op); -static int xdrdnet_endofrecord(XDR *, bool_t); - -static xdr_t::xdr_ops dnet_ops = { - dnet_getlong, - dnet_putlong, - dnet_getbytes, - dnet_putbytes, - dnet_getpostn, - dnet_setpostn, - dnet_inline, - dnet_destroy -}; - -static int request_count; - - -PORT DNET_analyze( - UCHAR * file_name, - SSHORT * file_length, - STATUS * status_vector, SSHORT uv_flag) -{ -/************************************** - * - * D N E T _ a n a l y z e - * - ************************************** - * - * Functional description - * Determine whether the file name has a "external!name". If so, - * establish an external connection to the node. - * - * If a connection is established, return a port block, otherwise - * return NULL. - * - **************************************/ - RDB rdb; - PORT port; - PACKET *packet; - P_CNCT *connect; - P_ATCH *attach; - struct passwd *pw; - SSHORT uid, length, user_length; - UCHAR node_name[ND_MAXNODE + 1 + OB_MAXNAME], *p, *q, user_id[128]; - STATUS local_status[20]; - p_cnct::p_cnct_repeat * protocol; - -/* Analyze the file name to see if a remote connection is required. If not, - quietly (sic) return. */ - -/* Pick up node if, if present */ - - p = node_name; - q = file_name; - length = *file_length; - - while (q[0] != ':' || q[1] != ':') { - if (--length < 0 || p >= node_name + sizeof(node_name) - 1) - return NULL; - *p++ = *q++; - } - - q += 2; - *p = 0; - length -= 2; - *file_length = length; - - if (length) - do - *file_name++ = *q++; - while (--length); - - *file_name = 0; - -/* We need to establish a connection to a remote server. Allocate the necessary - blocks and get ready to go. */ - - rdb = (RDB) ALLOC(type_rdb); - packet = &rdb->rdb_packet; - -/* Pick up some user identification information */ - - user_id[0] = CNCT_user; - p = user_id + 2; - ISC_get_user(p, 0, 0, 0, 0, 0, 0); - user_id[1] = user_length = strlen(p); - user_length += 2; - - for (; *p; p++) - if (*p >= 'A' && *p <= 'Z') - *p = *p - 'A' + 'a'; - -/* Establish connection to server */ - - connect = &packet->p_cnct; - packet->p_operation = op_connect; - connect->p_cnct_operation = op_attach; - connect->p_cnct_cversion = CONNECT_VERSION2; - connect->p_cnct_client = ARCHITECTURE; - connect->p_cnct_file.cstr_length = *file_length; - connect->p_cnct_file.cstr_address = file_name; - -/* Note: prior to V3.1E a recievers could not in truth handle more - then 5 protocol descriptions, so we try them in chunks of 5 or less */ - -#ifdef SCROLLABLE_CURSORS - connect->p_cnct_count = 4; -#else - connect->p_cnct_count = 2; -#endif - connect->p_cnct_user_id.cstr_length = user_length; - connect->p_cnct_user_id.cstr_address = user_id; - - protocol = connect->p_cnct_versions; - - protocol->p_cnct_version = PROTOCOL_VERSION8; - protocol->p_cnct_architecture = arch_generic; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 2; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_VERSION8; - protocol->p_cnct_architecture = ARCHITECTURE; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 3; - -#ifdef SCROLLABLE_CURSORS - ++protocol; - - protocol->p_cnct_version = PROTOCOL_SCROLLABLE_CURSORS; - protocol->p_cnct_architecture = arch_generic; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 4; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_SCROLLABLE_CURSORS; - protocol->p_cnct_architecture = ARCHITECTURE; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 5; -#endif - -/* If we can't talk to a server, punt. Let somebody else generate - an error. */ - - if (!(port = DNET_connect(node_name, packet, status_vector, FALSE))) { - ALLR_release(rdb); - return NULL; - } - -/* Get response packet from server. */ - - rdb->rdb_port = port; - port->port_context = rdb; - port->receive(packet); - - if (packet->p_operation == op_reject) { - disconnect(port); - packet->p_operation = op_connect; - connect->p_cnct_operation = op_attach; - connect->p_cnct_cversion = CONNECT_VERSION2; - connect->p_cnct_client = ARCHITECTURE; - connect->p_cnct_file.cstr_length = *file_length; - connect->p_cnct_file.cstr_address = file_name; - - /* try again with next set of known protocols */ - - connect->p_cnct_count = 4; - connect->p_cnct_user_id.cstr_length = user_length; - connect->p_cnct_user_id.cstr_address = user_id; - - protocol = connect->p_cnct_versions; - - protocol->p_cnct_version = PROTOCOL_VERSION6; - protocol->p_cnct_architecture = arch_generic; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 2; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_VERSION6; - protocol->p_cnct_architecture = ARCHITECTURE; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 3; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_VERSION7; - protocol->p_cnct_architecture = arch_generic; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 4; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_VERSION7; - protocol->p_cnct_architecture = ARCHITECTURE; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_out_of_band; - protocol->p_cnct_weight = 5; - - if (!(port = DNET_connect(node_name, packet, status_vector, FALSE))) { - ALLR_release(rdb); - return NULL; - } - - /* Get response packet from server. */ - - rdb->rdb_port = port; - port->port_context = rdb; - port->receive(packet); - } - - if (packet->p_operation == op_reject) { - disconnect(port); - packet->p_operation = op_connect; - connect->p_cnct_operation = op_attach; - connect->p_cnct_cversion = CONNECT_VERSION2; - connect->p_cnct_client = ARCHITECTURE; - connect->p_cnct_file.cstr_length = *file_length; - connect->p_cnct_file.cstr_address = file_name; - - /* try again with next set of known protocols */ - - connect->p_cnct_count = 4; - connect->p_cnct_user_id.cstr_length = user_length; - connect->p_cnct_user_id.cstr_address = user_id; - - protocol = connect->p_cnct_versions; - - protocol->p_cnct_version = PROTOCOL_VERSION3; - protocol->p_cnct_architecture = arch_generic; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_batch_send; - protocol->p_cnct_weight = 2; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_VERSION3; - protocol->p_cnct_architecture = ARCHITECTURE; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_batch_send; - protocol->p_cnct_weight = 3; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_VERSION4; - protocol->p_cnct_architecture = arch_generic; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_batch_send; - protocol->p_cnct_weight = 4; - - ++protocol; - - protocol->p_cnct_version = PROTOCOL_VERSION4; - protocol->p_cnct_architecture = ARCHITECTURE; - protocol->p_cnct_min_type = ptype_rpc; - protocol->p_cnct_max_type = ptype_batch_send; - protocol->p_cnct_weight = 5; - - if (!(port = DNET_connect(node_name, packet, status_vector, FALSE))) { - ALLR_release(rdb); - return NULL; - } - - /* Get response packet from server. */ - - rdb->rdb_port = port; - port->port_context = rdb; - port->receive(packet); - } - - if (packet->p_operation != op_accept) { - ib_fprintf(ib_stderr, "remote server refused connection\n"); - return NULL; - } - - port->port_protocol = packet->p_acpt.p_acpt_version; - - if (packet->p_acpt.p_acpt_architecture == ARCHITECTURE) - port->port_flags |= PORT_symmetric; - - if (packet->p_acpt.p_acpt_type == ptype_rpc) - port->port_flags |= PORT_rpc; - - if (packet->p_acpt.p_acpt_type != ptype_out_of_band) - port->port_flags |= PORT_no_oob; - - return port; -} - - -PORT DNET_connect(UCHAR * name, - PACKET * packet, STATUS * status_vector, int flag) -{ -/************************************** - * - * D N E T _ c o n n e c t - * - ************************************** - * - * Functional description - * Establish half of a communication link. If a connect packet is given, - * the connection is on behalf of a remote interface. Other the connect - * is is for a server process. - * - **************************************/ - XDR xdr; - int n, l, object_number; - PORT port; - struct sockaddr_dn address; - struct nodeent *node; - TEXT *p, *object_name, node_name[ND_MAXNODE + 1 + OB_MAXNAME]; - -/* If given a debug protocol, use it */ - - if (name) { - strcpy(node_name, name); - for (p = node_name; *p;) - if (*p++ == '/') { - p[-1] = 0; - name = (UCHAR *) node_name; - break; - } - object_name = (*p) ? p : OBJECT_NAME; - } - -/* Allocate a port block */ - - port = alloc_port(NULL); - port->port_status_vector = status_vector; - status_vector[0] = gds_arg_gds; - status_vector[1] = 0; - - if (name && *name) { - if (port->port_connection) - ALLR_free(port->port_connection); - port->port_connection = REMOTE_make_string(name); - } - else - name = (UCHAR *) port->port_host->str_data; - -/* Client and server connections diverge here */ - - if (packet) { - port->port_handle = dnet_conn(name, object_name, SOCK_SEQPACKET, - NULL, NULL, NULL, NULL); - if (port->port_handle == -1) { - dnet_error(port, "dnet_conn", errno); - return NULL; - } - send_full(port, packet); - return port; - } - -/* Server stuff */ - - port->port_handle = socket(AF_DECnet, SOCK_STREAM, 0); - if (port->port_handle == -1) { - dnet_error(port, "socket", errno); - return NULL; - } - - node = getnodebyname(name); - if (!node) { - dnet_error(port, "getnodebyname", errno); - return NULL; - } - - bzero((SCHAR *) & address, sizeof(address)); - bcopy(node->n_addr, address.sdn_add.a_addr, node->n_length); - address.sdn_add.a_len = node->n_length; - address.sdn_family = node->n_addrtype; - address.sdn_objnum = object_number; - strcpy(address.sdn_objname, object_name); - address.sdn_objnamel = strlen(address.sdn_objname); - - if (bind(port->port_handle, &address, sizeof(address)) < 0) { - dnet_error(port, "bind", errno); - return NULL; - } - - if (listen(port->port_handle, 2) < 0) { - dnet_error(port, "listen", errno); - return NULL; - } - -/* We're a server, so wait for a host to show up */ - - while (TRUE) { - l = sizeof(address); - n = accept(port->port_handle, &address, &l); - if (n == -1) { - dnet_error(port, "accept", errno); - return NULL; - } - - if (flag || !fork()) { - if (port->port_handle != (HANDLE) - 1) - close(port->port_handle); - port->port_handle = n; - port->port_server_flags = TRUE; - return port; - } - close(n); - } -} - - -PORT DNET_server(int socket) -{ -/************************************** - * - * D N E T _ s e r v e r - * - ************************************** - * - * Functional description - * We have been spawned by a master server with a connection - * established. Set up port block with the appropriate socket. - * - **************************************/ - PORT port; - - port = alloc_port(NULL); - port->port_server_flags |= SRVR_server; - port->port_handle = socket; - - return port; -} - - -static int accept_connection( PORT port, P_CNCT * connect) -{ -/************************************** - * - * a c c e p t _ c o n n e c t i o n - * - ************************************** - * - * Functional description - * Accept an incoming request for connection. This is purely a lower - * level handshaking function, and does not constitute the server - * response for protocol selection. - * - **************************************/ - UCHAR name[32], password[32], *id, *end, *p, *q; - SLONG length; - struct passwd *passwd; - -/* Default account to "guest" */ - - strcpy(name, "guest"); - password[0] = 0; - -/* Pick up account and password, if given */ - - id = connect->p_cnct_user_id.cstr_address; - end = id + connect->p_cnct_user_id.cstr_length; - - while (id < end) - switch (*id++) { - case CNCT_user: - p = name; - if (length = *id++) - do - *p++ = *id++; - while (--length); - *p = 0; - break; - - case CNCT_passwd: - p = password; - if (length = *id++) - do - *p++ = *id++; - while (--length); - *p = 0; - break; - - default: - p += *p + 1; - } - -/* See if user exists. If not, reject connection */ - - passwd = getpwnam(name); - if (!check_host(port)) - return FALSE; - -/* Change effective user id and default directory */ - - setreuid(-1, passwd->pw_uid); - chdir(passwd->pw_dir); - - return TRUE; -} - - -static PORT alloc_port( PORT parent) -{ -/************************************** - * - * a l l o c _ p o r t - * - ************************************** - * - * Functional description - * Allocate a port block, link it in to parent (if there is a parent), - * and initialize input and output XDR streams. - * - **************************************/ - SCHAR buffer[256], *p; - UCHAR *message; - PORT port; - - port = (PORT) ALLOCV(type_port, BUFFER_SIZE * 2); - port->port_type = port_decnet; - port->port_state = state_pending; - port->port_version = REMOTE_make_string("DECnet"); - -/* Init file descriptors so we can tell when they are used */ - - port->port_handle = (HANDLE) - 1; - port->port_channel = (int) -1; - - if (!(p = getnodename())) - p = "?"; - port->port_host = REMOTE_make_string(p); - port->port_connection = REMOTE_make_string(p); - sprintf(buffer, "DECnet (%s)", port->port_host->str_data); - if (port->port_version) - ALLR_free(port->port_version); - port->port_version = REMOTE_make_string(buffer); - - if (parent) { - port->port_parent = parent; - port->port_next = parent->port_clients; - parent->port_clients = port; - port->port_handle = parent->port_handle; - port->port_server = parent->port_server; - port->port_server_flags = parent->port_server_flags; - } - - message = port->port_buffer; - port->port_accept = accept_connection; - port->port_disconnect = disconnect; - port->port_receive_packet = receive; - port->port_send_packet = send_full; - port->port_send_partial = send_partial; - port->port_connect = aux_connect; - port->port_request = aux_request; - port->port_buff_size = BUFFER_SIZE; - - xdrdnet_create(&port->port_send, port, - &port->port_buffer[BUFFER_SIZE], BUFFER_SIZE, XDR_ENCODE); - - xdrdnet_create(&port->port_receive, port, port->port_buffer, 0, - XDR_DECODE); - - return port; -} - - -static PORT aux_connect(PORT port, PACKET* packet, XDR_INT (*ast)()) -{ -/************************************** - * - * a u x _ c o n n e c t - * - ************************************** - * - * Functional description - * Try to establish an alternative connection. Somebody has already - * done a successfull connect request ("packet" contains the response). - * - **************************************/ - P_RESP *response; - int n, l, pid; - TEXT *p, *end, object_name[OB_MAXNAME]; - PORT new_port; - struct sockaddr_dn address; - -/* If this is a server, we're got an auxiliary connection. Accept it */ - - if (port->port_server_flags) { - l = sizeof(address); - n = accept(port->port_channel, &address, &l); - if (n == -1) { - dnet_error(port, "accept", errno); - if (port->port_channel != (int) -1) { - close(port->port_channel); - port->port_channel = (int) -1; - } - return NULL; - } - if (port->port_channel != (int) -1) { - close(port->port_channel); - port->port_channel = (int) -1; - } - port->port_handle = (HANDLE) n; - port->port_flags |= PORT_async; - return port; - } - -/* client side */ - - response = &packet->p_resp; - if (response->p_resp_data.cstr_length > OB_MAXNAME) { - dnet_error(port, "dnet_conn", EINVAL); - return NULL; - } - else - bcopy(response->p_resp_data.cstr_address, object_name, - response->p_resp_data.cstr_length); - - n = - dnet_conn(port->port_connection->str_data, object_name, - SOCK_SEQPACKET, NULL, NULL, NULL, NULL); - - if (n < 0) { - dnet_error(port, "dnet_conn", errno); - return NULL; - } - - new_port = alloc_port(port->port_parent); - new_port->port_handle = (HANDLE) n; - new_port->port_flags |= PORT_async; - new_port->port_flags = port->port_flags & PORT_no_oob; - - if (ast) { - pid = getpid(); - if (ioctl(new_port->port_handle, SIOCSPGRP, &pid) < 0) { - disconnect(new_port); - dnet_error(port, "ioctl/SIOCSPGRP", errno); - return NULL; - } - ISC_signal(SIGURG, dnet_handler, new_port); - new_port->port_ast = ast; - } - - port->port_async = new_port; - return new_port; -} - - -static PORT aux_request( PORT port, PACKET * packet) -{ -/************************************** - * - * a u x _ r e q u e s t - * - ************************************** - * - * Functional description - * A remote interface has requested the server prepare an auxiliary - * connection; the server calls aux_request to set up the connection. - * - **************************************/ - PORT new_port; - P_RESP *response; - int n, pid; - struct sockaddr_dn address; - -/* Set up new socket */ - - if ((n = socket(AF_DECnet, SOCK_STREAM, 0)) < 0) { - dnet_error(port, "socket", errno); - return NULL; - } - - bzero((SCHAR *) & address, sizeof(address)); - address.sdn_family = AF_DECnet; - address.sdn_objnum = 0; - pid = getpid(); - sprintf(address.sdn_objname, "ISC_%X_%d", pid, request_count++); - address.sdn_objnamel = strlen(address.sdn_objname); - - if ((bind(n, &address, sizeof(address)) < 0) || (listen(n, 1) < 0)) { - close(n); - dnet_error(port, "bind", errno); - return NULL; - } - - new_port = alloc_port(port->port_parent); - new_port->port_server_flags = port->port_server_flags; - new_port->port_channel = n; - new_port->port_flags = port->port_flags & PORT_no_oob; - strcpy(new_port->port_buffer, address.sdn_objname); - - response = &packet->p_resp; - response->p_resp_data.cstr_address = new_port->port_buffer; - response->p_resp_data.cstr_length = strlen(new_port->port_buffer); - - port->port_async = new_port; - return new_port; -} - - -static int check_host( PORT port) -{ -/************************************** - * - * c h e c k _ h o s t - * - ************************************** - * - * Functional description - * Check the host on the other end of the socket to see it - * it's an equivalent host. - * - **************************************/ - IB_FILE *equiv; - UCHAR host_name[32]; - USHORT result; - int length; - struct sockaddr_dn address; - struct nodeent *node; - - return TRUE; - -/* comment out remaining code since it is not executed -length = sizeof (address); -if (getpeername (port->port_handle, &address, &length) == -1) - return FALSE; - -node = getnodebyaddr (&address.sdn_add, sizeof (address.sdn_add), - address.sdn_family); -if (!node) - return FALSE; - -equiv = ib_fopen ("/etc/hosts.equiv", "r"); -if (!equiv) - return FALSE; - -result = FALSE; - -while (ib_fscanf (equiv, "%s", host_name) != -1) - if (strcmp (host_name, node->n_name) == 0) - { - result = TRUE; - break; - } - -ib_fclose (equiv); - -return result; -end unxecuted code*/ -} - - -static void disconnect( PORT port) -{ -/************************************** - * - * d i s c o n n e c t - * - ************************************** - * - * Functional description - * Break a remote connection. - * - **************************************/ - PORT parent, *ptr; - - if (port->port_ast) - ISC_signal_cancel(SIGURG, dnet_handler, port); - -/* If this is a sub-port, unlink it from it's parent */ - - if (parent = port->port_parent) { - if (port->port_async) { - disconnect(port->port_async); - port->port_async = NULL; - } - for (ptr = &parent->port_clients; *ptr; ptr = &(*ptr)->port_next) - if (*ptr == port) { - *ptr = port->port_next; - if (ptr == &parent->port_clients) - parent->port_next = *ptr; - break; - } - } - else if (port->port_async) { -#ifdef MULTI_THREAD - port->port_async->port_flags |= PORT_disconnect; -#else - disconnect(port->port_async); - port->port_async = NULL; -#endif - } - - if (port->port_channel != (int) -1) { - close(port->port_channel); - port->port_channel = (int) -1; - } - - if (port->port_handle != (HANDLE) - 1) { - close(port->port_handle); - port->port_handle = (HANDLE) - 1; - } - - cleanup_port(port); -} - - -static void cleanup_port( PORT port) -{ -/************************************** - * - * c l e a n u p _ p o r t - * - ************************************** - * - * Functional description - * Walk through the port structure freeing - * allocated memory and then free the port. - * - **************************************/ - - if (port->port_version) - ALLR_free((UCHAR *) port->port_version); - - if (port->port_connection) - ALLR_free((UCHAR *) port->port_connection); - - if (port->port_host) - ALLR_free((UCHAR *) port->port_host); - - if (port->port_object_vector) - ALLR_free((UCHAR *) port->port_object_vector); - -#ifdef DEBUG_XDR_MEMORY - if (port->port_packet_vector) - ALLR_free((UCHAR *) port->port_packet_vector); -#endif - - ALLR_release((UCHAR *) port); - return; -} - - -static XDR_INT dnet_destroy( XDR * xdrs) -{ -/************************************** - * - * d n e t _ d e s t r o y - * - ************************************** - * - * Functional description - * Destroy a stream. A no-op. - * - **************************************/ -} - - -static int dnet_error( PORT port, TEXT * operation, int status) -{ -/************************************** - * - * d n e t _ e r r o r - * - ************************************** - * - * Functional description - * An I/O error has occurred. If a status vector is present, - * generate an error return. In any case, return NULL, which - * is used to indicate and error. - * - **************************************/ - RDB rdb; - STATUS *status_vector; - - port->port_flags |= PORT_broken; - port->port_state = state_broken; - - if (rdb = port->port_context) - status_vector = rdb->rdb_status_vector; - else - status_vector = port->port_status_vector; - - if (status_vector) { - *status_vector++ = gds_arg_gds; - *status_vector++ = gds__io_error; - *status_vector++ = gds_arg_string; - *status_vector++ = (STATUS) operation; - *status_vector++ = gds_arg_string; - *status_vector++ = (STATUS) "DECnet connection"; - if (status) { - *status_vector++ = gds_arg_unix; - *status_vector++ = status; - } - *status_vector++ = 0; - } - - return 0; -} - - -static bool_t dnet_getbytes( XDR * xdrs, SCHAR * buff, int count) -{ -/************************************** - * - * d n e t _ g e t b y t e s - * - ************************************** - * - * Functional description - * Get a bunch of bytes from a memory stream if it fits. - * - **************************************/ - SLONG bytecount = count; - -/* Use memcpy to optimize bulk transfers. */ - - while (bytecount > sizeof(GDS_QUAD)) { - if (xdrs->x_handy >= bytecount) { - memcpy(buff, xdrs->x_private, bytecount); - xdrs->x_private += bytecount; - xdrs->x_handy -= bytecount; - return TRUE; - } - else { - if (xdrs->x_handy > 0) { - memcpy(buff, xdrs->x_private, xdrs->x_handy); - xdrs->x_private += xdrs->x_handy; - buff += xdrs->x_handy; - bytecount -= xdrs->x_handy; - xdrs->x_handy = 0; - } - if (!dnet_read(xdrs)) - return FALSE; - } - } - -/* Scalar values and bulk transfer remainder fall thru - to be moved byte-by-byte to avoid memcpy setup costs. */ - - if (!bytecount) - return TRUE; - - if (bytecount && xdrs->x_handy >= bytecount) { - xdrs->x_handy -= bytecount; - do - *buff++ = *xdrs->x_private++; - while (--bytecount); - return TRUE; - } - - while (--bytecount >= 0) { - if (!xdrs->x_handy && !dnet_read(xdrs)) - return FALSE; - *buff++ = *xdrs->x_private++; - --xdrs->x_handy; - } - - return TRUE; -} - - -static bool_t dnet_getlong( XDR * xdrs, SLONG * lp) -{ -/************************************** - * - * d n e t _ g e t l o n g - * - ************************************** - * - * Functional description - * Fetch a longword into a memory stream if it fits. - * - **************************************/ - SLONG l; - - if (!(*xdrs->x_ops->x_getbytes) (xdrs, &l, 4)) - return FALSE; - - *lp = ntohl(l); - - return TRUE; -} - - -static u_int dnet_getpostn( XDR * xdrs) -{ -/************************************** - * - * d n e t _ g e t p o s t n - * - ************************************** - * - * Functional description - * Get the current position (which is also current length) from stream. - * - **************************************/ - - return xdrs->x_private - xdrs->x_base; -} - - -static void dnet_handler( PORT port) -{ -/************************************** - * - * d n e t _ h a n d l e r - * - ************************************** - * - * Functional description - * Dnet_handler is the signal handler on receipt of - * a SIGURG indicating out-of-band data. Since SIGURG - * may be noisy, check to see if any IO is pending on the channel. - * If not, ignore the signal. If so, call the port specific - * handler to do something appropriate. - * - **************************************/ - int n; - UCHAR junk; - -/* If there isn't any out of band data, this signal isn't for us */ - - if ((n = recv(port->port_handle, &junk, 1, MSG_OOB)) < 0) - return; - - (*port->port_ast) (port); -} - - -static caddr_t dnet_inline( XDR * xdrs, u_int bytecount) -{ -/************************************** - * - * d n e t _ i n l i n e - * - ************************************** - * - * Functional description - * Return a pointer to somewhere in the buffer. - * - **************************************/ - - if (bytecount > xdrs->x_handy) - return FALSE; - - return xdrs->x_base + bytecount; -} - - -static bool_t dnet_putbytes( XDR * xdrs, SCHAR * buff, int count) -{ -/************************************** - * - * d n e t _ p u t b y t e s - * - ************************************** - * - * Functional description - * Put a bunch of bytes to a memory stream if it fits. - * - **************************************/ - SLONG bytecount = count; - -/* Use memcpy to optimize bulk transfers. */ - - while (bytecount > sizeof(GDS_QUAD)) { - if (xdrs->x_handy >= bytecount) { - memcpy(xdrs->x_private, buff, bytecount); - xdrs->x_private += bytecount; - xdrs->x_handy -= bytecount; - return TRUE; - } - else { - if (xdrs->x_handy > 0) { - memcpy(xdrs->x_private, buff, xdrs->x_handy); - xdrs->x_private += xdrs->x_handy; - buff += xdrs->x_handy; - bytecount -= xdrs->x_handy; - xdrs->x_handy = 0; - } - if (!dnet_write(xdrs, FALSE)) - return FALSE; - } - } - -/* Scalar values and bulk transfer remainder fall thru - to be moved byte-by-byte to avoid memcpy setup costs. */ - - if (!bytecount) - return TRUE; - - if (bytecount && xdrs->x_handy >= bytecount) { - xdrs->x_handy -= bytecount; - do - *xdrs->x_private++ = *buff++; - while (--bytecount); - return TRUE; - } - - while (--bytecount >= 0) { - if (xdrs->x_handy <= 0 && !dnet_write(xdrs, FALSE)) - return FALSE; - --xdrs->x_handy; - *xdrs->x_private++ = *buff++; - } - - return TRUE; -} - - -static bool_t dnet_putlong( XDR * xdrs, SLONG * lp) -{ -/************************************** - * - * d n e t _ p u t l o n g - * - ************************************** - * - * Functional description - * Fetch a longword into a memory stream if it fits. - * - **************************************/ - SLONG l; - - l = htonl(*lp); - return (*xdrs->x_ops->x_putbytes) (xdrs, &l, 4); -} - - -static bool_t dnet_read( XDR * xdrs) -{ -/************************************** - * - * d n e t _ r e a d - * - ************************************** - * - * Functional description - * Read a buffer full of data. If we receive a bad packet, - * send the moral equivalent of a NAK and retry. ACK all - * partial packets. Don't ACK the last packet -- the next - * message sent will handle this. - * - **************************************/ - PORT port; - SSHORT length; - UCHAR *p, *end; - - port = (PORT) xdrs->x_public; - p = (UCHAR *) xdrs->x_base; - end = p + BUFFER_SIZE; - -/* If buffer is not completely empty, slide down what what's left */ - - if (xdrs->x_handy > 0) { - memmove(p, xdrs->x_private, xdrs->x_handy); - p += xdrs->x_handy; - } - -/* If an ACK is pending, do an ACK. The alternative is deadlock. */ - -/* -if (port->port_flags & PORT_pend_ack) - if (!packet_send (port, NULL, 0)) - return FALSE; -*/ - - while (TRUE) { - length = end - p; - if (!packet_receive(port, p, length, &length)) - return FALSE; - if (length >= 0) { - p += length; - break; - } - p -= length; - if (!packet_send(port, NULL, 0)) - return FALSE; - } - - port->port_flags |= PORT_pend_ack; - xdrs->x_handy = p - (UCHAR *) xdrs->x_base; - xdrs->x_private = xdrs->x_base; - - return TRUE; -} - - -static bool_t dnet_setpostn( XDR * xdrs, u_int bytecount) -{ -/************************************** - * - * d n e t _ s e t p o s t n - * - ************************************** - * - * Functional description - * Set the current position (which is also current length) from stream. - * - **************************************/ - - if (bytecount > xdrs->x_handy) - return FALSE; - - xdrs->x_private = xdrs->x_base + bytecount; - - return TRUE; -} - - -static bool_t dnet_write( XDR * xdrs, bool_t end_flag) -{ -/************************************** - * - * d n e t _ w r i t e - * - ************************************** - * - * Functional description - * Write a buffer fulll of data. If the end_flag isn't set, indicate - * that the buffer is a fragment, and reset the XDR for another buffer - * load. - * - **************************************/ - UCHAR aux_buffer[BUFFER_SIZE], *p, *q; - UCHAR buffer[BUFFER_SIZE]; - PORT port; - SSHORT l, length, l2; - -/* Encode the data portion of the packet */ - - port = (PORT) xdrs->x_public; - p = (UCHAR *) xdrs->x_base; - length = (UCHAR *) xdrs->x_private - p; - -/* Send data in manageable hunks. If a packet is partial, indicate - that with a negative length. A positive length marks the end. */ - - p = (UCHAR *) xdrs->x_base; - - while (length) { - port->port_misc1 = (port->port_misc1 + 1) % MAX_SEQUENCE; - l = MIN(length, MAX_DATA); - length -= l; - while (TRUE) { - if (!packet_send(port, p, (length) ? -l : l)) - return FALSE; - /* - if (packet_receive (port, aux_buffer, sizeof (aux_buffer), &l2)) - */ - break; - } - p += l; - } - - xdrs->x_private = xdrs->x_base; - xdrs->x_handy = BUFFER_SIZE; - - return TRUE; -} - - -static int packet_receive( - PORT port, - UCHAR * buffer, - SSHORT buffer_length, SSHORT * length) -{ -/************************************** - * - * p a c k e t _ r e c e i v e - * - ************************************** - * - * Functional description - * Receive a packet and pass on it's goodness. If it's good, - * return TRUE and the reported length of the packet, and update - * the receive sequence number. If it's bad, return FALSE. If it's - * a duplicate message, just ignore it. - * - **************************************/ - UCHAR c, aux_buffer[1024], *p; - USHORT l, n, checksum; - - do - n = read(port->port_handle, buffer, buffer_length); - while (n == -1 && SYSCALL_INTERRUPTED(errno)); - - if (n == -1) - return dnet_error(port, "read", errno); - - if (!n) - return dnet_error(port, "read end-of_file", 0); - - *length = n; - - return TRUE; -} - - -static int packet_send( PORT port, UCHAR * data, SSHORT length) -{ -/************************************** - * - * p a c k e t _ s e n d - * - ************************************** - * - * Functional description - * Send some data on it's way. - * - **************************************/ - SSHORT checksum, n; - - do - n = write(port->port_handle, data, length); - while (n == -1 && SYSCALL_INTERRUPTED(errno)); - - if (n == -1) - return dnet_error(port, "write", errno); - - if ((port->port_flags & PORT_async) && !(port->port_flags & PORT_no_oob)) - n = send(port->port_handle, data, 1, MSG_OOB); - - if (n == -1) - return dnet_error(port, "send/oob", errno); - - port->port_flags &= ~PORT_pend_ack; - - return TRUE; -} - - -static PORT receive( PORT port, PACKET * packet) -{ -/************************************** - * - * r e c e i v e - * - ************************************** - * - * Functional description - * Receive a message from a port or clients of a port. If the process - * is a server and a connection request comes in, generate a new port - * block for the client. - * - **************************************/ - - if (!xdr_protocol(&port->port_receive, packet)) - return NULL; - - return port; -} - - -static int send_full( PORT port, PACKET * packet) -{ -/************************************** - * - * s e n d _ f u l l - * - ************************************** - * - * Functional description - * Send a packet across a port to another process. - * - **************************************/ - - if (!xdr_protocol(&port->port_send, packet)) - return FALSE; - - return xdrdnet_endofrecord(&port->port_send, TRUE); -} - - -static int send_partial( PORT port, PACKET * packet) -{ -/************************************** - * - * s e n d _ p a r t i a l - * - ************************************** - * - * Functional description - * Send a packet across a port to another process. - * - **************************************/ - - return xdr_protocol(&port->port_send, packet); -} - - - - -static xdrdnet_create( - XDR * xdrs, - PORT port, - UCHAR * buffer, USHORT length, enum xdr_op x_op) -{ -/************************************** - * - * x d r d n e t _ c r e a t e - * - ************************************** - * - * Functional description - * Initialize an XDR stream for Apollo mailboxes. - * - **************************************/ - - xdrs->x_public = (caddr_t) port; - xdrs->x_base = xdrs->x_private = (caddr_t) buffer; - xdrs->x_handy = length; - xdrs->x_ops = &dnet_ops; - xdrs->x_op = x_op; - - return TRUE; -} - - -static int xdrdnet_endofrecord( XDR * xdrs, bool_t flushnow) -{ -/************************************** - * - * x d r d n e t _ e n d o f r e c o r d - * - ************************************** - * - * Functional description - * Write out the rest of a record. - * - **************************************/ - - return dnet_write(xdrs, flushnow); -} diff --git a/src/remote/dnet_proto.h b/src/remote/dnet_proto.h deleted file mode 100644 index cd52fb64fa..0000000000 --- a/src/remote/dnet_proto.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * PROGRAM: JRD Remote Interface/Server - * MODULE: dnet_proto.h - * DESCRIPTION: Prototpe header file for dnet.c - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy - * of the License at http://www.Inprise.com/IPL.html - * - * Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express - * or implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#ifndef _REMOTE_DNET_PROTO_H_ -#define _REMOTE_DNET_PROTO_H_ - -extern PORT DNET_analyze (UCHAR *, SSHORT *, STATUS *, SSHORT); -extern PORT DNET_connect (UCHAR *, struct packet *, STATUS *, int); -extern PORT DNET_server (int); - -#endif /* _REMOTE_DNET_PROTO_H */ diff --git a/src/remote/dnet_server.cpp b/src/remote/dnet_server.cpp deleted file mode 100644 index 613dab8c03..0000000000 --- a/src/remote/dnet_server.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * PROGRAM: JRD Remote Server - * MODULE: dnet_server.c - * DESCRIPTION: DECnet remote server. - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy - * of the License at http://www.Inprise.com/IPL.html - * - * Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express - * or implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#include "firebird.h" -#include "../jrd/common.h" -#include "../jrd/license.h" -#include "../remote/remote.h" -#include "../remote/dnet_proto.h" -#include "../remote/serve_proto.h" -#include "../jrd/gds_proto.h" - - -void main( int argc, char *argv[]) -{ -/************************************** - * - * m a i n - * - ************************************** - * - * Functional description - * Run the server with DECnet. - * - **************************************/ - PORT port; - int debug, flag, standalone; - STATUS status_vector[20]; - TEXT *p, **end, c, protocol[128]; - - end = argc + argv; - argv++; - debug = standalone = flag = FALSE; - protocol[0] = 0; - - while (argv < end) { - p = *argv++; - if (*p++ == '-') - while (c = *p++) - switch (UPPER(c)) { - case 'D': - flag |= SRVR_debug; - debug = standalone = TRUE; - break; - - case 'S': - standalone = TRUE; - break; - - case 'I': - standalone = FALSE; - break; - - case 'P': - sprintf(protocol, "/%s", *argv++); - break; - - case 'Z': - ib_printf("Interbase DECnet server version %s\n", - GDS_VERSION); - exit(FINI_OK); - } - } - - if (standalone) { - port = DNET_connect(protocol, 0, status_vector, flag); - if (!port) { - gds__print_status(status_vector); - exit(FINI_ERROR); - } - } - else - port = DNET_server(1); - - SRVR_main(port, flag); - - exit(FINI_OK); -} diff --git a/src/remote/inet.cpp b/src/remote/inet.cpp index b17b8212fc..76cac9ec99 100644 --- a/src/remote/inet.cpp +++ b/src/remote/inet.cpp @@ -23,7 +23,7 @@ * FSG 16.03.2001 */ /* -$Id: inet.cpp,v 1.3 2001-07-29 23:43:24 skywalker Exp $ +$Id: inet.cpp,v 1.4 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" #include "../jrd/ib_stdio.h" @@ -36,13 +36,17 @@ $Id: inet.cpp,v 1.3 2001-07-29 23:43:24 skywalker Exp $ #include "../jrd/time.h" +#ifdef DARWIN +#include +#endif + #ifdef HAVE_SYS_PARAM_H #include #endif -//#ifdef HAVE_GRP_H +#ifdef HAVE_GRP_H #include -//#endif +#endif #ifdef HAVE_SYS_TYPES_H #include @@ -154,6 +158,7 @@ extern int h_errno; #define INET_RETRY_ERRNO WSAEINPROGRESS #define INET_ADDR_IN_USE WSAEADDRINUSE #define sleep(seconds) Sleep ((seconds) * 1000) +typedef int socklen_t; /* ** Winsock has a typedef for socket, so #define SOCKET to the typedef here diff --git a/src/remote/inet_server.cpp b/src/remote/inet_server.cpp index 9c6ee235d9..79b654e0cc 100644 --- a/src/remote/inet_server.cpp +++ b/src/remote/inet_server.cpp @@ -23,7 +23,7 @@ * FSG 16.03.2001 */ /* -$Id: inet_server.cpp,v 1.3 2001-07-29 23:43:24 skywalker Exp $ +$Id: inet_server.cpp,v 1.4 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" #include "../jrd/ib_stdio.h" diff --git a/src/remote/interface.cpp b/src/remote/interface.cpp index 70f079a4b5..abf77d3e7f 100644 --- a/src/remote/interface.cpp +++ b/src/remote/interface.cpp @@ -4671,7 +4671,7 @@ static BOOLEAN batch_dsql_fetch( statement->rsr_rows_pending = 0; --statement->rsr_batch_count; dequeue_receive(port); - LONGJMP(*trdb->trdb_setjmp, user_status[1]); + Firebird::status_longjmp_error::raise(user_status[1]); /* we don't return from the LONGJMP - but put a return here to make the compiler happy. */ @@ -4831,7 +4831,7 @@ static BOOLEAN batch_gds_receive( tail->rrq_rows_pending = 0; --tail->rrq_batch_count; dequeue_receive(port); - LONGJMP(*trdb->trdb_setjmp, user_status[1]); + Firebird::status_longjmp_error::raise(user_status[1]); /* we don't return from the LONGJMP - but put a return here to make the compiler happy. */ @@ -5700,9 +5700,10 @@ static RTR make_transaction( RDB rdb, USHORT id) } -static STATUS mov_dsql_message( - UCHAR * from_msg, - FMT from_fmt, UCHAR * to_msg, FMT to_fmt) +static STATUS mov_dsql_message( UCHAR* from_msg, + FMT from_fmt, + UCHAR* to_msg, + FMT to_fmt) { /************************************** * @@ -5725,10 +5726,7 @@ static STATUS mov_dsql_message( old_env = trdb->trdb_setjmp; trdb->trdb_setjmp = &env; - if (SETJMP(env)) { - trdb->trdb_setjmp = old_env; - return FAILURE; - } + try { if (!from_fmt || !to_fmt || from_fmt->fmt_count != to_fmt->fmt_count) { move_error(gds_dsql_sqlda_err, gds_arg_end); @@ -5746,6 +5744,12 @@ static STATUS mov_dsql_message( CVT_move(&from, &to, (FPTR_VOID) move_error); } + } // try + catch (...) { + trdb->trdb_setjmp = old_env; + return FAILURE; + } + return SUCCESS; } @@ -5837,7 +5841,7 @@ static void move_error( STATUS status, ...) if (p_args >= end_args) end_args[-1] = gds_arg_end; - LONGJMP(*trdb->trdb_setjmp, trdb->trdb_status_vector[1]); + Firebird::status_longjmp_error::raise(trdb->trdb_status_vector[1]); } diff --git a/src/remote/parser.cpp b/src/remote/parser.cpp index 685ee8acb9..1c37ec7b08 100644 --- a/src/remote/parser.cpp +++ b/src/remote/parser.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: parser.cpp,v 1.2 2001-07-29 23:43:24 skywalker Exp $ +$Id: parser.cpp,v 1.3 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" diff --git a/src/remote/protocol.h b/src/remote/protocol.h index be54ccb298..817c03c11b 100644 --- a/src/remote/protocol.h +++ b/src/remote/protocol.h @@ -23,7 +23,7 @@ * FSG 16.03.2001 */ /* -$Id: protocol.h,v 1.2 2001-07-12 05:46:06 bellardo Exp $ +$Id: protocol.h,v 1.3 2001-12-24 02:50:53 tamlin Exp $ */ #ifndef _REMOTE_PROTOCOL_H_ #define _REMOTE_PROTOCOL_H_ @@ -268,13 +268,6 @@ typedef struct cstring UCHAR* cstr_address; } CSTRING; -typedef struct lstring -{ - ULONG lstr_length; - ULONG lstr_allocated; - UCHAR* lstr_address; -} LSTRING; - #ifdef DEBUG_XDR_MEMORY diff --git a/src/remote/remote.h b/src/remote/remote.h index c13e94f09f..d4705b694e 100644 --- a/src/remote/remote.h +++ b/src/remote/remote.h @@ -61,7 +61,7 @@ /* Block types */ #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif @@ -164,11 +164,7 @@ typedef struct str #include "../jrd/dsc.h" -typedef struct vary -{ - USHORT vary_length; - UCHAR vary_string[1]; -} *VARY; +typedef vary* VARY; typedef struct fmt { @@ -314,7 +310,7 @@ enum blk_t /* Generalized port definition. */ -enum port_t +enum rem_port_t { port_mailbox, /* Apollo mailbox */ port_pcic, /* IBM PC interconnect */ @@ -359,7 +355,7 @@ public: typedef struct port { struct blk port_header; - enum port_t port_type; /* type of port */ + enum rem_port_t port_type; /* type of port */ enum state_t port_state; /* state of port */ P_ARCH port_client_arch; /* so we can tell arch of client */ struct port* port_clients; /* client ports */ diff --git a/src/remote/server.cpp b/src/remote/server.cpp index 6930420dd2..38fb55d14e 100644 --- a/src/remote/server.cpp +++ b/src/remote/server.cpp @@ -111,7 +111,7 @@ typedef struct srvr { struct srvr* srvr_next; struct port* srvr_parent_port; - enum port_t srvr_port_type; + enum rem_port_t srvr_port_type; USHORT srvr_flags; } *SRVR; @@ -274,18 +274,7 @@ void SRVR_multi_thread( PORT main_port, USHORT flags) trdb->trdb_setjmp = &env; trdb->trdb_status_vector = status_vector; - if (SETJMP(env)) { - /* Some kind of unhandled error occured during server setup. In lieu - * of anything we CAN do, log something (and we might be so hosed - * we can't log anything) and give up. - * The likely error here is out-of-memory. - */ - gds__log("SRVR_multi_thread: error during startup, shutting down"); - - RESTORE_THREAD_DATA; - THREAD_EXIT; - return; - } + try { set_server(main_port, flags); @@ -301,66 +290,11 @@ void SRVR_multi_thread( PORT main_port, USHORT flags) * server. */ - if (SETJMP(env)) - { - /* If we got as far as having a port allocated before the error, disconnect it - * gracefully. - */ - if (port != NULL) - { -#ifdef DEV_BUILD -#ifdef DEBUG - ConsolePrintf("%%ISERVER-F-NOPORT, no port in a storm\r\n"); -#endif /* DEBUG */ -#endif /* DEV_BUILD */ - gds__log("SRVR_multi_thread: forcefully disconnecting a port"); - - /* To handle recursion within the error handler */ - trdb->trdb_setjmp = &inner_env; - if (SETJMP(inner_env)) - { - port->disconnect(NULL, NULL); - port = NULL; - } - else - { - /* If we have a port, request really should be non-null, but just in case ... */ - if (request != NULL) { - /* Send client a real status indication of why we disconnected them */ - /* Note that send_response() can post errors that wind up in this same handler */ -#ifdef DEV_BUILD -#ifdef DEBUG - ConsolePrintf - ("%%ISERVER-F-NOMEM, virtual memory exhausted\r\n"); -#endif /* DEBUG */ -#endif /* DEV_BUILD */ - port->send_response(&request->req_send, 0, 0, - status_vector); - port->disconnect(&request->req_send, &request->req_receive); - } - else { - /* Can't tell the client much, just make 'em go away. Their side should detect - * a network error - */ - port->disconnect(NULL, NULL); - } - port = NULL; - } - trdb->trdb_setjmp = &env; - } - - /* There was an error in the processing of the request, if we have allocated - * a request, free it up and continue. - */ - if (request != NULL) { - request->req_next = free_requests; - free_requests = request; - request = NULL; - } - } + try { /* When this loop exits, the server will no longer receive requests */ - while (TRUE) { + while (TRUE) + { port = NULL; /* Allocate a memory block to store the request in */ @@ -399,7 +333,7 @@ void SRVR_multi_thread( PORT main_port, USHORT flags) #ifdef DEV_BUILD #ifdef DEBUG if ((request_count++ % 4) == 0) { - LONGJMP(*trdb->trdb_setjmp, gds__virmemexh); + Firebird::status_longjmp_error::raise(gds__virmemexh); } #endif /* DEBUG */ #endif /* DEV_BUILD */ @@ -423,7 +357,7 @@ void SRVR_multi_thread( PORT main_port, USHORT flags) #ifdef DEV_BUILD #ifdef DEBUG if ((request_count % 5) == 0) { - LONGJMP(*trdb->trdb_setjmp, gds__virmemexh); + Firebird::status_longjmp_error::raise(gds__virmemexh); } #endif /* DEBUG */ #endif /* DEV_BUILD */ @@ -521,6 +455,78 @@ void SRVR_multi_thread( PORT main_port, USHORT flags) THREAD_EXIT; + } // try + catch (...) + { + /* If we got as far as having a port allocated before the error, disconnect it + * gracefully. + */ + if (port != NULL) + { +#ifdef DEV_BUILD +#ifdef DEBUG + ConsolePrintf("%%ISERVER-F-NOPORT, no port in a storm\r\n"); +#endif /* DEBUG */ +#endif /* DEV_BUILD */ + gds__log("SRVR_multi_thread: forcefully disconnecting a port"); + + /* To handle recursion within the error handler */ + trdb->trdb_setjmp = &inner_env; + try { + /* If we have a port, request really should be non-null, but just in case ... */ + if (request != NULL) { + /* Send client a real status indication of why we disconnected them */ + /* Note that send_response() can post errors that wind up in this same handler */ +#ifdef DEV_BUILD +#ifdef DEBUG + ConsolePrintf + ("%%ISERVER-F-NOMEM, virtual memory exhausted\r\n"); +#endif /* DEBUG */ +#endif /* DEV_BUILD */ + port->send_response(&request->req_send, 0, 0, + status_vector); + port->disconnect(&request->req_send, &request->req_receive); + } + else { + /* Can't tell the client much, just make 'em go away. Their side should detect + * a network error + */ + port->disconnect(NULL, NULL); + } + port = NULL; + + trdb->trdb_setjmp = &env; + } // try + catch (...) { + port->disconnect(NULL, NULL); + port = NULL; + } + } + + /* There was an error in the processing of the request, if we have allocated + * a request, free it up and continue. + */ + if (request != NULL) { + request->req_next = free_requests; + free_requests = request; + request = NULL; + } + } + + } // try + catch (...) { + /* Some kind of unhandled error occured during server setup. In lieu + * of anything we CAN do, log something (and we might be so hosed + * we can't log anything) and give up. + * The likely error here is out-of-memory. + */ + gds__log("SRVR_multi_thread: error during startup, shutting down"); + + RESTORE_THREAD_DATA; + THREAD_EXIT; + return; + } + #endif /* Why isn't this inside the #endif above? */ @@ -3010,20 +3016,10 @@ BOOLEAN process_packet(PORT port, THD_put_specific((THDD) trdb); trdb->trdb_thd_data.thdd_type = THDD_TYPE_TRDB; - if (SETJMP(env)) { - /* There must be something better to do here. BUT WHAT? */ + try { - gds__log("SERVER/process_packet: out of memory", 0); - - /* It would be nice to log an error to the user, instead of just terminating them! */ - port->send_response(send, 0, 0, trdb->trdb_status_vector); - port->disconnect(send, receive); /* Well, how about this... */ - - THD_restore_specific(); - return FALSE; - } - - switch (op = receive->p_operation) { + switch (op = receive->p_operation) + { case op_connect: if (!accept_connection(port, &receive->p_cnct, send)) { if (string = port->port_user_name) { @@ -3271,6 +3267,20 @@ BOOLEAN process_packet(PORT port, *result = port; THD_restore_specific(); + + } // try + catch (...) { + /* There must be something better to do here. BUT WHAT? */ + + gds__log("SERVER/process_packet: out of memory", 0); + + /* It would be nice to log an error to the user, instead of just terminating them! */ + port->send_response(send, 0, 0, trdb->trdb_status_vector); + port->disconnect(send, receive); /* Well, how about this... */ + + THD_restore_specific(); + return FALSE; + } return TRUE; } diff --git a/src/remote/srvr_w32.cpp b/src/remote/srvr_w32.cpp index 47ee9ebe71..754e283afd 100644 --- a/src/remote/srvr_w32.cpp +++ b/src/remote/srvr_w32.cpp @@ -335,7 +335,7 @@ static void THREAD_ROUTINE wnet_connect_wait_thread( void *dummy) port = WNET_connect(protocol_wnet, 0, status_vector, server_flag); THREAD_EXIT; if (!port) { - if (status_vector[1] != gds__io_error || + if (status_vector[1] != gds_io_error || status_vector[6] != gds_arg_win32 || status_vector[7] != ERROR_CALL_NOT_IMPLEMENTED) { gds__log_status(0, status_vector); diff --git a/src/remote/xdr_proto.h b/src/remote/xdr_proto.h index 73ffaf5704..7f9b842317 100644 --- a/src/remote/xdr_proto.h +++ b/src/remote/xdr_proto.h @@ -24,6 +24,8 @@ #ifndef REMOTE_XDR_PROTO_H #define REMOTE_XDR_PROTO_H +#include "../remote/xdr.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/src/utilities/create_db.cpp b/src/utilities/create_db.cpp index a5515f55fd..b33f21a4f7 100644 --- a/src/utilities/create_db.cpp +++ b/src/utilities/create_db.cpp @@ -17,7 +17,7 @@ int main(int argc, char **argv) printf("Usage: %s \n", argv[0]); return -1; } - + d = dpb; *d++ = (UCHAR) isc_dpb_version1; *d++ = (UCHAR) isc_dpb_set_db_readonly; diff --git a/src/utilities/dba.epp b/src/utilities/dba.epp index bc066c441c..0787f11f4c 100644 --- a/src/utilities/dba.epp +++ b/src/utilities/dba.epp @@ -44,6 +44,7 @@ #include "../jrd/enc_proto.h" #ifdef SUPERSERVER #include "../utilities/cmd_util_proto.h" +#include "../jrd/thd_proto.h" #endif #ifdef HAVE_UNISTD_H @@ -226,8 +227,11 @@ static struct tdba *gddba; #define RESTORE_THREAD_DATA #endif +//#define EXIT(code) { tddba->exit_code = code; \ +// LONGJMP(*reinterpret_cast(&tddba->dba_env), 1); } + #define EXIT(code) { tddba->exit_code = code; \ - LONGJMP((jmp_buf) tddba->dba_env, 1); } + Firebird::status_longjmp_error::raise(0); } #define GSTAT_MSG_FAC 21 @@ -245,7 +249,7 @@ static BOOLEAN fAnsiCP = FALSE; int main_gstat( SVC service) #else -int CLIB_ROUTINE main( int argc, char **argv) +int CLIB_ROUTINE main(int argc, char **argv) #endif { /************************************** @@ -309,90 +313,7 @@ int CLIB_ROUTINE main( int argc, char **argv) argv = service->svc_argv; #endif - if (SETJMP(env)) { - int exit_code; - - /* free mem */ - - if (status_vector[1]) { - STATUS *vector; - SCHAR s[1024]; -#ifdef SUPERSERVER - STATUS *status; - int i = 0, j; - - status = tddba->dba_service_blk->svc_status; - if (status != status_vector) { - while (*status && (++i < ISC_STATUS_LENGTH)) - status++; - for (j = 0; status_vector[j] && (i < ISC_STATUS_LENGTH); - j++, i++) - *status++ = status_vector[j]; - } -#endif - vector = status_vector; - if (isc_interprete(s, &vector)) { - FPRINTF(tddba->sw_outfile, "%s\n", s); - s[0] = '-'; - while (isc_interprete(s + 1, &vector)) - FPRINTF(tddba->sw_outfile, "%s\n", s); - } - } - - /* if there still exists a database handle, disconnect from the - * server - */ - FINISH; - -#ifdef SUPERSERVER - SVC_STARTED(service); - alloced = tddba->head_of_mem_list; - while (alloced != 0) { - free(alloced->memory); - alloced = alloced->mem_next; - } - - /* close files */ - open_file = tddba->head_of_files_list; - while (open_file) { - db_close(open_file->desc); - open_file = open_file->open_files_next; - } - - /* free linked lists */ - while (tddba->head_of_files_list != 0) { - tmp1 = tddba->head_of_files_list; - tddba->head_of_files_list = - tddba->head_of_files_list->open_files_next; - free(tmp1); - } - - while (tddba->head_of_mem_list != 0) { - tmp2 = tddba->head_of_mem_list; - tddba->head_of_mem_list = tddba->head_of_mem_list->mem_next; - free(tmp2); - } - - service->svc_handle = 0; - if (service->svc_service->in_use != NULL) - *(service->svc_service->in_use) = FALSE; - - /* Mark service thread as finished and cleanup memory being - * used by service in case if client detached from the service - */ - - SVC_finish(service, SVC_finished); -#endif - - exit_code = tddba->exit_code; - RESTORE_THREAD_DATA; - -#ifdef SUPERSERVER - return exit_code; -#else - exit(exit_code); -#endif - } + try { #ifdef SUPERSERVER sw_outfile = tddba->sw_outfile = service; @@ -595,8 +516,8 @@ int CLIB_ROUTINE main( int argc, char **argv) #ifdef SUPERSERVER CMD_UTIL_put_svc_status(tddba->dba_service_blk->svc_status, GSTAT_MSG_FAC, 3, - isc_arg_number, ODS_VERSION, - isc_arg_number, header->hdr_ods_version, + isc_arg_number, reinterpret_cast(ODS_VERSION), + isc_arg_number, reinterpret_cast(header->hdr_ods_version), 0, NULL, 0, NULL, 0, NULL); #endif dba_error(3, (TEXT *) ODS_VERSION, (TEXT *) header->hdr_ods_version, @@ -730,11 +651,15 @@ int CLIB_ROUTINE main( int argc, char **argv) FOR(TRANSACTION_HANDLE transact1 REQUEST_HANDLE request1) X IN RDB$RELATIONS SORTED BY DESC X.RDB$RELATION_NAME - if (!sw_system && X.RDB$SYSTEM_FLAG) - continue; - if (!X.RDB$VIEW_BLR.NULL || !X.RDB$EXTERNAL_FILE.NULL) + + if (!sw_system && X.RDB$SYSTEM_FLAG) { + continue; + } + if (!X.RDB$VIEW_BLR.NULL || !X.RDB$EXTERNAL_FILE.NULL) { continue; - if (sw_relation) { + } + if (sw_relation) + { truncate_name(X.RDB$RELATION_NAME); for (relation = tddba->relations; relation; relation = relation->rel_next) if (!(strcmp(relation->rel_name, X.RDB$RELATION_NAME))) { @@ -744,7 +669,8 @@ int CLIB_ROUTINE main( int argc, char **argv) if (!relation) continue; } - else { + else + { relation = (REL) ALLOC(sizeof(struct rel)); relation->rel_next = tddba->relations; tddba->relations = relation; @@ -757,10 +683,12 @@ int CLIB_ROUTINE main( int argc, char **argv) Y IN RDB$PAGES WITH Y.RDB$RELATION_ID EQ relation->rel_id AND Y.RDB$PAGE_SEQUENCE EQ 0 - if (Y.RDB$PAGE_TYPE == pag_pointer) + if (Y.RDB$PAGE_TYPE == pag_pointer) { relation->rel_pointer_page = Y.RDB$PAGE_NUMBER; - if (Y.RDB$PAGE_TYPE == pag_root) + } + if (Y.RDB$PAGE_TYPE == pag_root) { relation->rel_index_root = Y.RDB$PAGE_NUMBER; + } END_FOR; ON_ERROR EXIT(FINI_ERROR); @@ -786,12 +714,15 @@ int CLIB_ROUTINE main( int argc, char **argv) EXIT(FINI_ERROR); END_ERROR - if (request1) + if (request1) { isc_release_request(status_vector, &request1); - if (request2) + } + if (request2) { isc_release_request(status_vector, &request2); - if (request3) + } + if (request3) { isc_release_request(status_vector, &request3); + } COMMIT transact1; ON_ERROR @@ -805,23 +736,30 @@ int CLIB_ROUTINE main( int argc, char **argv) dba_print(10, 0, 0, 0, 0, 0); /* msg 10: \nAnalyzing database pages ...\n */ - for (relation = tddba->relations; relation; relation = relation->rel_next) { - if (relation->rel_id == -1) + for (relation = tddba->relations; relation; relation = relation->rel_next) + { + if (relation->rel_id == -1) { continue; - if (sw_data) + } + if (sw_data) { analyze_data(relation, sw_record); - for (index = relation->rel_indexes; index; index = index->idx_next) + } + for (index = relation->rel_indexes; index; index = index->idx_next) { analyze_index(relation, index); + } } /* Print results */ - for (relation = tddba->relations; relation; relation = relation->rel_next) { - if (relation->rel_id == -1) + for (relation = tddba->relations; relation; relation = relation->rel_next) + { + if (relation->rel_id == -1) { continue; + } FPRINTF(sw_outfile, "%s (%d)\n", relation->rel_name, relation->rel_id); - if (sw_data) { + if (sw_data) + { dba_print(11, (TEXT *) relation->rel_pointer_page, (TEXT *) relation->rel_index_root, 0, 0, 0); /* msg 11: " Primary pointer page: %ld, Index root page: %ld" */ if (sw_record) { @@ -857,7 +795,8 @@ int CLIB_ROUTINE main( int argc, char **argv) print_distribution("\t", relation->rel_fill_distribution); } FPRINTF(sw_outfile, "\n"); - for (index = relation->rel_indexes; index; index = index->idx_next) { + for (index = relation->rel_indexes; index; index = index->idx_next) + { dba_print(14, index->idx_name, (TEXT *) index->idx_id, 0, 0, 0); /* msg 14: " Index %s (%d)" */ dba_print(15, (TEXT *) index->idx_depth, (TEXT *) index->idx_leaf_buckets, @@ -876,6 +815,98 @@ int CLIB_ROUTINE main( int argc, char **argv) EXIT(FINI_OK); + } // try + catch (...) + { + /* free mem */ + + if (status_vector[1]) + { + STATUS *vector; + SCHAR s[1024]; +#ifdef SUPERSERVER + STATUS *status; + int i = 0, j; + + status = tddba->dba_service_blk->svc_status; + if (status != status_vector) + { + while (*status && (++i < ISC_STATUS_LENGTH)) { + status++; + } + for (j = 0; status_vector[j] && (i < ISC_STATUS_LENGTH); + j++, i++) + { + *status++ = status_vector[j]; + } + } +#endif + vector = status_vector; + if (isc_interprete(s, &vector)) + { + FPRINTF(tddba->sw_outfile, "%s\n", s); + s[0] = '-'; + while (isc_interprete(s + 1, &vector)) { + FPRINTF(tddba->sw_outfile, "%s\n", s); + } + } + } + + /* if there still exists a database handle, disconnect from the + * server + */ + FINISH; + +#ifdef SUPERSERVER + SVC_STARTED(service); + alloced = tddba->head_of_mem_list; + while (alloced != 0) { + free(alloced->memory); + alloced = alloced->mem_next; + } + + /* close files */ + open_file = tddba->head_of_files_list; + while (open_file) { + db_close(open_file->desc); + open_file = open_file->open_files_next; + } + + /* free linked lists */ + while (tddba->head_of_files_list != 0) { + tmp1 = tddba->head_of_files_list; + tddba->head_of_files_list = + tddba->head_of_files_list->open_files_next; + free(tmp1); + } + + while (tddba->head_of_mem_list != 0) { + tmp2 = tddba->head_of_mem_list; + tddba->head_of_mem_list = tddba->head_of_mem_list->mem_next; + free(tmp2); + } + + service->svc_handle = 0; + if (service->svc_service->in_use != NULL) + *(service->svc_service->in_use) = FALSE; + + /* Mark service thread as finished and cleanup memory being + * used by service in case if client detached from the service + */ + + SVC_finish(service, SVC_finished); +#endif + + int exit_code = tddba->exit_code; + RESTORE_THREAD_DATA; + +#ifdef SUPERSERVER + return exit_code; +#else + exit(exit_code); +#endif + } + return 0; } @@ -893,11 +924,10 @@ static SCHAR *alloc( SLONG size) * **************************************/ SCHAR *block, *p; -#ifdef SUPERSERVER - mem *mem_list; - TDBA tddba; - tddba = GET_THREAD_DATA; +#ifdef SUPERSERVER + + TDBA tddba = GET_THREAD_DATA; block = p = (SCHAR*) malloc(size); if (!p) { @@ -909,7 +939,8 @@ static SCHAR *alloc( SLONG size) *p++ = 0; while (--size); - if (!(mem_list = malloc(sizeof(mem)))) { + mem* mem_list = (mem*)malloc(sizeof(mem)); + if (!mem_list) { /* NOMEM: return error */ dba_error(31, 0, 0, 0, 0, 0); } @@ -1462,13 +1493,10 @@ static DBA_FIL db_open( UCHAR * file_name, USHORT file_length) * Open a database file. * **************************************/ - DBA_FIL fil; - TDBA tddba; -#ifdef SUPERSERVER - open_files *file_list; -#endif - tddba = GET_THREAD_DATA; + TDBA tddba = GET_THREAD_DATA; + + DBA_FIL fil; if (tddba->files) { for (fil = tddba->files; fil->fil_next; fil = fil->fil_next); @@ -1490,14 +1518,17 @@ static DBA_FIL db_open( UCHAR * file_name, USHORT file_length) fil->fil_fudge = 0; fil->fil_max_page = 0L; - if ((fil->fil_desc = CreateFile(file_name, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | - FILE_FLAG_RANDOM_ACCESS, - 0)) == INVALID_HANDLE_VALUE) { + fil->fil_desc = CreateFile( reinterpret_cast(file_name), + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | + FILE_FLAG_RANDOM_ACCESS, + 0); + + if (fil->fil_desc == INVALID_HANDLE_VALUE) + { #ifdef SUPERSERVER CMD_UTIL_put_svc_status(tddba->dba_service_blk->svc_status, GSTAT_MSG_FAC, 29, @@ -1508,11 +1539,12 @@ static DBA_FIL db_open( UCHAR * file_name, USHORT file_length) } #ifdef SUPERSERVER - if (!(file_list = malloc(sizeof(*file_list)))) { + open_files* file_list = reinterpret_cast(malloc(sizeof(*file_list))); + if (!file_list) { /* NOMEM: return error */ dba_error(31, 0, 0, 0, 0, 0); } - file_list->desc = fil->fil_desc; + file_list->desc = reinterpret_cast(fil->fil_desc); file_list->open_files_next = 0; if (tddba->head_of_files_list == 0) @@ -1569,9 +1601,12 @@ static PAG db_read( SLONG page_number) db_error(GetLastError()); } - if (!ReadFile - (fil->fil_desc, tddba->global_buffer, tddba->page_size, - &actual_length, NULL)) { + if (!ReadFile( fil->fil_desc, + tddba->global_buffer, + tddba->page_size, + reinterpret_cast(&actual_length), + NULL)) + { #ifdef SUPERSERVER CMD_UTIL_put_svc_status(tddba->dba_service_blk->svc_status, GSTAT_MSG_FAC, 30, diff --git a/src/utilities/dba_full.epp b/src/utilities/dba_full.epp index 5c253e5a69..697a014c20 100644 --- a/src/utilities/dba_full.epp +++ b/src/utilities/dba_full.epp @@ -146,7 +146,7 @@ static TEXT help_text[] = "Available switches:\n\ #include #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../jrd/svc.h" diff --git a/src/utilities/drop.cpp b/src/utilities/drop.cpp index 24eade16da..e61b71bb86 100644 --- a/src/utilities/drop.cpp +++ b/src/utilities/drop.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: drop.cpp,v 1.3 2001-07-29 23:43:24 skywalker Exp $ +$Id: drop.cpp,v 1.4 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" diff --git a/src/utilities/gsec.cpp b/src/utilities/gsec.cpp index 0408bded3f..4f50acc6cf 100644 --- a/src/utilities/gsec.cpp +++ b/src/utilities/gsec.cpp @@ -49,10 +49,6 @@ #include #endif - -extern "C" { - - #if defined (WIN95) && !defined (GUI_TOOLS) static BOOLEAN fAnsiCP = FALSE; #define TRANSLATE_CP(a) if (!fAnsiCP) CharToOem(a, a) @@ -85,7 +81,6 @@ int output_svc(SLONG, UCHAR *); static int output_main(SLONG, UCHAR *); - #ifdef SUPERSERVER int main_gsec( SVC service) { @@ -113,6 +108,7 @@ int main_gsec( SVC service) return exit_code; } + int output_svc( SLONG output_data, UCHAR * output_buf) { /************************************** @@ -205,8 +201,9 @@ int UTIL_gsec( tdsec = (struct tsec *) gds__alloc(sizeof(*tdsec)); /* NOMEM: return error, FREE: during function exit in the SETJMP */ - if (tdsec == NULL) + if (tdsec == NULL) { EXIT(FINI_ERROR); + } SET_THREAD_DATA; SVC_PUTSPECIFIC_DATA; @@ -215,29 +212,13 @@ int UTIL_gsec( tdsec->tsec_user_data = (struct user_data *) gds__alloc(sizeof(*user_data)); /* NOMEM: return error, FREE: during function exit in the SETJMP */ - if (tdsec->tsec_user_data == NULL) + if (tdsec->tsec_user_data == NULL) { EXIT(FINI_ERROR); + } memset((void *) tdsec->tsec_user_data, 0, sizeof(*user_data)); - if (SETJMP(env)) { - int exit_code; - - /* All calls to EXIT(), normal and error exits, wind up here */ - SVC_STARTED(tdsec->tsec_service_blk); - tdsec->tsec_env = NULL; - exit_code = tdsec->tsec_exit_code; - - if (tdsec->tsec_user_data != NULL) - gds__free((SLONG *) tdsec->tsec_user_data); - - if (tdsec != NULL) - gds__free((SLONG *) tdsec); - - /* All returns occur from this point - even normal returns */ - return exit_code; - } - + try { /* Perform some special handling when run as an Interbase service. The first switch can be "-svc" (lower case!) or it can be "-svc_re" followed @@ -390,6 +371,23 @@ int UTIL_gsec( } EXIT(FINI_OK); return 0; // silence compiler warning + + } // try + catch (...) { + /* All calls to EXIT(), normal and error exits, wind up here */ + SVC_STARTED(tdsec->tsec_service_blk); + tdsec->tsec_env = NULL; + const int exit_code = tdsec->tsec_exit_code; + + if (tdsec->tsec_user_data != NULL) + gds__free((SLONG *) tdsec->tsec_user_data); + + if (tdsec != NULL) + gds__free((SLONG *) tdsec); + + /* All returns occur from this point - even normal returns */ + return exit_code; + } } @@ -1322,5 +1320,3 @@ void UTIL_print_partial( util_output("%s ", buffer); } - -} // extern "C" diff --git a/src/utilities/gsec.h b/src/utilities/gsec.h index 0d536d6a8b..0d2b7f936c 100644 --- a/src/utilities/gsec.h +++ b/src/utilities/gsec.h @@ -87,7 +87,7 @@ typedef int (DLL_EXPORT* OUTPUTPROC) (SLONG, UCHAR *); #define EXIT(code) { tdsec->tsec_exit_code = (code); \ if (tdsec->tsec_env != NULL) \ - LONGJMP(*tdsec->tsec_env, 1); } + Firebird::status_longjmp_error::raise(1); } typedef struct user_data { int operation; /* what's to be done */ diff --git a/src/utilities/guard.cpp b/src/utilities/guard.cpp index 40679f5197..5ead457066 100644 --- a/src/utilities/guard.cpp +++ b/src/utilities/guard.cpp @@ -15,7 +15,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: guard.cpp,v 1.2 2001-07-29 23:43:24 skywalker Exp $ + * $Id: guard.cpp,v 1.3 2001-12-24 02:50:53 tamlin Exp $ */ /* contains the main() and not shared routines for ibguard */ diff --git a/src/utilities/ibmgr.cpp b/src/utilities/ibmgr.cpp index 22ec85bb30..4d9483d791 100644 --- a/src/utilities/ibmgr.cpp +++ b/src/utilities/ibmgr.cpp @@ -20,7 +20,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: ibmgr.cpp,v 1.2 2001-07-29 23:43:24 skywalker Exp $ + * $Id: ibmgr.cpp,v 1.3 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" diff --git a/src/utilities/ibmgr.h b/src/utilities/ibmgr.h index aca7950e8d..f664c10c22 100644 --- a/src/utilities/ibmgr.h +++ b/src/utilities/ibmgr.h @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: ibmgr.h,v 1.1.1.1 2001-05-23 13:26:42 tamlin Exp $ + * $Id: ibmgr.h,v 1.2 2001-12-24 02:50:53 tamlin Exp $ */ #ifndef _UTILITIES_IBMGR_H_ diff --git a/src/utilities/ibmgrswi.h b/src/utilities/ibmgrswi.h index 6dce271cf8..fe09aa0a07 100644 --- a/src/utilities/ibmgrswi.h +++ b/src/utilities/ibmgrswi.h @@ -19,7 +19,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: ibmgrswi.h,v 1.2 2001-08-01 08:11:52 skywalker Exp $ + * $Id: ibmgrswi.h,v 1.3 2001-12-24 02:50:53 tamlin Exp $ */ #ifndef _IBMGR_IBMGRSWI_H_ diff --git a/src/utilities/sbc_print.cpp b/src/utilities/sbc_print.cpp index 714b5744f9..45f54e0363 100644 --- a/src/utilities/sbc_print.cpp +++ b/src/utilities/sbc_print.cpp @@ -30,7 +30,7 @@ #include "../jrd/common.h" #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../jrd/isc.h" diff --git a/src/utilities/srvrmgr.cpp b/src/utilities/srvrmgr.cpp index 70bb21fe3a..ee85984951 100644 --- a/src/utilities/srvrmgr.cpp +++ b/src/utilities/srvrmgr.cpp @@ -20,7 +20,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: srvrmgr.cpp,v 1.2 2001-07-29 23:43:24 skywalker Exp $ + * $Id: srvrmgr.cpp,v 1.3 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" diff --git a/src/utilities/util.cpp b/src/utilities/util.cpp index e70967b431..9626948e44 100644 --- a/src/utilities/util.cpp +++ b/src/utilities/util.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: util.cpp,v 1.2 2001-07-29 23:43:24 skywalker Exp $ +$Id: util.cpp,v 1.3 2001-12-24 02:50:53 tamlin Exp $ */ #include "firebird.h" diff --git a/src/wal/wal_prnt.cpp b/src/wal/wal_prnt.cpp index 13242e809e..21ceba0d4f 100644 --- a/src/wal/wal_prnt.cpp +++ b/src/wal/wal_prnt.cpp @@ -36,7 +36,7 @@ #ifdef NETWARE_386 #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../jrd/svc.h" diff --git a/src/wal/walw.cpp b/src/wal/walw.cpp index 8e65494476..b3a227835b 100644 --- a/src/wal/walw.cpp +++ b/src/wal/walw.cpp @@ -47,12 +47,12 @@ #include "../jrd/llio_proto.h" #include "../jrd/misc_proto.h" #include "../jrd/divorce.h" +#include #ifdef HAVE_UNISTD_H #include #endif -#include #if !(defined WIN_NT) #ifndef VMS #include @@ -111,7 +111,8 @@ extern "C" { #define ERRNO errno #endif -typedef struct walwl { +typedef struct walwl +{ jmp_buf walwl_env; SLONG walwl_log_fd; struct jrn *walwl_journal_handle; @@ -375,14 +376,12 @@ SSHORT WALW_writer(STATUS * status_vector, WAL WAL_handle) acquired = FALSE; log_header = (WALFH) gds__alloc(WALFH_LENGTH); /* NOMEM: return failure, FREE: error returns & macro WALW_WRITER_RETURN */ - if (!log_header) + if (!log_header) { return FAILURE; - if (setjmp(ENV)) { - if (acquired) - WALC_release(WAL_handle); - WALW_WRITER_RETURN(FAILURE); } + try { + /* If there already is a WAL writer running, return quietly. */ if (WALC_check_writer(WAL_handle) == SUCCESS) @@ -631,6 +630,14 @@ SSHORT WALW_writer(STATUS * status_vector, WAL WAL_handle) ISC_event_clear(WAL_EVENTS + WAL_WRITER_WORK_DONE_SEM); WALW_WRITER_RETURN(SUCCESS); + + } // try + catch (...) { + if (acquired) { + WALC_release(WAL_handle); + } + WALW_WRITER_RETURN(FAILURE); + } } @@ -1760,7 +1767,7 @@ static void report_walw_bug_or_error( ib_fprintf(DEBUG_FD, "WAL writer encountered error, code=%d\n", code); } - longjmp(ENV, (int) status_vector[1]); + Firebird::status_longjmp_error::raise(status_vector[1]); } diff --git a/src/wal/wstatus.cpp b/src/wal/wstatus.cpp index 505daffde5..85cbd701e5 100644 --- a/src/wal/wstatus.cpp +++ b/src/wal/wstatus.cpp @@ -26,7 +26,7 @@ #include "../wal/walc_proto.h" #ifdef NETWARE_386 #ifndef INCLUDE_FB_BLK -#include "../include/fb_blk.h" +#include "../include/old_fb_blk.h" #endif #include "../jrd/svc.h"