Skip to content

Commit 397cf15

Browse files
authored
Merge pull request #23 from cpunion/reduce-types
reduce exported types
2 parents c4ea32c + bf2bf59 commit 397cf15

20 files changed

+61
-62
lines changed

bool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Bool struct {
99
Object
1010
}
1111

12-
func newBool(obj *PyObject) Bool {
12+
func newBool(obj *cPyObject) Bool {
1313
return Bool{newObject(obj)}
1414
}
1515

bytes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Bytes struct {
1212
Object
1313
}
1414

15-
func newBytes(obj *PyObject) Bytes {
15+
func newBytes(obj *cPyObject) Bytes {
1616
return Bytes{newObject(obj)}
1717
}
1818

complex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Complex struct {
99
Object
1010
}
1111

12-
func newComplex(obj *PyObject) Complex {
12+
func newComplex(obj *cPyObject) Complex {
1313
return Complex{newObject(obj)}
1414
}
1515

convert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func From(from any) Object {
1515
switch v := from.(type) {
1616
case Objecter:
17-
return newObject(v.Obj())
17+
return newObject(v.cpyObj())
1818
case int8:
1919
return newObject(C.PyLong_FromLong(C.long(v)))
2020
case int16:
@@ -181,11 +181,11 @@ func ToValue(from Object, to reflect.Value) bool {
181181
}
182182
} else {
183183
maps := getGlobalData()
184-
tyMeta := maps.typeMetas[from.Type().Obj()]
184+
tyMeta := maps.typeMetas[from.Type().cpyObj()]
185185
if tyMeta == nil {
186186
return false
187187
}
188-
wrapper := (*wrapperType)(unsafe.Pointer(from.Obj()))
188+
wrapper := (*wrapperType)(unsafe.Pointer(from.cpyObj()))
189189
to.Set(reflect.ValueOf(wrapper.goObj).Elem())
190190
return true
191191
}

convert_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ func TestFromSpecialCases(t *testing.T) {
180180
}()
181181

182182
func() {
183-
// Test From with Object.Obj()
183+
// Test From with Object.cpyObj()
184184
original := From(42)
185-
obj := From(original.Obj())
185+
obj := From(original.cpyObj())
186186

187187
if !obj.IsLong() {
188-
t.Error("From(Object.Obj()) did not create Long object")
188+
t.Error("From(Object.cpyObj()) did not create Long object")
189189
}
190190
if got := obj.AsLong().Int64(); got != 42 {
191-
t.Errorf("From(Object.Obj()) = %d, want 42", got)
191+
t.Errorf("From(Object.cpyObj()) = %d, want 42", got)
192192
}
193193

194194
// Test that the new object is independent
@@ -281,7 +281,7 @@ func TestFromWithCustomType(t *testing.T) {
281281
obj := From(p)
282282

283283
// Verify the type
284-
if obj.Type().Obj() != pointClass.Obj() {
284+
if obj.Type().cpyObj() != pointClass.cpyObj() {
285285
t.Error("From(Point) created object with wrong type")
286286
}
287287
// Verify the values
@@ -311,7 +311,7 @@ func TestFromWithCustomType(t *testing.T) {
311311
obj := From(p)
312312

313313
// Verify the type
314-
if obj.Type().Obj() != pointClass.Obj() {
314+
if obj.Type().cpyObj() != pointClass.cpyObj() {
315315
t.Error("From(*Point) created object with wrong type")
316316
}
317317

dict.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Dict struct {
1313
Object
1414
}
1515

16-
func newDict(obj *PyObject) Dict {
16+
func newDict(obj *cPyObject) Dict {
1717
return Dict{newObject(obj)}
1818
}
1919

@@ -44,19 +44,19 @@ func (d Dict) HasKey(key any) bool {
4444
}
4545

4646
func (d Dict) Get(key Objecter) Object {
47-
v := C.PyDict_GetItem(d.obj, key.Obj())
47+
v := C.PyDict_GetItem(d.obj, key.cpyObj())
4848
C.Py_IncRef(v)
4949
return newObject(v)
5050
}
5151

5252
func (d Dict) Set(key, value Objecter) {
53-
keyObj := key.Obj()
54-
valueObj := value.Obj()
53+
keyObj := key.cpyObj()
54+
valueObj := value.cpyObj()
5555
C.PyDict_SetItem(d.obj, keyObj, valueObj)
5656
}
5757

5858
func (d Dict) SetString(key string, value Objecter) {
59-
valueObj := value.Obj()
59+
valueObj := value.cpyObj()
6060
ckey := AllocCStr(key)
6161
r := C.PyDict_SetItemString(d.obj, ckey, valueObj)
6262
C.free(unsafe.Pointer(ckey))
@@ -72,7 +72,7 @@ func (d Dict) GetString(key string) Object {
7272
}
7373

7474
func (d Dict) Del(key Objecter) {
75-
C.PyDict_DelItem(d.obj, key.Obj())
75+
C.PyDict_DelItem(d.obj, key.cpyObj())
7676
}
7777

7878
func (d Dict) Iter() *DictIter {

extension.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func CreateFunc(name string, fn any, doc string) Func {
3131
}
3232

3333
type wrapperType struct {
34-
PyObject
34+
cPyObject
3535
goObj any
3636
holder *objectHolder
3737
}
@@ -139,7 +139,7 @@ func getterMethod(self *C.PyObject, _closure unsafe.Pointer, methodId C.int) *C.
139139
return (*C.PyObject)(unsafe.Pointer(newWrapper))
140140
}
141141
}
142-
return From(field.Interface()).Obj()
142+
return From(field.Interface()).cpyObj()
143143
}
144144

145145
//export setterMethod
@@ -307,17 +307,17 @@ func wrapperMethod_(typeMeta *typeMeta, methodMeta *slotMeta, self, args *C.PyOb
307307
}
308308

309309
if len(results) == 0 {
310-
return None().Obj()
310+
return None().cpyObj()
311311
}
312312
if len(results) == 1 {
313-
return From(results[0].Interface()).Obj()
313+
return From(results[0].Interface()).cpyObj()
314314
}
315315

316316
tuple := MakeTupleWithLen(len(results))
317317
for i := range results {
318318
tuple.Set(i, From(results[i].Interface()))
319319
}
320-
return tuple.Obj()
320+
return tuple.cpyObj()
321321
}
322322

323323
func goNameToPythonName(name string) string {

extension_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ func TestAddTypeDuplicate(t *testing.T) {
700700
t.Fatal("Failed to get type on second registration")
701701
}
702702

703-
if typ1.Obj() != typ2.Obj() {
703+
if typ1.cpyObj() != typ2.cpyObj() {
704704
t.Fatal("Expected same type object on second registration")
705705
}
706706

@@ -721,7 +721,7 @@ assert obj1.value == 42
721721
t.Fatal("Failed to get type on registration with pointer")
722722
}
723723

724-
if typ1.Obj() != typ3.Obj() {
724+
if typ1.cpyObj() != typ3.cpyObj() {
725725
t.Fatal("Expected same type object on second registration")
726726
}
727727
}

float.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Float struct {
1111
Object
1212
}
1313

14-
func newFloat(obj *PyObject) Float {
14+
func newFloat(obj *cPyObject) Float {
1515
return Float{newObject(obj)}
1616
}
1717

function.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package gp
66
import "C"
77

88
type Objecter interface {
9-
Obj() *PyObject
9+
cpyObj() *cPyObject
1010
object() Object
1111
Ensure()
1212
}
@@ -15,7 +15,7 @@ type Func struct {
1515
Object
1616
}
1717

18-
func newFunc(obj *PyObject) Func {
18+
func newFunc(obj *cPyObject) Func {
1919
return Func{newObject(obj)}
2020
}
2121

@@ -32,7 +32,7 @@ func (f Func) callNoArgs() Object {
3232
}
3333

3434
func (f Func) callOneArg(arg Objecter) Object {
35-
return newObject(C.PyObject_CallOneArg(f.obj, arg.Obj()))
35+
return newObject(C.PyObject_CallOneArg(f.obj, arg.cpyObj()))
3636
}
3737

3838
func (f Func) CallObject(args Tuple) Object {

0 commit comments

Comments
 (0)