summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2014-11-16 21:56:49 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2014-11-16 22:43:04 +0100
commit675b92aa6b6c8124c8ccf9535e338fd37b8b9977 (patch)
treef3201e9ceb6fab30db8c97bcc01812ef341f97b9 /src
parent52045957a87f2c86f61f2054cafbebe050a1299b (diff)
Move inline function definitions to header files
Inline functions must be defined in header files in order to be inlined in other compilation units. This also fixes the MSVC build where out-of-line versions weren't created and allows to remove the -fgnu89-inline flag.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/ast.h55
-rw-r--r--src/buffer.c5
-rw-r--r--src/buffer.h7
-rw-r--r--src/cmark.c54
5 files changed, 56 insertions, 69 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c399713..6f78a26 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -125,10 +125,6 @@ if(MSVC)
set(CMAKE_C_FLAGS "/TP")
endif()
-if(CMAKE_COMPILER_IS_MINGW)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fgnu89-inline")
-endif(CMAKE_COMPILER_IS_MINGW)
-
if($ENV{TIMER})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1")
endif($ENV{TIMER})
diff --git a/src/ast.h b/src/ast.h
index dc8df41..0640f88 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -5,6 +5,7 @@
#include "config.h"
#include "buffer.h"
#include "chunk.h"
+#include "cmark.h"
#ifdef __cplusplus
extern "C" {
@@ -136,15 +137,59 @@ struct cmark_doc_parser {
cmark_strbuf *curline;
};
-struct cmark_node_inl *cmark_make_link(struct cmark_node_inl *label, unsigned char *url, unsigned char *title);
+unsigned char *cmark_clean_autolink(chunk *url, int is_email);
+
+static inline cmark_node_inl *cmark_make_link(cmark_node_inl *label, unsigned char *url, unsigned char *title)
+{
+ cmark_node_inl* e = (cmark_node_inl *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = CMARK_INL_LINK;
+ e->content.linkable.label = label;
+ e->content.linkable.url = url;
+ e->content.linkable.title = title;
+ e->next = NULL;
+ }
+ return e;
+}
-struct cmark_node_inl* cmark_make_autolink(struct cmark_node_inl* label, cmark_chunk url, int is_email);
+static inline cmark_node_inl* cmark_make_autolink(cmark_node_inl* label, cmark_chunk url, int is_email)
+{
+ return cmark_make_link(label, cmark_clean_autolink(&url, is_email), NULL);
+}
-struct cmark_node_inl* cmark_make_inlines(cmark_inl_tag t, struct cmark_node_inl* contents);
+static inline cmark_node_inl* cmark_make_inlines(cmark_inl_tag t, cmark_node_inl* contents)
+{
+ cmark_node_inl * e = (cmark_node_inl *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = t;
+ e->content.inlines = contents;
+ e->next = NULL;
+ }
+ return e;
+}
-struct cmark_node_inl* cmark_make_literal(cmark_inl_tag t, cmark_chunk s);
+// Create an inline with a literal string value.
+static inline cmark_node_inl* cmark_make_literal(cmark_inl_tag t, cmark_chunk s)
+{
+ cmark_node_inl * e = (cmark_node_inl *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = t;
+ e->content.literal = s;
+ e->next = NULL;
+ }
+ return e;
+}
-struct cmark_node_inl* cmark_make_simple(cmark_inl_tag t);
+// Create an inline with no value.
+static inline cmark_node_inl* cmark_make_simple(cmark_inl_tag t)
+{
+ cmark_node_inl* e = (cmark_node_inl *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = t;
+ e->next = NULL;
+ }
+ return e;
+}
// Macros for creating various kinds of simple.
#define cmark_make_str(s) cmark_make_literal(INL_STRING, s)
diff --git a/src/buffer.c b/src/buffer.c
index c7b784a..45b6984 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -201,11 +201,6 @@ int cmark_strbuf_printf(strbuf *buf, const char *format, ...)
return r;
}
-inline const char *cmark_strbuf_cstr(const cmark_strbuf *buf)
-{
- return (char *)buf->ptr;
-}
-
void cmark_strbuf_copy_cstr(char *data, int datasize, const strbuf *buf)
{
int copylen;
diff --git a/src/buffer.h b/src/buffer.h
index acbead7..be888e1 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -84,10 +84,13 @@ void cmark_strbuf_attach(cmark_strbuf *buf, unsigned char *ptr, int asize);
CMARK_EXPORT
unsigned char *cmark_strbuf_detach(cmark_strbuf *buf);
CMARK_EXPORT
-inline const char *cmark_strbuf_cstr(const cmark_strbuf *buf);
-CMARK_EXPORT
void cmark_strbuf_copy_cstr(char *data, int datasize, const cmark_strbuf *buf);
+static inline const char *cmark_strbuf_cstr(const cmark_strbuf *buf)
+{
+ return (char *)buf->ptr;
+}
+
#define cmark_strbuf_at(buf, n) ((buf)->ptr[n])
/*
diff --git a/src/cmark.c b/src/cmark.c
index f793499..e7f6899 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -73,20 +73,7 @@ void cmark_free_inlines(cmark_node_inl* e)
}
}
-inline cmark_node_inl *cmark_make_link(cmark_node_inl *label, unsigned char *url, unsigned char *title)
-{
- cmark_node_inl* e = (cmark_node_inl *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->tag = CMARK_INL_LINK;
- e->content.linkable.label = label;
- e->content.linkable.url = url;
- e->content.linkable.title = title;
- e->next = NULL;
- }
- return e;
-}
-
-unsigned char *clean_autolink(chunk *url, int is_email)
+unsigned char *cmark_clean_autolink(chunk *url, int is_email)
{
strbuf buf = GH_BUF_INIT;
@@ -102,45 +89,6 @@ unsigned char *clean_autolink(chunk *url, int is_email)
return strbuf_detach(&buf);
}
-inline cmark_node_inl* cmark_make_autolink(cmark_node_inl* label, chunk url, int is_email)
-{
- return cmark_make_link(label, clean_autolink(&url, is_email), NULL);
-}
-
-inline cmark_node_inl* cmark_make_inlines(cmark_inl_tag t, cmark_node_inl* contents)
-{
- cmark_node_inl * e = (cmark_node_inl *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->tag = t;
- e->content.inlines = contents;
- e->next = NULL;
- }
- return e;
-}
-
-// Create an inline with a literal string value.
-inline cmark_node_inl* cmark_make_literal(cmark_inl_tag t, cmark_chunk s)
-{
- cmark_node_inl * e = (cmark_node_inl *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->tag = t;
- e->content.literal = s;
- e->next = NULL;
- }
- return e;
-}
-
-// Create an inline with no value.
-inline cmark_node_inl* cmark_make_simple(cmark_inl_tag t)
-{
- cmark_node_inl* e = (cmark_node_inl *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->tag = t;
- e->next = NULL;
- }
- return e;
-}
-
// Free a node_block list and any children.
void cmark_free_blocks(cmark_node_block *e)
{