Merge pull request #546 from KLayout/sonarqube-fixes

Sonarqube fixes
This commit is contained in:
Matthias Köfferlein 2020-04-30 22:06:38 +02:00 committed by GitHub
commit cb3833f563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 108 additions and 49 deletions

View File

@ -331,6 +331,7 @@ BD_PUBLIC int strmxor (int argc, char *argv[])
xor_data.threads = threads;
xor_data.tile_size = tile_size;
xor_data.output_layout = output_layout.get ();
xor_data.output_cell = output_top;
xor_data.l2l_map = l2l_map;
xor_data.results = &results;

View File

@ -427,6 +427,9 @@ struct PathCompareOpWithTolerance
db::Path::iterator ia = a.begin (), ib = b.begin ();
while (ia != a.end () && ib != b.end ()) {
c = compare_point (*ia, *ib, m_tolerance);
if (c != 0) {
return c < 0;
}
++ia;
++ib;
}

View File

@ -358,8 +358,10 @@ void LayoutToNetlistStandardReader::read_netlist (db::Netlist *netlist, db::Layo
dm->set_name (name);
netlist->add_device_abstract (dm);
db::cell_index_type ci = l2n->internal_layout ()->add_cell (name.c_str ());
dm->set_cell_index (ci);
if (l2n) {
db::cell_index_type ci = l2n->internal_layout ()->add_cell (name.c_str ());
dm->set_cell_index (ci);
}
std::string cls;
read_word_or_quoted (cls);

View File

@ -90,6 +90,7 @@ LibraryManager::delete_lib (Library *library)
library->remap_to (0);
delete library;
m_libs [id] = 0;
break;
}
}
}

View File

@ -0,0 +1,24 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2020 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dbPlugin.h"

View File

@ -132,4 +132,5 @@ Class<db::Manager> decl_Manager ("db", "Manager",
"This class has been introduced in version 0.19.\n"
);
}
}

View File

