I have several wxFlexGridSizers that used to work in wxWigets version 2.8.11. After upgrading the wxWidgets library to 2.9.4 I am now getting an invalid column index in wxFlexGridSizer::AddGrowableCol().
Here is a sample of the sizer that I am creating:
wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 3, 2, 0, 0 );
fgSizer1->AddGrowableCol( 2 );
fgSizer1->SetFlexibleDirection( wxBOTH );
fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
I tried changing the value of the AddGrowableCol() arguement to 1 because maybe I thought it might have been wrong before or something but it still throws the same error. I can include the stacktrace if that would be helpful as well.
..\..\src\common\sizer.cpp(1956): assert "!m_cols || idx < (size_t)m_cols" failed in wxFlexGridSizer::AddGrowableCol(): invalid column index
Call stack:
[00] wxGUIAppTraitsBase::ShowAssertDialog j:\wxwidgets-2.9.4\src\common\appcmn.cpp:475
[01] ShowAssertDialog j:\wxwidgets-2.9.4\src\common\appbase.cpp:1265
[02] wxAppConsoleBase::OnAssertFailure j:\wxwidgets-2.9.4\src\common\appbase.cpp:761
[03] wxDefaultAssertHandler j:\wxwidgets-2.9.4\src\common\appbase.cpp:1065
[04] wxOnAssert j:\wxwidgets-2.9.4\src\common\appbase.cpp:1141
[05] wxFlexGridSizer::AddGrowableCol j:\wxwidgets-2.9.4\src\common\sizer.cpp:1956
[06] MyFrame::MyFrame c:\users\james\documents\code\wx29starter - copy (2)\minimal.cpp:181
[07] MyApp::OnInit c:\users\james\documents\code\wx29starter - copy (2)\minimal.cpp:130
[08] wxAppConsoleBase::CallOnInit j:\wxwidgets-2.9.4\include\wx\app.h:94
[09] wxEntryReal j:\wxwidgets-2.9.4\src\common\init.cpp:456
[10] wxEntry j:\wxwidgets-2.9.4\src\msw\main.cpp:189
[11] wxEntry j:\wxwidgets-2.9.4\src\msw\main.cpp:416
[12] WinMain c:\users\james\documents\code\wx29starter - copy (2)\minimal.cpp:111
[13] __tmainCRTStartup f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c:578
[14] WinMainCRTStartup f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c:403
[15] BaseThreadInitThunk
[16] RtlInitializeExceptionChain
[17] RtlInitializeExceptionChain
Here is the assert code
void wxFlexGridSizer::AddGrowableCol( size_t idx, int proportion )
{
wxASSERT_MSG( !IsColGrowable( idx ),
"AddGrowableCol() called for growable column" );
// see comment in AddGrowableRow(): although it's less common to omit the
// specification of the number of columns, it still can also happen
wxCHECK_RET( !m_cols || idx < (size_t)m_cols, "invalid column index" );
m_growableCols.Add( idx );
m_growableColsProportions.Add( proportion );
}
With confirmation from winterblood changing the parameter to 1 for the call to AddGrowableCol()will solve the problem, despite your test!
Related
I got this error while all the malloc nodes are freed when I run the Valgrind test:
in use at exit: 0 bytes in 0 blocks
total heap usage: 30 allocs, 30 frees, 7,520 bytes allocated
All heap blocks were freed -- no leaks are possible
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
also this with Valgrind -v test:
WARNING: new redirection conflicts with existing -- ignoring it
old: 0x04022e10 (strlen ) R-> (0000.0) 0x580c9ce2 ???
new: 0x04022e10 (strlen ) R-> (2007.0) 0x0483f060 strlen
and this is the error report :
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 95)
// Represents a node in a hash table
typedef struct node
{
char TEXT[48];
struct node *next;
}
node;
//loop over hash buckets
for (int I = 0; I < N; I++)
{
table [I] = malloc(sizeof(node)); <--- line 37
table [I]-> next = NULL;
}
here is the check function :
int x = hash(word);
node *check_ptr = table[x];
int m = strlen(word);
while (check_ptr != NULL )
{
int n = strlen(check_ptr -> TEXT);<----- line 91
"some code "
}
UPDATE - more detailed message
by 0x401C57: check (dictionary.c:91)
---- by 0x40160B: main (speller.c:113)
---- Uninitialised value was created by a heap allocation at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
---- by 0x4019C6: load (dictionary.c:37)
--- by 0x4012CE: main (speller.c:40)
WORDS IN TEXT: 10
HEAP SUMMARY: in use at exit: 0 bytes in 0 blocks
---- total heap usage: 143,122 allocs, 143,122 frees, 8,024,712 bytes allocated
All heap blocks were freed -- no leaks are possible
---- ERROR SUMMARY: 10 errors from 1 contexts (suppressed: 0 from 0)
//loop over hash buckets to initialize the all the buckets to contain null TEXT value solves the problem
it was because i never initialized the TEXT values while i was trying to access them later in the code.
for (int I = 0; I < N; I++)
{
table [I] = malloc(sizeof(node));
table [I]-> next = NULL;
**for (int u =0; u< 48 ; u++)
{
table [I]-> TEXT[u] = '0';
}**
}
I have some troubles with running a program in Ada. I have the three following project files (I use GPS) :
Types.ads
package types is
subtype T_valeurind is Integer range 2..14;
type T_couleur is (s, h, c, d);
type t_carte is record
valeur : T_valeurind;
couleur : T_couleur;
end record;
type T_jeu is array (1..7) of t_carte;
function trans(val: Character) return T_valeurind;
end types;
Trans.adb
with types;
use types;
WITH Text_Io , Ada.Integer_Text_Io;
USE Text_Io , Ada.Integer_Text_Io;
function trans(val : Character)
return T_valeurind is
ret: Integer;
begin
case val is
when '3' => ret:=3;
when '4' => ret:=4;
when '5' => ret:=5;
when '6' => ret:=6;
when '7' => ret:=7;
when '8' => ret:=8;
when '9' => ret:=9;
when 'T' => ret:=10;
when 'J' => ret:=11;
when 'Q' => ret:=12;
when 'K' => ret:=13;
when 'A' => ret:=14;
when others => null;
end case;
return ret;
end trans;
Test.adb
WITH Text_Io , Ada.Integer_Text_Io;
USE Text_Io , Ada.Integer_Text_Io;
with types;
use types;
procedure test is
begin
put(T_valeurind'Image(trans('c')));
end test;
I'm just trying to execute test.adb just to check if my function "trans" works well. When I build the files in GPS, everything works just fine. But when I want to run them, I have the following message, and no execution :
cannot generate code for file types.ads (package spec)
gprbuild: *** compilation phase failed
[2018-12-02 02:01:39] process exited with status 4, 100% (2/2), elapsed time: 01.65s
But what is perturbing is that the first time I tried running the code, it worked. Without changing anything, it stopped working.
I don't know what to do. I've seen that this message just tells me that .ads file is not compilable, but what I try to compile and run is an .adb file, so I don't get it..
Do you have an idea why it doesn't work ?
Thank you all in advance !
First, those aren't project files, which would have type .gpr; they're Ada source files in your project.
Your types.ads promises function trans, which means it needs a package body in types.adb,
package body types is
function trans(val : Character)
return T_valeurind is
ret: Integer;
begin
case val is
when '3' => ret:=3;
when '4' => ret:=4;
when '5' => ret:=5;
when '6' => ret:=6;
when '7' => ret:=7;
when '8' => ret:=8;
when '9' => ret:=9;
when 'T' => ret:=10;
when 'J' => ret:=11;
when 'Q' => ret:=12;
when 'K' => ret:=13;
when 'A' => ret:=14;
when others => null;
end case;
return ret;
end trans;
end types;
(Hmm. If you pass in an invalid character, you'll return uninitialised data, and as like as not get a Constraint_Error; T_valeurind includes the value 2, shouldn’t you cover it?)
Your trans.adb specifies a library-level function instead.
When I build the files in GPS, everything works just fine. But when I want to run them, I have the following message, and no execution :
If a package spec (types.ads) requires a body (types.adb) and you don't provide it, the compiler will produce the message you report when you try to compile it. If you try to just compile test.adb it will be OK. If you try to build test.adb it will try to compile the package Types and will fail, regardless of whether you're trying to Build or Build & Run.
I have no idea how this could have worked first time!
It looks like you forgot to include your function Trans in the context of the test program. And if it isn't in the context, you can't use it.
Try to add:
with Trans;
To the context clause of procedure Test.
Your whole problem could have been avoided in the first place using powerful Ada enums capabilities (and some bad inputs handling strategy, like exceptions). Your trans procedure would be useless.
If you are interested in the order relation of your enum values, you can also use the Ada's 'First* (first enum literal), 'Last (last enum literal), 'Pos (position inside the enum), 'Succ (next enum literal), 'Pred (previous enum literal).
If you perform memory mapping for your variables, you could use 'Valid to check if the variable has a valid value and save the need of exception catch for constraint errors.
See example below:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Exceptions; use Ada.Exceptions;
procedure Hello is
-- miwing chars and literal values in enum
-- note that jack is 'J' and not the single source code character J
type My_Awesome_Enum is ('1', '2', '3', 'J', Q, K, Ace);
for My_Awesome_Enum use
('1' => -1,
'2' => 2,
'3' => 3,
-- ...
'J' => 11,
Q => 12,
K => 13,
Ace => 14);
temp : Integer;
prev : My_Awesome_Enum;
succ : My_Awesome_Enum;
temp2 : My_Awesome_Enum;
begin
-- ------------------------------------------
-- Ada enum power
declare
begin
for value in My_Awesome_Enum loop
temp := My_Awesome_Enum'Enum_Rep(value);
Put_Line("Enum litteral value: " & value'Image & " - memory representation: " & Integer'Image(temp));
if value /= My_Awesome_Enum'First then
prev := My_Awesome_Enum'Pred(value);
Put_Line("Previous: " & prev'Image);
else
Put_Line("No previous");
end if;
if value /= My_Awesome_Enum'Last then
succ := My_Awesome_Enum'Succ(value);
Put_Line("Next: " & succ'Image);
else
Put_Line("No next");
end if;
Put_Line("");
end loop;
end;
-- ------------------------------------------
-- conversion from some input source
Put_Line("");
declare
strInput : String := "Unknown user value";
begin
Put_Line("Handling of user input: " & strInput);
temp2 := My_Awesome_Enum'Value (strInput);
exception
when E: others =>
Put_Line("Exception catched: " & Exception_Information (E));
Put_Line("Setting value to Ace instead");
temp2 := Ace;
end;
Put_Line("tmp2 value: " & temp2'Image & " - memory representation: " & Integer'Image(My_Awesome_Enum'Enum_Rep(temp2)));
-- ------------------------------------------
-- mmemory mapping
Put_Line("");
declare
my_int : Integer := -3;
mapped_Enum : My_Awesome_Enum;
for mapped_Enum'Address use my_int'Address;
last_enum : My_Awesome_Enum := (My_Awesome_Enum'Last);
stop_condition : Integer := (last_enum'Enum_Rep) + 2;
begin
while (my_int < stop_condition) loop
if mapped_Enum'Valid then
Put_Line("Enum with value: " & my_int'Image & " is valid.");
else
Put_Line("Memory mapping would result in invalid enum for value: " & my_int'Image);
end if;
my_int := my_int + 1;
end loop;
end;
end Hello;
This give sthe following output (https://www.tutorialspoint.com/compile_ada_online.php, with GNATMAKE v7.1.1):
Build:
$gnatmake -o hello *.adb
gcc -c hello.adb
gnatbind -x hello.ali
gnatlink hello.ali -o hello
Execute:
Enum litteral value: '1' - memory representation: -1
No previous
Next: '2'
Enum litteral value: '2' - memory representation: 2
Previous: '1'
Next: '3'
Enum litteral value: '3' - memory representation: 3
Previous: '2'
Next: 'J'
Enum litteral value: 'J' - memory representation: 11
Previous: '3'
Next: Q
Enum litteral value: Q - memory representation: 12
Previous: J
Next: K
Enum litteral value: K - memory representation: 13
Previous: Q
Next: ACE
Enum litteral value: ACE - memory representation: 14
Previous: K
No next
Handling of user input: Unknown user value
Exception catched: raised CONSTRAINT_ERROR : bad input for 'Value: "Unknown user value"
Setting value to Ace instead
tmp2 value: ACE - memory representation: 14
Memory mapping would result in invalid enum for value: -3
Memory mapping would result in invalid enum for value: -2
Enum with value: -1 is valid.
Memory mapping would result in invalid enum for value: 0
Memory mapping would result in invalid enum for value: 1
Enum with value: 2 is valid.
Enum with value: 3 is valid.
Memory mapping would result in invalid enum for value: 4
Memory mapping would result in invalid enum for value: 5
Memory mapping would result in invalid enum for value: 6
Memory mapping would result in invalid enum for value: 7
Memory mapping would result in invalid enum for value: 8
Memory mapping would result in invalid enum for value: 9
Memory mapping would result in invalid enum for value: 10
Enum with value: 11 is valid.
Enum with value: 12 is valid.
Enum with value: 13 is valid.
Enum with value: 14 is valid.
Memory mapping would result in invalid enum for value: 15
When trying to store in an Oracle SQL table a string of more than 100 chars, while the field limitation is 1000 bytes which I understood is ~1000 English chars, I'm getting out of bounds exception:
StringIndexOutOfBoundsException: String index out of range: -3
What might be the cause for this low limitation?
Thanks!
EDIT :
The code where the error occurs is (see chat):
// Commenting the existing code, because for sensitive information
// toString returns masked data
int nullSize = 5;
int i = 0;
// removing '[' and ']', signs and fields with 'null' value and also add
// ';' as delimiter.
while (i != -1) {
int index1 = str.indexOf('[', i);
int index2 = str.indexOf(']', i + 1);
i = index2;
if (index2 != -1 && index1 != -1) {
int index3 = str.indexOf('=', index1);
if (index3 + nullSize > str.length() || !str.substring(index3 + 1, index3 + nullSize).equals("null")) {
String str1 = str.substring(index1 + 1, index2);
concatStrings = concatStrings.append(str1);
concatStrings = concatStrings.append(";");
}
}
}
Generally, when the string to store in a varchar field is too long, it is cropped silently. Anyway when there is an error message, it is generally specific. The error seems to be related to a operation on a string (String.substring()?).
Furthermore, even when the string is encoded in UTF-8, the ratio characters/bytes shouldn't be that low.
You really should put the code sample where your error occurs in you question and the string causing this and also have a closer look at the stacktrace to see where the error occurs.
From the code you posted in your chat, I can see this line of code :
String str1 = str.substring(index1 + 1, index2);
You check that index1 and index2 are different than -1 but you don't check if (index1 + 1) >= index2 which makes your code crash.
Try this with str = "*]ab=null[" (which length is under 100 characters) but you can also get the error with a longer string such as "osh]] [ = null ]Clipers: RRR was removed by user and customer called in to have it since it was an RRT".
Once again the size of the string doesn't matter, only the content!!!
You can reproduce your problem is a closing square bracket (]) before an opening one([) and between them an equal sign (=) followed (directly or not) by the "null" string.
I agree with Jonathon Ogden "limitations of 1000 bytes does not necessarily mean 1000 characters as it depends on character encoding".
I recommend you to Alter column in your Oracle table from VARCHAR2(1000 Byte) to VARCHAR2(1000 Char).
Example:
st> [ fnord := 7 ] value
I was always under the impression that they went into the SystemDictionary at Smalltalk, but that's not true:
st> [ fnord := 7 ] value
st> Smalltalk at: #fnord
Object: SystemDictionary new: 512 "<0x2acfca382030>" error: Invalid argument #fnord: key not found
However, at least on GNU Smalltalk, the values seem to be persisted somewhere --- accessing fnord returns the right value:
st> [ fnord := 7 ] value
st> fnord
7
Update: I figured out how to disassemble blocks! It's really hard.
st> [ fnord := 7 ] block inspect
An instance of CompiledBlock
header: 32768
clean-ness flags: 0
number of arguments: 0
number of temporaries: 0
number of literals: 4
needed stack slots: 8
method: UndefinedObject>>executeStatements
literals: [
[1] {fnord}
[2] a BlockClosure
[3] #block
[4] #inspect
]
byte codes: [
[1] source code line number 1
[3] push 7
[5] store into Global Variable {fnord}
[7] pop stack top
push Global Variable {fnord}
[9] return stack top
]
[] in UndefinedObject>>executeStatements
So it definitely thinks it's writing to a global variable.
Undeclared variable bindings go into a global dictionary named Undeclared. That binding (a key->value pair) gets moved to Smalltalk once you properly declare it. This is how forward-references are resolved when loading code, for example. That is, when a variable is used before the code declaring it is loaded.
During a debug session with XCode 5, how would I display the actual value of an NSDecimal var? I found this question but that doesn't work for me. Entering a summary description like {(int)[$VAR intValue]} just results in a message "Summary Unavailable". I should add that my NSDecimals are in an array (NSDecimal dataPoint[2];).
Using the debug console to either print the var description via the context menu or by using p dataPoint[0] just gives me the raw NSDecimal view:
Printing description of dataPoint[0]:
(NSDecimal) [0] = {
_exponent = -1
_length = 1
_isNegative = 0
_isCompact = 1
_reserved = 0
_mantissa = {
[0] = 85
[1] = 0
[2] = 42703
[3] = 65236
[4] = 65534
[5] = 65535
[6] = 23752
[7] = 29855
}
}
UPDATE
In Xcode 10.0, there was an lldb bug that made this answer print the wrong value if the Decimal is a value in a Dictionary<String: Decimal> (and probably in other cases). See this question and answer and Swift bug report SR-8989. The bug was fixed by Xcode 11 (possibly earlier).
ORIGINAL
You can add lldb support for formatting NSDecimal (and, in Swift, Foundation.Decimal) by installing Python code that converts the raw bits of the NSDecimal to a human-readable string. This is called a type summary script and is documented under “PYTHON SCRIPTING” on this page of the lldb documentation.
One advantage of using a type summary script is that it doesn't involve running code in the target process, which can be important for certain targets.
Another advantage is that the Xcode debugger's variable view seems to work more reliably with a type summary script than with a summary format as seen in hypercrypt's answer. I had trouble with the summary format, but the type summary script works reliably.
Without a type summary script (or other customization), Xcode shows an NSDecimal (or Swift Decimal) like this:
With a type summary script, Xcode shows it like this:
Setting up the type summary script involves two steps:
Save the script (shown below) in a file somewhere. I saved it in ~/.../lldb/Decimal.py.
Add a command to ~/.lldbinit to load the script. The command should look like this:
command script import ~/.../lldb/Decimal.py
Change the path to wherever you stored the script.
Here's the script. I have also saved it in this gist.
# Decimal / NSDecimal support for lldb
#
# Put this file somewhere, e.g. ~/.../lldb/Decimal.py
# Then add this line to ~/.lldbinit:
# command script import ~/.../lldb/Decimal.py
import lldb
def stringForDecimal(sbValue, internal_dict):
from decimal import Decimal, getcontext
sbData = sbValue.GetData()
if not sbData.IsValid():
raise Exception('unable to get data: ' + sbError.GetCString())
if sbData.GetByteSize() != 20:
raise Exception('expected data to be 20 bytes but found ' + repr(sbData.GetByteSize()))
sbError = lldb.SBError()
exponent = sbData.GetSignedInt8(sbError, 0)
if sbError.Fail():
raise Exception('unable to read exponent byte: ' + sbError.GetCString())
flags = sbData.GetUnsignedInt8(sbError, 1)
if sbError.Fail():
raise Exception('unable to read flags byte: ' + sbError.GetCString())
length = flags & 0xf
isNegative = (flags & 0x10) != 0
if length == 0 and isNegative:
return 'NaN'
if length == 0:
return '0'
getcontext().prec = 200
value = Decimal(0)
scale = Decimal(1)
for i in range(length):
digit = sbData.GetUnsignedInt16(sbError, 4 + 2 * i)
if sbError.Fail():
raise Exception('unable to read memory: ' + sbError.GetCString())
value += scale * Decimal(digit)
scale *= 65536
value = value.scaleb(exponent)
if isNegative:
value = -value
return str(value)
def __lldb_init_module(debugger, internal_dict):
print('registering Decimal type summaries')
debugger.HandleCommand('type summary add Foundation.Decimal -F "' + __name__ + '.stringForDecimal"')
debugger.HandleCommand('type summary add NSDecimal -F "' + __name__ + '.stringForDecimal"')
The easiest way is to turn it into an NSDecimalNumber in the debugger, i.e.
po [NSDecimalNumber decimalNumberWithDecimal:dataPoint[0]]
This will create a new NSDecimalNumber which prints a nice description. The NSDecimal in your questions is 8.5.
(lldb) po [NSDecimalNumber decimalNumberWithDecimal:dataPoint[0]]
8.5
If you want to have the number displayed in the Variable View, the Summary Format for it would be:
{[NSDecimalNumber decimalNumberWithDecimal:$VAR]}:s