我正试图用一些 c和一些on子书写一个单元。 我正在利用cy来弥合这一差距。
我想把我(非常长)的常数储存在平线上,因为许多nic子:
const char long_string = "
part of string
"
"next part
"
"last part
";
相对于:
long_string = """
part of string
next part
last part
"""
(the strings are much longer than this, and more complicated - to the extent that I don t want to have to add and remove the "
s and
"
s every time I want to edit it with syntax highlighting. In fact, they are openCL kernels.)
我需要能够把这些内容变成使用方言的方言,根据。 我只需要这样做:
cdef bytes py_bytes = py_string.encode()
cdef char* c_string = py_bytes
只要我提到<代码>py_bytes,则不进行人工记忆管理。
However, I can t get this working with a simple printf test. Here is my cython file:
cdef extern from "stdio.h":
printf(char* string)
def go():
py_string = """
a complicated string
with a few
newlines.
"""
cdef bytes py_bytes = py_string.encode()
cdef char* c_string = py_bytes
printf(c_string)
print "we don t get this far :("
在操作时使用<代码>pyximport汇编 定点前向终点站提供以下产出:
a complicated string
with a few
newlines.
Segmentation fault: 11
现在,我检查了在案卷中实际运用的cy子,并在一个面包车C档案中对其进行审判。
#include "stdio.h"
static char __pyx_k_1[] = "
a complicated string
with a few
newlines.
";
int main(void) {
void* output = printf(__pyx_k_1);
if (!output) {
printf("apparently, !output.");
}
}
为明确起见,cy星生成的编码可捕获<条码>(
我在座的唯一猜测是,扼杀行为被不当终止,因此,照样只是过去结束,造成ault,但由于这确实发生在我的纯粹考验中,我完全 st。
因此,我的实际问题是,我是如何? 是否从cy到 code? 答复指出,解决Im试图在顶端解决的实际问题更为容易,也令人非常欢迎: