~alcinnz/rhapsode

505b29c376006540cd8919667fa3e24456d3cf6e — Adrian Cochrane 4 years ago 489dd5c
Partially fix segfaults, enough to continue on.

Still questions remain, and there's broken C APIs exposed.
2 files changed, 9 insertions(+), 6 deletions(-)

M src/CExports.hs
M src/main.c
M src/CExports.hs => src/CExports.hs +3 -1
@@ 132,7 132,9 @@ text2cstring txt = Txt.withCStringLen txt $ \s -> (peekCStringLen s >>= newCStri
foreign export ccall c_docLinksAndRendering :: StablePtr Session -> StablePtr Page -> IO (CArray CString)

c_docLinksAndRendering c_session c_page = do
    (c_links, ssml) <- c_extractLinks c_page `concurrently` c_renderDoc c_session c_page
    c_links <- c_extractLinks c_page
    ssml <- c_renderDoc c_session c_page
    -- (c_links, ssml) <- c_extractLinks c_page `concurrently` c_renderDoc c_session c_page
    nil <- newCString ""
    links <- peekArray0 nil c_links
    newArray0 nil (ssml : links)

M src/main.c => src/main.c +6 -5
@@ 9,21 9,22 @@ void c_freeSession(struct session*);

struct page;
struct page *c_initialReferer();
void *c_fetchURL(struct session*, char*, char*);
//struct page **c_fetchURLs(struct session*, struct page*, char**);
void *c_fetchURL(struct session*, char*, struct page*, char*);
//struct page **c_fetchURLs(struct session*, struct page*, char**); // FIXME segfaults.
void c_freePage(struct page*);

char *c_renderDoc(struct session*, struct page*);
char **c_extractLinks(struct page*);
char **c_docLinksAndRendering(struct session*, struct page*);
char **c_docLinksAndRendering(struct session*, struct page*); // FIXME segfaults.

int main(int argc, char **argv) {
    hs_init(&argc, &argv);
    struct session *session = c_newSession();

    struct page *referer = c_initialReferer();
    struct page *page = c_fetchURL(session, "text/xml text/html text/plain", argv[1]);
    // char *ssml = c_renderDoc(session, page); // FIXME segfaults alongside extractLinks & the combined function.
    struct page *page = c_fetchURL(session, "text/xml text/html text/plain", referer, argv[1]);
    char *ssml = c_renderDoc(session, page);
    char **links = c_extractLinks(page);

    printf("%i Hello, world!\n", argc);