Permalink
Browse files

Fix the kernel to not contain any system info

* Rubinius can now load config files, in the same format
  of the RBX env variable, but with newlines seperating
  definitions.
* Added some code to generate runtime/platform.conf
  in Rakefile, which contains any system dependent
  data.
* Fit DirEntry into this scheme.
  • Loading branch information...
1 parent b3aa2af commit 1c9328e1624dfc7338eb94695f1b71ab4013594a @evanphx evanphx committed Dec 16, 2007
View
@@ -18,6 +18,7 @@ tmp
scratch
!runtime/stable/loader.rbc
runtime/pristine*
+runtime/platform.conf
*.o
*.lo
@@ -34,7 +35,6 @@ runtime/pristine*
attic/externals/syd-parser/pkg
kernel/.load_order.txt
-kernel/core/dir.rb
kernel/core/dir_entry.rb
lib/etc.rb
View
@@ -264,10 +264,6 @@ file 'runtime/stable/compiler1.rba' => 'build:compiler1' do
end
Rake::StructGeneratorTask.new do |t|
- t.dest = "kernel/core/dir.rb"
-end
-
-Rake::StructGeneratorTask.new do |t|
t.dest = "lib/etc.rb"
end
@@ -417,6 +413,8 @@ namespace :clean do
(Dir["lib/compiler1/*.rbc"] + Dir["lib/compiler1/**/*.rbc"]).each do |f|
rm_f f, :verbose => $verbose
end
+
+ rm_f "runtime/platform.conf"
end
desc "Cleans up VM building site"
@@ -434,6 +432,7 @@ namespace :build do
task :all => %w[
build:shotgun
+ build:platform
build:rbc
compiler1
lib/etc.rb
@@ -532,9 +531,24 @@ RbConfig = Config
sh "cd shotgun/lib; make DEV=1"
end
end
+
+ task :platform => 'runtime/platform.conf'
+end
+file 'runtime/platform.conf' do
+ sg = StructGenerator.new
+ sg.include "dirent.h"
+ sg.name 'struct dirent'
+ fel = sg.field :d_name
+ sg.calculate
+
+ File.open("runtime/platform.conf", "w") do |f|
+ f.puts "rbx.platform.dir.d_name = #{fel.offset}"
+ end
+
end
+
desc "Build extensions from lib/ext"
task :extensions => %w[
build:shotgun
@@ -2,11 +2,7 @@
class Dir
class DirEntry < FFI::Struct
- @@@
- name "struct dirent"
- include "dirent.h"
- field :d_name, :char_array
- @@@
+ layout :d_name, :char_array, Rubinius::RUBY_CONFIG['rbx.platform.dir.d_name']
end
include Enumerable
@@ -2,33 +2,44 @@
require "rake/tasklib"
require "tempfile"
-class Field
- attr_reader :name
- attr_reader :type
- attr_reader :offset
-
- def initialize(name, type)
- @name = name
- @type = type
- @offset = nil
- end
+class StructGenerator
+ class Field
+ attr_reader :name
+ attr_reader :type
+ attr_reader :offset
+
+ def initialize(name, type)
+ @name = name
+ @type = type
+ @offset = nil
+ end
- def offset=(o)
- @offset = o
+ def offset=(o)
+ @offset = o
+ end
end
-end
-
-class StructGenerator
+
def initialize
@struct_name = nil
@includes = []
@fields = []
end
+
+ def get_field(name)
+ @fields.each do |f|
+ return f if name == f.name
+ end
+
+ return nil
+ end
+
+ attr_reader :fields
def self.generate_from_code(code)
sg = StructGenerator.new
sg.instance_eval(code)
- sg.layout
+ sg.calculate
+ sg.generate_layout
end
def name(n)
@@ -39,11 +50,13 @@ def include(i)
@includes << i
end
- def field(name, type)
- @fields << Field.new(name, type)
+ def field(name, type=nil)
+ fel = Field.new(name, type)
+ @fields << fel
+ return fel
end
- def layout
+ def calculate
binary = "rb_struct_gen_bin_#{Process.pid}"
Tempfile.open("rbx_struct_gen_tmp") do |f|
@@ -79,7 +92,9 @@ def layout
line_no += 1
end
-
+ end
+
+ def generate_layout
buf = ""
@fields.each_with_index do |field, i|
@@ -110,10 +125,6 @@ def initialize
define
end
- def field(name, type)
- @fields << Field.new(name, type)
- end
-
def define
task :clean do
rm_f @dest
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -579,35 +579,60 @@ void machine_setup_argv(machine m, int argc, char **argv) {
machine_set_const(m, "ARGV", ary);
}
-static void machine_parse_config_var(machine m, const char *var) {
- char *eq;
- char buf[1024];
- char *name;
- const char *or;
- name = buf;
- int sz;
- eq = strstr(var, "=");
+int is_number(char *str) {
+ while(*str) {
+ if(!isdigit(*str)) return FALSE;
+ str++;
+ }
+
+ return TRUE;
+}
+
+static char *trim_str(char *str) {
+ int i;
+ while(*str && !isalnum(*str)) str++;
+
+ for(i = strlen(str) - 1; str[i] && !isalnum(str[i]); i++) {
+ str[i] = 0;
+ }
+
+ return str;
+}
+
+static void machine_parse_config_var(machine m, const char *input) {
+ char *name, *val, *var, *eq;
+
+ var = strdup(input);
+ eq = strchr(var, '=');
+
if(eq) {
- or = var;
- sz = eq - var;
- strncpy(name, var, sz);
- name[sz] = 0;
- var += (sz + 1);
- while(*name == ' ') name++;
- if(m->show_config) {
- printf("[config] '%s' => '%s'\n", name, var);
+ *eq++ = 0;
+
+ name = trim_str(var);
+ val = trim_str(eq);
+
+ if(!strcmp("include", name)) {
+ machine_parse_config_file(m, val);
+ } else {
+ if(m->show_config) {
+ printf("[config] '%s' => '%s'\n", name, val);
+ }
+
+ ht_config_insert(m->s->config, cstr2bstr(name), cstr2bstr(val));
}
- ht_config_insert(m->s->config, cstr2bstr(name), cstr2bstr(var));
} else {
if(m->show_config) {
printf("[config] '%s' => '1'\n", var);
}
- while(*var == ' ') var++;
- ht_config_insert(m->s->config, cstr2bstr(var), cstr2bstr("1"));
+
+ name = trim_str(var);
+ ht_config_insert(m->s->config, cstr2bstr(name), cstr2bstr("1"));
}
+
+ free(var);
}
-static void machine_parse_configs(machine m, const char *config) {
+void machine_parse_configs(machine m, const char *config) {
char *semi;
char tmp[1024];
int sz;
@@ -622,22 +647,50 @@ static void machine_parse_configs(machine m, const char *config) {
}
machine_parse_config_var(m, config);
+}
+
+void machine_parse_config_file(machine m, const char *path) {
+ FILE *fo;
+ char line[1024];
- m->s->global->config = hash_new(m->s);
+ fo = fopen(path, "r");
+ if(!fo) return;
+ while(!feof(fo)) {
+ fgets(line, 1024, fo);
+ if(*line) {
+ machine_parse_config_var(m, line);
+ }
+ *line = 0;
+ }
+}
+
+void machine_migrate_config(machine m) {
struct hashtable_itr iter;
- hashtable_iterator_init(&iter, m->s->config);
+ rstate state = m->s;
+
+ m->s->global->config = hash_new(m->s);
+
+ if(hashtable_count(m->s->config) > 0) {
+
+ hashtable_iterator_init(&iter, m->s->config);
- do
- {
- bstring k = (bstring) hashtable_iterator_key(&iter);
- bstring v = (bstring) hashtable_iterator_value(&iter);
- OBJECT ok = string_newfrombstr(m->s, k);
- OBJECT ov = string_newfrombstr(m->s, v);
+ do {
+ OBJECT ok, ov;
+ bstring k = (bstring)hashtable_iterator_key(&iter);
+ bstring v = (bstring)hashtable_iterator_value(&iter);
+ ok = string_newfrombstr(m->s, k);
+ if(is_number(bdata(v))) {
+ ov = I2N(atoi(bdata(v)));
+ } else {
+ ov = string_newfrombstr(m->s, v);
+ }
hash_set(m->s, m->s->global->config, ok, ov);
- }
- while (hashtable_iterator_advance(&iter));
+ } while (hashtable_iterator_advance(&iter));
+
+ }
+
machine_set_const(m, "RUBY_CONFIG", m->s->global->config);
}
@@ -800,9 +853,12 @@ void machine_config_env(machine m) {
config = getenv("RBX");
if(config) {
machine_parse_configs(m, config);
- } else {
- machine_parse_configs(m, "");
}
+
+ config = getenv("RBX_CONFFILE");
+ if(config) {
+ machine_parse_config_file(m, config);
+ }
}
int machine_load_directory(machine m, const char *prefix) {
View
@@ -29,4 +29,7 @@ void machine_emit_memory(machine m);
void machine_save_args(machine m, int argc, char **argv);
void machine_setup_config(machine m);
void machine_setup_from_config(machine m);
+void machine_parse_configs(machine m, const char *config);
+void machine_migrate_config(machine m);
+void machine_parse_config_file(machine m, const char *path);
const char *_inspect(OBJECT obj);
View
@@ -56,6 +56,13 @@ int main(int argc, char **argv) {
/* move argc and argv around so that the kernel and rubinius
don't show up. */
machine_config_env(m);
+
+ archive = search_for("RBX_PLATFORM_CONF", "platform.conf");
+ if(archive) {
+ machine_parse_config_file(m, archive);
+ }
+
+ machine_migrate_config(m);
machine_setup_from_config(m);
machine_setup_argv(m, argc-offset, argv+offset);

0 comments on commit 1c9328e

Please sign in to comment.