@ -1,3 +1,4 @@
/*
KLayout Layout Viewer

View File

@ -1300,15 +1300,17 @@ TEST(6)
EXPECT_EQ (r.text (),
"layout_diff: paths differ for layer 17/0 in cell c2x\n"
"Not in b but in a:\n"
" (1,2;11,12) w=17 bx=0 ex=0 r=false\n"
"Not in a but in b:\n"
" (1,2;11,12) w=17 bx=0 ex=0 r=true\n"
" (1,2;11,12) w=17 bx=0 ex=-1 r=false\n"
" (1,3;11,11) w=17 bx=0 ex=0 r=false\n"
" (1,3;11,12) w=17 bx=0 ex=0 r=false\n"
" (1,2;11,12) w=17 bx=1 ex=0 r=false\n"
" (1,2;11,12) w=18 bx=0 ex=0 r=false\n"
);
// two more to match more of h:
// some more to match more of h:
g.cell (c2i).shapes (0).insert (p);
g.cell (c2i).shapes (0).insert (p);
g.cell (c2i).shapes (0).insert (p);

View File

@ -618,21 +618,21 @@ public:
size_t n = data_length ();
for (unsigned int i = 0; i < 3; ++i) {
if (mp_color_data[i]) {
stat->add (typeid (float []), (void *) mp_color_data[i], sizeof (n * sizeof (float)), sizeof (n * sizeof (float)), (void *) this, purpose, cat);
stat->add (typeid (float []), (void *) mp_color_data[i], n * sizeof (float), n * sizeof (float), (void *) this, purpose, cat);
}
if (mp_color_byte_data[i]) {
stat->add (typeid (unsigned char []), (void *) mp_color_byte_data[i], sizeof (n * sizeof (unsigned char)), sizeof (n * sizeof (unsigned char)), (void *) this, purpose, cat);
stat->add (typeid (unsigned char []), (void *) mp_color_byte_data[i], n * sizeof (unsigned char), n * sizeof (unsigned char), (void *) this, purpose, cat);
}
}
if (mp_mask) {
stat->add (typeid (unsigned char []), (void *) mp_mask, sizeof (n * sizeof (unsigned char)), sizeof (n * sizeof (unsigned char)), (void *) this, purpose, cat);
stat->add (typeid (unsigned char []), (void *) mp_mask, n * sizeof (unsigned char), n * sizeof (unsigned char), (void *) this, purpose, cat);
}
if (mp_data) {
stat->add (typeid (float []), (void *) mp_data, sizeof (n * sizeof (float)), sizeof (n * sizeof (float)), (void *) this, purpose, cat);
stat->add (typeid (float []), (void *) mp_data, n * sizeof (float), n * sizeof (float), (void *) this, purpose, cat);
}
if (mp_byte_data) {
stat->add (typeid (unsigned char []), (void *) mp_byte_data, sizeof (n * sizeof (unsigned char)), sizeof (n * sizeof (unsigned char)), (void *) this, purpose, cat);
stat->add (typeid (unsigned char []), (void *) mp_byte_data, n * sizeof (unsigned char), n * sizeof (unsigned char), (void *) this, purpose, cat);
}
}

View File

@ -46,7 +46,7 @@ public:
MacroTreeModel (QObject *parent, lay::MacroEditorDialog *dialog, lym::MacroCollection *root, const std::string &cat);
MacroTreeModel (QWidget *parent, lym::MacroCollection *root, const std::string &cat);
int columnCount (const QModelIndex &parent) const;
int columnCount (const QModelIndex &parent) const;
QVariant data (const QModelIndex &index, int role) const;
Qt::ItemFlags flags (const QModelIndex &index) const;
bool hasChildren (const QModelIndex &parent) const;

View File

@ -142,7 +142,7 @@ SearchReplaceResults::size () const
return std::max (std::max (m_cell_result.size (), m_data_result.size ()), std::max (m_shape_result.size (), m_inst_result.size ())) + (m_has_more ? 1 : 0);
}
int
int
SearchReplaceResults::columnCount (const QModelIndex & /*parent*/) const
{
// Note: keep last column count for empty model to avoid resize events for the header
@ -396,7 +396,7 @@ SearchReplaceResults::data (const QModelIndex &index, int role) const
return QVariant ();
}
Qt::ItemFlags
Qt::ItemFlags
SearchReplaceResults::flags (const QModelIndex & /*index*/) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
@ -414,7 +414,7 @@ SearchReplaceResults::hasIndex (int row, int /*column*/, const QModelIndex &pare
return ! parent.isValid () && row < int (size ());
}
QModelIndex
QModelIndex
SearchReplaceResults::index (int row, int column, const QModelIndex &parent) const
{
if (! parent.isValid ()) {
@ -424,13 +424,13 @@ SearchReplaceResults::index (int row, int column, const QModelIndex &parent) con
}
}
QModelIndex
QModelIndex
SearchReplaceResults::parent (const QModelIndex & /*index*/) const
{
return QModelIndex ();
}
int
int
SearchReplaceResults::rowCount (const QModelIndex &parent) const
{
return parent.isValid () ? 0 : int (size ());
@ -455,7 +455,7 @@ escape_csv (const std::string &s)
}
}
void
void
SearchReplaceResults::export_csv (const std::string &file)
{
std::ofstream output (file.c_str ());
@ -488,7 +488,7 @@ SearchReplaceResults::export_csv (const std::string &file)
}
}
void
void
SearchReplaceResults::export_layout (db::Layout &layout)
{
if (! m_data_result.empty () || ! m_cell_result.empty () || ! m_inst_result.empty ()) {
@ -520,7 +520,7 @@ SearchReplaceResults::export_layout (db::Layout &layout)
}
}
void
void
SearchReplaceResults::export_rdb (rdb::Database &rdb, double dbu)
{
if (! m_cell_result.empty ()) {

View File

@ -120,15 +120,15 @@ public:
return m_cell_result;
}
int columnCount (const QModelIndex &parent) const;
int columnCount (const QModelIndex &parent) const;
QVariant data (const QModelIndex &index, int role) const;
Qt::ItemFlags flags (const QModelIndex &index) const;
Qt::ItemFlags flags (const QModelIndex &index) const;
bool hasChildren (const QModelIndex &parent) const;
bool hasIndex (int row, int column, const QModelIndex &parent) const;
QVariant headerData (int section, Qt::Orientation orientation, int role) const;
QModelIndex index (int row, int column, const QModelIndex &parent) const;
QModelIndex parent (const QModelIndex &index) const;
int rowCount (const QModelIndex &parent) const;
QModelIndex index (int row, int column, const QModelIndex &parent) const;
QModelIndex parent (const QModelIndex &index) const;
int rowCount (const QModelIndex &parent) const;
void has_more (bool hm);
void export_csv (const std::string &file);

View File

@ -1675,7 +1675,6 @@ LayoutView::enable_edits (bool enable)
if (m_disabled_edits > 0) {
--m_disabled_edits;
}
enable = (m_disabled_edits == 0);
} else {
++m_disabled_edits;
}

