|
| From: | anonymous |
| Subject: | [Octave-bug-tracker] [bug #54571] gethostname must not be called from within DllMain on Win32 systems |
| Date: | Sat, 25 Aug 2018 10:05:08 -0400 (EDT) |
| User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0 |
URL:
<http://savannah.gnu.org/bugs/?54571>
Summary: gethostname must not be called from within DllMain
on Win32 systems
Project: GNU Octave
Submitted by: None
Submitted on: Sat 25 Aug 2018 02:05:06 PM UTC
Category: Libraries
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Other
Status: None
Assigned to: None
Originator Name: Octave user
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: 4.4.1
Operating System: Microsoft Windows
_______________________________________________________
Details:
According to DllMain
<https://docs.microsoft.com/en-us/windows/desktop/dlls/dllmain> there several
restrictions which functions may be called from within DllMain. Especially
LoadLibrary must not be called directly nor indirectly Dynamic-Link Library
Best Practices
<https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-best-practices>.
Although octave is not providing an implementation of DllMain, it will be
generated by the compiler. Any initialized global or static variable of a Dll
outside of a function will be initialized in DllMain.
For example the following definition in oct-hist.cc will actually call
gethostname from within DllMain:
static std::string Vhistory_timestamp_format_string =
default_history_timestamp_format ();
The behaviour of such a call could be undefined because it depends on other
Dll's which might not be initialized properly if their DllMain has not been
called before. So it might work or might not work depending on the load order
of Dll's.
The patch in the attached file fixes this issue at least in case of
gethostname. It simply delays the call to gethostname until main is called.
As a side effect this patch can reduce start-up time of octave depending on OS
version and system configuration.
Without patch:
$ time /usr/local/bin/octave-cli -qf --eval x=pi
x = 3.1416
real 0m20.470s
user 0m0.000s
sys 0m0.031s
With patch:
$ time /usr/local/bin/octave-cli -qf --eval x=pi
x = 3.1416
real 0m0.485s
user 0m0.016s
sys 0m0.015s
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Sat 25 Aug 2018 02:05:06 PM UTC Name: octave-gethostname.patch Size:
2KiB By: None
<http://savannah.gnu.org/bugs/download.php?file_id=44860>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?54571>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
| [Prev in Thread] | Current Thread | [Next in Thread] |