1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Don't replace ENV twice on non Windows platforms

https://github.com/rubygems/rubygems/commit/8dc86b7096
This commit is contained in:
David Rodríguez 2021-10-15 13:51:49 +02:00 committed by git
parent 3d19c2900e
commit c4b1aa19a3
4 changed files with 68 additions and 1 deletions

View file

@ -38,7 +38,10 @@ module Bundler
# Replaces `ENV` with the bundler environment variables backed up
def replace_with_backup
ENV.replace(backup) unless Gem.win_platform?
unless Gem.win_platform?
ENV.replace(backup)
return
end
# Fallback logic for Windows below to workaround
# https://bugs.ruby-lang.org/issues/16798. Can be dropped once all

View file

@ -0,0 +1,57 @@
# frozen_string_literal: true
RSpec.describe "loading dinamically linked library on a bundle exec context", :realworld => true do
it "passes ENV right after argv in memory" do
create_file "foo.rb", <<~RUBY
require 'ffi'
module FOO
extend FFI::Library
ffi_lib './libfoo.so'
attach_function :Hello, [], :void
end
FOO.Hello()
RUBY
create_file "libfoo.c", <<~'C'
#include <stdio.h>
static int foo_init(int argc, char** argv, char** envp) {
if (argv[argc+1] == NULL) {
printf("FAIL\n");
} else {
printf("OK\n");
}
return 0;
}
#if defined(__APPLE__) && defined(__MACH__)
__attribute__((section("__DATA,__mod_init_func"), used, aligned(sizeof(void*))))
#else
__attribute__((section(".init_array")))
#endif
static void *ctr = &foo_init;
extern char** environ;
void Hello() {
return;
}
C
sys_exec "gcc -g -o libfoo.so -shared -fpic libfoo.c"
install_gemfile <<-G
source "https://rubygems.org"
gem 'ffi'
G
bundle "exec ruby foo.rb"
expect(out).to eq("OK")
end
end

View file

@ -0,0 +1,7 @@
> GET /gems/ffi-1.15.4.gem
> accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
> accept: */*
> user-agent: Ruby
> connection: keep-alive
> keep-alive: 30
> host: rubygems.org