Class: ChildProcess::Unix::PosixSpawnProcess::Envp

Inherits:
Object
  • Object
show all
Defined in:
lib/childprocess/unix/posix_spawn_process.rb

Overview

Argv

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Envp

Returns a new instance of Envp.



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/childprocess/unix/posix_spawn_process.rb', line 116

def initialize(env)
  @ptrs = env.map do |key, val|
    next if val.nil?

    if key =~ /=|\0/ || val.include?("\0")
      raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.inspect}"
    end

    FFI::MemoryPointer.from_string("#{key}=#{val}")
  end.compact

  @ptrs << nil
end

Instance Method Details

#to_ptrObject



130
131
132
133
134
135
# File 'lib/childprocess/unix/posix_spawn_process.rb', line 130

def to_ptr
  env = FFI::MemoryPointer.new(:pointer, @ptrs.size)
  env.put_array_of_pointer(0, @ptrs)

  env
end