3434
3535#include < libcob.h>
3636
37+ #include < string>
3738#include < map>
3839
3940typedef struct loader_impl_cob_handle_type
@@ -123,7 +124,7 @@ loader_impl_data cob_loader_impl_initialize(loader_impl impl, configuration conf
123124 (void )impl;
124125 (void )config;
125126
126- loader_copy (host-> log );
127+ loader_copy (host);
127128
128129 // Copy environment variables in order to resolve properly the scripts
129130 const char * scripts_path = getenv (" LOADER_SCRIPT_PATH" );
@@ -156,17 +157,15 @@ int cob_loader_impl_execution_path(loader_impl impl, const loader_naming_path pa
156157
157158loader_handle cob_loader_impl_load_from_file (loader_impl impl, const loader_naming_path paths[], size_t size)
158159{
159- loader_impl_cob_handle cob_handle = static_cast <loader_impl_cob_handle>( malloc ( sizeof ( struct loader_impl_cob_handle_type )) );
160+ loader_impl_cob_handle cob_handle = new loader_impl_cob_handle_type ( );
160161
161162 (void )impl;
162163
163- if (cob_handle == NULL )
164+ if (cob_handle == nullptr )
164165 {
165166 return NULL ;
166167 }
167168
168- cob_handle->funcs = std::map<std::string, void *>();
169-
170169 for (size_t path_count = 0 ; path_count < size; ++path_count)
171170 {
172171 loader_naming_name module_name;
@@ -188,14 +187,14 @@ loader_handle cob_loader_impl_load_from_file(loader_impl impl, const loader_nami
188187 }
189188 else
190189 {
191- cob_handle->funcs [module_name] = func;
190+ cob_handle->funcs . insert (std::pair<std::string, void *>( std::string (module_name), func)) ;
192191 }
193192 }
194193 }
195194
196195 if (cob_handle->funcs .size () == 0 )
197196 {
198- free ( cob_handle) ;
197+ delete cob_handle;
199198 return NULL ;
200199 }
201200
@@ -230,9 +229,11 @@ int cob_loader_impl_clear(loader_impl impl, loader_handle handle)
230229
231230 (void )impl;
232231
233- if (cob_handle != NULL )
232+ if (cob_handle != nullptr )
234233 {
235- free (cob_handle);
234+ // TODO: Is there any cob_resolve inverse function?
235+
236+ delete cob_handle;
236237 }
237238
238239 return 0 ;
@@ -246,9 +247,9 @@ int cob_loader_impl_discover(loader_impl impl, loader_handle handle, context ctx
246247
247248 (void )impl;
248249
249- for (std::pair<std::string, void *> func : cob_handle->funcs )
250+ for (const auto & func : cob_handle->funcs )
250251 {
251- function f = function_create (func.first .c_str (), 0 , NULL , &function_cob_singleton);
252+ function f = function_create (func.first .c_str (), 0 , func. second , &function_cob_singleton);
252253
253254 scope_define (sp, function_name (f), value_create_function (f));
254255 }
0 commit comments