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) {
|
||||
return nil, fmt.Errorf("failed to add module 'guessit'")
|
||||
}
|
||||
defer module.DecRef()
|
||||
|
||||
dict := python3.PyModule_GetDict(module) //ret val: Borrowed
|
||||
if !(dict != nil && python3.PyErr_Occurred() == nil) {
|
||||
return nil, fmt.Errorf("could not get dict for module")
|
||||
}
|
||||
|
||||
guessitfn := python3.PyDict_GetItemString(dict, "guessit") //retval: Borrowed
|
||||
if !(guessitfn != nil && python3.PyCallable_Check(guessitfn)) {
|
||||
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)
|
||||
defer item.DecRef()
|
||||
|
||||
opts := python3.PyUnicode_FromString(strings.Join(options[:], " "))
|
||||
defer opts.DecRef()
|
||||
|
||||
args := python3.PyTuple_New(2) //retval: New reference
|
||||
if args == nil {
|
||||
return
|
||||
}
|
||||
defer args.DecRef()
|
||||
|
||||
ret := python3.PyTuple_SetItem(args, 0, item) //steals ref to pylist
|
||||
if ret != 0 {
|
||||
if python3.PyErr_Occurred() != nil {
|
||||
|
@ -108,11 +114,13 @@ func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
//fmt.Println(python3.PyUnicode_AsUTF8(testdataPy.Repr()))
|
||||
|
||||
size := python3.PyDict_Size(testdataPy)
|
||||
keys := python3.PyDict_Keys(testdataPy)
|
||||
defer keys.DecRef()
|
||||
vals := python3.PyDict_Values(testdataPy)
|
||||
defer vals.DecRef()
|
||||
|
||||
testdataPy = nil
|
||||
|
||||
tmpmap := make(map[string]interface{})
|
||||
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):
|
||||
var tmp []string
|
||||
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)
|
||||
}
|
||||
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{
|
||||
WeaklyTypedInput: true,
|
||||
Result: &out,
|
||||
|
|
Loading…
Reference in New Issue