Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Quincey Morris
On Feb 19, 2016, at 22:14 , Gerriet M. Denkmann  wrote:
> 
> Is there (yet) a Swift version of ‘[NSString stringWithFormat: “%08lx”, 
> (someCast) someValue]’ ?

No, and yes, and no, and yes.

There is currently AFAIK no such native formatting syntax in Swift print 
statements, so “no”.

But you can of course use ‘String (format: “%08lx”, someCast (someValue))’. 
This isn’t actually cheating, because Swift has its own implementation of the 
entire NSString API. There’s no bridging to NSString objects involved in these 
functions, so “yes”.

But you can’t *use* this API in Swift unless you import Foundation. Without the 
import, Swift will pretend it doesn’t have those String APIs, though it really 
does, so “no”.

But starting with Swift 3, later this year, Foundation will migrate natively 
into Swift — for all supported Swift platforms, such as Linux — so I assume 
there will be some kind of native String formatting syntax, so “yes”, though 
whether it will use the same format strings as Cocoa, I don’t know.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Roland King

> On 20 Feb 2016, at 14:14, Gerriet M. Denkmann  wrote:
> 
> 
>> On 20 Feb 2016, at 13:02, Quincey Morris 
>>  wrote:
>> 
>> On Feb 19, 2016, at 21:30 , Gerriet M. Denkmann  wrote:
>> 
>> Now that I code almost exclusively in Swift, the problem has largely 
>> disappeared, because ‘“\(someValue)"' is a lot easier*** than ‘[NSString 
>> stringWithFormat: "%lu", (someCast) someValue]’.
> 
> Is there (yet) a Swift version of ‘[NSString stringWithFormat: “%08lx”, 
> (someCast) someValue]’ ?
> Last time I checked, this was the only way to print formatted strings.
> 
> Kind regards,

var str = String( format: "%08lx", 123 )
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Gerriet M. Denkmann

> On 20 Feb 2016, at 13:02, Quincey Morris 
>  wrote:
> 
> On Feb 19, 2016, at 21:30 , Gerriet M. Denkmann  wrote:
> 
>  Now that I code almost exclusively in Swift, the problem has largely 
> disappeared, because ‘“\(someValue)"' is a lot easier*** than ‘[NSString 
> stringWithFormat: "%lu", (someCast) someValue]’.

Is there (yet) a Swift version of ‘[NSString stringWithFormat: “%08lx”, 
(someCast) someValue]’ ?
Last time I checked, this was the only way to print formatted strings.

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Quincey Morris
On Feb 19, 2016, at 21:30 , Gerriet M. Denkmann  wrote:
> 
> One can NOT force NSUInteger to be different sizes. It will always be 4 bytes 
> on 32 bit systems, and 8 bytes on 64 bit ones.
> 
> 32 bit without DNS_BUILD_32_LIKE_64 
>   NSUInteger = int; 
> 32 bit with DNS_BUILD_32_LIKE_64 
>   NSUInteger = long (but long = int)
> 
> 64 bit (regardless of DNS_BUILD_32_LIKE_64)
>   NSUInteger = long (but long > int)

Ah, yes, sorry, I forgot. It’s not about the length, it’s about the type. But 
then I think NS_BUILD_32_LIKE_64  is doubly useless:

— The difference between int and long is itself ABI-breaking. The Obj-C runtime 
encodes types as single characters, and int and long may encode as different 
characters, even when they have the same length. This is going to break stuff. 
That’s why NS_BUILD_32_LIKE_64 was an option you had to choose to use — it 
breaks ABI compatibility with 3rd-party frameworks that existed before the 
transition, or were compiled with non-NS_BUILD_32_LIKE_64 rules after the 
transition.

— The issue with string formats is about the number of bytes, not the 
compile-time type, because it’s about the way arg lists are constructed by the 
compiler. Again, its correctness depends on external knowledge that NSUInteger 
and long are the same number of bytes, which I claim is a (minor) drawback to 
your approach**. Apple’s recommendation is correct absolutely because “%lu" 
*matches* ‘long’ and “(long) anyValue” *is* long. You don’t need to know what 
long (or NSUInteger) is.


** I admit, that’s exactly the approach I used from about 2006 to 2008, happy 
to avoid casting the variables. Once the iOS SDK appeared, I started casting 
again. Later, I switched over to %tu and stopped casting. Now that I code 
almost exclusively in Swift, the problem has largely disappeared, because 
‘"\(someValue)"' is a lot easier*** than ‘[NSString stringWithFormat: "%lu", 
(someCast) someValue]’.

*** Although, AFAIK, the Swift formatting is currently unlocalized, whereas 
NSString formatting of numeric values has been localized for the last 2-3 
years. This may be something that affects you.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Gerriet M. Denkmann

> On 20 Feb 2016, at 11:59, Quincey Morris 
>  wrote:
> 
> On Feb 19, 2016, at 20:43 , Gerriet M. Denkmann  wrote:
>> 
>> This:
>>  UIDevice *theDevice = [UIDevice currentDevice]; 
>>  NSLog(@“%s NSUInteger %lu bytes on %@“,__FUNCTION__, 
>> sizeof(NSUInteger), theDevice.localizedModel);
>> 
>> prints:
>>  -[AppDelegate application:didFinishLaunchingWithOptions:] NSUInteger 4 
>> bytes on iPhone (iPone 4s in Simulator)
>>  -[AppDelegate application:didFinishLaunchingWithOptions:] NSUInteger 8 
>> bytes on iPad (iPad Air in Simulator)
> 
> I’m not sure what that proves. Yes, NSUInteger is different sizes for 
> different iOS architectures. What I said was that if you could force 
> NSUInteger to be 8 bytes instead of 4 bytes on iOS (using 
> NS_BUILD_32_LIKE_64), then the app would crash on an architecture where 
> system frameworks knew NSUInteger to be 4 bytes.


Sorry about being not very clear. One can NOT force NSUInteger to be different 
sizes. It will always be 4 bytes on 32 bit systems, and 8 bytes on 64 bit ones.

32 bit without DNS_BUILD_32_LIKE_64 
NSUInteger = int; 
32 bit with DNS_BUILD_32_LIKE_64 
NSUInteger = long (but long = int)

64 bit (regardless of DNS_BUILD_32_LIKE_64)
NSUInteger = long (but long > int)
> 
>> With DNS_BUILD_32_LIKE_64 NSUInteger is long on all platforms, so %lu works 
>> in all cases.
> 
> Can you demonstrate NS_BUILD_32_LIKE_64 making NSUInteger 8 bytes for the 
> iPhone 4s?

Sorry, as I said above, this cannot be done.

> 
> You also need to be careful about demonstrating architectural claims on a 
> simulator. It’s an iOS simulator, but it’s an OS X platform, which is why you 
> can’t [legally] lipo together simulator and device dylibs into a single 
> framework, to the annoyance of many 3rd-party framework developers.

Without the complication of Simulators:
NSUInteger 4 bytes on “พาย" = iPad 3rd Generation (iPad); iOS 9.2.1
NSUInteger 8 bytes on "โพยม" = iPad Air(Wifi) (iPad); iOS 9.2.1


Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Quincey Morris
On Feb 19, 2016, at 20:43 , Gerriet M. Denkmann  wrote:
> 
> This:
>   UIDevice *theDevice = [UIDevice currentDevice]; 
>   NSLog(@“%s NSUInteger %lu bytes on %@“,__FUNCTION__, 
> sizeof(NSUInteger), theDevice.localizedModel);
> 
> prints:
>   -[AppDelegate application:didFinishLaunchingWithOptions:] NSUInteger 4 
> bytes on iPhone (iPone 4s in Simulator)
>   -[AppDelegate application:didFinishLaunchingWithOptions:] NSUInteger 8 
> bytes on iPad (iPad Air in Simulator)

