Last active
August 29, 2015 14:07
-
-
Save singularperturbation/b48c2c6234a17c188aaa to your computer and use it in GitHub Desktop.
Nimrod using libmarkdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
type | |
MKD_FLAG = cuint | |
PMMIOT = pointer | |
proc mkd_in(inputFile: TFile, | |
mflag: MKD_FLAG) : | |
PMMIOT {.importc: "mkd_in", | |
dynlib: "libmarkdown.so(.2|.2.1.3)".} | |
proc markdown(doc : PMMIOT, | |
output: TFile, | |
flag: MKD_FLAG) : cint | |
{.importc: "markdown", | |
dynlib: "libmarkdown.so(.2|.2.1.3)".} | |
proc cleanup(fileOpen: bool, fileVar: TFile) = | |
if fileOpen: | |
close(fileVar) | |
proc main() = | |
var | |
inFile: TFile = nil | |
fName: string = os.getCurrentDir() / "sample.md" | |
mkProcessed: PMMIOT | |
opened: bool | |
opened = open(inFile, fName) | |
if not opened: | |
echo("Could not open file.") | |
cleanup(opened, inFile) | |
return | |
mkProcessed = mkd_in(inFile,cuint(0)) | |
if mkProcessed != nil: | |
discard markdown(mkProcessed,stdout,cuint(0)) | |
cleanup(opened,inFile) | |
for i in 1..40: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put main in loop to test memory allocation
valgrind complains about extra frees:
total heap usage: 2,245 allocs, 2,240 frees
Edit: Nothing to worry about - dynlib library allocs currently not freed until program exists.