Commit 96aafb08 authored by Stefan Behnel's avatar Stefan Behnel

keep C++ code out of C files and vice-versa by splitting module preamble...

keep C++ code out of C files and vice-versa by splitting module preamble (original patch by Lars Mans)
parent 736d715f
...@@ -562,6 +562,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -562,6 +562,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_cvariable_declarations(module, modulecode, defined_here) self.generate_cvariable_declarations(module, modulecode, defined_here)
self.generate_cfunction_declarations(module, modulecode, defined_here) self.generate_cfunction_declarations(module, modulecode, defined_here)
def _put_setup_code(self, code, name):
code.put(UtilityCode.load_as_string(name, "ModuleSetupCode.c")[1])
def generate_module_preamble(self, env, cimported_modules, metadata, code): def generate_module_preamble(self, env, cimported_modules, metadata, code):
code.put_generated_by() code.put_generated_by()
if metadata: if metadata:
...@@ -583,7 +586,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -583,7 +586,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
from .. import __version__ from .. import __version__
code.putln('#define CYTHON_ABI "%s"' % __version__.replace('.', '_')) code.putln('#define CYTHON_ABI "%s"' % __version__.replace('.', '_'))
code.put(UtilityCode.load_as_string("CModulePreamble", "ModuleSetupCode.c")[1]) self._put_setup_code(code, "CModulePreamble")
if env.context.options.cplus:
self._put_setup_code(code, "CppInitCode")
else:
self._put_setup_code(code, "CInitCode")
self._put_setup_code(code, "MathInitCode")
code.put(""" code.put("""
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
...@@ -603,11 +611,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -603,11 +611,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_extern_c_macro_definition(code) self.generate_extern_c_macro_definition(code)
code.putln("") code.putln("")
code.putln("#if defined(WIN32) || defined(MS_WINDOWS)")
code.putln("#define _USE_MATH_DEFINES")
code.putln("#endif")
code.putln("#include <math.h>")
code.putln("#define %s" % Naming.h_guard_prefix + self.api_name(env)) code.putln("#define %s" % Naming.h_guard_prefix + self.api_name(env))
code.putln("#define %s" % Naming.api_guard_prefix + self.api_name(env)) code.putln("#define %s" % Naming.api_guard_prefix + self.api_name(env))
self.generate_includes(env, cimported_modules, code) self.generate_includes(env, cimported_modules, code)
......
...@@ -200,20 +200,7 @@ typedef struct { ...@@ -200,20 +200,7 @@ typedef struct {
#define __Pyx_PyType_AsAsync(obj) NULL #define __Pyx_PyType_AsAsync(obj) NULL
#endif #endif
/* inline attribute */ // restrict
#ifndef CYTHON_INLINE
#if defined(__GNUC__)
#define CYTHON_INLINE __inline__
#elif defined(_MSC_VER)
#define CYTHON_INLINE __inline
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define CYTHON_INLINE inline
#else
#define CYTHON_INLINE
#endif
#endif
/* restrict */
#ifndef CYTHON_RESTRICT #ifndef CYTHON_RESTRICT
#if defined(__GNUC__) #if defined(__GNUC__)
#define CYTHON_RESTRICT __restrict__ #define CYTHON_RESTRICT __restrict__
...@@ -226,22 +213,32 @@ typedef struct { ...@@ -226,22 +213,32 @@ typedef struct {
#endif #endif
#endif #endif
#ifdef NAN #define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() { /////////////// CInitCode ///////////////
/* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is // inline attribute
a quiet NaN. */ #ifndef CYTHON_INLINE
float value; #if defined(__GNUC__)
memset(&value, 0xFF, sizeof(value)); #define CYTHON_INLINE __inline__
return value; #elif defined(_MSC_VER)
} #define CYTHON_INLINE __inline
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define CYTHON_INLINE inline
#else
#define CYTHON_INLINE
#endif
#endif #endif
#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)
#ifdef __cplusplus /////////////// CppInitCode ///////////////
// inline attribute
#ifndef CYTHON_INLINE
#define CYTHON_INLINE inline
#endif
// Work around clang bug http://stackoverflow.com/questions/21847816/c-invoke-nested-template-class-destructor // Work around clang bug http://stackoverflow.com/questions/21847816/c-invoke-nested-template-class-destructor
template<typename T> template<typename T>
void __Pyx_call_destructor(T* x) { void __Pyx_call_destructor(T* x) {
...@@ -259,7 +256,28 @@ class __Pyx_FakeReference { ...@@ -259,7 +256,28 @@ class __Pyx_FakeReference {
private: private:
T *ptr; T *ptr;
}; };
/////////////// MathInitCode ///////////////
#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif #endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
// Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
// a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
// a quiet NaN.
float value;
memset(&value, 0xFF, sizeof(value));
return value;
}
#endif
/////////////// UtilityFunctionPredeclarations.proto /////////////// /////////////// UtilityFunctionPredeclarations.proto ///////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment