Hi, snprintf() in VC 2010 had not supported "%zd" format. So we can not use it in PyOS_snprintf, PySys_WriteStdout, etc... But VC supports "%zd" format since (at least) VC 2015. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-... "%zd" is standard C99 feature. Can we assume it is portable for now? Regards, -- Inada Naoki <songofacandy@gmail.com>
Hi INADA-san, Is it supported on macOS, FreeBSD, AIX, Android, etc.? My notes on platforms supported by Python: https://pythondev.readthedocs.io/platforms.html For example, xlc C compiler seems to be commonly used on AIX. I don't know how is its C99 support. Can we write an unit test somewhere to ensure that %zd works as expected? Victor Le 01/08/2019 à 14:01, Inada Naoki a écrit :
Hi,
snprintf() in VC 2010 had not supported "%zd" format. So we can not use it in PyOS_snprintf, PySys_WriteStdout, etc...
But VC supports "%zd" format since (at least) VC 2015. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-...
"%zd" is standard C99 feature. Can we assume it is portable for now?
Regards,
-- Night gathers, and now my watch begins. It shall not end until my death.
On 01Aug2019 15:14, Victor Stinner <vstinner@redhat.com> wrote:
Is it supported on macOS, FreeBSD, AIX, Android, etc.?
Looks like it is supported on MacOS 10.11.6 (El Capitan) here. "man 3 snprintf" lists the "z" modifier and says: The z modifier, when applied to a d or i conversion, indicates that the argument is of a signed type equivalent in size to a size_t. I know this is only one data point of many. Cheers, Cameron Simpson <cs@cskk.id.au>
On Thu, Aug 1, 2019 at 10:21 PM Victor Stinner <vstinner@redhat.com> wrote:
Hi INADA-san,
Is it supported on macOS, FreeBSD, AIX, Android, etc.?
My notes on platforms supported by Python: https://pythondev.readthedocs.io/platforms.html
For example, xlc C compiler seems to be commonly used on AIX. I don't know how is its C99 support.
Can we write an unit test somewhere to ensure that %zd works as expected?
Victor
I don't know about AIX too. I googled, but I can not find even man manual for snprintf(3) on AIX. I'm frustrated I wasted a few hours to read some PDFs and searching but I can not find any official document about snprintf(3). I feel it's impossible to support such platforms... Except AIX, I believe all platforms supports size_t and %zd because it's very basic C99 feature. Regards, -- Inada Naoki <songofacandy@gmail.com>
If it's in MSVC as used to compile Python, gcc, and clang I think that's enough coverage by PEP 7 standards: https://www.python.org/dev/peps/pep-0007/#c-dialect.
On 02/08/2019 04:12, Inada Naoki wrote:
On Thu, Aug 1, 2019 at 10:21 PM Victor Stinner <vstinner@redhat.com> wrote:
Hi INADA-san,
Is it supported on macOS, FreeBSD, AIX, Android, etc.?
My notes on platforms supported by Python: https://pythondev.readthedocs.io/platforms.html
For example, xlc C compiler seems to be commonly used on AIX. I don't know how is its C99 support.
Can we write an unit test somewhere to ensure that %zd works as expected?
Victor
I don't know about AIX too. I googled, but I can not find even man manual for snprintf(3) on AIX.
I'm frustrated I wasted a few hours to read some PDFs and searching but I can not find any official document about snprintf(3). I feel it's impossible to support such platforms...
AIX man pages "group" printf() functions together on one page. During a quick search I found a man page for AIX 4.3.3 (which is roughly 1997), and also for AIX 7.2. So the core function is there (in libc.a). I do not have any systems older than AIX 5.3 - and a much too simplified program (printf(), sprintf(), snprintf() all support the same formatting arguments. In the documentation I do not see any reference to %z... support (although I do see support for vectors using %v...). As to XLC and c99, etc.. FYI: when called as "cc" the compiler behavior is "pre-c99", whatever that may be. For strict c99 you call it as c99. I call it as xlc and xlc_r to get c99 and some other extensions by default. The only thing you need remember is that XLC supports, for years, various standards - including c99. Just not, by default, if called as "cc". Further, (imho) it is not the compiler that "supports" a particular printf() format - rather the compiler verifies the syntax, does the work for the call - but the actual support is provided by libc.a - which is maintained by core AIX - not the compiler developer/maintainers. OK - a too simple program - run on AIX 5.3 - seems to indicate that XLC (version 11, so quite old!) accepts "%zd". If someone would be kind enough to mail me a better example of what needs to be verfied - I am happy to compile and publish the results. root@x065:[/data/prj/aixtools/tests]cat printf-test.c #include <stdio.h> main() { printf("Hello World - testing for %%zd support\n"); printf("%%zd of 1001 == %zd\n", 1001); printf("\nTest complete\n"); } oot@x065:[/data/prj/aixtools/tests]./a.out Hello World - testing for %zd support %zd of 1001 == 1001 Test complete fyi: AIX 4.3 https://sites.ualberta.ca/dept/chemeng/AIX-43/share/man/info/C/a_doc_lib/lib... and AIX 7.2 https://www.ibm.com/support/knowledgecenter/ssw_aix_72/p_bostechref/printf.h...
Except AIX, I believe all platforms supports size_t and %zd because it's very basic C99 feature.
Regards, -- Inada Naoki <songofacandy@gmail.com> _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/O7H4FBLD...
Thank you for confining it! Currently, Python defines PY_FORMAT_SIZE_T as: #ifndef PY_FORMAT_SIZE_T # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__) # define PY_FORMAT_SIZE_T "" # elif SIZEOF_SIZE_T == SIZEOF_LONG # define PY_FORMAT_SIZE_T "l" # elif defined(MS_WINDOWS) # define PY_FORMAT_SIZE_T "I" # else # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T" # endif #endif https://github.com/python/cpython/blob/1213123005d9f94bb5027c0a5256ea4d3e97b... This can be changed to this: #ifndef PY_FORMAT_SIZE_T /* "z" is defined C99 and portable enough. We can use "%zd" instead of "%" PY_FORMAT_SIZE_T "d" for now. */ # define PY_FORMAT_SIZE_T "z" #endif On Mon, Aug 5, 2019 at 6:05 PM Michael <aixtools@felt.demon.nl> wrote:
OK - a too simple program - run on AIX 5.3 - seems to indicate that XLC (version 11, so quite old!) accepts "%zd".
If someone would be kind enough to mail me a better example of what needs to be verfied - I am happy to compile and publish the results.
root@x065:[/data/prj/aixtools/tests]cat printf-test.c #include <stdio.h>
main() { printf("Hello World - testing for %%zd support\n"); printf("%%zd of 1001 == %zd\n", 1001); printf("\nTest complete\n"); }
oot@x065:[/data/prj/aixtools/tests]./a.out Hello World - testing for %zd support %zd of 1001 == 1001
Test complete
fyi: AIX 4.3 https://sites.ualberta.ca/dept/chemeng/AIX-43/share/man/info/C/a_doc_lib/lib...
and AIX 7.2 https://www.ibm.com/support/knowledgecenter/ssw_aix_72/p_bostechref/printf.h...
On 05/08/2019 11:16, Inada Naoki wrote:
https://github.com/python/cpython/blob/1213123005d9f94bb5027c0a5256ea4d3e97b...
This can be changed to this:
#ifndef PY_FORMAT_SIZE_T /* "z" is defined C99 and portable enough. We can use "%zd" instead of "%" PY_FORMAT_SIZE_T "d" for now. */ # define PY_FORMAT_SIZE_T "z" #endif
Just in case you are curious - I made the change manually in pyport.h and AIX passes all tests. Hope this helps!
On 01/08/2019 15:14, Victor Stinner wrote:
For example, xlc C compiler seems to be commonly used on AIX. I don't know how is its C99 support.
FYI - this is from the XL C "compiler" reference document for V-10, with copyright set in 2008. Just an excerpt - c99 is supported. Just have to say CC=c99 or CC=xlc or one of the other variants. If more documentation is desired - just let me know. Michael Standards and specifications XL C is designed to support the following standards and specifications. You can refer to these standards for precise definitions of some of the features found in this information. * Information Technology – Programming languages – C, ISO/IEC 9899:1990, also known as C89. * Information Technology – Programming languages – C, ISO/IEC 9899:1999, also known as C99.
participants (5)
-
Brett Cannon
-
Cameron Simpson
-
Inada Naoki
-
Michael
-
Victor Stinner