Browse Source

+ AfterConstruction and BeforeDestruction implemented
+ TInterfacedObject implemented

florian 25 years ago
parent
commit
f79644d9ca
4 changed files with 144 additions and 21 deletions
  1. 48 3
      rtl/i386/i386.inc
  2. 6 3
      rtl/inc/dynarr.inc
  3. 57 1
      rtl/inc/objpas.inc
  4. 33 14
      rtl/inc/objpash.inc

+ 48 - 3
rtl/i386/i386.inc

@@ -1117,14 +1117,59 @@ end;
 {$ifdef SYSTEMDEBUG}
 {$ifdef SYSTEMDEBUG}
 end;
 end;
 {$endif def SYSTEMDEBUG}
 {$endif def SYSTEMDEBUG}
+{$ifdef HASINTF}
+{ do a thread save inc/dec }
 
 
+procedure declocked(var l : longint);assembler;
+
+  asm
+{$ifdef MTRTL}
+     { this check should be done because a lock takes a lot }
+     { of time!                                             }
+     cmpb       $0,IsMultithreaded
+     jz         .Ldeclockednolock
+     movl       l,%edi
+     lock
+     decl       (%edi)
+     jmp        .Ldeclockedend
+.Ldeclockednolock:
+{$endif MTRTL}
+     movl       l,%edi
+     decl       (%edi);
+.Ldeclockedend:
+  end ['EDI'];
+
+procedure inclocked(var l : longint);assembler;
+
+  asm
+{$ifdef MTRTL}
+     { this check should be done because a lock takes a lot }
+     { of time!                                             }
+     cmpb       $0,IsMultithreaded
+     jz         .Linclockednolock
+     movl       l,%edi
+     lock
+     incl       (%edi)
+     jmp        .Linclockedend
+.Linclockednolock:
+{$endif MTRTL}
+     movl       l,%edi
+     incl       (%edi);
+.Linclockedend:
+  end ['EDI'];
+
+{$endif HASINTF}
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2000-07-14 10:33:09  michael
+  Revision 1.4  2000-11-07 23:42:21  florian
+    + AfterConstruction and BeforeDestruction implemented
+    + TInterfacedObject implemented
+
+  Revision 1.3  2000/07/14 10:33:09  michael
   + Conditionals fixed
   + Conditionals fixed
 
 
   Revision 1.2  2000/07/13 11:33:41  michael
   Revision 1.2  2000/07/13 11:33:41  michael
   + removed logs
   + removed logs
- 
-}
+
+}

+ 6 - 3
rtl/inc/dynarr.inc

@@ -132,10 +132,13 @@ function dynarray_copy(var p : pointer;ti : pdynarraytypeinfo;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.2  2000-11-06 21:35:59  peter
+  Revision 1.3  2000-11-07 23:42:21  florian
+    + AfterConstruction and BeforeDestruction implemented
+    + TInterfacedObject implemented
+
+  Revision 1.2  2000/11/06 21:35:59  peter
     * removed some warnings
     * removed some warnings
 
 
   Revision 1.1  2000/11/04 17:52:46  florian
   Revision 1.1  2000/11/04 17:52:46  florian
     * fixed linker errors
     * fixed linker errors
-
-}
+}

+ 57 - 1
rtl/inc/objpas.inc

@@ -595,6 +595,58 @@ Procedure Finalize (Data,TypeInfo: Pointer);forward;
         begin
         begin
           getinterfacetable:=pinterfacetable((pointer(Self)+vmtIntfTable)^);
           getinterfacetable:=pinterfacetable((pointer(Self)+vmtIntfTable)^);
         end;
         end;
+{****************************************************************************
+                               TINTERFACEDOBJECT
+****************************************************************************}
+
+    function TInterfacedObject.QueryInterface(
+      const iid : tguid;out obj) : longint;stdcall;
+
+      begin
+         if getinterface(iid,obj) then
+           result:=0
+         else
+           result:=$80004002;
+      end;
+
+    function TInterfacedObject._AddRef : longint;stdcall;
+
+      begin
+         inclocked(frefcount);
+         _addref:=frefcount;
+      end;
+
+    function TInterfacedObject._Release : longint;stdcall;
+
+      begin
+         declocked(frefcount);
+         _release:=frefcount;
+         if frefcount=0 then
+           destroy;
+      end;
+
+    procedure TInterfacedObject.AfterConstruction;
+
+      begin
+         { we need to fix the refcount we forced in newinstance }
+         { further, it must be done in a thread safe way        }
+         declocked(frefcount);
+      end;
+
+    procedure TInterfacedObject.BeforeDestruction;
+
+      begin
+         if frefcount<>0 then
+           HandleError(204);
+      end;
+
+    class function TInterfacedObject.NewInstance : TObject;
+
+      begin
+         NewInstance:=inherited NewInstance;
+         TInterfacedObject(NewInstance).frefcount:=1;
+      end;
+
 {$endif HASINTF}
 {$endif HASINTF}
 
 
 {****************************************************************************
 {****************************************************************************
@@ -609,7 +661,11 @@ Procedure Finalize (Data,TypeInfo: Pointer);forward;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.9  2000-11-06 22:03:12  florian
+  Revision 1.10  2000-11-07 23:42:21  florian
+    + AfterConstruction and BeforeDestruction implemented
+    + TInterfacedObject implemented
+
+  Revision 1.9  2000/11/06 22:03:12  florian
     * another fix
     * another fix
 
 
   Revision 1.8  2000/11/06 21:53:38  florian
   Revision 1.8  2000/11/06 21:53:38  florian

+ 33 - 14
rtl/inc/objpash.inc

@@ -151,23 +151,38 @@
 {$ifdef HASINTF}
 {$ifdef HASINTF}
        IUnknown = interface
        IUnknown = interface
          ['{00000000-0000-0000-C000-000000000046}']
          ['{00000000-0000-0000-C000-000000000046}']
-         function QueryInterface(const iid: tguid; out obj): LongInt; stdcall;
-         function _AddRef: LongInt; stdcall;
-         function _Release: LongInt; stdcall;
+         function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
+         function _AddRef : longint;stdcall;
+         function _Release : longint;stdcall;
        end;
        end;
 
 
        { for native dispinterface support }
        { for native dispinterface support }
        IDispatch = interface(IUnknown)
        IDispatch = interface(IUnknown)
-         ['{00020400-0000-0000-C000-000000000046}']
-         function GetTypeInfoCount(out count: LongInt): LongInt; stdcall;
-         function GetTypeInfo(Index, LocaleID: LongInt;
-           out TypeInfo): LongInt; stdcall;
-         function GetIDsOfNames(const iid: TGUID; names: Pointer;
-           NameCount, LocaleID: LongInt; DispIDs: Pointer): LongInt; stdcall;
-         function Invoke(DispID: LongInt; const iid: TGUID;
-           LocaleID: LongInt; Flags: Word; var params;
-           VarResult, ExcepInfo, ArgErr: Pointer): Integer; stdcall;
+          ['{00020400-0000-0000-C000-000000000046}']
+          function GetTypeInfoCount(out count : longint) : longint;stdcall;
+          function GetTypeInfo(Index,LocaleID : longint;
+            out TypeInfo): LongInt;stdcall;
+          function GetIDsOfNames(const iid: TGUID; names: Pointer;
+            NameCount, LocaleID: LongInt; DispIDs: Pointer) : longint;stdcall;
+          function Invoke(DispID: LongInt;const iid : TGUID;
+            LocaleID : longint; Flags: Word;var params;
+            VarResult,ExcepInfo,ArgErr : pointer) : longint;stdcall;
        end;
        end;
+
+       TInterfacedObject = class(TObject,IUnknown)
+       protected
+          frefcount : longint;
+          { implement methods of IUnknown }
+          function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
+          function _AddRef : longint;stdcall;
+          function _Release : longint;stdcall;
+        public
+          procedure AfterConstruction;override;
+          procedure BeforeDestruction;override;
+          class function NewInstance : TObject;override;
+          property RefCount : longint read frefcount;
+       end;
+
 {$endif HASINTF}
 {$endif HASINTF}
 
 
        TExceptProc = Procedure (Obj : TObject; Addr,Frame: Pointer);
        TExceptProc = Procedure (Obj : TObject; Addr,Frame: Pointer);
@@ -258,7 +273,11 @@
        end;
        end;
 {
 {
   $Log$
   $Log$
-  Revision 1.7  2000-11-06 20:34:24  peter
+  Revision 1.8  2000-11-07 23:42:21  florian
+    + AfterConstruction and BeforeDestruction implemented
+    + TInterfacedObject implemented
+
+  Revision 1.7  2000/11/06 20:34:24  peter
     * changed ver1_0 defines to temporary defs
     * changed ver1_0 defines to temporary defs
 
 
   Revision 1.6  2000/11/04 17:31:50  florian
   Revision 1.6  2000/11/04 17:31:50  florian
@@ -277,4 +296,4 @@
   Revision 1.2  2000/07/13 11:33:45  michael
   Revision 1.2  2000/07/13 11:33:45  michael
   + removed logs
   + removed logs
 
 
-}
+}