I’m not sure what that proves. Yes, NSUInteger is different sizes for different 
iOS architectures. What I said was that if you could force NSUInteger to be 8 
bytes instead of 4 bytes on iOS (using NS_BUILD_32_LIKE_64), then the app would 
crash on an architecture where system frameworks knew NSUInteger to be 4 bytes. 
(On Macs that support 32-bit and 64-bit apps, there are two versions of every 
framework, so this would only be a problem on iOS.)

> With DNS_BUILD_32_LIKE_64 NSUInteger is long on all platforms, so %lu works 
> in all cases.

Can you demonstrate NS_BUILD_32_LIKE_64 making NSUInteger 8 bytes for the 
iPhone 4s?

You also need to be careful about demonstrating architectural claims on a 
simulator. It’s an iOS simulator, but it’s an OS X platform, which is why you 
can’t [legally] lipo together simulator and device dylibs into a single 
framework, to the annoyance of many 3rd-party framework developers.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Gerriet M. Denkmann

> On 20 Feb 2016, at 11:24, Quincey Morris 
>  wrote:
> 
> On Feb 19, 2016, at 19:00 , Gerriet M. Denkmann  wrote:
>> 
>> I use Other C Flags: -DNS_BUILD_32_LIKE_64=1
> 
> AFAIK this is a Mac-only thing. I don’t believe it works on a 32-bit iOS 
> platform, in particular because I don’t believe there are any 64-bit system 
> frameworks on such a system. There’d be an ABI mismatch.

This:
UIDevice *theDevice = [UIDevice currentDevice]; 
NSLog(@“%s NSUInteger %lu bytes on %@“,__FUNCTION__, 
sizeof(NSUInteger), theDevice.localizedModel);

prints:
-[AppDelegate application:didFinishLaunchingWithOptions:] NSUInteger 4 
bytes on iPhone (iPone 4s in Simulator)
-[AppDelegate application:didFinishLaunchingWithOptions:] NSUInteger 8 
bytes on iPad (iPad Air in Simulator)


> 
> Also (I could be wrong but) I don’t think it was ever in the iOS SDK.
> 
> The point about Apple’s %ld/(long) recommendation was that it replaced a 
> source code construct that was correct only via knowledge of the architecture 
> it was compiled for, with a construct that was correct for all platforms.

With DNS_BUILD_32_LIKE_64 NSUInteger is long on all platforms, so %lu works in 
all cases.


Kind regards,

Gerriet.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Quincey Morris
On Feb 19, 2016, at 19:00 , Gerriet M. Denkmann  wrote:
> 
> I use Other C Flags: -DNS_BUILD_32_LIKE_64=1

AFAIK this is a Mac-only thing. I don’t believe it works on a 32-bit iOS 
platform, in particular because I don’t believe there are any 64-bit system 
frameworks on such a system. There’d be an ABI mismatch.

Also (I could be wrong but) I don’t think it was ever in the iOS SDK.

The point about Apple's %ld/(long) recommendation was that it replaced a source 
code construct that was correct only via knowledge of the architecture it was 
compiled for, with a construct that was correct for all platforms.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Gerriet M. Denkmann

> On 20 Feb 2016, at 06:32,Charles Srstka  wrote:
> 
> 
> 
>> On Feb 19, 2016, at 4:29 PM, Jens Alfke  wrote:
>> 
>> NSInteger is a typedef of ‘long’ in 64-bit, and ‘int’ in 32-bit.
>> You’re correct that %d should be used for NSInteger in 32-bit.
> 
> The recommended way to use an NSInteger, as per Apple documentation, is to 
> use %ld and explicitly cast it to long.
> 
> NSLog(@“foo is %ld”, (long)foo);
> 
> This will work regardless of platform.
> 
> For NSUInteger, you use %lu and cast to unsigned long.

I use Other C Flags: -DNS_BUILD_32_LIKE_64=1
with this:
NSLog(@“array size %lu”, someArray.size )
works fine both for 32 and 64 bit; no warnings or errors.


