Mercurial > cpython-lru_cache-weakref
annotate Include/memoryobject.h @ 73323:dad02a080bbc
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run
under python -O, some paths for pyc files would be pyo, because I called
imp.cache_from_source without explicit debug_override argument in some
places, and under -O that would return .pyo (this is well explained in
the imp docs). Now all code (util.byte_compile, build_py, install_lib)
can create .pyo files according to options given by users,
without interference from the calling Python’s own optimize mode.
On a related topic, I also removed the code that prevented byte
compilation under python -B. The rationale is that packaging gives
control over the creation of pyc files to the user with its own explicit
option, and the behavior should not be changed if the calling Python
happens to run with -B for whatever reason. I will argue that this is a
bug fix and ask to be allowed to backport this change to distutils.
Finally, I moved one nugget of information about the --compile and
--optimize options from the source into the doc. It clears up a
misunderstanding that I (and maybe other people) had.
| author | Éric Araujo <merwok@netwok.org> |
|---|---|
| date | Thu, 03 Nov 2011 05:08:28 +0100 |
| parents | 8a302a09ee83 |
| children | 215690b782f8 |
| rev | line source |
|---|---|
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
1 /* Memory view object. In Python this is available as "memoryview". */ |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
2 |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
3 #ifndef Py_MEMORYOBJECT_H |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
4 #define Py_MEMORYOBJECT_H |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
5 #ifdef __cplusplus |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
6 extern "C" { |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
7 #endif |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
8 |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
9 PyAPI_DATA(PyTypeObject) PyMemoryView_Type; |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
10 |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
11 #define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
12 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65944
diff
changeset
|
13 #ifndef Py_LIMITED_API |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
14 /* Get a pointer to the underlying Py_buffer of a memoryview object. */ |
|
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
15 #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) |
|
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
16 /* Get a pointer to the PyObject from which originates a memoryview object. */ |
|
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
17 #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj) |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65944
diff
changeset
|
18 #endif |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
19 |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
20 |
|
43550
4ea945cbbb6d
Fix problems with memoryview object. There is still more to do to finish PEP 3118. The memory-view object needs to be fleshed out and the struct module needs to be modified.
Travis E. Oliphant <oliphant@enthought.com>
parents:
43423
diff
changeset
|
21 PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, |
|
4ea945cbbb6d
Fix problems with memoryview object. There is still more to do to finish PEP 3118. The memory-view object needs to be fleshed out and the struct module needs to be modified.
Travis E. Oliphant <oliphant@enthought.com>
parents:
43423
diff
changeset
|
22 int buffertype, |
|
4ea945cbbb6d
Fix problems with memoryview object. There is still more to do to finish PEP 3118. The memory-view object needs to be fleshed out and the struct module needs to be modified.
Travis E. Oliphant <oliphant@enthought.com>
parents:
43423
diff
changeset
|
23 char fort); |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
24 |
|
50501
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
25 /* Return a contiguous chunk of memory representing the buffer |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
26 from an object in a memory view object. If a copy is made then the |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
27 base object for the memory view will be a *new* bytes object. |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
28 |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
29 Otherwise, the base-object will be the object itself and no |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
30 data-copying will be done. |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
31 |
|
50501
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
32 The buffertype argument can be PyBUF_READ, PyBUF_WRITE, |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
33 PyBUF_SHADOW to determine whether the returned buffer |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
34 should be READONLY, WRITABLE, or set to update the |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
35 original buffer if a copy must be made. If buffertype is |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
36 PyBUF_WRITE and the buffer is not contiguous an error will |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
37 be raised. In this circumstance, the user can use |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
38 PyBUF_SHADOW to ensure that a a writable temporary |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
39 contiguous buffer is returned. The contents of this |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
40 contiguous buffer will be copied back into the original |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
41 object after the memoryview object is deleted as long as |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
42 the original object is writable and allows setting an |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
43 exclusive write lock. If this is not allowed by the |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
44 original object, then a BufferError is raised. |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
45 |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
46 If the object is multi-dimensional and if fortran is 'F', |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
47 the first dimension of the underlying array will vary the |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
48 fastest in the buffer. If fortran is 'C', then the last |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
49 dimension will vary the fastest (C-style contiguous). If |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
50 fortran is 'A', then it does not matter and you will get |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
51 whatever the object decides is more efficient. |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
52 |
|
50501
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
53 A new reference is returned that must be DECREF'd when finished. |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
54 */ |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
55 |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
56 PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
57 |
|
67419
8a302a09ee83
Remove buffer API from stable ABI for now, see #10181.
Martin v. Löwis <martin@v.loewis.de>
parents:
66664
diff
changeset
|
58 #ifndef Py_LIMITED_API |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
59 PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); |
|
50501
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
60 /* create new if bufptr is NULL |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
61 will be a new bytesobject in base */ |
|
67419
8a302a09ee83
Remove buffer API from stable ABI for now, see #10181.
Martin v. Löwis <martin@v.loewis.de>
parents:
66664
diff
changeset
|
62 #endif |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
63 |
|
50501
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
64 |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
65 /* The struct is declared here so that macros can work, but it shouldn't |
|
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
66 be considered public. Don't access those fields directly, use the macros |
|
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
67 and functions instead! */ |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65944
diff
changeset
|
68 #ifndef Py_LIMITED_API |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
69 typedef struct { |
|
50501
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
70 PyObject_HEAD |
|
de2771070d85
Merged revisions 68212 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
48770
diff
changeset
|
71 Py_buffer view; |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
72 } PyMemoryViewObject; |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65944
diff
changeset
|
73 #endif |
|
48770
7511f3e672a2
#3560: cleanup C memoryview API
Antoine Pitrou <solipsis@pitrou.net>
parents:
44351
diff
changeset
|
74 |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
75 #ifdef __cplusplus |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
76 } |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
77 #endif |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
diff
changeset
|
78 #endif /* !Py_MEMORYOBJECT_H */ |
