mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
756 stars 138 forks source link

Issues on C++ #114

Closed nedpals closed 4 years ago

nedpals commented 4 years ago

Hi! First of all, thanks for creating this library. It's been a pleasure to use and miles better than cmark in terms of portability and extensibility.

I'm about to include md4c into the V Programming Language when it failed on the C++ test of our CI because of some issues regarding md4c.c. Here's the short preview of the error message:

/home/runner/work/v/v/thirdparty/md4c/md4c.o not found, building it...
failed thirdparty object build cmd: g++-9  -fPIC -I "/home/runner/work/v/v/thirdparty/md4c" -c -o "/home/runner/work/v/v/thirdparty/md4c/md4c.o" "/home/runner/work/v/v/thirdparty/md4c/md4c.c"   
builder error: /home/runner/work/v/v/thirdparty/md4c/md4c.c: In function ‘int md_build_ref_def_hashtable(MD_CTX*)’:
/home/runner/work/v/v/thirdparty/md4c/md4c.c:1665:36: error: invalid conversion from ‘void*’ to ‘void**’ [-fpermissive]
 1665 |     ctx->ref_def_hashtable = malloc(ctx->ref_def_hashtable_size * sizeof(void*));
      |                              ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                    |
      |                                    void*
/home/runner/work/v/v/thirdparty/md4c/md4c.c: In function ‘MD_MARK* md_push_mark(MD_CTX*)’:
/home/runner/work/v/v/thirdparty/md4c/md4c.c:2502:28: error: invalid conversion from ‘void*’ to ‘MD_MARK*’ {aka ‘MD_MARK_tag*’} [-fpermissive]
 2502 |         new_marks = realloc(ctx->marks, ctx->alloc_marks * sizeof(MD_MARK));
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            |
      |                            void*
/home/runner/work/v/v/thirdparty/md4c/md4c.c: In function ‘int md_process_inlines(MD_CTX*, const MD_LINE*, int)’:
/home/runner/work/v/v/thirdparty/md4c/md4c.c:4216:48: error: invalid conversion from ‘void*’ to ‘const MD_CHAR*’ {aka ‘const char*’} [-fpermissive]
 4216 |                                 md_mark_get_ptr(ctx, title_mark - ctx->marks), title_mark->prev));
      |                                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                |
      |                                                void*
/home/runner/work/v/v/thirdparty/md4c/md4c.c:377:16: note: in definition of macro ‘MD_CHECK’
  377 |         ret = (func);                                              

Hoping it would get fixed ASAP or have a workaround on how to bypass this error. :smiley:

mity commented 4 years ago

That's clearly because (unlike C) C++ does not allow the implicit casts from void* to other pointers, so explicit casts to target types would have to be added.

If you really need to feed the source to C++ compiler instead of C compiler, feel free to make a pull request.

spytheman commented 4 years ago

passing -fpermissive -w to the building stage was enough

spytheman commented 4 years ago

@mity thanks for the quick response!

spytheman commented 4 years ago

and for the great library too!

mity commented 4 years ago

passing -fpermissive -w to the building stage was enough

It would imho be cleaner to compile .c files with gcc instead of g++, and only use g++ when linking it all together but whatever.

Closing.