This repeats the same code several times. Please move it to a
function.
Instead of guessing whether :lcd or :cd was used it would be better to
check the actual situation. Probably by checking the value of
curwin->w_localdir.
--
How To Keep A Healthy Level Of Insanity:
9. As often as possible, skip rather than walk.
/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
I took your suggestions and additionally moved the directory restore
calls into the ((un)?load|wipe)_dummy_buffer functions so that it is
easier to maintain in the future, if these functions are used
elsewhere. The root cause of the problem was that many of the
functions from buffer.c called by these dummy_buffer functions were
using the DO_AUTOCHDIR macro, though presumably an appropriately
defined autocmd would do the same thing, so whenever we touch the
dummy buffer we need to restore the directory. Presumably creating a
"dummy buffer" should never have lasting effects on the current
directory!
Updated patch attached to fix that 'autochdir' causes :vimgrep to
fail, based on 7.3.421. I did have one more question: I noticed that
the pre-existing code dynamically allocates memory of static size
MAXPATHL for both dirname_start and dirname_now. I have kept this and
done the same thing for the restore_start_dir function I added, but I
wonder, is there a reason the path string cannot be stack-allocated
instead? Is it to limit stack size or something, since MAXPATHL can be
somewhat large?
--
Ben
> Thanks, everyone. The curwin->w_localdir variable was exactly what I
> was looking for, and the tertiary operator makes it a little clearer
> what is going on in the directory restore code.
>
> I took your suggestions and additionally moved the directory restore
> calls into the ((un)?load|wipe)_dummy_buffer functions so that it is
> easier to maintain in the future, if these functions are used
> elsewhere. The root cause of the problem was that many of the
> functions from buffer.c called by these dummy_buffer functions were
> using the DO_AUTOCHDIR macro, though presumably an appropriately
> defined autocmd would do the same thing, so whenever we touch the
> dummy buffer we need to restore the directory. Presumably creating a
> "dummy buffer" should never have lasting effects on the current
> directory!
Thanks, I'll put the patch in the todo list.
> Updated patch attached to fix that 'autochdir' causes :vimgrep to
> fail, based on 7.3.421. I did have one more question: I noticed that
> the pre-existing code dynamically allocates memory of static size
> MAXPATHL for both dirname_start and dirname_now. I have kept this and
> done the same thing for the restore_start_dir function I added, but I
> wonder, is there a reason the path string cannot be stack-allocated
> instead? Is it to limit stack size or something, since MAXPATHL can be
> somewhat large?
As a rule of thumb: A function should not put more than about 1000 bytes
on the stack. Les if it used recursively. That's because we can
gracefully handle out-of-memory allocations but not out-of-stack errors,
these cause a crash.
--
Apparently, 1 in 5 people in the world are Chinese. And there are 5
people in my family, so it must be one of them. It's either my mum
or my dad. Or my older brother Colin. Or my younger brother
Ho-Cha-Chu. But I think it's Colin.
Yes, thanks for the clarification. You said earlier:
> As a rule of thumb: A function should not put more than about 1000 bytes
> on the stack. Les if it used recursively. That's because we can
> gracefully handle out-of-memory allocations but not out-of-stack errors,
> these cause a crash.
As I mentioned, the patch uses the existing method of dynamically allocating MAXPATHL bytes instead of putting it on the stack; I decided it was probably done for a reason, I just wasn't sure of the reason. I was asking only for the sake of better understanding of the Vim code. This isn't holding up the patch, is it?
I just saw patch 509, never mind my premature question :-)