Changeset 13248 for trunk/abcl/src/org


Ignore:
Timestamp:
03/12/11 23:08:21 (10 years ago)
Author:
ehuelsmann
Message:

Close #138 by implementing finalizers on LispObject derived objects.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Autoload.java

    r13247 r13248  
    520520        autoload(PACKAGE_EXT, "make-weak-reference", "WeakReference", true);
    521521        autoload(PACKAGE_EXT, "weak-reference-value", "WeakReference", true);
     522        autoload(PACKAGE_EXT, "finalize", "Primitives", true);
     523        autoload(PACKAGE_EXT, "cancel-finalization", "Primitives", true);
    522524        autoload(PACKAGE_JAVA, "%jnew-proxy", "JProxy");
    523525        autoload(PACKAGE_JAVA, "%find-java-class", "JavaObject");
  • trunk/abcl/src/org/armedbear/lisp/LispObject.java

    r12826 r13248  
    12851285  {
    12861286  }
     1287
     1288  private Cons finalizers = null;
     1289
     1290  synchronized public void addFinalizer(LispObject fun) {
     1291      finalizers = new Cons(fun, finalizers);
     1292  }
     1293
     1294  synchronized public void cancelFinalizers() {
     1295      finalizers = null;
     1296  }
     1297
     1298  @Override
     1299  @SuppressWarnings("FinalizeDeclaration")
     1300  protected void finalize()
     1301    throws Throwable {
     1302      while (finalizers != null) {
     1303          finalizers.car.execute();
     1304          finalizers = (Cons)finalizers.cdr;
     1305      }
     1306      super.finalize();
     1307  }
    12871308}
  • trunk/abcl/src/org/armedbear/lisp/Primitives.java

    r13183 r13248  
    33 *
    44 * Copyright (C) 2002-2007 Peter Graves
     5 * Copyright (C) 2011 Erik Huelsmann
    56 * $Id$
    67 *
     
    58195820    };
    58205821
     5822    // ### finalize
     5823    private static final Primitive FINALIZE
     5824        = new pf_finalize();
     5825    private static final class pf_finalize extends Primitive {
     5826        pf_finalize() {
     5827            super("finalize", PACKAGE_EXT, true, "object function");
     5828        }
     5829
     5830        @Override
     5831        public LispObject execute(LispObject obj, LispObject fun) {
     5832            obj.addFinalizer(fun);
     5833            return obj;
     5834        }
     5835    };
     5836
     5837    // ### cancel-finalization
     5838    private static final Primitive CANCEL_FINALIZATION
     5839        = new pf_cancel_finalization();
     5840    private static final class pf_cancel_finalization extends Primitive {
     5841        pf_cancel_finalization() {
     5842            super("cancel-finalization", PACKAGE_EXT, true, "object");
     5843        }
     5844
     5845        @Override
     5846        public LispObject execute(LispObject obj) {
     5847            obj.cancelFinalizers();
     5848            return obj;
     5849        }
     5850    };
     5851
    58215852}
Note: See TracChangeset for help on using the changeset viewer.