Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

64 bit support for CoreGraphics #45

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c237171
added 64bit Version of NSRect
sbaer Feb 28, 2013
cac90ff
using tab style preference for mono files
sbaer Feb 28, 2013
d48b33f
NSRect, NSPoint, NSSize for 64 bit build
sbaer Feb 28, 2013
a99b88e
NSPredicateEditorRowTemplate reviewed for 64 bit
sbaer Feb 28, 2013
069985f
Working on 64bit support for CoreGraphics
sbaer Mar 6, 2013
77da4da
CoreGraphics 64bit support
sbaer Mar 6, 2013
8a5d71e
Removed warning on 32 build of unused variable
sbaer Mar 6, 2013
db07975
merge recent changes on main maccore repository
sbaer Mar 7, 2013
321d1f4
Update ImageIO for 64 bit
sbaer Mar 9, 2013
6778c03
NSArray and NSAttributedString made 64bit compatible
sbaer Mar 9, 2013
6de5e39
NSCache, NSCalendarDate, NSData modified for 64 bit build
sbaer Mar 9, 2013
6ee26b6
64bit updates to foundation classes
sbaer Mar 9, 2013
ae46760
64 bit modifications for foundation classes
sbaer Mar 9, 2013
5175dab
Making foundation generated classes 64bit compatible
sbaer Mar 13, 2013
768f55d
foundation.cs updated to be 64bit compatible
sbaer Mar 13, 2013
db3b0f9
Merge remote-tracking branch 'upstream/master'
sbaer Mar 13, 2013
a67c224
Added constructors/functions to point,rect,size to make it easier to …
sbaer Apr 5, 2013
4f359d3
added overload of NSArray.FromObjects to 64 bit compile
sbaer Apr 11, 2013
91d9323
64bit fix for figuring out which obj_msg... function to call based on…
sbaer Apr 25, 2013
fbe5430
added set properties for NSRect
sbaer Apr 25, 2013
6542951
Added "debugging" command args for testing
sbaer Apr 25, 2013
2ead7f7
set up project for working on a 64 bit compile
sbaer Apr 25, 2013
22b2455
update to fix compile error with latest mono release
sbaer Oct 11, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/AddressBook/ABAddressBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Authors: Mono Team
//
// Copyright (C) 2009 Novell, Inc
// Copyright 2011, 2012 Xamarin Inc.
// Copyright 2011-2013 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -69,13 +69,17 @@ public ExternalChangeEventArgs (ABAddressBook addressBook, NSDictionary info)
//
// Meaning we can't rely on static constructors, as they could be invoked
// before those functions have been invoked. :-/
//
// Note that the above comment was removed from iOS 6.0+ documentation (and were not part of OSX docs AFAIK).
// It make sense since it's not possible to call those functions, from 6.0+ they will return NULL on devices,
// unless the application has been authorized to access the address book.
class InitConstants {
public static void Init () {}

static InitConstants ()
{
// ensure we can init.
CFObject.CFRelease (ABAddressBook.ABAddressBookCreate ());
// ensure we can init. This is needed before iOS6 (as per doc).
IntPtr p = ABAddressBook.ABAddressBookCreate ();

ABGroupProperty.Init ();
ABLabel.Init ();
Expand All @@ -89,6 +93,11 @@ static InitConstants ()
ABPersonRelatedNamesLabel.Init ();
ABPersonUrlLabel.Init ();
ABSourcePropertyId.Init ();

// From iOS 6.0+ this might return NULL, e.g. if the application is not authorized to access the
// address book, and we would crash if we tried to release a null pointer
if (p != IntPtr.Zero)
CFObject.CFRelease (p);
}
}

Expand Down
39 changes: 22 additions & 17 deletions src/AudioToolbox/AudioBuffers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,23 @@ public AudioBuffers (IntPtr address, bool owns)
this.owns = owns;
}

public AudioBuffers (int count)
public unsafe AudioBuffers (int count)
{
if (count < 0)
throw new ArgumentOutOfRangeException ("count");

var size = sizeof (int) + count * Marshal.SizeOf (typeof (AudioBuffer));
var size = sizeof (int) + count * sizeof (AudioBuffer);
address = Marshal.AllocHGlobal (size);
owns = true;

Marshal.WriteInt32 (address, 0, count);
for (int i = sizeof (int); i < size; i++)
Marshal.WriteByte (address, i, 0);
AudioBuffer *ptr = (AudioBuffer *) (((byte *) address) + sizeof (int));
for (int i = 0; i < count; i++){
ptr->NumberChannels = 0;
ptr->DataByteSize = 0;
ptr->Data = IntPtr.Zero;
ptr++;
}
}

