1. pygame
  2. Untitled project
  3. pygame

Commits

Lenard Lindstrom  committed 52175e8 Merge

Bring in corrections to assert statements

  • Participants
  • Parent commits 9b8c395, ac4f6f6
  • Branches default

Comments (0)

Files changed (3)

File src/base.c

View file
     internal_p->cobj = 0;
     view_p->internal = internal_p;
     if (PyBUF_HAS_FLAG (flags, PyBUF_FORMAT)) {
-        if (_arraystruct_to_format(internal_p->format, inter_p, 3)) {
+        if (_arraystruct_to_format(internal_p->format,
+                                   inter_p,
+                                   sizeof (internal_p->format))) {
             return -1;
         }
     view_p->format = internal_p->format;
         view_p->format = 0;
     }
     view_p->buf = inter_p->data;
-    if ((flags | PyBUF_WRITABLE) == PyBUF_WRITABLE) {
-        view_p->ndim = 0;
-    }
-    else {
-        view_p->ndim = (Py_ssize_t)inter_p->nd;
-    }
     view_p->itemsize = (Py_ssize_t)inter_p->itemsize;
     view_p->readonly = readonly;
     if (PyBUF_HAS_FLAG (flags, PyBUF_ND)) {
+        view_p->ndim = (Py_ssize_t)inter_p->nd;
         view_p->shape = internal_p->imem;
         for (i = 0; i < view_p->ndim; ++i) {
             view_p->shape[i] = (Py_ssize_t)inter_p->shape[i];
         }
     }
     else if (inter_p->flags & PAI_CONTIGUOUS) {
+        view_p->ndim = 0;
         view_p->shape = 0;
     }
     else {
     if (!PyBUF_HAS_FLAG (flags, PyBUF_FORMAT)) {
         view_p->format = 0;
     }
-    if ((flags | PyBUF_WRITABLE) == PyBUF_WRITABLE) {
+    if (!PyBUF_HAS_FLAG (flags, PyBUF_ND)) {
         view_p->ndim = 0;
     }
     Py_XINCREF (obj);

File src/bufferproxy.c

View file
 #define PROXY_TYPE_NAME "BufferProxy"
 #define PROXY_TYPE_FULLNAME (IMPPREFIX PROXY_TYPE_NAME)
 
+#ifdef NDEBUG
+#define PyBUF_PG_VIEW PyBUF_RECORDS
+#define PyBUF_PG_VIEW_RO PyBUF_RECORDS_RO
+#else
+#define PyBUF_PG_VIEW (PyBUF_RECORDS | PyBUF_PYGAME)
+#define PyBUF_PG_VIEW_RO (PyBUF_RECORDS_RO | PyBUF_PYGAME)
+#endif
+
 typedef struct PgBufproxyObject_s {
     PyObject_HEAD
     PyObject *obj;                             /* Wrapped object (parent)     */
         pg_view_p->consumer = (PyObject *)proxy;
         if (proxy->get_buffer(proxy->obj,
                               (Py_buffer *)pg_view_p,
-                              PyBUF_RECORDS_RO)) {
+                              PyBUF_PG_VIEW_RO)) {
             PyMem_Free(pg_view_p);
             return 0;
         }
         proxy->pg_view_p = pg_view_p;
     }
-    assert(((Py_buffer *)view_p)->len && ((Py_buffer *)view_p)->itemsize);
+    assert(((Py_buffer *)pg_view_p)->len && ((Py_buffer *)pg_view_p)->itemsize);
     return (Py_buffer *)pg_view_p;
 }
 
     }
 #undef ARG_FORMAT
 
-    if (proxy_getbuffer(self, &view, PyBUF_RECORDS)) {
+    if (proxy_getbuffer(self, &view, PyBUF_PG_VIEW)) {
         return 0;
     }
     if (!PyBuffer_IsContiguous(&view, 'A')) {
 {
     Py_buffer *obj_view_p = PyMem_Malloc(sizeof (Pg_buffer));
 
+#ifndef NDEBUG
+    flags |= PyBUF_PYGAME;
+#endif
     view_p->obj = 0;
     if (!obj_view_p) {
         PyErr_NoMemory();

File src/surface.c

View file
     Pg_bufferinternal *internal;
 
     assert (surf);
-    assert (pg_view_p);
+    assert (view_p);
     assert (PyObject_IsInstance (surf, (PyObject *)&PySurface_Type));
     assert (PyBUF_HAS_FLAG (flags, PyBUF_PYGAME));
     consumer = ((Pg_buffer *)view_p)->consumer;