locale, initWithLocaleIdentifier_("en_US") bug?

I am using macosx 10.8.2 and Xcode 4.5.2 and the following code line (from Shane’s examples) is giving problems:

  setLocale_(current application's NSLocale's alloc()'s initWithLocaleIdentifier_("en_US"))

Here a part of the crash message:

0x7fff8a9d6080: pushq %rbp
0x7fff8a9d6081: movq %rsp, %rbp
0x7fff8a9d6084: pushq %rbx
0x7fff8a9d6085: pushq %rax
0x7fff8a9d6086: movq %rdi, %rbx
0x7fff8a9d6089: testq %rbx, %rbx
0x7fff8a9d608c: jne 0x7fff8a9d60ae ; CFRetain + 46
0x7fff8a9d608e: leaq 1620375(%rip), %rax ; “*** CFRetain() called with NULL ***”
0x7fff8a9d6095: movq %rax, 2285484(%rip)
0x7fff8a9d609c: int3

Is this a known bug with the NSLocale under 10.8.xx (because i tried other methods within) but it keeps crashing.
Under 10.7 this was no problem.

Model: macbook Pro
Browser: Safari 536.25
Operating System: Mac OS X (10.8)

it’s working fine here. You don’t give any context for your code or error. Try reworking your code as separate steps, to locate exactly where the crash is happening.

Hi Shane,

To test I created a very simple app like this:

script AppDelegate
	property parent : class "NSObject"
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened
		log formatNumber_decimals_(1.23456, 2)
	end applicationWillFinishLaunching_
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	property theFormatter : missing value
	on formatNumber_decimals_(n, decimals)
		if my theFormatter = missing value then
			set my theFormatter to current application's NSNumberFormatter's alloc()'s init()
			tell my theFormatter
				setLocale_(current application's NSLocale's alloc()'s initWithLocaleIdentifier_("en_US"))
				setNumberStyle_(current application's NSNumberFormatterDecimalStyle)
				setRoundingMode_(current application's NSNumberFormatterRoundHalfUp)
			end tell
		end if
		set theresult to theFormatter's stringFromNumber_(n)
		return theresult
	end formatNumber_decimals_
end script

In the settings i have Objective-C Automatic Reference Counting set to Yes

When the line : setLocale_(current application’s NSLocale’s alloc()'s initWithLocaleIdentifier_(“en_US”)) is active then I get the following crash

CoreFoundation`-[__NSCFLocale retain]:
0x7fff8aa874f0: pushq %rbp
0x7fff8aa874f1: movq %rsp, %rbp
0x7fff8aa874f4: pushq %rbx
0x7fff8aa874f5: pushq %rax
0x7fff8aa874f6: movq %rdi, %rbx
0x7fff8aa874f9: movq %rbx, %rdi
0x7fff8aa874fc: callq 0x7fff8a9d6080 ; CFRetain
0x7fff8aa87501: movq %rbx, %rax
0x7fff8aa87504: addq $8, %rsp
0x7fff8aa87508: popq %rbx
0x7fff8aa87509: popq %rbp
0x7fff8aa8750a: ret
0x7fff8aa8750b: nopl (%rax,%rax)

When the line is commented then it runs without errors.
I hope you can find out what that could be!?

First thing to do is break it down something like this:

set theLocale to current application's NSLocale's alloc()'s initWithLocaleIdentifier_("en_US")
log "After local call"
tell my theFormatter

Hi Shane,

I tried your suggestion and the result is unfortunately the same.
The code does not reach the log statement.
The crash result is :

CoreFoundation`-[__NSCFLocale retain]:
0x7fff976524f0: pushq %rbp
0x7fff976524f1: movq %rsp, %rbp
0x7fff976524f4: pushq %rbx
0x7fff976524f5: pushq %rax
0x7fff976524f6: movq %rdi, %rbx
0x7fff976524f9: movq %rbx, %rdi
0x7fff976524fc: callq 0x7fff975a1080 ; CFRetain
0x7fff97652501: movq %rbx, %rax
0x7fff97652504: addq $8, %rsp
0x7fff97652508: popq %rbx
0x7fff97652509: popq %rbp
0x7fff9765250a: ret
0x7fff9765250b: nopl (%rax,%rax)

Looks like a real bug?

Yes – please make sure you report it to bugreporter.

The workaround is probably going to require some Objective-C.

I reported this bug to Apple.
I got an answer that the bug is a duplicate.
I suppose it was already reported by somebody else.
Now we will wait till it is solved.

It was :wink: