~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/Framework/CoreFoundation.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
                
48
48
                [DllImport (CFLib, EntryPoint="CFRelease")]
49
49
                public static extern void Release (IntPtr cfRef);
 
50
                
 
51
                                struct CFRange {
 
52
                        public int Location, Length;
 
53
                        public CFRange (int l, int len)
 
54
                        {
 
55
                                Location = l;
 
56
                                Length = len;
 
57
                        }
 
58
                }
 
59
                
 
60
                [DllImport (CFLib, CharSet=CharSet.Unicode)]
 
61
                extern static int CFStringGetLength (IntPtr handle);
 
62
 
 
63
                [DllImport (CFLib, CharSet=CharSet.Unicode)]
 
64
                extern static IntPtr CFStringGetCharactersPtr (IntPtr handle);
 
65
                
 
66
                [DllImport (CFLib, CharSet=CharSet.Unicode)]
 
67
                extern static IntPtr CFStringGetCharacters (IntPtr handle, CFRange range, IntPtr buffer);
 
68
                
 
69
                public static string FetchString (IntPtr handle)
 
70
                {
 
71
                        if (handle == IntPtr.Zero)
 
72
                                return null;
 
73
                        
 
74
                        string str;
 
75
                        
 
76
                        int l = CFStringGetLength (handle);
 
77
                        IntPtr u = CFStringGetCharactersPtr (handle);
 
78
                        IntPtr buffer = IntPtr.Zero;
 
79
                        if (u == IntPtr.Zero){
 
80
                                CFRange r = new CFRange (0, l);
 
81
                                buffer = Marshal.AllocCoTaskMem (l * 2);
 
82
                                CFStringGetCharacters (handle, r, buffer);
 
83
                                u = buffer;
 
84
                        }
 
85
                        unsafe {
 
86
                                str = new string ((char *) u, 0, l);
 
87
                        }
 
88
                        
 
89
                        if (buffer != IntPtr.Zero)
 
90
                                Marshal.FreeCoTaskMem (buffer);
 
91
                        
 
92
                        return str;
 
93
                }
50
94
        }
51
95
}