Skip to content

Commit 253270a

Browse files
Merge pull request #1973 from KLayout/feature/issue-1971
Feature/issue 1971
2 parents b4dc9a6 + a75eca5 commit 253270a

File tree

8 files changed

+95
-28
lines changed

8 files changed

+95
-28
lines changed

src/gsi/gsi/gsiDeclTl.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ Class<Logger> decl_Logger ("tl", "Logger",
105105
"Level 0 is silent, levels 10, 20, 30 etc. denote levels with increasing verbosity. "
106106
"11, 21, 31 .. are sublevels which also enable timing logs in addition to messages."
107107
) +
108-
gsi::method ("verbosity=", &Logger::set_verbosity, gsi::arg ("v"),
108+
gsi::method ("verbosity=|set_verbosity", &Logger::set_verbosity, gsi::arg ("v"),
109109
"@brief Sets the verbosity level for the application\n"
110110
"\n"
111111
"See \\verbosity for a definition of the verbosity levels. Please note that this method "
112112
"changes the verbosity level for the whole application.\n"
113+
"\n"
114+
"The 'set_verbosity' alias has been introduced in version 0.29.11 as class attributes "
115+
"are not always available in Python."
113116
),
114117
"@brief A logger\n"
115118
"\n"

src/gsi/gsi_test/gsiTest.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,18 @@ A *A::a20_get ()
375375
return a_inst.get ();
376376
}
377377

378+
static int s_sp = 0;
379+
380+
int A::sp_i_get ()
381+
{
382+
return s_sp;
383+
}
384+
385+
void A::sp_i_set (int v)
386+
{
387+
s_sp = v + 1;
388+
}
389+
378390
// ----------------------------------------------------------------
379391
// Implementation of B
380392

@@ -1253,6 +1265,8 @@ static gsi::Class<A> decl_a ("", "A",
12531265
gsi::method ("a9b", &A::a9b) +
12541266
gsi::method ("a20", &A::a20) +
12551267
gsi::method ("a20_get", &A::a20_get) +
1268+
gsi::method ("sp_i", &A::sp_i_get) +
1269+
gsi::method ("sp_i=", &A::sp_i_set) +
12561270
gsi::method ("to_s", &A::to_s) +
12571271
gsi::iterator ("a6", &A::a6b, &A::a6e) +
12581272
gsi::iterator ("a7", &A::a7b, &A::a7e) +

src/gsi/gsi_test/gsiTest.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ struct A
415415

416416
std::string to_s () const;
417417

418+
// static (class) properties
419+
static int sp_i_get ();
420+
static void sp_i_set (int v);
421+
418422
// members
419423
std::vector<double> m_d;
420424
int n;

src/pya/pya/pyaCallables.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,14 @@ property_setter_impl (int mid, PyObject *self, PyObject *value)
12851285

12861286
meth->call (obj, arglist, retlist);
12871287

1288-
return get_return_value (p, retlist, meth, heap);
1288+
PyObject *ret = get_return_value (p, retlist, meth, heap);
1289+
1290+
if (ret == NULL) {
1291+
Py_INCREF (Py_None);
1292+
ret = Py_None;
1293+
}
1294+
1295+
return ret;
12891296

12901297
}
12911298
}

src/pya/pya/pyaModule.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,23 @@ class PythonClassGenerator
426426
doc += "\n\n";
427427
}
428428
doc += (*m)->doc ();
429-
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a readable attribute '%s'. This is the getter")), name));
429+
if (! is_static) {
430+
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a readable attribute '%s'. This is the getter")), name));
431+
} else {
432+
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The class exposes a readable attribute '%s'. This is the getter")), name));
433+
}
430434
}
431435

432436
for (MethodTableEntry::method_iterator m = begin_setters; m != end_setters; ++m) {
433437
if (! doc.empty ()) {
434438
doc += "\n\n";
435439
}
436440
doc += (*m)->doc ();
437-
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a writable attribute '%s'. This is the setter")), name));
441+
if (! is_static) {
442+
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a writable attribute '%s'. This is the setter")), name));
443+
} else {
444+
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The class exposes a writable attribute '%s'. This setter may not be available in Python")), name));
445+
}
438446
}
439447

440448
PythonRef attr;

