Skip to content

Commit

Permalink
Clarify prefix check on interned string type
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Nov 9, 2023
1 parent 21c35b2 commit c7d3315
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pyc_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class PycModule {
return (m_maj >= 3) || (m_code->flags() & PycCode::CO_FUTURE_UNICODE_LITERALS) != 0;
}

bool internIsBytes() const
{
return (m_maj < 3) && (m_code->flags() & PycCode::CO_FUTURE_UNICODE_LITERALS) != 0;
}

PycRef<PycCode> code() const { return m_code; }

void intern(PycRef<PycString> str) { m_interns.emplace_back(std::move(str)); }
Expand Down
8 changes: 4 additions & 4 deletions pyc_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ void PycString::print(std::ostream &pyc_output, PycModule* mod, bool triple,
prefix = mod->strIsUnicode() ? 0 : 'u';
break;
case PycObject::TYPE_INTERNED:
prefix = mod->internIsBytes() ? 'b' : 0;
break;
case PycObject::TYPE_ASCII:
case PycObject::TYPE_ASCII_INTERNED:
case PycObject::TYPE_SHORT_ASCII:
case PycObject::TYPE_SHORT_ASCII_INTERNED:
if (mod->majorVer() >= 3)
prefix = 0;
else
prefix = mod->strIsUnicode() ? 'b' : 0;
// These types don't exist until Python 3.4
prefix = 0;
break;
default:
throw std::runtime_error("Invalid string type");
Expand Down

0 comments on commit c7d3315

Please sign in to comment.