delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/10/08/15:10:36

Message-ID: <361D1379.26E7FDA9@inetlab.com>
Date: Fri, 09 Oct 1998 01:33:13 +0600
From: Ilya Ryzhenkov <orangy AT inetlab DOT com>
Organization: iNetLab
X-Mailer: Mozilla 4.03 [en] (Win95; I)
MIME-Version: 1.0
To: djgpp workers list <djgpp-workers AT delorie DOT com>
Subject: Sorry ... DLM Overview here.
Reply-To: djgpp-workers AT delorie DOT com

Hi!

I'm sorry, I forgot that not everyone was here 2 years ago ;))
Here is some information on DLM library :

NOTE : sorry, it is somewhat not organized, I'm compiling it
now from several docs available...
	
------------------------ from readme.txt -------------------
     DLM  stands  for  "Dynamic  Link  Module".  DLM  engine creates
 environment,  which allow you to link different modules together at
 run-time.  The  way  it  works  is  similar  to  the  static linker
 functionality,  but  is  performed  during  program execution. Many
 popular  systems,  that  allow dynamic loading and using of modules
 (or  libraries)  use  the  "ask-me-for-a-pointer"  scheme.  In such
 environments  you  must first load module, than ask for pointer and
 then  reference  data  and/or code via pointer. 
     Unlike  all  of  this  DLM environment allows you to write your
 source code as if there would be static linkage (and you really can
 use  the  same  source  code  without  ANY changes for DLM-oriented
 version and static linked version by creating some #defines).
     There is no special syntax for calling functions or referencing
 data  from  other  DLMs.  For  example,  let  func()  be defined in
 some.dlm. You can use it like :

   if (!LoadDLM("some.dlm")) 
     {
      printf("Can't load DLM some.dlm\n");
      exit(1);
     }
   func();
   
  That's all, easy! And much easier than the following

   int dllhandle=LoadDLL("some.dll");
   void (*f)();
   if (!dllhandle) printf("Can't load...\n"); else
    {
     f=(void (*)())GetSymbolAddress(dllhandle,"func");
     if (!f) printf("func is not defined ...\n");
       else f();
       /* which is actually call via pointer and waste of CPU time */
    }

     After  .c  file  is compiled you will have .o file,  which  is  
 used to create Dynamic Link Module (DLM) for your project.  

     Function  "int  constructor();" is called IMMEDIATELY after DLM
 was  loaded,  even before calling constructors for static C++ class
 instances.  If  this  function  returns 0 - DLM will be immediately
 unloaded without calling to any other code.
     Function  "int  destructor();" is called right before unloading
 DLM. It's return value have no sense yet, it is reserved for future
 use.

     If  you  want  to  create  one  DLM from several .o files - use
 command like this
  ld -r -o someobjs.o file1.o file2.o -T.../lib/dlm/dlm.djl
 to create single obj file, then convert it to DLM.

 So what is happen after you type progname.exe at command prompt ?
 - The djgpp standart stub is executed, it switches to pmode and do
   other it's native tasks. It loads DLMSTUB and start it.
 - DLMSTUB initialize engine, export many function, which are used
inside
   of it and loads DLM from the exe. Then it attempts to find function
   main and calls it on success.
 - Your programm starts working, making calls to DLM engine using
   functions like LoadDLM, UnloadDLM and other.

 -------------------------- extra information from other docs
-------------------------
 Extra Symbols are special symbols, that are placed to DLM using
 DLM Manager -s option. They handle contents of some file, that was
 placed into DLM. Note, symbol is NOT a pointer to file contents, it IS
 file contents. For example :

 --- begin DLM source test.c ---
 #include <stdio.h>
 char text;
 void main()
 {
  // printf is exported implicitly from dlmstub.exe, we may not load
libc.dlm
  printf("%s",&text); // You need here pointer to string.
 };
 --- end DLM source test.c ---
 Commands :

 gcc -o test.o -c test.c
 dlmman test.o -ec -s _text=somefile.txt
 // Note: leading underscore must be present !
 // Note: somefile.txt must be null-terminated !
 test
 // will print contents of somefile.txt

 You can obtain size of data referenced by such symbol by using
 SizeofDLMSymbol() function. 

 -------------------------- extra information from other docs
-------------------------

 DLM engine support all common C++ mechanisms, like inheritance, 
 virtual  functions, etc. It doesn't require any special syntax. You 
 can  use  static  class  instances,  dynamic  objects  (via new and 
 delete), and so on. But in some situations DLM engine will not have 
 enough  information  to  successfully  manage  your  program if you 
 will  not  follow some rules, described  below. You also  must load 
 libc.dlm as it contains C++ specific symbols, like operator new. 

 What to have in mind, while using DLMs and C++ : 
 1. Using inline methods and especially inline constructors may 
    cause problems. Compiler can decide not to export them as 
    symbols and you will be unable to call them. But usually they 
    works fine, except of 'named classes', see below. 
 2. Static class instances are created AFTER call to constructor(), 
    so don't use them in constructor. Functions with `constructor' 
    attribute are called like static object's constructors, i.e. 
    in order of appearance. 

 Special feature -- Named Classes

 DLM engine gives your a unique feature - create an instance of a class
from 
 the following information : 
 1. Run-time computed name of the class. 
 2. Compile-time declared class, which is higher in the hierarchy (i.e.
any of 
    parent class). This is required to obtain constructor syntax and
virtual 
    tables. 
 3. Inherited class have constructor with the same parameters as parent
class. 
 4. The class was exported (by using special macro) in the definition
place. 

 The syntax is the following : 
 In the EXPORTER module, i.e. where the class was DEFINED. 
   DLM_EXP_NAMEDCLASS(class_identifier) 
 This one is needed to obtain sizeof(class_identifier) at run-time. 

 In the IMPORTER module, i.e. where you want to create instance of such 
 class. 
   DLM_USE_NAMEDCLASS /* No name here! This macro allows use of any
named class */ 

 To create instance : 
  new("class_identifier") Known_Base_Class_identifier( parameters ); 

 This command will call class_indetifier's (NOT
Known_Base_Class_identifier's!) 
 constructor with the given parameters. 
 It's obvious, that you must HAVE constructor with  such prototype. 

 Downloading

 Download binary distribution at 
ftp://solo.iis.nsk.su/pub/djgpp/dlm/dlm20b.zip 
 Source distribution is not ready yet, but you can get a work-zip at
 ftp://solo.iis.nsk.su/pub/djgpp/dlm/dlmwork.zip 
 Work-zip is just a snapshot of some relatively stable state of my
working dirs.
 It can even not compile on your system! I'm working now primarily on
source 
 distribution. And of course bug fixes.

 Docs are included both in binary and source distribution  in the form 
 of plain ascii file. 
============================
Ilya P. Ryzhenkov aka Orangy
Fido   : 2:5000/120.7
E-mail : orangy AT inetlab DOT com
   ICQ : 17942172

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019