Commit 3c1df9e8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f1b89b31
......@@ -37,7 +37,7 @@ type KEY int64
// are chained together via 'next', so that the entire BTree contents
// can be traversed in sorted order quickly and easily.
type ZBucket struct {
*pyObject
*PyPersistent
next *ZBucket // the bucket with the next-larger keys
keys []KEY // 'len' keys, in increasing order
......@@ -55,7 +55,7 @@ type zBTreeItem struct {
// See https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/Development.txt#L198
// for details.
type ZBTree struct {
*pyObject
*PyPersistent
// firstbucket points to the bucket containing the smallest key in
// the BTree. This is found by traversing leftmost child pointers
......@@ -249,8 +249,8 @@ func (b *ZBucket) PySetState(pystate interface{}) error {
// ---- register classes to ZODB ----
func bucketNew(pyobj *pyObject) IPyPersistent { return &ZBucket{pyObject: pyobj} }
func btreeNew(pyobj *pyObject) IPyPersistent { return &ZBTree{pyObject: pyobj} }
func bucketNew(pyobj *PyPersistent) IPyPersistent { return &ZBucket{PyPersistent: pyobj} }
func btreeNew(pyobj *PyPersistent) IPyPersistent { return &ZBTree{PyPersistent: pyobj} }
func init() {
registerPyClass("zodb.BTree.LOBucket", bucketNew)
......
......@@ -35,7 +35,7 @@ const zwendelin = "wendelin.bigfile.file_zodb"
// ZBlk0 mimics ZBlk0 from python.
type ZBlk0 struct {
*pyObject
*PyPersistent
blkdata string
}
......@@ -58,7 +58,7 @@ func (zb *ZBlk0) PySetState(pystate interface{}) error {
// ZData mimics ZData from python.
type ZData struct {
*pyObject
*PyPersistent
data string
}
......@@ -79,7 +79,7 @@ func (zd *ZData) PySetState(pystate interface{}) error {
// ZBlk1 mimics ZBlk1 from python.
type ZBlk1 struct {
*pyObject
*PyPersistent
chunktab *ZBTree // {} offset -> ZData(chunk)
}
......@@ -103,7 +103,7 @@ func (zb *ZBlk1) PySetState(pystate interface{}) error {
// ZBigFile mimics ZBigFile from python.
type ZBigFile struct {
*pyObject
*PyPersistent
blksize int64
blktab *ZBTree // LOBtree{} blk -> ZBlk*(blkdata)
......@@ -147,10 +147,10 @@ func (bf *ZBigFile) PySetState(pystate interface{}) (err error) {
// ----------------------------------------
func zblk0New(base *pyObject) IPyPersistent { return &ZBlk0{pyObject: base} }
func zblk1New(base *pyObject) IPyPersistent { return &ZBlk1{pyObject: base} }
func zdataNew(base *pyObject) IPyPersistent { return &ZData{pyObject: base} }
func zbigfileNew(pyobj *pyObject) IPyPersistent { return &ZBigFile{pyObject: pyobj} }
func zblk0New(base *PyPersistent) IPyPersistent { return &ZBlk0{PyPersistent: base} }
func zblk1New(base *PyPersistent) IPyPersistent { return &ZBlk1{PyPersistent: base} }
func zdataNew(base *PyPersistent) IPyPersistent { return &ZData{PyPersistent: base} }
func zbigfileNew(pyobj *PyPersistent) IPyPersistent { return &ZBigFile{PyPersistent: pyobj} }
func init() {
registerPyClass(zwendelin + ".ZBlk", zblk0New)
......
......@@ -38,14 +38,14 @@ type IPyPersistent interface {
PyStateful
}
// pyObject is common base implementation for in-RAM representation of ZODB Python objects.
type pyObject struct {
// PyPersistent is common base implementation for in-RAM representation of ZODB Python objects.
type PyPersistent struct {
Persistent
pyclass pickle.Class
}
func (pyobj *pyObject) PyClass() pickle.Class { return pyobj.pyclass }
//func (pyobj *pyObject) PyState() interface{} { return pyobj.pystate }
func (pyobj *PyPersistent) PyClass() pickle.Class { return pyobj.pyclass }
//func (pyobj *PyPersistent) PyState() interface{} { return pyobj.pystate }
// PyStateful is the interface describing in-RAM object whose data state can be
// exchanged as Python data.
......@@ -59,17 +59,17 @@ type PyStateful interface {
//PyGetState() interface{} TODO
}
// ---- pyObject <-> Persistent state exchange ----
// ---- PyPersistent <-> Persistent state exchange ----
// pyinstance returns .instance upcasted to IPyPersistent.
//
// this should be always safe because we always create pyObjects via
// newGhost which passes IPyPersistent as instance to IPersistent.
func (pyobj *pyObject) pyinstance() IPyPersistent {
func (pyobj *PyPersistent) pyinstance() IPyPersistent {
return pyobj.instance.(IPyPersistent)
}
func (pyobj *pyObject) SetState(state *mem.Buf) error {
func (pyobj *PyPersistent) SetState(state *mem.Buf) error {
pyclass, pystate, err := zodb.PyData(state.Data).Decode()
if err != nil {
return err // XXX err ctx
......@@ -84,12 +84,12 @@ func (pyobj *pyObject) SetState(state *mem.Buf) error {
return pyobj.pyinstance().PySetState(pystate) // XXX err ctx = ok?
}
// TODO pyObject.GetState
// TODO PyPersistent.GetState
// ---- pyclass -> new ghost ----
// function representing new of a class.
type pyClassNewFunc func(base *pyObject) IPyPersistent
type pyClassNewFunc func(base *PyPersistent) IPyPersistent
// path(pyclass) -> new(pyobj)
var pyClassTab = make(map[string]pyClassNewFunc)
......@@ -105,7 +105,7 @@ func registerPyClass(pyClassPath string, classNew pyClassNewFunc) {
// newGhost creates new ghost object corresponding to pyclass and oid.
func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) IPyPersistent {
pyobj := &pyObject{
pyobj := &PyPersistent{
Persistent: Persistent{jar: conn, oid: oid, serial: 0, state: GHOST},
pyclass: pyclass,
}
......@@ -116,7 +116,7 @@ func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) IPyPersiste
if classNew != nil {
instance = classNew(pyobj)
} else {
instance = &dummyPyInstance{pyObject: pyobj}
instance = &dummyPyInstance{PyPersistent: pyobj}
}
pyobj.instance = instance
......@@ -125,7 +125,7 @@ func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) IPyPersiste
// dummyPyInstance is used for python classes that were not registered.
type dummyPyInstance struct {
*pyObject
*PyPersistent
pystate interface{}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment