inline float Power(float x, float y) { Verify(x >= 0); return static_cast<float>(pow(static_cast<double>(x), static_cast<double>(y))); }
void Dismiss() { Verify(this == get_Top()); // corruption test m_pPrev->put_Top(); }
int main() { double data[][5] = { { 0.1, 0.2, 0.3, 0.4, 0.5 }, { 1.1, 1.2, 1.3, 1.4, 1.5 }, { 2.1, 2.2, 2.3, 2.4, 2.5 }, }; std::wstring fileName = L"data.dat"; std::ofstream os(ws2s(fileName)); if (os.is_open()) { for (size_t j = 0; j < ARRAYSIZE(data[0]); ++j) { for (size_t i = 0; i < ARRAYSIZE(data); ++i) os.write(reinterpret_cast<const char *>(&data[i][j]), sizeof data[i][j]); } os.close(); } SharedFileDataSourcePtr dataSource = std::make_shared<SimpleFileDataSource<double>>(3, 1); Verify(dataSource->ReadFile(fileName)); for (int i = 0; i < dataSource->GetChannelCount(); ++i) { for (int j = 0; j < dataSource->GetLength(); ++j) std::cout << dataSource->Read(i, j, 1)[0] << "\t"; std::cout << std::endl; } DIVIDING_LINE_2('-', 79); short data2[][5] = { { short(0.1 * 1000), short(0.2 * 1000), short(0.3 * 1000), short(0.4 * 1000), short(0.5 * 1000) }, { short(1.1 * 1000), short(1.2 * 1000), short(1.3 * 1000), short(1.4 * 1000), short(1.5 * 1000) }, { short(2.1 * 1000), short(2.2 * 1000), short(2.3 * 1000), short(2.4 * 1000), short(2.5 * 1000) }, }; std::ofstream os2(ws2s(fileName)); if (os2.is_open()) { for (size_t j = 0; j < ARRAYSIZE(data2[0]); ++j) { for (size_t i = 0; i < ARRAYSIZE(data2); ++i) os2.write(reinterpret_cast<const char *>(&data2[i][j]), sizeof data2[i][j]); } os2.close(); } dataSource = std::make_shared<SimpleFileDataSource<short>>(3, 1); Verify(dataSource->ReadFile(fileName)); for (int i = 0; i < dataSource->GetChannelCount(); ++i) { for (int j = 0; j < dataSource->GetLength(); ++j) std::cout << dataSource->Read(i, j, 1)[0] << "\t"; std::cout << std::endl; } return 0; }
// ignores milli seconds void CTimeStamp::ToLocalTime(tm* tm_struct) const { // tm* _Time = localtime(& m_TimeB.time); // memcpy(tm_struct, _Time, sizeof tm); Verify(localtime_s(tm_struct, & m_TimeB.time) == 0); }
// Draw the src rect of the specified image into the dest rect of the hdc void CImgBitsDIB::StretchBlt(HDC hdc, RECT* prcDst, RECT* prcSrc, DWORD dwRop, DWORD dwFlags) { HDC hdcDib = NULL; HBITMAP hbmSav = NULL; int xDst = prcDst->left; int yDst = prcDst->top; int xDstWid = prcDst->right - xDst; int yDstHei = prcDst->bottom - yDst; int xSrc = prcSrc->left; int ySrc = prcSrc->top; int xSrcWid = prcSrc->right - xSrc; int ySrcHei = prcSrc->bottom - ySrc; int yUseHei = _yHeight; // Cases in which there is nothing to draw if((!_pvImgBits && !_pvMaskBits && !_fSolid) || _yHeightValid==0) { return; } if(xDstWid<=0 || xSrcWid<=0 || _xWidth<=0 || yDstHei<=0 || ySrcHei<=0 || _yHeight<=0) { return; } if(dwRop!=SRCCOPY && (_pvMaskBits || _iTrans>=0)) { return; } // Step 1: Limit the source and dest rectangles to the visible area only. if(_yHeightValid>0 && _yHeightValid<_yHeight) { yUseHei = _yHeightValid; } if(xSrc < 0) { xDst += MulDivQuick(-xSrc, xDstWid, xSrcWid); xDstWid = prcDst->right - xDst; xSrcWid += xSrc; xSrc = 0; if(xDstWid<=0 || xSrcWid<=0) { return; } } if(ySrc < 0) { yDst += MulDivQuick(-ySrc, yDstHei, ySrcHei); yDstHei = prcDst->bottom - yDst; ySrcHei += ySrc; ySrc = 0; if(yDstHei<=0 || ySrcHei<=0) { return; } } if(xSrc+xSrcWid > _xWidth) { xDstWid = MulDivQuick(xDstWid, _xWidth-xSrc, xSrcWid); xSrcWid = _xWidth - xSrc; if(xDstWid<=0 || xSrcWid<=0) { return; } } if(ySrc+ySrcHei > yUseHei) { yDstHei = MulDivQuick(yDstHei, yUseHei-ySrc, ySrcHei); ySrcHei = yUseHei - ySrc; if(yDstHei<=0 || ySrcHei<=0) { return; } } // For the mirrored case, we need flip then offset. if(_fNeedMirroring) { // We need to handle clipping correctly and give a right-to-left tiling effect. // Let's take the "opposite" slice of the source. // The maximum will be the whole image. xSrc = - xSrc +_xWidth - xSrcWid; xDst += xDstWid - 1; xDstWid = - xDstWid; } // Optimization: if solid, just patblt the color if(_fSolid) { // Turn on the palette relative bit for palettized devices in order to ensure that dithering // doesn't happen here. The main reason is that is looks ugly, but more importantly we aren't // prepared to seam multiple copies of the image so that the dithering looks smooth. PatBltBrush(hdc, xDst, yDst, xDstWid, yDstHei, PATCOPY, _crSolid|g_crPaletteRelative); return; } SetStretchBltMode(hdc, COLORONCOLOR); // Step 2: For tranparent images, use mask to whiten drawing area if(_pvMaskBits || _iTrans>=0) { if(dwFlags & DRAWIMAGE_NOTRANS) { goto NoTransparency; } if(GetDeviceCaps(hdc, TECHNOLOGY) == DT_RASPRINTER) { // No transparency for printers that we know lie about their support for transparency. int iEscapeFunction = POSTSCRIPT_PASSTHROUGH; THREADSTATE* pts = GetThreadState(); if(Escape(hdc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&iEscapeFunction, NULL)) { // Skip transparency unless we are a mask-only image if(_pvImgBits || !_pvMaskBits) { goto NoTransparency; } } } if(_pvMaskBits) { // 1-bit mask case if(_hbmMask) { // We have an HBITMAP, not just bits Assert(!hdcDib && !hbmSav); hdcDib = GetMemoryDC(); if(!hdcDib) { goto Cleanup; } // Special case: use MaskBlt for the whole thing on NT if(xSrcWid==xDstWid && ySrcHei==yDstHei && _hbmImg) { hbmSav = (HBITMAP)SelectObject(hdcDib, _hbmImg); MaskBlt(hdc, xDst, yDst, xDstWid, yDstHei, hdcDib, xSrc, ySrc, _hbmMask, xSrc, ySrc, 0xAACC0020); goto Cleanup; } hbmSav = (HBITMAP)SelectObject(hdcDib, _hbmMask); if(!_pvImgBits) { // a mask-only one-bit image: just draw the "1" bits as black ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei, hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, MERGEPAINT); } else { // transparent mask: draw the "1" bits as white ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei, hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, SRCPAINT); } } else { // We have just bits, not an HBITMAP struct { BITMAPINFOHEADER bmih; union { RGBQUAD rgb[2]; WORD windex[2]; }; } bmiMask; // construct mask header memset(&bmiMask, 0, sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*2); bmiMask.bmih.biSize = sizeof(BITMAPINFOHEADER); bmiMask.bmih.biWidth = _xWidth; bmiMask.bmih.biHeight = _yHeight; bmiMask.bmih.biPlanes = 1; bmiMask.bmih.biBitCount = 1; if(!_pvImgBits) { // a mask-only one-bit image: just draw the "1" bits as black bmiMask.rgb[0] = g_rgbWhite; StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei, xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvMaskBits, (BITMAPINFO*)&bmiMask, DIB_RGB_COLORS, SRCAND); } else if(_iBitCount<=8 && _fPalColors && !(dwFlags&DRAWIMAGE_NHPALETTE)) { // this setup only occurs on an 8-bit palettized display; we can use DIB_PAL_COLORS bmiMask.windex[1] = 255; StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei, xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvMaskBits, (BITMAPINFO*)&bmiMask, DIB_PAL_COLORS, SRCPAINT); } else { bmiMask.rgb[1] = g_rgbWhite; StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei, xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvMaskBits, (BITMAPINFO *)&bmiMask, DIB_RGB_COLORS, SRCPAINT); } } } else { // 1- 4- or 8-bit mask case (with _iTrans) long cTable = 1 << _iBitCount; Assert(_iTrans >= 0); Assert(_iTrans < cTable); Assert(_iBitCount <= 8); if(_hbmImg) { // We have an HBITMAP, not just bits RGBQUAD argbOld[256]; RGBQUAD argbNew[256]; memset(argbNew, 0, sizeof(RGBQUAD)*cTable); argbNew[_iTrans] = g_rgbWhite; Assert(!hdcDib && !hbmSav); hdcDib = GetMemoryDC(); if(!hdcDib) { goto Cleanup; } hbmSav = (HBITMAP)SelectObject(hdcDib, _hbmImg); // HBM case: we need to change the color table, which can only be done one-at-a time g_csImgTransBlt.Enter(); Verify(GetDIBColorTable(hdcDib, 0, cTable, argbOld) > 0); Verify(SetDIBColorTable(hdcDib, 0, cTable, argbNew) == (unsigned)cTable); ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei, hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, MERGEPAINT); Verify(SetDIBColorTable(hdcDib, 0, cTable, argbOld) == (unsigned)cTable); g_csImgTransBlt.Leave(); } else { // We have just bits, not an HBITMAP struct { BITMAPINFOHEADER bmih; RGBQUAD rgb[256]; } bmiMask; // construct mask header memset(&bmiMask, 0, sizeof(BITMAPINFOHEADER)+(sizeof(RGBQUAD)*cTable)); bmiMask.bmih.biSize = sizeof(BITMAPINFOHEADER); bmiMask.bmih.biWidth = _xWidth; bmiMask.bmih.biHeight = _yHeight; bmiMask.bmih.biPlanes = 1; bmiMask.bmih.biBitCount = _iBitCount; bmiMask.rgb[_iTrans] = g_rgbWhite; StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei, xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvImgBits, (BITMAPINFO*)&bmiMask, DIB_RGB_COLORS, MERGEPAINT); } } // prepare for transparent blt: area to be painted is now whitened, so AND-blt on top of it dwRop = SRCAND; } NoTransparency: // Step 3: Draw the image bits if(_pvImgBits) { if(dwFlags & DRAWIMAGE_MASKONLY) { goto Cleanup; } if(_hbmImg) { // The normal case (not to a Win95 printer): call StretchBlt if(!hdcDib) { hdcDib = GetMemoryDC(); if(!hdcDib) { goto Cleanup; } } HBITMAP hbmOld; hbmOld = (HBITMAP)SelectObject(hdcDib, _hbmImg); if(!hbmSav) { hbmSav = hbmOld; } ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei, hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, dwRop); } else { // We have just bits, not an HBITMAP if(!_pbmih) { // No color table header: cobble up a standard header [perhaps these should just be globally cached?] struct { BITMAPINFOHEADER bmih; union { WORD windex[256]; RGBQUAD rgb[256]; DWORD bfmask[3]; }; } bmi; DWORD dwDibMode = DIB_RGB_COLORS; // construct mask header memset(&bmi, 0, sizeof(BITMAPINFOHEADER)+(_iBitCount>8?sizeof(DWORD)*3:sizeof(WORD)*(_iBitCount<<1))); bmi.bmih.biSize = sizeof(BITMAPINFOHEADER); bmi.bmih.biWidth = _xWidth; bmi.bmih.biHeight = _yHeight; bmi.bmih.biPlanes = 1; bmi.bmih.biBitCount = _iBitCount + (_iBitCount==15); if(_iBitCount == 4) { // Thanks to Steve Palmer: fix VGA color rendering bmi.bmih.biClrUsed = 16; bmi.bmih.biClrImportant = 16; CopyColorsFromPaletteEntries(bmi.rgb, g_peVga, 16); } else if(_iBitCount <= 8) { if(dwFlags & DRAWIMAGE_NHPALETTE) { // If being drawn on an <= 8-bit surface from a filter, we can make no assumptions about // the selected palette, so use RGB_COLORS LONG c; c = (1 << (_iBitCount-1)); memcpy(bmi.rgb, g_rgbHalftone, c*sizeof(RGBQUAD)); memcpy(bmi.rgb+c, g_rgbHalftone+256-c, c*sizeof(RGBQUAD)); } else { // internal draw, no color table with _iBitCount <= 8 means that the palette selected into hdc // is our standard 8-bit halftone palette and we can use DIB_PAL_COLORS LONG c; LONG d; WORD* pwi; dwDibMode = DIB_PAL_COLORS; for(c=(1<<(_iBitCount-1)),pwi=bmi.windex+c; c; *(--pwi)=(--c)); for(c=(1<<(_iBitCount-1)),pwi=bmi.windex+c*2,d=256; c; --c,*(--pwi)=(--d)); } } else if(_iBitCount == 16) { // sixteen-bit case: fill in the bitfields mask for 565 bmi.bmih.biCompression = BI_BITFIELDS; bmi.bfmask[0] = MASK565_0; bmi.bfmask[1] = MASK565_1; bmi.bfmask[2] = MASK565_2; } StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei, xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvImgBits, (BITMAPINFO*)&bmi, dwDibMode, dwRop); } else { StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei, xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvImgBits, (BITMAPINFO*)_pbmih, DIB_RGB_COLORS, dwRop); } } } Cleanup: if(hbmSav) { SelectObject(hdcDib, hbmSav); } if(hdcDib) { ReleaseMemoryDC(hdcDib); } }
// //########################################################################### //########################################################################### // RGBColor& RGBColor::operator=(const HSVColor &color) { Check_Object(this); Check_Object(&color); Verify(color.saturation >= 0.0 && color.saturation <= 1.0f); // //---------------- // Check for black //---------------- // if (color.saturation <= SMALL) { red = green = blue = 0.0f; return *this; } // //----------------------------- // find the sextant for the hue //----------------------------- // Verify(color.hue >= 0.0 && color.hue <= 1.0f); Scalar hue = (color.hue == 1.0f) ? 0.0f : color.hue; hue *= 6.0f; int sextant = Truncate_Float_To_Byte(hue); Verify(static_cast<unsigned>(sextant) < 6); Scalar remainder = hue - static_cast<Scalar>(sextant); // //-------------------- // Build the RGB color //-------------------- // Verify(color.value >= 0.0f && color.value <= 1.0f); Scalar a = color.value * (1.0f - color.saturation); Verify(a >= 0.0f && a < 1.0f); switch (sextant) { case 0: red = color.value; green = color.value * (1.0f - color.saturation * (1.0f - remainder)); Verify(green >= 0.0f && green <= 1.0f); blue = a; break; case 1: red = color.value * (1.0f - color.saturation * remainder); Verify(red >= 0.0f && red <= 1.0f); green = color.value; blue = a; break; case 2: red = a; green = color.value; blue = color.value * (1.0f - color.saturation * (1.0f - remainder)); Verify(blue >= 0.0f && blue <= 1.0f); break; case 3: red = a; green = color.value * (1.0f - color.saturation * remainder); Verify(green >= 0.0f && green <= 1.0f); blue = color.value; break; case 4: red = color.value * (1.0f - color.saturation * (1.0f - remainder)); Verify(red >= 0.0f && red <= 1.0f); green = a; blue = color.value; break; case 5: red = color.value; green = a; blue = color.value * (1.0f - color.saturation * remainder); Verify(blue >= 0.0f && blue <= 1.0f); break; } return *this; }
void* operator new(size_t size) { Verify(size == sizeof(MLRIndexedPolyMesh)); return AllocatedMemory->New(); }
// 改变窗口大小 ///////////////////////////////////////////////////////////////////////////////// void D3D11RenderWindow::Resize(uint32_t width, uint32_t height) { width_ = width; height_ = height; // Notify viewports of resize viewport_->width = width; viewport_->height = height; RenderFactory& rf = Context::Instance().RenderFactoryInstance(); D3D11RenderEngine& d3d11_re = *checked_cast<D3D11RenderEngine*>(&rf.RenderEngineInstance()); ID3D11DeviceContextPtr d3d_imm_ctx = d3d11_re.D3DDeviceImmContext(); if (d3d_imm_ctx) { d3d_imm_ctx->ClearState(); } for (size_t i = 0; i < clr_views_.size(); ++ i) { clr_views_[i].reset(); } rs_view_.reset(); render_target_view_.reset(); depth_stencil_view_.reset(); back_buffer_.reset(); depth_stencil_.reset(); UINT flags = 0; if (this->FullScreen()) { flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; } this->OnUnbind(); #ifdef KLAYGE_PLATFORM_WINDOWS_DESKTOP #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) if (dxgi_sub_ver_ >= 2) { dxgi_stereo_support_ = gi_factory_2_->IsWindowedStereoEnabled() ? true : false; sc_desc1_.Width = width_; sc_desc1_.Height = height_; sc_desc1_.Stereo = (STM_LCDShutter == Context::Instance().Config().graphics_cfg.stereo_method) && dxgi_stereo_support_; } else #endif { sc_desc_.BufferDesc.Width = width_; sc_desc_.BufferDesc.Height = height_; } #else dxgi_stereo_support_ = gi_factory_2_->IsWindowedStereoEnabled() ? true : false; sc_desc1_.Width = width_; sc_desc1_.Height = height_; sc_desc1_.Stereo = (STM_LCDShutter == Context::Instance().Config().graphics_cfg.stereo_method) && dxgi_stereo_support_; #endif if (!!swap_chain_) { swap_chain_->ResizeBuffers(2, width, height, back_buffer_format_, flags); } else { ID3D11DevicePtr d3d_device = d3d11_re.D3DDevice(); #ifdef KLAYGE_PLATFORM_WINDOWS_DESKTOP #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) if (dxgi_sub_ver_ >= 2) { IDXGISwapChain1* sc = nullptr; gi_factory_2_->CreateSwapChainForHwnd(d3d_device.get(), hWnd_, &sc_desc1_, &sc_fs_desc_, nullptr, &sc); swap_chain_ = MakeCOMPtr(sc); } else #endif { IDXGISwapChain* sc = nullptr; gi_factory_->CreateSwapChain(d3d_device.get(), &sc_desc_, &sc); swap_chain_ = MakeCOMPtr(sc); } swap_chain_->SetFullscreenState(this->FullScreen(), nullptr); #else IDXGISwapChain1* sc = nullptr; gi_factory_2_->CreateSwapChainForCoreWindow(d3d_device.get(), reinterpret_cast<IUnknown*>(wnd_.Get()), &sc_desc1_, nullptr, &sc); swap_chain_ = MakeCOMPtr(sc); #endif Verify(!!swap_chain_); } this->UpdateSurfacesPtrs(); d3d11_re.ResetRenderStates(); this->OnBind(); App3DFramework& app = Context::Instance().AppInstance(); app.OnResize(width, height); }
/** * Get the ID of a task * @returns Task ID of this task. Task::kInvalidTaskID (-1) if the task has not been started or has already exited. */ INT32 NTTask::GetID() { if (Verify()) return m_taskID; return kInvalidTaskID; }
//------------------------------------------------------------------------------ // void gosFX::CardCloud::TestInstance(void) const { Verify(IsDerivedFrom(DefaultData)); }
void pilotfile::csg_read_missions() { int i, j, idx, list_size; cmission *missionp; if ( !m_have_info ) { throw "Missions before Info!"; } for (i = 0; i < Campaign.num_missions_completed; i++) { idx = cfread_int(cfp); missionp = &Campaign.missions[idx]; missionp->completed = 1; // flags missionp->flags = cfread_int(cfp); // goals missionp->num_goals = cfread_int(cfp); if (missionp->num_goals > 0) { missionp->goals = (mgoal *) vm_malloc( missionp->num_goals * sizeof(mgoal) ); Verify( missionp->goals != NULL ); memset( missionp->goals, 0, missionp->num_goals * sizeof(mgoal) ); for (j = 0; j < missionp->num_goals; j++) { cfread_string_len(missionp->goals[j].name, NAME_LENGTH, cfp); missionp->goals[j].status = cfread_char(cfp); } } // events missionp->num_events = cfread_int(cfp); if (missionp->num_events > 0) { missionp->events = (mevent *) vm_malloc( missionp->num_events * sizeof(mevent) ); Verify( missionp->events != NULL ); memset( missionp->events, 0, missionp->num_events * sizeof(mevent) ); for (j = 0; j < missionp->num_events; j++) { cfread_string_len(missionp->events[j].name, NAME_LENGTH, cfp); missionp->events[j].status = cfread_char(cfp); } } // variables missionp->num_variables = cfread_int(cfp); if (missionp->num_variables > 0) { missionp->variables = (sexp_variable *) vm_malloc( missionp->num_variables * sizeof(sexp_variable) ); Verify( missionp->variables != NULL ); memset( missionp->variables, 0, missionp->num_variables * sizeof(sexp_variable) ); for (j = 0; j < missionp->num_variables; j++) { missionp->variables[j].type = cfread_int(cfp); cfread_string_len(missionp->variables[j].text, TOKEN_LENGTH, cfp); cfread_string_len(missionp->variables[j].variable_name, TOKEN_LENGTH, cfp); } } // scoring stats missionp->stats.score = cfread_int(cfp); missionp->stats.rank = cfread_int(cfp); missionp->stats.assists = cfread_int(cfp); missionp->stats.kill_count = cfread_int(cfp); missionp->stats.kill_count_ok = cfread_int(cfp); missionp->stats.bonehead_kills = cfread_int(cfp); missionp->stats.p_shots_fired = cfread_uint(cfp); missionp->stats.p_shots_hit = cfread_uint(cfp); missionp->stats.p_bonehead_hits = cfread_uint(cfp); missionp->stats.s_shots_fired = cfread_uint(cfp); missionp->stats.s_shots_hit = cfread_uint(cfp); missionp->stats.s_bonehead_hits = cfread_uint(cfp); // ship kills (scoring) list_size = (int)ship_list.size(); for (j = 0; j < list_size; j++) { idx = cfread_int(cfp); if (ship_list[j].index >= 0) { missionp->stats.kills[ship_list[j].index] = idx; } } // medals (scoring) list_size = (int)medals_list.size(); for (j = 0; j < list_size; j++) { idx = cfread_int(cfp); if (medals_list[j].index >= 0) { missionp->stats.medal_counts[medals_list[j].index] = idx; } } } }
int GetNumberOfSetBits() {Check_Pointer(this); Verify(clippingState<=ClipMask); return numberBitsLookUpTable[clippingState]; }
//-------------------------------------------------------------------------- // BLoad() -- THIS HAS NOT BEEN FULLY TESTED! // // NOTICE : This version of BLOAD is compatable with JAMPak V3.0 and the // new fileformat... //-------------------------------------------------------------------------- unsigned long BLoad(char *SourceFile, memptr *DstPtr) { int handle; memptr SrcPtr; unsigned long i, j, k, r, c; word flags; byte Buffer[8]; unsigned long SrcLen,DstLen; struct CMP1Header CompHeader; boolean Compressed = false; memset((void *)&CompHeader,0,sizeof(struct CMP1Header)); // // Open file to load.... // if ((handle = open(SourceFile, O_RDONLY|O_BINARY)) == -1) return(0); // // Look for JAMPAK headers // read(handle,Buffer,4); if (!strncmp(Buffer,COMP,4)) { // // Compressed under OLD file format // Compressed = true; SrcLen = Verify(SourceFile); read(handle,(void *)&CompHeader.OrginalLen,4); CompHeader.CompType = ct_LZW; MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else if (!strncmp(Buffer,CMP1,4)) { // // Compressed under new file format... // Compressed = true; SrcLen = Verify(SourceFile); read(handle,(void *)&CompHeader,sizeof(struct CMP1Header)); MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else DstLen = Verify(SourceFile); // // Load the file in memory... // if (Compressed) { DstLen = CompHeader.OrginalLen; if ((MM_TotalFree() < SrcLen) && (CompHeader.CompType)) { if (!InitBufferedIO(handle,&lzwBIO)) TrashProg("No memory for buffered I/O."); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: lzwDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: lzhDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM)); break; #endif default: TrashProg("BLoad() - Unrecognized/Supported compression"); break; } FreeBufferedIO(&lzwBIO); } else { CA_LoadFile(SourceFile,&SrcPtr); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: lzwDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_MEM|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: lzhDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM)); break; #endif default: TrashProg("BLoad() - Unrecognized/Supported compression"); break; } MM_FreePtr(&SrcPtr); } } else CA_LoadFile(SourceFile,DstPtr); close(handle); return(DstLen); }
inline uint8_t Round_Float_To_Byte(float in) { Verify(in >= 0.0f && in < 256.0f); in += 12582912.0f; return *Cast_Pointer(puint8_t, &in); }
int IpVerify::Verify( DCpermission perm, const condor_sockaddr& addr, const char * user, MyString *allow_reason, MyString *deny_reason ) { perm_mask_t mask; in6_addr sin6_addr; const char *thehost; const char * who = user; MyString peer_description; // we build this up as we go along (DNS etc.) if( !did_init ) { Init(); } /* * Be Warned: careful about parameter "sin" being NULL. It could be, in * which case we should return FALSE (unless perm is ALLOW) * */ switch ( perm ) { case ALLOW: return USER_AUTH_SUCCESS; break; default: break; } sin6_addr = addr.to_ipv6_address(); mask = 0; // must initialize to zero because we logical-or bits into this if (who == NULL || *who == '\0') { who = TotallyWild; } if ( perm >= LAST_PERM || !PermTypeArray[perm] ) { EXCEPT("IpVerify::Verify: called with unknown permission %d\n",perm); } // see if a authorization hole has been dyamically punched (via // PunchHole) for this perm / user / IP // Note that the permission hierarchy is dealt with in // PunchHole(), by punching a hole for all implied levels. // Therefore, if there is a hole or an implied hole, we will // always find it here before we get into the subsequent code // which recursively calls Verify() to traverse the hierarchy. // This is important, because we do not want holes to find // there way into the authorization cache. // if ( PunchedHoleArray[perm] != NULL ) { HolePunchTable_t* hpt = PunchedHoleArray[perm]; MyString ip_str_buf = addr.to_ip_string(); const char* ip_str = ip_str_buf.Value(); MyString id_with_ip; MyString id; int count; if ( who != TotallyWild ) { id_with_ip.sprintf("%s/%s", who, ip_str); id = who; if ( hpt->lookup(id, count) != -1 ) { if( allow_reason ) { allow_reason->sprintf( "%s authorization has been made automatic for %s", PermString(perm), id.Value() ); } return USER_AUTH_SUCCESS; } if ( hpt->lookup(id_with_ip, count) != -1 ) { if( allow_reason ) { allow_reason->sprintf( "%s authorization has been made automatic for %s", PermString(perm), id_with_ip.Value() ); } return USER_AUTH_SUCCESS; } } id = ip_str; if ( hpt->lookup(id, count) != -1 ) { if( allow_reason ) { allow_reason->sprintf( "%s authorization has been made automatic for %s", PermString(perm), id.Value() ); } return USER_AUTH_SUCCESS; } } if ( PermTypeArray[perm]->behavior == USERVERIFY_ALLOW ) { // allow if no HOSTALLOW_* or HOSTDENY_* restrictions // specified. if( allow_reason ) { allow_reason->sprintf( "%s authorization policy allows access by anyone", PermString(perm)); } return USER_AUTH_SUCCESS; } if ( PermTypeArray[perm]->behavior == USERVERIFY_DENY ) { // deny if( deny_reason ) { deny_reason->sprintf( "%s authorization policy denies all access", PermString(perm)); } return USER_AUTH_FAILURE; } if( LookupCachedVerifyResult(perm,sin6_addr,who,mask) ) { if( deny_reason && (mask&deny_mask(perm)) ) { deny_reason->sprintf( "cached result for %s; see first case for the full reason", PermString(perm)); } else if( allow_reason && (mask&allow_mask(perm)) ) { allow_reason->sprintf( "cached result for %s; see first case for the full reason", PermString(perm)); } } else { mask = 0; // if the deny bit is already set, skip further DENY analysis perm_mask_t const deny_resolved = deny_mask(perm); // if the allow or deny bit is already set, // skip further ALLOW analysis perm_mask_t const allow_resolved = allow_mask(perm)|deny_mask(perm); // check for matching subnets in ip/mask style char ipstr[INET6_ADDRSTRLEN] = { 0, }; addr.to_ip_string(ipstr, INET6_ADDRSTRLEN); peer_description = addr.to_ip_string(); if ( !(mask&deny_resolved) && lookup_user_ip_deny(perm,who,ipstr)) { mask |= deny_mask(perm); if( deny_reason ) { deny_reason->sprintf( "%s authorization policy denies IP address %s", PermString(perm), addr.to_ip_string().Value() ); } } if ( !(mask&allow_resolved) && lookup_user_ip_allow(perm,who,ipstr)) { mask |= allow_mask(perm); if( allow_reason ) { allow_reason->sprintf( "%s authorization policy allows IP address %s", PermString(perm), addr.to_ip_string().Value() ); } } std::vector<MyString> hostnames; // now scan through hostname strings if( !(mask&allow_resolved) || !(mask&deny_resolved) ) { hostnames = get_hostname_with_alias(addr); } for (unsigned int i = 0; i < hostnames.size(); ++i) { thehost = hostnames[i].Value(); peer_description.append_to_list(thehost); if ( !(mask&deny_resolved) && lookup_user_host_deny(perm,who,thehost) ) { mask |= deny_mask(perm); if( deny_reason ) { deny_reason->sprintf( "%s authorization policy denies hostname %s", PermString(perm), thehost ); } } if ( !(mask&allow_resolved) && lookup_user_host_allow(perm,who,thehost) ) { mask |= allow_mask(perm); if( allow_reason ) { allow_reason->sprintf( "%s authorization policy allows hostname %s", PermString(perm), thehost ); } } } // if we found something via our hostname or subnet mactching, we now have // a mask, and we should add it into our table so we need not // do a gethostbyaddr() next time. if we still do not have a mask // (perhaps because this host doesn't appear in any list), create one // and then add to the table. // But first, check our parent permission levels in the // authorization heirarchy. // DAEMON and ADMINISTRATOR imply WRITE. // WRITE, NEGOTIATOR, and CONFIG_PERM imply READ. bool determined_by_parent = false; if ( mask == 0 ) { if ( PermTypeArray[perm]->behavior == USERVERIFY_ONLY_DENIES ) { dprintf(D_SECURITY,"IPVERIFY: %s at %s not matched to deny list, so allowing.\n",who, addr.to_sinful().Value()); if( allow_reason ) { allow_reason->sprintf( "%s authorization policy does not deny, so allowing", PermString(perm)); } mask |= allow_mask(perm); } else { DCpermissionHierarchy hierarchy( perm ); DCpermission const *parent_perms = hierarchy.getPermsIAmDirectlyImpliedBy(); bool parent_allowed = false; for( ; *parent_perms != LAST_PERM; parent_perms++ ) { if( Verify( *parent_perms, addr, user, allow_reason, NULL ) == USER_AUTH_SUCCESS ) { determined_by_parent = true; parent_allowed = true; dprintf(D_SECURITY,"IPVERIFY: allowing %s at %s for %s because %s is allowed\n",who, addr.to_sinful().Value(),PermString(perm),PermString(*parent_perms)); if( allow_reason ) { MyString tmp = *allow_reason; allow_reason->sprintf( "%s is implied by %s; %s", PermString(perm), PermString(*parent_perms), tmp.Value()); } break; } } if( parent_allowed ) { mask |= allow_mask(perm); } else { mask |= deny_mask(perm); if( !determined_by_parent && deny_reason ) { // We don't just allow anyone, and this request // did not match any of the entries we do allow. // In case the reason we didn't match is // because of a typo or a DNS problem, record // all the hostnames we searched for. deny_reason->sprintf( "%s authorization policy contains no matching " "ALLOW entry for this request" "; identifiers used for this host: %s, hostname size = %lu, " "original ip address = %s", PermString(perm), peer_description.Value(), (unsigned long)hostnames.size(), ipstr); } } } } if( !determined_by_parent && (mask&allow_mask(perm)) ) { // In case we are allowing because of not matching a DENY // entry that the user expected us to match (e.g. because // of typo or DNS problem), record all the hostnames we // searched for. if( allow_reason && !peer_description.IsEmpty() ) { allow_reason->sprintf_cat( "; identifiers used for this remote host: %s", peer_description.Value()); } } // finally, add the mask we computed into the table with this IP addr add_hash_entry(sin6_addr, who, mask); } // end of if find_match is FALSE // decode the mask and return True or False to the user. if ( mask & deny_mask(perm) ) { return USER_AUTH_FAILURE; } if ( mask & allow_mask(perm) ) { return USER_AUTH_SUCCESS; } return USER_AUTH_FAILURE; }
char *test_assym(hid_t hdf, int mpirank) { // The process 0 does not write anything. // The process 1 writes one column // The process 2 writes two column AH5_Earrayset_t arrayset; AH5_initialize_Earrayset(&arrayset); hsize_t dims[] = { H5S_UNLIMITED, 3 }; AH5_RETURN_IF_FAILED(AH5_create_PEarrayset(hdf, "peArraySet", 2, dims, H5T_NATIVE_INT, &arrayset), "Creation PEarrayset failed.\n"); hsize_t block[] = {1, mpirank}; hsize_t start[] = {0, 0}; if(mpirank != 0) { start[1] = mpirank - 1; } hsize_t ones[] = {1, 1}; AH5_RETURN_IF_FAILED(AH5_set_mpi_mapping_PEarrayset(&arrayset, block, start, ones, ones, block), "Set mapping PEarrayset failed.\n"); AH5_RETURN_IF_FAILED(AH5_set_int_dim_Earrayset(&arrayset, 0, 1, dims, NULL, "coucou nature", NULL, NULL), "Set dim 0 PEarrayset failed.\n"); dims[0] = 3; int datadim[] = {1, 2, 2}; AH5_RETURN_IF_FAILED(AH5_set_int_dim_Earrayset(&arrayset, 1, 1, dims, datadim, "mpirank", NULL, NULL), "Set dim 1 PEarrayset failed.\n"); int maxdim = 20; int i; for(i=0; i<maxdim; i++) { int *data = NULL; if(mpirank!=0) { data = malloc(mpirank * sizeof(int)); int j; for(j=0; j<mpirank; j++) { data[j] = 3 * i + j + mpirank - 1; } } datadim[0] = i; AH5_RETURN_IF_FAILED(AH5_append_Earrayset(&arrayset, 1, data, datadim), "Extension PEarrayset failed.\n"); if(mpirank!=0) { free(data); } MPI_Barrier(MPI_COMM_WORLD); } AH5_RETURN_IF_FAILED(AH5_free_Earrayset(&arrayset), "Free PEarrayset failed.\n"); // Verif int *refdata = malloc(maxdim * 3 * sizeof(int)); dims[0] = maxdim; dims[1] = 3; int iu; int iv; for(iu=0; iu<maxdim; iu++) { for(iv=0; iv<3; iv++) { hsize_t rank[] = { iu, iv }; hsize_t id = Index(2, dims, rank); refdata[id] = 3 * iu + iv; } } AH5_RETURN_IF_FAILED(Verify(hdf, "peArraySet/data", maxdim * 3, refdata), "Verif PEdataset failed.\n"); free(refdata); return NULL; }
// //########################################################################### //########################################################################### // HSVColor& HSVColor::operator=(const RGBColor &color) { Check_Object(this); Check_Object(&color); Verify(color.red >= 0.0f && color.red <= 1.0f); Verify(color.green >= 0.0f && color.green <= 1.0f); Verify(color.blue >= 0.0f && color.blue <= 1.0f); // //-------------------- // Set the color value //-------------------- // value = Max(color.red, Max(color.green, color.blue)); // //------------------------- // Set the saturation value //------------------------- // Scalar delta = value - Min(color.red, Min(color.green, color.blue)); if (value > SMALL) { saturation = delta / value; Verify(saturation > 0.0f && saturation <= 1.0f); } else { saturation = 0.0f; } // //------------ // Set the hue //------------ // if (saturation <= SMALL) { hue = 0.0f; } else { Verify(delta > SMALL); if (color.red == value) { hue = (color.green - color.blue) / delta; } else if (color.green == value) { hue = 2.0f + (color.blue - color.red) / delta; } else { hue = 4.0f + (color.red - color.green) / delta; } if (hue < 0.0f) { hue += 6.0f; } hue *= 1.0f/6.0f; Verify(hue >= 0.0f && hue <= 1.0f); } return *this; }
void deleteGlobal() { Verify(g_globalImpl); g_globalImpl.reset(); }
int main (int argc, char **argv) { int row_receive, col_receive; int world_rank, world_size; int source, destination; double start_time, end_time; int i,j; int row_i, column_i, cycle; int rank2; MPI_Comm comm2; MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &world_rank); MPI_Comm_size (MPI_COMM_WORLD, &world_size); double root_p; /* sqrt of no of processors */ root_p = sqrt ((double) world_size); if (NRA % (int) root_p != 0) { printf ("Please enter a processor count which a perfect square and a multiple "); MPI_Abort (MPI_COMM_WORLD, 1); } int sub_matrix = NRA / root_p; /* Need to create a grid of root p x root p processors */ dims [0] = (int) root_p; dims [1] = (int) root_p; period [0] = 1; period [1] = 1; /* Now Matrix is made up of sub-matrices of size n/root p */ double sub_A [sub_matrix][sub_matrix]; double sub_B [sub_matrix][sub_matrix]; double sub_C [sub_matrix][sub_matrix]; double sub_CT [sub_matrix][sub_matrix]; /* Now creating a cartesian topology */ MPI_Cart_create (MPI_COMM_WORLD, 2, dims, period, 0, &comm2); /* NOw getting a new rank */ MPI_Comm_rank (comm2, &world_rank); /*Determine process co ordinate based on rank */ MPI_Cart_coords (comm2, world_rank, 2, coordinates); Init_zero_Mat (sub_matrix, sub_C); if (world_rank == 0) { Matrix_init (NRA, NRA, A); Matrix_init (NRA, NRA, B); //print_Mat (NRA, A); //print_Mat (NRA, B); Init_zero_Mat (sub_matrix, sub_C); /* Let us send each portion of A and B and start multiplying */ start_time = MPI_Wtime (); for (i = 0; i < root_p; i++) { for (j = 0; j < root_p; j++) { if ( i != 0 || j != 0) { send_coordinates [0] = i; send_coordinates [1] = j; row_i = -1; int k; for (k = i * sub_matrix; k < i * sub_matrix + sub_matrix; k++) { column_i = 0; row_i ++; int l; for (l = j *sub_matrix; l < j * sub_matrix + sub_matrix; l++) { sub_A[row_i][column_i] = A[k][l]; sub_B[row_i][column_i] = B[k][l]; column_i++; } } /* Make the co ordinate reference to column and send it to processor pij */ send_coordinates [0] = i; send_coordinates [1] = ((j - i) < 0) ? (j-i) + root_p : (j-i); MPI_Cart_rank (comm2, send_coordinates, &rank2); MPI_Send (sub_A, sub_matrix * sub_matrix, MPI_DOUBLE, rank2, 1, comm2); send_coordinates [0] = ((i-j) < 0) ? (i-j) + root_p : i-j; send_coordinates [1] = j; MPI_Cart_rank (comm2, send_coordinates, &rank2); MPI_Send (sub_B, sub_matrix * sub_matrix, MPI_DOUBLE, rank2, 2, comm2); } } } /* NOws send to process 0 */ for (i =0 ; i<sub_matrix; i++) { for ( j = 0; j < sub_matrix; j++) { sub_A[i][j] = A[i][j]; sub_B[i][j] = B[i][j]; } } /* calculate c for matrix in process 0 */ /* Todo: use in function */ for (cycle = 0; cycle < sub_matrix; cycle++) { Matrix_mul (sub_matrix, sub_A, sub_B, sub_C); MPI_Cart_shift (comm2, 1, -1, &source, &destination); MPI_Sendrecv_replace (sub_A, sub_matrix * sub_matrix, MPI_DOUBLE,destination, 1, source, 1, comm2, &status1); MPI_Cart_shift (comm2, 0, -1, &source, &destination); MPI_Sendrecv_replace (sub_B, sub_matrix * sub_matrix, MPI_DOUBLE,destination, 2, source, 2, comm2, &status2); } } /*end of master */ else { MPI_Recv (sub_A, sub_matrix * sub_matrix, MPI_DOUBLE, 0, 1, comm2, &status1); MPI_Recv (sub_B, sub_matrix * sub_matrix, MPI_DOUBLE, 0, 2, comm2, &status2); for (cycle = 0; cycle < sub_matrix; cycle ++) { Matrix_mul (sub_matrix, sub_A, sub_B, sub_C); MPI_Cart_shift (comm2, 1, -1, &source, &destination); MPI_Sendrecv_replace (sub_A, sub_matrix * sub_matrix, MPI_DOUBLE,destination, 1, source, 1, comm2, &status1); MPI_Cart_shift (comm2, 0, -1, &source, &destination); MPI_Sendrecv_replace (sub_B, sub_matrix * sub_matrix, MPI_DOUBLE,destination, 2, source, 2, comm2, &status2); } /* send final result to process 0 */ MPI_Send (sub_C, sub_matrix * sub_matrix, MPI_DOUBLE, 0 , world_rank, comm2); } if (world_rank == 0) { Init_zero_Mat (NRA , C); int k; for (i =1; i < world_size; i++) { MPI_Recv (sub_CT, sub_matrix * sub_matrix, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG,comm2, &status3); MPI_Cart_coords (comm2, status3.MPI_TAG, 2, send_coordinates); row_receive = send_coordinates [0]; col_receive = send_coordinates [1]; row_i = -1; column_i = 0; for ( j = row_receive * sub_matrix; j < row_receive * sub_matrix + sub_matrix; j++) { row_i ++; for ( k = col_receive * sub_matrix; k < col_receive * sub_matrix + sub_matrix; k++) { C[j][k] = sub_CT[row_i][column_i]; column_i ++; } column_i = 0; } } /* On process 0 */ for (i = 0; i < sub_matrix; i++) { for (j =0 ; j <sub_matrix; j++) { C[i][j] = sub_C[i][j]; } } end_time = MPI_Wtime (); double serial = Verify (NRA, A,B,C); printf ("speedup :%f s",serial/( end_time - start_time)); } MPI_Finalize (); return 0; }
IGlobal &getGlobal() { Verify(g_globalImpl); return *g_globalImpl; }
//------------------------------------------------------------------------------ // void gosFX::Shape::TestInstance() const { Verify(IsDerivedFrom(DefaultData)); }
void nativeCrashHandler_onLoad(JavaVM *jvm) { javaVM = jvm; JNIEnv *env = 0; int result = jvm->GetEnv((void **) &env, JNI_VERSION_1_6); Verify(result == JNI_OK, "Could not get JNI environment"); applicationClass = env->FindClass("com/github/nativehandler/NativeCrashHandler"); Verify(applicationClass, "Could not find NativeCrashHandler java class"); applicationClass = (jclass)env->NewGlobalRef(applicationClass); Verify(applicationClass, "Could not create NativeCrashHandler java class global reference"); makeCrashReportMethod = env->GetMethodID(applicationClass, "makeCrashReport", "(Ljava/lang/String;[Ljava/lang/StackTraceElement;I)V"); Verify(makeCrashReportMethod, "Could not find makeCrashReport java method"); stackTraceElementClass = env->FindClass("java/lang/StackTraceElement"); Verify(stackTraceElementClass, "Could not find StackTraceElement java class"); stackTraceElementClass = (jclass)env->NewGlobalRef(stackTraceElementClass); Verify(stackTraceElementClass, "Could not create StackTraceElement java class global reference"); stackTraceElementMethod = env->GetMethodID(stackTraceElementClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V"); Verify(stackTraceElementMethod, "Could not find StackTraceElement constructor java method"); Verify(env->ExceptionCheck() == JNI_FALSE, "Java threw an exception"); // void * libcorkscrew = dlopen("libcorkscrew.so", RTLD_LAZY | RTLD_LOCAL); // if (libcorkscrew) { // unwind_backtrace_signal_arch = (t_unwind_backtrace_signal_arch) dlsym(libcorkscrew, "unwind_backtrace_signal_arch"); // acquire_my_map_info_list = (t_acquire_my_map_info_list) dlsym(libcorkscrew, "acquire_my_map_info_list"); // release_my_map_info_list = (t_release_my_map_info_list) dlsym(libcorkscrew, "release_my_map_info_list"); // get_backtrace_symbols = (t_get_backtrace_symbols) dlsym(libcorkscrew, "get_backtrace_symbols"); // free_backtrace_symbols = (t_free_backtrace_symbols) dlsym(libcorkscrew, "free_backtrace_symbols"); // } struct sigaction handler; memset(&handler, 0, sizeof(handler)); sigemptyset(&handler.sa_mask); handler.sa_sigaction = nativeCrashHandler_sigaction; handler.sa_flags = SA_SIGINFO | SA_ONSTACK; stack_t stack; memset(&stack, 0, sizeof(stack)); stack.ss_size = 1024 * 128; stack.ss_sp = malloc(stack.ss_size); Verify(stack.ss_sp, "Could not allocate signal alternative stack"); stack.ss_flags = 0; result = sigaltstack(&stack, NULL); Verify(!result, "Could not set signal stack"); result = sigaction(SIGILL, &handler, &old_sa[SIGILL] ); Verify(!result, "Could not register signal callback for SIGILL"); result = sigaction(SIGABRT, &handler, &old_sa[SIGABRT] ); Verify(!result, "Could not register signal callback for SIGABRT"); result = sigaction(SIGBUS, &handler, &old_sa[SIGBUS] ); Verify(!result, "Could not register signal callback for SIGBUS"); result = sigaction(SIGFPE, &handler, &old_sa[SIGFPE] ); Verify(!result, "Could not register signal callback for SIGFPE"); result = sigaction(SIGSEGV, &handler, &old_sa[SIGSEGV] ); Verify(!result, "Could not register signal callback for SIGSEGV"); result = sigaction(SIGSTKFLT, &handler, &old_sa[SIGSTKFLT] ); Verify(!result, "Could not register signal callback for SIGSTKFLT"); result = sigaction(SIGPIPE, &handler, &old_sa[SIGPIPE] ); Verify(!result, "Could not register signal callback for SIGPIPE"); }
// ignores milli seconds void CTimeStamp::ToGMTTime(tm* tm_struct) const { // tm* _Time = gmtime(& m_TimeB.time); // memcpy(tm_struct, _Time, sizeof tm); Verify(gmtime_s(tm_struct, & m_TimeB.time) == 0); }
void _makeNativeCrashReport(const char *reason, struct siginfo *siginfo, void *sigcontext) { JNIEnv *env = 0; int result = javaVM->GetEnv((void **) &env, JNI_VERSION_1_6); if (result == JNI_EDETACHED) { __android_log_print(ANDROID_LOG_WARN, "NativeCrashHandler", "Native crash occured in a non jvm-attached thread"); result = javaVM->AttachCurrentThread(&env, NULL); } if (result != JNI_OK) __android_log_print(ANDROID_LOG_ERROR, "NativeCrashHandler", "Could not attach thread to Java VM for crash reporting.\n" "Crash was: %s", reason ); else if (env && applicationObject) { jobjectArray elements = NULL; if (unwind_backtrace_signal_arch != NULL && siginfo != NULL) { map_info_t *map_info = acquire_my_map_info_list(); backtrace_frame_t frames[256] = {0,}; backtrace_symbol_t symbols[256] = {0,}; const ssize_t size = unwind_backtrace_signal_arch(siginfo, sigcontext, map_info, frames, 1, 255); get_backtrace_symbols(frames, size, symbols); elements = env->NewObjectArray(size, stackTraceElementClass, NULL); Verify(elements, "Could not create StackElement java array"); int pos = 0; jstring jni = env->NewStringUTF("<JNI>"); for (int i = 0; i < size; ++i) { const char *method = symbols[i].demangled_name; if (!method) method = symbols[i].symbol_name; if (!method) method = "?"; //__android_log_print(ANDROID_LOG_ERROR, "DUMP", "%s", method); const char *file = symbols[i].map_name; if (!file) file = "-"; jobject element = env->NewObject(stackTraceElementClass, stackTraceElementMethod, jni, env->NewStringUTF(method), env->NewStringUTF(file), -2 ); Verify(element, "Could not create StackElement java object"); env->SetObjectArrayElement(elements, pos++, element); Verify(env->ExceptionCheck() == JNI_FALSE, "Java threw an exception"); } free_backtrace_symbols(symbols, size); release_my_map_info_list(map_info); } env->CallVoidMethod(applicationObject, makeCrashReportMethod, env->NewStringUTF(reason), elements, (jint)gettid()); Verify(env->ExceptionCheck() == JNI_FALSE, "Java threw an exception"); } else __android_log_print(ANDROID_LOG_ERROR, "NativeCrashHandler", "Could not create native crash report as registerForNativeCrash was not called in JAVA context.\n" "Crash was: %s", reason ); }
void CBookmarksDialog::OnNewBookmark(wxCommandEvent&) { if (!Verify()) return; UpdateBookmark(); wxTreeItemId item = m_pTree->GetSelection(); if (!item) item = m_bookmarks_global; if (m_pTree->GetItemData(item)) item = m_pTree->GetItemParent(item); if (item == m_bookmarks_site) { std::list<wxString> bookmarks; if (m_site_path.empty() || !CSiteManager::GetBookmarks(m_site_path, bookmarks)) { if (wxMessageBoxEx(_("Site-specific bookmarks require the server to be stored in the Site Manager.\nAdd current connection to the site manager?"), _("New bookmark"), wxYES_NO | wxICON_QUESTION, this) != wxYES) return; m_site_path = CSiteManager::AddServer(*m_server); if (m_site_path.empty()) { wxMessageBoxEx(_("Could not add connection to Site Manager"), _("New bookmark"), wxICON_EXCLAMATION, this); return; } } } wxString newName = _("New bookmark"); int index = 2; for (;;) { wxTreeItemId child; wxTreeItemIdValue cookie; child = m_pTree->GetFirstChild(item, cookie); bool found = false; while (child.IsOk()) { wxString name = m_pTree->GetItemText(child); int cmp = name.CmpNoCase(newName); if (!cmp) { found = true; break; } child = m_pTree->GetNextChild(item, cookie); } if (!found) break; newName = _("New bookmark") + wxString::Format(_T(" %d"), index++); } wxTreeItemId child = m_pTree->AppendItem(item, newName, 1, 1, new CBookmarkItemData); m_pTree->SortChildren(item); m_pTree->SelectItem(child); m_pTree->EditLabel(child); }
bool KeyPair::VerifyData(const Signature& in, const void* data, size_t len) { Digest hash; blake2b(hash, sizeof(hash), 0, 0, data, len); return Verify(in, hash); }
bool sphPluginCreate ( const char * szLib, PluginType_e eType, const char * sName, ESphAttr eUDFRetType, CSphString & sError ) { #if !HAVE_DLOPEN sError = "no dlopen(), no plugins"; return false; #else if ( !g_bPluginsEnabled ) { sError = "plugin support disabled (requires a valid plugin_dir)"; return false; } // validate library name for ( const char * p = szLib; *p; p++ ) if ( *p=='/' || *p=='\\' ) { sError = "restricted character (path delimiter) in a library file name"; return false; } CSphString sLib = szLib; sLib.ToLower(); // FIXME? preregister known rankers instead? if ( eType==PLUGIN_RANKER ) { for ( int i=0; i<SPH_RANK_TOTAL; i++ ) { const char * r = sphGetRankerName ( ESphRankMode(i) ); if ( r && strcasecmp ( sName, r )==0 ) { sError.SetSprintf ( "%s is a reserved ranker name", r ); return false; } } } // from here, we need a lock (we intend to update the plugin hash) CSphScopedLock<CSphMutex> tLock ( g_tPluginMutex ); // validate function name PluginKey_t k ( eType, sName ); if ( g_hPlugins(k) ) { sError.SetSprintf ( "plugin '%s' already exists", k.m_sName.cstr() ); return false; } // lookup or load library PluginLib_c * pLib = NULL; if ( g_hPluginLibs ( sLib ) ) { pLib = g_hPluginLibs [ sLib ]; pLib->AddRef(); } else { pLib = LoadPluginLibrary ( sLib.cstr(), sError ); if ( !pLib ) return false; } assert ( pLib->GetHandle() ); PluginDesc_c * pPlugin = NULL; const SymbolDesc_t * pSym = NULL; switch ( eType ) { case PLUGIN_RANKER: pPlugin = new PluginRanker_c ( pLib ); pSym = g_dSymbolsRanker; break; case PLUGIN_INDEX_TOKEN_FILTER: pPlugin = new PluginTokenFilter_c ( pLib ); pSym = g_dSymbolsTokenFilter; break; case PLUGIN_QUERY_TOKEN_FILTER: pPlugin = new PluginQueryTokenFilter_c ( pLib ); pSym = g_dSymbolsQueryTokenFilter; break; case PLUGIN_FUNCTION: pPlugin = new PluginUDF_c ( pLib, eUDFRetType ); pSym = g_dSymbolsUDF; break; default: sError.SetSprintf ( "INTERNAL ERROR: unknown plugin type %d in CreatePlugin()", (int)eType ); pLib->Release(); return false; } // release the refcount that this very function is holding // or in other words, transfer the refcount to newly created plugin instance (it does its own addref) pLib->Release(); if ( !PluginLoadSymbols ( pPlugin, pSym, pLib->GetHandle(), k.m_sName.cstr(), sError ) ) { sError.SetSprintf ( "%s in %s", sError.cstr(), sLib.cstr() ); pPlugin->Release(); return false; } // add library if needed if ( !g_hPluginLibs ( sLib ) ) { Verify ( g_hPluginLibs.Add ( pLib, pLib->GetName() ) ); pLib->AddRef(); // the hash reference } // add function Verify ( g_hPlugins.Add ( pPlugin, k ) ); pPlugin->GetLib()->m_iHashedPlugins++; return true; #endif // HAVE_DLOPEN }
greet_user_rtn GreetUser(struct display * d, Display ** dpy, struct verify_info * verify, struct greet_info * greet) { int flag; int pid; int code; Save_d = d; /* hopefully, this is OK */ *dpy = XOpenDisplay(d->name); /* make sure we have the display */ /* * Run the setup script - note this usually will not work when * the server is grabbed, so we don't even bother trying. */ if (!d->grabServer) SetupDisplay(d); if (!*dpy) { WDMError("Cannot reopen display %s for greet window\n", d->name); exit(RESERVER_DISPLAY); } pid = InitGreet(d); /* fork and exec the external program */ for (;;) { /* * Greet user, requesting name/password */ code = Greet(d, greet); WDMDebug("Greet greet done: %s, pwlen=%i\n", name, strlen(password)); if (code != 0) { WDMDebug("Greet: exit code=%i, %s\n", code, exitArg); if (wdmVerify || wdmRoot) { flag = False; if (Verify(d, greet, verify)) flag = True; if (wdmRoot && (strcmp(greet->name, "root") != 0)) flag = False; } else flag = True; if (flag == True) { switch (code) { case 2: /* reboot */ CloseGreet(pid); WDMInfo("reboot(%s) by %s\n", exitArg, name); system(wdmReboot); SessionExit(d, UNMANAGE_DISPLAY, FALSE); break; case 3: /* halt */ CloseGreet(pid); WDMInfo("halt(%s) by %s\n", exitArg, name); system(wdmHalt); SessionExit(d, UNMANAGE_DISPLAY, FALSE); break; case 4: /* exit */ CloseGreet(pid); WDMDebug("UNMANAGE_DISPLAY\n"); WDMInfo("%s exit(%s) by %s\n", PACKAGE_NAME, exitArg, name); #if 0 SessionExit(d, UNMANAGE_DISPLAY, FALSE); #else WDMDebug("Killing parent process %d\n", getppid()); kill(getppid(), SIGINT); #endif break; } } else { kill(pid, SIGUSR1); /* Verify failed */ } } else { /* * Verify user */ if ((!*greet->name) && *wdmDefaultUser) { greet->name = wdmDefaultUser; greet->password = wdmDefaultPasswd; } if (Verify(d, greet, verify)) break; else kill(pid, SIGUSR1); /* Verify failed */ } } DeleteXloginResources(d, *dpy); CloseGreet(pid); WDMDebug("Greet loop finished\n"); /* * Run system-wide initialization file */ if (source(verify->systemEnviron, d->startup) != 0) { WDMDebug("Startup program %s exited with non-zero status\n", d->startup); SessionExit(d, OBEYSESS_DISPLAY, FALSE); } return Greet_Success; }
void CVerifier::Verify(CP p) { CTypeSpec ts = Type(p); if (ts < TS_SYMBOL && (ts!=TS_CONS || p)) return; CObMap::CVal& val = m_obMap.m_arP[g_arTS[ts]][AsIndex(p)]; if (val.Flag) return; val.Flag = true; switch (ts) { case TS_FRAME_PTR: Throw(E_FAIL); case TS_CONS: case TS_RATIO: case TS_COMPLEX: #if UCFG_LISP_BUILTIN_RANDOM_STATE case TS_RANDOMSTATE: #endif { CConsValue *cons = Lisp().AsCons(p); Verify(cons->m_car); Verify(cons->m_cdr); } break; case TS_SYMBOL: { CSymbolValue *sv = ToSymbol(p); Verify(sv->GetFun()); Verify(sv->GetPropList()); Verify(sv->m_dynValue); } break; case TS_INTFUNC: { CIntFuncValue *ifv = Lisp().ToIntFunc(p); Verify(ifv->m_name); Verify(ifv->m_docstring); Verify(ifv->m_body); Verify(ifv->m_vars); Verify(ifv->m_optInits); Verify(ifv->m_keywords); Verify(ifv->m_keyInits); Verify(ifv->m_auxInits); Verify(ifv->m_env.m_varEnv); Verify(ifv->m_env.m_funEnv); Verify(ifv->m_env.m_blockEnv); Verify(ifv->m_env.m_goEnv); Verify(ifv->m_env.m_declEnv); } break; case TS_HASHTABLE: { CHashMap& m = *Lisp().ToHashTable(p)->m_pMap; Verify(m.m_func); for (CHashMap::iterator i=m.begin(); i!=m.end(); ++i) { Verify(i->first); Verify(i->second); } } break; case TS_STRUCT: case TS_OBJECT: case TS_ARRAY: case TS_CCLOSURE: { CArrayValue *av = Lisp().ToArray(p); Verify(av->m_displace); Verify(av->m_fillPointer); Verify(av->m_dims); if (!av->m_displace && av->m_elType == ELTYPE_T) { uintptr_t size = 1; for (CP p1=av->m_dims; p1;) { CConsValue *cons = Lisp().AsCons(p1); size *= AsNumber(cons->m_car); p1 = cons->m_cdr; } for (size_t i=0; i<size; ++i) Verify(av->m_pData[i]); } } break; case TS_PACKAGE: { CPackage *pack = ToPackage(p); Verify(pack->m_useList); //!!! Verify(pack->m_docString); } break; } }
inline float Arcsin(float x) { Verify(x >= -1.0f && x <= 1.0f); return static_cast<float>(asin(x)); }