Attempt at allowing to use C++ structures in C only code: We use the
CreateAsmStructOffsetsHeader mechanism to generate a header with macros defined to the sizes of the structures we're interested in and when compiling in C mode define the structures as "struct { char bytes[size]; }". It works in principle, but due to how jam works, one would have to specify the dependency to the generated header for all sources that include it directly or indirectly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34441 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
cf44da4c44
commit
fc7864091e
@ -389,6 +389,7 @@ HAIKU_PRIVATE_KERNEL_HEADERS =
|
||||
[ PrivateHeaders $(DOT) kernel libroot
|
||||
kernel/boot/platform/$(HAIKU_BOOT_PLATFORM) ]
|
||||
[ ArchHeaders $(HAIKU_ARCH) ]
|
||||
[ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR) system kernel ]
|
||||
$(HAIKU_PRIVATE_SYSTEM_HEADERS)
|
||||
;
|
||||
|
||||
|
24
headers/private/kernel/kernel_c++_structs.h
Normal file
24
headers/private/kernel/kernel_c++_structs.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_KERNEL_CPP_STRUCTS_H
|
||||
#define _KERNEL_KERNEL_CPP_STRUCTS_H
|
||||
|
||||
|
||||
#include <util/kernel_c.h>
|
||||
|
||||
#include <kernel_c++_struct_sizes.h>
|
||||
// this is the generated defining macros for the structure sizes
|
||||
|
||||
|
||||
// in C++ mode include the headers defining the structures
|
||||
#ifdef __cplusplus
|
||||
# include <condition_variable.h>
|
||||
#endif
|
||||
|
||||
// in C mode define the structures
|
||||
DEFINE_KERNEL_CPP_STRUCT(ConditionVariable)
|
||||
|
||||
|
||||
#endif // _KERNEL_KERNEL_CPP_STRUCTS_H
|
31
headers/private/kernel/util/kernel_c.h
Normal file
31
headers/private/kernel/util/kernel_c.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_UTIL_KERNEL_C_H
|
||||
#define _KERNEL_UTIL_KERNEL_C_H
|
||||
|
||||
|
||||
/*! Defines a structure that has the size of a certain C++ structure.
|
||||
\param name The name of the C++ structure.
|
||||
\param flatName The name of the structure to be defined.
|
||||
*/
|
||||
#define DEFINE_FLAT_KERNEL_CPP_STRUCT(name, flatName) \
|
||||
struct flatName { \
|
||||
char bytes[_KERNEL_CPP_STRUCT_SIZE_##name]; \
|
||||
};
|
||||
|
||||
|
||||
/*! In C mode DEFINE_KERNEL_CPP_STRUCT() defines a struct \a name with the
|
||||
size of the C++ structure of the same name. In C++ it is a no-op.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
# define DEFINE_KERNEL_CPP_STRUCT(name)
|
||||
#else
|
||||
# define DEFINE_KERNEL_CPP_STRUCT(name) \
|
||||
DEFINE_FLAT_KERNEL_CPP_STRUCT(name, name) \
|
||||
typedef struct name name;
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _KERNEL_UTIL_KERNEL_C_H */
|
@ -63,6 +63,14 @@ KernelMergeObject kernel_core.o :
|
||||
: $(TARGET_KERNEL_PIC_CCFLAGS)
|
||||
;
|
||||
|
||||
# Generate the header defining macros for C++ structure sizes.
|
||||
local kernelC++StructSizesHeader = [ FGristFiles kernel_c++_struct_sizes.h ] ;
|
||||
TARGET_HDRS on $(kernelC++StructSizesHeader)
|
||||
= [ on $(kernelC++StructSizesHeader) return $(TARGET_HDRS) ]
|
||||
$(TARGET_PRIVATE_KERNEL_HEADERS) ;
|
||||
CreateAsmStructOffsetsHeader $(kernelC++StructSizesHeader)
|
||||
: kernel_c++_structs.cpp ;
|
||||
|
||||
# We need to specify the dependency on the generated syscalls files explicitly.
|
||||
Includes [ FGristFiles syscalls.cpp ]
|
||||
: <syscalls>syscall_dispatcher.h <syscalls>syscall_table.h
|
||||
|
24
src/system/kernel/kernel_c++_structs.cpp
Normal file
24
src/system/kernel/kernel_c++_structs.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <computed_asm_macros.h>
|
||||
|
||||
#include <condition_variable.h>
|
||||
|
||||
|
||||
// NOTE: Don't include <kernel_c++_structs.h>, since that would result in a
|
||||
// circular dependency.
|
||||
|
||||
|
||||
#define DEFINE_SIZE_MACRO(name) \
|
||||
DEFINE_COMPUTED_ASM_MACRO(_KERNEL_CPP_STRUCT_SIZE_##name, sizeof(name));
|
||||
|
||||
|
||||
void
|
||||
dummy()
|
||||
{
|
||||
DEFINE_SIZE_MACRO(ConditionVariable)
|
||||
}
|
Loading…
Reference in New Issue
Block a user