code:load_binary - why there's module as argument

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

code:load_binary - why there's module as argument

John Doe
Hi all,
I wonder why code:load_binary() requires module name as one of the arguments? The function would fail if this name is not equal to the real module name from the binary, so it can deduce the correct name. Why it does not allow loading just whatever module from a given binary and return something like {ok, moduleName} as the result?

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: code:load_binary - why there's module as argument

Attila Rajmund Nohl
2018-04-14 21:11 GMT+02:00 John Doe <[hidden email]>:
Hi all,
I wonder why code:load_binary() requires module name as one of the arguments? The function would fail if this name is not equal to the real module name from the binary, so it can deduce the correct name. Why it does not allow loading just whatever module from a given binary and return something like {ok, moduleName} as the result?

​I guess to avoid overwriting an unexpected module. The input binary can contain any code, if it pretends to be the list module, but the caller thinks its the strings module, that could be a problem.​


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: code:load_binary - why there's module as argument

John Doe
Fair enough, but it would be nice to have a version without such limitation.

2018-04-16 12:05 GMT+03:00 Attila Rajmund Nohl <[hidden email]>:
2018-04-14 21:11 GMT+02:00 John Doe <[hidden email]>:
Hi all,
I wonder why code:load_binary() requires module name as one of the arguments? The function would fail if this name is not equal to the real module name from the binary, so it can deduce the correct name. Why it does not allow loading just whatever module from a given binary and return something like {ok, moduleName} as the result?

​I guess to avoid overwriting an unexpected module. The input binary can contain any code, if it pretends to be the list module, but the caller thinks its the strings module, that could be a problem.​


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: code:load_binary - why there's module as argument

Pierre Fenoll-2
Semantically it ensures that the atom is already in the atom table. Now I didn’t look at the code but maybe there is an assumption on this. 
Send a PR maybe?

On Mon 16 Apr 2018 at 20:05, John Doe <[hidden email]> wrote:
Fair enough, but it would be nice to have a version without such limitation.

2018-04-16 12:05 GMT+03:00 Attila Rajmund Nohl <[hidden email]>:
2018-04-14 21:11 GMT+02:00 John Doe <[hidden email]>:
Hi all,
I wonder why code:load_binary() requires module name as one of the arguments? The function would fail if this name is not equal to the real module name from the binary, so it can deduce the correct name. Why it does not allow loading just whatever module from a given binary and return something like {ok, moduleName} as the result?

​I guess to avoid overwriting an unexpected module. The input binary can contain any code, if it pretends to be the list module, but the caller thinks its the strings module, that could be a problem.​


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
--

Cheers,
-- 
Pierre Fenoll


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions