Skip to content

Commit 8c7df69

Browse files
committed
Handle PyUnicode object state layout changes in 3.14t
1 parent 3005c6d commit 8c7df69

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/pystack/_pystack/cpython/string.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,22 @@ typedef struct
109109

110110
} // namespace Python3_12
111111

112+
namespace Python3_14t {
113+
114+
struct _PyUnicode_State
115+
{
116+
unsigned char interned;
117+
unsigned int kind : 3;
118+
unsigned int compact : 1;
119+
unsigned int ascii : 1;
120+
unsigned int statically_allocated : 1;
121+
};
122+
123+
} // namespace Python3_14t
124+
125+
union AnyPyUnicodeState {
126+
Python3::_PyUnicode_State python3;
127+
Python3_14t::_PyUnicode_State python3_14t;
128+
};
129+
112130
} // namespace pystack

src/pystack/_pystack/process.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,15 @@ AbstractProcessManager::getStringFromAddress(remote_addr_t addr) const
540540
<< addr;
541541
Structure<py_unicode_v> unicode(shared_from_this(), addr);
542542

543-
Python3::_PyUnicode_State state = unicode.getField(&py_unicode_v::o_state);
544-
if (state.kind != 1 || state.compact != 1) {
545-
throw InvalidRemoteObject();
543+
AnyPyUnicodeState state = unicode.getField(&py_unicode_v::o_state);
544+
if (versionIsAtLeast(3, 14) and isFreeThreaded()) {
545+
if (state.python3_14t.kind != 1 || state.python3_14t.compact != 1) {
546+
throw InvalidRemoteObject();
547+
}
548+
} else {
549+
if (state.python3.kind != 1 || state.python3.compact != 1) {
550+
throw InvalidRemoteObject();
551+
}
546552
}
547553

548554
len = unicode.getField(&py_unicode_v::o_length);

src/pystack/_pystack/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct py_bytes_v
7777
struct py_unicode_v
7878
{
7979
ssize_t size;
80-
FieldOffset<Python3::_PyUnicode_State> o_state;
80+
FieldOffset<AnyPyUnicodeState> o_state;
8181
FieldOffset<Py_ssize_t> o_length;
8282
FieldOffset<remote_addr_t> o_ascii;
8383
};

0 commit comments

Comments
 (0)