我[rust] "instead of a package manifest"在问之前在这个网站上搜索过,但没有找到。我还在这里阅读了虚拟清单,但没有解决我的问题。
我的目标是对azul进行更改。
为了实现这一点,我在这里阅读了有关修补依赖项的信息,现在我有了这个Cargo.toml
[package]
name = "my_first_azul_app"
version = "0.1.0"
authors = ["Name <Email>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
azul = { git = "https://github.com/maps4print/azul" }
[patch."https://github.com/maps4print/azul"]
azul = { path = "../azul" }
Run Code Online (Sandbox Code Playgroud)
在路径中,../azul我使用git clone. 在main.rs我遵循这个得到,
extern crate azul;
fn main() {
println!("Hello world!");
} …Run Code Online (Sandbox Code Playgroud) 我在Windows 8上使用Python 3.4.1.
我想读一个带缓冲接口的文件,它允许我查看前面的一定数量的字节以及读取字节.io.BufferedReader似乎是正确的选择.
不幸的是,io.BufferReader.peek似乎没用,因为它似乎只返回缓冲区中存储的所有字节,而不是请求的数字.事实上,这个函数的文档允许这样做(强调我的):
peek([size])从流中返回字节而不提升位置.最多只对原始流进行一次读取以满足调用.返回的字节数可能少于或多于请求的数量.
为了演示我认为无用的行为,我有以下测试文件Test1.txt:
first line
second line
third line
Run Code Online (Sandbox Code Playgroud)
我io.BufferedReader在IDLE中创建这样的对象:
>>> stream = io.BufferedReader(io.FileIO('Test1.txt'))
Run Code Online (Sandbox Code Playgroud)
然后要求两个字节,
>>> stream.peek(2)
b'first line\r\nsecond line\r\nthird line'
Run Code Online (Sandbox Code Playgroud)
嗯?这只是默认缓冲区大小中的所有文本(在我的系统上是8192字节).如果我更改此默认值,我可以确认peek()只是返回缓冲区的内容,
>>> stream2 = io.BufferedReader(io.FileIO('Test1.txt'), buffer_size=2)
>>> stream2.peek(17)
b'fi'
>>> stream2.peek(17)
b'fi'
>>> stream2.read(2)
b'fi'
>>> stream2.peek(17)
b'rs'
Run Code Online (Sandbox Code Playgroud)
需要说明的是,以下是我希望看到的输出:
>>> stream = io.BufferedReader(io.FileIO('Test1.txt'))
>>> stream.peek(2)
b'fi'
>>> stream.read(1)
b'f'
>>> stream.peek(2)
b'ir'
Run Code Online (Sandbox Code Playgroud)
也就是说,典型的缓冲流.
我在构建这个时做错了BufferedReader什么?如何观察我期望在Python 3.4.1中看到的行为?
我已经从具有完整调试信息的源代码(Clang IIUC 的默认构建类型)构建了 Clang 程序。我通过注意到模块中有编译单元来检查可执行文件中的调试信息是否可用:
$ lldb /opt/bin/clang++
(lldb) script lldb.target.module['/opt/bin/clang++'].GetNumCompileUnits()
1341
Run Code Online (Sandbox Code Playgroud)
我在 Clang 源代码树中检测了一个文件,lib/Sema/SemaExpr.cpp在Sema::DiagnoseAssignmentResult方法中使用 printf 语句(在我的副本中的第 10853 行)。我知道我的测试文件会调用此方法test.cc,但我无法让调试器在此方法的断点处停止!我试过用两种方式设置断点,
$ lldb /opt/bin/clang++
(lldb) breakpoint set -m DiagnoseAssignmentResult
Breakpoint 2: where = clang++`clang::Sema::DiagnoseAssignmentResult(clang::Sema::AssignConvertType, clang::SourceLocation, clang::QualType, clang::QualType, clang::Expr*, clang::Sema::AssignmentAction, bool*) + 87 at SemaExpr.cpp:10858, address = 0x0000000100ab9947
(lldb) process launch -- ./test.cc
<< message from my printf statement >>
... then clang++ runs to completion and exits, no breakpoint hit ...
(lldb)
Run Code Online (Sandbox Code Playgroud)
我注意到lldb 确实在源代码中找到了正确的位置,但是当它通过方法时并没有停止。我还尝试通过指定文件和行号来设置断点, …
**编辑:问题不是关于未对齐数据访问的定义,而是为什么memcpy使ubsanitizers静音而类型转换没有,尽管生成相同的汇编代码**
我有一些示例代码来解析一个协议,该协议发送一个字节数组,该数组被分段为六个字节的组.
void f(u8 *ba) {
// I know this array's length is a multiple of 6
u8 *p = ba;
u32 a = *(u32 *)p;
printf("a = %d\n", a);
p += 4;
u16 b = *(u16 *)p;
printf("b = %d\n", b);
p += 2;
a = *(u32 *)p;
printf("a = %d\n", a);
p += 4;
b = *(u16 *)p;
printf("b = %d\n", b);
}
Run Code Online (Sandbox Code Playgroud)
在将指针递增6并进行另一次32位读取后,UBSan会报告有关未对齐负载的错误.我使用memcpy而不是类型惩罚来压制这个错误,但我不太清楚为什么.要清楚,这是没有UBSan错误的相同例程,
void f(u8 *ba) {
// I know this array's length is a …Run Code Online (Sandbox Code Playgroud) 我很难在SO上找到许多引用这个主题的答案,但这里有一些看似无辜的代码,当F它不是一个定义的宏时无法编译,
int main() {
#if defined(F) && F(0, 2, 0)
return 0;
#endif
return 1;
}
Run Code Online (Sandbox Code Playgroud)
根据GCC手册的这一部分,问题是内部#if表达式"表达式中的所有宏都在表达式值的实际计算开始之前被扩展",所以这在无效检查中,因为当F未定义时,我看到,
test.cpp:2:20: error: missing binary operator before token "("
#if defined(F) && F(0, 2, 0)
^
Run Code Online (Sandbox Code Playgroud)
我的问题:这是正确做这种检查的唯一方法吗?
int main() {
#if defined(F)
#if F(0, 2, 0)
return 0;
#endif
#endif
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我发现这很丑陋且不直观,所以我希望在预处理器中有更好的方法来做这些事情.
我带来了很多来自Java的假设,以及我对C++的学习,这似乎让我再次陷入困境.我没有足够的词汇来雄辩地说出我希望从下面的程序中看到的内容,所以我只是提出它并说出我期望看到的内容:
#include <iostream>
#include <vector>
using namespace std;
class Piece {};
class Man : public Piece {};
class Square {
Piece p;
public:
Square(Piece p) : p(p) { };
Piece get_piece() const { return p; }
};
ostream& operator<<(ostream& os, const Piece& p)
{
cout << "Piece";
return os;
}
ostream& operator<<(ostream& os, const Man& m)
{
cout << "Man";
return os;
}
ostream& operator<<(ostream& os, const Square& s)
{
cout << s.get_piece() << '\n';
return os;
}
int main() …Run Code Online (Sandbox Code Playgroud) 以下程序产生分段错误,我不知道为什么.malloc成功,所以它似乎不是一个初始化错误,但由于某种原因,当我访问253900元素时它会段错误.该数组只有4*1e6字节,或大约一兆字节.
这确实产生了很多输出
#include <stdlib.h>
#include <stdio.h>
int *long_array(size_t N) {
int *arr = (int *) malloc(N);
if (arr == NULL) { printf("could not malloc"); exit(1); }
for (size_t i = 0; i < N; i++) {
printf(".. %ld ", i);
arr[i] = 10;
}
printf("done with loop\n");
return arr;
}
int main(void) {
int *arr = long_array(1000000);
printf("%d", arr[5050]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我编译它gcc -std=c99并运行输出以查看在segfault之前打印的最后几个数字:
253899 .. 253900 .. 2
segmentation fault (core dumped) ./a.out
Run Code Online (Sandbox Code Playgroud)
我不明白为什么访问特定索引会导致分段错误.我猜我必须访问我的进程地址空间之外的内存位置,但如果我从地址空间成功分配内存,这似乎是一个错误.
我根据这里的文档构建了LLVM和Clang .
步骤是
export SRC_DIR=/work/llvmexport BUILD_DIR=/work/make_llvmcd $BUILD_DIR$SRC_DIR/configure --prefix=/work/my_llvmmake -j 4make install我PATH确实/work/my_llvm/bin在前面.
然后我cd $BUILD_DIR/examples输入make系统响应的类型,
llvm-config: unknown component name: jit
make[1]: Entering directory `/work/make_llvm/examples/BrainF'
/work/llvm/Makefile.rules:1071: *** llvm-config --libs failed. Stop.
make[1]: Leaving directory `/work/make_llvm/examples/BrainF'
make: *** [BrainF/.makeall] Error 2
Run Code Online (Sandbox Code Playgroud)
好像没有JIT支持,或者llvm-config找不到它.但是LLVM编译与按照默认启用JIT支持configure --help,我看至少调用一个JIT相关的库libLLVMMCJIT.a在/work/my_llvm/lib.
如何构建LLVM示例?
从https://doc.rust-lang.org/rust-by-example/std_misc/file/read_lines.html 继续,我想定义一个接受路径可迭代的函数,并返回一个包装所有进入单个流的路径,我的不可编译的尝试,
fn read_lines<P, I: IntoIterator<Item = P>>(files: I) -> Result<io::Lines<io::BufReader<File>>>
where
P: AsRef<Path>,
{
let handles = files.into_iter()
.map(|path|
File::open(path).unwrap());
// I guess it is hard (impossible?) to define the type of this reduction,
// Chain<File, Chain<File, ..., Chain<File, File>>>
// and that is the reason the compiler is complaining.
match handles.reduce(|a, b| a.chain(b)) {
Some(combination) => Ok(BufReader::new(combination).lines()),
None => {
// Not nice, hard fail if the array len is 0
Ok(BufReader::new(handles.next().unwrap()).lines())
},
}
}
Run Code Online (Sandbox Code Playgroud)
这给出了一个预期的错误,我不确定如何解决, …