void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState) { if (isImmutable()) { exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); return; } if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ")."); return; } SVGLengthContext lengthContext(contextElement()); target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext, exceptionState); commitChange(); }
void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState) { if (isImmutable()) { exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); return; } if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length."); return; } SVGLengthContext lengthContext(contextElement()); target()->setValue(value, lengthContext); commitChange(); }
void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState) { if (isImmutable()) { throwReadOnly(exceptionState); return; } if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length."); return; } SVGLengthContext lengthContext(contextElement()); if (target()->isCalculated()) target()->setValueAsNumber(value); else target()->setValue(value, lengthContext); commitChange(); }
void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionState& exceptionState) { if (isImmutable()) { throwReadOnly(exceptionState); return; } if (!isValidLengthUnit(unitType)) { exceptionState.throwDOMException( NotSupportedError, "Cannot set value with unknown or invalid units (" + String::number(unitType) + ")."); return; } target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUnits); commitChange(); }
void SVGAngleTearOff::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionState& exceptionState) { if (isImmutable()) { throwReadOnly(exceptionState); return; } if (unitType == SVGAngle::kSvgAngletypeUnknown || unitType > SVGAngle::kSvgAngletypeGrad) { exceptionState.throwDOMException( NotSupportedError, "Cannot set value with unknown or invalid units (" + String::number(unitType) + ")."); return; } target()->newValueSpecifiedUnits( static_cast<SVGAngle::SVGAngleType>(unitType), valueInSpecifiedUnits); commitChange(); }
void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& exceptionState) { if (isImmutable()) { throwReadOnly(exceptionState); return; } String oldValue = target()->valueAsString(); SVGParsingError status = target()->setValueAsString(str); if (status == SVGParseStatus::NoError && !hasExposedLengthUnit()) { target()->setValueAsString(oldValue); // rollback to old value status = SVGParseStatus::ParsingFailed; } if (status != SVGParseStatus::NoError) { exceptionState.throwDOMException( SyntaxError, "The value provided ('" + str + "') is invalid."); return; } commitChange(); }
void StringData::removeChar(int offset) { ASSERT(offset >= 0 && offset < size()); int len = size(); if (isImmutable()) { char *data = (char*)malloc(len); if (offset) { memcpy(data, this->data(), offset); } if (offset < len - 1) { memcpy(data + offset, this->data() + offset + 1, len - offset - 1); } data[len] = 0; m_len = len; releaseData(); m_data = data; } else { m_len = ((m_len & IsMask) | (len - 1)); memmove((void*)(m_data + offset), m_data + offset + 1, len - offset); } }
StringData* StringData::shrinkImpl(size_t len) { assert(!isImmutable() && !hasMultipleRefs()); assert(isFlat()); assert(len <= m_len); assert(len <= capacity()); auto const sd = Make(len); auto const src = slice(); auto const dst = sd->mutableData(); assert(len <= src.len); sd->setSize(len); auto const mcret = memcpy(dst, src.ptr, len); auto const ret = static_cast<StringData*>(mcret) - 1; // Recalculating ret from mcret avoids a spill. assert(ret == sd); assert(ret->checkSane()); return ret; }
StringData* StringData::reserve(size_t cap) { assert(!isImmutable() && !hasMultipleRefs()); assert(isFlat()); if (cap <= capacity()) return this; cap = std::min(cap + cap/4, size_t(MaxSize) + 1); auto const sd = Make(cap); auto const src = slice(); auto const dst = sd->mutableData(); sd->setSize(src.len); auto const mcret = memcpy(dst, src.ptr, src.len); auto const ret = static_cast<StringData*>(mcret) - 1; // Recalculating ret from mcret avoids a spill. assert(ret == sd); assert(ret->checkSane()); return ret; }
void SVGAngleTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState) { if (isImmutable()) { exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); return; } if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN || unitType > SVGAngle::SVG_ANGLETYPE_GRAD) { exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ")."); return; } if (target()->unitType() == SVGAngle::SVG_ANGLETYPE_UNKNOWN) { exceptionState.throwDOMException(NotSupportedError, "Cannot convert from unknown or invalid units."); return; } target()->convertToSpecifiedUnits(static_cast<SVGAngle::SVGAngleType>(unitType)); commitChange(); }
void SVGAngleTearOff::setValueAsString(const String& value, ExceptionState& exceptionState) { if (isImmutable()) { exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); return; } String oldValue = target()->valueAsString(); SVGParsingError status = target()->setValueAsString(value); if (status == SVGParseStatus::NoError && !hasExposedAngleUnit()) { target()->setValueAsString(oldValue); // rollback to old value status = SVGParseStatus::ParsingFailed; } if (status != SVGParseStatus::NoError) { exceptionState.throwDOMException(SyntaxError, "The value provided ('" + value + "') is invalid."); return; } commitChange(); }
void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState) { if (isImmutable()) { exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); return; } if (!isValidLengthUnit(unitType)) { exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ")."); return; } if ((target()->isRelative() || SVGLength::isRelativeUnit(toCSSUnitType(unitType))) && !canResolveRelativeUnits(contextElement())) { exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length."); return; } SVGLengthContext lengthContext(contextElement()); target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext); commitChange(); }
void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& exceptionState) { if (isImmutable()) { exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); return; } String oldValue = target()->valueAsString(); SVGParsingError status = target()->setValueAsString(str); if (status == NoError && !hasExposedLengthUnit()) { target()->setValueAsString(oldValue); // rollback to old value status = ParsingAttributeFailedError; } if (status != NoError) { exceptionState.throwDOMException(SyntaxError, "The value provided ('" + str + "') is invalid."); return; } commitChange(); }
void SVGAngleTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState) { if (isImmutable()) { throwReadOnly(exceptionState); return; } if (unitType == SVGAngle::kSvgAngletypeUnknown || unitType > SVGAngle::kSvgAngletypeGrad) { exceptionState.throwDOMException( NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ")."); return; } if (target()->unitType() == SVGAngle::kSvgAngletypeUnknown) { exceptionState.throwDOMException( NotSupportedError, "Cannot convert from unknown or invalid units."); return; } target()->convertToSpecifiedUnits( static_cast<SVGAngle::SVGAngleType>(unitType)); commitChange(); }
void generateRandMove(dungeon_t* dungeonPtr, monster* monsterPtr, int* dstX, int* dstY) { direction_t movementDir; int tunneling = monsterPtr->abilities & MONSTER_TUNNELING; int targetX, targetY; do { movementDir = utilRandDir(); targetX = monsterPtr->x; targetY = monsterPtr->y; if (movementDir & north) { targetY--; } else if (movementDir & south) { targetY++; } if (movementDir & west) { targetX--; } else if (movementDir & east) { targetX++; } } while (tunneling ? isImmutable(dungeonPtr->grid, targetX, targetY) : isRock(dungeonPtr->grid, targetX, targetY)); *dstX = targetX; *dstY = targetY; }
StringData* StringData::reserve(size_t cap) { assert(!isImmutable() && !hasMultipleRefs()); assert(isFlat()); if (cap <= capacity()) return this; cap = std::min(cap + cap / 4, size_t(MaxSize)); auto const sd = allocFlatForLenSmall(cap); // Request-allocated StringData are always aligned at 16 bytes, thus it is // safe to copy in 16-byte groups. This copies m_lenAndHash (8 bytes), the // characters (m_len bytes), add the trailing zero (1 byte). memcpy16_inline(&sd->m_lenAndHash, &m_lenAndHash, (m_len + 8 + 1 + 15) & ~0xF); assertx(reinterpret_cast<uintptr_t>(&m_lenAndHash) + 8 == reinterpret_cast<uintptr_t>(m_data)); assertx(reinterpret_cast<uintptr_t>(&m_lenAndHash) % 16 == 0); assert(sd->hasExactlyOneRef()); assert(sd->isFlat()); assert(sd->checkSane()); return sd; }
// mutations void StringData::setChar(int offset, CStrRef substring) { assert(!isStatic()); if (offset >= 0) { StringSlice s = slice(); if (s.len == 0) { // PHP will treat data as an array and we don't want to follow that. throw OffsetOutOfRangeException(); } char c = substring.empty() ? 0 : substring.data()[0]; if (uint32_t(offset) < s.len) { ((char*)s.ptr)[offset] = c; } else if (offset <= RuntimeOption::StringOffsetLimit) { uint32_t newlen = offset + 1; MutableSlice buf = isImmutable() ? escalate(newlen) : reserve(newlen); memset(buf.ptr + s.len, ' ', newlen - s.len); buf.ptr[offset] = c; setSize(newlen); } else { throw OffsetOutOfRangeException(); } m_hash = 0; // since we modified the string. } }
void Declaration::checkModify(Loc loc, Scope *sc, Type *t) { if (sc->incontract && isParameter()) error(loc, "cannot modify parameter '%s' in contract", toChars()); if (sc->incontract && isResult()) error(loc, "cannot modify result '%s' in contract", toChars()); if (isCtorinit() && !t->isMutable()) { // It's only modifiable if inside the right constructor Dsymbol *s = sc->func; while (1) { FuncDeclaration *fd = NULL; if (s) fd = s->isFuncDeclaration(); if (fd && ((fd->isCtorDeclaration() && storage_class & STCfield) || (fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) && fd->toParent() == toParent() ) { VarDeclaration *v = isVarDeclaration(); assert(v); v->ctorinit = 1; //printf("setting ctorinit\n"); } else { if (s) { s = s->toParent2(); continue; } else { const char *p = isStatic() ? "static " : ""; error(loc, "can only initialize %sconst %s inside %sconstructor", p, toChars(), p); } } break; } } else { VarDeclaration *v = isVarDeclaration(); if (v && v->canassign == 0) { const char *p = NULL; if (isConst()) p = "const"; else if (isImmutable()) p = "immutable"; else if (storage_class & STCmanifest) p = "enum"; else if (!t->isAssignable()) p = "struct with immutable members"; if (p) { error(loc, "cannot modify %s", p); } } } }
void StringData::inc() { assert(!isStatic()); assert(!empty()); if (isImmutable()) { escalate(m_len + 1); } else { reserve(m_len + 1); } m_hash = 0; enum class CharKind { UNKNOWN, LOWER_CASE, UPPER_CASE, NUMERIC }; auto const len = m_len; auto const s = m_data; int carry = 0; int pos = len - 1; auto last = CharKind::UNKNOWN; // Shut up the compiler warning int ch; while (pos >= 0) { ch = s[pos]; if (ch >= 'a' && ch <= 'z') { if (ch == 'z') { s[pos] = 'a'; carry=1; } else { s[pos]++; carry=0; } last = CharKind::LOWER_CASE; } else if (ch >= 'A' && ch <= 'Z') { if (ch == 'Z') { s[pos] = 'A'; carry=1; } else { s[pos]++; carry=0; } last = CharKind::UPPER_CASE; } else if (ch >= '0' && ch <= '9') { if (ch == '9') { s[pos] = '0'; carry=1; } else { s[pos]++; carry=0; } last = CharKind::NUMERIC; } else { carry=0; break; } if (carry == 0) { break; } pos--; } if (carry) { if (UNLIKELY(len + 1 > MaxSize)) { throw InvalidArgumentException("len > 2^31-2", len); } assert(len + 2 <= capacity()); memmove(s + 1, s, len); s[len + 1] = '\0'; m_len = len + 1; switch (last) { case CharKind::NUMERIC: s[0] = '1'; break; case CharKind::UPPER_CASE: s[0] = 'A'; break; case CharKind::LOWER_CASE: s[0] = 'a'; break; default: break; } } }
bool KConfig::sync() { Q_D(KConfig); if (isImmutable() || name().isEmpty()) { // can't write to an immutable or anonymous file. return false; } if (d->bDirty && d->mBackend) { const QByteArray utf8Locale(locale().toUtf8()); // Create the containing dir, maybe it wasn't there d->mBackend->createEnclosing(); // lock the local file if (d->configState == ReadWrite && !d->lockLocal()) { qWarning() << "couldn't lock local file"; return false; } // Rewrite global/local config only if there is a dirty entry in it. bool writeGlobals = false; bool writeLocals = false; Q_FOREACH (const KEntry &e, d->entryMap) { if (e.bDirty) { if (e.bGlobal) { writeGlobals = true; } else { writeLocals = true; } if (writeGlobals && writeLocals) { break; } } } d->bDirty = false; // will revert to true if a config write fails if (d->wantGlobals() && writeGlobals) { QExplicitlySharedDataPointer<KConfigBackend> tmp = KConfigBackend::create(*sGlobalFileName); if (d->configState == ReadWrite && !tmp->lock()) { qWarning() << "couldn't lock global file"; //unlock the local config if we're returning early if (d->mBackend->isLocked()) { d->mBackend->unlock(); } d->bDirty = true; return false; } if (!tmp->writeConfig(utf8Locale, d->entryMap, KConfigBackend::WriteGlobal)) { d->bDirty = true; } if (tmp->isLocked()) { tmp->unlock(); } } if (writeLocals) { if (!d->mBackend->writeConfig(utf8Locale, d->entryMap, KConfigBackend::WriteOptions())) { d->bDirty = true; } } if (d->mBackend->isLocked()) { d->mBackend->unlock(); } } return !d->bDirty; }
void StringData::setChar(int offset, char ch) { ASSERT(offset >= 0 && offset < size() && !isStatic()); if (isImmutable()) escalate(); ((char*)rawdata())[offset] = ch; m_hash = 0; }