View File

@ -1131,11 +1131,10 @@ LayoutViewConfigPage6::stipple_button_clicked ()
if (m_palette.stipples () > i) {
unsigned int s = m_palette.stipple_by_index (i);
SelectStippleForm stipples_form (0, m_pattern);
if (stipples_form.exec () && stipples_form.selected () >= 0) {
s = stipples_form.selected ();
unsigned int s = stipples_form.selected ();
m_manager.transaction (tl::to_string (QObject::tr ("Set stipple")));
m_manager.queue (this, new StipplePaletteOp (m_palette, false, true /*before*/));
@ -1350,11 +1349,10 @@ LayoutViewConfigPage6a::line_style_button_clicked ()
if (m_palette.styles () > i) {
unsigned int s = m_palette.style_by_index (i);
SelectLineStyleForm styles_form (0, m_style);
if (styles_form.exec () && styles_form.selected () >= 0) {
s = styles_form.selected ();
unsigned int s = styles_form.selected ();
m_manager.transaction (tl::to_string (QObject::tr ("Set style")));
m_manager.queue (this, new LineStylePaletteOp (m_palette, true /*before*/));

View File

@ -1406,7 +1406,6 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
std::string layer;
int flags = 0;
double width1 = 0.0, width2 = 0.0;
unsigned int got_width = 0;
double common_width1 = 0.0, common_width2 = 0.0;
unsigned int common_width_set = 0;
double ex = 0.0, ey = 0.0, ez = 1.0;
@ -1417,6 +1416,7 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
unsigned int xy_flags = 0;
double x = 0.0, y = 0.0;
unsigned int got_width = 0;
while ((g = read_group_code ()) != 0) {
@ -1445,7 +1445,6 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
if (got_width == 3) {
widths.push_back (std::make_pair (seg_start, width1));
widths.push_back (std::make_pair (points.size () - 1, width2));
got_width = 0;
}
got_width = 0;
@ -1516,7 +1515,7 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
const std::string &e = read_string (true);
if (e == "VERTEX") {
got_width = 0;
unsigned int got_width = 0;
double x = 0.0, y = 0.0;
double bnew = 0.0;
@ -1551,7 +1550,6 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
if (got_width == 3) {
widths.push_back (std::make_pair (seg_start, width1));
widths.push_back (std::make_pair (points.size () - 1, width2));
got_width = 0;
}
} else if (e == "SEQEND") {
@ -2303,7 +2301,6 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
// close previous loop if necessary
finish_loop (loop_start, iedges.size (), iedges);
loop_start = iedges.size ();
// create the polygons
std::pair <bool, unsigned int> ll = open_layer (layout, layer);

View File

@ -383,4 +383,5 @@ gsi::ClassExt<db::SaveLayoutOptions> dxf_writer_options (
""
);
}
}

View File

@ -292,4 +292,5 @@ gsi::ClassExt<db::SaveLayoutOptions> oasis_writer_options (
""
);
}
}

View File

@ -1,3 +1,4 @@
/*
KLayout Layout Viewer

View File

@ -526,7 +526,7 @@ PyObject *c2python_func<const char *>::operator() (const char *p)
#if PY_MAJOR_VERSION < 3
return PyString_FromString (s);
#else
PyObject *ret = PyUnicode_DecodeUTF8 (p, strlen (p), NULL);
PyObject *ret = PyUnicode_DecodeUTF8 (s, strlen (s), NULL);
if (ret == NULL) {
check_error ();
}

View File

@ -114,7 +114,7 @@ PYAChannelObject::make_class (PyObject *module)
{"write", (PyCFunction) &pya_channel_write, METH_VARARGS, "internal stdout/stderr redirection object: write method" },
{"flush", (PyCFunction) &pya_channel_flush, METH_VARARGS, "internal stdout/stderr redirection object: flush method" },
{"isatty", (PyCFunction) &pya_channel_isatty, METH_VARARGS, "internal stdout/stderr redirection object: isatty method" },
{NULL, NULL},
{NULL, NULL},
};
channel_type.tp_flags = Py_TPFLAGS_DEFAULT;
@ -630,7 +630,7 @@ PYASignal::make_class (PyObject *module)
{"remove", (PyCFunction) &pya_signal_remove, METH_VARARGS, "internal signal proxy object: -= operator" },
{"set", (PyCFunction) &pya_signal_set, METH_VARARGS, "internal signal proxy object: assignment" },
{"clear", (PyCFunction) &pya_signal_clear, METH_NOARGS, "internal signal proxy object: clears all receivers" },
{NULL, NULL},
{NULL, NULL},
};
static PyNumberMethods nm = { };

View File

@ -1930,6 +1930,7 @@ property_getter_impl (int mid, PyObject *self)
// a signal getter is implemented as returning a proxy object for the signal which allows manipulation
// of the signal
tl_assert (p != 0); // no static signals
return PYASignal::create (self, p->signal_handler (meth));
} else {

View File

@ -104,10 +104,10 @@ class _PCellDeclarationHelper(PCellDeclaration):
pdecl.unit = unit
if not (choices is None):
if not isinstance(choices, list) and not isinstance(choices, tuple):
raise "choices value must be an list/tuple of two-element arrays (description, value)"
raise Exception("choices value must be an list/tuple of two-element arrays (description, value)")
for c in choices:
if (not isinstance(choices, list) and not isinstance(choices, tuple)) or len(c) != 2:
raise "choices value must be an list/tuple of two-element arrays (description, value)"
raise Exception("choices value must be an list/tuple of two-element arrays (description, value)")
pdecl.add_choice(c[0], c[1])
# return the declaration object for further operations

View File

@ -245,7 +245,7 @@ namespace tl
}
template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
typename _Compare>
typename _Compare>
void
__push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __topIndex, const _Tp &__v, _Compare __comp)
@ -311,7 +311,7 @@ namespace tl
}
template<typename _RandomAccessIterator, typename _Distance,
typename _Tp, typename _Compare>
typename _Tp, typename _Compare>
void
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, const _Tp &__v, _Compare __comp)
@ -476,7 +476,7 @@ namespace tl
}
--__depth_limit;
_RandomAccessIter __cut =
tl::__unguarded_partition(__first, __last,
tl::__unguarded_partition(__first, __last,
_ValueType(tl::__median(*__first,
*(__first + (__last - __first)/2),
*(__last - 1), __comp)),

View File

@ -38,7 +38,9 @@ namespace tl
TL_PUBLIC NO_RETURN void assertion_failed (const char *filename, unsigned int line, const char *condition);
// the throw int(0) instruction will tell the compiler that the assertion will not return
#define tl_assert(COND) if (!(COND)) { tl::assertion_failed (__FILE__, __LINE__, #COND); }
#define tl_assert(COND) if (!(COND)) { \
tl::assertion_failed (__FILE__, __LINE__, #COND); \
}
} // namespace tl

View File

@ -1731,10 +1731,10 @@ std::string format_sci_stlport_fix (double f, int prec, unsigned int flags)
std::string res;
res.reserve (os.str ().size ());
for (const char *cp = os.str ().c_str (); *cp; ++cp) {
if (*cp == '0' && (cp[1] == 'e' || cp[1] == 'E')) {
++cp;
}
res += *cp;
if (*cp == '0' && (cp[1] == 'e' || cp[1] == 'E')) {
++cp;
}
res += *cp;
}
return res;
};
@ -1841,7 +1841,7 @@ sprintf (const char *f, const std::vector <tl::Variant> &vv, unsigned int a0)
}
if (a < vv.size ()) {
#if defined(_STLPORT_VERSION) && _STLPORT_VERSION == 0x521 && defined(_MSC_VER)
os << format_sci_stlport_fix (vv [a].to_double (), os.precision (), os.flags ()).c_str ();
os << format_sci_stlport_fix (vv [a].to_double (), os.precision (), os.flags ()).c_str ();
#else
os << vv [a].to_double ();
#endif

View File

@ -0,0 +1,24 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2020 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "tlVector.h"