# [RFC] 64 bit platform improvements for string length and integer

- Thread: https://externals.io/message/71043
- Original archive: https://news-web.php.net/php.internals/71043
- Started by Anatol Belski on 2014-01-10T14:58:23+00:00
- Messages: 79
- RFC: 64 bit platform improvements for string length and integer (Declined) — https://externals.io/rfc/size_t_and_int64.md
- Page 1 of 4: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/71043.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #71043 — Anatol Belski — 2014-01-10T14:58:23+00:00

URL: https://externals.io/message/71043#71043

Hi,

https://wiki.php.net/rfc/size_t_and_int64

The discussion time has come. The work on the feature branch continues.
The current patch is stable enough to be discussed.

Regards

Anatol

---

## #71044 — Kalle Sommer Nielsen — 2014-01-10T18:29:49+00:00

URL: https://externals.io/message/71043#71044 · In reply to: #71043

Hi Anatol

2014/1/10 Anatol Belski <ab@php.net>:
> Hi,
>
> https://wiki.php.net/rfc/size_t_and_int64

I absolutely love the work, time and effort you have put in to this
branch, I've been following it closely on the sideline. There is one
thing I'm wondering about, maybe I skipped through some of the
sections too fast in the RFC, but what about API BC? I know you
propose it for PHP6, but are there gonna be any macros or other
helpers for extension developers to ease the use of #ifdefs, I realize
things like the parameter parsing one is gonna be tough, but just as a
general thought, I think Derick was asking something like this not too
long ago?



-- 
regards,

Kalle Sommer Nielsen
kalle@php.net

---

## #71045 — Anatol Belski — 2014-01-10T19:32:58+00:00

URL: https://externals.io/message/71043#71045 · In reply to: #71044

Hi Kalle,


> Hi Anatol
>
>
> 2014/1/10 Anatol Belski <ab@php.net>:
>
> > […]
>
> I absolutely love the work, time and effort you have put in to this
> branch, I've been following it closely on the sideline. There is one thing
> I'm wondering about, maybe I skipped through some of the
> sections too fast in the RFC, but what about API BC? I know you propose it
> for PHP6, but are there gonna be any macros or other helpers for extension
> developers to ease the use of #ifdefs, I realize things like the parameter
> parsing one is gonna be tough, but just as a general thought, I think
> Derick was asking something like this not too
> long ago?
>
thanks for the good words :)

The short answer is: yes. I gonna start with that probably right as next.
In plan is the tool for any possible automatic replacements and the
header(s) for backward compatibility. That will be a big ease for the
first step, though it can of course not replace the manual porting.
Parameter parsing is one of the cracky points, but more it will be about
the extension code adoption. Especially size_t usage, while being trivial,
might get one in a muddle. I personally needed 1-2 hours to habituate
size_t, so it works.

Cheers

anatol

---

## #71046 — Anatol Belski — 2014-01-10T19:39:57+00:00

URL: https://externals.io/message/71043#71046 · In reply to: #71045

> Hi Kalle,
>
>
> 
>
> > […]
> thanks for the good words :)
>
> The short answer is: yes. I gonna start with that probably right as next.
>  In plan is the tool for any possible automatic replacements and the
> header(s) for backward compatibility. That will be a big ease for the first
> step, though it can of course not replace the manual porting. Parameter
> parsing is one of the cracky points, but more it will be about the
> extension code adoption. Especially size_t usage, while being trivial,
> might get one in a muddle. I personally needed 1-2 hours to habituate
> size_t, so it works.
>

Ah, btw it is on the RFC, a couple of sentences under "Migration path for
PECL extensions".

Anatol

---

## #71047 — Jan Ehrhardt — 2014-01-10T20:31:14+00:00

URL: https://externals.io/message/71043#71047 · In reply to: #71043

"Anatol Belski" in php.internals (Fri, 10 Jan 2014 15:58:23 +0100):
>https://wiki.php.net/rfc/size_t_and_int64
>
>The discussion time has come. The work on the feature branch continues.
>The current patch is stable enough to be discussed.

I do not have voting karma, but I can confirm that the current
experimental branch is quite stable. I have been testing the
experimental builds for Windows (and compiling them myself). In Drupal6,
Drupal7, Wordpress and own own code I am getting very few different
results compared to the 5.5 releases.

