Skip to content

Commit

Permalink
change type of txn.val from *C.MDBX_val to C.MDBX_val
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Miheev committed Jun 12, 2024
1 parent 6f9a27c commit a86986f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
22 changes: 11 additions & 11 deletions mdbx/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
}
if err != nil {
*c.txn.key = C.MDBX_val{}
*c.txn.val = C.MDBX_val{}
c.txn.val = C.MDBX_val{}
return nil, nil, err
}

Expand All @@ -174,12 +174,12 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
key = castToBytes(c.txn.key)
}
}
val = castToBytes(c.txn.val)
val = castToBytes(&c.txn.val)

// Clear transaction storage record storage area for future use and to
// prevent dangling references.
*c.txn.key = C.MDBX_val{}
*c.txn.val = C.MDBX_val{}
c.txn.val = C.MDBX_val{}

return key, val, nil
}
Expand All @@ -189,7 +189,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
//
// See mdb_cursor_get.
func (c *Cursor) getVal0(op uint) error {
ret := C.mdbx_cursor_get(c._c, c.txn.key, c.txn.val, C.MDBX_cursor_op(op))
ret := C.mdbx_cursor_get(c._c, c.txn.key, &c.txn.val, C.MDBX_cursor_op(op))
return operrno("mdbx_cursor_get", ret)
}

Expand All @@ -206,7 +206,7 @@ func (c *Cursor) getVal1(setkey []byte, op uint) error {
c._c,
k, C.size_t(len(setkey)),
c.txn.key,
c.txn.val,
&c.txn.val,
C.MDBX_cursor_op(op),
)
return operrno("mdbx_cursor_get", ret)
Expand All @@ -220,7 +220,7 @@ func (c *Cursor) getVal01(setval []byte, op uint) error {
c._c,
v, C.size_t(len(setval)),
c.txn.key,
c.txn.val,
&c.txn.val,
C.MDBX_cursor_op(op),
)
return operrno("mdbx_cursor_get", ret)
Expand All @@ -242,7 +242,7 @@ func (c *Cursor) getVal2(setkey, setval []byte, op uint) error {
c._c,
k, C.size_t(len(setkey)),
v, C.size_t(len(setval)),
c.txn.key, c.txn.val,
c.txn.key, &c.txn.val,
C.MDBX_cursor_op(op),
)
return operrno("mdbx_cursor_get", ret)
Expand Down Expand Up @@ -280,16 +280,16 @@ func (c *Cursor) PutReserve(key []byte, n int, flags uint) ([]byte, error) {
ret := C.mdbxgo_cursor_put1(
c._c,
k, C.size_t(len(key)),
c.txn.val,
&c.txn.val,
C.MDBX_put_flags_t(flags|C.MDBX_RESERVE),
)
err := operrno("mdbx_cursor_put", ret)
if err != nil {
*c.txn.val = C.MDBX_val{}
c.txn.val = C.MDBX_val{}
return nil, err
}
b := castToBytes(c.txn.val)
*c.txn.val = C.MDBX_val{}
b := castToBytes(&c.txn.val)
c.txn.val = C.MDBX_val{}
return b, nil
}

Expand Down
29 changes: 14 additions & 15 deletions mdbx/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ const (
//
// See MDBX_txn.
type Txn struct {
env *Env
_txn *C.MDBX_txn
key *C.MDBX_val
valNP C.MDBX_val
val *C.MDBX_val
env *Env
_txn *C.MDBX_txn
key *C.MDBX_val
val C.MDBX_val

errLogf func(format string, v ...interface{})

Expand Down Expand Up @@ -94,14 +93,14 @@ func beginTxn(env *Env, parent *Txn, flags uint) (*Txn, error) {
// In a write Txn we can use the shared, C-allocated key and value
// allocated by env, and freed when it is closed.
txn.key = env.ckey
txn.val = env.cval
txn.val = *env.cval
} else {
// It is not easy to share C.MDBX_val values in this scenario unless
// there is a synchronized pool involved, which will increase
// overhead. Further, allocating these values with C will add
// overhead both here and when the values are freed.
txn.key = new(C.MDBX_val)
txn.val = new(C.MDBX_val)
txn.val = C.MDBX_val{}
}
} else {
// Because parent Txn objects cannot be used while a sub-Txn is active
Expand Down Expand Up @@ -594,15 +593,15 @@ func (txn *Txn) Get(dbi DBI, key []byte) ([]byte, error) {
ret := C.mdbxgo_get(
txn._txn, C.MDBX_dbi(dbi),
k, C.size_t(len(key)),
&txn.valNP,
&txn.val,
)
err := operrno("mdbx_get", ret)
if err != nil {
txn.valNP.iov_base, txn.valNP.iov_len = nil, 0
txn.val = C.MDBX_val{}
return nil, err
}
b := castToBytes(&txn.valNP)
txn.valNP.iov_base, txn.valNP.iov_len = nil, 0
b := castToBytes(&txn.val)
txn.val = C.MDBX_val{}
return b, nil
}

Expand Down Expand Up @@ -638,16 +637,16 @@ func (txn *Txn) PutReserve(dbi DBI, key []byte, n int, flags uint) ([]byte, erro
ret := C.mdbxgo_put1(
txn._txn, C.MDBX_dbi(dbi),
k, C.size_t(len(key)),
txn.val,
&txn.val,
C.MDBX_put_flags_t(flags|C.MDBX_RESERVE),
)
err := operrno("mdbx_put", ret)
if err != nil {
*txn.val = C.MDBX_val{}
txn.val = C.MDBX_val{}
return nil, err
}
b := castToBytes(txn.val)
*txn.val = C.MDBX_val{}
b := castToBytes(&txn.val)
txn.val = C.MDBX_val{}
return b, nil
}

Expand Down

0 comments on commit a86986f

Please sign in to comment.