p**o 发帖数: 3409 | 1 手写了一些C扩展,有些返回多重指针的函数不知道怎么用SWIG来包来供Python调用……
比如下面这个strsplit()函数,返回的是char**,怎么改才能让Python收到一个list (
of strings)?
http://www.swig.org/tutorial.html
我只是照tutorial简单地把函数声明抄进.i文件,Python中调用时返回的是
#include
#include
#include
/* Split an input string 'instr', using a set of given delimiters, to an
array of strings of at most 'maxparts' parts. */
char **strsplit (const char *instr, const char *delimiters, size_t maxparts)
{
char *... 阅读全帖 |
|
b******n 发帖数: 592 | 2 请问有没有使用过perl2exe或者perlApp编译过含有SWIG制作的module的script. 编
译后的exe总是告诉我没有办法找到AUTOLOAD需要的dll,即使编译成功。 |
|
H*T 发帖数: 43 | 3 从C/C++里返回string到Perl?
swig的文档太复杂,一时看不过来。
求有经验的高手指点。 |
|
l*****c 发帖数: 316 | 4 我有src1 和 src2 两个folder的C code.
src1 里面make 之后产生一个 src1.lo file copy 到 src2 里面
src2 再和 src1.lo 一起编译
我现在需要用swig做一个python library, 这个python code 可以直接调用 src2
main.c 里面的一些function。
不太清楚这种情况下应该怎么样编译。我只搞明白了针对一个 C src folder情况下的
做法,我面对的情况不太清楚应该怎么编译。
希望各位大仙给予指点啊!
多谢! |
|
b***i 发帖数: 3043 | 5 问题在于swig负责衔接,如果返回指针,那么swig默认C++传出的指针不应由swig来销
毁,就像vector删掉元素并不销毁内存一样,所以Python的变量如果出范围是
不会调用swig来销毁这个空间的。
返回对象则默认Python应该负责销毁,所以swig会帮助进行销毁。指针也可以达到类似
的效果,要使用%newobject cppapi::ReturnObj();
那么swig就认为C++把所有权交给了python,
a=cppapi.return_obj()就获得了所有权(swig设的域thisown)
当变量a出范围后,Python就可以告诉swig,swig再调用析构函数。 |
|
l****z 发帖数: 29846 | 6 Max Hastings反思英国骚乱:多年的左派教条催生了不讲道德、不学无术、依赖福利、
凶狠野蛮的一代年轻人
Years of liberal dogma have spawned a generation of amoral, uneducated,
welfare dependent, brutalised youngsters
By Max Hastings
Last updated at 12:49 PM on 10th August 2011
A few weeks after the U.S. city of Detroit was ravaged by 1967 race riots in
which 43 people died, I was shown around the wrecked areas by a black
reporter named Joe Strickland.
He said: ‘Don’t you believe all that stuff people here are giving media
folk about how sorr... 阅读全帖 |
|
b******n 发帖数: 592 | 7 If you haven't used other tools to interface with C++, then there is no
point to argue.
I know many people use SWIG and there are many projects. The wrapper code is
ugly and there are pitfalls you may have to tweak it. ctype doesn't have
good
C++ support, and it needs a lot coding. Boost.Python is the one I haven't
used. It is said to be good but will need more coding.
You don't have to use a language for everything. I know Python is good, I
use it everyday. But I do use Perl, Bash, C/C++ as wel... 阅读全帖 |
|
d****i 发帖数: 4809 | 8 If you don't want to have any overhead of IPC, then JNI is the best bet, or
if you don't want to write JNI wrapper function, then JNA (Java-Native-
Access) is an alternative way. Of course, there is SWIG to connect C/C++
with any other high level languages including Java:
http://www.swig.org/index.php
You may use that too. Also there are some ongoing effort by RedHat people to
make the C++<->Java bridge easier, called "Project Panama", but I haven't
tried that. |
|
s*****r 发帖数: 43070 | 9 【 以下文字转载自 SanFrancisco 讨论区 】
发信人: skiiwalker (Skiing), 信区: SanFrancisco
标 题: 斯坦福出了国人投毒事件
发信站: BBS 未名空间站 (Thu Apr 2 05:13:15 2015, 美东)
http://www.straitstimes.com/news/singapore/courts-crime/story/r
投毒者:Ouyang Xiangyu 新加坡籍,大陆出生 受害人: Xing Liujing,Zhao Ludan
“
In September, when graduate student Xing Liujing drank from her water bottle
, she felt an immediate burning sensation in her throat and mouth. She also
noticed that the water in her bottle smelt like PFA, a chemical the lab
researchers wer... 阅读全帖 |
|
q********i 发帖数: 152 | 10 扯淡吧,狗家基本是python + C++一统天下。
你再看新的Deep Learning,Theano, Tensorflow都是python + SWIG + C++,Torch是
Lua. |
|
l****z 发帖数: 29846 | 11 http://www.wsj.com/articles/the-athletes-who-train-with-soda-14
The Athletes Who Train With Soda
Aaron Rodgers, Tour de France Cyclists and Olympic Medalists Cling to Coke
or Crush
Green Bay Packers quarterback Aaron Rodgers sparked discussion by drinking
grape-flavored Crush after a recent victory. ENLARGE
Green Bay Packers quarterback Aaron Rodgers sparked discussion by drinking
grape-flavored Crush after a recent victory. WLUK-TV Green Bay
.
By
Rachel Bachman
Updated Dec. 9, 2014 2:27 p... 阅读全帖 |
|
e**********0 发帖数: 7133 | 12 研究了有一些产品,发现多数的history low发生在某几个special moment.
为什么会这样。就是因为amazon的价格swig是program 好的。因为好几个大卖家,
beachcamera, adorama, Expo 哥几个在amazon的压迫下,为了出货,轮番跳水。
amazon要beat他们,全靠价格了。等信号一到,history low就来了。其它几家的
history low只能挺几分钟就不行了。 而amazon确可以挺十几分钟,半个小时。
不过就几分钟的triger 就全够了。大家都挂上武器,等信号,all in吧。 |
|
m*****n 发帖数: 5245 | 13 ☆─────────────────────────────────────☆
wisher1 (wisher) 于 (Sat Jun 13 20:05:08 2009, 美东) 提到:
在考虑是不是需要自学一下C++. 我在这边上的CS, 美国学校好像大多都是教java的.
可是不会C++就少了一些机会, 象Bloomberg就只用C++.
请大家指点一下. 是不是有必要自学一下.
多谢!
☆─────────────────────────────────────☆
hedaoke (荷刀客) 于 (Sat Jun 13 20:17:00 2009, 美东) 提到:
觉得 c++ 加上 python 是比较好的组合, 用python写大部分模块,C++写performance
critical模块,Swig实现调用。
C++: Performance critical applications/modules
Python: Web application, Scripting, Desktop applications
运行效率:C++ > Java > Py |
|
a***m 发帖数: 5037 | 14 You will need to be someone who consistently keeps up-to-date with the
latest C++ techniques and who is passionate about the technology that they
use.
The Senior C++ Software Engineer (Exchange Connectivity, TCP/IP, Low Latency
, UNIX) will need:
Strong development experience of C++, ideally C++11
Good experience with TCP/IP
Experience working on Real-Time/Low Latency Systems
Good experience of Linux/UNIX
Experience working with Exchange Connectivity
Senior C++ Software Engineer – C++, Low Laten... 阅读全帖 |
|
a***m 发帖数: 5037 | 15 You will need to be someone who consistently keeps up-to-date with the
latest C++ techniques and who is passionate about the technology that they
use.
The Senior C++ Software Engineer (Exchange Connectivity, TCP/IP, Low Latency
, UNIX) will need:
Strong development experience of C++, ideally C++11
Good experience with TCP/IP
Experience working on Real-Time/Low Latency Systems
Good experience of Linux/UNIX
Experience working with Exchange Connectivity
Senior C++ Software Engineer – C++, Low Laten... 阅读全帖 |
|
n********e 发帖数: 41 | 16 楼主 看到 你 isDiffByOne 函数就知道你必然要超时
Leetcode免费给你用 就别挑剔了。凡事要先从自身找问题
你那个测试不是大数据
真正的大数据在这里:
start = "nanny";
end = "aloud";
String[] d = {"ricky","grind","cubic","panic","lover","farce","gofer
","sales","flint","omens","lipid","briny","cloth","anted","slime","oaten","
harsh","touts","stoop","cabal","lazed","elton","skunk","nicer","pesky","
kusch","bused","kinda","tunis","enjoy","aches","prowl","babar","rooms","
burst","slush","pines","urine","pinky","bayed","mania","light","flare","
wares","wom... 阅读全帖 |
|
|
l*********e 发帖数: 5385 | 18 笑话来啦~~~~
And Then The Fight Started
My wife sat down on the couch next to me as I was flipping channels.
She asked, "What's on TV?"
I said, "Dust."
And then the fight started.
======================================================================
My wife was hinting about what she wanted for our upcoming anniversary.
She said, "I want something shiny that goes from 0 to 150 in about 3 seconds
."
I bought her a scale.
And then the fight started.
===================================================... 阅读全帖 |
|
b**********5 发帖数: 7881 | 19 Hooker sipped wine & watched Google exec die on yacht: cops
Forrest Hayes (left) died after high-end prostitute Alix Tichelman (right)
allegedly injected him with heroin and then left the scene.
SANTA CRUZ — A high-end prostitute injected lethal doses of heroin into a
former Google executive before callously stepping over his body, downing a
final swig of wine and then leaving him to die about his yacht, officials
said.
The Santa Cruz Sentinel reported Tuesday that surveillance video from the
bo... 阅读全帖 |
|
|
|
|
s********r 发帖数: 154 | 23 http://www.straitstimes.com/news/singapore/courts-crime/story/r
投毒者:Ouyang Xiangyu 新加坡籍,大陆出生 受害人: Xing Liujing,Zhao Ludan
“
In September, when graduate student Xing Liujing drank from her water bottle
, she felt an immediate burning sensation in her throat and mouth. She also
noticed that the water in her bottle smelt like PFA, a chemical the lab
researchers were familiar with.
From then on, Ms Xing began smelling the water in her bottle each time
before drinking. She would later tell police tha... 阅读全帖 |
|
g*2 发帖数: 658 | 24 Crank your calorie-blasting way up with these quick tricks.
1. Linger in the dairy aisle - Women burned more fat and calories when they
ate 1,000 to 1,400 milligrams of calcium per day, according to findings
published in the American Journal of Clinical Nutrition. That’s three to
four servings of dairy.
2. Eat more meat...and eggs and beans - People who got 40% of their daily
calories from protein lost significantly more body fat than those whose
diets had only 15% protein, even though they cons... 阅读全帖 |
|
w**m 发帖数: 4061 | 25 越来越懒了,连整篇的读后感都不想写了。挖这么个坑,随手灌些感想,书摘之类的。
估计会比较随意,零散,甚至放肆,充满剧透和个人观点,提前通知。“肉屑”可能也
不少,顾不了许多。
在读 We Need to Talk about Kevin,近四分之三,美国作家 Lionel Shriver 2003年
的作品,获2005 Orange Prize。Orange Prize for Fiction授予在英国出版且用英语
写成的女作家的作品。
前一阵子读的几本小说,有些共同点,男作家,年纪相对较大(50-70),叙事成熟平
稳,没有强烈的情绪色彩,即使在描述激烈甚至黑暗的情节或是心理活动的时候。这本
Kevin则不同,女作家,写作时40多岁,个人情绪很浓,关注的也是母子间紧张关系,
口气冷峻讽刺,颇为压抑,且不乏粗言粗语。
小说第一人称,Eva给丈夫Franklin写信的形式,每封长信为一节,一上来就点破儿子
Kevin在16岁那年枪杀多名同学老师,属于之前总结的,明梗,上来就挑明,以此牵
引读者的情绪和注意力。已拍成电影,现于各大电影节点映,明年初上映,因为怕剧透
,预告片还没看。
读之前... 阅读全帖 |
|
w**m 发帖数: 4061 | 26 越来越懒了,连整篇的读后感都不想写了。挖这么个坑,随手灌些感想,书摘之类的。
估计会比较随意,零散,甚至放肆,充满剧透和个人观点,提前通知。“肉屑”可能也
不少,顾不了许多。
在读 We Need to Talk about Kevin,近四分之三,美国作家 Lionel Shriver 2003年
的作品,获2005 Orange Prize。Orange Prize for Fiction授予在英国出版且用英语
写成的女作家的作品。
前一阵子读的几本小说,有些共同点,男作家,年纪相对较大(50-70),叙事成熟平
稳,没有强烈的情绪色彩,即使在描述激烈甚至黑暗的情节或是心理活动的时候。这本
Kevin则不同,女作家,写作时40多岁,个人情绪很浓,关注的也是母子间紧张关系,
口气冷峻讽刺,颇为压抑,且不乏粗言粗语。
小说第一人称,Eva给丈夫Franklin写信的形式,每封长信为一节,一上来就点破儿子
Kevin在16岁那年枪杀多名同学老师,属于之前总结的,明梗,上来就挑明,以此牵
引读者的情绪和注意力。已拍成电影,现于各大电影节点映,明年初上映,因为怕剧透
,预告片还没看。
读之前... 阅读全帖 |
|
x*****a 发帖数: 7797 | 27 My wife and I were sitting at a table at my high school reunion, and I kept
staring at a drunken lady swigging her drink as she sat alone at a nearby
table.
My wife asked, 'Do you know her?'
'Yes,' I sighed, 'She's my old girlfriend. I understand she took to
drinking right after we split up those many years ago, and I hear she hasn
't been sober since.'
'My God!' says my wife, 'who would think a person could go on celebrating
that long?'
And then the fight started... |
|
l****e 发帖数: 79 | 28 Three men are talking about their wives. Two of the men are talking about
the control they have over their wives, while the third remains silent.
After a while, the first two men turn to the third and ask, “What about you
? What kind of control do you have over your wife?”
The third man turns to the first two and says, “Well, I’ll tell you, just
the other day I had her on her knees.”
The first two men are dumbfounded. “Wow! What happened next?” they ask.
The third man takes a healthy swig of ... 阅读全帖 |
|
E*****m 发帖数: 25615 | 29 "Christianity is obviously the best way to counter homosexuality...you know,
getting down on your knees, taking a swig of wine, and accepting a man's
body into your mouth!" -Steven Colbert |
|
|
|
p*****s 发帖数: 344 | 32 keywords, SWIG, FFI, ctypes |
|
F*******i 发帖数: 190 | 33 Well said.
Any suggestions/docsto write c modules for python?
Also, any suggestions to connect c++ <-> python? (boost/swig/cython?)
thanks! |
|
|
k*******d 发帖数: 1340 | 35 python是很适合用来集成C++的代码的,很多人这么做,用SWIG |
|
w**********1 发帖数: 130 | 36 Combination of C++, python and SWIG,
Good? Best? |
|
j***i 发帖数: 1278 | 37 之前看有人说用swig ,感觉documuent作的不好,高了半天,没高出来
不知到大家还有什么常用的方法 |
|
r****t 发帖数: 10904 | 38 ctypes? 听说 swig 挺容易的?
直接写成 python c-module 也不难,我有个同学不咋写程序的都自己搞好了。 |
|
b******n 发帖数: 592 | 39 come on, seriously? SWIG? Boost.Python? ctype?
I did Python interface for our engine, and used C#. I wouldn't say Python
works great. |
|
r*******n 发帖数: 3020 | 40 I don't use C# and have no idea how easily C# work with C++ compared to
Python.
You think any of SWIG, Boost.Python and ctype are not good?
Could you point something out? |
|
b******n 发帖数: 592 | 41 Python may take over the world. It is trendy, I agree. My company current
use
Python to prototype the product in research environment, and then we have
software engineer to develop the actual product in C++.
The advantage of Python is its ease of use. So the researchers don't have to
spend too much time on software development. Maybe it is just the perception
of software industry that none of the company is giving up Java, C, C++, C#
for Python. Tomorrow it maybe the only language every one use.... 阅读全帖 |
|
h***i 发帖数: 1970 | 42 你要是返回c++ style的string(就是返回个object,可以用所有std::string的函数),
直接include string.i就行,要是返回perl 的string,自己写typemap. |
|
|
p**o 发帖数: 3409 | 44 我是举个简单易懂的例子,这个strsplit()其实是供其他C函数调用的,
还有好些类似的函数是py没有的。 |
|
|
y****e 发帖数: 23939 | 46 做C++/Pyhton Binding的话,SWIG不如boost.python好用 |
|
|
y****e 发帖数: 23939 | 48 做C++/Pyhton Binding的话,SWIG不如boost.python好用 |
|
W*****k 发帖数: 158 | 49 循环多的地方用c写的
然后想用python调用自己定义的c函数
网上搜了半天,发现有各种各样的api
CPython,C type,swig,Cython....
但是怎么都找不到一个比较简单明了的tutorial
哪位大侠帮一下菜鸟? |
|