Gerriet.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Marco S Hyman

>> On Feb 19, 2016, at 4:29 PM, Jens Alfke  wrote:
>> 
>> NSInteger is a typedef of ‘long’ in 64-bit, and ‘int’ in 32-bit.
>> You’re correct that %d should be used for NSInteger in 32-bit.
> 
> The recommended way to use an NSInteger, as per Apple documentation, is to 
> use %ld and explicitly cast it to long.
> 
> NSLog(@“foo is %ld”, (long)foo);
> 
> This will work regardless of platform.
> 
> For NSUInteger, you use %lu and cast to unsigned long.

This was posted on the xcode list a while back by Quincey Morris:

"As suggested by Greg Parker on this list a couple of years ago, you can use

%t… (%td, %to, %tu %tx, %tX) for unsigned results
%z… (%zd, %zo, %zu %zx, %zX) for signed results

and these work on NS[U]Integer-sized variables on all platforms and
architectures that are supported by Apple (without having to cast the 
parameters).”

They are documented in (all version I think) of the String Programming Guide.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Charles Srstka
> On Feb 19, 2016, at 4:29 PM, Jens Alfke  wrote:
> 
> NSInteger is a typedef of ‘long’ in 64-bit, and ‘int’ in 32-bit.
> You’re correct that %d should be used for NSInteger in 32-bit.

The recommended way to use an NSInteger, as per Apple documentation, is to use 
%ld and explicitly cast it to long.

NSLog(@“foo is %ld”, (long)foo);

This will work regardless of platform.

For NSUInteger, you use %lu and cast to unsigned long.

Source: 
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW5
 

> The whole variable-size NS[U]Integer thing is awful, especially for anyone 
> writing code that needs to support both 32-bit and 64-bit. One trick I 
> recently heard about that helps somewhat is to use %zd and %zu to format it — 
> the ‘z’ modifier indicates the value is a size_t or ssize_t, and it turns out 
> those have the same size as NS[U]Integers.

As long as you cast it as shown above, it’s no issue at all, and it’s better to 
do that than to rely on implementation details such as these.

> (Here’s one reason NSInteger sucks: the difference in sizes doesn’t make 
> sense for values that don’t refer to memory sizes. For example, is it OK use 
> NSUInteger to store a file size? In a 64-bit process, sure! In a 32-bit one, 
> you’ll be fine until you encounter a file > 4GB long, then you overflow and 
> get the size wrong. Likewise, how about using NSUInteger to store an index 
> into a persistent array? Bad idea if the persistence layer supports >4 
> billion items, which any real database does.)

In cases where it matters what size the integer is, you should use use an 
explicitly sized type (like uint64_t, here). For the common case where the size 
doesn’t really matter, NS(U)Integer will use whatever size of integer the 
processor natively handles, which is good for performance.

Charles
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Sean McBride
On Fri, 19 Feb 2016 14:29:03 -0800, Jens Alfke said:

>(Here’s one reason NSInteger sucks: the difference in sizes doesn’t make
>sense for values that don’t refer to memory sizes. For example, is it OK
>use NSUInteger to store a file size? In a 64-bit process, sure! In a 32-
>bit one, you’ll be fine until you encounter a file > 4GB long, then you
>overflow and get the size wrong.

Which is why API that deal with file sizes don't use NSUInteger.  It doesn't 
mean NSInteger sucks, it's just a 'right tool for right job' kind of thing.

Cheers,

-- 

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com 
Mac Software Developer  Montréal, Québec, Canada

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Jens Alfke

> On Feb 19, 2016, at 1:44 PM, Jean-Daniel Dupas  wrote:
> 
> Not exactly. %d is for 32 bit signed integer,

Not exactly ;) %d is for “int”, whose size is unspecified. It does happen to be 
32 bits on Apple platforms with current compilers. (I still remember the “fun” 
period of the early ‘90s when some Mac C compilers had 16-bit ints and some had 
32-bit.)

