Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Wrap C library #2

Closed
wants to merge 15 commits into from
Closed

Wrap C library #2

wants to merge 15 commits into from

Conversation

gjtorikian
Copy link

Closes #1.

Here's what's going on in this PR:

  • I added the C implementation as a submodule.
  • I added a few bootstrapping scripts to simplify fetching dependencies and submodules.
  • I trashed FFI in favor of rake-compiler. Personally, I am not a huge fan of DSLs as they tend to obfuscate what's really going on. Writing the Ruby C bindings is simple enough to do it by hand.
  • I rewrote some of the gemspec so that it's actually publishable on RubyGems.

Right now, I'm working my way through the basic test suite. Walking the chain seems to be coming along just fine. I'm curious to know if you have any style/design concerns or whether I should continue down this path.

It would be great to add a Travis file to this repo so that I can get automated tests for this branch.

@jgm
Copy link
Owner

jgm commented May 9, 2015

This looks great to me! You are obviously a much more accomplished
rubyist than I am, so what I'd like to suggest is that you simply take
over the project. I have enough projects to maintain as it is, and I'd
love to have someone else shepherding the ruby bindings. What do you
think?

One note: libcmark now provides its own iterator inference for walking
the AST. So I think you'd probably want to remove my old ruby 'walk' function
and everything that supports it, and replace it with something that
wraps the C library's iterator functions. Maybe you already realized
that.

@gjtorikian
Copy link
Author

@jgm That sounds good to me. Are you thinking to just transfer the repo? If so I might need to remove my fork first, to avoid a name clash.

I did not know there was a function for walking the AST--thanks for the tip!

@jgm
Copy link
Owner

jgm commented May 10, 2015

+++ Garen Torikian [May 09 15 19:01 ]:

@jgm That sounds good to me. Are you thinking to just transfer the repo? If so I might need to remove my fork first, to avoid a name clash.

It is probably easiest just to make your fork the canonical repository
for this library. It's not as if my repo has issues or anything else
that would need to be transfered. I could just delete my repo, or keep
it and put a note on the README pointing to yours. But if you'd rather
that I transfer the whole repo, I'd be happy to do that instead.

I don't think I ever pushed this to a remote gem repository, so
there shouldn't be any problems there.

I did not know there was a function for walking the AST--thanks for the tip!

There have been lots of changes to the C API since I wrote this ruby
wrapper -- the man page (man 3 cmark) has up-to-date documentation of
the API.

@gjtorikian
Copy link
Author

Cool. I've detached my repo from the network: https://github.com/gjtorikian/commonmarker/

Thanks very much! Closing this out as it's irrelevant now.

@jgm
Copy link
Owner

jgm commented May 10, 2015

Great! Let me know when you've finished the library, and we can publicize it on http://talk.commonmark.org and put it on the list of implementations.

@gjtorikian
Copy link
Author

I'm very nearly finished with the initial wrapper. I have two questions that I can't seem to solve, I was hoping you might be able to shed some light on them.

First, only four tests in the spec are failing. They seem to have to deal with emphasis next to punctuation. The Ruby lib is not providing proper emphasis:

  1) Failure:
TestSpec#test_to_html_example_281 [/Users/gjtorikian/Development/commonmarker/test/test_spec.rb:12]:
foo-_(bar)_
.
--- expected
+++ actual
@@ -1,2 +1,2 @@
-"<p>foo-<em>(bar)</em></p>
+"<p>foo-_(bar)_</p>
 "



  2) Failure:
TestSpec#test_to_html_example_294 [/Users/gjtorikian/Development/commonmarker/test/test_spec.rb:12]:
_(bar)_.
.
--- expected
+++ actual
@@ -1,2 +1,2 @@
-"<p><em>(bar)</em>.</p>
+"<p>_(bar)_.</p>
 "



  3) Failure:
TestSpec#test_to_html_example_307 [/Users/gjtorikian/Development/commonmarker/test/test_spec.rb:12]:
foo-__(bar)__
.
--- expected
+++ actual
@@ -1,2 +1,2 @@
-"<p>foo-<strong>(bar)</strong></p>
+"<p>foo-__(bar)__</p>
 "



  4) Failure:
