[Cython] C data type and a C function() sharing the same name

2013-06-01 Thread Marin Atanasov Nikolov
Hello,

Working on creating Cython wrappers for a C library I came across a strange
problem.

I have in the C library a struct like this:

 struct my_jobs;

I also have this function, which returns the next job in the queue:

 int my_jobs(struct my_jobs *jobs);

Translating this into Cython and putting this in the .pxd file it looks
like this:

  cdef struct my_jobs
  int my_jobs(my_jobs *jobs)

During build I'm having issues because it seems that the function my_jobs()
is translated in a way that it should return a "int struct my_jobs".

The real problem I see is that I cannot have a data type and a function
sharing the same name.

How can I overcome this issue? Suppose that I wrote the C API I could
change that, but how would you really  solve this if you cannot touch
what's in upstream?

Any ways to solve this?

Thanks and regards,
Marin

-- 
Marin Atanasov Nikolov

dnaeon AT gmail DOT com
http://www.unix-heaven.org/
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] C data type and a C function() sharing the same name

2013-06-01 Thread Nikita Nemkin
On Sat, 01 Jun 2013 19:29:17 +0600, Marin Atanasov Nikolov  
 wrote:



Hello,

Working on creating Cython wrappers for a C library I came across a  
strange

problem.

I have in the C library a struct like this:

 struct my_jobs;

I also have this function, which returns the next job in the queue:

 int my_jobs(struct my_jobs *jobs);

Translating this into Cython and putting this in the .pxd file it looks
like this:

  cdef struct my_jobs
  int my_jobs(my_jobs *jobs)

During build I'm having issues because it seems that the function  
my_jobs()

is translated in a way that it should return a "int struct my_jobs".

The real problem I see is that I cannot have a data type and a function
sharing the same name.

How can I overcome this issue? Suppose that I wrote the C API I could
change that, but how would you really  solve this if you cannot touch
what's in upstream?

Any ways to solve this?


This question would be more appropriate on the cython-users mailing list.

Use renaming:
http://docs.cython.org/src/userguide/external_C_code.html#resolving-naming-conflicts-c-name-specifications

For example, rename the function:

int my_jobs_func "my_jobs" (my_jobs *jobs)

or the struct:

cdef struct my_jobs_t "my_jobs"

or both.

Best regards,
Nikita Nemkin
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] C data type and a C function() sharing the same name

2013-06-01 Thread Marin Atanasov Nikolov
Thanks, Nikita!

I've been looking at the Cython documentation, but was not able to find it
previously, thanks!

I'm still waiting for my previous posts to show up in the
cython-users@mailing list (although I am subscribed there), but they
don't seem to show
up.

Thanks for your help!

Best regards,
Marin

//offtopic
Why does it take so long for a post to be approved/published on
cython-users@ ?



On Sat, Jun 1, 2013 at 5:12 PM, Nikita Nemkin  wrote:

> On Sat, 01 Jun 2013 19:29:17 +0600, Marin Atanasov Nikolov <
> dna...@gmail.com> wrote:
>
>  Hello,
>>
>> Working on creating Cython wrappers for a C library I came across a
>> strange
>> problem.
>>
>> I have in the C library a struct like this:
>>
>>  struct my_jobs;
>>
>> I also have this function, which returns the next job in the queue:
>>
>>  int my_jobs(struct my_jobs *jobs);
>>
>> Translating this into Cython and putting this in the .pxd file it looks
>> like this:
>>
>>   cdef struct my_jobs
>>   int my_jobs(my_jobs *jobs)
>>
>> During build I'm having issues because it seems that the function
>> my_jobs()
>> is translated in a way that it should return a "int struct my_jobs".
>>
>> The real problem I see is that I cannot have a data type and a function
>> sharing the same name.
>>
>> How can I overcome this issue? Suppose that I wrote the C API I could
>> change that, but how would you really  solve this if you cannot touch
>> what's in upstream?
>>
>> Any ways to solve this?
>>
>
> This question would be more appropriate on the cython-users mailing list.
>
> Use renaming:
> http://docs.cython.org/src/**userguide/external_C_code.**
> html#resolving-naming-**conflicts-c-name-**specifications
>
> For example, rename the function:
>
> int my_jobs_func "my_jobs" (my_jobs *jobs)
>
> or the struct:
>
> cdef struct my_jobs_t "my_jobs"
>
> or both.
>
> Best regards,
> Nikita Nemkin
> __**_
> cython-devel mailing list
> cython-devel@python.org
> http://mail.python.org/**mailman/listinfo/cython-devel
>