I ran into a segfault with one Drupal7 site (but not with other Drupal7
sites) with opcache enabled. But upon investigating that glitch, I
discovered that PHP 5.5 NTS stumbled over the same Drupal7 site with
opcache enabled. See the php-windows list for details.

Keep on the good work, Anatol!

Jan

---

## #71048 — Nikita Popov — 2014-01-10T21:42:49+00:00

URL: https://externals.io/message/71043#71048 · In reply to: #71043

> Hi,
>
> https://wiki.php.net/rfc/size_t_and_int64
>
> The discussion time has come. The work on the feature branch continues.
> The current patch is stable enough to be discussed.
>

What is the reason behind the renames of IS_LONG to IS_INT (and Z_LVAL to
Z_IVAL etc), as well as the renames in zpp (s -> S, etc)? Why can't we keep
the old names here? That should reduce the amount of ifndefs involved a
lot, as you'd only have to do it for the type declarations themselves, not
for every single usage. Or is the point here to intentionally provide a
maximum amount of BC breakage, so code doesn't "accidentally" continue to
run (e.g. I think that without the renames extensions could continue to run
mostly without issue on 32bit.)

Nikita

---

## #71049 — Anatol Belski — 2014-01-10T23:11:22+00:00

URL: https://externals.io/message/71043#71049 · In reply to: #71048

Hi Nikita,


> 
>
>
> > […]
>
> What is the reason behind the renames of IS_LONG to IS_INT (and Z_LVAL to
>  Z_IVAL etc), as well as the renames in zpp (s -> S, etc)? Why can't we
> keep the old names here? That should reduce the amount of ifndefs involved
> a lot, as you'd only have to do it for the type declarations themselves,
> not for every single usage. Or is the point here to intentionally provide
> a maximum amount of BC breakage, so code doesn't "accidentally" continue
> to run (e.g. I think that without the renames extensions could continue to
> run mostly without issue on 32bit.)
>
> Nikita
>
the renames you mention like IS_LONG -> IS_INT are thought more for
correct semantic, as there is no firm 'long' anymore. The same for
Z_STRLEN -> Z_STRSIZE and others. That kind of thing should be done the
most obvious way. Well, the max BC reason you gave I like too :)

For the same reason zend_parse_parameters() formats was changed, as it'll
issue an error on runtime. However here I still scratch my head as that's
a runtime issue, but it should break the compilation as well.

Without semantic replacements many extensions would just continue to
compile/run on 32 bit, indeed. Though because of the size_t one could
still have some unpleasant surprise in some situation. Besides that, I'd
really see that more like a side effect with not very clear use.

With the #ifdef's - there shouldn't be any or should be very few. The
compatibility header I've mentioned in one of the previous responses
should do it one for all. It can look like

#if `PHP_MAJOR_VERSION` < 6
# define IS_INT IS_LONG
# define php_size_t int
.......
#endif

Once included and given an extension is compiled with an older PHP
version, that defines should cover the compatibility with older semantics.
Some more complicated solution will probably be needed for zpp to replace
"i" with "l" and co. for the older PHP. But generally, such a header
should make the same ext source in 6.x style compatible with 5.x branch.
Of course some exceptions will have to take place, but i think those will
be not more than the current mainstream already contains to separate the
code for minor versions in 5.x branch.

The migration path is the very next thing I have to do.

Regards

Anatol

---

## #71050 — Jan Ehrhardt — 2014-01-11T01:31:41+00:00

URL: https://externals.io/message/71043#71050 · In reply to: #71048

Nikita Popov in php.internals (Fri, 10 Jan 2014 22:42:49 +0100):
>                         Or is the point here to intentionally provide a
>maximum amount of BC breakage, so code doesn't "accidentally" continue to
>run (e.g. I think that without the renames extensions could continue to run
>mostly without issue on 32bit.)

Some of the PECL extensions compiled without really complaining with the
new experimental branch (on Windows). Anatol's own xmldiff,
php_blenc.dll (but it did not work), php_uploadprogress.dll and
php_timezonedb.dll.

The BC break should probably be even greater, so that cases like the
blenc extension do not occur.

I have converted one of my own extensions (that is not even on PECL):
php_ffmpeg.dll. I did not do that (yet) with ifndef's, but just with
global searching and replacing. So I have two sources for the same
extension right now.

Jan

---

## #71051 — Hannes Magnusson — 2014-01-11T01:33:50+00:00

URL: https://externals.io/message/71043#71051 · In reply to: #71049

> Hi Nikita,
>
> 
> > […]
> the renames you mention like IS_LONG -> IS_INT are thought more for
> correct semantic, as there is no firm 'long' anymore. The same for
> Z_STRLEN -> Z_STRSIZE and others. That kind of thing should be done the
> most obvious way. Well, the max BC reason you gave I like too :)
>
> For the same reason zend_parse_parameters() formats was changed, as it'll
> issue an error on runtime. However here I still scratch my head as that's
> a runtime issue, but it should break the compilation as well.
>
> Without semantic replacements many extensions would just continue to
> compile/run on 32 bit, indeed. Though because of the size_t one could
> still have some unpleasant surprise in some situation. Besides that, I'd
> really see that more like a side effect with not very clear use.
>
> With the #ifdef's - there shouldn't be any or should be very few. The
> compatibility header I've mentioned in one of the previous responses
> should do it one for all. It can look like
>
> #if `PHP_MAJOR_VERSION` < 6
> # define IS_INT IS_LONG
> # define php_size_t int
> .......
> #endif
>
> Once included and given an extension is compiled with an older PHP
> version, that defines should cover the compatibility with older semantics.
> Some more complicated solution will probably be needed for zpp to replace
> "i" with "l" and co. for the older PHP. But generally, such a header
> should make the same ext source in 6.x style compatible with 5.x branch.
> Of course some exceptions will have to take place, but i think those will
> be not more than the current mainstream already contains to separate the
> code for minor versions in 5.x branch.
>
> The migration path is the very next thing I have to do.


I am really confused on that. How is the compatibility header useful
if I still need a ifdef else for zpp and things that boil down to
printfs, like error reporting,  with 2 different arguments?

Wouldn't it be better to not change them, but maybe force extensions
to define a _I_SUPPORT_PHP6, if not defined refuse to build the ext
against PHP6?

Then all I have to do in extension is to include the compat header,
change some of my types passed to zpp/printfs and define that macro..
and I could support PHP5 and PHP6.

And if I try to build against PHP6 it would result in compiler failure...
We'd maybe need to tweak the build system a tiny bit, and phpize, for
that to happen - but that seem to be much easier then supporting PHP5
and 6 for extensions in the same codebase with renamed zpp values?

-Hannes

---

## #71053 — Anatol Belski — 2014-01-11T03:34:20+00:00

URL: https://externals.io/message/71043#71053 · In reply to: #71051

Hi Hannes,


> 
>
> > […]
>
>
> I am really confused on that. How is the compatibility header useful
> if I still need a ifdef else for zpp and things that boil down to printfs,
> like error reporting,  with 2 different arguments?
with the php_error_docref() - very good point, the header can't help much.
Except to define something like php_error_docref_comp() as a wrapper
function in the compat header, so %pd and alike can be replaced on
runtime. The code might miss some #ifdefs then, so be cleaner.

> Wouldn't it be better to not change them, but maybe force extensions
> to define a _I_SUPPORT_PHP6, if not defined refuse to build the ext against
> PHP6?
>
Yeah, I'd say an explicit define to indicate PHP6 readiness is good point
as well.

About zpp I've got a click - the compatibility with 5.x can be integrated
into zpp itself in 6.x. I mean look here
http://git.php.net/?p=php-src.git;a=blob;f=Zend/zend_API.c;hb=refs/heads/str_size_and_int64#l326
- 'l' and 'L' was replaced with 'i' and 'I', but nothing prevents to turn
those formats as aliases in 6.x. That way 'l' and 'i' and another pairs
will do the same thing, new implementations can use clean semantics, and
the old formats can be removed after 5.x EOL. This solution however won't
force the new semantic.

Another way i could suggest for zpp is similarly to docrefs using a
wrapper like zend_parse_parameters_comp(), which would replace new for
old. Still not very nice but would guarantee semantically correct formats.


> Then all I have to do in extension is to include the compat header,
> change some of my types passed to zpp/printfs and define that macro.. and I
> could support PHP5 and PHP6.
>
> And if I try to build against PHP6 it would result in compiler failure...
>  We'd maybe need to tweak the build system a tiny bit, and phpize, for
> that to happen - but that seem to be much easier then supporting PHP5 and 6
> for extensions in the same codebase with renamed zpp values?
>
Sounds plausible to me. Parameters parsing and spprintf are the only
cracky places I can think of now, the other macros/function renames should
be easy covered with the compat header, so can me machinable replaced with
some tool, even sed script.

