Commit e64e2aa5 authored by Kirill Smelkov's avatar Kirill Smelkov

go/*: Switch pickletools.Xint64 to ogórek.AsInt64

ogórek.AsInt64 was added in https://github.com/kisielk/og-rek/commit/010fbd2e
with functionality similar to what we had in pickletools.Xint64 before.
parent 8e028058
// Copyright (C) 2018-2020 Nexedi SA and Contributors. // Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// Package btree provides B⁺ Trees for ZODB. // Package btree provides B⁺ Trees for ZODB.
...@@ -45,7 +45,7 @@ import ( ...@@ -45,7 +45,7 @@ import (
"reflect" "reflect"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools" pickle "github.com/kisielk/og-rek"
) )
// Length is equivalent of BTrees.Length.Length in BTree/py. // Length is equivalent of BTrees.Length.Length in BTree/py.
...@@ -69,9 +69,9 @@ func (l *lengthState) PyGetState() interface{} { ...@@ -69,9 +69,9 @@ func (l *lengthState) PyGetState() interface{} {
// PySetState implements zodb.PyStateful. // PySetState implements zodb.PyStateful.
func (l *lengthState) PySetState(pystate interface{}) (err error) { func (l *lengthState) PySetState(pystate interface{}) (err error) {
v, ok := pickletools.Xint64(pystate) v, err := pickle.AsInt64(pystate)
if !ok { if err != nil {
return fmt.Errorf("state must be int; got %T", pystate) return fmt.Errorf("state: %s", err)
} }
l.value = int(v) l.value = int(v)
......
// Copyright (c) 2001, 2002 Zope Foundation and Contributors. // Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved. // All Rights Reserved.
// //
// Copyright (C) 2018-2021 Nexedi SA and Contributors. // Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This software is subject to the provisions of the Zope Public License, // This software is subject to the provisions of the Zope Public License,
...@@ -26,7 +26,6 @@ import ( ...@@ -26,7 +26,6 @@ import (
pickle "github.com/kisielk/og-rek" pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
) )
// Node represents a tree node - either BTree or Bucket. // Node represents a tree node - either BTree or Bucket.
...@@ -493,9 +492,9 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) { ...@@ -493,9 +492,9 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
xk := t[2*i] xk := t[2*i]
v := t[2*i+1] v := t[2*i+1]
k, ok := pickletools.Xint64(xk) k, err := pickle.AsInt64(xk)
if !ok { if err != nil {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk) return fmt.Errorf("data: [%d]: key: %s", i, err)
} }
kk := KEY(k) kk := KEY(k)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// Copyright (c) 2001, 2002 Zope Foundation and Contributors. // Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved. // All Rights Reserved.
// //
// Copyright (C) 2018-2021 Nexedi SA and Contributors. // Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This software is subject to the provisions of the Zope Public License, // This software is subject to the provisions of the Zope Public License,
...@@ -28,7 +28,6 @@ import ( ...@@ -28,7 +28,6 @@ import (
pickle "github.com/kisielk/og-rek" pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
) )
// IONode represents a tree node - either IOBTree or IOBucket. // IONode represents a tree node - either IOBTree or IOBucket.
...@@ -495,9 +494,9 @@ func (b *iobucketState) PySetState(pystate interface{}) (err error) { ...@@ -495,9 +494,9 @@ func (b *iobucketState) PySetState(pystate interface{}) (err error) {
xk := t[2*i] xk := t[2*i]
v := t[2*i+1] v := t[2*i+1]
k, ok := pickletools.Xint64(xk) k, err := pickle.AsInt64(xk)
if !ok { if err != nil {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk) return fmt.Errorf("data: [%d]: key: %s", i, err)
} }
kk := int32(k) kk := int32(k)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// Copyright (c) 2001, 2002 Zope Foundation and Contributors. // Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved. // All Rights Reserved.
// //
// Copyright (C) 2018-2021 Nexedi SA and Contributors. // Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This software is subject to the provisions of the Zope Public License, // This software is subject to the provisions of the Zope Public License,
...@@ -28,7 +28,6 @@ import ( ...@@ -28,7 +28,6 @@ import (
pickle "github.com/kisielk/og-rek" pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
) )
// LONode represents a tree node - either LOBTree or LOBucket. // LONode represents a tree node - either LOBTree or LOBucket.
...@@ -495,9 +494,9 @@ func (b *lobucketState) PySetState(pystate interface{}) (err error) { ...@@ -495,9 +494,9 @@ func (b *lobucketState) PySetState(pystate interface{}) (err error) {
xk := t[2*i] xk := t[2*i]
v := t[2*i+1] v := t[2*i+1]
k, ok := pickletools.Xint64(xk) k, err := pickle.AsInt64(xk)
if !ok { if err != nil {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk) return fmt.Errorf("data: [%d]: key: %s", i, err)
} }
kk := int64(k) kk := int64(k)
......
// Copyright (C) 2017-2019 Nexedi SA and Contributors. // Copyright (C) 2017-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -25,27 +25,10 @@ package pickletools ...@@ -25,27 +25,10 @@ package pickletools
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"math/big"
pickle "github.com/kisielk/og-rek" pickle "github.com/kisielk/og-rek"
) )
// Xint64 tries to convert unpickled value to int64.
//
// (ogórek decodes python long as big.Int)
func Xint64(xv interface{}) (v int64, ok bool) {
switch v := xv.(type) {
case int64:
return v, true
case *big.Int:
if v.IsInt64() {
return v.Int64(), true
}
}
return 0, false
}
// Xstrbytes verifies and extacts str|bytes from unpickled value. // Xstrbytes verifies and extacts str|bytes from unpickled value.
func Xstrbytes(x interface{}) (string, error) { func Xstrbytes(x interface{}) (string, error) {
var s string var s string
......
// Copyright (C) 2017-2019 Nexedi SA and Contributors. // Copyright (C) 2017-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -36,7 +36,6 @@ import ( ...@@ -36,7 +36,6 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb/storage/fs1/fsb" "lab.nexedi.com/kirr/neo/go/zodb/storage/fs1/fsb"
pickle "github.com/kisielk/og-rek" pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
"lab.nexedi.com/kirr/go123/mem" "lab.nexedi.com/kirr/go123/mem"
"lab.nexedi.com/kirr/go123/xbufio" "lab.nexedi.com/kirr/go123/xbufio"
...@@ -229,7 +228,6 @@ func LoadIndex(r io.Reader) (fsi *Index, err error) { ...@@ -229,7 +228,6 @@ func LoadIndex(r io.Reader) (fsi *Index, err error) {
} }
}() }()
var ok bool
var xtopPos, xv interface{} var xtopPos, xv interface{}
xr := xbufio.NewReader(r) xr := xbufio.NewReader(r)
...@@ -241,9 +239,9 @@ func LoadIndex(r io.Reader) (fsi *Index, err error) { ...@@ -241,9 +239,9 @@ func LoadIndex(r io.Reader) (fsi *Index, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
topPos, ok := pickletools.Xint64(xtopPos) topPos, err := pickle.AsInt64(xtopPos)
if !ok { if err != nil {
return nil, fmt.Errorf("topPos is %T:%v (expected int64)", xtopPos, xtopPos) return nil, fmt.Errorf("topPos: %s", err)
} }
fsi = IndexNew() fsi = IndexNew()
......
// Copyright (C) 2018-2021 Nexedi SA and Contributors. // Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -132,13 +132,13 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) { ...@@ -132,13 +132,13 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) {
if len(tpkt) != 4 { if len(tpkt) != 4 {
return m, derrf("len(msg-tuple)=%d; expected 4", len(tpkt)) return m, derrf("len(msg-tuple)=%d; expected 4", len(tpkt))
} }
m.msgid, ok = pickletools.Xint64(tpkt[0]) m.msgid, err = pickle.AsInt64(tpkt[0])
if !ok { if err != nil {
return m, derrf("msgid: got %T; expected int", tpkt[0]) return m, derrf("msgid: %s", err)
} }
flags, ok := pickletools.Xint64(tpkt[1]) flags, err := pickle.AsInt64(tpkt[1])
if !ok { if err != nil {
bflags, ok := tpkt[1].(bool) bflags, ok := tpkt[1].(bool)
if !ok { if !ok {
return m, derrf("flags: got %T; expected int|bool", tpkt[1]) return m, derrf("flags: got %T; expected int|bool", tpkt[1])
......
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