Try to make GC work better
parent
bc3d64da7b
commit
481101bc53
18
guessit.go
18
guessit.go
|
@ -59,11 +59,13 @@ func New() (*Guessit, error) {
|
||||||
if !(module != nil && python3.PyErr_Occurred() == nil) {
|
if !(module != nil && python3.PyErr_Occurred() == nil) {
|
||||||
return nil, fmt.Errorf("failed to add module 'guessit'")
|
return nil, fmt.Errorf("failed to add module 'guessit'")
|
||||||
}
|
}
|
||||||
|
defer module.DecRef()
|
||||||
|
|
||||||
dict := python3.PyModule_GetDict(module) //ret val: Borrowed
|
dict := python3.PyModule_GetDict(module) //ret val: Borrowed
|
||||||
if !(dict != nil && python3.PyErr_Occurred() == nil) {
|
if !(dict != nil && python3.PyErr_Occurred() == nil) {
|
||||||
return nil, fmt.Errorf("could not get dict for module")
|
return nil, fmt.Errorf("could not get dict for module")
|
||||||
}
|
}
|
||||||
|
|
||||||
guessitfn := python3.PyDict_GetItemString(dict, "guessit") //retval: Borrowed
|
guessitfn := python3.PyDict_GetItemString(dict, "guessit") //retval: Borrowed
|
||||||
if !(guessitfn != nil && python3.PyCallable_Check(guessitfn)) {
|
if !(guessitfn != nil && python3.PyCallable_Check(guessitfn)) {
|
||||||
return nil, fmt.Errorf("could not find function 'guessit'")
|
return nil, fmt.Errorf("could not find function 'guessit'")
|
||||||
|
@ -80,13 +82,17 @@ func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
item := python3.PyUnicode_FromString(s)
|
item := python3.PyUnicode_FromString(s)
|
||||||
|
defer item.DecRef()
|
||||||
|
|
||||||
opts := python3.PyUnicode_FromString(strings.Join(options[:], " "))
|
opts := python3.PyUnicode_FromString(strings.Join(options[:], " "))
|
||||||
|
defer opts.DecRef()
|
||||||
|
|
||||||
args := python3.PyTuple_New(2) //retval: New reference
|
args := python3.PyTuple_New(2) //retval: New reference
|
||||||
if args == nil {
|
if args == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer args.DecRef()
|
defer args.DecRef()
|
||||||
|
|
||||||
ret := python3.PyTuple_SetItem(args, 0, item) //steals ref to pylist
|
ret := python3.PyTuple_SetItem(args, 0, item) //steals ref to pylist
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
if python3.PyErr_Occurred() != nil {
|
if python3.PyErr_Occurred() != nil {
|
||||||
|
@ -108,11 +114,13 @@ func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println(python3.PyUnicode_AsUTF8(testdataPy.Repr()))
|
|
||||||
|
|
||||||
size := python3.PyDict_Size(testdataPy)
|
size := python3.PyDict_Size(testdataPy)
|
||||||
keys := python3.PyDict_Keys(testdataPy)
|
keys := python3.PyDict_Keys(testdataPy)
|
||||||
|
defer keys.DecRef()
|
||||||
vals := python3.PyDict_Values(testdataPy)
|
vals := python3.PyDict_Values(testdataPy)
|
||||||
|
defer vals.DecRef()
|
||||||
|
|
||||||
|
testdataPy = nil
|
||||||
|
|
||||||
tmpmap := make(map[string]interface{})
|
tmpmap := make(map[string]interface{})
|
||||||
for i := 0; i < size; i++ {
|
for i := 0; i < size; i++ {
|
||||||
|
@ -126,7 +134,9 @@ func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
||||||
case python3.PyList_Check(val):
|
case python3.PyList_Check(val):
|
||||||
var tmp []string
|
var tmp []string
|
||||||
for i := 0; i < python3.PyList_Size(val); i++ {
|
for i := 0; i < python3.PyList_Size(val); i++ {
|
||||||
v := python3.PyUnicode_AsUTF8(python3.PyList_GetItem(val, i))
|
item := python3.PyList_GetItem(val, i)
|
||||||
|
v := python3.PyUnicode_AsUTF8(item)
|
||||||
|
item.DecRef()
|
||||||
tmp = append(tmp, v)
|
tmp = append(tmp, v)
|
||||||
}
|
}
|
||||||
tmpmap[key] = tmp
|
tmpmap[key] = tmp
|
||||||
|
@ -134,8 +144,6 @@ func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//spew.Dump(tmpmap)
|
|
||||||
|
|
||||||
config := &mapstructure.DecoderConfig{
|
config := &mapstructure.DecoderConfig{
|
||||||
WeaklyTypedInput: true,
|
WeaklyTypedInput: true,
|
||||||
Result: &out,
|
Result: &out,
|
||||||
|
|
Loading…
Reference in New Issue