Commit e0063782 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 2d54cad5
// Copyright (C) 2018-2020 Nexedi SA and Contributors.
// Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Package btree provides B⁺ Trees for ZODB.
......@@ -45,7 +45,7 @@ import (
"reflect"
"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.
......@@ -69,9 +69,9 @@ func (l *lengthState) PyGetState() interface{} {
// PySetState implements zodb.PyStateful.
func (l *lengthState) PySetState(pystate interface{}) (err error) {
v, ok := pickletools.Xint64(pystate)
if !ok {
return fmt.Errorf("state must be int; got %T", pystate)
v, err := pickle.AsInt64(pystate)
if err != nil {
return fmt.Errorf("state: %s", err)
}
l.value = int(v)
......
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
......@@ -26,7 +26,6 @@ import (
pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr"
"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.
......@@ -493,9 +492,9 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
xk := t[2*i]
v := t[2*i+1]
k, ok := pickletools.Xint64(xk)
if !ok {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk)
k, err := pickle.AsInt64(xk)
if err != nil {
return fmt.Errorf("data: [%d]: key: %s", i, err)
}
kk := KEY(k)
......
......@@ -3,7 +3,7 @@
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
......@@ -28,7 +28,6 @@ import (
pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr"
"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.
......@@ -495,9 +494,9 @@ func (b *iobucketState) PySetState(pystate interface{}) (err error) {
xk := t[2*i]
v := t[2*i+1]
k, ok := pickletools.Xint64(xk)
if !ok {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk)
k, err := pickle.AsInt64(xk)
if err != nil {
return fmt.Errorf("data: [%d]: key: %s", i, err)
}
kk := int32(k)
......
......@@ -3,7 +3,7 @@
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
......@@ -28,7 +28,6 @@ import (
pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr"
"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.
......@@ -495,9 +494,9 @@ func (b *lobucketState) PySetState(pystate interface{}) (err error) {
xk := t[2*i]
v := t[2*i+1]
k, ok := pickletools.Xint64(xk)
if !ok {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk)
k, err := pickle.AsInt64(xk)
if err != nil {
return fmt.Errorf("data: [%d]: key: %s", i, err)
}
kk := int64(k)
......
// Copyright (C) 2017-2019 Nexedi SA and Contributors.
// Copyright (C) 2017-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -25,27 +25,10 @@ package pickletools
import (
"encoding/binary"
"fmt"
"math/big"
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.
func Xstrbytes(x interface{}) (string, error) {
var s string
......
// Copyright (C) 2017-2019 Nexedi SA and Contributors.
// Copyright (C) 2017-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -36,7 +36,6 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb/storage/fs1/fsb"
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/xbufio"
......@@ -229,7 +228,6 @@ func LoadIndex(r io.Reader) (fsi *Index, err error) {
}
}()
var ok bool
var xtopPos, xv interface{}
xr := xbufio.NewReader(r)
......@@ -241,9 +239,9 @@ func LoadIndex(r io.Reader) (fsi *Index, err error) {
if err != nil {
return nil, err
}
topPos, ok := pickletools.Xint64(xtopPos)
if !ok {
return nil, fmt.Errorf("topPos is %T:%v (expected int64)", xtopPos, xtopPos)
topPos, err := pickle.AsInt64(xtopPos)
if err != nil {
return nil, fmt.Errorf("topPos: %s", err)
}
fsi = IndexNew()
......
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -132,13 +132,13 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) {
if len(tpkt) != 4 {
return m, derrf("len(msg-tuple)=%d; expected 4", len(tpkt))
}
m.msgid, ok = pickletools.Xint64(tpkt[0])
if !ok {
return m, derrf("msgid: got %T; expected int", tpkt[0])
m.msgid, err = pickle.AsInt64(tpkt[0])
if err != nil {
return m, derrf("msgid: %s", err)
}
flags, ok := pickletools.Xint64(tpkt[1])
if !ok {
flags, err := pickle.AsInt64(tpkt[1])
if err != nil {
bflags, ok := tpkt[1].(bool)
if !ok {
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