Browse Source

+ Implemented loading of dynamical libraries

michael 25 years ago
parent
commit
bfdac9385b

+ 55 - 0
rtl/inc/dynlibs.pp

@@ -0,0 +1,55 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by the Free Pascal development team
+
+    Implements OS-independent loading of dynamic libraries.
+    
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{$MODE OBJFPC}
+
+unit dynlibs;
+
+interface
+
+{ ---------------------------------------------------------------------
+  Read OS-dependent interface declarations.
+  ---------------------------------------------------------------------}
+
+{$define readinterface}
+{$i dynlibs.inc}
+{$undef  readinterface}
+
+{ ---------------------------------------------------------------------
+  OS - Independent declarations.
+  ---------------------------------------------------------------------}
+
+
+Function LoadLibrary(Name : AnsiString) : TLibHandle;
+Function GetProcedureAddress(Lib : TlibHandle; ProcName : AnsiString) : Pointer;
+Function UnloadLibrary(Lib : TLibHandle) : Boolean;
+
+Implementation
+
+{ ---------------------------------------------------------------------
+  OS - Independent declarations.
+  ---------------------------------------------------------------------}
+
+{$i dynlibs.inc}
+
+end.
+
+{
+  $Log$
+  Revision 1.1  2000-08-18 19:15:34  michael
+  + Implemented loading of dynamical libraries
+
+}

+ 8 - 3
rtl/linux/Makefile

@@ -1,5 +1,5 @@
 #
-# Makefile generated by fpcmake v0.99.15 [2000/07/02]
+# Makefile generated by fpcmake v1.00 [2000/07/11]
 #
 
 defaultrule: all
@@ -202,7 +202,7 @@ endif
 # Targets
 
 override LOADEROBJECTS+=prt0 cprt0 gprt0 cprt21 gprt21
-override UNITOBJECTS+=$(SYSTEMUNIT) objpas strings linux ports initc dos crt objects printer graph ggigraph sysutils typinfo math cpu mmx getopts heaptrc lineinfo errors sockets gpm ipc serial
+override UNITOBJECTS+=$(SYSTEMUNIT) objpas strings linux ports initc dos crt objects printer graph ggigraph sysutils typinfo math cpu mmx getopts heaptrc lineinfo errors sockets gpm ipc serial dl dynlibs
 override RSTOBJECTS+=math
 
 # Clean
@@ -230,7 +230,7 @@ endif
 
 LIBNAME=libfprtl.so
 LIBVERSION=1.0
-SHAREDLIBUNITOBJECTS=$(SYSTEMUNIT) objpas strings linux ports dos crt objects printer sysutils typinfo math cpu mmx getopts heaptrc errors sockets ipc
+SHAREDLIBUNITOBJECTS=$(SYSTEMUNIT) objpas strings linux ports dos crt objects printer sysutils typinfo math cpu mmx getopts heaptrc errors sockets ipc dl dynlibs
 
 # Info
 
@@ -1249,6 +1249,11 @@ linux$(PPUEXT) : linux.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc
 
 ports$(PPUEXT) : ports.pp linux$(PPUEXT) objpas$(PPUEXT)
 
+dl$(PPUEXT) : dl.pp
+
+dynlibs$(PPUEXT) : $(INC)/dynlibs.pp dynlibs.inc dl$(PPUEXT)
+
+
 #
 # TP7 Compatible RTL Units
 #

+ 8 - 2
rtl/linux/Makefile.fpc

@@ -9,7 +9,8 @@ units=$(SYSTEMUNIT) objpas strings \
       dos crt objects printer graph ggigraph \
       sysutils typinfo math \
       cpu mmx getopts heaptrc lineinfo \
-      errors sockets gpm ipc serial
+      errors sockets gpm ipc serial dl dynlibs
+
 rst=math
 
 [require]
@@ -35,7 +36,7 @@ libunits=$(SYSTEMUNIT) objpas strings \
       dos crt objects printer \
       sysutils typinfo math \
       cpu mmx getopts heaptrc \
-      errors sockets ipc
+      errors sockets ipc dl dynlibs
 
 
 [presettings]
@@ -129,6 +130,11 @@ linux$(PPUEXT) : linux.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc
 
 ports$(PPUEXT) : ports.pp linux$(PPUEXT) objpas$(PPUEXT)
 
+dl$(PPUEXT) : dl.pp
+
+dynlibs$(PPUEXT) : $(INC)/dynlibs.pp dynlibs.inc dl$(PPUEXT) objpas$(PPUEXT)
+
+
 #
 # TP7 Compatible RTL Units
 #

+ 18 - 0
rtl/linux/dl.pp

@@ -0,0 +1,18 @@
+Unit dl;
+
+Interface
+
+Const  
+  LibDL = 'dl';
+
+  RTLD_LAZY         = $001;
+  RTLD_NOW          = $002;
+  RTLD_BINDING_MASK = $003;
+  
+Function dlopen(Name : PChar; Flags : longint) : Pointer; cdecl; external libdl;
+FUnction dlsym(Lib : Pointer; Name : Pchar) : Pointer; cdecl; external Libdl;  
+Function dlclose(Lib : Pointer) : Longint; cdecl; external libdl;
+
+implementation
+
+end.

+ 62 - 0
rtl/linux/dynlibs.inc

