[erlang-questions] Function Dependency

Richard O'Keefe ok@REDACTED
Wed Aug 22 00:19:10 CEST 2012


On 21/08/2012, at 6:23 PM, Tyron Zerafa wrote:
> 
> I need to extract the function body for the following reasons. I need to transfer only the code that a function makes use of between nodes, nothing more. Xref is giving me the signature of all those functions that I need. Now, I want to use these signatures to extract the remaining body of the functions. 

Xref *never* provides any kind of signatures.
All it provides is function *names* (module:atom/arity triples).
Those are *NOT* what computer science calls signatures.
> 
> Another short question, is there any way in which I can differentiate whether a function comes from an Erlang release or not? Thus, if for example I ask is_native(io_lib,format,2) - > true, otherwise is_native(MyModule, MyFunction,0) -> false. I do not need to transfer functions which are native to Erlang and which can be found on any Erlang node.

Suppose you have the name of a function in MFA {Module,Function,Arity}
form.  If any function in a module comes from an Erlang/OTP release,
all of them do.  So you need to find out where a module comes from.

code:is_loaded(Module_Name)
  -> {file,"/where/it/came/from"}
    if the module is loaded;
  -> preloaded
    if the module is preloaded
  -> cover_compiled
    if the module was processed by cover(3)
    for coverage analysis

All of the files from an Erlang release will be somewhere inside a
common directory; on my Solaris 10 box it's /users/local/lib/erlang/lib.

Just what are you going to do if a function you want to send over
depends on a driver written in C?  The receiving system may not have
that driver, and even if you could extract it, that might do no good
because one of the systems might be an ARM7 and the other might be
an x86_64.

Then too, suppose you want to extract the function whose name is
{nurke,fred,1} and you discover that it depends on {seagoon,neddy,5},
but you think that's ok, because the receiving system tells you it
*has* {seagoon,neddy,5}.  How do you know it means the same thing?

Yesterday I was reading a short article in New Scientist about
someone transplanting bits of zebra finch embryo brains into
quail embryo brains.  I can see the scientific reasons for this
but some things just fail the gut test, they really do.
It's not at all surprising that the quanch embryos don't hatch.
That kind of thing only works between closely related species.

Get my drift?  You cannot expect to "transplant" an arbitrary function
from one Erlang system to another unless you have ensured that they
are very very similar.  And if you can exert that much control over
both configurations, why not ensure that they are identical?

I don't even want to think of the security implications of a system
deliberately allowing another one to inject arbitrary code into itself.
But you should!




More information about the erlang-questions mailing list