public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
From: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
To: cygwin-developers@cygwin.com
Subject: Re: About the dll search algorithm of dlopen (patch-r3)
Date: Thu, 01 Sep 2016 08:58:00 -0000	[thread overview]
Message-ID: <769b023d-1e44-28ed-58d1-77c2ee0ef71a@ssi-schaefer.com> (raw)
In-Reply-To: <20160826111824.GQ9783@calimero.vinschen.de>

Hi Corinna,

On 08/26/2016 01:18 PM, Corinna Vinschen wrote:
> On Aug 26 12:59, Corinna Vinschen wrote:
>> On Aug 25 19:48, Michael Haubenwallner wrote:
>>> Using tmp_pathbuf now, wrapped behind some trivial allocator - which
>>> might fit better somewhere else than to dlfcn.cc?
>>>
>>> BTW: Is it really intended for tmp_pathbuf to have a single active
>>> instance (per thread) at a time?
>>
>> Well, yes.  tmp_pathbuf is meant to be initialized on function entry
>> (more or less, depends).  It's supposed to exist only once per frame.
>> When the frame goes out of scope, the tmp_pathbuf usage counter is
>> restored to the values of the parent frame.
>>
>>> +   ATTENTION: Requesting memory from an instance of tmp_pathbuf breaks
>>> +   when another instance on a newer stack frame has provided memory. */
>>
>> I don't understand this comment, though.  tmp_pathbuf can be used
>> multiple times in the same thread stackm see other Cygwin functions.
>> What you can't do is to call a function, instantiate tmp_pathbuf,
>> allocate memory in the called function, and then use it in the caller.
>> Well, you *can* do that, but if you do this more than once, the same
>> memory region is reused.
>> That's the whole idea of tmp_pathbuf.
>> Temporary per-thread memory for the current frame and it's child frames
>> is allocated.  If a deeper frame using tmp_pathbuf goes out of scope,
>> the memory is not free'd, but recycled next time temporary memory is
>> needed.  The buffers are either 32K or 64K to matches the maximum long
>> path length.  They are now used for any purpose where larger temporary
>> per-thread memory is needed, but providing temporary long path buffers
>> without killing the stack was their original purposes.
> 
> So I also don't quite understand splitting off tmp_pathbuf_allocator.

Sorry, 've expected to have provided enough reasoning here:
https://cygwin.com/ml/cygwin-developers/2016-08/msg00016.html

Actually it is vstrlist doing the alloc+free, and I do expect vstrlist
to be useful even in scenarios where it does not work to ignore it's
free calls, but requires the allocator to fully maintain the alloc'ed
regions to allow for free'd regions to become reused.
And as I've stumbled over 3 different memory providers already (malloc,
cmalloc, tmp_pathbuf), I don't think vstrlist should know anything
about tmp_pathbuf at all - otherwise it should be named tmp_vstrlist.

Same stands for pathfinder, which needs the allocator interface reference
only for construction of the embedded vstrlist that holds the searchdirs.

> Why didn't you just include a tmp_pathbuf member into class pathfinder,
> kind of like this:
> 
>   /* pathfinder.h */
>   class pathfinder
>   {
>     tmp_pathbuf tp;
>     [...]
>   };
> 
>   /* dlfcn.cc */
>   get_full_path_of_dll()
>   {
>     pathfinder finder ();	/* Has a tmp_pathbuf member */
> 
>     [...]
>     finder.add_basename (basename);
>     [...]
>     finder.add_searchdir (dir, ...);
> 
> 
>     return true;		/* finder goes out of scope, so
> 				   its tmp_pathbuf goes out of scope
> 				   so tmp_pathbuf::~tmp_pathbuf is
> 				   called and all is well. */
>   }

Well, as one stackframe better uses one _single_ instance of tmp_pathbuf,
I prefer to be explicit about this and have pathfinder+vstrlist take a
tmp_pathbuf _reference_:
A member instance would be hidden to some degree, and thus will ask for
trouble in the long run, as it would not be obvious to developers in the
future that this stackframe already _does_ have that single instance and
one should not add (another) one.

In hope to provide graspable thoughts,
/haubi/

  parent reply	other threads:[~2016-09-01  8:58 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-01  6:39 About the dll search algorithm of dlopen Michael Haubenwallner
2016-06-01 11:09 ` Corinna Vinschen
2016-06-01 14:25   ` Michael Haubenwallner
2016-06-01 20:18     ` Corinna Vinschen
2016-06-01 23:29       ` Yaakov Selkowitz
2016-08-19 16:37       ` Michael Haubenwallner
2016-08-19 16:39         ` Michael Haubenwallner
2016-08-20 19:32           ` Corinna Vinschen
2016-08-22 12:15             ` Michael Haubenwallner
2016-08-22 12:48               ` Peter Rosin
2016-08-22 13:01                 ` Michael Haubenwallner
2016-08-22 16:02               ` About the dll search algorithm of dlopen (patch-r2) Michael Haubenwallner
2016-08-22 18:37                 ` Corinna Vinschen
2016-08-23  8:16                   ` Corinna Vinschen
2016-08-25 17:48                   ` About the dll search algorithm of dlopen (patch-r3) Michael Haubenwallner
2016-08-26 10:59                     ` Corinna Vinschen
2016-08-26 11:18                       ` Corinna Vinschen
2016-08-26 11:49                         ` Corinna Vinschen
2016-08-29 16:50                           ` Michael Haubenwallner
2016-08-30 14:51                             ` Corinna Vinschen
2016-08-30 15:57                               ` Michael Haubenwallner
2016-08-31 18:48                                 ` Corinna Vinschen
2016-09-01  8:58                         ` Michael Haubenwallner [this message]
2016-08-26 14:08                       ` Michael Haubenwallner
2016-08-30 13:26                         ` Corinna Vinschen
2016-08-26 12:04                     ` Corinna Vinschen
2016-08-29  9:24                       ` Michael Haubenwallner
2016-08-30 13:35                         ` Corinna Vinschen
2016-08-30 16:41                           ` Michael Haubenwallner
2016-08-31 18:43                             ` Corinna Vinschen
2016-08-22 18:49               ` About the dll search algorithm of dlopen Corinna Vinschen
2016-08-23  8:55                 ` Michael Haubenwallner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=769b023d-1e44-28ed-58d1-77c2ee0ef71a@ssi-schaefer.com \
    --to=michael.haubenwallner@ssi-schaefer.com \
    --cc=cygwin-developers@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).