aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-05-02 22:18:09 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-05-02 22:18:09 +0000
commite77032a5a6df50ceb27bcfd6f5fce71428b3332f (patch)
tree6aa20289513975b383574600e0cb2db42e6f1b0b
parent213d79e1a635f92799f5c3ca19efdd1bb0c3ad7f (diff)
downloadpaludis-e77032a5a6df50ceb27bcfd6f5fce71428b3332f.tar.gz
paludis-e77032a5a6df50ceb27bcfd6f5fce71428b3332f.tar.xz
Remove EnvironmentData class.
-rw-r--r--ruby/check.cc4
-rw-r--r--ruby/dep_list.cc2
-rw-r--r--ruby/environment.cc75
-rw-r--r--ruby/find_unused_packages_task.cc2
-rw-r--r--ruby/paludis_ruby.cc2
-rw-r--r--ruby/paludis_ruby.hh28
-rw-r--r--ruby/qa_environment.cc13
7 files changed, 43 insertions, 83 deletions
diff --git a/ruby/check.cc b/ruby/check.cc
index 0a1edcd..e89da4d 100644
--- a/ruby/check.cc
+++ b/ruby/check.cc
@@ -72,7 +72,7 @@ namespace
ptr = new EbuildCheckData(
value_to_qualified_package_name(argv[0]),
value_to_version_spec(argv[1]),
- value_to_qa_environment(argv[2]));
+ value_to_qa_environment(argv[2]).get());
}
else
{
@@ -112,7 +112,7 @@ namespace
ptr = new PerProfileEbuildCheckData(
value_to_qualified_package_name(argv[0]),
value_to_version_spec(argv[1]),
- value_to_qa_environment(argv[2]),
+ value_to_qa_environment(argv[2]).get(),
FSEntry(StringValuePtr(argv[3]))
);
}
diff --git a/ruby/dep_list.cc b/ruby/dep_list.cc
index 4eeaba5..d0f907a 100644
--- a/ruby/dep_list.cc
+++ b/ruby/dep_list.cc
@@ -804,7 +804,7 @@ namespace
{
if (2 == argc)
{
- ptr = new DepList(value_to_environment_data(argv[0])->env_ptr,
+ ptr = new DepList(value_to_environment(argv[0]).get(),
*value_to_dep_list_options(argv[1]));
}
else
diff --git a/ruby/environment.cc b/ruby/environment.cc
index eaf3ea6..969c3c4 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -45,13 +45,10 @@ namespace
VALUE
environment_query_use(VALUE self, VALUE flag, VALUE pdev)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
-
try
{
PackageDatabaseEntry pde(value_to_package_database_entry(pdev));
- return env_data->env_ptr->query_use(UseFlagName(StringValuePtr(flag)), pde) ? Qtrue : Qfalse;
+ return value_to_environment(self)->query_use(UseFlagName(StringValuePtr(flag)), pde) ? Qtrue : Qfalse;
}
catch (const std::exception & e)
{
@@ -68,13 +65,10 @@ namespace
VALUE
environment_mask_reasons(VALUE self, VALUE pde_value)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
-
PackageDatabaseEntry pde = value_to_package_database_entry(pde_value);
try
{
- MaskReasons r(env_data->env_ptr->mask_reasons(pde));
+ MaskReasons r(value_to_environment(self)->mask_reasons(pde));
return mask_reasons_to_value(r);
}
catch (const std::exception & e)
@@ -92,12 +86,9 @@ namespace
VALUE
environment_package_database(VALUE self)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
-
try
{
- return package_database_to_value(env_data->env_ptr->package_database());
+ return package_database_to_value(value_to_environment(self)->package_database());
}
catch (const std::exception & e)
{
@@ -114,12 +105,9 @@ namespace
VALUE
environment_set(VALUE self, VALUE set_name)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
-
try
{
- return dep_spec_to_value(env_data->env_ptr->set(SetName(StringValuePtr(set_name))));
+ return dep_spec_to_value(value_to_environment(self)->set(SetName(StringValuePtr(set_name))));
}
catch (const std::exception & e)
{
@@ -136,12 +124,10 @@ namespace
VALUE
environment_accept_license(VALUE self, VALUE license, VALUE p)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
try
{
PackageDatabaseEntry pde = value_to_package_database_entry(p);
- return env_data->env_ptr->accept_license(std::string(StringValuePtr(license)), pde) ? Qtrue : Qfalse;
+ return value_to_environment(self)->accept_license(std::string(StringValuePtr(license)), pde) ? Qtrue : Qfalse;
}
catch (const std::exception & e)
{
@@ -158,8 +144,6 @@ namespace
VALUE
environment_accept_keywords(VALUE self, VALUE keywords, VALUE p)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
try
{
PackageDatabaseEntry pde = value_to_package_database_entry(p);
@@ -171,7 +155,7 @@ namespace
VALUE kw = rb_ary_entry(keywords, i);
knc->insert(KeywordName(StringValuePtr(kw)));
}
- return env_data->env_ptr->accept_keywords(knc, pde) ? Qtrue : Qfalse;
+ return value_to_environment(self)->accept_keywords(knc, pde) ? Qtrue : Qfalse;
}
catch (const std::exception & e)
{
@@ -188,9 +172,7 @@ namespace
VALUE
environment_root(VALUE self)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
- return rb_str_new2(stringify(env_data->env_ptr->root()).c_str());
+ return rb_str_new2(stringify(value_to_environment(self)->root()).c_str());
}
/*
@@ -203,9 +185,7 @@ namespace
VALUE
environment_default_destinations(VALUE self)
{
- EnvironmentData * env_data;
- Data_Get_Struct(self, EnvironmentData, env_data);
- std::tr1::shared_ptr<const DestinationsCollection> dc = env_data->env_ptr->default_destinations();
+ std::tr1::shared_ptr<const DestinationsCollection> dc (value_to_environment(self)->default_destinations());
VALUE result(rb_ary_new());
for (DestinationsCollection::Iterator i(dc->begin()), i_end(dc->end()) ; i != i_end ; ++i)
rb_ary_push(result, repository_to_value(*i));
@@ -214,12 +194,14 @@ namespace
}
- PaludisEnvironment *
+ std::tr1::shared_ptr<PaludisEnvironment>
value_to_paludis_environment(VALUE v)
{
if (rb_obj_is_kind_of(v, c_paludis_environment))
{
- return static_cast<PaludisEnvironment *>(value_to_environment_data(v)->env_ptr);
+ std::tr1::shared_ptr<PaludisEnvironment> * v_ptr;
+ Data_Get_Struct(v, std::tr1::shared_ptr<PaludisEnvironment>, v_ptr);
+ return *v_ptr;
}
else
{
@@ -251,9 +233,8 @@ namespace
else if (0 != argc)
rb_raise(rb_eArgError, "PaludisEnvironment.new expects one or zero arguments, but got %d", argc);
- PaludisEnvironment * e(new PaludisEnvironment(config_suffix));
- EnvironmentData * ptr(new EnvironmentData(e, e));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<EnvironmentData>::free, ptr));
+ std::tr1::shared_ptr<PaludisEnvironment> * e = new std::tr1::shared_ptr<PaludisEnvironment>(new PaludisEnvironment(config_suffix));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<PaludisEnvironment> >::free, e));
rb_obj_call_init(tdata, argc, argv);
return tdata;
}
@@ -323,14 +304,13 @@ namespace
else
path = StringValuePtr(argv[0]);
- NoConfigEnvironment * e(new NoConfigEnvironment(NoConfigEnvironmentParams::create()
+ std::tr1::shared_ptr<NoConfigEnvironment> * e = new std::tr1::shared_ptr<NoConfigEnvironment>(new NoConfigEnvironment(NoConfigEnvironmentParams::create()
.repository_dir(FSEntry(path))
.write_cache(write_cache)
.accept_unstable(false)
.repository_type(ncer_auto)
.master_repository_dir(FSEntry(master_repository_dir))));
- EnvironmentData * ptr(new EnvironmentData(e, e));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<EnvironmentData>::free, ptr));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<NoConfigEnvironment> >::free, e));
rb_obj_call_init(tdata, argc, argv);
return tdata;
}
@@ -405,11 +385,10 @@ namespace
{
try
{
- std::tr1::shared_ptr<Environment> e(EnvironmentMaker::get_instance()->make_from_spec(
+ std::tr1::shared_ptr<Environment> * e = new std::tr1::shared_ptr<Environment>(EnvironmentMaker::get_instance()->make_from_spec(
StringValuePtr(spec)));
- EnvironmentData * ptr(new EnvironmentData(e.get(), 0, e));
- VALUE tdata(Data_Wrap_Struct(c_environment, 0, &Common<EnvironmentData>::free, ptr));
+ VALUE tdata(Data_Wrap_Struct(c_environment, 0, &Common<std::tr1::shared_ptr<Environment> >::free, e));
return tdata;
}
catch (const std::exception & e)
@@ -474,27 +453,29 @@ namespace
}
}
-EnvironmentData *
-paludis::ruby::value_to_environment_data(VALUE v)
+std::tr1::shared_ptr<Environment>
+paludis::ruby::value_to_environment(VALUE v)
{
if (rb_obj_is_kind_of(v, c_environment))
{
- EnvironmentData * v_ptr;
- Data_Get_Struct(v, EnvironmentData, v_ptr);
- return v_ptr;
+ std::tr1::shared_ptr<Environment> * v_ptr;
+ Data_Get_Struct(v, std::tr1::shared_ptr<Environment>, v_ptr);
+ return *v_ptr;
}
else
{
- rb_raise(rb_eTypeError, "Can't convert %s into EnvironmentData", rb_obj_classname(v));
+ rb_raise(rb_eTypeError, "Can't convert %s into Environment", rb_obj_classname(v));
}
}
-NoConfigEnvironment *
+std::tr1::shared_ptr<NoConfigEnvironment>
paludis::ruby::value_to_no_config_environment(VALUE v)
{
if (rb_obj_is_kind_of(v, c_no_config_environment))
{
- return static_cast<NoConfigEnvironment *>(value_to_environment_data(v)->env_ptr);
+ std::tr1::shared_ptr<NoConfigEnvironment> * v_ptr;
+ Data_Get_Struct(v, std::tr1::shared_ptr<NoConfigEnvironment>, v_ptr);
+ return *v_ptr;
}
else
{
diff --git a/ruby/find_unused_packages_task.cc b/ruby/find_unused_packages_task.cc
index e55dae6..a577882 100644
--- a/ruby/find_unused_packages_task.cc
+++ b/ruby/find_unused_packages_task.cc
@@ -44,7 +44,7 @@ namespace
{
if (2 == argc)
{
- ptr = new FindUnusedPackagesTask(value_to_environment_data(argv[0])->env_ptr,
+ ptr = new FindUnusedPackagesTask(value_to_environment(argv[0]).get(),
value_to_repository(argv[1]).get());
}
else
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index c63d9f6..456d625 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -94,7 +94,7 @@ namespace
{
try
{
- Environment * env = value_to_environment_data(en)->env_ptr;
+ std::tr1::shared_ptr<Environment> env = value_to_environment(en);
std::tr1::shared_ptr<const PackageDepSpec> spec = value_to_package_dep_spec(a);
PackageDatabaseEntry target = value_to_package_database_entry(t);
return match_package(*env, *spec, target) ? Qtrue : Qfalse;
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 33b3adb..8a98f14 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -47,28 +47,6 @@ namespace paludis
namespace ruby
{
- class EnvironmentData
- {
- private:
- Environment * _e;
- const std::tr1::shared_ptr<Environment> _ee;
-
- public:
- Environment * const env_ptr;
-
- EnvironmentData(Environment * const ee, Environment * const free_e = 0,
- const std::tr1::shared_ptr<Environment> & free_sp_e = std::tr1::shared_ptr<Environment>()) :
- _e(free_e),
- _ee(free_sp_e),
- env_ptr(ee)
- {
- }
-
- ~EnvironmentData()
- {
- delete _e;
- }
- };
/* general utilities */
void exception_to_ruby_exception(const std::exception &) PALUDIS_ATTRIBUTE((noreturn));
@@ -101,8 +79,8 @@ namespace paludis
std::tr1::shared_ptr<const DepSpec> value_to_dep_spec(VALUE v);
QualifiedPackageName value_to_qualified_package_name(VALUE v);
PackageDatabaseEntry value_to_package_database_entry(VALUE v);
- EnvironmentData* value_to_environment_data(VALUE v);
- NoConfigEnvironment* value_to_no_config_environment(VALUE v);
+ std::tr1::shared_ptr<Environment> value_to_environment(VALUE v);
+ std::tr1::shared_ptr<NoConfigEnvironment> value_to_no_config_environment(VALUE v);
RepositoryPortageInterface::ProfilesDescLine value_to_profiles_desc_line(VALUE v);
MaskReasons value_to_mask_reasons(VALUE v);
Query value_to_query(VALUE v);
@@ -114,7 +92,7 @@ namespace paludis
qa::EbuildCheckData value_to_ebuild_check_data(VALUE v);
qa::PerProfileEbuildCheckData value_to_per_profile_ebuild_check_data(VALUE v);
qa::ProfileCheckData value_to_profile_check_data(VALUE v);
- qa::QAEnvironment* value_to_qa_environment(VALUE v);
+ std::tr1::shared_ptr<qa::QAEnvironment> value_to_qa_environment(VALUE v);
VALUE ebuild_check_data_to_value(const qa::EbuildCheckData &);
VALUE per_profile_ebuild_check_data_to_value(const qa::PerProfileEbuildCheckData &);
VALUE profile_check_data_to_value(const qa::ProfileCheckData &);
diff --git a/ruby/qa_environment.cc b/ruby/qa_environment.cc
index 34032c3..df1b985 100644
--- a/ruby/qa_environment.cc
+++ b/ruby/qa_environment.cc
@@ -72,10 +72,9 @@ namespace
{
rb_raise(rb_eArgError, "QAEnvironment expects one to three arguments, but got %d",argc);
}
- QAEnvironment * e = new QAEnvironment(FSEntry(StringValuePtr(argv[0])), FSEntry(write_cache),
- FSEntry(master_repository_dir));
- EnvironmentData * ptr(new EnvironmentData(e,e));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<EnvironmentData>::free, ptr));
+ std::tr1::shared_ptr<QAEnvironment> * e = new std::tr1::shared_ptr<QAEnvironment>(new QAEnvironment(FSEntry(StringValuePtr(argv[0])), FSEntry(write_cache),
+ FSEntry(master_repository_dir)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common< std::tr1::shared_ptr<QAEnvironment> >::free, e));
rb_obj_call_init(tdata, argc, argv);
return tdata;
}
@@ -99,12 +98,14 @@ namespace
}
}
-QAEnvironment*
+std::tr1::shared_ptr<QAEnvironment>
paludis::ruby::value_to_qa_environment(VALUE v)
{
if (rb_obj_is_kind_of(v, c_qa_environment))
{
- return static_cast<QAEnvironment *>(value_to_environment_data(v)->env_ptr);
+ std::tr1::shared_ptr<QAEnvironment> * v_ptr;
+ Data_Get_Struct(v, std::tr1::shared_ptr<QAEnvironment>, v_ptr);
+ return *v_ptr;
}
else
{