[rdnzl-devel] C# pointer comparison.

Matthew O Connor matthew.oconnor at calyptech.com
Sat Mar 15 00:32:55 UTC 2008


Edi,

I tried out the code you gave me but it doesn't do the trick. I've created some test code to illustrate my problem a bit better. It is listed below.

There are two parts to it. You have to build a simple dll which contains a class that simply stores a reference passed to it as an "object". The lisp code simply instantiates a ReferenceComparisonTest object, passes it a reference to itself and then later compares what it passed in with what it got back to see if they are the same thing. 

They should be the same but clearly aren't. I think this is the crux of my problem.

Here is the code:

// C#



using System;



namespace ReferenceComparisonTest

{

    public class ReferenceComparisonTest

    {

        private object _reference = null;



        public ReferenceComparisonTest()

        {

            _reference = this;

        }



        public object reference

        {

            get { return _reference; }

            set { _reference = value; }

        }

    }

}



;; LISP



(load "../RDNZL/rdnzl-0.12.0/load.lisp")



(rdnzl:enable-rdnzl-syntax)



(rdnzl:import-types "ReferenceComparisonTest" "ReferenceComparisonTest")

(rdnzl:use-namespace "ReferenceComparisonTest")



(defun pointers-equal (a b)

  (fli::pointer-eq (rdnzl::pointer a) (rdnzl::pointer b)))



(defun main ()

  (let ((x (rdnzl::new "ReferenceComparisonTest")))

    ;; Make x store a reference to itself.

    (setf [%reference x] x)

    ;; Compare x with what was stored in x. These should be the same.

    (if (pointers-equal x [%reference x])

        (format t "Excellent! The references are the same as expected.")

      (format t "Error! The references were different but should have been the same."))))



(main)


Regards,

Matthew



-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3337 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/rdnzl-devel/attachments/20080315/38de0332/attachment.bin>


More information about the rdnzl-devel mailing list