Skip to content

Commit b26fac8

Browse files
Joris Vankerschaverjreback
Joris Vankerschaver
authored andcommitted
DEV: Add static modifier to inline declarations.
It is currently impossible to build a debug version of Pandas on Mac OS, since some of the C function declarations are declared as `inline`, and compiling in debug mode turns off optimizations and hence inlining. While this could be solved by adding a compile argument to `setup.py` to use the C89 behavior for inline as in pandas-dev#10510, I believe an ultimately cleaner solution may consist of declaring inlined functions as `static`, so that the code is properly C99-compliant. For the implementation, I added the `static` keyword to the definitions of `PANDAS_INLINE` and `P_INLINE` (and removed duplicate occurrences of `static` from some function declarations), so that future implementations that use those defines are automatically compliant. This is slightly different from e.g. Cython, which defines `CYTHON_INLINE` as `inline` and declares everything as `static CYTHON_INLINE`. Author: Joris Vankerschaver <[email protected]> Closes pandas-dev#12123 from jvkersch/dev/static-inline and squashes the following commits: 6a225e7 [Joris Vankerschaver] MAINT: Remove compile flag that is no longer needed. a5138f0 [Joris Vankerschaver] DEV: Add static modifier to inline declarations.
1 parent 1d2f0a7 commit b26fac8

File tree

10 files changed

+41
-58
lines changed

10 files changed

+41
-58
lines changed

doc/source/whatsnew/v0.18.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,5 @@ of columns didn't match the number of series provided (:issue:`12039`).
538538

539539
- Bug in ``.loc`` setitem indexer preventing the use of a TZ-aware DatetimeIndex (:issue:`12050`)
540540
- Big in ``.style`` indexes and multi-indexes not appearing (:issue:`11655`)
541+
542+
- Bug in building Pandas with debugging symbols (:issue:`12123`)

pandas/src/helper.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
#ifndef PANDAS_INLINE
55
#if defined(__GNUC__)
6-
#define PANDAS_INLINE __inline__
6+
#define PANDAS_INLINE static __inline__
77
#elif defined(_MSC_VER)
8-
#define PANDAS_INLINE __inline
8+
#define PANDAS_INLINE static __inline
99
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
10-
#define PANDAS_INLINE inline
10+
#define PANDAS_INLINE static inline
1111
#else
1212
#define PANDAS_INLINE
1313
#endif

pandas/src/klib/khash.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ typedef double khfloat64_t;
132132

133133
#ifndef PANDAS_INLINE
134134
#if defined(__GNUC__)
135-
#define PANDAS_INLINE __inline__
135+
#define PANDAS_INLINE static __inline__
136136
#elif defined(_MSC_VER)
137-
#define PANDAS_INLINE __inline
137+
#define PANDAS_INLINE static __inline
138138
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
139-
#define PANDAS_INLINE inline
139+
#define PANDAS_INLINE static inline
140140
#else
141141
#define PANDAS_INLINE
142142
#endif
@@ -324,7 +324,7 @@ static const double __ac_HASH_UPPER = 0.77;
324324
}
325325

