jgm/pandoc-types

nullAttr doesn't seem to work as before with pandoc filter

Closed this issue · 4 comments

I come to get a runtime error with nullAttr (from Text.Pandoc.Defitnition) in pandoc-types-1.23.1 when I use it within a pandoc filter like bellow;

$ cat myfilter.hs
import Text.Pandoc.JSON

main :: IO ()
main = toJSONFilter block

block (Para _) = Div nullAttr []
block b = b

This leads to an unexpected error instead of the expected result [ Div ( "" , [] , [] ) [] ];

$ pandoc --filter myfilter.hs -f markdown -t native
foo
(hit ctrl-d)
Error running filter myfilter.hs:
Filter returned error status -11

This filter worked as expected before, though I'm not sure until which version. And I could get the expected result now if I redefined nullAttr as the same definition as the original ("",[],[]), hiding the imported definition.

Does somebody has any clue regarding this error?

-- Sorry in advance if this was to be issued in pandoc itself instead of here.

jgm commented

I can't understand why this would be so, nor can I reproduce the issue!

Thank you for trying to check that. Then it might be caused by my environment including GHC. Sorry to have bothered you. I closed this issue anyway.

Just some follow-ups. My ghc version is 9.4.4, and I tried more minimal reproducible example;

import Text.Pandoc.Definition

main = do
  putStrLn $ show $ Div nullAttr []

This ended up a segmenation failt with runghc.

$ runghc myfilter.hs
Div ("Segmentation fault

Funnily enough, the compiled binary works fine.

$ ./myfilter
Div ("",[],[]) []

Some tweeking with lldb tells the segv happend at Data.Text.

$ lldb -- ~/.ghcup/ghc/9.4.4/lib/ghc-9.4.4/bin/runhaskell ./myfilter.hs
(snip)
...
CodeBlock ("Process 362618 stopped
* thread #5, name = 'ghc:w', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0x00007fffed56a12c libHStext-2.0.1-ghc9.4.4.so
->  0x7fffed56a12c: jmpq   *(%rbx)
    0x7fffed56a12e: nop
    0x7fffed56a130: addl   %eax, (%rax)
    0x7fffed56a132: addb   %al, (%rax)

This gave me a curious inspiration of forcing precedences by adding $.

import Text.Pandoc.Definition

main = do
  putStrLn $ show $ Div nullAttr $ []

And it just worked even with runghc without any segv!

jgm commented

Very strange...I can't say what's going on here.