src/tl/tl/tlLog.cc

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -392,34 +392,42 @@ WarningChannel::~WarningChannel ()
392392
void
393393
WarningChannel::puts (const char *s)
394394
{
395-
fputs (s, stdout);
395+
if (verbosity () >= 0) {
396+
fputs (s, stdout);
397+
}
396398
}
397399

398400
void
399401
WarningChannel::endl ()
400402
{
401-
fputs ("\n", stdout);
402-
m_new_line = true;
403+
if (verbosity () >= 0) {
404+
fputs ("\n", stdout);
405+
m_new_line = true;
406+
}
403407
}
404408

405409
void
406410
WarningChannel::end ()
407411
{
408-
if (m_colorized) {
409-
fputs (ANSI_RESET, stdout);
412+
if (verbosity () >= 0) {
413+
if (m_colorized) {
414+
fputs (ANSI_RESET, stdout);
415+
}
416+
fflush (stdout);
410417
}
411-
fflush (stdout);
412418
}
413419

414420
void
415421
WarningChannel::begin ()
416422
{
417-
if (m_colorized) {
418-
fputs (ANSI_BLUE, stdout);
419-
}
420-
if (m_new_line) {
421-
fputs ("Warning: ", stdout);
422-
m_new_line = false;
423+
if (verbosity () >= 0) {
424+
if (m_colorized) {
425+
fputs (ANSI_BLUE, stdout);
426+
}
427+
if (m_new_line) {
428+
fputs ("Warning: ", stdout);
429+
m_new_line = false;
430+
}
423431
}
424432
}
425433

@@ -463,34 +471,42 @@ ErrorChannel::~ErrorChannel ()
463471
void
464472
ErrorChannel::puts (const char *s)
465473
{
466-
fputs (s, stderr);
474+
if (verbosity () >= -10) {
475+
fputs (s, stderr);
476+
}
467477
}
468478

469479
void
470480
ErrorChannel::endl ()
471481
{
472-
fputs ("\n", stderr);
473-
m_new_line = true;
482+
if (verbosity () >= -10) {
483+
fputs ("\n", stderr);
484+
m_new_line = true;
485+
}
474486
}
475487

476488
void
477489
ErrorChannel::end ()
478490
{
479-
if (m_colorized) {
480-
fputs (ANSI_RESET, stderr);
491+
if (verbosity () >= -10) {
492+
if (m_colorized) {
493+
fputs (ANSI_RESET, stderr);
494+
}
495+
fflush (stderr);
481496
}
482-
fflush (stderr);
483497
}
484498

485499
void
486500
ErrorChannel::begin ()
487501
{
488-
if (m_colorized) {
489-
fputs (ANSI_RED, stderr);
490-
}
491-
if (m_new_line) {
492-
fputs ("ERROR: ", stderr);
493-
m_new_line = false;
502+
if (verbosity () >= -10) {
503+
if (m_colorized) {
504+
fputs (ANSI_RED, stderr);
505+
}
506+
if (m_new_line) {
507+
fputs ("ERROR: ", stderr);
508+
m_new_line = false;
509+
}
494510
}
495511
}
496512

testdata/python/basic.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ class BasicTest(unittest.TestCase):
149149

150150
def test_00(self):
151151

152+
# does not work with all Python versions
153+
# (debugging shows that Python calls the setter on the metaclass,
154+
# not on the class itself at least on 3.12)
155+
# # static (class) properties
156+
# pya.A.sp_i = 17
157+
# self.assertEqual(pya.A.sp_i, 18)
158+
# pya.A.sp_i = -1
159+
# self.assertEqual(pya.A.sp_i, 0)
160+
152161
# all references of PA are released now:
153162
ic0 = pya.A.instance_count()
154163

testdata/ruby/basic_testcore.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def test_FIRST
2424
# for testing the ut logger:
2525
puts "Special chars: <&>"
2626

27+
# static (class) properties
28+
RBA::A.sp_i = 17
29+
assert_equal( RBA::A.sp_i, 18 )
30+
RBA::A.sp_i = -1
31+
assert_equal( RBA::A.sp_i, 0 )
32+
2733
GC.start
2834

2935
# all references of A are released now:

0 commit comments

Comments
 (0)