我想在 cygwin 中使用 python (2.6.5) ctypes,但我不知道如何加载 dll。
我尝试了各种变体,例如
>>> form ctypes import *
>>> cdll.LoadLibrary("/lib/libcairo.dll.a")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: Permission denied
Run Code Online (Sandbox Code Playgroud) 我是新生的,并且在所有权/借款方面仍然存在一些问题.在这种情况下,我想在枚举中存储一个FnOnce,然后从另一个线程调用它.我尝试了很多不同的变种,但总是卡在某个地方.这是我目前拥有的缩小版本:
#![feature(fnbox)]
use std::sync::{Arc, Mutex};
use std::boxed::{Box, FnBox};
enum Foo<T> {
DoNothing,
CallFunction(Box<FnBox(&T) + Send>)
}
struct FooInMutex<T> {
foo: Arc<Mutex<Foo<T>>>
}
impl<T> FooInMutex<T> {
fn put_fn(&self, f: Box<FnBox(&T)+Send>) {
let mut foo = self.foo.lock().unwrap();
let mut new_foo : Foo<T>;
match *foo {
Foo::DoNothing =>
new_foo = Foo::CallFunction(f),
_ =>
new_foo = Foo::DoNothing
}
*foo = new_foo;
}
fn do_it(&self, t: T) {
let mut foo = self.foo.lock().unwrap();
let mut new_foo : Foo<T>;
match *foo {
Foo::CallFunction(ref mut f) => …Run Code Online (Sandbox Code Playgroud)