Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/gstreamer-sharp/MiniObject.cs b/gstreamer-sharp/MiniObject.cs
- index cc04b1c..c479382 100644
- --- a/gstreamer-sharp/MiniObject.cs
- +++ b/gstreamer-sharp/MiniObject.cs
- @@ -33,6 +33,7 @@ namespace Gst {
- using System;
- using System.Collections;
- + using System.Collections.Generic;
- using System.ComponentModel;
- using System.Reflection;
- using System.Runtime.InteropServices;
- @@ -47,10 +48,10 @@ namespace Gst {
- [StructLayout (LayoutKind.Sequential) ]
- struct GstMiniObjectClass {
- - GTypeClass parent;
- - IntPtr copy;
- - IntPtr finalize;
- - IntPtr reserved;
- + public GTypeClass parent;
- + public IntPtr copy;
- + public IntPtr finalize;
- + public IntPtr reserved;
- }
- [StructLayout (LayoutKind.Sequential) ]
- @@ -68,20 +69,28 @@ namespace Gst {
- IntPtr handle;
- bool disposed = false;
- - static Hashtable Objects = new Hashtable();
- + static Dictionary<IntPtr, WeakReference> Objects = new Dictionary<IntPtr, WeakReference>();
- ~MiniObject () {
- - Dispose ();
- + if (WarnOnFinalize)
- + Console.Error.WriteLine ("Unexpected finalization of " + GetType() + " instance. Consider calling Dispose.");
- +
- + Dispose (false);
- }
- [DllImport ("libgstreamer-0.10.dll") ]
- static extern void gst_mini_object_unref (IntPtr raw);
- - public virtual void Dispose () {
- + public void Dispose () {
- if (disposed)
- return;
- + Dispose(true);
- disposed = true;
- + GC.SuppressFinalize (this);
- + }
- +
- + protected virtual void Dispose (bool disposing) {
- lock (typeof (MiniObject)) {
- if (handle != IntPtr.Zero) {
- Objects.Remove (handle);
- @@ -93,9 +102,10 @@ namespace Gst {
- }
- handle = IntPtr.Zero;
- }
- - }
- - GC.SuppressFinalize (this);
- - }
- + }
- + }
- +
- + public static bool WarnOnFinalize { get; set; }
- [DllImport ("libgstreamer-0.10.dll") ]
- static extern IntPtr gst_mini_object_ref (IntPtr raw);
- @@ -106,18 +116,17 @@ namespace Gst {
- MiniObject obj = null;
- lock (typeof (MiniObject)) {
- - WeakReference weak_ref = Objects[o] as WeakReference;
- -
- - if (weak_ref != null && weak_ref.IsAlive)
- - obj = weak_ref.Target as MiniObject;
- -
- - if (obj == null)
- - obj = Objects[o] as MiniObject;
- + WeakReference weak_ref;
- + if (Objects.TryGetValue (o, out weak_ref)) {
- + if (weak_ref != null && weak_ref.IsAlive)
- + obj = weak_ref.Target as MiniObject;
- + }
- }
- if (obj != null && obj.handle == o) {
- if (owned_ref)
- gst_mini_object_unref (obj.handle);
- +
- obj.disposed = false;
- return obj;
- }
- @@ -128,6 +137,7 @@ namespace Gst {
- if (!owned_ref)
- gst_mini_object_ref (obj.Handle);
- +
- Objects [o] = new WeakReference (obj);
- return obj;
- }
- @@ -194,7 +204,7 @@ namespace Gst {
- }
- - private static void InvokeClassInitializers (GType gtype, System.Type t) {
- + private static void InvokeTypeInitializers (GType gtype, System.Type t) {
- object[] parms = {gtype, t};
- BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic;
- @@ -297,7 +307,7 @@ namespace Gst {
- Gst.GLib.GType.Register (gtype, t);
- ConnectDefaultHandlers (gtype, t);
- - InvokeClassInitializers (gtype, t);
- + InvokeTypeInitializers (gtype, t);
- return gtype;
- }
- @@ -332,18 +342,23 @@ namespace Gst {
- protected virtual void CreateNativeObject () {
- Raw = gst_mini_object_new (LookupGType ().Val);
- - Objects [handle] = this;
- }
- protected virtual IntPtr Raw {
- get {
- return handle;
- } set {
- + if (handle == value)
- + return;
- +
- if (handle != IntPtr.Zero)
- Objects.Remove (handle);
- +
- handle = value;
- +
- if (value == IntPtr.Zero)
- return;
- +
- Objects [value] = new WeakReference (this);
- }
- }
- @@ -360,27 +375,19 @@ namespace Gst {
- }
- protected string TypeName {
- - get {
- - return NativeType.ToString();
- - }
- + get { return NativeType.ToString(); }
- }
- internal Gst.GLib.GType NativeType {
- - get {
- - return LookupGType ();
- - }
- + get { return LookupGType (); }
- }
- public IntPtr Handle {
- - get {
- - return handle;
- - }
- + get { return handle; }
- }
- public IntPtr OwnedHandle {
- - get {
- - return gst_mini_object_ref (handle);
- - }
- + get { return gst_mini_object_ref (handle); }
- }
- public override int GetHashCode () {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement