kCFBooleanTrue

Mac OSX specific forum
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

kCFBooleanTrue

Post by Rinzwind »

I just came across this crazy code:

Code: Select all

Global.i kCFBooleanTrue
Global.i kCFBooleanFalse
!mov rax, qword [kCFBooleanTruePtr]
!mov rdx, qword [kCFBooleanFalsePtr]
!mov rax, [rax]
!mov rdx, [rdx]
!mov [v_kCFBooleanTrue], rax
!mov [v_kCFBooleanFalse], rdx
DataSection
   !extern _kCFBooleanTrue
   !extern _kCFBooleanFalse
   !kCFBooleanTruePtr: dq _kCFBooleanTrue
   !kCFBooleanFalsePtr: dq _kCFBooleanFalse
EndDataSection
Isn't it time for PB to include a predefined kCFBooleanTrue and kCFBooleanFalse on macOS if it's such a 'difficult' value?
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: kCFBooleanTrue

Post by Rinzwind »

Well, there is a huge discrepancy between build-in Windows constants and macOS ones...
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: kCFBooleanTrue

Post by wilbert »

The problem is that something like kCFBooleanTrue is not a simple value but an object.

This will return the same by the way.

Code: Select all

Global.i kCFBooleanTrue = PeekI(dlsym_(#RTLD_DEFAULT, "kCFBooleanTrue"))
Global.i kCFBooleanFalse = PeekI(dlsym_(#RTLD_DEFAULT, "kCFBooleanFalse"))

Debug kCFBooleanTrue
Debug kCFBooleanFalse
And NSNumber can also be used.

Code: Select all

Debug CocoaMessage(0, 0, "NSNumber numberWithBool:", #YES)
Debug CocoaMessage(0, 0, "NSNumber numberWithBool:", #NO)
Windows (x64)
Raspberry Pi OS (Arm64)
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: kCFBooleanTrue

Post by Rinzwind »

Ah that looks much better. Makes this topic useful because I only found ASM code in the forum.
Thanks
Post Reply