@@ -0,0 +1,62 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by the Free Pascal development team
+
+    Implement OS-dependent part of dynamic library loading.
+    
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{$ifdef readinterface}
+
+{ ---------------------------------------------------------------------
+    Interface declarations
+  ---------------------------------------------------------------------}
+
+Type
+  TLibHandle = Pointer;
+
+Const
+  NilHandle = Nil;
+
+{$else}
+
+{ ---------------------------------------------------------------------
+    Implementation section
+  ---------------------------------------------------------------------}
+
+uses dl;
+
+Function LoadLibrary(Name : AnsiString) : TLibHandle;
+
+begin
+  Result:=dlopen(Pchar(Name),RTLD_LAZY);
+end;
+
+Function GetProcedureAddress(Lib : TLibHandle; ProcName : AnsiString) : Pointer;
+
+begin
+  Result:=dlsym(lib,pchar(ProcName));
+end;
+
+Function UnloadLibrary(Lib : TLibHandle) : Boolean;
+
+begin
+  Result:=dlClose(Lib)=0;
+end;
+
+{$endif}
+
+{
+  $Log$
+  Revision 1.1  2000-08-18 19:15:34  michael
+  + Implemented loading of dynamical libraries
+
+}

+ 62 - 0
rtl/template/dynlibs.inc

@@ -0,0 +1,62 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by the Free Pascal development team
+
+    Implements OS dependent part for loading of dynamic libraries.
+    
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+
+{$ifdef readinterface}
+
+{ ---------------------------------------------------------------------
+    Interface declarations
+  ---------------------------------------------------------------------}
+
+Type
+  TLibHandle = Longint;
+
+Const
+  NilHandle = 0; 
+
+{$else}
+
+{ ---------------------------------------------------------------------
+    Implementation section
+  ---------------------------------------------------------------------}
+
+
+Function LoadLibrary(Name : AnsiString) : TlibHandle;
+
+begin
+  Result:=NilHandle;
+end;
+
+Function GetProcedureAddress(Lib : TLibHandle; ProcName : AnsiString) : Pointer;
+
+begin
+  Result:=Nil;
+end;
+
+Function UnloadLibrary(Lib : TLibHandle) : Boolean;
+
+begin
+  Result:=False;
+end;
+
+{$endif}
+
+{
+  $Log$
+  Revision 1.1  2000-08-18 19:15:34  michael
+  + Implemented loading of dynamical libraries
+
+}

+ 4 - 2
rtl/win32/Makefile

@@ -1,5 +1,5 @@
 #
-# Makefile generated by fpcmake v0.99.15 [2000/07/02]
+# Makefile generated by fpcmake v1.00 [2000/07/11]
 #
 
 defaultrule: all
@@ -198,7 +198,7 @@ endif
 # Targets
 
 override LOADEROBJECTS+=wprt0 wdllprt0
-override UNITOBJECTS+=$(SYSTEMUNIT) objpas strings windows ole2 opengl32 os_types winsock initc dos crt objects graph sysutils typinfo math cpu mmx getopts heaptrc lineinfo wincrt winmouse sockets printer
+override UNITOBJECTS+=$(SYSTEMUNIT) objpas strings windows ole2 opengl32 os_types winsock initc dos crt objects graph sysutils typinfo math cpu mmx getopts heaptrc lineinfo wincrt winmouse sockets printer dynlibs
 override RSTOBJECTS+=math
 
 # Clean
@@ -1248,6 +1248,8 @@ wincrt$(PPUEXT) : wincrt.pp $(SYSTEMPPU) windows$(PPUEXT) graph$(PPUEXT)
 
 winmouse$(PPUEXT) : winmouse.pp $(SYSTEMPPU) windows$(PPUEXT) graph$(PPUEXT)
 
+dynlibs$(PPUEXT) : $(INC)/dynlibs.pp windows$(PPUEXT)
+
 #
 # TP7 Compatible RTL Units
 #

+ 4 - 1
rtl/win32/Makefile.fpc

@@ -9,7 +9,8 @@ units=$(SYSTEMUNIT) objpas strings \
       dos crt objects graph \
       sysutils typinfo math \
       cpu mmx getopts heaptrc lineinfo \
-      wincrt winmouse sockets printer
+      wincrt winmouse sockets printer dynlibs
+
 rst=math
 
 [require]
@@ -121,6 +122,8 @@ wincrt$(PPUEXT) : wincrt.pp $(SYSTEMPPU) windows$(PPUEXT) graph$(PPUEXT)
 
 winmouse$(PPUEXT) : winmouse.pp $(SYSTEMPPU) windows$(PPUEXT) graph$(PPUEXT)
 
+dynlibs$(PPUEXT) : $(INC)/dynlibs.pp windows$(PPUEXT)
+
 #
 # TP7 Compatible RTL Units
 #

+ 63 - 0
rtl/win32/dynlibs.inc

@@ -0,0 +1,63 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by the Free Pascal development team
+
+    Implements OS dependent part for loading of dynamic libraries.
+    
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+
+{$ifdef readinterface}
+
+{ ---------------------------------------------------------------------
+    Interface declarations
+  ---------------------------------------------------------------------}
+
+Type
+  TLibHandle = Longint;
+
+Const
+  NilHandle = 0; 
+
+{$else}
+
+{ ---------------------------------------------------------------------
+    Implementation section
+  ---------------------------------------------------------------------}
+
+Uses windows;
+
+Function LoadLibrary(Name : AnsiString) : TlibHandle;
+
+begin
+  Result:=Windows.LoadLibrary(PChar(Name));
+end;
+
+Function GetProcedureAddress(Lib : TLibHandle; ProcName : AnsiString) : Pointer;
+
+begin
+  Result:=Windows.GetProcAddress(Lib,PChar(ProcName));
+end;
+
+Function UnloadLibrary(Lib : TLibHandle) : Boolean;
+
+begin
+  Result:=FreeLibrary(Lib);
+end;
+
+{$endif}
+
+{
+  $Log$
+  Revision 1.1  2000-08-18 19:15:34  michael
+  + Implemented loading of dynamical libraries
+
+}