|
Meta tags:
description=Ctypes currently produces wrong pep3118 type codes for several types.
E.g. memoryview(ctypes.c_long()).format gives l on 64-bit platforms,
but it should be q instead for sizeof(c_long) == 8
The problem is that the endian specification in the struct syntax
also turns on the standard size mode, which makes type characters have
a platform-independent meaning, which does not match with the codes used
internally in ctypes. The struct module format syntax also does not
allow specifying native-size non-native-endian items.
This commit adds a converter function that maps the internal ctypes
codes to appropriate struct module standard-size codes in the pep3118
format strings. The tests are modified to check for this.
Example of the current problem in practice:
import numpy, ctypes
numpy.asarray(memoryview(ctypes.c_long(42)))
/usr/lib64/python3.5/site-packages/numpy/core/numeric.py:482: RuntimeWarning: Item size computed from the PEP 3118 buffer format string does not match the actual item size.
return array(a, dtype, copy=False, order=order)
Traceback (most recent call last):
File stdin , line 1, in module
File /usr/lib64/python3.5/site-packages/numpy/core/numeric.py , line 482, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.
struct format string syntax
bpo-10746
htt????/bugs.python.org/issue10746;
Headings (most frequently used words):
for, navigation, uh, oh, bpo, 10746, ctypes, fix, pep, 3118, type, codes, c_long, c_bool, c_int, 31, footer, diff, view, menu, repository, there, are, no, files, selected, viewing, filter, by, extension,
Text of the page (most frequently used words):
pointer (37), file (25), the (23), and (20), pep_code (17), c_short (17), github (16), for (16), #c_long (16), this (15), break (15), case (14), s_long (14), line (12), code (12), type (12), applied (11), ctypes (11), c_int (11), that (10), all (10), format (10), show (9), hidden (9), characters (9), unicode (9), lepoint (9), replace (9), complete (9), c_bool (9), expand (8), result (8), error (8), pep (8), diff (8), bpo (8), 10746 (8), bepoint (8), structwitharrays (8), reload (8), you (7), suggestion (7), cannot (7), suggestions (7), stgdict (7), with (7), codes (7), open (7), c_ulong (7), c_uint (7), sizeof (7), sign (7), while (6), changes (6), null (6), sizeof__bool (6), elif (6), may (6), 3118 (6), number (6), bidirectional (6), _ctypes (6), incomplete (6), c_double (6), c_ulonglong (6), c_longlong (6), security (5), comments (5), has (5), change (5), commit (5), sizeof_int (5), learn (5), about (5), view (5), fix (5), 2017 (5), structure (5), support (5), s_short (5), c_ushort (5), loading (5), your (5), can (4), not (4), please (4), pull (4), one (4), endif (4), proto_str (4), else (4), pyobject (4), sizeof_long (4), char (4), contains (4), what (4), review (4), more (4), next (4), rst (4), aunion (4), emptystruct (4), point2 (4), packedpoint (4), point (4), c_float (4), c_byte (4), c_longdouble (4), s_ulong (4), test (4), there (4), files (4), copilot (4), community (3), navigation (3), request (3), from (3), add (3), batch (3), down (3), _ctypes_alloc_format_string_for_type (3), string (3), unexpected (3), value (3), original (3), text (3), interpreted (3), compiled (3), differently (3), than (3), appears (3), below (3), editor (3), reveals (3), desktop (3), delete (3), edit (3), modules (3), deletions (3), misc (3), news (3), library (3), nmavfu (3), endian (3), machines (3), class (3), s_longdouble (3), s_ulonglong (3), s_longlong (3), s_uint (3), s_int (3), lib (3), test_pep3118 (3), hide (3), whitespace (3), was (3), page (3), nbsp (3), filter (3), commits (3), merged (3), python (3), account (3), quality (3), another (3), tab (3), window (3), refresh (3), session (3), developers (3), changelog (3), customer (3), enterprise (3), grade (3), features (3), build (3), contact (2), status (2), privacy (2), terms (2), footer (2), later (2), been (2), single (2), viewing (2), toggle (2), _ctypes_alloc_format_string (2), getfunc (2), fmt (2), setfunc (2), non (2), into (2), returns (2), failure (2), allocate (2), memory (2), block (2), pep3118 (2), return (2), big_endian (2), standard (2), size (2), 249 (2), additions (2), types (2), little (2), arrays (2), unions (2), structures (2), pointers (2), py_object (2), s_bool (2), alias (2), none (2), are (2), aliases (2), s_ushort (2), c_ubyte (2), c_char (2), s_double (2), platform (2), 112 (2), selected (2), apply (2), split (2), unified (2), failed (2), load (2), retry (2), jump (2), extension (2), tree (2), issue (2), insights (2), projects (2), actions (2), repository (2), cpython (2), signed (2), universe (2), training (2), integrations (2), stories (2), center (2), documentation (2), business (2), fixes (2), products (2), secret (2), perform, action, time, share, personal, information, manage, cookies, docs, 2026, inc, right, now, check, back, queued, merge, multi, pending, reviews, marked, resolved, outdated, must, existing, order, create, valid, applying, deleted, lines, supported, only, per, subset, closed, invalid, because, were, made, annotations, notes, py_decref, ifdef, words_bigendian, 1930, 1995, pycsimpletype_new, pytypeobject, args, kwds, suffix, copy, prefix, pymem_malloc, same, default, switch, int, static, since, endianness, need, swapped, native, produces, mode, struct, module, indicator, set, suitable, corresponding, given, filled, pydict_getitemproxy, dict, key, producing, wrong, integer, addition, __name__, __main__, endian_types, 196, 223, littleendianstructure, unfortunately, fixed, created, starts, but, completed, after, sub, does, packed, implement, bit, platforms, 120, 148, shape, calc, itemsize, native_types, definitions, __init__, s_float, specific, replaces, big, table, strings, they, look, conversations, clear, filters, viewed, feb, 4cb7409, select, changed, checks, conversation, aug, master, pitrou, already, clicking, agree, our, occasionally, send, related, emails, statement, service, free, its, maintainers, have, question, project, new, items, requests, issues, message, dismiss, alert, switched, accounts, out, appearance, settings, search, pricing, event, talks, workshops, partners, company, forum, events, webinars, blog, resource, connect, resources, premium, advanced, ons, trust, why, evaluate, see, industries, government, manufacturing, financial, services, healthcare, industry, nonprofits, startups, team, enterprises, stage, businesses, source, latest, improvements, across, place, developer, articles, sponsors, trending, repos, explore, customize, certifications, scanning, leak, prevention, protection, vulnerability, detection, remediation, secure, cloud, development, environments, codespaces, analysis, enforcement, automation, ship, coding, agent, tasks, automated, work, hosting, collaboration, menu, skip, content,
|