Welcome! Log In Create A New Profile

Advanced

Re: Store an ngx_fd_t within the void *

Peter Leonov
May 04, 2010 04:28AM
On 30.04.2010, at 15:23, Igor Sysoev wrote:

> On Fri, Apr 30, 2010 at 01:07:32PM +0200, Grzegorz Nosek wrote:
>
>> On Fri, Apr 30, 2010 at 03:02:04PM +0400, Peter Leonov wrote:
>>> Hi devels,
>>>
>>> Wanna store the value of ngx_fd_t in the void * variable (on the SpiderMonkey “private” field).
>>> Am doing the following trick to avoid the warning “cast to pointer from integer of different size”:
>>>
>>> #if (NGX_PTR_SIZE == 8)
>>> #define FD_TO_PTR(fd) ((void *) (uint64_t) fd)
>>> #elif (NGX_PTR_SIZE == 4)
>>> #define FD_TO_PTR(fd) ((void *) (uint32_t) fd)
>>> #else
>>> #warning can't determine the proper fd to pointer conversion
>>> #define FD_TO_PTR(fd) ((void *) fd)
>>> #endif
>>>
>>> and somewhere in the code:
>>> void *private = FD_TO_PTR(fd);
>>>
>>> Is all this legal?
>>
>> I'd say uintptr_t is a better alternative. It's an unsigned integer type
>> equal in size to void*. However, I'm not sure it's available on all
>> platforms and whether Nginx emulates one if not found.
>>
>> There's also intptr_t, which is the signed counterpart.
>
> uintptr_t is certainly better and nginx tries to emulate it.

Done it like this:
#define FD_TO_PTR(fd) ((void *) (uintptr_t) fd)
#define PTR_TO_FD(p) ((ngx_fd_t) (uintptr_t) p)

Works like a charm on the 64-bit Mac OS Snow Leopard with a 32-bit kernel.
Thank you guys! :)

>
> --
> Igor Sysoev
> http://sysoev.ru/en/

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Store an ngx_fd_t within the void *

Peter Leonov 2490 April 30, 2010 10:52AM

Re: Store an ngx_fd_t within the void *

Grzegorz Nosek 958 April 30, 2010 10:52AM

Re: Store an ngx_fd_t within the void *

Peter Leonov 951 April 30, 2010 10:52AM

Re: Store an ngx_fd_t within the void *

Igor Sysoev 1026 April 30, 2010 10:52AM

Re: Store an ngx_fd_t within the void *

Peter Leonov 1209 May 04, 2010 04:28AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 313
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready