Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent data type #100

Merged
merged 2 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 6 additions & 6 deletions src/BugsnagUnity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const char *bugsnag_getReleaseStage(const void *configuration);

void bugsnag_setNotifyReleaseStages(const void *configuration, const char *releaseStages[], int releaseStagesCount);
void bugsnag_getNotifyReleaseStages(const void *configuration, const void *managedConfiguration, void (*callback)(const void *instance, const char *releaseStages[], NSUInteger size));
void bugsnag_getNotifyReleaseStages(const void *configuration, const void *managedConfiguration, void (*callback)(const void *instance, const char *releaseStages[], int size));

void bugsnag_setAppVersion(const void *configuration, char *appVersion);
const char *bugsnag_getAppVersion(const void *configuration);
Expand All @@ -35,7 +35,7 @@

void *bugsnag_createBreadcrumbs(const void *configuration);
void bugsnag_addBreadcrumb(const void *breadcrumbs, char *name, char *type, char *metadata[], int metadataCount);
void bugsnag_retrieveBreadcrumbs(const void *breadcrumbs, const void *managedBreadcrumbs, void (*breadcrumb)(const void *instance, const char *name, const char *timestamp, const char *type, const char *keys[], NSUInteger keys_size, const char *values[], NSUInteger values_size));
void bugsnag_retrieveBreadcrumbs(const void *breadcrumbs, const void *managedBreadcrumbs, void (*breadcrumb)(const void *instance, const char *name, const char *timestamp, const char *type, const char *keys[], int keys_size, const char *values[], int values_size));

void bugsnag_retrieveAppData(const void *appData, void (*callback)(const void *instance, const char *key, const char *value));
void bugsnag_retrieveDeviceData(const void *deviceData, void (*callback)(const void *instance, const char *key, const char *value));
Expand Down Expand Up @@ -71,9 +71,9 @@ void bugsnag_setNotifyReleaseStages(const void *configuration, const char *relea
((__bridge BugsnagConfiguration *)configuration).notifyReleaseStages = ns_releaseStages;
}

void bugsnag_getNotifyReleaseStages(const void *configuration, const void *managedConfiguration, void (*callback)(const void *instance, const char *releaseStages[], NSUInteger size)) {
void bugsnag_getNotifyReleaseStages(const void *configuration, const void *managedConfiguration, void (*callback)(const void *instance, const char *releaseStages[], int size)) {
NSArray *releaseStages = ((__bridge BugsnagConfiguration *)configuration).notifyReleaseStages;
NSUInteger count = [releaseStages count];
int count = [NSNumber numberWithUnsignedInteger: [releaseStages count]].intValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing a step here, but is there a reason we can't convert using:

int count = (int)[releaseStages count];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the recommendation from @kattrali. @kattrali are you able to give a quick comment here on why this is a better approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our quick chat, I wasn't quite sure what "layer" the number was coming from - but knew that would cover your bases. A cast should be fine as presumably there aren't that many release stages?

const char **c_releaseStages = (const char **) malloc(sizeof(char *) * (count + 1));

for (NSUInteger i = 0; i < count; i++) {
Expand Down Expand Up @@ -167,7 +167,7 @@ void bugsnag_addBreadcrumb(const void *breadcrumbs, char *name, char *type, char
}];
}

void bugsnag_retrieveBreadcrumbs(const void *breadcrumbs, const void *managedBreadcrumbs, void (*breadcrumb)(const void *instance, const char *name, const char *timestamp, const char *type, const char *keys[], NSUInteger keys_size, const char *values[], NSUInteger values_size)) {
void bugsnag_retrieveBreadcrumbs(const void *breadcrumbs, const void *managedBreadcrumbs, void (*breadcrumb)(const void *instance, const char *name, const char *timestamp, const char *type, const char *keys[], int keys_size, const char *values[], int values_size)) {
NSArray *crumbs = [((__bridge BugsnagBreadcrumbs *) breadcrumbs) arrayValue];
[crumbs enumerateObjectsUsingBlock:^(id crumb, NSUInteger index, BOOL *stop){
const char *name = [[crumb valueForKey: @"name"] UTF8String];
Expand All @@ -179,7 +179,7 @@ void bugsnag_retrieveBreadcrumbs(const void *breadcrumbs, const void *managedBre
NSArray *keys = [metadata allKeys];
NSArray *values = [metadata allValues];

NSUInteger count = [keys count];
int count = [NSNumber numberWithUnsignedInteger: [keys count]].intValue;
const char **c_keys = (const char **) malloc(sizeof(char *) * (count + 1));
const char **c_values = (const char **) malloc(sizeof(char *) * (count + 1));

Expand Down
2 changes: 1 addition & 1 deletion src/BugsnagUnity/Native/Cocoa/Breadcrumbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Breadcrumb[] Retrieve()
}

[MonoPInvokeCallback(typeof(NativeCode.BreadcrumbInformation))]
static void PopulateBreadcrumb(IntPtr instance, string name, string timestamp, string type, string[] keys, long keysSize, string[] values, long valuesSize)
static void PopulateBreadcrumb(IntPtr instance, string name, string timestamp, string type, string[] keys, int keysSize, string[] values, int valuesSize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is switching from long to int going to be causing issues or impacts elsewhere? Do we know why it was initially a long?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not, there will probably be bigger issues if we have more keys in our breadcrumb metadata than int max. It was initially long as I only had 64 bit devices available to test on and NSUInteger changes depending on the architecture of the device

{
var handle = GCHandle.FromIntPtr(instance);
if (handle.Target is List<Breadcrumb> breadcrumbs)
Expand Down
2 changes: 1 addition & 1 deletion src/BugsnagUnity/Native/Cocoa/NativeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ partial class NativeCode
[DllImport(Import)]
internal static extern void bugsnag_addBreadcrumb(IntPtr breadcrumbs, string name, string type, string[] metadata, int metadataCount);

internal delegate void BreadcrumbInformation(IntPtr instance, string name, string timestamp, string type, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)]string[] keys, long keysSize, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 7)]string[] values, long valuesSize);
internal delegate void BreadcrumbInformation(IntPtr instance, string name, string timestamp, string type, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)]string[] keys, int keysSize, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 7)]string[] values, int valuesSize);

[DllImport(Import)]
internal static extern void bugsnag_retrieveBreadcrumbs(IntPtr breadcrumbs, IntPtr instance, BreadcrumbInformation visitor);
Expand Down