void FEapply_null(ADF_CB *cb, char *null) { if ( (cb->adf_nullstr.nlst_string = STalloc(null)) == NULL ) { EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc2)")); } cb->adf_nullstr.nlst_length = STlength(null); }
/** ** Name: MHi8div() - Divide two i8 values ** ** Description: ** Return the resultant of dividing the two i8 operands and signal ** EXINTDIV if the divisor is equal to zero. ** ** Inputs: ** dv1,dv2 The input i8 operands. ** ** Outputs: ** none ** ** Returns: ** dv1/dv2 ** ** Exceptions: ** EXINTOVF ** ** Side Effects: ** none ** ** History: ** 18-mar-04 (inkdo01) ** Written for bigint support. */ i8 MHi8div(i8 dv1, i8 dv2) { if(dv2 == 0) { EXsignal(EXINTDIV, 0); return( 0); } return( dv1/dv2); }
/** ** Name: MHi4div() - Divide two i4 values ** ** Description: ** Return the resultant of dividing the two i4 operands and signal ** EXINTDIV if the dividsor is equal to zero. ** ** Inputs: ** dv1,dv2 The input i4 operands. ** ** Outputs: ** none ** ** Returns: ** dv1/dv2 ** ** Exceptions: ** EXINTOVF ** ** Side Effects: ** none ** ** History: ** 08-mar-1993 (stevet) ** Initial Creation. ** 06-apr-1993 (stevet) ** Return 0 on divid-by-zero error. */ i4 MHi4div(i4 dv1, i4 dv2) { if(dv2 == 0) { EXsignal(EXINTDIV, 0); return( 0); } return( dv1/dv2); }
/** ** Name: MHi8mul() - Multiply two i8 values ** ** Description: ** Return the resultant of multiplying the two i8 operands and signal ** EXINTOVF if the resultant excess MAXI8 or less than MINI8. ** ** Inputs: ** dv1,dv2 The input i8 operands. ** ** Outputs: ** none ** ** Returns: ** dv1*dv2 ** ** Exceptions: ** EXINTOVF ** ** Side Effects: ** none ** ** History: ** 18-mar-04 (inkdo01) ** Written for bigint support. */ i8 MHi8mul(i8 dv1, i8 dv2) { f8 temp1,temp2; temp1 = dv1; temp2 = temp1*dv2; if(temp2 > MAXI8 || temp2 < MINI8) EXsignal(EXINTOVF, 0); return( dv1*dv2); }
/** ** Name: MHi4mul() - Multiply two i4 values ** ** Description: ** Return the resultant of multiplying the two i4 operands and signal ** EXINTOVF if the resultant excess MAXI4 or less than MINI4. ** ** Inputs: ** dv1,dv2 The input i4 operands. ** ** Outputs: ** none ** ** Returns: ** dv1*dv2 ** ** Exceptions: ** EXINTOVF ** ** Side Effects: ** none ** ** History: ** 08-mar-1993 (stevet) ** Initial Creation. */ i4 MHi4mul(i4 dv1, i4 dv2) { f8 temp1,temp2; temp1 = dv1; temp2 = temp1*dv2; if(temp2 > MAXI4 || temp2 < MINI4) EXsignal(EXINTOVF, 0); return( dv1*dv2); }
/*{ ** Name: opx_error - this routine will report an optimizer error ** ** Description: ** This routine will report a E_DB_ERROR optimizer error. The routine ** will not return but instead generate an internal exception and ** exit via the exception handling mechanism. The error code will be ** placed directly in the user's calling control block. A ptr to this ** block was placed in the session control block (which can be requested ** from SCF) ** ** Inputs: ** error optimizer error code to report ** ** Outputs: ** Returns: ** - routine does not return ** Exceptions: ** - internal exception generated ** ** Side Effects: ** the exception handling routines are responsible for ** deallocating OPF resources bound to this session. ** ** History: ** 3-jul-86 (seputis) ** initial creation [@history_line@]... */ VOID opx_error( OPX_ERROR error) { OPS_CB *opscb; /* ptr to session control block ** for this optimization */ opscb = ops_getcb(); opscb->ops_retstatus = E_DB_ERROR; /* return status code */ opx_rerror( opscb->ops_callercb, error); /* log error */ EXsignal( (EX)EX_JNP_LJMP, (i4)1, (long)error);/* signal an optimizer long ** jump */ }
/*{ ** Name: opx_vrecover - this routine return an error code without reporting ** ** Description: ** This routine will not log or report to the user this recoverable error ** to but instead exit to the caller who is expected to take corrective ** action. ** ** Inputs: ** error optimizer error code to report ** facility facility's error code ** status facility's return status ** ** Outputs: ** Returns: ** VOID ** Exceptions: ** - internal exception generated ** ** Side Effects: ** the exception handling routines are responsible for ** deallocating OPF resources bound to this session. ** ** History: ** 3-jul-86 (seputis) ** initial creation [@history_line@]... */ VOID opx_vrecover( DB_STATUS status, OPX_ERROR error, OPX_FACILITY facility) { OPS_CB *opscb; /* ptr to session control block ** for this optimization */ opscb = ops_getcb(); opscb->ops_retstatus = status; /* save status code */ opscb->ops_callercb->opf_errorblock.err_code = error; /* save error code */ opscb->ops_callercb->opf_errorblock.err_data = facility; /* save code ** from facility */ if (DB_SUCCESS_MACRO(status)) { return; /* return if error is not ** serious */ } EXsignal( (EX)EX_JNP_LJMP, (i4)1, (long)error); /* signal an optimizer long ** jump with error code */ }
/*{ ** Name: opx_2perror - print error with 2 parameters ** ** Description: ** Print error with exactly 2 parameters, do not use variable parameters to ** avoid lint errors ** ** Inputs: ** error error message number ** p1 parameter 1 ** p2 parameter 2 ** ** Outputs: ** ** Returns: ** VOID ** Exceptions: ** exits via exception handler ** ** Side Effects: ** does not return ** ** History: ** 18-may-92 (seputis) ** initial creation for tech support ** 24-oct-92 (andre) ** interfaces of ule_format() and opx_sccerror() have been changed to ** receive (DB_SQLSTATE *) [@history_template@]... */ VOID opx_2perror( OPX_ERROR error, PTR p1, PTR p2) { DB_STATUS ule_status; /* return status from ule_format */ i4 ule_error; /* ule cannot format message */ char msg_buffer[DB_ERR_SIZE]; /* error message buffer */ i4 msg_buf_length; /* length of message returned */ i4 log; /* should this error be logged */ DB_SQLSTATE sqlstate; OPS_CB *opscb; /* ptr to session control block ** for this optimization */ opscb = ops_getcb(); opscb->ops_retstatus = E_DB_ERROR; /* return status code */ opscb->ops_callercb->opf_errorblock.err_code = error; /* save error code */ if ((error % 256) < 128) log = ULE_LOOKUP; else log = ULE_LOG; ule_status = ule_format( error, (CL_SYS_ERR *)NULL, log, &sqlstate, msg_buffer, (i4) (sizeof(msg_buffer)-1), &msg_buf_length, &ule_error, 2 /* 2 parameters */, (i4)0, p1, (i4)0, p2); if (ule_status != E_DB_OK) { (VOID)STprintf(msg_buffer, "ULE error = %x, Optimizer message cannot be found - error no. = %x\n", ule_error, error ); } else msg_buffer[msg_buf_length] = 0; /* null terminate */ (VOID) opx_sccerror(E_DB_ERROR, &sqlstate, error, msg_buffer, (i4)msg_buf_length); EXsignal( (EX)EX_JNP_LJMP, (i4)1, (long)error);/* signal an optimizer long ** jump */ }
/* Observe that philosopher n is thinking */ void thinks( i4 n) { #ifdef EX_DEBUG EX_CONTEXT context; if (EXdeclare(ex_handler, &context) != OK) { /* some exception was raised */ Psem( &SIsem ); SIfprintf( stderr,"exception raised while thinking, OK...\n"); Vsem( &SIsem ); EXdelete(); return; } #endif if( Noisy ) { Psem( &SIsem ); SIfprintf(stderr, "%d (%s) thinks...\n", n, Names[ n ] ); Vsem( &SIsem ); } CSswitch(); #ifdef EX_DEBUG EXsignal(not_handled, 0); Psem( &SIsem ); SIfprintf( stderr,"Error: should not be reached in thinks()..."); Vsem( &SIsem ); EXdelete(); #endif }
/*{ ** Name: opx_verror - this routine will report another facility's error ** ** Description: ** This routine will report an error from another facility ** optimizer error. It will check the status and see the error ** is recoverable. The routine will not return if the status is fatal ** but instead generate an internal exception and ** exit via the exception handling mechanism. The error code will be ** placed directly in the user's calling control block. A ptr to this ** block was placed in the session control block (which can be requested ** from SCF) ** ** Inputs: ** error optimizer error code to report ** facility facility's error code ** status facility's return status ** ** Outputs: ** Returns: ** VOID ** Exceptions: ** - internal exception generated ** ** Side Effects: ** the exception handling routines are responsible for ** deallocating OPF resources bound to this session. ** ** History: ** 3-jul-86 (seputis) ** initial creation ** 28-jan-91 (seputis) ** added support for OPF ACTIVE flag ** 30-apr-92 (bryanp) ** Translate E_RD002A_DEADLOCK to E_OP0010_RDF_DEADLOCK. [@history_line@]... */ VOID opx_verror( DB_STATUS status, OPX_ERROR error, OPX_FACILITY facility) { OPS_CB *opscb; /* ptr to session control block ** for this optimization */ opscb = ops_getcb(); opscb->ops_retstatus = status; /* save status code */ if (facility == E_RD002A_DEADLOCK) error = E_OP0010_RDF_DEADLOCK; if ((facility == E_RD002B_LOCK_TIMER_EXPIRED) && (opscb->ops_smask & OPS_MCONDITION)) { error = E_OP000D_RETRY; /* when an attempt is made to ** report the RDF timeout error ** then it should be translated ** into a retry error, since an ** undetected deadlock may have ** occurred due to the ACTIVE flag */ opscb->ops_server->opg_sretry++; /* track number of retrys */ opx_vrecover(status, E_OP000D_RETRY, facility); /* this routine will not ** return */ } else opx_rverror(opscb->ops_callercb, status, error, facility); if (DB_SUCCESS_MACRO(status)) { return; /* return if error is not ** serious */ } EXsignal( (EX)EX_JNP_LJMP, (i4)1, (long)error); /* signal an optimizer long ** jump with error code */ }
/* release sticks held by philosopher n */ void freesticks( i4 n) { #ifdef EX_DEBUG EX_CONTEXT context; if (EXdeclare(ex_handler2, &context) != OK) { /* free_exc error should never be EX_DECLARE'd. */ Psem( &SIsem ); SIfprintf( stderr,"Error: unexpected exception in freesticks()..."); Vsem( &SIsem ); EXdelete(); return; } #endif Psem( &Freesem ); #ifdef EX_DEBUG EXsignal(free_exc, 1, n); #endif Freesticks[ n ] += 2; ++Freesticks[ LEFT( n ) ]; ++Freesticks[ RIGHT( n ) ]; CSswitch(); /* gratuitous, tests semaphores */ Vsem( &Freesem ); #ifdef EX_DEBUG EXdelete(); #endif }
ADF_CB * FEadfcb () { if (!done) { char *cp; DB_STATUS rval; PTR srv_cb_ptr; SIZE_TYPE srv_size; SIZE_TYPE dbinfo_size; PTR dbinfoptr; STATUS tmtz_status; STATUS date_status; char date_type_alias[100]; char col[] = "udefault"; STATUS status = OK; CL_ERR_DESC sys_err; ADUUCETAB *ucode_ctbl; /* unicode collation information */ PTR ucode_cvtbl; done = TRUE; /* first, get the size of the ADF's server control block */ srv_size = adg_srv_size(); /* allocate enough memory for it */ if ((srv_cb_ptr = MEreqmem(0, srv_size, FALSE, (STATUS *)NULL)) == NULL) { EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)")); } /* ** Fix up code so that "now" works properly for frontends. ** Only allocating enough for one (1) dbmsinfo() request. */ dbinfo_size = sizeof(ADF_TAB_DBMSINFO); if ((dbinfoptr = MEreqmem(0, dbinfo_size, TRUE, (STATUS*)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("FEadfcb")); } dbinfo = (ADF_TAB_DBMSINFO *) dbinfoptr; dbinfo->tdbi_next = NULL; dbinfo->tdbi_prev = NULL; dbinfo->tdbi_length = dbinfo_size; dbinfo->tdbi_type = ADTDBI_TYPE; dbinfo->tdbi_s_reserved = -1; dbinfo->tdbi_l_reserved = (PTR)-1; dbinfo->tdbi_owner = (PTR)-1; dbinfo->tdbi_ascii_id = ADTDBI_ASCII_ID; dbinfo->tdbi_numreqs = 1; /* ** Now define request. */ dbinfo->tdbi_reqs[0].dbi_func = IIUGnfNowFunc; dbinfo->tdbi_reqs[0].dbi_num_inputs = 0; dbinfo->tdbi_reqs[0].dbi_lenspec.adi_lncompute = ADI_FIXED; STcopy("_BINTIM", dbinfo->tdbi_reqs[0].dbi_reqname); dbinfo->tdbi_reqs[0].dbi_reqcode = 1; dbinfo->tdbi_reqs[0].dbi_lenspec.adi_fixedsize = 4; dbinfo->tdbi_reqs[0].dbi_dtr = DB_INT_TYPE; /* ** set timezone in ADF cb - Any errors must be reported ** after adg_init() called. */ if ( (tmtz_status = TMtz_init(&cb.adf_tzcb)) == OK) { tmtz_status = TMtz_year_cutoff(&cb.adf_year_cutoff); } /* Always use INGRESDATE by default, and check ** 'ii.<node>.config.date_alias' (kibro01) b118702 */ cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_INGRES; STprintf(date_type_alias,ERx("ii.%s.config.date_alias"),PMhost()); date_status = PMget(date_type_alias, &cp); if (date_status == OK && cp != NULL && STlength(cp)) { if (STbcompare(cp, 0, ERx("ansidate"), 0, 1) == 0) cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_ANSI; else if (STbcompare(cp, 0, ERx("ingresdate"), 0, 1) == 0) cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_INGRES; else cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_NONE; } /* set timezone table to NULL in ADF cb, adg_init() will fill it */ /* cb.adf_tz_table = NULL; - not needed, done in declaration above */ /* Start up ADF */ rval = adg_startup(srv_cb_ptr, srv_size, dbinfo, 0); if (DB_FAILURE_MACRO(rval)) { /* ** Before bailing out, try to be helpful. Since the environment ** is likely not set up correctly, write hard coded messages ** since error message fetch will likely fail in this situation. */ char *tempchar; i4 dummy; LOCATION temploc; NMgtAt("II_SYSTEM", &tempchar); if (tempchar && *tempchar) { LOfroms(PATH, tempchar, &temploc); if (LOexist(&temploc)) { tempchar = ERx("FEadfcb: II_SYSTEM DOES NOT EXIST\n"); SIwrite(STlength(tempchar), tempchar, &dummy, stderr); } else { NMloc(ADMIN, FILENAME, ERx("config.dat"), &temploc); if (LOexist(&temploc)) { tempchar = ERx("FEadfcb: II_SYSTEM IS NOT SET CORRECTLY\n"); SIwrite(STlength(tempchar), tempchar, &dummy, stderr); } } } else { tempchar = ERx("FEadfcb: II_SYSTEM IS NOT SET\n"); SIwrite(STlength(tempchar), tempchar, &dummy, stderr); } EXsignal(EXFEBUG, 1, ERx("FEadfcb(start)")); } /* put the pointer to ADF's server control block in the ADF_CB */ cb.adf_srv_cb = srv_cb_ptr; /* set up the error message buffer */ cb.adf_errcb.ad_ebuflen = DB_ERR_SIZE; cb.adf_errcb.ad_errmsgp = ebuffer; /* initialize the ADF_CB */ rval = adg_init(&cb); if (DB_FAILURE_MACRO(rval)) { EXsignal(EXFEBUG, 1, ERx("FEadfcb(init)")); } /* find out which natural language we should speak */ cb.adf_slang = iiuglcd_langcode(); /* Always QUEL; for SQL explictly change this with 'IIAFdsDmlSet()'. */ cb.adf_qlang = DB_QUEL; /* lets get the multinational info */ /* ** Defaults for all of these are initially set statically, above. */ NMgtAt(ERx("II_DATE_FORMAT"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_date_format(&cb,cp); } NMgtAt(ERx("II_MONEY_FORMAT"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_money_format(&cb,cp); } NMgtAt(ERx("II_MONEY_PREC"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_money_prec(&cb,cp); } NMgtAt(ERx("II_DECIMAL"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_decimal(&cb,cp); } NMgtAt(ERx("II_UNICODE_SUBS"), &cp); if ( !cp ) { cb.adf_unisub_status = AD_UNISUB_OFF; } else { /* As with SET unicode_substitution take the first char */ cb.adf_unisub_status = AD_UNISUB_ON; *cb.adf_unisub_char = cp[0]; } NMgtAt(ERx("II_NULL_STRING"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_null(&cb,cp); } /* If there was a Timezone error other than the expected ingbuild ** error TM_PMFILE_OPNERR, then lets report it now. */ if (tmtz_status && (tmtz_status != TM_PMFILE_OPNERR)) { LOCATION loc_root; STATUS status = OK; status = NMloc(FILES, PATH, ERx("zoneinfo"), &loc_root); #if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64) status = LOfaddpath(&loc_root, ERx("lp64"), &loc_root); #endif #if defined(conf_BUILD_ARCH_64_32) && defined(BUILD_ARCH32) { /* ** Reverse hybrid support must be available in ALL ** 32bit binaries */ char *rhbsup; NMgtAt("II_LP32_ENABLED", &rhbsup); if ( (rhbsup && *rhbsup) && ( !(STbcompare(rhbsup, 0, "ON", 0, TRUE)) || !(STbcompare(rhbsup, 0, "TRUE", 0, TRUE)))) status = LOfaddpath(&loc_root, "lp32", &loc_root); } #endif /* ! LP64 */ if ( status == OK ) { status = LOexist(&loc_root); } if ( status == OK ) { IIUGerr(tmtz_status, 0, 0); /* As this may disappear from the screen quickly, ** let's pause to allow the users to reflect on the ** fact that the timezone info is (probably) wrong. */ if (!IIugefa_err_function) PCsleep(5000); } } /* Initialize unicode collation for UTF8 installations */ if (CMischarset_utf8()) { if (status = aduucolinit(col, MEreqmem, &ucode_ctbl, &ucode_cvtbl, &sys_err)) { EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)")); } cb.adf_ucollation = (PTR) ucode_ctbl; /* Set unicode normalization to NFC just in case ** Front end will need it. */ if ((status = adg_setnfc(&cb)) != E_DB_OK) EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)")); } /* lets not do this again! */ } return &cb; }