Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to destructors #700

Open
9 tasks
ringabout opened this issue Apr 23, 2021 · 2 comments
Open
9 tasks

switch to destructors #700

ringabout opened this issue Apr 23, 2021 · 2 comments

Comments

@ringabout
Copy link
Collaborator

ringabout commented Apr 23, 2021

legacy modules which are too important to change(need more think) or they should be deferred
maybe we a new IO modules

  • File Handle
  • Socket Handle
  • Streams

Less important modules
provide a wrapper for them with destructors

New modules
easy to add

  • TempFile

Unstable modules
can we remove deinit**** procs and use destructors?

  • sharedlists
  • sharedtables
@timotheecour timotheecour changed the title switch to destrutors switch to destructors Apr 23, 2021
@timotheecour
Copy link
Owner

timotheecour commented Apr 23, 2021

also:

option 1

a wrapper object eg:

type FileObj* = object
  handle: File
proc openFile*(path: string): FileObj = FileObj(handle: open(path))
proc `=destroy`(a: var FileObj) =
  if a.handle != nil: close(a.handle)
  • we also should allow UniquePtr/ShadredPtr to pass ownership of those wrapper objects around and make sure it works in various settings
  • and we should make sure this has 0 impact on performance compared to using handles directly and doing manual management of init+deinit (eg open close)

option 2

extend the rules to allow destructors for types other than objects; maybe only allowing it for distinct types?

I haven't thought of implications of this though, this potentially cannot work

@ringabout
Copy link
Collaborator Author

Latest experiment is here: nim-lang#18640

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants