English 中文(简体)
从y到 c和从 c到 p
原标题:marshalling from py to c and from c to py

In cython the marshalling of the types like int or char is done automatically, but if I use a

       cdef struct MyClass_Tag:
            pass
      ctypedef MyClass_Tag* MyClass_ptr
      ....
      cdef class MyClass:
           cdef MyClass_ptr obj
           ....

Now for wrapping any function like for example in c is some function foo that takes

      foo(char* , MyClass_ptr self)
           #return stuff

总结这一职能:

       def py_foo(char* n, self):
            return foo(n,self.obj)

So from py to c:

       char is done automatically
       but self is of type MyClass so to call the foo i have to write self.obj , 
       so i pass the same obj

这里发生的情况是,从y到 c。

The problem is that I don t understand where happen the marshalling from c to py, I mean at which point does it happen?

Even in this case or even if you give me some other example it will be ok. Thank you!

问题回答

我没有完全理解你的问题,但你可能要利用指挥:

cython -a <yourfile.pyx>

然后,用你的网络浏览器开张。 你们看一看cy如何将你的法典翻译成C,然后找到你的答复:

作为参数名称<代码>本身 建议Cfoo()功能作为在沙捞中的一种方法具有更大的意义:

cdef extern void c_foo "foo" (char* n, MyClass_ptr)

cdef class MyClass:
   cdef MyClass_ptr this

   def foo(self, unicode n not None):
       b = n.encode( ascii )
       cdef char* p = b
       c_foo(p, self.this)

另见。 C Library

Cython将你的代码翻译成C(或C++)。 此时此刻,你可以忘记这一点。 根特的C法典是一种普通的C推广法,适用于沙尔。 该守则载有普通的“快速通道”:PyBytes_AsString(>。 (convertshed bytes to char* or PyInt_FromLong ( (convert C int to Zhu integer).

<编码> MyClass_ptr a. 使用:

struct __pyx_obj_3foo_MyClass {
  PyObject_HEAD
  MyClass_ptr this; /* <-- using MyClass_ptr as is */
};

i. 即,纯粹的沙尔法从来就看不见它,因此没有从/转成灰色物体。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签