~AudioBuffers ()
Expand All @@ -73,9 +78,9 @@ public AudioBuffers (int count)
GC.SuppressFinalize (this);
}

public int Count {
public unsafe int Count {
get {
return Marshal.ReadInt32 (address);
return *(int *) address;
}
}

Expand All @@ -96,8 +101,8 @@ public AudioBuffer this [int index] {
unsafe {
byte *baddress = (byte *) address;

var ptr = baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer));
return (AudioBuffer) Marshal.PtrToStructure ((IntPtr) ptr, typeof (AudioBuffer));
var ptr = baddress + sizeof (int) + index * sizeof (AudioBuffer);
return *(AudioBuffer *) ptr;
}
}
set {
Expand All @@ -106,10 +111,8 @@ public AudioBuffer this [int index] {

unsafe {
byte *baddress = (byte *) address;
var ptr = (IntPtr) (baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer)));
Marshal.WriteInt32 (ptr, value.NumberChannels);
Marshal.WriteInt32 (ptr, sizeof (int), value.DataByteSize);
Marshal.WriteIntPtr (ptr, sizeof (int) + sizeof (int), value.Data);
var ptr = (AudioBuffer *) (baddress + sizeof (int) + index * sizeof (AudioBuffer));
*ptr = value;
}
}
}
Expand All @@ -126,8 +129,8 @@ public void SetData (int index, IntPtr data)

unsafe {
byte * baddress = (byte *) address;
var ptr = (IntPtr)(baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer)) + sizeof (int) + sizeof (int));
Marshal.WriteIntPtr (ptr, data);
var ptr = (IntPtr *)(baddress + sizeof (int) + index * sizeof (AudioBuffer) + sizeof (int) + sizeof (int));
*ptr = data;
}
}

Expand All @@ -138,9 +141,11 @@ public void SetData (int index, IntPtr data, int dataByteSize)

unsafe {
byte *baddress = (byte *) address;
var ptr = (IntPtr)(baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer)) + sizeof (int));
Marshal.WriteInt32 (ptr, dataByteSize);
Marshal.WriteIntPtr (ptr, sizeof (int), data);
var ptr = (int *)(baddress + sizeof (int) + index * sizeof (AudioBuffer) + sizeof (int));
*ptr = dataByteSize;
ptr++;
IntPtr *iptr = (IntPtr *) ptr;
*iptr = data;
}
}

Expand Down
34 changes: 20 additions & 14 deletions src/AudioToolbox/AudioConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public enum AudioConverterPrimeMethod
None = 2
}

[StructLayout (LayoutKind.Sequential)]
public struct AudioConverterPrimeInfo
{
public int LeadingFrames;
Expand Down Expand Up @@ -185,10 +186,10 @@ public AudioConverterPrimeMethod PrimeMethod {
}
}

