Merge lp://staging/~chasedouglas/frame/generic into lp://staging/frame
Status: | Merged |
---|---|
Merged at revision: | 54 |
Proposed branch: | lp://staging/~chasedouglas/frame/generic |
Merge into: | lp://staging/frame |
Diff against target: | 0 lines |
To merge this branch: | bzr merge lp://staging/~chasedouglas/frame/generic |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stephen M. Webb (community) | Approve | ||
Jussi Pakkanen (community) | Approve | ||
Chase Douglas (community) | Needs Resubmitting | ||
Review via email: mp+86873@code.staging.launchpad.net |
Description of the change
I found out about C11's new _Generic feature. I decided to make Jussi happy and add type checking support to the utouch-frame property getters.
With these changes, we now have compile-time and runtime checks for proper data types passed in by reference. For example:
// Succeeds, returns UFStatusSuccess
UFEventType type;
status = frame_event_
// Fails to compile because no event properties are of type char
char test1;
status = frame_event_
// Fails at runtime because UFDevice is not the correct type for UFEventProperty
UFDevice test2;
status = frame_event_
This should all be backwards compatible with correctly written code. However, runtime checking is a bit pedantic. For example, using an unsigned int instead of an int will produce an error. This also adds internal functions to the API, so the version was bumped.
Unfortunately, GCC doesn't support _Generic yet. Clang 3.0 does, but there is a libstdc++ bug that prevents Clang from compiling any code that uses std::shared_ptr. Upstream libstdc++ has the fix, but it has not been backported to gcc 4.6 yet. So, the easiest way to test is:
1. Install "clang" on Precise (11.10 and earlier have old versions of Clang that don't have _Generic)
2. Add ppa:chasedougla
3. Configure with "clang" as the compilers: CC=clang CXX=clang ./configure --prefix=/usr --with-xi
4. Run make as normal
Having these checks is better than not having them, but I still strongly prefer type safe proper functions that are guaranteed to not fail ever.
Documentation on _Generic on the internets is quite sparse, so I can't really comment on the implementation all that much. However there are some minor issues.
You use
#if !__has_ extension( c_generic_ selections) /* See frame_internal.h */
in several places. This should be checked only one (in a configure test?) and put in a config.h as HAS_GENERIC_ SELECTIONS or somesuch.
Redefining compiler behaviour with #define __has_extension(x) 0 in a public header feels extremely suspicious.
There are no unit tests for the runtime failure. Can you test that a piece of code does not compile with gtest?