326326
#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
327-
KHASH_INIT2(name, static PANDAS_INLINE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
327+
KHASH_INIT2(name, PANDAS_INLINE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
328328

329329
/* --- BEGIN OF HASH FUNCTIONS --- */
330330

@@ -354,7 +354,7 @@ static const double __ac_HASH_UPPER = 0.77;
354354
@param s Pointer to a null terminated string
355355
@return The hash value
356356
*/
357-
static PANDAS_INLINE khint_t __ac_X31_hash_string(const char *s)
357+
PANDAS_INLINE khint_t __ac_X31_hash_string(const char *s)
358358
{
359359
khint_t h = *s;
360360
if (h) for (++s ; *s; ++s) h = (h << 5) - h + *s;
@@ -371,7 +371,7 @@ static PANDAS_INLINE khint_t __ac_X31_hash_string(const char *s)
371371
*/
372372
#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0)
373373

374-
static PANDAS_INLINE khint_t __ac_Wang_hash(khint_t key)
374+
PANDAS_INLINE khint_t __ac_Wang_hash(khint_t key)
375375
{
376376
key += ~(key << 15);
377377
key ^= (key >> 10);

pandas/src/klib/kvec.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ int main() {
5454

5555
#ifndef PANDAS_INLINE
5656
#if defined(__GNUC__)
57-
#define PANDAS_INLINE __inline__
57+
#define PANDAS_INLINE static __inline__
5858
#elif defined(_MSC_VER)
59-
#define PANDAS_INLINE __inline
59+
#define PANDAS_INLINE static __inline
6060
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
61-
#define PANDAS_INLINE inline
61+
#define PANDAS_INLINE static inline
6262
#else
6363
#define PANDAS_INLINE
6464
#endif

pandas/src/parser/tokenizer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static int push_char(parser_t *self, char c) {
408408
return 0;
409409
}
410410

411-
static int P_INLINE end_field(parser_t *self) {
411+
int P_INLINE end_field(parser_t *self) {
412412
// XXX cruft
413413
// self->numeric_field = 0;
414414
if (self->words_len >= self->words_cap) {

pandas/src/parser/tokenizer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ See LICENSE for the license
4141

4242
#ifndef P_INLINE
4343
#if defined(__GNUC__)
44-
#define P_INLINE __inline__
44+
#define P_INLINE static __inline__
4545
#elif defined(_MSC_VER)
4646
#define P_INLINE
4747
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
48-
#define P_INLINE inline
48+
#define P_INLINE static inline
4949
#else
5050
#define P_INLINE
5151
#endif

pandas/src/period_helper.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,19 @@ static int daytime_conversion_factors[][2] = {
283283

284284
static npy_int64** daytime_conversion_factor_matrix = NULL;
285285

286-
PANDAS_INLINE static int max_value(int a, int b) {
286+
PANDAS_INLINE int max_value(int a, int b) {
287287
return a > b ? a : b;
288288
}
289289

290-
PANDAS_INLINE static int min_value(int a, int b) {
290+
PANDAS_INLINE int min_value(int a, int b) {
291291
return a < b ? a : b;
292292
}
293293

294-
PANDAS_INLINE static int get_freq_group(int freq) {
294+
PANDAS_INLINE int get_freq_group(int freq) {
295295
return (freq/1000)*1000;
296296
}
297297

298-
PANDAS_INLINE static int get_freq_group_index(int freq) {
298+
PANDAS_INLINE int get_freq_group_index(int freq) {
299299
return freq/1000;
300300
}
301301

@@ -399,7 +399,7 @@ PANDAS_INLINE npy_int64 downsample_daytime(npy_int64 ordinal, asfreq_info *af_in
399399
return ordinal / (af_info->intraday_conversion_factor);
400400
}
401401

402-
PANDAS_INLINE static npy_int64 transform_via_day(npy_int64 ordinal, char relation, asfreq_info *af_info, freq_conv_func first_func, freq_conv_func second_func) {
402+
PANDAS_INLINE npy_int64 transform_via_day(npy_int64 ordinal, char relation, asfreq_info *af_info, freq_conv_func first_func, freq_conv_func second_func) {
403403
//printf("transform_via_day(%ld, %ld, %d)\n", ordinal, af_info->intraday_conversion_factor, af_info->intraday_conversion_upsample);
404404
npy_int64 result;
405405

pandas/src/skiplist.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818

1919
#ifndef PANDAS_INLINE
2020
#if defined(__GNUC__)
21-
#define PANDAS_INLINE __inline__
21+
#define PANDAS_INLINE static __inline__
2222
#elif defined(_MSC_VER)
23-
#define PANDAS_INLINE __inline
23+
#define PANDAS_INLINE static __inline
2424
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
25-
#define PANDAS_INLINE inline
25+
#define PANDAS_INLINE static inline
2626
#else
2727
#define PANDAS_INLINE
2828
#endif
2929
#endif
3030

31-
PANDAS_INLINE static float __skiplist_nanf(void)
31+
PANDAS_INLINE float __skiplist_nanf(void)
3232
{
3333
const union { int __i; float __f;} __bint = {0x7fc00000UL};
3434
return __bint.__f;
3535
}
3636
#define PANDAS_NAN ((double) __skiplist_nanf())
3737

3838

39-
static PANDAS_INLINE double Log2(double val) {
39+
PANDAS_INLINE double Log2(double val) {
4040
return log(val) / log(2.);
4141
}
4242

@@ -59,15 +59,15 @@ typedef struct {
5959
int maxlevels;
6060
} skiplist_t;
6161

62-
static PANDAS_INLINE double urand(void) {
62+
PANDAS_INLINE double urand(void) {
6363
return ((double) rand() + 1) / ((double) RAND_MAX + 2);
6464
}
6565

66-
static PANDAS_INLINE int int_min(int a, int b) {
66+
PANDAS_INLINE int int_min(int a, int b) {
6767
return a < b ? a : b;
6868
}
6969

70-
static PANDAS_INLINE node_t *node_init(double value, int levels) {
70+
PANDAS_INLINE node_t *node_init(double value, int levels) {
7171
node_t *result;
7272
result = (node_t*) malloc(sizeof(node_t));
7373
if (result) {
@@ -88,11 +88,11 @@ static PANDAS_INLINE node_t *node_init(double value, int levels) {
8888
}
8989

9090
// do this ourselves
91-
static PANDAS_INLINE void node_incref(node_t *node) {
91+
PANDAS_INLINE void node_incref(node_t *node) {
9292
++(node->ref_count);
9393
}
9494

95-
static PANDAS_INLINE void node_decref(node_t *node) {
95+
PANDAS_INLINE void node_decref(node_t *node) {
9696
--(node->ref_count);
9797
}
9898

@@ -115,7 +115,7 @@ static void node_destroy(node_t *node) {
115115
}
116116
}
117117

118-
static PANDAS_INLINE void skiplist_destroy(skiplist_t *skp) {
118+
PANDAS_INLINE void skiplist_destroy(skiplist_t *skp) {
119119
if (skp) {
120120
node_destroy(skp->head);
121121
free(skp->tmp_steps);
@@ -124,7 +124,7 @@ static PANDAS_INLINE void skiplist_destroy(skiplist_t *skp) {
124124
}
125125
}
126126

127-
static PANDAS_INLINE skiplist_t *skiplist_init(int expected_size) {
127+
PANDAS_INLINE skiplist_t *skiplist_init(int expected_size) {
128128
skiplist_t *result;
129129
node_t *NIL, *head;
130130
int maxlevels, i;
@@ -163,7 +163,7 @@ static PANDAS_INLINE skiplist_t *skiplist_init(int expected_size) {
163163
}
164164

165165
// 1 if left < right, 0 if left == right, -1 if left > right
166-
static PANDAS_INLINE int _node_cmp(node_t* node, double value){
166+
PANDAS_INLINE int _node_cmp(node_t* node, double value){
167167
if (node->is_nil || node->value > value) {
168168
return -1;
169169
}
@@ -175,7 +175,7 @@ static PANDAS_INLINE int _node_cmp(node_t* node, double value){
175175
}
176176
}
177177

178-
static PANDAS_INLINE double skiplist_get(skiplist_t *skp, int i, int *ret) {
178+
PANDAS_INLINE double skiplist_get(skiplist_t *skp, int i, int *ret) {
179179
node_t *node;
180180
int level;
181181

@@ -199,7 +199,7 @@ static PANDAS_INLINE double skiplist_get(skiplist_t *skp, int i, int *ret) {
199199
return node->value;
200200
}
201201

202-
static PANDAS_INLINE int skiplist_insert(skiplist_t *skp, double value) {
202+
PANDAS_INLINE int skiplist_insert(skiplist_t *skp, double value) {
203203
node_t *node, *prevnode, *newnode, *next_at_level;
204204
int *steps_at_level;
205205
int size, steps, level;
@@ -253,7 +253,7 @@ static PANDAS_INLINE int skiplist_insert(skiplist_t *skp, double value) {
253253
return 1;
254254
}
255255

256-
static PANDAS_INLINE int skiplist_remove(skiplist_t *skp, double value) {
256+
PANDAS_INLINE int skiplist_remove(skiplist_t *skp, double value) {
257257
int level, size;
258258
node_t *node, *prevnode, *tmpnode, *next_at_level;
259259
node_t **chain;

pandas/src/ujson/lib/ultrajson.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ typedef __int64 JSLONG;
9595

9696
#define FASTCALL_MSVC __fastcall
9797
#define FASTCALL_ATTR
98-
#define INLINE_PREFIX __inline
98+
#define INLINE_PREFIX static __inline
9999

100100
#else
101101

@@ -114,7 +114,7 @@ typedef uint32_t JSUINT32;
114114
#define FASTCALL_ATTR
115115
#endif
116116

117-
#define INLINE_PREFIX inline
117+
#define INLINE_PREFIX static inline
118118

119119
typedef uint8_t JSUINT8;
120120
typedef uint16_t JSUTF16;

setup.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def run(self):
290290
class CheckingBuildExt(build_ext):
291291
"""
292292
Subclass build_ext to get clearer report if Cython is necessary.
293-
Also, add some platform based compiler flags.
293+
294294
"""
295295

296296
def check_cython_extensions(self, extensions):
@@ -304,27 +304,8 @@ def check_cython_extensions(self, extensions):
304304

305305
def build_extensions(self):
306306
self.check_cython_extensions(self.extensions)
307-
self.add_gnu_inline_flag(self.extensions)
308307
build_ext.build_extensions(self)
309308

310-
def add_gnu_inline_flag(self, extensions):
311-
'''
312-
Add CFLAGS `-fgnu89-inline` for clang on FreeBSD 10+
313-
'''
314-
if not platform.system() == 'FreeBSD':
315-
return
316-
317-
try:
318-
bsd_release = float(platform.release().split('-')[0])
319-
except ValueError: # unknow freebsd version
320-
return
321-
322-
if bsd_release < 10: # 9 or earlier still using gcc42
323-
return
324-
325-
for ext in extensions:
326-
ext.extra_compile_args += ['-fgnu89-inline']
327-
328309

329310
class CythonCommand(build_ext):
330311
"""Custom distutils command subclassed from Cython.Distutils.build_ext

0 commit comments

Comments
 (0)