public AudioConverterPrimeInfo PrimeInfo {
public unsafe AudioConverterPrimeInfo PrimeInfo {
get {
AudioConverterPrimeInfo value;
var size = Marshal.SizeOf (typeof (AudioConverterPrimeInfo));
var size = sizeof (AudioConverterPrimeInfo);
var res = AudioConverterGetProperty (handle, AudioConverterPropertyID.PrimeInfo, ref size, out value);
if (res != AudioConverterError.None)
throw new ArgumentException (res.ToString ());
Expand Down Expand Up @@ -328,7 +329,7 @@ public AudioChannelLayoutTag[] AvailableEncodeChannelLayoutTags {
}
}

public AudioStreamBasicDescription CurrentOutputStreamDescription {
public unsafe AudioStreamBasicDescription CurrentOutputStreamDescription {
get {
int size;
bool writable;
Expand All @@ -341,13 +342,13 @@ public AudioStreamBasicDescription CurrentOutputStreamDescription {
if (res != AudioConverterError.None)
throw new ArgumentException (res.ToString ());

var asbd = (AudioStreamBasicDescription) Marshal.PtrToStructure (ptr, typeof (AudioStreamBasicDescription));
var asbd = *(AudioStreamBasicDescription *) ptr;
Marshal.FreeHGlobal (ptr);
return asbd;
}
}

public AudioStreamBasicDescription CurrentInputStreamDescription {
public unsafe AudioStreamBasicDescription CurrentInputStreamDescription {
get {
int size;
bool writable;
Expand All @@ -360,7 +361,7 @@ public AudioStreamBasicDescription CurrentInputStreamDescription {
if (res != AudioConverterError.None)
throw new ArgumentException (res.ToString ());

var asbd = (AudioStreamBasicDescription) Marshal.PtrToStructure (ptr, typeof (AudioStreamBasicDescription));
var asbd = *(AudioStreamBasicDescription*) ptr;
Marshal.FreeHGlobal (ptr);
return asbd;
}
Expand All @@ -375,9 +376,9 @@ public int BitDepthHint {
}
}

public AudioFormat[] FormatList {
public unsafe AudioFormat[] FormatList {
get {
return GetArray<AudioFormat> (AudioConverterPropertyID.PropertyFormatList, Marshal.SizeOf (typeof (AudioFormat)));
return GetArray<AudioFormat> (AudioConverterPropertyID.PropertyFormatList, sizeof (AudioFormat));
}
}

Expand Down Expand Up @@ -568,26 +569,31 @@ double GetDoubleProperty (AudioConverterPropertyID propertyID)
return value;
}

AudioValueRange[] GetAudioValueRange (AudioConverterPropertyID prop)
unsafe AudioValueRange[] GetAudioValueRange (AudioConverterPropertyID prop)
{
return GetArray<AudioValueRange> (prop, Marshal.SizeOf (typeof (AudioValueRange)));
return GetArray<AudioValueRange> (prop, sizeof (AudioValueRange));
}

unsafe T[] GetArray<T> (AudioConverterPropertyID prop, int elementSize) where T : struct
unsafe T[] GetArray<T> (AudioConverterPropertyID prop, int elementSize)
{
int size;
bool writable;
if (AudioConverterGetPropertyInfo (handle, prop, out size, out writable) != AudioConverterError.None)
return null;

var data = new T[size / elementSize];
fixed (T* ptr = &data[0]) {
var res = AudioConverterGetProperty (handle, prop, ref size, (IntPtr)ptr);
var data = new T [size / elementSize];
var array_handle = GCHandle.Alloc (data, GCHandleType.Pinned);

try {
var ptr = array_handle.AddrOfPinnedObject ();
var res = AudioConverterGetProperty (handle, prop, ref size, ptr);
if (res != 0)
return null;

Array.Resize (ref data, size / elementSize);
return data;
} finally {
array_handle.Free ();
}
}

Expand Down
40 changes: 21 additions & 19 deletions src/AudioToolbox/AudioFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public AudioFileMarker this [int index] {
// }
//
unsafe {
var ptr = (byte *) this.ptr + 2 * sizeof (int) + index * Marshal.SizeOf (typeof (AudioFileMarker));
return (AudioFileMarker) Marshal.PtrToStructure ((IntPtr) ptr, typeof (AudioFileMarker));
var ptr = (AudioFileMarker *) this.ptr + 2 * sizeof (int) + index * sizeof (AudioFileMarker);
return *ptr;
}
}
}
Expand Down Expand Up @@ -347,15 +347,15 @@ internal IntPtr NameWeak {
}
}

public AudioFileRegionFlags Flags {
public unsafe AudioFileRegionFlags Flags {
get {
return (AudioFileRegionFlags) Marshal.ReadInt32 (ptr, sizeof (uint) + Marshal.SizeOf (typeof (IntPtr)));
return (AudioFileRegionFlags) Marshal.ReadInt32 (ptr, sizeof (uint) + sizeof (IntPtr));
}
}

public int Count {
public unsafe int Count {
get {
return Marshal.ReadInt32 (ptr, 2 * sizeof (uint) + Marshal.SizeOf (typeof (IntPtr)));
return Marshal.ReadInt32 (ptr, 2 * sizeof (uint) + sizeof (IntPtr));
}
}

Expand All @@ -365,15 +365,15 @@ public AudioFileMarker this [int index] {
throw new ArgumentOutOfRangeException ("index");

unsafe {
var ptr = (byte *) this.ptr + 3 * sizeof (int) + Marshal.SizeOf (typeof (IntPtr)) + index * Marshal.SizeOf (typeof (AudioFileMarker));
return (AudioFileMarker) Marshal.PtrToStructure ((IntPtr) ptr, typeof (AudioFileMarker));
var ptr = (AudioFileMarker *) this.ptr + 3 * sizeof (int) + sizeof (IntPtr) + index * sizeof (AudioFileMarker);
return *ptr;
}
}
}

internal int TotalSize {
internal unsafe int TotalSize {
get {
return Count * Marshal.SizeOf (typeof (AudioFileMarker));
return Count * sizeof (AudioFileMarker);
}
}
}
Expand Down Expand Up @@ -991,7 +991,7 @@ public IntPtr GetProperty (AudioFileProperty property, out int size)
return IntPtr.Zero;
}

T? GetProperty<T> (AudioFileProperty property) where T : struct
unsafe T? GetProperty<T> (AudioFileProperty property) where T : struct
{
int size, writable;

Expand All @@ -1002,8 +1002,10 @@ public IntPtr GetProperty (AudioFileProperty property, out int size)
return null;
try {
var r = AudioFileGetProperty (handle, property, ref size, buffer);
if (r == 0)
return (T) Marshal.PtrToStructure (buffer, typeof (T));
if (r == 0){
T t = (T) Marshal.PtrToStructure (buffer, typeof (T));
return t;
}

return null;
} finally {
Expand Down Expand Up @@ -1258,7 +1260,7 @@ public AudioFileRegionList RegionList {
}
}

public AudioFilePacketTableInfo? PacketTableInfo {
public unsafe AudioFilePacketTableInfo? PacketTableInfo {
get {
return GetProperty<AudioFilePacketTableInfo> (AudioFileProperty.PacketTableInfo);
}
Expand All @@ -1267,7 +1269,7 @@ public AudioFilePacketTableInfo? PacketTableInfo {
throw new ArgumentNullException ("value");

AudioFilePacketTableInfo afpti = value.Value;
var res = AudioFileSetProperty (handle, AudioFileProperty.PacketTableInfo, Marshal.SizeOf (typeof (AudioFilePacketTableInfo)), ref afpti);
var res = AudioFileSetProperty (handle, AudioFileProperty.PacketTableInfo, sizeof (AudioFilePacketTableInfo), ref afpti);
if (res != 0)
throw new ArgumentException (res.ToString ());
}
Expand Down Expand Up @@ -1326,7 +1328,7 @@ public long PacketToFrame (long packet)

unsafe {
AudioFramePacketTranslation *p = &buffer;
int size = Marshal.SizeOf (buffer);
int size = sizeof (AudioFramePacketTranslation);
if (AudioFileGetProperty (handle, AudioFileProperty.PacketToFrame, ref size, (IntPtr) p) == 0)
return buffer.Frame;
return -1;
Expand All @@ -1340,7 +1342,7 @@ public long FrameToPacket (long frame, out int frameOffsetInPacket)

unsafe {
AudioFramePacketTranslation *p = &buffer;
int size = Marshal.SizeOf (buffer);
int size = sizeof (AudioFramePacketTranslation);
if (AudioFileGetProperty (handle, AudioFileProperty.FrameToPacket, ref size, (IntPtr) p) == 0){
frameOffsetInPacket = buffer.FrameOffsetInPacket;
return buffer.Packet;
Expand All @@ -1357,7 +1359,7 @@ public long PacketToByte (long packet, out bool isEstimate)

unsafe {
AudioBytePacketTranslation *p = &buffer;
int size = Marshal.SizeOf (buffer);
int size = sizeof (AudioBytePacketTranslation);
if (AudioFileGetProperty (handle, AudioFileProperty.PacketToByte, ref size, (IntPtr) p) == 0){
isEstimate = (buffer.Flags & BytePacketTranslationFlags.IsEstimate) != 0;
return buffer.Byte;
Expand All @@ -1374,7 +1376,7 @@ public long ByteToPacket (long byteval, out int byteOffsetInPacket, out bool isE

unsafe {
AudioBytePacketTranslation *p = &buffer;
int size = Marshal.SizeOf (buffer);
int size = sizeof (AudioBytePacketTranslation);
if (AudioFileGetProperty (handle, AudioFileProperty.ByteToPacket, ref size, (IntPtr) p) == 0){
isEstimate = (buffer.Flags & BytePacketTranslationFlags.IsEstimate) != 0;
byteOffsetInPacket = buffer.ByteOffsetInPacket;
Expand Down
Loading