> but %ld is for signed long, and so is the right formatter for NSInteger value 
> (which is a typedef alias of long) and 64 bit integer on 64 bit platform.

NSInteger is a typedef of ‘long’ in 64-bit, and ‘int’ in 32-bit.
You’re correct that %d should be used for NSInteger in 32-bit.

The whole variable-size NS[U]Integer thing is awful, especially for anyone 
writing code that needs to support both 32-bit and 64-bit. One trick I recently 
heard about that helps somewhat is to use %zd and %zu to format it — the ‘z’ 
modifier indicates the value is a size_t or ssize_t, and it turns out those 
have the same size as NS[U]Integers.

(Here’s one reason NSInteger sucks: the difference in sizes doesn’t make sense 
for values that don’t refer to memory sizes. For example, is it OK use 
NSUInteger to store a file size? In a 64-bit process, sure! In a 32-bit one, 
you’ll be fine until you encounter a file > 4GB long, then you overflow and get 
the size wrong. Likewise, how about using NSUInteger to store an index into a 
persistent array? Bad idea if the persistence layer supports >4 billion items, 
which any real database does.)

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Jim Adams
It really was the wrong format specifier. Turns out the crash was on the next 
line where I used %d and %@ together. The -1 was an indicator of the issue but 
not the cause of my crash.

Thanks for the quick look. I will try that warning flag. I haven’t changed any 
of those flags so it may very well be warning me.

On Feb 19, 2016, at 4:44 PM, Jean-Daniel Dupas 
> wrote:


Le 19 févr. 2016 à 22:29, Jens Alfke 
> a écrit :


On Feb 19, 2016, at 1:17 PM, Jim Adams 
> wrote:

 SLogInfo(@"Starting csi %ld count %d", csi, sortedEvents.count);

In the console I see:
INFO: Starting csi -1 count -1
The very next line crashes when the sortedEvents are accessed. What could cause 
the array to have a -1 count?

You’re using the wrong format strings for both of those parameters.

csi is 64-bit so you need %lld. The formatter sees %ld and thinks it’s 32-bit 
not 64-bit, so it skips the wrong amount of space on the stack when going to 
the next parameter, which is why you then get a bogus value for the count.

Also, NSArray.count is of type NSUInteger, which is unsigned, and has different 
sizes on different platforms. The right format specifier is either %lu (in a 
32-bit app) or %llu (in 64-bit).

Not exactly. %d is for 32 bit signed integer, but %ld is for signed long, and 
so is the right formatter for NSInteger value (which is a typedef alias of 
long) and 64 bit integer on 64 bit platform.

%lld is for signed long long and is the same as long for most platform.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Jean-Daniel Dupas

> Le 19 févr. 2016 à 22:29, Jens Alfke  a écrit :
> 
> 
>> On Feb 19, 2016, at 1:17 PM, Jim Adams  wrote:
>> 
>>   SLogInfo(@"Starting csi %ld count %d", csi, sortedEvents.count);
>> 
>> In the console I see:
>> INFO: Starting csi -1 count -1
>> The very next line crashes when the sortedEvents are accessed. What could 
>> cause the array to have a -1 count?
> 
> You’re using the wrong format strings for both of those parameters.
> 
> csi is 64-bit so you need %lld. The formatter sees %ld and thinks it’s 32-bit 
> not 64-bit, so it skips the wrong amount of space on the stack when going to 
> the next parameter, which is why you then get a bogus value for the count.
> 
> Also, NSArray.count is of type NSUInteger, which is unsigned, and has 
> different sizes on different platforms. The right format specifier is either 
> %lu (in a 32-bit app) or %llu (in 64-bit).

Not exactly. %d is for 32 bit signed integer, but %ld is for signed long, and 
so is the right formatter for NSInteger value (which is a typedef alias of 
long) and 64 bit integer on 64 bit platform.

%lld is for signed long long and is the same as long for most platform.




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Sandor Szatmari
Jim,

