Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
5c8cfac1
Commit
5c8cfac1
authored
Jan 18, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5d69ba25
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
go/zodb/persistent.go
go/zodb/persistent.go
+17
-12
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+9
-0
No files found.
go/zodb/persistent.go
View file @
5c8cfac1
...
...
@@ -281,31 +281,36 @@ var typeTab = make(map[reflect.Type]*zclass) // {} type -> zclass
// ClassOf returns ZODB class of a Go object.
//
// If ZODB class was not registered for obj's type, "" is returned. // XXX
// XXX -> keep obj IPersistent and add TypeOf(interface{}) ?
//func ClassOf(obj IPersistent) string {
func
ClassOf
(
obj
interface
{})
string
{
// The following is returned:
//
// - if obj's type was registered (RegisterClass) -- corresponding class.
// - for Broken objects -- ZODB.Broken("<broken-class>").
// - else -- ZODB.Go("<fully-qualified-type(obj)>")
func
ClassOf
(
obj
IPersistent
)
string
{
zb
,
broken
:=
obj
.
(
*
Broken
)
if
broken
{
return
fmt
.
Sprintf
(
"ZODB.Broken(%q)"
,
zb
.
class
)
}
typ
:=
reflect
.
TypeOf
(
obj
)
zc
,
ok
:=
typeTab
[
typ
.
Elem
()]
typ
=
typ
.
Elem
()
// *MyPersistent -> MyPersistent
zc
,
ok
:=
typeTab
[
typ
]
if
ok
{
return
zc
.
class
}
// XXX can we get vvv at all if obj is IPersistent? -> yes, if type was not registered.
// not Broken and type not registered to ZODB -> Broken(fullGoType(obj))
fullType
:=
"go:"
+
typ
.
PkgPath
()
if
typ
.
PkgPath
()
!=
""
{
// it could be builtin type, e.g. string
// the type was not registered to ZODB
fullType
:=
typ
.
PkgPath
()
if
typ
.
PkgPath
()
!=
""
{
fullType
+=
"."
}
fullType
+=
typ
.
Name
()
//return fmt.Sprintf("ZODB.Broken(%q)", fullType)
return
fullType
if
fullType
==
""
{
// fallback, since it is possible if the type is anonymous
// XXX not fully qualified
fullType
=
fmt
.
Sprintf
(
"*%T"
,
typ
)
}
return
fmt
.
Sprintf
(
"ZODB.Go(%q)"
,
fullType
)
}
var
rIPersistent
=
reflect
.
TypeOf
((
*
IPersistent
)(
nil
))
.
Elem
()
// typeof(IPersistent)
...
...
go/zodb/persistent_test.go
View file @
5c8cfac1
...
...
@@ -51,6 +51,11 @@ func (o *myObjectState) PySetState(pystate interface{}) error {
return
nil
}
// Peristent that is not registered to ZODB.
type
Unregistered
struct
{
Persistent
}
func
init
()
{
t
:=
reflect
.
TypeOf
RegisterClass
(
"t.zodb.MyObject"
,
t
(
MyObject
{}),
t
(
myObjectState
{}))
...
...
@@ -132,6 +137,10 @@ func TestPersistent(t *testing.T) {
checkObj
(
obj
,
nil
,
12
,
InvalidTid
,
GHOST
,
0
,
nil
)
assert
.
Equal
(
ClassOf
(
obj
),
"t.zodb.MyObject"
)
// ClassOf(unregistered-obj)
obj2
:=
&
Unregistered
{}
assert
.
Equal
(
ClassOf
(
obj2
),
`ZODB.Go("lab.nexedi.com/kirr/neo/go/zodb.Unregistered")`
)
// TODO activate - jar has to load, state changes
// TODO activate again - refcnt++
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment