int _except_handler3(PEXCEPTION_RECORD rec, MSVCRT_EXCEPTION_FRAME* frame, PCONTEXT context, void *dispatcher) { long retval; int trylevel; EXCEPTION_POINTERS exceptPtrs; PSCOPETABLE pScopeTable; //syslog(LOG_DEBUG, "msvcrt: exception %lx flags=%lx at %p handler=%p %p %p semi-stub", // rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, // frame->handler, context, dispatcher); __asm cld; if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)) { // Unwinding the current frame _local_unwind2(frame, TRYLEVEL_END); return ExceptionContinueSearch; } else { // Hunting for handler exceptPtrs.ExceptionRecord = rec; exceptPtrs.ContextRecord = context; *((DWORD *) frame - 1) = (DWORD) &exceptPtrs; trylevel = frame->trylevel; pScopeTable = frame->scopetable; while (trylevel != TRYLEVEL_END) { if (pScopeTable[trylevel].lpfnFilter) { //syslog(LOG_DEBUG, "filter = %p", pScopeTable[trylevel].lpfnFilter); retval = call_filter(pScopeTable[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp); //syslog(LOG_DEBUG, "filter returned %s", retval == EXCEPTION_CONTINUE_EXECUTION ? // "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ? // "EXECUTE_HANDLER" : "CONTINUE_SEARCH"); if (retval == EXCEPTION_CONTINUE_EXECUTION) return ExceptionContinueExecution; if (retval == EXCEPTION_EXECUTE_HANDLER) { // Unwind all higher frames, this one will handle the exception _global_unwind2((PEXCEPTION_FRAME) frame); _local_unwind2(frame, trylevel); // Set our trylevel to the enclosing block, and call the __finally code, which won't return frame->trylevel = pScopeTable->previousTryLevel; //syslog(LOG_DEBUG, "__finally block %p",pScopeTable[trylevel].lpfnHandler); call_finally_block(pScopeTable[trylevel].lpfnHandler, &frame->_ebp); panic("Returned from __finally block"); } } trylevel = pScopeTable->previousTryLevel; } } return ExceptionContinueSearch; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *input_values; /* 1xN input matrix */ double *output_values; /* 1xN output matrix */ size_t n; /* size of matrix */ /* Check for proper number of arguments */ if (nrhs != 1) { mexErrMsgIdAndTxt("MATLAB:mex_weighting_filter2:nargin", "mex_weighting_filter2 requires three input arguments."); } else if (nlhs > 1) { mexErrMsgIdAndTxt("MATLAB:mex_weighting_filter2:nargout", "mex_weighting_filter2 requires 1 output argument."); } /* make sure the first input argument is type double */ if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0])) { mexErrMsgIdAndTxt("MATLAB:mex_weighting_filter2:notDouble","mex_weighting_filter2 input vector must be type double."); } /* create a pointer to the real data in the input matrix 1 */ input_values = mxGetPr(prhs[0]); /* get dimensions of the input matrices */ n = mxGetN(prhs[0]); /* create the output matrix */ plhs[0] = mxCreateDoubleMatrix(1,(mwSize)n,mxREAL); /* get a pointer to the real data in the output matrix */ output_values = mxGetPr(plhs[0]); /* call the computational routine */ call_filter(output_values,input_values,n); return; }