Skip to content

Commit

Permalink
+ Separated out #prefix code from #src.
Browse files Browse the repository at this point in the history
+ Added #prefix code to MD5 calculation to force rebuilds on non-signature changes.

[git-p4: depot-paths = "//src/RubyInline/dev/": change = 8419]
  • Loading branch information
zenspider committed Apr 18, 2013
1 parent a007a9b commit f9761e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ def generate_ext

ext << @inc
ext << nil
unless @pre.empty? then
ext << @pre.join("\n\n")
ext << nil
end
ext << @src.join("\n\n")
ext << nil
ext << nil
Expand Down Expand Up @@ -368,6 +372,7 @@ def module_name
unless defined? @module_name then
module_name = @mod.name.gsub('::','__')
md5 = Digest::MD5.new
@pre.each { |m| md5 << m.to_s }
@sig.keys.sort_by { |x| x.to_s }.each { |m| md5 << m.to_s }
@module_name = "Inline_#{module_name}_#{md5}"
end
Expand All @@ -383,7 +388,7 @@ def so_name

attr_reader :rb_file, :mod
attr_writer :mod
attr_accessor :src, :sig, :flags, :libs, :init_extra
attr_accessor :src, :pre, :sig, :flags, :libs, :init_extra

##
# Sets the name of the C struct for generating accessors. Used with
Expand All @@ -404,6 +409,7 @@ def initialize(mod)
@rb_file = File.expand_path real_caller

@mod = mod
@pre = []
@src = []
@inc = []
@sig = {}
Expand Down Expand Up @@ -763,7 +769,7 @@ def include_ruby_last
# Adds any amount of text/code to the source

def prefix(code)
@src << code
@pre << code
end

##
Expand Down
6 changes: 5 additions & 1 deletion test/test_inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,15 @@ def test_generate_ext

@builder.c "VALUE my_method() { return Qnil; }"

@builder.prefix "static int x;"

windoze = "\n __declspec(dllexport)" if Inline::WINDOZE

expected = <<-EXT
#include "ruby.h"
static int x;
# line N "#{$test_inline_path}"
static VALUE allocate(VALUE self) {
return (Qnil); }
Expand All @@ -765,7 +769,7 @@ def test_generate_ext
#ifdef __cplusplus
extern \"C\" {
#endif#{windoze}
void Init_Inline_TestInline__TestC_eba5e5454322e22fe2310198ef14e43f() {
void Init_Inline_TestInline__TestC_3ab8c09639e499394bb1f0a0194a839f() {
VALUE c = rb_cObject;
c = rb_const_get(c, rb_intern("TestInline"));
c = rb_const_get(c, rb_intern("TestC"));
Expand Down

0 comments on commit f9761e2

Please sign in to comment.