Skip to content

Commit 2faf67d

Browse files
Update test outputs + fix semantics
1 parent 085df26 commit 2faf67d

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

python/ql/src/Classes/CallsToInitDel/MethodCallOrder.qll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ Function getASuperCallTarget(Class mroBase, Function meth, DataFlow::MethodCallN
1919
meth = call.getScope() and
2020
getADirectSuperclass*(mroBase) = meth.getScope() and
2121
call.calls(_, meth.getName()) and
22-
exists(Function target, Class nextMroBase |
23-
(result = target or result = getASuperCallTarget(nextMroBase, target, _))
24-
|
22+
exists(Function target | (result = target or result = getASuperCallTarget(mroBase, target, _)) |
2523
superCall(call, _) and
26-
nextMroBase = mroBase and
2724
target =
2825
findFunctionAccordingToMroKnownStartingClass(getNextClassInMroKnownStartingClass(meth.getScope(),
2926
mroBase), mroBase, meth.getName())
3027
or
31-
callsMethodOnClassWithSelf(meth, call, nextMroBase, _) and
32-
target = findFunctionAccordingToMro(nextMroBase, meth.getName())
28+
exists(Class called |
29+
callsMethodOnClassWithSelf(meth, call, called, _) and
30+
target = findFunctionAccordingToMroKnownStartingClass(called, mroBase, meth.getName())
31+
)
3332
)
3433
}
3534

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| multiple_del.py:17:1:17:17 | class Y3 | Class Y3 may not be cleaned up properly as $@ may be called multiple times during destruction. | multiple_del.py:9:5:9:22 | Function __del__ | method Y1.__del__ |
2-
| multiple_del.py:34:1:34:17 | class Z3 | Class Z3 may not be cleaned up properly as $@ may be called multiple times during destruction. | multiple_del.py:26:5:26:22 | Function __del__ | method Z1.__del__ |
1+
| multiple_del.py:21:5:21:22 | Function __del__ | This delete method calls $@ multiple times. | multiple_del.py:9:5:9:22 | Function __del__ | Y1.__del__ |
2+
| multiple_del.py:43:5:43:22 | Function __del__ | This delete method calls $@ multiple times. | multiple_del.py:32:5:32:22 | Function __del__ | Z1.__del__ |

python/ql/test/query-tests/Classes/multiple/multiple-del/multiple_del.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,48 @@
22
class Base(object):
33

44
def __del__(self):
5-
pass
5+
print("Base del")
66

77
class Y1(Base):
88

99
def __del__(self):
10+
print("Y1 del")
1011
super(Y1, self).__del__()
1112

1213
class Y2(Base):
1314

1415
def __del__(self):
16+
print("Y2 del")
1517
super(Y2, self).__del__() #When `type(self) == Y3` this calls `Y1.__del__`
1618

1719
class Y3(Y2, Y1):
1820

19-
def __del__(self):
21+
def __del__(self): # $ Alert
22+
print("Y3 del")
2023
Y1.__del__(self)
2124
Y2.__del__(self)
2225

26+
a = Y3()
27+
del a
28+
2329
#Calling a method multiple times by using explicit calls when a base inherits from other base
2430
class Z1(object):
2531

2632
def __del__(self):
27-
pass
33+
print("Z1 del")
2834

2935
class Z2(Z1):
3036

3137
def __del__(self):
38+
print("Z2 del")
3239
Z1.__del__(self)
3340

3441
class Z3(Z2, Z1):
3542

36-
def __del__(self):
43+
def __del__(self): # $ Alert
44+
print("Z3 del")
3745
Z1.__del__(self)
3846
Z2.__del__(self)
47+
48+
b = Z3()
49+
del b
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| multiple_init.py:17:1:17:17 | class C3 | Class C3 may not be initialized properly as $@ may be called multiple times during initialization. | multiple_init.py:9:5:9:23 | Function __init__ | method C1.__init__ |
2-
| multiple_init.py:34:1:34:17 | class D3 | Class D3 may not be initialized properly as $@ may be called multiple times during initialization. | multiple_init.py:26:5:26:23 | Function __init__ | method D1.__init__ |
1+
| multiple_init.py:21:5:21:23 | Function __init__ | This initialization method calls $@ multiple times. | multiple_init.py:9:5:9:23 | Function __init__ | C1.__init__ |
2+
| multiple_init.py:42:5:42:23 | Function __init__ | This initialization method calls $@ multiple times. | multiple_init.py:31:5:31:23 | Function __init__ | D1.__init__ |

python/ql/test/query-tests/Classes/multiple/multiple-init/multiple_init.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,64 @@ def __init__(self):
77
class C1(Base):
88

99
def __init__(self):
10+
print("C1 init")
1011
super(C1, self).__init__()
1112

1213
class C2(Base):
1314

1415
def __init__(self):
16+
print("C2 init")
1517
super(C2, self).__init__() #When `type(self) == C3` this calls `C1.__init__`
1618

1719
class C3(C2, C1):
1820

19-
def __init__(self):
21+
def __init__(self): # $ Alert
22+
print("C3 init")
2023
C1.__init__(self)
2124
C2.__init__(self)
2225

26+
C3()
27+
2328
#Calling a method multiple times by using explicit calls when a base inherits from other base
2429
class D1(object):
2530

2631
def __init__(self):
27-
pass
32+
print("D1 init")
2833

2934
class D2(D1):
3035

3136
def __init__(self):
37+
print("D2 init")
3238
D1.__init__(self)
3339

3440
class D3(D2, D1):
3541

36-
def __init__(self):
42+
def __init__(self): # $ Alert
43+
print("D3 init")
3744
D1.__init__(self)
3845
D2.__init__(self)
3946

47+
D3()
48+
4049
#OK to call object.__init__ multiple times
4150
class E1(object):
4251

4352
def __init__(self):
53+
print("E1 init")
4454
super(E1, self).__init__()
4555

4656
class E2(object):
4757

4858
def __init__(self):
59+
print("E2 init")
4960
object.__init__(self)
5061

5162
class E3(E2, E1):
5263

53-
def __init__(self):
64+
def __init__(self): # OK: builtin init methods are fine.
5465
E1.__init__(self)
5566
E2.__init__(self)
5667

57-
#Two invocations, but can only be called once
58-
class F1(Base):
59-
60-
def __init__(self, cond):
61-
if cond:
62-
Base.__init__(self)
63-
else:
64-
Base.__init__(self)
65-
66-
#Single call, splitting causes what seems to be multiple invocations.
67-
class F2(Base):
68-
69-
def __init__(self, cond):
70-
if cond:
71-
pass
72-
if cond:
73-
pass
74-
Base.__init__(self)
68+
E3()
7569

7670

0 commit comments

Comments
 (0)