> On Feb 19, 2016, at 16:17, Jim Adams  wrote:
> 
> I have code that looks like the following:
> 
> NSArray *sortedEvents = [events.eventSet sortedArrayUsingDescriptors:[NSArray 
> arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"date" 
> ascending:YES]]];
>int64_t csi = -1LL;
> 
>SLogInfo(@"Starting csi %ld count %d", csi, sortedEvents.count);
> 
> In the console I see:
> INFO: Starting csi -1 count -1
> The very next line crashes when the sortedEvents are accessed. What could 
> cause the array to have a -1 count?
The return type of -[NSArray count] is NSUInteger so no it is not negative one. 
 But you are logging it with %d which is for signed integers.  So, certain 
unsigned values would log as negative one,  unsigned max comes to mind as its 
twos complement should be negative one when interpreted as signed.

Sandor

> 
> 
> Note that I am seeing this in a release build so debugging is very difficult.
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Can an NSArray ever have a count of -1?

2016-02-19 Thread Jens Alfke

> On Feb 19, 2016, at 1:17 PM, Jim Adams  wrote:
> 
>SLogInfo(@"Starting csi %ld count %d", csi, sortedEvents.count);
> 
> In the console I see:
> INFO: Starting csi -1 count -1
> The very next line crashes when the sortedEvents are accessed. What could 
> cause the array to have a -1 count?

You’re using the wrong format strings for both of those parameters.

csi is 64-bit so you need %lld. The formatter sees %ld and thinks it’s 32-bit 
not 64-bit, so it skips the wrong amount of space on the stack when going to 
the next parameter, which is why you then get a bogus value for the count.

Also, NSArray.count is of type NSUInteger, which is unsigned, and has different 
sizes on different platforms. The right format specifier is either %lu (in a 
32-bit app) or %llu (in 64-bit).

FYI, You must be ignoring compiler warnings, or you've turned off the “type 
check printf” warning setting. Don’t do that ;) I always strongly recommend 
turning on “Treat warnings as errors”, which will force you to fix warnings. 
This is very useful because a number of compiler warnings are actually nasty 
and hard-to-find errors like the above.

—Jens

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Can an NSArray ever have a count of -1?

2016-02-19 Thread Jim Adams
I have code that looks like the following:

NSArray *sortedEvents = [events.eventSet sortedArrayUsingDescriptors:[NSArray 
arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"date" 
ascending:YES]]];
int64_t csi = -1LL;

SLogInfo(@"Starting csi %ld count %d", csi, sortedEvents.count);

In the console I see:
INFO: Starting csi -1 count -1
The very next line crashes when the sortedEvents are accessed. What could cause 
the array to have a -1 count?


Note that I am seeing this in a release build so debugging is very difficult.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Breakpoints: Swift Error

2016-02-19 Thread Quincey Morris
On Feb 19, 2016, at 11:20 , Eric E. Dolecki  wrote:
> 
> Yes, it's in the AVAudioPlayer init.

Which is a very interesting fact, because it suggests that the frameworks are 
using Swift code. I wasn’t aware that Apple had begun using Swift in actual 
frameworks yet, but I guess it had to start sometime.

> I do have a catch, and it never gets there. Things stop on that player 
> instantiation.

So it’s probably a case of the initializer trying some variations of the URL. 
(I wouldn’t be surprised if it played games with the file extension.) The 
errors are only transient in a case like that.

> I've turned the breakpoint off for now and things seem to be working 
> perfectly.

If you need the breakpoint, you may just have to get used to continuing from 
there, every time.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Breakpoints: Swift Error

2016-02-19 Thread Eric E. Dolecki
Yes, it's in the AVAudioPlayer init. I do have a catch, and it never gets
there. Things stop on that player instantiation. I've turned the breakpoint
off for now and things seem to be working perfectly. I have a post on the
Apple Dev Forum about it as well. Thanks for your input!

