GNU bug report logs -
#22737
25.1; Finalizer should be optional in dynamic modules
Previous Next
Reported by: Jess Balint <jbalint <at> gmail.com>
Date: Thu, 18 Feb 2016 21:58:02 UTC
Severity: normal
Tags: notabug, wontfix
Found in version 25.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #23 received at 22737 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Fri, Feb 26, 2016 at 12:36 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> > Date: Fri, 26 Feb 2016 10:17:26 -0600
> > From: Jess Balint <jbalint <at> gmail.com>
> > Cc: 22737 <at> debbugs.gnu.org
> >
> > Situation #1 - globals:
> >
> > I have pointers to data that are global (not on the heap). I return
> these pointers from module functions so that
> > they may be used as parameters to other module function calls. These
> pointers should *never* be freed. In
> > this case I need to supply a no-op finalizer when creating the user
> pointer.
> >
> > Situation #2 - manual memory management:
> >
> > I have heap-allocated structures whose memory should not be managed by
> Emacs. I may return pointers to
> > this data one or many times from module calls. The data should be freed
> only when explicitly requested. I may
> > return many user pointers to the same heap-allocated structure. Even
> when all these are freed by Emacs, I
> > still retain a pointer in my module which may be returned in a future
> module call. Again, I'm required to supply
> > a no-op finalizer when creating these user pointers.
>
> What will happen if such objects are exposed to Lisp, copied or
> assigned to other Lisp variables, etc.? Won't this cause all kinds of
> trouble, like modifying one such object will magically modify several
> others, which share its storage?
>
This is how C code works. If you return a pointer from a function, you may
have to free that pointer yourself or you may not. You may get the same
pointer back from multiple calls to the same function. If you use the
pointer after it's been freed, it's your problem. You need to agree with
the owner of the pointer how the memory is to be managed. With pointers,
modifications to the underlying data are visible by all who have a pointer
to the data. I wouldn't call this "magically modifying others".
Jess
[Message part 2 (text/html, inline)]
This bug report was last modified 5 years and 316 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.