The _I_SUPPORT_PHP6 def (should be defined before includes) can be checked
directly in php.h, where an #error can be thrown. That sounds like a sane
migration workflow. Like if I'm not aware of 6.x and try to compile just
right on, it'll reject. If I explicitly say, that i'm ready for 6.x, means
i've done the porting work before.

So for the migration it'd be like

- run the replacement tool on the sources for simple semantic fixes
- include compat header
- #define PHP6_SUPPORTED
- replace appropriate things with *_compat() wrappers or do some #ifdefs
- fix datatypes for function args
- fix the extension code where appropriate (that might be big or not, as
Jan meant some exts he's tried was easy)
- check if it plays good with some lib i link against, do some range
checks eventually

Sounds like a plan.

Thanks for the ideas!

Anatol

---

## #71055 — Jakub Zelenka — 2014-01-11T13:18:46+00:00

URL: https://externals.io/message/71043#71055 · In reply to: #71053

Hi Anatol,



>
> About zpp I've got a click - the compatibility with 5.x can be integrated
> into zpp itself in 6.x. I mean look here
>
> http://git.php.net/?p=php-src.git;a=blob;f=Zend/zend_API.c;hb=refs/heads/str_size_and_int64#l326
> - 'l' and 'L' was replaced with 'i' and 'I', but nothing prevents to turn
> those formats as aliases in 6.x. That way 'l' and 'i' and another pairs
> will do the same thing, new implementations can use clean semantics, and
> the old formats can be removed after 5.x EOL. This solution however won't
> force the new semantic.
>

I agree with keeping old flags ('l', 'p', 's'...). I think that would be
good to add range checks to zend_parse_arg_impl for these flags. If the
casted value is bigger (LONG_MAX, INT_MAX...), then warning. It would be
really helpful and simplify the migration for library wrappers where these
checks needs to be usually done...

Thanks

Jakub

---

## #71061 — Pierre Joye — 2014-01-11T14:43:14+00:00

URL: https://externals.io/message/71043#71061 · In reply to: #71043

Hi,


>
> Hi,
>
> https://wiki.php.net/rfc/size_t_and_int64
>
> The discussion time has come. The work on the feature branch continues.
> The current patch is stable enough to be discussed.
>

For the record, we actually like to target 5.6 for this change. There was a
little confusion due to the 5.6 timetable having been slightly shifted.

Also the various changes we introduce has been discussed intensively (on
this list on irc) to minimize the amount of changes required to support
64bit integer.

Cheers,
Pierre

---

## #71062 — Anatol Belski — 2014-01-11T14:48:22+00:00

URL: https://externals.io/message/71043#71062 · In reply to: #71055

Hi Jakub,


> Hi Anatol,
>
>
>
>
> > […]
>
> I agree with keeping old flags ('l', 'p', 's'...). I think that would be
> good to add range checks to zend_parse_arg_impl for these flags. If the
> casted value is bigger (LONG_MAX, INT_MAX...), then warning. It would be
> really helpful and simplify the migration for library wrappers where
> these checks needs to be usually done...
>
the range checks is what 'L' vs 'I' would stand for, the 'L' would be
available as alias for 'I', so one don't has to change zpp. A good thing
were to add type checks,

with gcc http://gcc.gnu.org/onlinedocs/gcc/Typeof.html , however not sure
it's available with Visual Studio.

Regards

Anatol

---

## #71063 — Jakub Zelenka — 2014-01-11T15:05:01+00:00

URL: https://externals.io/message/71043#71063 · In reply to: #71062

> the range checks is what 'L' vs 'I' would stand for, the 'L' would be
> available as alias for 'I', so one don't has to change zpp. A good thing
> were to add type checks,
>
>
Oh I see. The only small objection is that these lines could lead to the
unexpected result from the user point of view:

if (d > ZEND_INT_MAX) {
    *p = ZEND_INT_MAX;
    break;
} else if (d < ZEND_INT_MIN) {
    *p = ZEND_INT_MIN;
    break;
}

I think that would make sense to add warning here

Also similar checks for "s" and "p" length part (size_t -> int) would be
great too! ;)

Thanks

Regards

Jakub

---

