kivikakk / cmark-gfm-hs

Haskell bindings to libcmark-gfm GitHub Flavored Markdown parser
Other
13 stars 6 forks source link

Auto-register plugins on use #2

Closed kivikakk closed 7 years ago

kivikakk commented 7 years ago

I'm not sure how legit this strategy is, but it seems to work.

/ccing the two people who have run into this (other than me) if you have any thoughts: @robrix @jgm

jgm commented 7 years ago

Why not factor out this pattern

fmap catMaybes $ mapM resolveExt exts

as resolveExts, and put the registerPlugins in front of it? Otherwise registerPlugins will be called once for each extension.

resolveExts :: [CMarkExtension] -> IO [ExtensionPtr]
resolveExts exts = do
  registerPlugins
  catMaybes <$> mapM resolveExt exts

Even better, this could raise an exception if resolveExt returns a Nothing for one of the specified extensions. Or maybe resolveExt should do that. Otherwise, when a plugin fails to register, this is a silent failure.

kivikakk commented 7 years ago

Thanks so much, Rob and John! I really appreciate your review and thoughts. :heart:

kivikakk commented 7 years ago

Getting a fascinating segfault on Travis CI:

(gdb) run
Starting program: /home/travis/builds/kivikakk/cmark-gfm-hs/.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/test-cmark-gfm/test-cmark-gfm
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6041700 (LWP 1828)]
[New Thread 0x7ffff5840700 (LWP 1829)]
[New Thread 0x7ffff503f700 (LWP 1830)]
Cases: 16  Tried: 7  Errors: 0  Failures: 0
Program received signal SIGSEGV, Segmentation fault.
0x00000000004465a5 in cmark_render_html_with_mem (root=<optimized out>, options=0, extensions=0x8c9d40, mem=0x888c80 <CMARK_DEFAULT_MEM_ALLOCATOR>)
    at cbits/html.c:386
386         if (((cmark_syntax_extension *) extensions->data)->html_filter_func)
(gdb) print extensions
$1 = (cmark_llist *) 0x8c9d40
(gdb) print extensions->data
$2 = (void *) 0x21
(gdb)
kivikakk commented 7 years ago

Answer: I had some pretty silly code in there. Thanks, CI!