Skip to content

Commit e9dcfd9

Browse files
committed
Merge pull request #59 from tanakad/019-rename-decref
Rename DecRef to Release
2 parents 42fbc07 + a321150 commit e9dcfd9

7 files changed

+32
-32
lines changed

error_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ func TestPyError(t *testing.T) {
1111
So(err, ShouldBeNil)
1212
So(mdl, ShouldNotBeNil)
1313
Reset(func() {
14-
mdl.DecRef()
14+
mdl.Release()
1515
})
1616

1717
syntaxError, err := mdl.GetClass("SyntaxError")
1818
So(err, ShouldBeNil)
1919
Reset(func() {
20-
syntaxError.DecRef()
20+
syntaxError.Release()
2121
})
2222
Convey("applying isSyntaxError to SyntaxError should return true.", func() {
2323
So(isSyntaxError(syntaxError.p), ShouldBeTrue)
@@ -26,7 +26,7 @@ func TestPyError(t *testing.T) {
2626
environmentError, err := mdl.GetClass("EnvironmentError")
2727
So(err, ShouldBeNil)
2828
Reset(func() {
29-
environmentError.DecRef()
29+
environmentError.Release()
3030
})
3131
Convey("applying isSyntaxError to EnvironmentError should return false.", func() {
3232
So(isSyntaxError(environmentError.p), ShouldBeFalse)

func_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestGetPyFuncError(t *testing.T) {
1515
So(err, ShouldBeNil)
1616
So(mdl, ShouldNotBeNil)
1717
Reset(func() {
18-
mdl.DecRef()
18+
mdl.Release()
1919
})
2020

2121
Convey("When func name is not exist", func() {
@@ -59,14 +59,14 @@ func TestPyFunc(t *testing.T) {
5959
obj, err := mdl.NewInstance("negator", nil, nil)
6060
So(err, ShouldBeNil)
6161
Reset(func() {
62-
obj.DecRef()
62+
obj.Release()
6363
})
6464
negator := ObjectFunc{obj.Object, "negator"}
6565

6666
alwaysFailObj, err := mdl.NewInstance("alwaysFail", nil, nil)
6767
So(err, ShouldBeNil)
6868
Reset(func() {
69-
alwaysFailObj.DecRef()
69+
alwaysFailObj.Release()
7070
})
7171
alwaysFail := ObjectFunc{alwaysFailObj.Object, "alwaysFail"}
7272

@@ -76,7 +76,7 @@ func TestPyFunc(t *testing.T) {
7676
})
7777
So(err, ShouldBeNil)
7878
Reset(func() {
79-
arg.DecRef()
79+
arg.Release()
8080
})
8181

8282
ret, err := safePythonCall(func() (Object, error) {
@@ -85,7 +85,7 @@ func TestPyFunc(t *testing.T) {
8585
Convey("it should succeed.", func() {
8686
So(err, ShouldBeNil)
8787
Reset(func() {
88-
ret.DecRef()
88+
ret.Release()
8989
})
9090
})
9191
})
@@ -96,7 +96,7 @@ func TestPyFunc(t *testing.T) {
9696
})
9797
So(err, ShouldBeNil)
9898
Reset(func() {
99-
badArg.DecRef()
99+
badArg.Release()
100100
})
101101

102102
ret2, err := safePythonCall(func() (Object, error) {

go2py_converter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestConvertGo2PyObject(t *testing.T) {
8888
})
8989

9090
Reset(func() {
91-
mdl.DecRef()
91+
mdl.Release()
9292
})
9393
})
9494
}

module_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestNewInstanceAndStateness(t *testing.T) {
5252
So(err, ShouldBeNil)
5353
So(ins, ShouldNotBeNil)
5454
Reset(func() {
55-
ins.DecRef()
55+
ins.Release()
5656
})
5757

5858
Convey("And when call a logger function", func() {
@@ -75,7 +75,7 @@ func TestNewInstanceAndStateness(t *testing.T) {
7575
So(err, ShouldBeNil)
7676
So(ins2, ShouldNotBeNil)
7777
Reset(func() {
78-
ins2.DecRef()
78+
ins2.Release()
7979
})
8080

8181
Convey("And when call a logger function", func() {
@@ -103,7 +103,7 @@ func TestNewInstanceAndStateness(t *testing.T) {
103103
So(err, ShouldBeNil)
104104
So(ins, ShouldNotBeNil)
105105
Reset(func() {
106-
ins.DecRef()
106+
ins.Release()
107107
})
108108

109109
actual, err := ins.Call("get_a")
@@ -118,7 +118,7 @@ func TestNewInstanceAndStateness(t *testing.T) {
118118
So(err, ShouldBeNil)
119119
So(ins2, ShouldNotBeNil)
120120
Reset(func() {
121-
ins2.DecRef()
121+
ins2.Release()
122122
})
123123

124124
actual2, err := ins2.Call("get_a")
@@ -149,7 +149,7 @@ func TestNewInstanceAndStateness(t *testing.T) {
149149
So(err, ShouldBeNil)
150150
})
151151
Reset(func() {
152-
class.DecRef()
152+
class.Release()
153153
})
154154

155155
Convey("Then process should get a string", func() {
@@ -187,7 +187,7 @@ func TestNewInstanceAndStateness(t *testing.T) {
187187
So(err, ShouldBeNil)
188188
})
189189
Reset(func() {
190-
class.DecRef()
190+
class.Release()
191191
})
192192

193193
Convey("Then process should get a string", func() {
@@ -216,13 +216,13 @@ func TestNewInstanceWithKeywordArgument(t *testing.T) {
216216
So(err, ShouldBeNil)
217217
So(mdl, ShouldNotBeNil)
218218
Reset(func() {
219-
mdl.DecRef()
219+
mdl.Release()
220220
})
221221

222222
Convey("When get a new test python instance with empty map", func() {
223223
ins, err := mdl.NewInstance("PythonTest", nil, data.Map{})
224224
Reset(func() {
225-
ins.DecRef()
225+
ins.Release()
226226
})
227227

228228
Convey("Then process should get a python instance from the module", func() {
@@ -240,7 +240,7 @@ func TestNewInstanceWithKeywordArgument(t *testing.T) {
240240
}
241241
ins, err := mdl.NewInstance("PythonTestForKwd", nil, arg)
242242
Reset(func() {
243-
ins.DecRef()
243+
ins.Release()
244244
})
245245

246246
Convey("Then process should get instance and set values", func() {
@@ -259,7 +259,7 @@ func TestNewInstanceWithKeywordArgument(t *testing.T) {
259259
}
260260
ins, err := mdl.NewInstance("PythonTestForKwd", nil, arg)
261261
Reset(func() {
262-
ins.DecRef()
262+
ins.Release()
263263
})
264264

265265
Convey("Then process should get instance and set values", func() {
@@ -279,7 +279,7 @@ func TestNewInstanceWithKeywordArgument(t *testing.T) {
279279
}
280280
ins, err := mdl.NewInstance("PythonTestForKwd", []data.Value{arg}, kwdArg)
281281
Reset(func() {
282-
ins.DecRef()
282+
ins.Release()
283283
})
284284

285285
Convey("Then process should get instance and set values", func() {

object.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ type Object struct {
1313
p *C.PyObject
1414
}
1515

16-
// DecRef decrease reference counter of `C.PyObject`
17-
// This function is public for API users and
18-
// it acquires GIL of Python interpreter.
19-
// A user can safely call this method even when its target object is null.
20-
func (o *Object) DecRef() {
16+
// Release decreases reference counter of `C.PyObject` and released the object.
17+
// This function is public for API users and it acquires GIL of Python
18+
// interpreter. A user can safely call this method even when its target object
19+
// is null.
20+
func (o *Object) Release() {
2121
mainthread.ExecSync(func() { // TODO: This Exec should probably be removed.
2222
// Py_XDECREF is not used here because it causes SEGV on Windows.
2323
if o.p == nil {

py2go_converter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestConvertPyObject2Go(t *testing.T) {
5151
}
5252

5353
Reset(func() {
54-
mdl.DecRef()
54+
mdl.Release()
5555
})
5656
})
5757
}

pystate/base.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func NewBase(baseParams *BaseParams, params data.Map) (*Base, error) {
138138
}
139139

140140
// newPyInstance creates a new Python class instance.
141-
// User must call DecRef method to release a resource.
141+
// User must call Release method to release a resource.
142142
func newPyInstance(createMethodName string, baseParams *BaseParams,
143143
args []data.Value, kwdArgs data.Map) (py.ObjectInstance, error) {
144144
var null py.ObjectInstance
@@ -148,13 +148,13 @@ func newPyInstance(createMethodName string, baseParams *BaseParams,
148148
if err != nil {
149149
return null, err
150150
}
151-
defer mdl.DecRef()
151+
defer mdl.Release()
152152

153153
class, err := mdl.GetClass(baseParams.ClassName)
154154
if err != nil {
155155
return null, err
156156
}
157-
defer class.DecRef()
157+
defer class.Release()
158158

159159
ins, err := class.CallDirect(createMethodName, args, kwdArgs)
160160
return py.ObjectInstance{ins}, err
@@ -174,7 +174,7 @@ func LoadBase(ctx *core.Context, r io.Reader, params data.Map) (*Base, error) {
174174

175175
func (s *Base) set(ins py.ObjectInstance, baseParams *BaseParams) {
176176
if s.ins != nil {
177-
s.ins.DecRef()
177+
s.ins.Release()
178178
}
179179
s.params = *baseParams
180180
s.ins = &ins
@@ -187,7 +187,7 @@ func (s *Base) Terminate(ctx *core.Context) error {
187187
if s.ins == nil {
188188
return nil // This isn't an error in Terminate
189189
}
190-
s.ins.DecRef()
190+
s.ins.Release()
191191
s.ins = nil
192192
return nil
193193
}

0 commit comments

Comments
 (0)