Passing a struct* from one Cython class to anotherAre static class variables possible?How do I pass a variable by reference?Cython: overloaded constructor initialization using raw pointerHow to use a filepointer in a struct in cythonUsing a pointer array within a struct in CythonCython extension class: How do I expose methods in the auto-generated C struct?How to pass struct pointer to __cinit__ of Cython's cdef classInstantiating a C++ struct derived from a class in cythonCalling Cython from c++ with not built-in typesHow to pass Cython extension types as arguments to Cython functions/methods?

Can I ask the recruiters in my resume to put the reason why I am rejected?

What killed these X2 caps?

Could gravitational lensing be used to protect a spaceship from a laser?

What do you call someone who asks many questions?

How to draw the figure with four pentagons?

Why is the 'in' operator throwing an error with a string literal instead of logging false?

Facing a paradox: Earnshaw's theorem in one dimension

Assassin's bullet with mercury

What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?

What's the difference between 'rename' and 'mv'?

What to put in ESTA if staying in US for a few days before going on to Canada

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

Stopping power of mountain vs road bike

How do I write bicross product symbols in latex?

Why are electrically insulating heatsinks so rare? Is it just cost?

Combinations of multiple lists

1960's book about a plague that kills all white people

What is going on with Captain Marvel's blood colour?

How can I make my BBEG immortal short of making them a Lich or Vampire?

What is the word for reserving something for yourself before others do?

Alternative to sending password over mail?

How do conventional missiles fly?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

What is the most common color to indicate the input-field is disabled?



Passing a struct* from one Cython class to another


Are static class variables possible?How do I pass a variable by reference?Cython: overloaded constructor initialization using raw pointerHow to use a filepointer in a struct in cythonUsing a pointer array within a struct in CythonCython extension class: How do I expose methods in the auto-generated C struct?How to pass struct pointer to __cinit__ of Cython's cdef classInstantiating a C++ struct derived from a class in cythonCalling Cython from c++ with not built-in typesHow to pass Cython extension types as arguments to Cython functions/methods?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I am trying to pass a struct pointer from one Cython class to another. Here is some example code:



cdef struct MyStruct:
int a
int b

cdef class MyClass:
cdef MyStruct* s
def __init__(self):
self.s = <MyStruct*> malloc(sizeof(MyStruct))
self.s.a = 1
self.s.b = 2

cdef MyStruct* get_my_struct(self):
return self.s

cdef class PrinterClass:
cdef object m
def __init__(self):
self.m = MyClass()

cpdef print_struct(self):
cdef MyStruct* my_struct
my_struct = self.m.get_my_struct()
print(my_struct.a)


When I try to compile this class, I get these 2 errors around the my_struct = self.m.get_my_struct() line:




Cannot convert Python object to 'MyStruct *




and




Storing unsafe C derivative of temporary Python reference




Why is Cython attempting to do conversions here? Can't it just pass the pointer as is?