## #71064 — Anatol Belski — 2014-01-11T15:29:43+00:00

URL: https://externals.io/message/71043#71064 · In reply to: #71063

> 
>
>
> > […]
> Oh I see. The only small objection is that these lines could lead to the
> unexpected result from the user point of view:
>
> if (d > ZEND_INT_MAX) { *p = ZEND_INT_MAX;
> break; } else if (d < ZEND_INT_MIN) {
> *p = ZEND_INT_MIN;
> break; }
>
>
> I think that would make sense to add warning here
>
>
> Also similar checks for "s" and "p" length part (size_t -> int) would be
> great too! ;)
>
yep, that's exactly how it performs till now in the mainstream, just
replace ZEND_INT_MAX with LONG_MAX. Adding a warning to every such case
would cause a warning flood in many PHP apps, guaranteed :) Whereby it
might be ok for debug mode maybe, I wouldn't do it as I can't remember any
WTFs about the behavior.

Cheers

Anatol

---

## #71067 — Anatol Belski — 2014-01-11T16:05:38+00:00

URL: https://externals.io/message/71043#71067 · In reply to: #71061

> Hi,
>
>
> 
>
> > […]
>
> For the record, we actually like to target 5.6 for this change. There was
> a little confusion due to the 5.6 timetable having been slightly shifted.
>
> Also the various changes we introduce has been discussed intensively (on
> this list on irc) to minimize the amount of changes required to support
> 64bit integer.
>
>
I've updated the RFC accordingly, also the possible vote choices.

Regards

Anatol

---

## #71068 — Jakub Zelenka — 2014-01-11T16:08:26+00:00

URL: https://externals.io/message/71043#71068 · In reply to: #71064

>
> yep, that's exactly how it performs till now in the mainstream, just
> replace ZEND_INT_MAX with LONG_MAX. Adding a warning to every such case
> would cause a warning flood in many PHP apps, guaranteed :) Whereby it
> might be ok for debug mode maybe, I wouldn't do it as I can't remember any
> WTFs about the behavior.
>
>
I meant adding warning only for overflow cases. Values in existing apps
can't be bigger than LONG_MAX so I don't see how it could cause warning
flood in the current PHP apps. I don't even think that users will be often
using such a big values after the 64bit changes.

The thing is that if I use value bigger than LONG_MAX after 64bit changes
and I pass it to the function defined in extension that does not support it
(use "l" in zpp), then I rather see warning than unexpected rounding to
LONG_MAX... There is no way how to find out (except looking to the ext
sources) that the big values are not supported. If I get warning, I can fix
it in the code straight away...

The another thing is that this checking needs to be done by other libraries
wrappers after getting parameters because the most libraries using smaller
types. That was exactly what I did when I worked on openssl ext for 64bit
and I will need to do it in my fann and crypto extension. There are bunch
of other extensions that will need to do it too (for example imagick). The
difference with openssl changes is that the BC will need to be kept. I am
sure that if warnings were already in zend_parse_arg_impl, then the work
for supporting 64bit branch would much easier for me and other PECL
extension maintainers...

Cheers

Jakub

---

## #71069 — Anatol Belski — 2014-01-11T16:53:36+00:00

URL: https://externals.io/message/71043#71069 · In reply to: #71068

Hi Jakub,


> 
>
>
> > […]
> I meant adding warning only for overflow cases. Values in existing apps
> can't be bigger than LONG_MAX so I don't see how it could cause warning
> flood in the current PHP apps. I don't even think that users will be
> often using such a big values after the 64bit changes.
>
> The thing is that if I use value bigger than LONG_MAX after 64bit changes
>  and I pass it to the function defined in extension that does not support
> it (use "l" in zpp), then I rather see warning than unexpected rounding to
>  LONG_MAX... There is no way how to find out (except looking to the ext
> sources) that the big values are not supported. If I get warning, I can
> fix it in the code straight away...
>
But isn't it the exact situation now on ILP32 vs LP64 systems? Like 32 vs
64 bit Linux? I haven't suggested 'l' to handle the param the old way,
just it to be an alias for 'i'. In the new code that would be as dynamic
as php_int_t is, however 'l' as alias would retain zpp compatibility to
the older PHP.

For instance how much sense had such a centralized warding for the snippet
is_int(PHP_INT_MAX+1) ? There is a lot of functions accepting an arbitrary
numeric value and not depending on any library, why they should throw a
warning by default? Why should we throw a warning about 32 bit in the 64
bit build? Furtehrmore, LONG_MAX is 64 bit on LP64 systems, that would be
the same as PHP_INT_MAX.

> The another thing is that this checking needs to be done by other
> libraries wrappers after getting parameters because the most libraries
> using smaller types. That was exactly what I did when I worked on openssl
> ext for 64bit and I will need to do it in my fann and crypto extension.
> There are bunch
> of other extensions that will need to do it too (for example imagick). The
>  difference with openssl changes is that the BC will need to be kept. I
> am sure that if warnings were already in zend_parse_arg_impl, then the
> work for supporting 64bit branch would much easier for me and other PECL
> extension maintainers...
>
Yes, that's the case - the range checks have to be done locally according
to what the wrapped library needs. If you haven't done them till now, you
might have an issue on 64 bit linux anyway. Like say the lib uses int, but
64 bit long is passed. If that checks are already in place in your ext,
then it's fine.

The range checks you've done for openssl are the obligatory part, that's
what I was doing as well for all the other extensions. Some are still
pending as on the progress wiki page. And of course this is to mention in
the porting guide. The libraries are different, for instance iconv uses
size_t for string length, libxml uses int for string length. zpp cannot
know, which library an extension uses. On the other hand - an extension
without any library deps but with some math functions should be kept in
mind, too.

Regards

anatol

---

## #71070 — Jakub Zelenka — 2014-01-11T18:31:33+00:00

URL: https://externals.io/message/71043#71070 · In reply to: #71069

> Hi Jakub,
>
> 
> > […]
> to
> > […]
> But isn't it the exact situation now on ILP32 vs LP64 systems? Like 32 vs
> 64 bit Linux? I haven't suggested 'l' to handle the param the old way,
> just it to be an alias for 'i'. In the new code that would be as dynamic
> as php_int_t is, however 'l' as alias would retain zpp compatibility to
> the older PHP.
>
> For instance how much sense had such a centralized warding for the snippet
> is_int(PHP_INT_MAX+1) ? There is a lot of functions accepting an arbitrary
> numeric value and not depending on any library, why they should throw a
> warning by default? Why should we throw a warning about 32 bit in the 64
> bit build? Furtehrmore, LONG_MAX is 64 bit on LP64 systems, that would be
> the same as PHP_INT_MAX.
>
>
This is of course just about LLP64 when the situation has changed. I think
that we are talking about slightly different things. Sorry my first example
was a bit incorrect (ZEND_INT_MAX = _I64_MAX which is bigger than LONG_MAX
on LLP64)

What I was suggesting is keeping BC for code like this:
...
long n;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &n) == FAILURE) {
return; }
...
 The warning would be thrown if it's bigger than LONG_MAX or smaller than
LONG_MIN.

If I understood correctly you are suggesting using php_int_t for n (defined
in compat header as long if not defined in php.h)? The problem is that the
type would be dependent on PHP versions and when you need to be sure that
it's a long (which might be the case when you pass it to the another lib
function), then you need to check PHP_API_VERSION and in case it's not
long, you have to do range check.

In general, I think that would be better to keep BC for "l" and use it just
for long values (the "l" actually stands for long... :) ). That could be
achieved adding range checks with warning if the value is bigger than
LONG_MAX or smaller than LONG_MIN in zend_parse_arg_impl (it would probably
require small changes in zend_parse_arg [expected_value...]).

Btw. I see your point about the arbitary number. But I also feel that it
would be better to keep it as long as it would keep the same behavior when
passed to external libs.

Cheers

Jakub

---

## #71072 — Anatol Belski — 2014-01-11T19:34:59+00:00

URL: https://externals.io/message/71043#71072 · In reply to: #71070

Hi Jakub,


> 
>
>
> > […]
> This is of course just about LLP64 when the situation has changed. I
> think that we are talking about slightly different things. Sorry my first
> example was a bit incorrect (ZEND_INT_MAX = _I64_MAX which is bigger than
> LONG_MAX
> on LLP64)
well, there's no another chance to understand each other than using some
verbal devices  :)

> What I was suggesting is keeping BC for code like this:
> ...
> long n; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &n) ==
> FAILURE) {
> return; } ...
> The warning would be thrown if it's bigger than LONG_MAX or smaller than
> LONG_MIN.
>
> If I understood correctly you are suggesting using php_int_t for n
> (defined
> in compat header as long if not defined in php.h)? The problem is that the
>  type would be dependent on PHP versions and when you need to be sure
> that it's a long (which might be the case when you pass it to the another
> lib function), then you need to check PHP_API_VERSION and in case it's not
>  long, you have to do range check.
If a library expects long, in the new code that's the issue on 32 bit
windows only. So yes, probably the way you describe is plausible, check
PHP_WIN32 and PHP_API_VERSION. Honestly, right at the place where I sit, I
can't remember any library working with long (well, timeval struct and so
on, not really libs). There are int, size_t, int64_t, ... so while the
case you describe is of course possible, it's rather an exception. Usually
a simple runtime range check will be good enough, if needed at all.

>
> In general, I think that would be better to keep BC for "l" and use it
> just for long values (the "l" actually stands for long... :) ). That could
> be achieved adding range checks with warning if the value is bigger than
> LONG_MAX or smaller than LONG_MIN in zend_parse_arg_impl (it would
> probably require small changes in zend_parse_arg [expected_value...]).
>
Just to remind, your very first reply was to the mail about the zpp
compatibility, namely so then one wouldn't have to touch zpp calls for
migration, only the variables. That's why i've suggested to alias the new
formats with old. If we let 'l' to do the old thing, then zpp will have to
be touched at many places to be replaced with 'i' with all the
corresponding consequences. So retaining the functional compatibliity with
'l', an easier migration way is not possible. Also I'm asking myself, how
essential it really is, in the light of how many libs will profit from one
or another way.

Regards

anatol

---

## #71073 — Anatol Belski — 2014-01-11T20:17:13+00:00

URL: https://externals.io/message/71043#71073 · In reply to: #71072

> > […]
> If a library expects long, in the new code that's the issue on 32 bit
> windows only. So yes, probably the way you describe is plausible, check
> PHP_WIN32 and PHP_API_VERSION.

Err, it's issue only on windows 64 bit, as php_int_t is __int64 there. So
the macros needs check _WIN64 only, not PHP_WIN32.

Regards

Anatol

---

## #71105 — Jakub Zelenka — 2014-01-12T21:18:44+00:00

URL: https://externals.io/message/71043#71105 · In reply to: #71072

Hi Anatol,



> If a library expects long, in the new code that's the issue on 32 bit
> windows only. So yes, probably the way you describe is plausible, check
> PHP_WIN32 and PHP_API_VERSION. Honestly, right at the place where I sit, I
> can't remember any library working with long (well, timeval struct and so
> on, not really libs). There are int, size_t, int64_t, ... so while the
> case you describe is of course possible, it's rather an exception. Usually
> a simple runtime range check will be good enough, if needed at all.
>
>
Actually there is one big library where you can find it. It's OpenSSL which
is why I was asking about it.. :) There are quite a few places where it's
used. The main ones are following:

- ASN.1 API functions (I plan to completely wrap it :) ) where it's used
for data length.
- BIO_ctrl for length parameter (BIO_ctrl is a definition result for many
macros like BIO_set_mem_buf, BIO_set_buffer_size, BIO_set_write_buf_size...)
- Big numbers - there is a situation a bit more complicated but unsigned
long is used (there will be necessary some other checks anyway so it's not
an issue)

I think that would be good to have a look to the other exts and double
check if used libs have long parameters for data lengths. If not, then I
agree with you that there is no point to do casting to long with warnings
just because of OpenSSL.

However it would be good to define in compat header a macro for checking
that long != php_int_t . I know that it's currently only _WIN64 but if you
implement enabling 64bit on 32bit platform (future scope in the RFC :) ),
then there will be an extra definition.

Cheers

Jakub

---

## #71106 — Jakub Zelenka — 2014-01-12T23:23:49+00:00

URL: https://externals.io/message/71043#71106 · In reply to: #71105

