kaiserfarrell / core-plot

Automatically exported from code.google.com/p/core-plot
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Conditional compilation for multiple OS versions #422

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Compile the current trunk in XCode 3.

What is the expected output? What do you see instead?

The code should compile as is, but does not.

What version of the product are you using? On what operating system?

Compiling with XCode 3 and 4 on OS Lion. Current trunk.

Please provide any additional information below.

As I wrote in my e-mail:

the latest code has introduced a problem with conditional compilation. In 
CPTCalendarFormatter.m

-(NSString *)stringForObjectValue:(NSDecimalNumber *)coordinateValue

you are checking for 10.7, however this cannot work in XCode 3, because 
MAC_OS_X_VERSION_10_7 is not defined there. So line 182 should probably look 
like:

#if MAC_OS_X_VERSION_10_6 < MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_4_0 < 
__IPHONE_OS_VERSION_MAX_ALLOWED

But this is not the only problem here. When I compile code with such 
conditionals in XC4, where my deployment target is set to 10.6 but the base SDK 
is 10.7 (so I can create binaries that work on 10.6 still, but can use new 
features on 10.7 when running them there), code wrapped the way you did it in 
coreplot will access not available features when running on 10.6 and most 
probably crash. Hence the full solutions must look like this (here for the new 
full screen feature on lion):

        int macVersion;
        if (Gestalt(gestaltSystemVersion, &macVersion) == noErr) {
            runningOnLionOrLater = macVersion > MAC_OS_X_VERSION_10_6;
        }

    // Setup full screen mode support on Lion+.
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6
    if (runningOnLionOrLater) {
        [mainWindow setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
        [toggleFullscreenItem setHidden: NO];
    }
#endif

There are different ways to determine the current OS an app is running on, but 
this seems to be one of the simplest.

Original issue reported on code.google.com by mike.lischke on 7 Apr 2012 at 9:20

GoogleCodeExporter commented 8 years ago
Issue 427 has been merged into this issue.

Original comment by eskr...@mac.com on 17 Apr 2012 at 10:05

GoogleCodeExporter commented 8 years ago

Original comment by eskr...@mac.com on 18 Apr 2012 at 1:24

GoogleCodeExporter commented 8 years ago
What should Core Plot do if you use one of the options that's not available on 
the system running the code (e.g., NSWeekOfMonthCalendarUnit pre-10.7)? Log an 
error and ignore it? Throw an exception? Implement equivalent functionality so 
it works the same on all systems?

Original comment by eskr...@mac.com on 18 Apr 2012 at 1:39

GoogleCodeExporter commented 8 years ago
When you wrap this code with the current OS check (like my runningOnLionOrLater 
above) then it will never be executed on 10.6. In this case the app would 
behave as if it was compiled with XC3. If it did not have trouble without this 
new feature then there is no need to log or throw an error. The new feature is 
simply not available in this scenario.

Original comment by mike.lischke on 18 Apr 2012 at 7:54

GoogleCodeExporter commented 8 years ago
The problem code is part of a switch statement. Some of the options are only 
available on later systems. Something that builds and runs fine on Lion won't 
work on Snow Leopard if it uses one of those options. If we throw an exception, 
that should show up when testing the app on the earlier system and it will be 
up to the developer to find another option if they want to support that system 
version.

My gut feeling is to just throw an exception in this situation. A developer 
targeting the earlier systems should be aware of the NSDateComponents options 
that aren't supported on the targeted system.

Original comment by eskr...@mac.com on 19 Apr 2012 at 12:19

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 4d200c6985a9.

Original comment by eskr...@mac.com on 19 Apr 2012 at 1:14