FLTK logo

[master] ef65560 - fix to Fl_Plugin, avoid early driver loading (#1612)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.commit  ]
 
[ Previous Message ] [ Next Message ]

[master] ef65560 - fix to Fl_Plugin, avoid early driver loading (#1612) "Matthias Melcher" 09:32 Sep 24  
 
commit ef65560d4668b48ce9a319888ba84c598e96298d
Author:     Matthias Melcher <github@matthiasm.com>
AuthorDate: Thu Sep 24 11:18:03 2026 +0200
Commit:     GitHub <noreply@github.com>
CommitDate: Thu Sep 24 11:18:03 2026 +0200

    fix to Fl_Plugin, avoid early driver loading (#1612)
    
    * allow static compile time initialization of Fl_Menu_Item arrays
      by moving benign functions out of the system driver
    * allow Fl_Plugin to be used as an internal registry before
      any drivers need to be loaded

 FL/Enumerations.H                              | 14 +++++++++++++-
 FL/platform_types.h                            |  8 +-------
 src/Fl.cxx                                     | 18 ++++++++++++++----
 src/Fl_System_Driver.H                         | 17 +++++++----------
 src/Fl_System_Driver.cxx                       | 20 +-------------------
 src/drivers/Darwin/Fl_Darwin_System_Driver.H   |  6 +-----
 src/drivers/Darwin/Fl_Darwin_System_Driver.cxx | 15 ---------------
 src/drivers/Posix/Fl_Posix_System_Driver.H     |  3 +--
 src/drivers/WinAPI/Fl_WinAPI_System_Driver.H   |  3 +--
 src/fl_string_functions.cxx                    | 10 ++++++++--
 10 files changed, 47 insertions(+), 67 deletions(-)

diff --git FL/Enumerations.H FL/Enumerations.H
index e4fec9a..f724f87 100644
--- FL/Enumerations.H
+++ FL/Enumerations.H
@@ -1,7 +1,7 @@
 //
 // Enumerations for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2025 by Bill Spitzak and others.
+// Copyright 1998-2026 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -515,6 +515,18 @@ enum Fl_Callback_Reason {
                                         // correct for XFree86
 #define FL_SCROLL_LOCK  0x00800000      ///< The scroll lock is on
                                         // correct for XFree86
+
+// To allow compile time initialisation of menus, this must not be moved into the System Driver.
+#if defined(__APPLE__) &&!defined(FLTK_USE_X11)
+#define FL_COMMAND FL_META
+#define FL_CONTROL FL_CTRL
+#else
+#define FL_COMMAND FL_CTRL
+#define FL_CONTROL FL_META
+#endif
+constexpr FL_EXPORT int fl_command_modifier() { return FL_COMMAND; }
+constexpr FL_EXPORT int fl_control_modifier() { return FL_CONTROL; }
+
 // Mouse buttons
 
 #define FL_BUTTON1      0x01000000        ///< Mouse button 1 is pushed (L)
diff --git FL/platform_types.h FL/platform_types.h
index 67656b7..1d49cfd 100644
--- FL/platform_types.h
+++ FL/platform_types.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2023 by Bill Spitzak and others.
+ * Copyright 2016-2026 by Bill Spitzak and others.
  *
  * This library is free software. Distribution and use rights are outlined in
  * the file "COPYING" which should have been included with this file.  If this
@@ -130,12 +130,6 @@ typedef  unsigned __int64 FL_SOCKET;    /* *FIXME* - FL_SOCKET (see above) */
 typedef  int FL_SOCKET;
 # endif
 
-#include <FL/Fl_Export.H>
-extern FL_EXPORT int fl_command_modifier();
-extern FL_EXPORT int fl_control_modifier();
-#  define FL_COMMAND    fl_command_modifier()
-#  define FL_CONTROL    fl_control_modifier()
-
 #endif /* FL_PLATFORM_TYPES_H */
 
 /* This is currently the same for all platforms but may change in the future */
diff --git src/Fl.cxx src/Fl.cxx
index 2dcda67..b684493 100644
--- src/Fl.cxx
+++ src/Fl.cxx
@@ -2621,10 +2621,20 @@ int Fl::system(const char *command) {
 
 // Pointers you can use to change FLTK to another language.
 // Note: Similar pointers are defined in FL/fl_ask.H and src/fl_ask.cxx
-FL_EXPORT const char* fl_local_shift = Fl::system_driver()->shift_name();
-FL_EXPORT const char* fl_local_meta  = Fl::system_driver()->meta_name();
-FL_EXPORT const char* fl_local_alt   = Fl::system_driver()->alt_name();
-FL_EXPORT const char* fl_local_ctrl  = Fl::system_driver()->control_name();
+// Note: To be able to defer creating the driver, we no longer provide virtual
+//    calls into the System driver for key names (since 1.5.0). System Driver
+//    may still override the names when instantiated.
+#if defined(__APPLE__) &&!defined(FLTK_USE_X11)
+FL_EXPORT const char* fl_local_shift = "â?§\\"; // "\xe2\x87\xa7\\"; // U+21E7 (upwards white arrow)
+FL_EXPORT const char* fl_local_meta  = "â??\\"; // "\xe2\x8c\x98\\"; // U+2318 (place of interest sign)
+FL_EXPORT const char* fl_local_alt   = "â?¥\\"; // "\xe2\x8c\xa5\\"; // U+2325 (option key)
+FL_EXPORT const char* fl_local_ctrl  = "â??\\"; // "\xe2\x8c\x83\\"; // U+2303 (up arrowhead)
+#else
+FL_EXPORT const char* fl_local_shift = "Shift";
+FL_EXPORT const char* fl_local_meta  = "Meta";
+FL_EXPORT const char* fl_local_alt   = "Alt";
+FL_EXPORT const char* fl_local_ctrl  = "Ctrl";
+#endif
 
 /**
   Convert Windows commandline arguments to UTF-8.
diff --git src/Fl_System_Driver.H src/Fl_System_Driver.H
index 315b026..e79f02d 100644
--- src/Fl_System_Driver.H
+++ src/Fl_System_Driver.H
@@ -2,7 +2,7 @@
 // A base class for platform specific system calls
 // for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 2010-2022 by Bill Spitzak and others.
+// Copyright 2010-2026 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -78,8 +78,12 @@ public:
 
 public:
   virtual ~Fl_System_Driver();
-  static int command_key;
-  static int control_key;
+
+  // To save initialisation time, don't make these virtual.
+  static const char *shift_name() { return fl_local_shift; }
+  static const char *meta_name() { return fl_local_meta; }
+  static const char *alt_name() { return fl_local_alt; }
+  static const char *control_name() { return fl_local_ctrl; }
 
   // implement if the system adds unwanted program argument(s)
   virtual int single_arg(const char *) { return 0; }
@@ -102,8 +106,6 @@ public:
   virtual int open(const char* /*f*/, int /*oflags*/, int /*pmode*/) {return -1;}
 
   // implement these to support cross-platform string operations
-  virtual char *strdup(const char *) {return NULL;}
-
   // Note: the default implementation ignores the 'binary' argument.
   // Some platforms (notably Windows) may use this argument.
   virtual int open_ext(const char* f, int /*binary*/, int oflags, int pmode) {
@@ -222,11 +224,6 @@ public:
   virtual void open_callback(void (*)(const char *));
   // The default implementation may be enough.
   virtual void gettime(time_t *sec, int *usec);
-  // The default implementation of the next 4 functions may be enough.
-  virtual const char *shift_name() { return "Shift"; }
-  virtual const char *meta_name() { return "Meta"; }
-  virtual const char *alt_name() { return "Alt"; }
-  virtual const char *control_name() { return "Ctrl"; }
   virtual Fl_Sys_Menu_Bar_Driver *sys_menu_bar_driver() { return NULL; }
   virtual void lock_ring() {}
   virtual void unlock_ring() {}
diff --git src/Fl_System_Driver.cxx src/Fl_System_Driver.cxx
index a1ae242..e841dac 100644
--- src/Fl_System_Driver.cxx
+++ src/Fl_System_Driver.cxx
@@ -1,7 +1,7 @@
 //
 // A base class for platform specific system calls.
 //
-// Copyright 1998-2025 by Bill Spitzak and others.
+// Copyright 1998-2026 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -33,26 +33,8 @@
 #include <time.h>
 
 
-int Fl_System_Driver::command_key = 0;
-int Fl_System_Driver::control_key = 0;
-
-
-int fl_command_modifier() {
-  if (!Fl_System_Driver::command_key) Fl::system_driver();
-  return Fl_System_Driver::command_key;
-}
-
-
-int fl_control_modifier() {
-  if (!Fl_System_Driver::control_key) Fl::system_driver();
-  return Fl_System_Driver::control_key;
-}
-
-
 Fl_System_Driver::Fl_System_Driver()
 {
-  command_key = FL_CTRL;
-  control_key = FL_META;
 }
 
 Fl_System_Driver::~Fl_System_Driver()
diff --git src/drivers/Darwin/Fl_Darwin_System_Driver.H src/drivers/Darwin/Fl_Darwin_System_Driver.H
index 7dd0ae6..bef1075 100644
--- src/drivers/Darwin/Fl_Darwin_System_Driver.H
+++ src/drivers/Darwin/Fl_Darwin_System_Driver.H
@@ -2,7 +2,7 @@
 // Definition of Apple Darwin system driver
 // for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 2010-2021 by Bill Spitzak and others.
+// Copyright 2010-2026 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -72,10 +72,6 @@ public:
   void remove_fd(int, int when) FL_OVERRIDE;
   void remove_fd(int) FL_OVERRIDE;
   void open_callback(void (*)(const char *)) FL_OVERRIDE;
-  const char *shift_name() FL_OVERRIDE;
-  const char *meta_name() FL_OVERRIDE;
-  const char *alt_name() FL_OVERRIDE;
-  const char *control_name() FL_OVERRIDE;
   Fl_Sys_Menu_Bar_Driver *sys_menu_bar_driver() FL_OVERRIDE;
   double wait(double time_to_wait) FL_OVERRIDE;
   int ready() FL_OVERRIDE;
diff --git src/drivers/Darwin/Fl_Darwin_System_Driver.cxx src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
index c11a95f..f40d9f1 100644
--- src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
+++ src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
@@ -35,23 +35,8 @@
 #include <sys/stat.h>
 
 
-const char *Fl_Darwin_System_Driver::shift_name() {
-  return "â?§\\"; // "\xe2\x87\xa7\\"; // U+21E7 (upwards white arrow)
-}
-const char *Fl_Darwin_System_Driver::meta_name() {
-  return "â??\\"; // "\xe2\x8c\x98\\"; // U+2318 (place of interest sign)
-}
-const char *Fl_Darwin_System_Driver::alt_name() {
-  return "â?¥\\"; // "\xe2\x8c\xa5\\"; // U+2325 (option key)
-}
-const char *Fl_Darwin_System_Driver::control_name() {
-  return "â??\\"; // "\xe2\x8c\x83\\"; // U+2303 (up arrowhead)
-}
-
 Fl_Darwin_System_Driver::Fl_Darwin_System_Driver() : Fl_Posix_System_Driver() {
   if (fl_mac_os_version == 0) fl_mac_os_version = calc_mac_os_version();
-  command_key = FL_META;
-  control_key = FL_CTRL;
 }
 
 int Fl_Darwin_System_Driver::single_arg(const char *arg) {
diff --git src/drivers/Posix/Fl_Posix_System_Driver.H src/drivers/Posix/Fl_Posix_System_Driver.H
index 8465204..b325bd2 100644
--- src/drivers/Posix/Fl_Posix_System_Driver.H
+++ src/drivers/Posix/Fl_Posix_System_Driver.H
@@ -2,7 +2,7 @@
 // Definition of POSIX system driver
 // for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 2010-2022 by Bill Spitzak and others.
+// Copyright 2010-2026 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -81,7 +81,6 @@ public:
   const char *home_directory_name() FL_OVERRIDE { return ::getenv("HOME"); }
   int dot_file_hidden() FL_OVERRIDE {return 1;}
   void gettime(time_t *sec, int *usec) FL_OVERRIDE;
-  char* strdup(const char *s) FL_OVERRIDE {return ::strdup(s);}
   int close_fd(int fd) FL_OVERRIDE;
 #if defined(HAVE_PTHREAD)
   void lock_ring() FL_OVERRIDE;
diff --git src/drivers/WinAPI/Fl_WinAPI_System_Driver.H src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
index 016cad9..0613ec8 100644
--- src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
+++ src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
@@ -1,7 +1,7 @@
 //
 // Windows system driver for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 2010-2022 by Bill Spitzak and others.
+// Copyright 2010-2026 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -113,7 +113,6 @@ public:
   void remove_fd(int, int when) FL_OVERRIDE;
   void remove_fd(int) FL_OVERRIDE;
   void gettime(time_t *sec, int *usec) FL_OVERRIDE;
-  char* strdup(const char *s) FL_OVERRIDE { return ::_strdup(s); }
   void lock_ring() FL_OVERRIDE;
   void unlock_ring() FL_OVERRIDE;
   double wait(double time_to_wait) FL_OVERRIDE;
diff --git src/fl_string_functions.cxx src/fl_string_functions.cxx
index 2e5e5d5..a36b7b7 100644
--- src/fl_string_functions.cxx
+++ src/fl_string_functions.cxx
@@ -1,7 +1,7 @@
 /*
  * Platform agnostic string portability functions for the Fast Light Tool Kit (FLTK).
  *
- * Copyright 2020 by Bill Spitzak and others.
+ * Copyright 2020-2026 by Bill Spitzak and others.
  *
  * This library is free software. Distribution and use rights are outlined in
  * the file "COPYING" which should have been included with this file.  If this
@@ -30,7 +30,13 @@
     - WinAPI: _strdup()
  */
 char *fl_strdup(const char *s) {
-  return Fl::system_driver()->strdup(s);
+  // Note: don't move this into Fl_System_Driver, as it needs to be available
+  // at initialisation time before the system driver is loaded.
+#  if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+  return ::_strdup(s);
+#  else
+  return ::strdup(s);
+#  endif
 }
 
 /*
[ Direct Link to Message ]
 
     
[ Previous Message ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.