示例#1
0
 unsafe public bool PosTest2()
 {
     bool retVal = true;
     try
     {
         byte* mem = stackalloc byte[1024];
         System.IntPtr ip = new IntPtr((void*)mem);
         if (System.IntPtr.Size == 4)
         {
             if (ip.GetHashCode() != (int)mem)
             {
                 TestLibrary.TestFramework.LogError("002", "expect IntPtr.GetHashCode() equals the address");
                 retVal = false;
             }
         }
         else if (System.IntPtr.Size == 8)
         {
             if (ip.GetHashCode() != ((int)mem ^ (int)((long)mem >> 32)))
             {
                 TestLibrary.TestFramework.LogError("002", "expect IntPtr.GetHashCode() equals the address xor halves");
                 retVal = false;
             }
         }
         else
         {
             TestLibrary.TestFramework.LogError("002", "Unexpected IntPtr.Size: " + System.IntPtr.Size);
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
示例#2
0
 public bool PosTest1()
 {
     bool retVal = true;
     try
     {
         System.IntPtr ip = new IntPtr(0);
         if (ip.GetHashCode() != 0)
         {
             TestLibrary.TestFramework.LogError("001", "expect IntPtr(0).GetHashCode() == 0");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     return(handle.GetHashCode() >> 13 ^ data.GetHashCode());
 }
示例#4
0
 public override int GetHashCode()
 {
     return(this.GetType().FullName.GetHashCode() ^ Meta.GetHashCode() ^ RoiType.GetHashCode() ^ Id.GetHashCode() ^ ParentId.GetHashCode() ^ X.GetHashCode() ^ Y.GetHashCode() ^ W.GetHashCode() ^ H.GetHashCode() ^ _parms.GetHashCode());
 }
示例#5
0
    public bool PosTest4()
    {
        bool retVal = true;
        try
        {
            long addressOne = 0x123456FFFFFFFFL;
            long addressTwo = 0x654321FFFFFFFFL;
            System.IntPtr ipOne = new IntPtr(addressOne);
            System.IntPtr ipTwo = new IntPtr(addressTwo);
            if (ipOne.GetHashCode() == ipTwo.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("004", "expect different hashcodes.");
                retVal = false;
            }
        }
        catch (System.OverflowException ex)
        {
            if (System.IntPtr.Size == 4)
            {
                // ok, that's what it should be
                return retVal;
            }
            else
		   	{
                TestLibrary.TestFramework.LogError("004", "IntPtr should not have thrown an OverflowException: " + ex.ToString());
                retVal = false;
		   	}
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
 /// <summary>
 ///		Returns a hash code for this <see cref="InternalMemoryPointer"/>.
 /// </summary>
 /// <returns>
 ///		A hash code for this <see cref="InternalMemoryPointer"/>, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode() => internalMemoryPointer.GetHashCode();
 public override int GetHashCode()
 {
     return(_context.GetHashCode() ^ _signature.GetHashCode());
 }
示例#8
0
 public override int GetHashCode()
 {
     return(Next.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(devicePtr.GetHashCode());
 }
示例#10
0
 public static void TestEquals(IntPtr ptr1, object obj, bool expected)
 {
     if (obj is IntPtr)
     {
         IntPtr ptr2 = (IntPtr)obj;
         Assert.Equal(expected, ptr1 == ptr2);
         Assert.Equal(!expected, ptr1 != ptr2);
         Assert.Equal(expected, ptr1.GetHashCode().Equals(ptr2.GetHashCode()));
     }
     Assert.Equal(expected, ptr1.Equals(obj));
     Assert.Equal(ptr1.GetHashCode(), ptr1.GetHashCode());
 }
示例#11
0
 public override int GetHashCode()
 {
     return(_pData.GetHashCode() + _pRefClass.GetHashCode());
 }
示例#12
0
 public override int GetHashCode()
 {
     return(hNode.GetHashCode());
 }
示例#13
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     return(_MemoryAddress.GetHashCode());
 }
示例#14
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public override int GetHashCode()
 {
     return(pBuffers.GetHashCode());
 }
示例#15
0
 public override int GetHashCode()
 {
     return(_Ref.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(this.GetType().FullName.GetHashCode() ^ FpsN.GetHashCode() ^ FpsD.GetHashCode() ^ Flags.GetHashCode() ^ _latest_daily_jam.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(_hwnd.GetHashCode());
 }
示例#18
0
        private static unsafe Entry CacheMiss(IntPtr context, IntPtr signature, SignatureKind signatureKind = SignatureKind.GenericDictionary, object contextObject = null)
        {
            IntPtr result = IntPtr.Zero, auxResult = IntPtr.Zero;
            bool   previouslyCached = false;

            //
            // Try to find the entry in the previous version of the cache that is kept alive by weak reference
            //
            if (s_previousCache.IsAllocated)
            {
                Entry[] previousCache = (Entry[])s_previousCache.Target;
                if (previousCache != null)
                {
                    Entry previousEntry = LookupInCache(previousCache, context, signature);
                    if (previousEntry != null)
                    {
                        result           = previousEntry.Result;
                        auxResult        = previousEntry.AuxResult;
                        previouslyCached = true;
                    }
                }
            }

            //
            // Call into the type loader to compute the target
            //
            if (!previouslyCached)
            {
                switch (signatureKind)
                {
                case SignatureKind.GenericDictionary:
                    result = RuntimeAugments.TypeLoaderCallbacks.GenericLookupFromContextAndSignature(context, signature, out auxResult);
                    break;

                case SignatureKind.GenericVirtualMethod:
                    result = Internal.Runtime.CompilerServices.GenericVirtualMethodSupport.GVMLookupForSlot(new RuntimeTypeHandle(new EETypePtr(context)), *(RuntimeMethodHandle *)&signature);
                    break;

                case SignatureKind.OpenInstanceResolver:
                    result = Internal.Runtime.CompilerServices.OpenMethodResolver.ResolveMethodWorker(signature, contextObject);
                    break;

                case SignatureKind.DefaultConstructor:
                {
                    result = RuntimeAugments.TypeLoaderCallbacks.TryGetDefaultConstructorForType(new RuntimeTypeHandle(new EETypePtr(context)));
                    if (result == IntPtr.Zero)
                    {
                        result = RuntimeAugments.GetFallbackDefaultConstructor();
                    }
                }
                break;

                case SignatureKind.GenericDelegateThunk:
                    result = RuntimeAugments.TypeLoaderCallbacks.GetDelegateThunk((Delegate)contextObject, (int)signature);
                    break;

                default:
                    result = RawCalliHelper.Call <IntPtr>(s_resolutionFunctionPointers[(int)signatureKind], context, signature, contextObject, out auxResult);
                    break;
                }
            }

            //
            // Update the cache under the lock
            //
            if (s_lock == null)
            {
                Interlocked.CompareExchange(ref s_lock, new Lock(), null);
            }

            s_lock.Acquire();
            try
            {
                // Avoid duplicate entries
                Entry existingEntry = LookupInCache(s_cache, context, signature);
                if (existingEntry != null)
                {
                    return(existingEntry);
                }

                // Resize cache as necessary
                Entry[] cache = ResizeCacheForNewEntryAsNecessary();

                int key = ((context.GetHashCode() >> 4) ^ signature.GetHashCode()) & (cache.Length - 1);

                Entry newEntry = new Entry()
                {
                    Context = context, Signature = signature, Result = result, AuxResult = auxResult, Next = cache[key]
                };
                cache[key] = newEntry;
                return(newEntry);
            }
            finally
            {
                s_lock.Release();
            }
        }
 public override int GetHashCode()
 {
     return(m_Ptr.GetHashCode());
 }
示例#20
0
 public override int GetHashCode()
 {
     return(m_hMediaPlayer.GetHashCode());
 }
示例#21
0
文件: GType.cs 项目: masums/gtk-sharp
 public override int GetHashCode()
 {
     return(val.GetHashCode());
 }
示例#22
0
 public override int GetHashCode()
 {
     return(this.GetType().FullName.GetHashCode() ^ _need_data.GetHashCode() ^ _enough_data.GetHashCode() ^ _seek_data.GetHashCode());
 }
示例#23
0
 public override int GetHashCode()
 {
     return(inner_ptr.GetHashCode());
 }
示例#24
0
 public override int GetHashCode()
 {
     return(this.GetType().FullName.GetHashCode() ^ Pt.GetHashCode() ^ C.GetHashCode() ^ DataLen.GetHashCode() ^ _data.GetHashCode());
 }
示例#25
0
 public override int GetHashCode()
 {
     return(Handle.GetHashCode());
 }
示例#26
0
文件: FILE.cs 项目: tigros/GMPCalcGTK
 /// <summary>
 /// Returns the hash code for this instance.
 /// </summary>
 /// <returns>A 32-bit signed integer hash code.</returns>
 public override int GetHashCode()
 {
     return(Value.GetHashCode());
 }
示例#27
0
            public override int GetHashCode()
            {
                IntPtr intPtr = ICVar.GetIntPtr(m_icVar);

                return(intPtr.GetHashCode());
            }
示例#28
0
 /// <summary>
 ///   Gets a hash for <see cref="HashTupleNative" />.
 /// <para>Since EFL 1.24.</para>
 /// </summary>
 /// <returns>A hash code.</returns>
 public override int GetHashCode()
 => key.GetHashCode() ^ data.GetHashCode() ^ key_length.GetHashCode();
示例#29
0
 /// <summary>
 /// Returns a hash code for this <see cref="FIBITMAP"/> structure.
 /// </summary>
 /// <returns>An integer value that specifies the hash code for this <see cref="FIBITMAP"/>.</returns>
 public override int GetHashCode()
 {
     return(data.GetHashCode());
 }
示例#30
0
 public override int GetHashCode() => _pPtr.GetHashCode();
示例#31
0
 public override int GetHashCode() => Handle.GetHashCode();
示例#32
0
    public static unsafe void TestBasics()
    {
        if (sizeof(void*) == 4)
        {
            // Skip IntPtr tests on 32-bit platforms
            return;
        }

        IntPtr p;
        int i;
        long l;

        int size = IntPtr.Size;
        Assert.Equal(size, sizeof(void*));

        TestPointer(IntPtr.Zero, 0);

        i = 42;
        TestPointer(new IntPtr(i), i);
        TestPointer((IntPtr)i, i);

        i = 42;
        TestPointer(new IntPtr(i), i);

        i = -1;
        TestPointer(new IntPtr(i), i);

        l = 0x0fffffffffffffff;
        TestPointer(new IntPtr(l), l);
        TestPointer((IntPtr)l, l);

        void* pv = new IntPtr(42).ToPointer();
        TestPointer(new IntPtr(pv), 42);
        TestPointer((IntPtr)pv, 42);

        p = IntPtr.Add(new IntPtr(42), 5);
        TestPointer(p, 42 + 5);

        // Add is spected NOT to generate an OverflowException
        p = IntPtr.Add(new IntPtr(0x7fffffffffffffff), 5);
        unchecked
        {
            TestPointer(p, (long)0x8000000000000004);
        }

        p = IntPtr.Subtract(new IntPtr(42), 5);
        TestPointer(p, 42 - 5);

        bool b;
        p = new IntPtr(42);
        b = p.Equals(null);
        Assert.False(b);
        b = p.Equals((object)42);
        Assert.False(b);
        b = p.Equals((object)(new IntPtr(42)));
        Assert.True(b);

        int h = p.GetHashCode();
        int h2 = p.GetHashCode();
        Assert.Equal(h, h2);

        p = new IntPtr(42);
        i = (int)p;
        Assert.Equal(i, 42);
        l = (long)p;
        Assert.Equal(l, 42);
        IntPtr p2;
        p2 = (IntPtr)i;
        Assert.Equal(p, p2);
        p2 = (IntPtr)l;
        Assert.Equal(p, p2);
        p2 = (IntPtr)(p.ToPointer());
        Assert.Equal(p, p2);
        p2 = new IntPtr(40) + 2;
        Assert.Equal(p, p2);
        p2 = new IntPtr(44) - 2;
        Assert.Equal(p, p2);

        p = new IntPtr(0x7fffffffffffffff);
        Assert.Throws<OverflowException>(() => { i = (int)p; });
    }
示例#33
0
 public override int GetHashCode()
 {
     return(m_Handle.GetHashCode() ^ m_Version.GetHashCode());
 }
示例#34
0
 public override int GetHashCode()
 {
     return(_hdc.GetHashCode() ^ _handle.GetHashCode());
 }
示例#35
0
 public bool PosTest3()
 {
     bool retVal = true;
     try
     {
         int anyAddr = TestLibrary.Generator.GetInt32(-55);
         System.IntPtr ip = new IntPtr(anyAddr);
         if (ip.GetHashCode() != anyAddr )
         {
             TestLibrary.TestFramework.LogError("003", String.Format("expect IntPtr.GetHashCode() == {0}", anyAddr));
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
 public override int GetHashCode() => value.GetHashCode();
 public virtual bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   IntPtr ip1;
   Int32 iValue;
   try {
   strLoc = "Loc_743wg";
   iValue = 16;
   ip1 = new IntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_865sg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = -25;
   ip1 = new IntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_97356sg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = 0;
   ip1 = new IntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_97sdg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = Int32.MaxValue;
   ip1 = new IntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_97sdg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = Int32.MinValue;
   ip1 = new IntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_97sdg! Wrong value returned");
   }             
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
     return true;
     }
   else
     {
     Console.Error.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
示例#38
0
文件: IntPtr.cs 项目: kkurni/corefx
 public static void TestGetHashCodeRespectAllBits()
 {
     var ptr1 = new IntPtr(0x123456FFFFFFFF);
     var ptr2 = new IntPtr(0x654321FFFFFFFF);
     Assert.NotEqual(ptr1.GetHashCode(), ptr2.GetHashCode());
 }