From 0adad7743a211efe8a95a2ee8eb923aa8d198588 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 7 Jun 2018 22:54:01 -0400 Subject: [PATCH] Drop mixing of C and C++ class allocations, including placement new. This is the easiest change I can make to the Windows table code for now... --- windows/table.cpp | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/windows/table.cpp b/windows/table.cpp index c5dc9ef3..db070f44 100644 --- a/windows/table.cpp +++ b/windows/table.cpp @@ -2,7 +2,7 @@ struct uiTableModel { uiTableModelHandler *mh; - std::vector tables; + std::vector *tables; }; struct uiTableColumn { @@ -16,31 +16,23 @@ struct uiTable { uiWindowsControl c; uiTableModel *model; HWND hwnd; - std::vector columns; + std::vector *columns; }; -void *uiTableModelStrdup(const char *str) -{ - return strdup(str); -} - -void *uiTableModelGiveColor(double r, double g, double b, double a) -{ - return 0; // not implemented -} - uiTableModel *uiNewTableModel(uiTableModelHandler *mh) { uiTableModel *m; - m = new uiTableModel(); + m = uiprivNew(uiTableModel); m->mh = mh; + m->tables = new std::vector; return m; } void uiFreeTableModel(uiTableModel *m) { - delete m; + delete m->tables; + uiprivFree(m); } void uiTableModelRowInserted(uiTableModel *m, int newIndex) @@ -51,21 +43,21 @@ void uiTableModelRowInserted(uiTableModel *m, int newIndex) item.mask = 0; item.iItem = newIndex; item.iSubItem = 0; - for (auto t : m->tables) + for (auto t : *(m->tables)) if (SendMessageW(t->hwnd, LVM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1)) logLastError(L"error calling LVM_INSERTITEM in uiTableModelRowInserted()"); } void uiTableModelRowChanged(uiTableModel *m, int index) { - for (auto t : m->tables) + for (auto t : *(m->tables)) if (SendMessageW(t->hwnd, LVM_UPDATE, (WPARAM) index, 0) == (LRESULT) (-1)) logLastError(L"error calling LVM_UPDATE in uiTableModelRowChanged()"); } void uiTableModelRowDeleted(uiTableModel *m, int oldIndex) { - for (auto t : m->tables) + for (auto t : *(m->tables)) if (SendMessageW(t->hwnd, LVM_DELETEITEM, (WPARAM) oldIndex, 0) == (LRESULT) (-1)) logLastError(L"error calling LVM_DELETEITEM in uiTableModelRowDeleted()"); } @@ -81,7 +73,7 @@ void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand) c->modelColumn = modelColumn; // work out appropriate listview index for the column - for (auto candidate : t->columns) { + for (auto candidate : *(t->columns)) { if (candidate == c) break; if (candidate->modelColumn >= 0) @@ -140,7 +132,7 @@ uiTableColumn *uiTableAppendColumn(uiTable *t, const char *name) c->t = t; c->modelColumn = -1; // -1 = unassigned // we defer the actual ListView_InsertColumn call until a part is added... - t->columns.push_back(c); + t->columns->push_back(c); return c; } @@ -165,11 +157,11 @@ static void uiTableDestroy(uiControl *c) } } // free the columns - for (auto col : t->columns) { + for (auto col : *(t->columns)) { uiprivFree(col->name); uiprivFree(col); } - t->columns.~vector(); // (created with placement new, so just call dtor directly) + delete t->columns; uiFreeControl(uiControl(t)); } @@ -217,9 +209,9 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult) break; row = item->iItem; col = item->iSubItem; - if (col < 0 || col >= (int)t->columns.size()) + if (col < 0 || col >= (int)t->columns->size()) break; - tc = (uiTableColumn *)t->columns[col]; + tc = (uiTableColumn *)t->columns->at(col); mcol = tc->modelColumn; typ = (*mh->ColumnType)(mh, t->model, mcol); @@ -247,7 +239,8 @@ uiTable *uiNewTable(uiTableModel *model) int n; uiWindowsNewControl(uiTable, t); - new(&t->columns) std::vector(); // (initialising in place) + + t->columns = new std::vector; t->model = model; t->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, WC_LISTVIEW, L"",