Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified the FFI by eliminating public static inline functions #79

Closed
wants to merge 4 commits into from
Closed

Unified the FFI by eliminating public static inline functions #79

wants to merge 4 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 21, 2014

The FFI no longer consists of function pointers, which makes it much easier to import them in other programs/languages. Public functions that were declared static inline are now just inline and exported in a seperate translation unit, as recommended by section 6.7.4 of the ISO C standard

Something similar was already noted in include/chipmunk/chipmunk_ffi.h:

// TODO: get rid of the reliance on static inlines.
// They make a mess for FFIs.

Legacy function pointers are still supported, though the use of
-DCHIPMUNK_LEGACY_FFI. An additional option in cmake makes it easy to
enable or disable this feature. Eventually, it can be removed completely.

There were also a few inlude-directives in src/ that were inconsistent with some other files; I have changed them to what I thought they should be.

Tested on Ubuntu 14.04 with GCC 4.8.2.

Under the assumption that it does not declares a public interface of any
kind, but rather defines pointers to functions when compiling.
A separate translation unit is now responsible for generating exports,
as recommended by section 6.7.4 of the ISO C standard

This completes the task in *include/chipmunk/chipmunk_ffi.h*:

    // TODO: get rid of the reliance on static inlines.
    // They make a mess for FFIs.

Legacy function pointers are still supported, though the use of
-DCHIPMUNK_LEGACY_FFI. An additional option in cmake makes it easy to
enable or disable this feature. Eventually, it can be removed completely.
@ghost ghost changed the title Got rid of FFI function pointers by eliminating public static inline functions Unified the FFI by eliminating public static inline functions Jul 21, 2014
@andrewrk
Copy link
Contributor

@samvv This fixes compilation errors with building chipmunk library, but the demos still have a compilation error. Do they need to be updated to the new API?

In file included from /home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDemo.h:22:0,
                 from /home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:23:
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:22:1: error: unknown type name ‘cpSpaceDebugColor’
 static inline cpSpaceDebugColor RGBAColor(float r, float g, float b, float a){
 ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h: In function ‘RGBAColor’:
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:23:2: error: unknown type name ‘cpSpaceDebugColor’
  cpSpaceDebugColor color = {r, g, b, a};
  ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:23:2: warning: excess elements in scalar initializer [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:23:2: warning: (near initialization for ‘color’) [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:23:2: warning: excess elements in scalar initializer [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:23:2: warning: (near initialization for ‘color’) [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:23:2: warning: excess elements in scalar initializer [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:23:2: warning: (near initialization for ‘color’) [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h: At top level:
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:27:1: error: unknown type name ‘cpSpaceDebugColor’
 static inline cpSpaceDebugColor LAColor(float l, float a){
 ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h: In function ‘LAColor’:
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:28:2: error: unknown type name ‘cpSpaceDebugColor’
  cpSpaceDebugColor color = {l, l, l, a};
  ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:28:2: warning: excess elements in scalar initializer [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:28:2: warning: (near initialization for ‘color’) [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:28:2: warning: excess elements in scalar initializer [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:28:2: warning: (near initialization for ‘color’) [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:28:2: warning: excess elements in scalar initializer [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:28:2: warning: (near initialization for ‘color’) [enabled by default]
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h: At top level:
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:37:73: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawCircle(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
                                                                         ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:37:105: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawCircle(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
                                                                                                         ^
In file included from /home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDemo.h:22:0,
                 from /home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:23:
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:38:51: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawSegment(cpVect a, cpVect b, cpSpaceDebugColor color);
                                                   ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:39:70: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
                                                                      ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:39:102: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
                                                                                                      ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:40:79: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawPolygon(int count, const cpVect *verts, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
                                                                               ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:40:111: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawPolygon(int count, const cpVect *verts, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor);
                                                                                                               ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:41:53: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawDot(cpFloat size, cpVect pos, cpSpaceDebugColor fillColor);
                                                     ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDebugDraw.h:42:35: error: unknown type name ‘cpSpaceDebugColor’
 void ChipmunkDebugDrawBB(cpBB bb, cpSpaceDebugColor outlineColor);
                                   ^
In file included from /home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:23:0:
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDemo.h:64:1: error: unknown type name ‘cpShapeFilter’
 extern cpShapeFilter GRAB_FILTER;
 ^
/home/andy/Downloads/Chipmunk2D/Demo/ChipmunkDemo.h:65:1: error: unknown type name ‘cpShapeFilter’
 extern cpShapeFilter NOT_GRABBABLE_FILTER;
 ^
/home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c: In function ‘add_domino’:
/home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:42:2: warning: implicit declaration of function ‘cpBodySetPosition’ [-Wimplicit-function-declaration]
  cpBodySetPosition(body, pos);
  ^
/home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:44:2: error: too many arguments to function ‘cpBoxShapeNew’
  cpShape *shape = (flipped ? cpBoxShapeNew(body, HEIGHT, WIDTH, 0.0) : cpBoxShapeNew(body, WIDTH - radius*2.0f, HEIGHT, radius));
  ^
In file included from /usr/include/chipmunk/chipmunk.h:106:0,
                 from /home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:22:
/usr/include/chipmunk/cpPolyShape.h:54:10: note: declared here
 cpShape* cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height);
          ^
/home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:44:2: error: too many arguments to function ‘cpBoxShapeNew’
  cpShape *shape = (flipped ? cpBoxShapeNew(body, HEIGHT, WIDTH, 0.0) : cpBoxShapeNew(body, WIDTH - radius*2.0f, HEIGHT, radius));
  ^
In file included from /usr/include/chipmunk/chipmunk.h:106:0,
                 from /home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:22:
/usr/include/chipmunk/cpPolyShape.h:54:10: note: declared here
 cpShape* cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height);
          ^
/home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c: In function ‘init’:
/home/andy/Downloads/Chipmunk2D/Demo/PyramidTopple.c:63:2: warning: implicit declaration of function ‘cpShapeSetFilter’ [-Wimplicit-function-declaration]
  cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
  ^
make[2]: *** [Demo/CMakeFiles/chipmunk_demos.dir/PyramidTopple.c.o] Error 1
make[1]: *** [Demo/CMakeFiles/chipmunk_demos.dir/all] Error 2
make: *** [all] Error 2

@ghost
Copy link
Author

ghost commented Aug 11, 2014

@andrewrk You're right, totally forgot to test it on the demos! I will look into it when I have the time.

@ghost
Copy link
Author

ghost commented Feb 11, 2015

Just a minor feedback since this is already frozen since august: if someone still wants to see this added he or she will have to look into it, because I won't, unfortunately.

@ghost
Copy link
Author

ghost commented Nov 2, 2016

Found some time; see the new pull #139 for a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants