Patchwork compat: provide a new declaration of hg_ssize_t, in case we don't have it

login
register
mail settings
Submitter Maciej Fijalkowski
Date July 11, 2016, 11:53 a.m.
Message ID <069b332ce21d278384f0.1468238027@brick.arcode.com>
Download mbox | patch
Permalink /patch/15788/
State Changes Requested
Headers show

Comments

Maciej Fijalkowski - July 11, 2016, 11:53 a.m.
# HG changeset patch
# User Maciej Fijalkowski <fijall@gmail.com>
# Date 1468238015 -7200
#      Mon Jul 11 13:53:35 2016 +0200
# Node ID 069b332ce21d278384f0b571349b9aba57b42056
# Parent  b40939504d0e01e3a7f067b8cf49f26718a7c27c
compat: provide a new declaration of hg_ssize_t, in case we don't have it
Yuya Nishihara - July 11, 2016, 1:12 p.m.
On Mon, 11 Jul 2016 13:53:47 +0200, Maciej Fijalkowski wrote:
> # HG changeset patch
> # User Maciej Fijalkowski <fijall@gmail.com>
> # Date 1468238015 -7200
> #      Mon Jul 11 13:53:35 2016 +0200
> # Node ID 069b332ce21d278384f0b571349b9aba57b42056
> # Parent  b40939504d0e01e3a7f067b8cf49f26718a7c27c
> compat: provide a new declaration of hg_ssize_t, in case we don't have it
> 
> diff -r b40939504d0e -r 069b332ce21d mercurial/compat.h
> --- a/mercurial/compat.h	Mon Jul 11 11:05:08 2016 +0200
> +++ b/mercurial/compat.h	Mon Jul 11 13:53:35 2016 +0200
> @@ -35,4 +35,14 @@
>  #define inline __inline
>  #endif
>  
> +#ifdef HAVE_SSIZE_T

HAVE_SSIZE_T seems to be defined in pyconfig.h, which won't be available
for cffi build.

> +typedef ssize_t hg_ssize_t;
> +#elif sizeof(void*) == sizeof(long long)

sizeof() and C types can't be used in preprocessor.

> +typedef long long hg_ssize_t;
> +#elif sizeof(void*) == sizeof(long)
> +typedef long hg_ssize_t;
> +#else
> +typedef int hg_ssize_t;
>  #endif

Maybe we'll have to write a workaround specific to Windows?
Maciej Fijalkowski - July 11, 2016, 1:26 p.m.
The working workaround (it's a bit hard to test) seems to be:

#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T hg_ssize_t;
#else
typedef ssize_t hg_ssize_t
#endif

any opinions?

On Mon, Jul 11, 2016 at 3:12 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Mon, 11 Jul 2016 13:53:47 +0200, Maciej Fijalkowski wrote:
>> # HG changeset patch
>> # User Maciej Fijalkowski <fijall@gmail.com>
>> # Date 1468238015 -7200
>> #      Mon Jul 11 13:53:35 2016 +0200
>> # Node ID 069b332ce21d278384f0b571349b9aba57b42056
>> # Parent  b40939504d0e01e3a7f067b8cf49f26718a7c27c
>> compat: provide a new declaration of hg_ssize_t, in case we don't have it
>>
>> diff -r b40939504d0e -r 069b332ce21d mercurial/compat.h
>> --- a/mercurial/compat.h      Mon Jul 11 11:05:08 2016 +0200
>> +++ b/mercurial/compat.h      Mon Jul 11 13:53:35 2016 +0200
>> @@ -35,4 +35,14 @@
>>  #define inline __inline
>>  #endif
>>
>> +#ifdef HAVE_SSIZE_T
>
> HAVE_SSIZE_T seems to be defined in pyconfig.h, which won't be available
> for cffi build.
>
>> +typedef ssize_t hg_ssize_t;
>> +#elif sizeof(void*) == sizeof(long long)
>
> sizeof() and C types can't be used in preprocessor.
>
>> +typedef long long hg_ssize_t;
>> +#elif sizeof(void*) == sizeof(long)
>> +typedef long hg_ssize_t;
>> +#else
>> +typedef int hg_ssize_t;
>>  #endif
>
> Maybe we'll have to write a workaround specific to Windows?
Yuya Nishihara - July 11, 2016, 1:46 p.m.
On Mon, 11 Jul 2016 15:26:32 +0200, Maciej Fijalkowski wrote:
> The working workaround (it's a bit hard to test) seems to be:
> 
> #if defined(_MSC_VER)
> #include <BaseTsd.h>
> typedef SSIZE_T hg_ssize_t;
> #else
> typedef ssize_t hg_ssize_t
> #endif

(CC +adrian, I'm not Windows expert.)

It seems to work on Visual Studio 2008, which is the default compiler of
Python 2.7.

I slightly prefer using ssize_t like other int/uint_ typedefs, i.e.

  typedef SSIZE_T ssize_t;
Maciej Fijalkowski - July 11, 2016, 1:59 p.m.
On Mon, Jul 11, 2016 at 3:46 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Mon, 11 Jul 2016 15:26:32 +0200, Maciej Fijalkowski wrote:
>> The working workaround (it's a bit hard to test) seems to be:
>>
>> #if defined(_MSC_VER)
>> #include <BaseTsd.h>
>> typedef SSIZE_T hg_ssize_t;
>> #else
>> typedef ssize_t hg_ssize_t
>> #endif
>
> (CC +adrian, I'm not Windows expert.)
>
> It seems to work on Visual Studio 2008, which is the default compiler of
> Python 2.7.
>
> I slightly prefer using ssize_t like other int/uint_ typedefs, i.e.
>
>   typedef SSIZE_T ssize_t;

what happens if ssize_t is already defined? (there are some windows
compilers that do it badly_
Yuya Nishihara - July 11, 2016, 2:24 p.m.
On Mon, 11 Jul 2016 15:59:47 +0200, Maciej Fijalkowski wrote:
> On Mon, Jul 11, 2016 at 3:46 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> > On Mon, 11 Jul 2016 15:26:32 +0200, Maciej Fijalkowski wrote:  
> >> The working workaround (it's a bit hard to test) seems to be:
> >>
> >> #if defined(_MSC_VER)
> >> #include <BaseTsd.h>
> >> typedef SSIZE_T hg_ssize_t;
> >> #else
> >> typedef ssize_t hg_ssize_t
> >> #endif  
> >
> > (CC +adrian, I'm not Windows expert.)
> >
> > It seems to work on Visual Studio 2008, which is the default compiler of
> > Python 2.7.
> >
> > I slightly prefer using ssize_t like other int/uint_ typedefs, i.e.
> >
> >   typedef SSIZE_T ssize_t;  
> 
> what happens if ssize_t is already defined? (there are some windows
> compilers that do it badly_

s/compilers/libraries/ as we check _MSC_VER?

Do they have incompatible typedef? That's unfortunate.
Maciej Fijalkowski - July 11, 2016, 2:40 p.m.
that's I believe why python uses Py_ssize_t. Either way, I'm happy
with either solution (I'm probably happier with ssize_t simply), so
please advise which way we should go

On Mon, Jul 11, 2016 at 4:24 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Mon, 11 Jul 2016 15:59:47 +0200, Maciej Fijalkowski wrote:
>> On Mon, Jul 11, 2016 at 3:46 PM, Yuya Nishihara <yuya@tcha.org> wrote:
>> > On Mon, 11 Jul 2016 15:26:32 +0200, Maciej Fijalkowski wrote:
>> >> The working workaround (it's a bit hard to test) seems to be:
>> >>
>> >> #if defined(_MSC_VER)
>> >> #include <BaseTsd.h>
>> >> typedef SSIZE_T hg_ssize_t;
>> >> #else
>> >> typedef ssize_t hg_ssize_t
>> >> #endif
>> >
>> > (CC +adrian, I'm not Windows expert.)
>> >
>> > It seems to work on Visual Studio 2008, which is the default compiler of
>> > Python 2.7.
>> >
>> > I slightly prefer using ssize_t like other int/uint_ typedefs, i.e.
>> >
>> >   typedef SSIZE_T ssize_t;
>>
>> what happens if ssize_t is already defined? (there are some windows
>> compilers that do it badly_
>
> s/compilers/libraries/ as we check _MSC_VER?
>
> Do they have incompatible typedef? That's unfortunate.
Yuya Nishihara - July 12, 2016, 1:05 p.m.
On Mon, 11 Jul 2016 16:40:55 +0200, Maciej Fijalkowski wrote:
> that's I believe why python uses Py_ssize_t. Either way, I'm happy
> with either solution (I'm probably happier with ssize_t simply), so
> please advise which way we should go

Since we already have own int<n>_t and uint<n>_t typedefs for ancient MSVC,
I think it's fine to redefine ssize_t on MSVC.

Python would have more strict rules for platform compatibility.

Patch

diff -r b40939504d0e -r 069b332ce21d mercurial/compat.h
--- a/mercurial/compat.h	Mon Jul 11 11:05:08 2016 +0200
+++ b/mercurial/compat.h	Mon Jul 11 13:53:35 2016 +0200
@@ -35,4 +35,14 @@ 
 #define inline __inline
 #endif
 
+#ifdef HAVE_SSIZE_T
+typedef ssize_t hg_ssize_t;
+#elif sizeof(void*) == sizeof(long long)
+typedef long long hg_ssize_t;
+#elif sizeof(void*) == sizeof(long)
+typedef long hg_ssize_t;
+#else
+typedef int hg_ssize_t;
 #endif
+
+#endif