Skip to content

Commit

Permalink
Env.FD: use var instead of new() for clarity
Browse files Browse the repository at this point in the history
Change the C.mdb_filehandle_t declaration to use var instead of new() to
clarify that we are not retaining a pointer to anything.

This is related to #28, but in this case no issue, because we are not
assiging a pointer to Go allocated memory to a C value.

Functionally this does not change anything. Go decides if values are
stack allocated or heap allocated based on if they escape, not based on
the syntax.
  • Loading branch information
wojas committed Dec 7, 2023
1 parent d6e8388 commit b408c5f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lmdb/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ func (env *Env) FD() (uintptr, error) {
// to avoid constant value overflow errors at compile time.
const fdInvalid = ^uintptr(0)

mf := new(C.mdb_filehandle_t)
ret := C.mdb_env_get_fd(env._env, mf)
var mf C.mdb_filehandle_t
ret := C.mdb_env_get_fd(env._env, &mf)
err := operrno("mdb_env_get_fd", ret)
if err != nil {
return 0, err
}
fd := uintptr(*mf)
fd := uintptr(mf)

if fd == fdInvalid {
return 0, errNotOpen
Expand Down

0 comments on commit b408c5f

Please sign in to comment.