Skip to content

ARC, finalizer, allow rebinding the same function multiple times #13112

Closed
@StefanSalewski

Description

@StefanSalewski

https://forum.nim-lang.org/t/5734#35917

I would assume that it should be possible, if not we may have to use

https://forum.nim-lang.org/t/5786

but that would call for much rewriting of course.

$ nim c --gc:arc t0.nim 
/home/stefan/.nimble/pkgs/gintro-0.6.1/gintro/glib.nim(969, 6) Error: cannot bind another 'gBoxedFreeGBytes' to: Bytes:ObjectType; previous declaration was here: /home/stefan/.nimble/pkgs/gintro-0.6.1/gintro/glib.nim(897, 6)

There is only one single

$ grep "proc gBoxedFreeGBytes" ~/.nimble/pkgs/gintro-0.6.1/gintro/*
/home/stefan/.nimble/pkgs/gintro-0.6.1/gintro/glib.nim:proc gBoxedFreeGBytes*(self: Bytes) =

But there is

proc newBytesTake*(data: seq[uint8] | string): Bytes =
  let size = uint64(data.len)
  new(result, gBoxedFreeGBytes)
  result.impl = g_bytes_new_take(unsafeaddr(data[0]), size)

proc newBytesFromBytes*(self: Bytes; offset: uint64; length: uint64): Bytes =
  new(result, gBoxedFreeGBytes)
  result.impl = g_bytes_new_from_bytes(cast[ptr Bytes00](self.impl), offset, length)

proc g_bytes_ref(self: ptr Bytes00): ptr Bytes00 {.
    importc, libprag.}

proc `ref`*(self: Bytes): Bytes =
  new(result, gBoxedFreeGBytes)
  result.impl = g_bytes_ref(cast[ptr Bytes00](self.impl))

proc newBytes*(data: seq[uint8] | string): Bytes =
  let size = uint64(data.len)
  new(result, gBoxedFreeGBytes)
  result.impl = g_bytes_new(unsafeaddr(data[0]), size)

proc initBytes*[T](result: var T; data: seq[uint8] | string) =
  let size = uint64(data.len)
  assert(result is Bytes)
  new(result, gBoxedFreeGBytes)
  result.impl = g_bytes_new(unsafeaddr(data[0]), size)

But yes, we may be able to rewrite that -- for only one newBytes proc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions