Another function of unknown function



  • Another machine-specific function from a library I'm working with. The first comment is the official description of what the function does; the next two are the results of my investigation.

    /* Returns the platform device */
    
    /* Doesn't actually return the drawing device: it's used as an accessor for 
    the_device->machine_ref, which happens to be an HDC on Windows and a GrafPtr on
    Mac. */
    
    /* Also has unspecified side effects in preparing the device for drawing.
    Sometimes it's called for the side effects alone, and the function return is
    discarded.  Sometimes it's called for the function result alone, and the side
    effects are discarded. */
    
    generic_var pgGetPlatformDevice (graf_device_ptr the_device)


  • So to "discard" the unknown side effects, you have to save the entire contents of memory and restore it after running the function?  Then get the value you returned back into your program which has just seen time turn backwards and is about to call the offending function?



  • The side effects aren't unknown, they're unspecified. There's no documentation anywhere of what side effects this function is supposed to have, but it's quite clear what side effects it does have. Discarding them consists of following the call to pgGetPlatformDevice() with its counterpart: pgReleasePlatformDevice() (which isn't documented either), which, given the nature of the side effects, makes for a very slow way of doing "x = the_device->machine_ref".



  • @Carnildo said:


    /* Doesn't actually return the drawing device: it's used as an accessor for
    the_device->machine_ref, which happens to be an HDC on Windows and a GrafPtr on
    Mac. */

    GrafPtr? SERIOUSLY? Might be time to upgrade your library...



  • @teqman said:

    @Carnildo said:
    /* Doesn't actually return the drawing device: it's used as an accessor for
    the_device->machine_ref, which happens to be an HDC on Windows and a GrafPtr on
    Mac. */

    GrafPtr? SERIOUSLY? Might be time to upgrade your library...


    It was on the to-do list until Apple dropped the entire Carbon API. It's now on the "to do when Hell freezes over" list. There's no point in upgrading from one obsolete API to another, and re-writing the entire library in Cocoa is too much work.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.