mirror of
https://github.com/e621ng/dtext_rb.git
synced 2025-03-04 03:03:03 -05:00
Switch to building extension with C++
Switch to compiling the extension as C++. This way we can work towards replacing all the low-level C
code with C++, which is better at dealing with strings, and has a better standard library we can use
to replace the dependency on GLib.
d47307f2ef
Co-Authored-By: evazion <noizave@gmail.com>
This commit is contained in:
parent
014220bc38
commit
feca366bf7
6
Rakefile
6
Rakefile
@ -14,12 +14,12 @@ end
|
||||
|
||||
Rake::ExtensionTask.new "dtext" do |ext|
|
||||
# this goes here to ensure ragel runs *before* the extension is compiled.
|
||||
task :compile => ["ext/dtext/dtext.c", "ext/dtext/rb_dtext.c"]
|
||||
task :compile => ["ext/dtext/dtext.cpp", "ext/dtext/rb_dtext.cpp"]
|
||||
ext.lib_dir = "lib/dtext"
|
||||
end
|
||||
|
||||
file "ext/dtext/dtext.c" => Dir["ext/dtext/dtext.{rl,h}", "Rakefile"] do
|
||||
sh "ragel -G1 -C ext/dtext/dtext.rl -o ext/dtext/dtext.c"
|
||||
file "ext/dtext/dtext.cpp" => Dir["ext/dtext/dtext.{cpp.rl,h}", "Rakefile"] do
|
||||
sh "ragel -G1 -C ext/dtext/dtext.cpp.rl -o ext/dtext/dtext.cpp"
|
||||
end
|
||||
|
||||
def run_dtext(*args)
|
||||
|
@ -857,11 +857,11 @@ static inline void dstack_push(StateMachine * sm, element_t element) {
|
||||
}
|
||||
|
||||
static inline element_t dstack_pop(StateMachine * sm) {
|
||||
return GPOINTER_TO_INT(g_queue_pop_tail(sm->dstack));
|
||||
return (element_t)GPOINTER_TO_INT(g_queue_pop_tail(sm->dstack));
|
||||
}
|
||||
|
||||
static inline element_t dstack_peek(const StateMachine * sm) {
|
||||
return GPOINTER_TO_INT(g_queue_peek_tail(sm->dstack));
|
||||
return (element_t)GPOINTER_TO_INT(g_queue_peek_tail(sm->dstack));
|
||||
}
|
||||
|
||||
static inline bool dstack_check(const StateMachine * sm, element_t expected_element) {
|
@ -1,11 +1,12 @@
|
||||
require "mkmf"
|
||||
|
||||
$warnflags = "-Wall -Wextra -Wno-unused-parameter"
|
||||
$CFLAGS << " -std=c99 -D_GNU_SOURCE #{ENV["CFLAGS"]}"
|
||||
CONFIG["MKMF_VERBOSE"] = "1"
|
||||
|
||||
$CFLAGS << " " << (pkg_config "glib-2.0", "cflags")
|
||||
$warnflags = "-Wall -Wextra -Werror -Wno-unused-parameter -Wuninitialized -Wnull-dereference -Wformat=2 -Wformat-overflow=2 -Wstrict-overflow=5"
|
||||
$CXXFLAGS << " -std=c++17 -O2 -pipe -flto -fno-strict-aliasing -D_GNU_SOURCE -DNDEBUG"
|
||||
|
||||
pkg_config "glib-2.0"
|
||||
have_library "glib-2.0"
|
||||
have_header "glib.h"
|
||||
have_header "dtext.h"
|
||||
|
||||
create_makefile "dtext/dtext"
|
||||
|
@ -39,7 +39,7 @@ static VALUE c_parse(VALUE self, VALUE input, VALUE f_inline, VALUE f_allow_colo
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Init_dtext() {
|
||||
extern "C" void Init_dtext() {
|
||||
mDText = rb_define_module("DText");
|
||||
mDTextError = rb_define_class_under(mDText, "Error", rb_eStandardError);
|
||||
rb_define_singleton_method(mDText, "c_parse", c_parse, 5);
|
Loading…
Reference in New Issue
Block a user