-- 
Marin Atanasov Nikolov

dnaeon AT gmail DOT com
http://www.unix-heaven.org/
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] C data type and a C function() sharing the same name

2013-06-01 Thread Robert Bradshaw
On Sat, Jun 1, 2013 at 7:35 AM, Marin Atanasov Nikolov  wrote:
> Thanks, Nikita!
>
> I've been looking at the Cython documentation, but was not able to find it
> previously, thanks!
>
> I'm still waiting for my previous posts to show up in the cython-users@
> mailing list (although I am subscribed there), but they don't seem to show
> up.
>
> Thanks for your help!
>
> Best regards,
> Marin
>
> //offtopic
> Why does it take so long for a post to be approved/published on
> cython-users@ ?

Because it's manually moderated for first-time posters, which is the
most effective way of preventing spam (and, personally, I was on
vacation this week).

> On Sat, Jun 1, 2013 at 5:12 PM, Nikita Nemkin  wrote:
>>
>> On Sat, 01 Jun 2013 19:29:17 +0600, Marin Atanasov Nikolov
>>  wrote:
>>
>>> Hello,
>>>
>>> Working on creating Cython wrappers for a C library I came across a
>>> strange
>>> problem.
>>>
>>> I have in the C library a struct like this:
>>>
>>>  struct my_jobs;
>>>
>>> I also have this function, which returns the next job in the queue:
>>>
>>>  int my_jobs(struct my_jobs *jobs);
>>>
>>> Translating this into Cython and putting this in the .pxd file it looks
>>> like this:
>>>
>>>   cdef struct my_jobs
>>>   int my_jobs(my_jobs *jobs)
>>>
>>> During build I'm having issues because it seems that the function
>>> my_jobs()
>>> is translated in a way that it should return a "int struct my_jobs".
>>>
>>> The real problem I see is that I cannot have a data type and a function
>>> sharing the same name.
>>>
>>> How can I overcome this issue? Suppose that I wrote the C API I could
>>> change that, but how would you really  solve this if you cannot touch
>>> what's in upstream?
>>>
>>> Any ways to solve this?
>>
>>
>> This question would be more appropriate on the cython-users mailing list.
>>
>> Use renaming:
>>
>> http://docs.cython.org/src/userguide/external_C_code.html#resolving-naming-conflicts-c-name-specifications
>>
>> For example, rename the function:
>>
>> int my_jobs_func "my_jobs" (my_jobs *jobs)
>>
>> or the struct:
>>
>> cdef struct my_jobs_t "my_jobs"
>>
>> or both.
>>
>> Best regards,
>> Nikita Nemkin
>> ___
>> cython-devel mailing list
>> cython-devel@python.org
>> http://mail.python.org/mailman/listinfo/cython-devel
>
>
>
>
> --
> Marin Atanasov Nikolov
>
> dnaeon AT gmail DOT com
> http://www.unix-heaven.org/
>
> ___
> cython-devel mailing list
> cython-devel@python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] CF based type inference

2013-06-01 Thread Stefan Behnel
mark florisson, 21.05.2013 15:32:
> On 21 May 2013 14:14, Vitja Makarov wrote:
>>
>> def foo(int N):
>> x = 1
>> y = 0
>> for i in range(N):
>> x = x * 0.1 + y * 0.2
>> y = x * 0.3 + y * 0.4
>> print typeof(x), typeof(y)
>>
>> Here both x and y will be inferred as double
> 
> Ok, so I assume it promotes the incoming types (all reaching
> definitions)? If N == 0, then when using objects you get an int,
> otherwise a double.

I'm not sure what you mean here. I certainly don't think the inferred type
of x and y should depend on the value of N. It should always be a double,
because that's the spanning type for all paths. In the very unlikely case
that that's not what the user wants, explicit typing will easily fix it for
them.

Stefan

___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel