Skip to content

Commit bb8efeb

Browse files
committed
Ruby: Rename RSHIFT to RB_RSHIFT, temporarily
When Ruby attempts to load the FFmpeg header files, it'll complain that RSHIFT is redefined if the Ruby definition is still in place. So, we define RB_RSHIFT to contain the Ruby definition, undef RSHIFT, load the FFmpeg headers, move its RSHIFT into FF_RSHIFT if necessary, and then restore Ruby's RSHIFT from RB_RSHIFT.
1 parent f2db5fd commit bb8efeb

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/bindings/ruby/openshot.i

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ namespace std {
5757

5858

5959
%{
60+
/* Ruby and FFmpeg define competing RSHIFT macros,
61+
* so we move Ruby's out of the way for now. We'll
62+
* restore it after dealing with FFmpeg's
63+
*/
64+
#ifdef RSHIFT
65+
#define RB_RSHIFT(a, b) RSHIFT(a, b)
66+
#undef RSHIFT
67+
#endif
6068
#include "../../../include/Version.h"
6169
#include "../../../include/ReaderBase.h"
6270
#include "../../../include/WriterBase.h"
@@ -91,7 +99,15 @@ namespace std {
9199
#include "../../../include/Settings.h"
92100
#include "../../../include/Timeline.h"
93101
#include "../../../include/ZmqLogger.h"
94-
102+
/* Move FFmpeg's RSHIFT to FF_RSHIFT, if present */
103+
#ifdef RSHIFT
104+
#define FF_RSHIFT(a, b) RSHIFT(a, b)
105+
#undef RSHIFT
106+
#endif
107+
/* And restore Ruby's RSHIFT, if we captured it */
108+
#ifdef RB_RSHIFT
109+
#define RSHIFT(a, b) RB_RSHIFT(a, b)
110+
#endif
95111
%}
96112

97113
#ifdef USE_BLACKMAGIC
@@ -132,8 +148,29 @@ namespace std {
132148
%include "../../../include/EffectInfo.h"
133149
%include "../../../include/Enums.h"
134150
%include "../../../include/Exceptions.h"
151+
152+
/* Ruby and FFmpeg define competing RSHIFT macros,
153+
* so we move Ruby's out of the way for now. We'll
154+
* restore it after dealing with FFmpeg's
155+
*/
156+
#ifdef RSHIFT
157+
#define RB_RSHIFT(a, b) RSHIFT(a, b)
158+
#undef RSHIFT
159+
#endif
160+
135161
%include "../../../include/FFmpegReader.h"
136162
%include "../../../include/FFmpegWriter.h"
163+
164+
/* Move FFmpeg's RSHIFT to FF_RSHIFT, if present */
165+
#ifdef RSHIFT
166+
#define FF_RSHIFT(a, b) RSHIFT(a, b)
167+
#undef RSHIFT
168+
#endif
169+
/* And restore Ruby's RSHIFT, if we captured it */
170+
#ifdef RB_RSHIFT
171+
#define RSHIFT(a, b) RB_RSHIFT(a, b)
172+
#endif
173+
137174
%include "../../../include/Fraction.h"
138175
%include "../../../include/Frame.h"
139176
%include "../../../include/FrameMapper.h"

0 commit comments

Comments
 (0)