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

Explicitly export exported symbols, hide the rest #115

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ env['backendsincpath'] = calcInstallPath("$prefix", "include", "hammer", "backen
env['pkgconfigpath'] = calcInstallPath("$prefix", "lib", "pkgconfig")
env.ScanReplace('libhammer.pc.in')

env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable")
env.MergeFlags("-std=gnu99 -fvisibility=hidden -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable")

if env['PLATFORM'] == 'darwin':
env.Append(SHLINKFLAGS = '-install_name ' + env["libpath"] + '/${TARGET.file}')
Expand Down
1 change: 1 addition & 0 deletions contrib/freebsd/pkg-plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include/hammer/allocator.h
include/hammer/parsers/parser_internal.h
include/hammer/backends/regex.h
include/hammer/backends/contextfree.h
include/hammer/export.h
include/hammer/glue.h
include/hammer/hammer.h
lib/libhammer.so
Expand Down
1 change: 1 addition & 0 deletions contrib/netbsd/PLIST
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include/hammer/allocator.h
include/hammer/parsers/parser_internal.h
include/hammer/backends/regex.h
include/hammer/backends/contextfree.h
include/hammer/export.h
include/hammer/glue.h
include/hammer/hammer.h
lib/libhammer.so
Expand Down
8 changes: 4 additions & 4 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ dns: LDFLAGS:=-L../src -lhammer $(LDFLAGS)
dns: dns.o rr.o dns_common.o
$(call hush, "Linking $@") $(CC) -o $@ $^ $(LDFLAGS)

dns.o: ../src/hammer.h dns_common.h ../src/glue.h
rr.o: ../src/hammer.h rr.h dns_common.h ../src/glue.h
dns_common.o: ../src/hammer.h dns_common.h ../src/glue.h
dns.o: ../src/hammer.h dns_common.h ../src/glue.h ../src/export.h
rr.o: ../src/hammer.h rr.h dns_common.h ../src/glue.h ../src/export.h
dns_common.o: ../src/hammer.h dns_common.h ../src/glue.h ../src/export.h

base64: LDFLAGS:=-L../src -lhammer $(LDFLAGS)
base64: base64.o
Expand All @@ -38,4 +38,4 @@ base64_sem2: LDFLAGS:=-L../src -lhammer $(LDFLAGS)
base64_sem2: base64_sem2.o
$(call hush, "Linking $@") $(CC) -o $@ $^ $(LDFLAGS)

base64%.o: ../src/hammer.h ../src/glue.h
base64%.o: ../src/hammer.h ../src/glue.h ../src/export.h
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ all: libhammer.a
libhammer.a: $(HAMMER_PARTS)

bitreader.o: test_suite.h
hammer.o: hammer.h
glue.o: hammer.h glue.h
hammer.o: hammer.h export.h allocator.h
glue.o: hammer.h glue.h export.h allocator.h

all: libhammer.a

Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Import('env testruns')
dist_headers = [
"hammer.h",
"allocator.h",
"export.h",
"glue.h",
"internal.h"
]
Expand Down
15 changes: 8 additions & 7 deletions src/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef HAMMER_ALLOCATOR__H__
#define HAMMER_ALLOCATOR__H__
#include <sys/types.h>
#include "export.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -32,24 +33,24 @@ typedef struct HAllocator_ {

typedef struct HArena_ HArena ; // hidden implementation

HArena *h_new_arena(HAllocator* allocator, size_t block_size); // pass 0 for default...
H_EXPORT HArena *h_new_arena(HAllocator* allocator, size_t block_size); // pass 0 for default...
#ifndef SWIG
void* h_arena_malloc(HArena *arena, size_t count) __attribute__(( malloc, alloc_size(2) ));
H_EXPORT void* h_arena_malloc(HArena *arena, size_t count) __attribute__(( malloc, alloc_size(2) ));
#else
void* h_arena_malloc(HArena *arena, size_t count);
H_EXPORT void* h_arena_malloc(HArena *arena, size_t count);
#endif
void h_arena_free(HArena *arena, void* ptr); // For future expansion, with alternate memory managers.
void h_delete_arena(HArena *arena);
H_EXPORT void h_arena_free(HArena *arena, void* ptr); // For future expansion, with alternate memory managers.
H_EXPORT void h_delete_arena(HArena *arena);

typedef struct {
size_t used;
size_t wasted;
} HArenaStats;

void h_allocator_stats(HArena *arena, HArenaStats *stats);
H_EXPORT void h_allocator_stats(HArena *arena, HArenaStats *stats);

#ifdef __cplusplus
}
#endif

#endif // #ifndef LIB_ALLOCATOR__H__
#endif // #ifndef HAMMER_ALLOCATOR__H__
7 changes: 4 additions & 3 deletions src/bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
swig_opts=['-DHAMMER_INTERNAL__NO_STDARG_H',
'-I../../'],
define_macros=[('SWIG', None)],
depends=['allocator.h',
'glue.h',
depends=['allocator.h',
'export.h',
'glue.h',
'hammer.h',
'internal.h',],
extra_compile_args=['-fPIC',
'-std=gnu99',],
include_dirs=['../../'],
library_dirs=['../../'],
libraries=['hammer'],)],

py_modules=['hammer'],
)

Expand Down
22 changes: 22 additions & 0 deletions src/export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef HAMMER_EXPORT__H__
#define HAMMER_EXPORT__H__

#if defined _MSC_VER
# if defined BUILDING_HAMMER_DLL
# define H_EXPORT __declspec(dllexport)
# else
/*
* there is a slight performance gain in using __declspec(dllimport) here,
* but doing so would break static linking against hammer.
*/
# define H_EXPORT extern
# endif
#else
# if __GNUC__ >= 4
# define H_EXPORT __attribute__ ((visibility ("default")))
# else
# define H_EXPORT
# endif
#endif

#endif // #ifndef HAMMER_EXPORT__H__
83 changes: 42 additions & 41 deletions src/hammer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdint.h>
#include <stdio.h>
#include "allocator.h"
#include "export.h"

#define BYTE_BIG_ENDIAN 0x1
#define BIT_BIG_ENDIAN 0x2
Expand Down Expand Up @@ -197,47 +198,47 @@ typedef struct HBenchmarkResults_ {

// {{{ Preprocessor definitions
#define HAMMER_FN_DECL_NOARG(rtype_t, name) \
rtype_t name(void); \
rtype_t name##__m(HAllocator* mm__)
H_EXPORT rtype_t name(void); \
H_EXPORT rtype_t name##__m(HAllocator* mm__)

#define HAMMER_FN_DECL(rtype_t, name, ...) \
rtype_t name(__VA_ARGS__); \
rtype_t name##__m(HAllocator* mm__, __VA_ARGS__)
H_EXPORT rtype_t name(__VA_ARGS__); \
H_EXPORT rtype_t name##__m(HAllocator* mm__, __VA_ARGS__)

#define HAMMER_FN_DECL_ATTR(attr, rtype_t, name, ...) \
rtype_t name(__VA_ARGS__) attr; \
rtype_t name##__m(HAllocator* mm__, __VA_ARGS__) attr
H_EXPORT rtype_t name(__VA_ARGS__) attr; \
H_EXPORT rtype_t name##__m(HAllocator* mm__, __VA_ARGS__) attr

#ifndef SWIG
#define HAMMER_FN_DECL_VARARGS(rtype_t, name, ...) \
rtype_t name(__VA_ARGS__, ...); \
rtype_t name##__m(HAllocator* mm__, __VA_ARGS__, ...); \
rtype_t name##__mv(HAllocator* mm__, __VA_ARGS__, va_list ap); \
rtype_t name##__v(__VA_ARGS__, va_list ap); \
rtype_t name##__a(void *args[]); \
rtype_t name##__ma(HAllocator *mm__, void *args[])
H_EXPORT rtype_t name(__VA_ARGS__, ...); \
H_EXPORT rtype_t name##__m(HAllocator* mm__, __VA_ARGS__, ...); \
H_EXPORT rtype_t name##__mv(HAllocator* mm__, __VA_ARGS__, va_list ap); \
H_EXPORT rtype_t name##__v(__VA_ARGS__, va_list ap); \
H_EXPORT rtype_t name##__a(void *args[]); \
H_EXPORT rtype_t name##__ma(HAllocator *mm__, void *args[])

// Note: this drops the attributes on the floor for the __v versions
#define HAMMER_FN_DECL_VARARGS_ATTR(attr, rtype_t, name, ...) \
rtype_t name(__VA_ARGS__, ...) attr; \
rtype_t name##__m(HAllocator* mm__, __VA_ARGS__, ...) attr; \
rtype_t name##__mv(HAllocator* mm__, __VA_ARGS__, va_list ap); \
rtype_t name##__v(__VA_ARGS__, va_list ap); \
rtype_t name##__a(void *args[]); \
rtype_t name##__ma(HAllocator *mm__, void *args[])
H_EXPORT rtype_t name(__VA_ARGS__, ...) attr; \
H_EXPORT rtype_t name##__m(HAllocator* mm__, __VA_ARGS__, ...) attr; \
H_EXPORT rtype_t name##__mv(HAllocator* mm__, __VA_ARGS__, va_list ap); \
H_EXPORT rtype_t name##__v(__VA_ARGS__, va_list ap); \
H_EXPORT rtype_t name##__a(void *args[]); \
H_EXPORT rtype_t name##__ma(HAllocator *mm__, void *args[])
#else
#define HAMMER_FN_DECL_VARARGS(rtype_t, name, params...) \
rtype_t name(params, ...); \
rtype_t name##__m(HAllocator* mm__, params, ...); \
rtype_t name##__a(void *args[]); \
rtype_t name##__ma(HAllocator *mm__, void *args[])
H_EXPORT rtype_t name(params, ...); \
H_EXPORT rtype_t name##__m(HAllocator* mm__, params, ...); \
H_EXPORT rtype_t name##__a(void *args[]); \
H_EXPORT rtype_t name##__ma(HAllocator *mm__, void *args[])

// Note: this drops the attributes on the floor for the __v versions
#define HAMMER_FN_DECL_VARARGS_ATTR(attr, rtype_t, name, params...) \
rtype_t name(params, ...); \
rtype_t name##__m(HAllocator* mm__, params, ...); \
rtype_t name##__a(void *args[]); \
rtype_t name##__ma(HAllocator *mm__, void *args[])
H_EXPORT rtype_t name(params, ...); \
H_EXPORT rtype_t name##__m(HAllocator* mm__, params, ...); \
H_EXPORT rtype_t name##__a(void *args[]); \
H_EXPORT rtype_t name##__ma(HAllocator *mm__, void *args[])
#endif // SWIG
// }}}

Expand Down Expand Up @@ -673,12 +674,12 @@ HAMMER_FN_DECL(void, h_parse_result_free, HParseResult *result);
* Format token into a compact unambiguous form. Useful for parser test cases.
* Caller is responsible for freeing the result.
*/
char* h_write_result_unamb(const HParsedToken* tok);
H_EXPORT char* h_write_result_unamb(const HParsedToken* tok);
/**
* Format token to the given output stream. Indent starting at
* [indent] spaces, with [delta] spaces between levels.
*/
void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta);
H_EXPORT void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta);

/**
* Build parse tables for the given parser backend. See the
Expand All @@ -692,48 +693,48 @@ HAMMER_FN_DECL(int, h_compile, HParser* parser, HParserBackend backend, const vo
/**
* TODO: Document me
*/
HBitWriter *h_bit_writer_new(HAllocator* mm__);
H_EXPORT HBitWriter *h_bit_writer_new(HAllocator* mm__);

/**
* TODO: Document me
*/
void h_bit_writer_put(HBitWriter* w, uint64_t data, size_t nbits);
H_EXPORT void h_bit_writer_put(HBitWriter* w, uint64_t data, size_t nbits);

/**
* TODO: Document me
* Must not free [w] until you're done with the result.
* [len] is in bytes.
*/
const uint8_t* h_bit_writer_get_buffer(HBitWriter* w, size_t *len);
H_EXPORT const uint8_t* h_bit_writer_get_buffer(HBitWriter* w, size_t *len);

/**
* TODO: Document me
*/
void h_bit_writer_free(HBitWriter* w);
H_EXPORT void h_bit_writer_free(HBitWriter* w);

// General-purpose actions for use with h_action
// XXX to be consolidated with glue.h when merged upstream
HParsedToken *h_act_first(const HParseResult *p, void* userdata);
HParsedToken *h_act_second(const HParseResult *p, void* userdata);
HParsedToken *h_act_last(const HParseResult *p, void* userdata);
HParsedToken *h_act_flatten(const HParseResult *p, void* userdata);
HParsedToken *h_act_ignore(const HParseResult *p, void* userdata);
H_EXPORT HParsedToken *h_act_first(const HParseResult *p, void* userdata);
H_EXPORT HParsedToken *h_act_second(const HParseResult *p, void* userdata);
H_EXPORT HParsedToken *h_act_last(const HParseResult *p, void* userdata);
H_EXPORT HParsedToken *h_act_flatten(const HParseResult *p, void* userdata);
H_EXPORT HParsedToken *h_act_ignore(const HParseResult *p, void* userdata);

// {{{ Benchmark functions
HAMMER_FN_DECL(HBenchmarkResults *, h_benchmark, HParser* parser, HParserTestcase* testcases);
void h_benchmark_report(FILE* stream, HBenchmarkResults* results);
H_EXPORT void h_benchmark_report(FILE* stream, HBenchmarkResults* results);
//void h_benchmark_dump_optimized_code(FILE* stream, HBenchmarkResults* results);
// }}}

// {{{ Token type registry
/// Allocate a new, unused (as far as this function knows) token type.
HTokenType h_allocate_token_type(const char* name);
H_EXPORT HTokenType h_allocate_token_type(const char* name);

/// Get the token type associated with name. Returns -1 if name is unkown
HTokenType h_get_token_type_number(const char* name);
H_EXPORT HTokenType h_get_token_type_number(const char* name);

/// Get the name associated with token_type. Returns NULL if the token type is unkown
const char* h_get_token_type_name(HTokenType token_type);
H_EXPORT const char* h_get_token_type_name(HTokenType token_type);
// }}}

#ifdef __cplusplus
Expand Down