[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sys_socket: sockaddr_storage, new module alignof
From: |
Bruno Haible |
Subject: |
Re: sys_socket: sockaddr_storage, new module alignof |
Date: |
Fri, 8 May 2009 12:59:30 +0200 |
User-agent: |
KMail/1.9.9 |
Simon Josefsson wrote:
> +#define _SS_PADSIZE (_SS_SIZE - (max (sizeof (sa_family_t), \
> + alignof (__ss_aligntype)) \
> + + sizeof (__ss_aligntype)))
Fine, except that 'alignof' is not a predefined macro. We have a definition
of it in "malloca.h" and in some .c files from glibc. OSF/1 has it in a file
<alignof.h>, but it contains nothing better than our alignof macro.
I propose to create a module like this:
2009-05-08 Bruno Haible <address@hidden>
New module 'alignof'.
* lib/alignof.h: New file.
* modules/alignof: New file.
* lib/malloca.h: Include alignof.h.
(sa_alignof): Remove macro.
(sa_alignment_*): Use the alignof macro.
* modules/malloca (Depends-on): Add alignof.
=================================== lib/alignof.h =============================
/* Determine alignment of types.
Copyright (C) 2003-2004, 2006, 2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _ALIGNOF_H
#define _ALIGNOF_H
#include <stddef.h>
/* Determine the alignment of a type at compile time. */
#if defined __GNUC__
# define alignof __alignof__
#elif defined __cplusplus
template <class type> struct alignof_helper { char __slot1; type __slot2; };
# define alignof(type) offsetof (alignof_helper<type>, __slot2)
#elif defined __hpux
/* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
values. */
# define alignof(type) (sizeof (type) <= 4 ? 4 : 8)
#elif defined _AIX
/* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
values. */
# define alignof(type) (sizeof (type) <= 4 ? 4 : 8)
#else
# define alignof(type) offsetof (struct { char __slot1; type __slot2; },
__slot2)
#endif
#endif /* _ALIGNOF_H */
================================== modules/alignof ============================
Description:
Determine alignment of types.
Files:
lib/alignof.h
Depends-on:
configure.ac:
Makefile.am:
Include:
"alignof.h"
License:
LGPLv2+
Maintainer:
Bruno Haible
===============================================================================
*** lib/malloca.h.orig 2009-05-08 12:56:57.000000000 +0200
--- lib/malloca.h 2009-05-08 12:56:31.000000000 +0200
***************
*** 1,5 ****
/* Safe automatic memory allocation.
! Copyright (C) 2003-2007 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 2003.
This program is free software; you can redistribute it and/or modify
--- 1,5 ----
/* Safe automatic memory allocation.
! Copyright (C) 2003-2007, 2009 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 2003.
This program is free software; you can redistribute it and/or modify
***************
*** 23,28 ****
--- 23,30 ----
#include <stddef.h>
#include <stdlib.h>
+ #include "alignof.h"
+
#ifdef __cplusplus
extern "C" {
***************
*** 92,125 ****
/* ------------------- Auxiliary, non-public definitions -------------------
*/
- /* Determine the alignment of a type at compile time. */
- #if defined __GNUC__
- # define sa_alignof __alignof__
- #elif defined __cplusplus
- template <class type> struct sa_alignof_helper { char __slot1; type
__slot2; };
- # define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
- #elif defined __hpux
- /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
- values. */
- # define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
- #elif defined _AIX
- /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
- values. */
- # define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
- #else
- # define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; },
__slot2)
- #endif
-
enum
{
/* The desired alignment of memory allocations is the maximum alignment
among all elementary types. */
! sa_alignment_long = sa_alignof (long),
! sa_alignment_double = sa_alignof (double),
#if HAVE_LONG_LONG_INT
! sa_alignment_longlong = sa_alignof (long long),
#endif
! sa_alignment_longdouble = sa_alignof (long double),
sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
#if HAVE_LONG_LONG_INT
| (sa_alignment_longlong - 1)
--- 94,109 ----
/* ------------------- Auxiliary, non-public definitions -------------------
*/
enum
{
/* The desired alignment of memory allocations is the maximum alignment
among all elementary types. */
! sa_alignment_long = alignof (long),
! sa_alignment_double = alignof (double),
#if HAVE_LONG_LONG_INT
! sa_alignment_longlong = alignof (long long),
#endif
! sa_alignment_longdouble = alignof (long double),
sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
#if HAVE_LONG_LONG_INT
| (sa_alignment_longlong - 1)
*** modules/malloca.orig 2009-05-08 12:56:57.000000000 +0200
--- modules/malloca 2009-05-08 12:56:48.000000000 +0200
***************
*** 10,15 ****
--- 10,16 ----
m4/longlong.m4
Depends-on:
+ alignof
alloca-opt
configure.ac:
- sys_socket: sockaddr_storage, Simon Josefsson, 2009/05/07
- Re: sys_socket: sockaddr_storage, Tom G. Christensen, 2009/05/07
- Re: sys_socket: sockaddr_storage, Bruno Haible, 2009/05/07
- Re: sys_socket: sockaddr_storage, Tom G. Christensen, 2009/05/08
- Re: sys_socket: sockaddr_storage, Simon Josefsson, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof,
Bruno Haible <=
- Re: sys_socket: sockaddr_storage, new module alignof, Simon Josefsson, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof, Bruno Haible, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof, Simon Josefsson, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof, Simon Josefsson, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof, Bruno Haible, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof, Simon Josefsson, 2009/05/10
- Re: sys_socket: sockaddr_storage, new module alignof, Simon Josefsson, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof, Simon Josefsson, 2009/05/08
- Re: sys_socket: sockaddr_storage, new module alignof, Bruno Haible, 2009/05/12
- Re: sys_socket: sockaddr_storage, new module alignof, Eric Blake, 2009/05/12