使用HTTP::Request
from 指定包含下划线的自定义标题时LWP::UserAgent
,下划线将更改为连字符:
use LWP::UserAgent;
my $rq = HTTP::Request->new("GET", "http://cpan.org");
$rq->header("X-FOO_BAR", "xyzzy");
print $rq->as_string;
Run Code Online (Sandbox Code Playgroud)
输出:
GET http://cpan.org
X-FOO-BAR: xyzzy
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题?
编辑
经过一些更多的摆弄,我到目前为止已经隔离了以下状态:
print()
print()
print()
(显然一样与1D阵列)像这样:
>>> a = numpy.array([1,2,3], dtype="int32")
>>> a.data
<memory at 0x7f02e85e4048>
>>> a.data
<memory at 0x7f02e85e4110>
>>> a.data
<memory at 0x7f02e85e4048>
>>> a.data
<memory at 0x7f02e85e4110>
>>> a.data
<memory at 0x7f02e85e4048>
>>> print(a.data)
<memory at 0x7f02e85e4110>
>>> print(a.data)
<memory at 0x7f02e85e4110>
>>> print(a.data)
<memory at 0x7f02e85e4110>
>>> print(a.data)
<memory at …
Run Code Online (Sandbox Code Playgroud) 根据文档,第三个参数PyCapsule_New()
可以指定一个析构函数,我假设应该在解压缩时调用它.
void mapDestroy(PyObject *capsule) {
lash_map_simple_t *map;
fprintf(stderr, "Entered destructor\n");
map = (lash_map_simple_t*)PyCapsule_GetPointer(capsule, "MAP_C_API");
if (map == NULL)
return;
fprintf(stderr, "Destroying map %p\n", map);
lashMapSimpleFree(map);
free(map);
}
static PyObject * mapSimpleInit_func(PyObject *self, PyObject *args) {
unsigned int w;
unsigned int h;
PyObject *pymap;
lash_map_simple_t *map = (lash_map_simple_t*)malloc(sizeof(lash_map_simple_t));
pymap = PyCapsule_New((void *)map, "MAP_C_API", mapDestroy);
if (!PyArg_ParseTuple(args, "II", &w, &h))
return NULL;
lashMapSimpleInit(map, &w, &h);
return Py_BuildValue("O", pymap);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我实例化对象并删除它或退出Python控制台时,似乎没有调用析构函数:
>>> a = mapSimpleInit(10,20)
>>> a
<capsule object …
Run Code Online (Sandbox Code Playgroud) 给定未指定初始空间的映射分配,例如:
foo := make(map[string]int)
Run Code Online (Sandbox Code Playgroud)
该文件表明,这里的内存分配是依赖于实现.那么(怎么样)我可以告诉我的实现分配给这张地图的内存量是多少?
为什么......
char *dst = (char*) malloc(sizeof(char) * 11);
char *src = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";
strncpy(dst, src, 10);
Run Code Online (Sandbox Code Playgroud)
......工作正常,但......
char *dst = "ABCDEFGHIJ\0";
char *src = "ABCDEFGHIJKLMNOPQRSTUVQXYZ\0";
strncpy(dst, src, 10);
Run Code Online (Sandbox Code Playgroud)
... 甚至 ...
char *dst = "ABCDEFGHIJ\0";
char *src = "KLMNOPQRST\0";
strncpy(dst, src, 10);
Run Code Online (Sandbox Code Playgroud)
给段错?
另外,这是怎么回事:
char *dst = (char*) malloc(sizeof(char) * 10); // also works with 9
char *src = "ABCDEFGHIJKLMNOPQRSTUVQXYZ\0";
strncpy(dst, src, 10);
Run Code Online (Sandbox Code Playgroud)
将11个字节复制到分配有10个字节的指针中原则上应该失败?