TestSpec#test_to_html_example_320 [/Users/gjtorikian/Development/commonmarker/test/test_spec.rb:12]:
__(bar)__.
.
--- expected
+++ actual
@@ -1,2 +1,2 @@
-"<p><strong>(bar)</strong>.</p>
+"<p>__(bar)__.</p>
 "

I was wondering if you've seen this problem before? The test code is just straight calling the cmark_render_html underneath and, as I said, every other test in the spec passes.

The second problem is with HTMLRenderer. Almost all of those tests are failing, but for trivial reasons mostly dealing with \n not being handled correctly. For example:

138) Failure:
TestSpec#test_html_renderer_example_191 [/Users/gjtorikian/Development/commonmarker/test/test_spec.rb:20]:
   1.  A paragraph
       with two lines.

           indented code

       > A block quote.
.
--- expected
+++ actual
@@ -1,4 +1,4 @@
-"<ol>
+"
 <li>
 <p>A paragraph
 with two lines.</p>

Here, an extraneous newline is being inserted. This happens several times.

I was wondering if there was an easier way to fetch the expected HTMLRenderer behavior, without having to dig into the C for forever.

Thanks for any help!

@gjtorikian
Copy link
Author

One more tremendously confusing thing I just noticed: according to my latest Travis run, all the spec tests pass, including the four I have issues with up above. I'm running OS X,Travis runs Ubuntu 12.04. So perhaps I'm compiling the lib incorrectly on my machine--I wonder if there is a CFLAG or something I am missing? I can run all of cmark's spec tests just fine.

@jgm
Copy link
Owner

jgm commented May 11, 2015

Are you sure you have the latest version of the C code?
Maybe you just need to git submodule update?

+++ Garen Torikian [May 11 15 10:31 ]:

One more tremendously confusing thing I just noticed: according to my latest Travis run, all the spec tests pass, including the four I have issues with up above. I'm running OS X,Travis runs Ubuntu 12.04. So perhaps I'm compiling the lib incorrectly on my machine--I wonder if there is a CFLAG or something I am missing? I can run all of cmark's spec tests just fine.


Reply to this email directly or view it on GitHub:
#2 (comment)

@gjtorikian
Copy link
Author

Yep. My latest sha is bc5f16f146558a1faf9be6abe034755421f6ecce. gjtorikian/commonmarker@5a5be04

@jgm
Copy link
Owner

jgm commented May 12, 2015

On the first problem: those four tests that fail were added fairly recently. All of them pass in 0.19 but fail in earlier versions. That's why I suspected you had an earlier version. Are you sure you're linking against the version of the library in your submodule, and not e.g. one you installed to the system earlier? (Note: libcmark exports cmark_version_string, so if you expose this through ruby you can see directly what version is being used.)

If it's not that, I'm at a loss. My only other idea is to check your locale? But it shouldn't be sensitive to this.

(Note: the README still says that you must have installed libcmark to the system to use commonmarker. I believe that isn't supposed to be true any more, the way you're doing things. The README could probably use a rewrite, for this and for other things. It would be worth doing new benchmarks, too, as cmark has gotten a bit faster.)

@jgm
Copy link
Owner

jgm commented May 12, 2015

I was wondering if there was an easier way to fetch the expected HTMLRenderer behavior, without having to dig into the C for forever.

HTMLRenderer is a ruby class, so it has nothing to do with the C library. But I assume you mean, how do we get its output aligned with the standard HTML output of the C lib? Why not just look at the spec tests themselves?

@gjtorikian
Copy link
Author

Are you sure you're linking against the version of the library in your submodule, and not e.g. one you installed to the system earlier?

Damn! Good call. I was erroneously linking to 0.18.3. The gem now passes the C suite fully.

Note: the README still says that you must have installed libcmark to the system to use commonmarker.

Yeah, I need to update that and the benchmark results as part of the PR.

Why not just look at the spec tests themselves?

Heh, mostly because I was hoping for an easier way. 😀 Anyway, it shouldn't take me more than than the week to get that sorted out, now that the mystery of the failing spec is resolved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrapping libcmark?
2 participants