> Hi Anatol,
>
> Jakub
> 
>
> > […]
> Actually there is one big library where you can find it. It's OpenSSL
> which is why I was asking about it.. :) There are quite a few places where
> it's used. The main ones are following:
>
> - ASN.1 API functions (I plan to completely wrap it :) ) where it's used
> for data length.
> - BIO_ctrl for length parameter (BIO_ctrl is a definition result for many
> macros like BIO_set_mem_buf, BIO_set_buffer_size, BIO_set_write_buf_size...)
> - Big numbers - there is a situation a bit more complicated but unsigned
> long is used (there will be necessary some other checks anyway so it's not
> an issue)
>
> I think that would be good to have a look to the other exts and double
> check if used libs have long parameters for data lengths. If not, then I
> agree with you that there is no point to do casting to long with warnings
> just because of OpenSSL.
>
> However it would be good to define in compat header a macro for checking
> that long != php_int_t . I know that it's currently only _WIN64 but if you
> implement enabling 64bit on 32bit platform (future scope in the RFC :) ),
> then there will be an extra definition.
>
>
I was thinking a bit more what will be the consequences of asn1 and bio in
my ext for "l" flag and it won't be such a big issue regarding to zpp.
There are just few cases in asn1 (ASN1_INTEGER_set for example) and BIO
stuff will probably require mainly string conversions which is a bit
different issue...

What's the actually plan for keeping BC for "s" and "p"? Is it gonna be
zend_str_size from compat header and "s" and "p" aliases of "S" and "P"?

Something like...
...
char *s;
zend_str_size len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &s, &len) ==
FAILURE) { return; }
...

If so, I think that that would be a slightly bigger issue (size_t vs
int)...

There are only two solutions of zpp "s" that I think of:
1. check range (INT_MAX) and cast it to int (possibly throw warning if it's
out of range) -> that could result too many warning but it's safe
2. PHP version variable zend_str_size (see above) -> the same as discussed
for long but considerably more places where we will need to find out what
the zend_str_size really is.

What do you think?

Cheers

Jakub

---

## #71107 — Anatol Belski — 2014-01-13T03:37:04+00:00

URL: https://externals.io/message/71043#71107 · In reply to: #71053

Hi,



> About zpp I've got a click - the compatibility with 5.x can be integrated
>  into zpp itself in 6.x. I mean look here
> http://git.php.net/?p=php-src.git;a=blob;f=Zend/zend_API.c;hb=refs/heads/
> str_size_and_int64#l326 - 'l' and 'L' was replaced with 'i' and 'I', but
> nothing prevents to turn those formats as aliases in 6.x. That way 'l' and
> 'i' and another pairs
> will do the same thing, new implementations can use clean semantics, and
> the old formats can be removed after 5.x EOL. This solution however won't
>  force the new semantic.
>
> Another way i could suggest for zpp is similarly to docrefs using a
> wrapper like zend_parse_parameters_comp(), which would replace new for old.
> Still not very nice but would guarantee semantically correct formats.

Here's the first worky header and replacement tool variant
http://git.php.net/?p=php-src.git;a=tree;f=compat;h=166ac434f01d38119eb12160f2513cfe99c39b42;hb=refs/heads/str_size_and_int64
. The PECL readme is in progress.

After trying some extensions I come to conclusion, that both of the
compatibility variants above are not good.

The first one with aliasing gives no good feeling, after trying in
practice - it might lead even to more confusion.
The second with the *_compat() - technically it's a bit rubbish, as the
specs are literals saved in the readonly TEXT segment, so replacing on the
fly costs some allocations on the heap. While still doable, the overhead
isn't worthy.

The variant I would suggest is using ternary operator, passing both old
and new style, like

COMPAT ? "lLps" : "iIPS"

While being simple, this makes the difference good visible, so is clear.
Comparing with the breakages we had in the past like literals between 5.3
and 5.4, syntactically no #ifdef needed as it's done in place.

For the printf formats I'd suggest using ZEND_INT_FMT macros concatenated
with the format literal. The quirk here is the same as it's in the TEXT
segment. But still, with this solution no #ifdef is needed.

The latter solution suggestions are much simpler and don't need to be done
much, what do you think?

The readme is still in progress, however if curious, the current
replacement tool and header already do the job, so one can try the porting
with minimal effort.

Regards

Anatol

---

## #71111 — Anatol Belski — 2014-01-13T20:31:57+00:00

URL: https://externals.io/message/71043#71111 · In reply to: #71107

Hi,

the usable porting doc is now available

http://git.php.net/?p=php-src.git;a=blob;f=compat/PECL_PORTING;hb=refs/heads/str_size_and_int64

The replacement tool and the header are in the same folder.

Regards

Anatol

---

Next page: https://externals.io/message/71043.md?page=2