share|improve this question






























    2















    I am trying to pass a struct pointer from one Cython class to another. Here is some example code:



    cdef struct MyStruct:
    int a
    int b

    cdef class MyClass:
    cdef MyStruct* s
    def __init__(self):
    self.s = <MyStruct*> malloc(sizeof(MyStruct))
    self.s.a = 1
    self.s.b = 2

    cdef MyStruct* get_my_struct(self):
    return self.s

    cdef class PrinterClass:
    cdef object m
    def __init__(self):
    self.m = MyClass()

    cpdef print_struct(self):
    cdef MyStruct* my_struct
    my_struct = self.m.get_my_struct()
    print(my_struct.a)


    When I try to compile this class, I get these 2 errors around the my_struct = self.m.get_my_struct() line:




    Cannot convert Python object to 'MyStruct *




    and




    Storing unsafe C derivative of temporary Python reference




    Why is Cython attempting to do conversions here? Can't it just pass the pointer as is?










    share|improve this question


























      2












      2








      2








      I am trying to pass a struct pointer from one Cython class to another. Here is some example code:



      cdef struct MyStruct:
      int a
      int b

      cdef class MyClass:
      cdef MyStruct* s
      def __init__(self):
      self.s = <MyStruct*> malloc(sizeof(MyStruct))
      self.s.a = 1
      self.s.b = 2

      cdef MyStruct* get_my_struct(self):
      return self.s

      cdef class PrinterClass:
      cdef object m
      def __init__(self):
      self.m = MyClass()

      cpdef print_struct(self):
      cdef MyStruct* my_struct
      my_struct = self.m.get_my_struct()
      print(my_struct.a)


      When I try to compile this class, I get these 2 errors around the my_struct = self.m.get_my_struct() line:




      Cannot convert Python object to 'MyStruct *




      and




      Storing unsafe C derivative of temporary Python reference




      Why is Cython attempting to do conversions here? Can't it just pass the pointer as is?










      share|improve this question
















      I am trying to pass a struct pointer from one Cython class to another. Here is some example code:



      cdef struct MyStruct:
      int a
      int b

      cdef class MyClass:
      cdef MyStruct* s
      def __init__(self):
      self.s = <MyStruct*> malloc(sizeof(MyStruct))
      self.s.a = 1
      self.s.b = 2

      cdef MyStruct* get_my_struct(self):
      return self.s

      cdef class PrinterClass:
      cdef object m
      def __init__(self):
      self.m = MyClass()

      cpdef print_struct(self):
      cdef MyStruct* my_struct
      my_struct = self.m.get_my_struct()
      print(my_struct.a)


      When I try to compile this class, I get these 2 errors around the my_struct = self.m.get_my_struct() line:




      Cannot convert Python object to 'MyStruct *




      and




      Storing unsafe C derivative of temporary Python reference




      Why is Cython attempting to do conversions here? Can't it just pass the pointer as is?







      python cython






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 23:54









      Pikachu the Purple Wizard

      2,03161429




      2,03161429










      asked Mar 7 at 23:41









      slushislushi

      9721019




      9721019






















          1 Answer
          1






          active

          oldest

          votes


















          1














          In PrinterClass, replace cdef object m with cdef MyClass m or explicitly cast self.m to MyClass: my_struct = (<MyClass>self.m).get_my_struct(). (In addition, a __dealloc__ should be added to MyClass).



          I guess the difference lies in that object is a python object(in essence,dict), while cdef class is another kind of class(in essence, struct), see Extension types (aka. cdef classes).



          Expect further revelations from other experts :)






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054573%2fpassing-a-struct-from-one-cython-class-to-another%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            In PrinterClass, replace cdef object m with cdef MyClass m or explicitly cast self.m to MyClass: my_struct = (<MyClass>self.m).get_my_struct(). (In addition, a __dealloc__ should be added to MyClass).



            I guess the difference lies in that object is a python object(in essence,dict), while cdef class is another kind of class(in essence, struct), see Extension types (aka. cdef classes).



            Expect further revelations from other experts :)






            share|improve this answer



























              1














              In PrinterClass, replace cdef object m with cdef MyClass m or explicitly cast self.m to MyClass: my_struct = (<MyClass>self.m).get_my_struct(). (In addition, a __dealloc__ should be added to MyClass).



              I guess the difference lies in that object is a python object(in essence,dict), while cdef class is another kind of class(in essence, struct), see Extension types (aka. cdef classes).



              Expect further revelations from other experts :)






              share|improve this answer

























                1












                1








                1







                In PrinterClass, replace cdef object m with cdef MyClass m or explicitly cast self.m to MyClass: my_struct = (<MyClass>self.m).get_my_struct(). (In addition, a __dealloc__ should be added to MyClass).



                I guess the difference lies in that object is a python object(in essence,dict), while cdef class is another kind of class(in essence, struct), see Extension types (aka. cdef classes).



                Expect further revelations from other experts :)






                share|improve this answer













                In PrinterClass, replace cdef object m with cdef MyClass m or explicitly cast self.m to MyClass: my_struct = (<MyClass>self.m).get_my_struct(). (In addition, a __dealloc__ should be added to MyClass).



                I guess the difference lies in that object is a python object(in essence,dict), while cdef class is another kind of class(in essence, struct), see Extension types (aka. cdef classes).



                Expect further revelations from other experts :)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 1:30









                oz1oz1

                377311




                377311





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054573%2fpassing-a-struct-from-one-cython-class-to-another%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко