question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for cdef of C++ object references

See original GitHub issue

When a C++ function returns a reference we are forced to workaround: typically make the call inside a function accepting references

It would be desirable to support cdef Foo & obj = func_bar()

Cython apparently declares the reference and assigns to it in different steps, which obviously doesn’t compile.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
robertwbcommented, Jul 3, 2017

The cdef Foo* obj = &func_bar() trick only works when func_bar returns a reference. It is correct that an assignment invokes the assignment operator.

0reactions
ferdonlinecommented, Jul 3, 2017

Instead, write cdef Foo* obj = &func_bar() which is just as powerful.

I was wondering if cython was specially handling that case, but no, it doesn’t work. ...xxx:165:34: Taking address of non-lvalue (type Positions)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Borrowed reference to cdef class? - Google Groups
Basically, how do I do that? I cannot find it in the documentation. Say I have a cdef class like this: cdef class...
Read more >
Language Basics — Cython 3.0.0a11 documentation
C functions are defined using the cdef statement in Cython syntax or with the @cfunc decorator. They take either Python objects or C...
Read more >
References in C++ - GeeksforGeeks
C ++ · 1) Once a reference is created, it cannot be later made to reference another object; it cannot be reset. This...
Read more >
How to interface a c++ function that returns a reference to an ...
we would get the following generated C-code for the line cdef int * first=&(vect.at(0)) (only important parts): static PyObject *__ ...
Read more >
Reference declaration - cppreference.com
Concurrency support library (C++11) ... namespace alias definition ... as a reference, that is, an alias to an already-existing object or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found