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

.

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