11
11
12
12
#include " Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
13
13
#include " Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
14
+ #include " TestingSupport/SubsystemRAII.h"
14
15
#include " lldb/Host/File.h"
15
16
#include " lldb/Host/FileSystem.h"
16
17
#include " lldb/Host/HostInfo.h"
@@ -27,6 +28,8 @@ using llvm::Error;
27
28
using llvm::Expected;
28
29
29
30
class PythonDataObjectsTest : public PythonTestSuite {
31
+ SubsystemRAII<FileSystem> subsystems;
32
+
30
33
public:
31
34
void SetUp () override {
32
35
PythonTestSuite::SetUp ();
@@ -52,21 +55,24 @@ class PythonDataObjectsTest : public PythonTestSuite {
52
55
53
56
TEST_F (PythonDataObjectsTest, TestOwnedReferences) {
54
57
// 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) ;
57
60
EXPECT_LE (1 , original_refcnt);
58
61
59
62
// 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);
62
66
63
67
// 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);
66
71
67
72
// 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);
70
76
}
71
77
72
78
TEST_F (PythonDataObjectsTest, TestResetting) {
@@ -83,12 +89,15 @@ TEST_F(PythonDataObjectsTest, TestResetting) {
83
89
}
84
90
85
91
TEST_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 ());
88
95
EXPECT_LE (1 , original_refcnt);
89
96
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);
92
101
}
93
102
94
103
TEST_F (PythonDataObjectsTest, TestGlobalNameResolutionNoDot) {
@@ -204,8 +213,8 @@ TEST_F(PythonDataObjectsTest, TestPythonBoolean) {
204
213
};
205
214
206
215
// 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.
209
218
test_from_long (~0 ); // Any value != 0 is 'true'.
210
219
}
211
220
@@ -803,7 +812,8 @@ main = foo
803
812
testing::ContainsRegex (" line 7, in baz" ),
804
813
testing::ContainsRegex (" ZeroDivisionError" )))));
805
814
806
- #if !((defined(_WIN32) || defined(_WIN64)) && (defined(__aarch64__) || defined(_M_ARM64)))
815
+ #if !((defined(_WIN32) || defined(_WIN64)) && \
816
+ (defined (__aarch64__) || defined (_M_ARM64)))
807
817
808
818
static const char script2[] = R"(
809
819
class MyError(Exception):
0 commit comments