[issue18060] Updating _fields_ of a derived struct type yields a bad cif

2013-05-25 Thread Lauri Alanko

New submission from Lauri Alanko:

In Modules/_ctypes/stgdict.c:567 there is a suspicious line:

stgdict->length = len;  /* ADD ffi_ofs? */

That is, the length field of the stgdict is set to the number of fields in the 
immediate Structure class, and the number of fields in the parent class 
(ffi_ofs) is questionably left out. This is wrong.

The length field is used in PyCStgDict_clone to copy the ffi_type descriptors 
for struct elements to a derived struct type. If length is short, not all 
element types are copied, and the resulting array is not NULL-terminated.

So the problem manifests when you inherit from a structure type, update the 
_fields_ of the inherited type, and then inherit again from the updated type. 
Even then everything might seem normal, since the elements array is actually 
not used very much.

However, attached is a test case that segfaults at least with debug builds on 
ARM with the VFP ABI. The non-null-terminated element type array is traversed 
to find if the structure can be passed in floating point registers, eventually 
resulting in dereferencing 0xfbfbfbfb.

The test program should print out pi. To avoid the hassle of a separate C 
component, the program abuses the standard atan2 function by pretending it 
takes a struct of two doubles instead of two separate double parameters. This 
does not make a difference to the ABI.

Fixing the bug is trivial. Just change the line to:

 stgdict->length = ffi_ofs + len;

--
components: ctypes
files: t1.py
messages: 189992
nosy: lauri.alanko
priority: normal
severity: normal
status: open
title: Updating _fields_ of a derived struct type yields a bad cif
type: crash
versions: Python 3.3
Added file: http://bugs.python.org/file30369/t1.py

___
Python tracker 
<http://bugs.python.org/issue18060>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1298] Support for z/OS and EBCDIC.

2007-10-24 Thread Lauri Alanko

Lauri Alanko added the comment:

The port is certainly not yet "complete" in any sense. I have only fixed
the most obvious places where explicit conversion between ASCII/Unicode
values and platform-specific characters is required. There are a number
of remaining issues, some of which cannot be fixed without major
rehauls. The point of this first release is just to allow other
interested people to chime in, to test the patch, and to suggest what
should be done with it. The latter has certainly happened. :)

I have no great interest in whether the patch ever gets incorporated
into the main Python distribution. I do think, though, that it's a good
idea to make the relationship between characters and Unicode values more
explicit in the code in any case, and my patch shouldn't affect the
behavior on any other platforms.

Guido's comment about networking code is quite accurate, but the problem
is social, not technical: there is already networking code that assumes
that 8-bit string literals represent ASCII strings, and there is already
text-processing code that assumes that 8-bit string literals represent
"text" as found in ordinary text files on the platform. There is no
reliable way to make both kinds of code work on a platform whose native
encoding is not ASCII-compatible. In this sense, it is indeed impossible
to port Python 2.x to an EBCDIC platform "completely", so that all
existing code would continue to do "the right thing" without modifications.

However, Py3k presents a fresh start, and one where this particular
problem is gone, since string literals are no longer associated with a
particular encoding, and bytes literals explicitly represent the ASCII
values of the characters in the literal expression. Then text-processing
code will likely use string literals, and it easy to make the default
encoding platform-specific when transferring data between local text
files and string objects. As far as I can see, EBCDIC shouldn't pose any
special problems then.

>From what I read in PEP 3120 and the Py3k docs, there seems to be some
confusion regarding source encoding issues.

Firstly, Python source code is fundamentally _text_. For instance, a
string literal is delimited by single quote or double quote characters.
Characters themselves are abstract entities that have no inherent
numeric values, although we can name them with e.g. Unicode code points,
so we can say that the string delimiters are characters represented by
the code points U+0022 and U+0027.

What PEP 3120 specifies is a mechanism for mapping octet sequences into
these abstract characters. If this is made part of the language
specification, it presumably means that a conformant Py3k source file
must start as UTF-8 at least until an encoding declaration is
encountered. Further, a conformant Py3k implementation must accept such
UTF-8 source files and decode them as specified in the PEP.

So far so good. however, there is nothing to prevent an implementation
from providing (as an extension) a facility to allow _other_ kinds of
source as well. "There is no room for platform-specific derivations" is
an arbitrary restriction: there are certainly quite a number of ways to
support both UTF-8 and CP1047 source on z/OS: for instance, the
filesystem allows storing the encoding of a text file as metadata.

Moreover, there is a semantics-preserving mapping from UTF-8 source
files to CP1047 source files: since non-ASCII characters can only appear
in comments an string literals, and comments have no semantics, it
suffices to \u-escape the exotic characters in string literals. Hence
all Python source can be represented as native text on an EBCDIC
platform.

Of course you can declare that support for such extensions would be
heretical and no EBCDIC source file would be True Python Source and no
EBCDIC implementation would be a True Python Implementation, but I don't
really care. Python 3000 _can_ be ported to z/OS much better than 2.x,
and it probably will, even if you don't like it. Oh the wonders of open
source. :)

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1298>
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1298] Support for z/OS and EBCDIC.

2007-10-22 Thread Lauri Alanko

Lauri Alanko added the comment:

Further comments on the port can be at:
http://mail.python.org/pipermail/python-dev/2007-October/074991.html

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1298>
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1298] Support for z/OS and EBCDIC.

2007-10-19 Thread Lauri Alanko

Lauri Alanko added the comment:

How do you measure importance? Z/OS is not important to many
people in the world, but to those to whom it is important, it is
_very_ important, in a very tangible way. It was certainly
important enough for someone to port Python to it. :)

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1298>
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1298] Support for z/OS and EBCDIC.

2007-10-19 Thread Lauri Alanko

Lauri Alanko added the comment:

The character set of EBCDIC is a superset of the character set of
ASCII. In fact CP1047, the variant used on z/OS, has the same
character set as Latin-1. Only the encoding is completely
different.

As a non-ASCII platform, z/OS is certainly challenging for people
used to modern conventions, and that is exactly why a familiar
and easy-to-use tool like Python is so valuable there. As for
viability, there are some obvious difficulties with Python's
handling of source encodings, but as long as you restrict
yourself to the ASCII _character set_ in your source code, the
vast majority of things seem to work fine with my patch.

There are more details in my mail to python-dev, which doesn't
seem to have appeared yet. I'm not a subscriber, so it's probably
pending moderation somewhere. (I hope "The list address accepts
e-mail from non-members" is still correct information.)

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1298>
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com