lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi! (for the second time today!)

As I told you before, I have another problem concerning "watch_for_file_changes". It appears to me when it detects several changes simultaneously.

For example, I cut and past files "file1.txt" and "file2.txt" from one directory to another. Then, the callback function in Lua must be called 4 times: "file1.txt" deleted and created and "file2.txt" deleted and created. As expected, the callback function is called 4 times, with the correct actions, but with the same file name for the 4 calls.

It appears that in file_change_thread, the name of the file is written in the buffer 'outbuff'. Then, when using GUI application, the address of this buffer is directly put in a structure (parms->text = text) in call_lua and sent to the message queue. This message is processed later, in the main thread of the GUI application, by the WndProc callback you created in wutils.c. However, meanwhile, the thread of file_change_thread keeps on processing the next changes detected simultaneously in the directory, and use the same buffer to write the name. So, when the GUI message queue system catches the first message and processes it, the WndProc callback obtains the last name written in the buffer by the file_change_thread thread, and not the name of the file corresponding to the action, which is a bit hazardous.

To fix it, for now, I think I'll make the call_lua function allocate a new buffer and copy the content of 'text' and send the copy with the message. Then, in the WndProc callback, I'll free the memory of the 'text' field of the LuaCallParms structure, after use.

I think it should work, and it will be my fix for now. But I'm sure a more elegant solution (and using less memory allocations) can be found, so I watch for your feedback.

Thank you,


Alexandre Rion
Fuel and Fire Department (MEYGU)
EADS / Airbus Military