On Fri, Feb 19, 2016 at 2:08 PM Quincey Morris <
quinceymor...@rivergatesoftware.com> wrote:

> On Feb 19, 2016, at 10:45 , Eric E. Dolecki  wrote:
>
>
> I have an app where I have a breakpoint set for Swift Error. If it's on and
> I run the debug app, I get the breakpoint for a crash.
>
> try player = AVAudioPlayer(contentsOfURL: url)
>
>
> What, according to the backtrace, is the point of the error, where the
> throw is? Is the throw inside the AVAudioPlayer init at least?
>
> Note that since you have a ‘try’, you have a ‘catch’ somewhere. If an
> error is being returned to you, you should be able to see it somewhere. If
> necessary, you can enclose *this* try in a do-catch construct — to get an
> immediate look at the error — and then end the catch block with ‘throw
> error’ to rethrow.
>
> Unfortunately, using a Swift error breakpoint opens up the possibility of
> the debugger stopping on errors handled internally by the Cocoa frameworks,
> which is an annoyance for debugging your code. (You often see this problem
> when debugging system frameworks, such as the security framework, which are
> written in C++, where exceptions are also used for flow control, if you
> leave a C++ exception breakpoint enabled.)
>
> The other thing to verify is that it’s stopping on a Swift error, not an
> Obj-C exception. In an app I’m currently debugging, I turned on the Obj-C
> exception breakpoint, and now it stops when instantiating a document window
> controller from the main storyboard. It’s something handled internally
> apparently, if I continue, everything is OK.
>
> Lastly, when the debugger stops on an Obj-C exception, it usually hasn’t
> printed the error message to the console yet. If the error is repeatable,
> it’s worth clicking the Continue button (several times if necessary) to
> give the error a chance to be logged. If there’s nothing logged, then this
> may be a break you just need to ignore.
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Breakpoints: Swift Error

2016-02-19 Thread Quincey Morris
On Feb 19, 2016, at 10:45 , Eric E. Dolecki  wrote:
> 
> I have an app where I have a breakpoint set for Swift Error. If it's on and
> I run the debug app, I get the breakpoint for a crash.
> 
> try player = AVAudioPlayer(contentsOfURL: url)

What, according to the backtrace, is the point of the error, where the throw 
is? Is the throw inside the AVAudioPlayer init at least?

Note that since you have a ‘try’, you have a ‘catch’ somewhere. If an error is 
being returned to you, you should be able to see it somewhere. If necessary, 
you can enclose *this* try in a do-catch construct — to get an immediate look 
at the error — and then end the catch block with ‘throw error’ to rethrow.

Unfortunately, using a Swift error breakpoint opens up the possibility of the 
debugger stopping on errors handled internally by the Cocoa frameworks, which 
is an annoyance for debugging your code. (You often see this problem when 
debugging system frameworks, such as the security framework, which are written 
in C++, where exceptions are also used for flow control, if you leave a C++ 
exception breakpoint enabled.)

The other thing to verify is that it’s stopping on a Swift error, not an Obj-C 
exception. In an app I’m currently debugging, I turned on the Obj-C exception 
breakpoint, and now it stops when instantiating a document window controller 
from the main storyboard. It’s something handled internally apparently, if I 
continue, everything is OK.

Lastly, when the debugger stops on an Obj-C exception, it usually hasn’t 
printed the error message to the console yet. If the error is repeatable, it’s 
worth clicking the Continue button (several times if necessary) to give the 
error a chance to be logged. If there’s nothing logged, then this may be a 
break you just need to ignore.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Breakpoints: Swift Error

2016-02-19 Thread Eric E. Dolecki
I have an app where I have a breakpoint set for Swift Error. If it's on and
I run the debug app, I get the breakpoint for a crash.

try player = AVAudioPlayer(contentsOfURL: url)
The url is fine.

If I turn the breakpoint off, it runs and debugs perfectly fine. Could this
be a bug in Xcode? Is there a way to get more info out of the Swift Error
breakpoint?

Eric
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com