Subject: Re: bug#3468: drag and drop text

From: Eli Zaretskii <[email-masked]>
Date: Sat, 05 Oct 2024 15:30:45 +0300

> Date: Sat, 5 Oct 2024 14:07:01 +0200
> Cc: [email-masked]
> From: Cecilio Pardo <[email-masked]>
> 
> On 05/10/2024 13:07, Eli Zaretskii wrote:
> 
> >> There is no malloc/strdup.
> > 
> > Well, there are still 2 calls to malloc in w32_createwindow.  Any
> > reasons not to call xmalloc instead?  Can w32_createwindow be called
> > before we call init_heap?
> 
> [...]
> 
> > Do we ever have to free the two memory chunks we allocate here?  Like
> > when the window is disposed of?
> 
> They are freed in w32_drop_target_Release, which is called internally 
> when we call RevokeDragDrop while handling the WW_EMACS_DESTROYWINDOW on 
> w32_wnd_proc.
> 
> As this runs on the input thread, I used malloc/free instead of 
> xmalloc/xfree.  I could send a message to handle on w32_read_socket and 
> then use xmalloc.

It's okay to use malloc/free in this case, but we must check the
return value of malloc to not be NULL.

> > This function should call block_input at entry and unblock_input
> > before it exits, because we must make sure all the GlobalLock calls
> > are paired with GlobalUnlock and GlobalFree, while functions we call
> > here, process_dropfiles etc., all cons Lisp object, and therefore
> > could potentially QUIT, which throws to top-level.
> 
> The function (w32_process_dnd_data) is called from within the 
> block_input/unblock_input on w32_read_socket.

Ah, okay.

> Should I add its own calls for clarity? Maybe just a comment?

Yes, please.