Flash 结合炼金术使用STL 当炼金术支持编译C++时,使用STL似乎是麻烦,主要是由于A。奇怪的是炼金术似乎正在使用。很难相信在GNU的STL中std::string被破坏了
有人想出解决这个问题的办法了吗?没有STL的C++就像没有水的鱼。< / P> < P>这个问题不在STL。Flash 结合炼金术使用STL 当炼金术支持编译C++时,使用STL似乎是麻烦,主要是由于A。奇怪的是炼金术似乎正在使用。很难相信在GNU的STL中std::string被破坏了,flash,alchemy,Flash,Alchemy,有人想出解决这个问题的办法了吗?没有STL的C++就像没有水的鱼。< / P> < P>这个问题不在STL。std::string的GNU实现是使用线程安全函数\uuu GNU cxx::\uu交换和添加\uu GNU cxx::\uu原子添加进行引用计数的。问题是\uu交换\u和
std::string
的GNU实现是使用线程安全函数\uuu GNU cxx::\uu交换和添加\uu GNU cxx::\uu原子添加
进行引用计数的。问题是\uu交换\u和
/\uu原子\uu添加
被破坏
解决方案是用这些函数的良好实现重建STL
幸运的是,炼金术发行版为我们留下了一些面包屑。请参阅$ALCHEMY\u HOME/avm2 libc/README
,它告诉我们如何操作:
The sources used to build avm2-libstdc++.l.bc can be downloaded here:
http://download.macromedia.com/pub/labs/alchemy/alchemy_gnucpp3-4library_121008.zip
To build avm2-libstdc++.l.bc:
cd $ALCHEMY_HOME/avm2-libc
unzip alchemy_gnucpp3-4library_121008.zip
mv lib/avm2-libstdc++.l.bc lib/avm2-libstdc++.l.bc.OLD
make
You should *not* run achacks prior to using these building this library with make.
The Makefiles provided have been preconfigured to use LLVM directly where needed.
通常我希望在libstd++中找到uuu exchange_和add/uuu atomic_uadd的实现($ALCHEMY_HOME/avm2 libc/lib/avm2 libstdc++.l.bc
),但由于某些原因,它们是在libc中定义的($ALCHEMY_HOME/avm2 libc/libc/avm2 libc.l.bc
)
我不知道为什么会这样,但我们可以通过破解原子性来解决这个问题。h,原型保存的地方。请注意,解包alchemy_gnucpp3-4library_121008.zip后,您需要编辑两个atomicity.h文件:
$ALCHEMY\u HOME/avm2 libc/include/c++/3.4/bits/atomicity.h
$ALCHEMY\u HOME/avm2 libc/libstdc++/include/bits/atomicity.h
代码如下:
/*
* __exchange_and_add and __atomic_add are broken in Alchemy's libc.
* Replace them with functioning implementations. This isn't
* cross-platform, but this codebase is only compiling for Alchemy anyway.
*/
#define __exchange_and_add(x,y) __exchange_and_add_fix((x),(y))
#define __atomic_add(x,y) __exchange_and_add_fix((x),(y))
/*
* Correctly implement __exchange_and_add. It's not thread-safe,
* but Alchemy isn't threaded, so we should be ok.
*/
inline _Atomic_word __exchange_and_add_fix(volatile _Atomic_word* __mem, int __val) {
int orig= *__mem;
(*__mem)+= __val;
return orig;
}
以下是一些要运行的测试代码,以确保重建的STL正常工作:
#include <cstdio>
#include <string>
#include <map>
#include <fstream>
using namespace std;
void string_test() {
string s1;
string s2;
s1 = "a";
s2 = s1; // copy constructor
s1 = "b";
// use your favorite TRACE function here
printf("s1= %s \n", s1.c_str()); // expected: "b", actual: "b"
printf("s2= %s \n", s2.c_str()); // expected: "a", actual: "b", ERROR
}
void map_test() {
map<string, int> test_map;
test_map["test1"]= 1;
test_map["test2"]= 2;
test_map["test3"]= 3;
string tmp= "test1";
printf("%s : %d \n", tmp.c_str(), test_map[tmp]);
}
void ifstream_test()
{
std::ifstream in("test.txt");
// ERROR 1:
// Trying to seek file throws an error:
// Error #1006: value is not a function.
// at: basic_filebuf::char_traits::seekoff
in.seekg(0, std::ios::end);
int length = in.tellg();
in.seekg(0, std::ios::beg);
printf("File Length: %d \n", length);
while(in.good()) {
char buffer[512];
// ERROR 2:
// RangeError: Error #1125: The index 1092156 is out of range 721.
// at basic_filebuf::char_traits::underflow::work()
in.getline(buffer, 512, '\n');
printf("buffer= %s \n", buffer);
}
}
int main() {
string_test();
map_test();
ifstream_test();
return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
无效字符串_测试(){
字符串s1;
字符串s2;
s1=“a”;
s2=s1;//复制构造函数
s1=“b”;
//在这里使用您最喜欢的跟踪功能
printf(“s1=%s\n”,s1.c_str());//预期为“b”,实际为“b”
printf(“s2=%s\n”,s2.c_str());//预期为“a”,实际为“b”,错误
}
无效映射_测试(){
地图测试图;
test_map[“test1”]=1;
test_map[“test2”]=2;
test_map[“test3”]=3;
字符串tmp=“test1”;
printf(“%s:%d\n”,tmp.c_str(),test_map[tmp]);
}
无效IFU测试()
{
std::ifstream-in(“test.txt”);
//错误1:
//尝试查找文件时抛出错误:
//错误#1006:值不是函数。
//at:basic_filebuf::char_traits::seekoff
in.seekg(0,std::ios::end);
int length=in.tellg();
in.seekg(0,std::ios::beg);
printf(“文件长度:%d\n”,长度);
while(in.good()){
字符缓冲区[512];
//错误2:
//RangeError:Error#1125:索引1092156超出范围721。
//在basic_filebuf::char_traits::underflow::work()中
in.getline(缓冲区,512,“\n”);
printf(“缓冲区=%s\n”,缓冲区);
}
}
int main(){
字符串_测试();
map_测试();
ifstream_test();
返回0;
}
请注意,重建的STL似乎修复了与和的一些相关问题。这个问题是我放弃炼金术的原因。谢谢分享。@Gunslinger47:如果你准备重建STL,看起来你可以再次开始使用炼金术了。假设您没有转向其他技术。:)