PycString */
| 17 | |
| 18 | /* PycString */ |
| 19 | void PycString::load(PycData* stream, PycModule* mod) |
| 20 | { |
| 21 | if (type() == TYPE_STRINGREF) { |
| 22 | PycRef<PycString> str = mod->getIntern(stream->get32()); |
| 23 | m_type = str->m_type; |
| 24 | m_value = str->m_value; |
| 25 | } else { |
| 26 | int length; |
| 27 | if (type() == TYPE_SHORT_ASCII || type() == TYPE_SHORT_ASCII_INTERNED) |
| 28 | length = stream->getByte(); |
| 29 | else |
| 30 | length = stream->get32(); |
| 31 | |
| 32 | if (length < 0) |
| 33 | throw std::bad_alloc(); |
| 34 | |
| 35 | m_value.resize(length); |
| 36 | if (length) { |
| 37 | stream->getBuffer(length, &m_value.front()); |
| 38 | if (type() == TYPE_ASCII || type() == TYPE_ASCII_INTERNED || |
| 39 | type() == TYPE_SHORT_ASCII || type() == TYPE_SHORT_ASCII_INTERNED) { |
| 40 | if (!check_ascii(m_value)) |
| 41 | throw std::runtime_error("Invalid bytes in ASCII string"); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if (type() == TYPE_INTERNED || type() == TYPE_ASCII_INTERNED || |
| 46 | type() == TYPE_SHORT_ASCII_INTERNED) |
| 47 | mod->intern(this); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | bool PycString::isEqual(PycRef<PycObject> obj) const |
| 52 | { |