我试图找出使用Valgrind对一块内存进行无效写入的位置.它告诉我们存在这样一个问题,也就是说什么功能,但不是在哪一行.虽然功能非常小,但我想在Valgrind中显示行号.我在Valgrind的一些输出上看过这个,但目前它们没有显示,我想知道为什么.
输出如下:
niklas@emerald:~/Arbeitsfläche/spyr/bin/Debug$ valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./spyr
[...]
==4404== Invalid write of size 4
==4404== at 0x8048849: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048BFC: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== Address 0x422a0a0 is 4 bytes after a block of size 4 alloc'd
==4404== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==4404== by 0x8048BC1: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==
==4404== Invalid write of size 4
==4404== at 0x8048865: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048BFC: …Run Code Online (Sandbox Code Playgroud) 似乎编译一个__init__.pyx包含cimport语句的bug是错误的.
这是我的文件夹结构:
DrawAPI\
__init__.pyx
utils.pxd
Run Code Online (Sandbox Code Playgroud)
的__init__.pyx:
cimport utils
Run Code Online (Sandbox Code Playgroud)
编译__init__.pyxwith cython让我utils.pxd无法找到.但是重命名__init__.pyx为任何其他名称,foo.pyx例如
DrawAPI\
foo.pyx
utils.pxd
Run Code Online (Sandbox Code Playgroud)
然后编译foo.pyx工作就好了.
难道我做错了什么 ?
我正在努力在Windows 7 x64上安装Cython.我下载并安装了automated MinGW installer.使用以下内容为distutils文件夹创建了distutils.cfg:
[build]
compiler = mingw32
Run Code Online (Sandbox Code Playgroud)
添加C:\MinGW\bin到环境变量后,我调用了easy_install Cython但是我收到以下错误.翻阅互联网真的没有给我有用的结果,因为所有这些编译的东西(或者我应该说sh*t?)对我来说是如此新鲜.
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5d59): undefined reference to `_imp__PyObject_GetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5dc5): undefined reference to `_imp__PyObject_GetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5e31): undefined reference to `_imp__PyObject_GetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5ebc): undefined reference to `_imp__PyObject_Call'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5f08): undefined reference to `_imp__PyDict_New'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5f49): undefined reference to `_imp__PyObject_SetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5ffe): undefined reference to `_imp__PyErr_Occurred'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x6013): undefined reference to `_imp__PyExc_ImportError'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x601e): undefined reference to `_imp__PyErr_SetString'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x602d): undefined reference to `_imp__PyInt_FromLong'
collect2: ld returned 1 exit status
dllwrap: gcc exited with status …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个小脚本,应该用html为客户端提供支持.
import socket
sock = socket.socket()
sock.bind(('', 8080))
sock.listen(5)
client, adress = sock.accept()
print "Incoming:", adress
print client.recv(1024)
print
client.send("Content-Type: text/html\n\n")
client.send('<html><body></body></html>')
print "Answering ..."
print "Finished."
import os
os.system("pause")
Run Code Online (Sandbox Code Playgroud)
但它在浏览器中显示为纯文本.你能说出我需要做什么吗?我只是在谷歌找不到帮助我的东西..
谢谢.
我正在尝试用Cython包装一些C++代码.我有一个使用模板方法的类,但不是模板本身.
class SomeClass {
template <class T> SomeClass(T& spam);
};
Run Code Online (Sandbox Code Playgroud)
由于类不是模板而只是构造函数,因此我不能像在此一样将类声明为Cython中的模板.
# wrong!
cdef extern from "SomeClass.h":
cppclass SomeClass [T]:
SomeClass(T& spam)
Run Code Online (Sandbox Code Playgroud)
我正在包装一个大量使用枚举的库,因此包含许多常量标识符.有没有办法让它们可用于Cython(声明它们extern)并同时使它们可供Python使用?
我搜索这样的东西
cdef extern from *:
public enum:
spam
foo
ham
Run Code Online (Sandbox Code Playgroud)
哪个应该取代
cdef extern from *:
enum:
cspam "spam"
cfoo "foo"
cham "ham"
spam = cspam
foo = cfoo
ham = cham
Run Code Online (Sandbox Code Playgroud)
注意:我知道将extern-declarations移动到.pxd文件以避免命名冲突的选项.
谢谢,尼克拉斯
在PHP中,似乎每个对象都可以通过调用转换为整数intval($object),但这不是我想要的.我想要的是,检查对象是否有效转换为人类认为的整数.
即,有效的对象将是
1212.0"12""12.0"而且无效
MyFooInstance()"some string""12.0.0""0 12.0"在python中,我可以简单地进行以下操作:
try:
int(var)
except (TypeError, ValueError):
return False
return True
Run Code Online (Sandbox Code Playgroud)
我怎样才能在PHP中实现这一点?
我一直在寻找一段时间,但我能找到的不是我寻找的东西.我需要将一个可能非常大的整数值转换为字符串.听起来很简单:"$var"?不,因为这可以导致E+数字的表示.
<?php
$var = 10000000000000000000000000;
echo $var."\n";
echo "'$var'\n";
echo (string) $var."\n";
echo strval($var);
?>
Run Code Online (Sandbox Code Playgroud)
1.0E+25
'1.0E+25'
1.0E+25
1.0E+25
Run Code Online (Sandbox Code Playgroud)
我怎样才能改变输出10000000000000000000000000?
可能重复:
在构造函数内调用虚函数
main.cpp中
#include <iostream>
class BaseClass {
public:
BaseClass() {
init();
}
virtual ~BaseClass() {
deinit();
}
virtual void init() {
std::cout << "BaseClass::init()\n";
}
virtual void deinit() {
std::cout << "BaseClass::deinit()\n";
}
};
class SubClass : public BaseClass {
public:
virtual void init() {
std::cout << "SubClass::init()\n";
}
virtual void deinit() {
std::cout << "SubClass::deinit()\n";
}
};
int main() {
SubClass* cls = new SubClass;
delete cls;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么init()并deinit()没有正确重写和基类的方法被调用,而不是子类的吗?使其有效的要求是什么?
BaseClass::init()
BaseClass::deinit()
Run Code Online (Sandbox Code Playgroud) 所以,我希望long_description我的安装脚本是我README.md文件中的内容.但是当我这样做时,源代码分发的安装将失败,因为python setup.py sdist不会复制自述文件.
有没有办法让命令distutils.core.setup()包含README.md文件,sdist以便安装不会失败?
我已经尝试了一些解决方法,当README.md文件不可用时,我默认使用一些较短的文本,但实际上我确实希望不仅PyPi获取自述文件的内容,而且还有安装包的用户.