diff --git a/base.go b/base.go index 24d71a3..0a045c2 100644 --- a/base.go +++ b/base.go @@ -21,17 +21,11 @@ type BaseObject struct { o *C.PyObject } -var baseObjMap = make(map[*C.PyObject]*BaseObject) - // BaseType is the Type object that represents the BaseObject type. var BaseType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyBaseObject_Type)))) func newBaseObject(obj *C.PyObject) *BaseObject { - if bo, ok := baseObjMap[obj]; ok { - return bo - } bo := &BaseObject{o: obj} - baseObjMap[obj] = bo return bo } @@ -200,8 +194,11 @@ func (obj *BaseObject) CallObject(args *Tuple) (Object, error) { var a *C.PyObject = nil if args != nil { a = c(args) + defer args.Decref() } + ret := C.PyObject_CallObject(c(obj), a) + return obj2ObjErr(ret) } diff --git a/complex.go b/complex.go index fde9f55..fc880b6 100644 --- a/complex.go +++ b/complex.go @@ -19,8 +19,6 @@ type Complex struct { o *C.PyComplexObject } -var complexObjMap = make(map[*C.PyObject]*Complex) - // ComplexType is the Type object that represents the Complex type. var ComplexType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyComplex_Type)))) @@ -29,11 +27,7 @@ func complexCheck(obj Object) bool { } func newComplex(obj *C.PyObject) *Complex { - if c, ok := complexObjMap[obj]; ok { - return c - } c := &Complex{o: (*C.PyComplexObject)(unsafe.Pointer(obj))} - complexObjMap[obj] = c return c } diff --git a/dict.go b/dict.go index 765600d..c6627c2 100644 --- a/dict.go +++ b/dict.go @@ -22,8 +22,6 @@ type Dict struct { o *C.PyDictObject } -var dictObjMap = make(map[*C.PyObject]*Dict) - // DictType is the Type object that represents the Dict type. var DictType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyDict_Type)))) @@ -35,11 +33,7 @@ func dictCheck(obj Object) bool { } func newDict(obj *C.PyObject) *Dict { - if di, ok := dictObjMap[obj]; ok { - return di - } di := &Dict{o: (*C.PyDictObject)(unsafe.Pointer(obj))} - dictObjMap[obj] = di return di } diff --git a/exceptions.go b/exceptions.go index e1df7de..76fa1b3 100644 --- a/exceptions.go +++ b/exceptions.go @@ -16,14 +16,8 @@ type ExceptionClass struct { o *C.PyBaseExceptionObject } -var exceptionObjMap = make(map[*C.PyObject]*ExceptionClass) - func newException(obj *C.PyObject) *ExceptionClass { - if e, ok := exceptionObjMap[obj]; ok { - return e - } e := &ExceptionClass{o: (*C.PyBaseExceptionObject)(unsafe.Pointer(obj))} - exceptionObjMap[obj] = e return e } diff --git a/float.go b/float.go index 95d8987..585f006 100644 --- a/float.go +++ b/float.go @@ -19,8 +19,6 @@ type Float struct { o *C.PyFloatObject } -var floatObjMap = make(map[*C.PyObject]*Float) - // FloatType is the Type object that represents the Float type. var FloatType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyFloat_Type)))) @@ -29,11 +27,7 @@ func floatCheck(obj Object) bool { } func newFloat(obj *C.PyObject) *Float { - if f, ok := floatObjMap[obj]; ok { - return f - } f := &Float{o: (*C.PyFloatObject)(unsafe.Pointer(obj))} - floatObjMap[obj] = f return f } diff --git a/function.go b/function.go index 670df43..0f4cff7 100644 --- a/function.go +++ b/function.go @@ -17,17 +17,11 @@ type Function struct { o *C.PyFunctionObject } -var functionObjMap = make(map[*C.PyObject]*Function) - // FunctionType is the Type object that represents the Function type. var FunctionType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyFunction_Type)))) func newFunction(obj *C.PyObject) *Function { - if f, ok := functionObjMap[obj]; ok { - return f - } f := &Function{o: (*C.PyFunctionObject)(unsafe.Pointer(obj))} - functionObjMap[obj] = f return f } diff --git a/list.go b/list.go index ea49f42..f0be940 100644 --- a/list.go +++ b/list.go @@ -22,8 +22,6 @@ type List struct { o *C.PyListObject } -var listObjMap = make(map[*C.PyObject]*List) - // ListType is the Type object that represents the List type. var ListType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyList_Type)))) @@ -32,11 +30,7 @@ func listCheck(obj Object) bool { } func newList(obj *C.PyObject) *List { - if l, ok := listObjMap[obj]; ok { - return l - } l := &List{o: (*C.PyListObject)(unsafe.Pointer(obj))} - listObjMap[obj] = l return l } diff --git a/long.go b/long.go index ad08c2c..38b1a72 100644 --- a/long.go +++ b/long.go @@ -19,8 +19,6 @@ type Long struct { o *C.PyLongObject } -var longObjMap = make(map[*C.PyObject]*Long) - // LongType is the Type object that represents the Long type. var LongType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyLong_Type)))) @@ -32,11 +30,7 @@ func longCheck(obj Object) bool { } func newLong(obj *C.PyObject) *Long { - if l, ok := longObjMap[obj]; ok { - return l - } l := &Long{o: (*C.PyLongObject)(unsafe.Pointer(obj))} - longObjMap[obj] = l return l } diff --git a/module.go b/module.go index 2b43cca..e6e8856 100644 --- a/module.go +++ b/module.go @@ -17,8 +17,6 @@ type Module struct { o *C.PyObject } -var moduleObjMap = make(map[*C.PyObject]*Module) - // ModuleType is the Type object that represents the Module type. var ModuleType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyModule_Type)))) @@ -30,11 +28,7 @@ func moduleCheck(obj Object) bool { } func newModule(obj *C.PyObject) *Module { - if m, ok := moduleObjMap[obj]; ok { - return m - } m := &Module{o: obj} - moduleObjMap[obj] = m return m } diff --git a/set.go b/set.go index 6fa9f79..3853c13 100644 --- a/set.go +++ b/set.go @@ -24,8 +24,6 @@ type FrozenSet struct { Set } -var setObjMap = make(map[*C.PyObject]*Set) - // SetType is the Type object that represents the Set type. var SetType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPySet_Type)))) @@ -41,11 +39,7 @@ func frozenSetCheck(obj Object) bool { } func newSet(obj *C.PyObject) *Set { - if s, ok := setObjMap[obj]; ok { - return s - } s := &Set{o: (*C.PySetObject)(unsafe.Pointer(obj))} - setObjMap[obj] = s return s } diff --git a/tuple.go b/tuple.go index 1f57661..3bba2b2 100644 --- a/tuple.go +++ b/tuple.go @@ -20,8 +20,6 @@ type Tuple struct { o *C.PyTupleObject } -var tupleObjMap = make(map[*C.PyObject]*Tuple) - // TupleType is the Type object that represents the Tuple type. var TupleType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyTuple_Type)))) @@ -33,11 +31,7 @@ func tupleCheck(obj Object) bool { } func newTuple(obj *C.PyObject) *Tuple { - if t, ok := tupleObjMap[obj]; ok { - return t - } t := &Tuple{o: (*C.PyTupleObject)(unsafe.Pointer(obj))} - tupleObjMap[obj] = t return t } diff --git a/type.go b/type.go index 59919cc..cf8d3b7 100644 --- a/type.go +++ b/type.go @@ -22,8 +22,6 @@ type Type struct { o *C.PyTypeObject } -var typeObjMap = make(map[*C.PyObject]*Type) - // TypeType is the Type object that represents the Type type. var TypeType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyType_Type)))) @@ -35,11 +33,7 @@ func typeCheck(obj Object) bool { } func newType(obj *C.PyObject) *Type { - if t, ok := typeObjMap[obj]; ok { - return t - } t := &Type{o: (*C.PyTypeObject)(unsafe.Pointer(obj))} - typeObjMap[obj] = t return t } diff --git a/unicode.go b/unicode.go index f668a6d..98ef88d 100644 --- a/unicode.go +++ b/unicode.go @@ -15,8 +15,6 @@ type Unicode struct { o *C.PyUnicodeObject } -var unicodeObjMap = make(map[*C.PyObject]*Unicode) - // UnicodeType is the Type object that represents the Unicode type. var UnicodeType = newType((*C.PyObject)(unsafe.Pointer(C.getBasePyType(C.GoPyUnicode_Type)))) @@ -25,11 +23,7 @@ func unicodeCheck(obj Object) bool { } func newUnicode(obj *C.PyObject) *Unicode { - if u, ok := unicodeObjMap[obj]; ok { - return u - } u := &Unicode{o: (*C.PyUnicodeObject)(unsafe.Pointer(obj))} - unicodeObjMap[obj] = u return u }