$SAFE=4 and persistent storage! That is what i want.

This commit is contained in:
Denis Knauf 2010-03-02 00:51:15 +01:00
parent 4d4978d3ac
commit b82ce54d60
2 changed files with 50 additions and 21 deletions

View file

@ -2,38 +2,66 @@
require 'thread'
class Queue
attr_reader :que, :waiting
end
class Box
attr_reader :_
attr_reader :_, :emited
alias db emited
alias persistent emited
attr_accessor :emited
def initialize _
@_, @emited = _, []
def initialize db, _
@_, @emited = _, db
end
def emit k, v
@emited.push [k, v]
@emited[k] = v
end
def do code
instance_eval code, self.class.to_s, 0
end
end
Thread.abort_on_exception = true
q, o, r = Queue.new, Queue.new, nil
puts q.inspect
$stdout.print "(0)$ "
require 'sbdb'
STDIN.each_with_index do |l, i|
r = begin
Thread.new do
class Persistent
include Enumerable
def initialize( db) @db, @cursor = db, db.cursor end
def emit( k, v) @db[k] = v end
alias push emit
alias put emit
alias []= emit
def get( k) @db[k] end
alias [] get
alias fetch get
def inspect() "#<%s:0x%016x>" % [ self.class, self.object_id ] end
def each &e
e ? @cursor.each( &e) : Enumerator.new( self, :each)
end
def to_hash
h = {}
each {|k, v| h[ k] = v }
h
end
end
#Persistent.freeze
r = nil
Dir.mkdir 'logs' rescue Errno::EEXIST
SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs|
db = Persistent.new logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE]
$stdout.print "(0)$ "
STDIN.each_with_index do |l, i|
r = Thread.new do
l.untaint
$SAFE = 4
b = Box.new r
[b.instance_eval( l, 'BOX', 0), b.emited]
b = Box.new db, r
begin
b.do( l)
rescue Object
$!
end
end.value
rescue Object
[$!.class, $!, $!.backtrace].inspect
end
$stdout.print "#{r.inspect}\n(#{i+1})$ "
$stdout.print "=> #{r.inspect}\n(#{i+1})$ "
end
end

View file

@ -44,6 +44,7 @@ end
SBDB::Env.new 'conf' do |conf|
SBDB::Env.new 'logs' do |logs|
SBDB::Env.new 'cache' do |cache|
test = cache[ 'test']
while line = logs[ 'newids'].get( nil, "\0\0\0\0", nil, SBDB::CONSUME_WAIT)
end