erlang判断模块导出函数问题
- 1> erlang:function_exported(crypto,start,0).
- false
- 2> crypto:start().
- ok
- 3> erlang:function_exported(crypto,start,0).
- true
- -module(test).
- -compile(export_all).
- function_exported(Module, Function, Arity) ->
- case erlang:module_loaded(Module) of
- true ->
- next;
- _ ->
- code:ensure_loaded(Module)
- end,
- erlang:function_exported(Module, Function, Arity).
另外,如果模块被改成bif也无法判断了。不过这倒不用太过担心,我们自己写的函数都不会是bif
- BIF_RETTYPE function_exported_3(BIF_ALIST_3)
- {
- if (is_not_atom(BIF_ARG_1) || is_not_atom(BIF_ARG_2) || is_not_small(BIF_ARG_3)) {
- BIF_ERROR(BIF_P, BADARG);
- }
- if (erts_find_function(BIF_ARG_1, BIF_ARG_2, signed_val(BIF_ARG_3),
- erts_active_code_ix()) == NULL) {
- BIF_RET(am_false);
- }
- BIF_RET(am_true);
- }
erts_find_function实现在erts\emulator\beam\export.c中:
- /*
- * Find the export entry for a loaded function.
- * Returns a NULL pointer if the given function is not loaded, or
- * a pointer to the export entry.
- *
- * Note: This function never returns export entries for BIFs
- * or functions which are not yet loaded. This makes it suitable
- * for use by the erlang:function_exported/3 BIF or whenever you
- * cannot depend on the error_handler.
- */
- Export* erts_find_function(Eterm m, Eterm f, unsigned int a, ErtsCodeIndex code_ix)
- {
- struct export_templ templ;
- struct export_entry* ee;
- ee = hash_get(&export_tables[code_ix].htable, init_template(&templ, m, f, a));
- if (ee == NULL || (ee->ep->addressv[code_ix] == ee->ep->code+3 &&
- ee->ep->code[3] != (BeamInstr) BeamOp(op_i_generic_breakpoint))) {
- return NULL;
- }
- return ee->ep;
- }
这里,export_tables是一个全局变量,还是在export.c,其中,code_ix被用来控制代码版本,有时间的话再讨论erlang热更新机制
- static IndexTable export_tables[ERTS_NUM_CODE_IX]; /* Active not locked */
所以,erlang:function_exported/3只是去查找导出函数的哈希表,找到返回true,没有就false
erlang判断模块导出函数问题的更多相关文章
- DLL模块例1:使用.def模块导出函数,规范修饰名称,显示连接调用dll中函数
以下内容,我看了多篇文章,整合在一起,写的一个例子,关于dll工程的创建,请参考博客里另一篇文章:http://www.cnblogs.com/pingge/articles/3153571.html ...
- 关于DLL模块导出函数
当然以前我知道有一个.def文件的,里面写的都是需要导出的函数,以为与__declspec(dllexport)作用是一样的.但是今天看公司项目源码的时候才知道,它们两个导出方法是有一定的区别的,编译 ...
- driver: linux2.6 内核模块导出函数实例(EXPORT_SYMBOL) 【转】
转自:http://blog.chinaunix.net/uid-23381466-id-3837650.html 内核版本:2.6.38-11-generic 内核自己都大量利用内核符号表导出函数, ...
- python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性
python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性 inspect import inspect def fun(): pass inspect.ism ...
- DLL模块例2:使用__declspec(dllexport)导出函数,extern "C"规范修饰名称,隐式连接调用dll中函数
以下内容,我看了多篇文章,整合在一起,写的一个例子,关于dll工程的创建,请参考博客里另一篇文章:http://www.cnblogs.com/pingge/articles/3153571.html ...
- DLL的导出函数重定向机制
曾经,调试时跟进HeapAlloc,结果发现直接进入到ntdll的RtlAllocateHeap中,感到很有趣,就使用Dependency Walker查看kernel32.dll的导出函数,结果发现 ...
- AFX_MANAGE_STATE(AfxGetStaticModuleState())DLL导出函数包含MFC资源
AFX_MANAGE_STATE(AfxGetStaticModuleState()) 先看一个例子: .创建一个动态链接到MFC DLL的规则DLL,其内部包含一个对话框资源.指定该对话框ID如下: ...
- dll 导出函数名的那些事
dll 导出函数名的那些事 关键字: VC++ DLL 导出函数 经常使用VC6的Dependency或者是Depends工具查看DLL导出函数的名字,会发现有DLL导出函数的名字有时大不相同,导 ...
- C# 遍历DLL导出函数
C#如何去遍历一个由C++或E语言编写的本地DLL导出函数呢 不过在这里我建议对PE一无所知的人 你或许应先补补这方面的知识,我不知道为什么PE方面的 应用在C#中怎么这么少,我查阅过相关 C#的知识 ...
随机推荐
- 解决Keystore was tampered with, or password was incorrect
使用签名文件keystore查看生成的数字签名中报错解决 Keystore was tampered with, or password was incorrect 这是由于android规定自己定义 ...
- SimpleDateFormat的使用问题
今天对过去的代码进行重构,因为使用静态方法调用的原因,使用了一个静态的SimpleDateFormat,结果FindBug报错了,查看了一下,说是使用了静态的SimpleDateFormat对象. S ...
- C++开源码项目汇总
Google的C++开源码项目 v8 - V8 JavaScript Engine V8 是 Google 的开源 JavaScript 引擎. V8 採用 C++ 编写,可在谷歌浏览器(来自 G ...
- cpu信息
在linux系统下能够通过cat /proc/cpuinfo来查看本机上cpu的相关信息,通过processor能够推断逻辑cpu的个数,physical id能够推断物理cpu的个数,通过cpu c ...
- maven 解决Cannot change version of project facet Dynamic web module to 2.5
我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的,而一 ...
- HDU 2587 - 很O_O的汉诺塔
看题传送门 吐槽题目 叫什么很O_O的汉诺塔我还@.@呢. 本来是想过一段时间在来写题解的,不过有人找我要. 本来排名是第8的.然后搞了半天,弄到了第五.不过代码最短~ 截止目前就9个ID过,小小的成 ...
- 【例题 6-2 UVA - 514】Rails
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 栈模拟一下就好. 每个输出段后面都有一个空行. 包括最后一个. [代码] #include <bits/stdc++.h> ...
- 【POJ 3415】Common Substrings
[链接]h在这里写链接 [题意] 求两个串的长度大于等于k的公共子串个数. 相同的重复计数. [题解] 先把两个字符串用一个分隔符分开.最好比出现的字符都大的一个数字. ...
- 超链接a的download属性 实现文件下载功能
今天做项目遇到一个要点击按钮下载文件的功能. 百度之 知道了a的download属性.这是HTML5的新特性.主要功能是实现下载功能.主要语法是 <a href="url" ...
- [CSS] Use Generated Content to Augment Information
When you create a pseudo element, you have access to the parent HTML attributes. They can be used in ...