1111
1212#include " Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
1313#include " Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
14+ #include " TestingSupport/SubsystemRAII.h"
1415#include " lldb/Host/File.h"
1516#include " lldb/Host/FileSystem.h"
1617#include " lldb/Host/HostInfo.h"
@@ -27,6 +28,8 @@ using llvm::Error;
2728using llvm::Expected;
2829
2930class PythonDataObjectsTest : public PythonTestSuite {
31+ SubsystemRAII<FileSystem> subsystems;
32+
3033public:
3134 void SetUp () override {
3235 PythonTestSuite::SetUp ();
@@ -52,21 +55,24 @@ class PythonDataObjectsTest : public PythonTestSuite {
5255
5356TEST_F (PythonDataObjectsTest, TestOwnedReferences) {
5457 // After creating a new object, the refcount should be >= 1
55- PyObject *obj = PyLong_FromLong ( 3 );
56- Py_ssize_t original_refcnt = obj-> ob_refcnt ;
58+ PyObject *obj = PyBytes_FromString ( " foo " );
59+ Py_ssize_t original_refcnt = Py_REFCNT ( obj) ;
5760 EXPECT_LE (1 , original_refcnt);
5861
5962 // If we take an owned reference, the refcount should be the same
60- PythonObject owned_long (PyRefType::Owned, obj);
61- EXPECT_EQ (original_refcnt, owned_long.get ()->ob_refcnt );
63+ PythonObject owned (PyRefType::Owned, obj);
64+ Py_ssize_t owned_refcnt = Py_REFCNT (owned.get ());
65+ EXPECT_EQ (original_refcnt, owned_refcnt);
6266
6367 // Take another reference and verify that the refcount increases by 1
64- PythonObject strong_ref (owned_long);
65- EXPECT_EQ (original_refcnt + 1 , strong_ref.get ()->ob_refcnt );
68+ PythonObject strong_ref (owned);
69+ Py_ssize_t strong_refcnt = Py_REFCNT (strong_ref.get ());
70+ EXPECT_EQ (original_refcnt + 1 , strong_refcnt);
6671
6772 // If we reset the first one, the refcount should be the original value.
68- owned_long.Reset ();
69- EXPECT_EQ (original_refcnt, strong_ref.get ()->ob_refcnt );
73+ owned.Reset ();
74+ strong_refcnt = Py_REFCNT (strong_ref.get ());
75+ EXPECT_EQ (original_refcnt, strong_refcnt);
7076}
7177
7278TEST_F (PythonDataObjectsTest, TestResetting) {
@@ -83,12 +89,15 @@ TEST_F(PythonDataObjectsTest, TestResetting) {
8389}
8490
8591TEST_F (PythonDataObjectsTest, TestBorrowedReferences) {
86- PythonInteger long_value (PyRefType::Owned, PyLong_FromLong (3 ));
87- Py_ssize_t original_refcnt = long_value.get ()->ob_refcnt ;
92+ PythonByteArray byte_value (PyRefType::Owned,
93+ PyByteArray_FromStringAndSize (" foo" , 3 ));
94+ Py_ssize_t original_refcnt = Py_REFCNT (byte_value.get ());
8895 EXPECT_LE (1 , original_refcnt);
8996
90- PythonInteger borrowed_long (PyRefType::Borrowed, long_value.get ());
91- EXPECT_EQ (original_refcnt + 1 , borrowed_long.get ()->ob_refcnt );
97+ PythonByteArray borrowed_byte (PyRefType::Borrowed, byte_value.get ());
98+ Py_ssize_t borrowed_refcnt = Py_REFCNT (borrowed_byte.get ());
99+
100+ EXPECT_EQ (original_refcnt + 1 , borrowed_refcnt);
92101}
93102
94103TEST_F (PythonDataObjectsTest, TestGlobalNameResolutionNoDot) {
@@ -204,8 +213,8 @@ TEST_F(PythonDataObjectsTest, TestPythonBoolean) {
204213 };
205214
206215 // Test PythonBoolean constructed from long integer values.
207- test_from_long (0 ); // Test 'false' value.
208- test_from_long (1 ); // Test 'true' value.
216+ test_from_long (0 ); // Test 'false' value.
217+ test_from_long (1 ); // Test 'true' value.
209218 test_from_long (~0 ); // Any value != 0 is 'true'.
210219}
211220
@@ -803,7 +812,8 @@ main = foo
803812 testing::ContainsRegex (" line 7, in baz" ),
804813 testing::ContainsRegex (" ZeroDivisionError" )))));
805814
806- #if !((defined(_WIN32) || defined(_WIN64)) && (defined(__aarch64__) || defined(_M_ARM64)))
815+ #if !((defined(_WIN32) || defined(_WIN64)) && \
816+ (defined (__aarch64__) || defined (_M_ARM64)))
807817
808818 static const char script2[] = R"(
809819class MyError(Exception):
0 commit comments