/*static*/ int GCAlloc::ConservativeGetMark(const void *item, bool bogusPointerReturnValue) { GCBlock *block = GetBlock(item); #ifdef MMGC_MEMORY_INFO item = GetRealPointer(item); #endif // guard against bogus pointers to the block header if (item < block->items) return bogusPointerReturnValue; // floor value to start of item // FIXME: do this w/o division if we can int itemNum = GetIndex(block, item); // skip pointers into dead space at end of block if (itemNum > block->alloc->m_itemsPerBlock - 1) return bogusPointerReturnValue; // skip pointers into objects if(block->items + itemNum * block->size != item) return bogusPointerReturnValue; return GetMark(item); }
/* static */ bool GCLargeAlloc::ConservativeGetMark(const void *item, bool bogusPointerReturnValue) { if(((uintptr) item & 0xfff) == sizeof(LargeBlock)) { return GetMark(item); } return bogusPointerReturnValue; }
bool SQLTranslator::Translate(std::string& sql, std::string* pError) { size_t pos = 0; size_t mark_size = 0; std::string mark; std::string mark_val; while ( GetMark(sql, mark, pos) ) { // 整个 $(...) 的大小 mark_size = mark.size() + 3; if ( mark.find('+') != std::string::npos ) // 含 + 运算 { if ( !CalcMark(mark, true, mark_val, pError) ) { return false; } } else if ( mark.find('-') != std::string::npos ) // 含 - 运算 { if ( !CalcMark(mark, false, mark_val, pError) ) { return false; } } else // 不含 + 或者 - 运算 { if ( !TransMark(mark, mark_val, pError) ) { return false; } } sql.replace(pos, mark_size, mark_val); } return true; }