any help ? using confbridge,conf as confbridge is way making conference same as meetme.conf
**=====================================================================
Asterisk-11.5.1 Centos6 app_confbridge.c
=====================================================================
APP: MyConfbridgeCount(Confbridgename,variablename)
it will return no of user in conference if conference is created or else zero.
Task: Using Dailplan user want to retrive no of user in conference
'6050' =>
1. Verbose(3,"testMyConfbridgeCount") [pbx_config]
2. MyConfbridgeCount(4000,count) [pbx_config]
3. verbose(3,"== ${count} ====") [pbx_config]
======================================================================
issue:Currently asterisk core dumped as soon as app2 load .
I want to load module as after join confbridge by any user , using MyConfbridgeCount() to know no of conference user count .
file: app/app_confbrige.c**
==========================================================================
partial code of app_confbridge.c:
=========================================================================
static const char *const app2 ="MyConfbridgeCount";
static int count_exec(struct ast_channel *chan, const char *data)
{
int res = 0;
struct conference_bridge *conf=NULL;
int count;
char *localdata;
char val[80] = "0";
struct ao2_iterator i;
//struct conference_bridge *bridge = NULL;
struct conference_bridge tmp;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(confno);
AST_APP_ARG(varname);
);
ast_verb(3,"\n============Inside count_exec =============\n");
if ( ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "MyConfbrigeCount requires an argument (conference number)\n");
ast_verb(3, "\n MyConfbrigeCount requires an argument (conference number\n ");
return -1;
}
if (!ao2_container_count(conference_bridges)) {
ast_verb(3, "No active conferences.");
ast_log(LOG_NOTICE, "No active conferences.");
return -1;
}
if (!(localdata = ast_strdupa(data))){
return -1;
}
AST_STANDARD_APP_ARGS(args, localdata);
ast_copy_string(tmp.name, args.confno, sizeof(tmp.name));
conf = ao2_find(conference_bridges, &tmp, OBJ_POINTER);
if (conf) {
ao2_lock(conf);
count = conf->markedusers;
ao2_unlock(conf);
}else{
count = 0;
}
if (!ast_strlen_zero(args.varname)) {
snprintf(val, sizeof(val), "%d", count);
pbx_builtin_setvar_helper(chan, args.varname, val);
} else {
if ( ast_channel_state(chan)!= AST_STATE_UP) {
ast_answer(chan);
}
res = ast_say_number(chan, count, "",ast_channel_language(chan),(char *) NULL);
}
return res;
}
static int load_module(void)
{
ast_verb(3 ,"==Inside load_module==");
res |= ast_register_application_xml(app2,count_exec);
return res;
}
static int unload_module(void)
{
res |= ast_unregister_application(app2);
return res;
}
static struct ast_cli_entry cli_confbridge[] = {
AST_CLI_DEFINE(count_exec, "MyConfbrigdeCount Show Number of adminUser(s) in Conference." ),
}
============core dump=================================================
Program terminated with signal 11, Segmentation fault.
#0 __strlen_ia32 () at ../sysdeps/i386/i586/strlen.S:56
56 cmpb %dh, (%eax) /* is byte NUL? *
(gdb) bt
#0 __strlen_ia32 () at ../sysdeps/i386/i586/strlen.S:56
#1 0x00c1b4df in _IO_vfprintf_internal (s=0xfffffffe, format=<value optimized out>, ap=<value optimized out>) at vfprintf.c:1641
#2 0x00c409f0 in _IO_vsnprintf (string=0x835af1c "\374 -- \n======== inside count_exec == data is at address:[0xbf918b64] data:[nnel)\n", maxlen=<value optimized out>,
format=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
args=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at vsnprintf.c:120
#3 0x081a0f94 in __ast_str_helper (buf=0xbf9176a8, max_len=0, append=0,
fmt=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
ap=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at strings.c:76
#4 0x081b17d0 in ast_str_set_va (buf=0xbf9176a8, max_len=0,
fmt=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
ap=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at /usr/src/My-asterisk/asterisk-11.5.1/include/asterisk/strings.h:803
#5 0x08134a6f in __ast_verbose_ap (file=0xe1ca74 "app_confbridge.c", line=2453, func=0xe20652 "count_exec", level=3, callid=0x0,
fmt=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
ap=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at logger.c:1818
#6 0x08134b0b in __ast_verbose (file=0xe1ca74 "app_confbridge.c", line=2453, func=0xe20652 "count_exec", level=3,
fmt=0xe1da30 "\n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n") at logger.c:1836
#7 0x00e09a45 in count_exec (chan=0xe23c18, data=0xfffffffe <Address 0xfffffffe out of bounds>) at app_confbridge.c:2453
#8 0x080d40eb in __ast_cli_register (e=0xe23c18, ed=0x0) at cli.c:2118
#9 0x080d4459 in ast_cli_register (e=0xe23c18) at cli.c:2178
#10 0x080d4482 in ast_cli_register_multiple (e=0xe237a0, len=13) at cli.c:2189
#11 0x00e11f7d in load_module () at app_confbridge.c:4771
#12 0x0812ba89 in start_resource (mod=0x87fa908) at loader.c:845
#13 0x0812c45c in load_resource_list (load_order=0xbf918e90, global_symbols=0, mod_count=0xbf918e88) at loader.c:1045
#14 0x0812ca5a in load_modules (preload_only=0) at loader.c:1198
#15 0x080895f7 in main (argc=4, argv=0xbf91a3a4) at asterisk.c:4180
As i underestand you created NEW application MyConfbridgeCount,right?
And you are not voip nor c++ expert.
If so, recommended way is use GROUP functions to calculate number of channels BEFORE confbridge. That can be done via pure dialplan.
Creating c/c++ app require very carefull coding and multithreaded debugging(which is extreamly complex thing).
If you realy care what is your error - your error is sending to printf function incorrect address of string.
Related
I have a recursive function solveCountdownProblem which calls evaluateCountdown which takes an expression in reverse-polish notation format. evaluateCountdown is in a series of nested for loops (in solveCountdownProblem) so is called a lot of times.
double evaluateCountdown(string rpnIn) {
vector<double> stack;
double a = 0, b = 0;
string token = "";
char arithToken;
for (int i = 0; i < rpnIn.size(); ++i) {
if (rpnIn[i] == ' ') {
if (token != "") {
stack.push_back(stod(token)); // Push number to stack
token = "";
}
} else {
if (find(arithOperators.begin(), arithOperators.end(), rpnIn[i]) != arithOperators.end()) { //if char is arithmetic operator
// Pop two numbers of stack and perform operation
// Push result back into stack
arithToken = rpnIn[i];
a = stack.back(); stack.pop_back(); // pops and removes elements
b = stack.back(); stack.pop_back();
if (arithToken == '+') {
stack.push_back(b+a);
} else if (arithToken == '-'){
stack.push_back(b-a);
} else if (arithToken == '/') {
stack.push_back(b/a);
} else if (arithToken == '*') {
stack.push_back(b*a);
}
} else {
token += rpnIn[i]; //add chars to string
}
}
}
return stack.back();
}
It works after some time producing the right calculations but eventually I end up with a memory error 'double free or corruption (out)'. I've used gdb to debug and it produces this backtrace.
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 __GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7bee859 in __GI_abort () at abort.c:79
#2 0x00007ffff7c593ee in __libc_message (action=action#entry=do_abort, fmt=fmt#entry=0x7ffff7d83285 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#3 0x00007ffff7c6147c in malloc_printerr (str=str#entry=0x7ffff7d85670 "double free or corruption (out)") at malloc.c:5347
#4 0x00007ffff7c63120 in _int_free (av=0x7ffff7db4b80 <main_arena>, p=0x5555555733d0, have_lock=<optimized out>) at malloc.c:4314
#5 0x000055555555a932 in __gnu_cxx::new_allocator<double>::deallocate (this=0x7fffffffd270, __p=0x5555555733e0) at /usr/include/c++/9/ext/new_allocator.h:128
#6 0x0000555555559dc0 in std::allocator_traits<std::allocator<double> >::deallocate (__a=..., __p=0x5555555733e0, __n=4) at /usr/include/c++/9/bits/alloc_traits.h:470
#7 0x000055555555932e in std::_Vector_base<double, std::allocator<double> >::_M_deallocate (this=0x7fffffffd270, __p=0x5555555733e0, __n=4) at /usr/include/c++/9/bits/stl_vector.h:351
#8 0x00005555555588fe in std::_Vector_base<double, std::allocator<double> >::~_Vector_base (this=0x7fffffffd270, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/stl_vector.h:332
#9 0x0000555555558953 in std::vector<double, std::allocator<double> >::~vector (this=0x7fffffffd270, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/stl_vector.h:680
#10 0x0000555555556a9a in evaluateCountdown (rpnIn="4 6 5 * + +") at Countdown.h:58
#11 0x0000555555557762 in solveCountdownProblem (operands=std::vector of length 3, capacity 4 = {...}, targetValue=21) at Countdown.h:172
#12 0x0000555555556d61 in solveCountdownProblem (operands=std::vector of length 4, capacity 5 = {...}, targetValue=21) at Countdown.h:113
#13 0x0000555555556d61 in solveCountdownProblem (operands=std::vector of length 5, capacity 6 = {...}, targetValue=21) at Countdown.h:113
#14 0x0000555555556d61 in solveCountdownProblem (operands=std::vector of length 6, capacity 6 = {...}, targetValue=21) at Countdown.h:113
#15 0x0000555555557e17 in main () at TestCountdown.cpp:19
It seems to be pointing to the line 'vector stack;' but I'm not sure why I'm getting a memory error. Doesn't the destructor automatically deallocate 'stack' once it falls out of scope?
If you look into evaluated string "4 6 5 * + +" you can see that there are not enough operands for the last operation + and in your code you do not check if stack has enough elements before calling stack.pop_back() twice. You need to add that check and act accordingly. Probably cleanest way is to wrap popping in a function:
double pop( std::vector<double> &stack )
{
if( stack.empty() ) { // throw exception, return NaN or whatever logic of your program requires
...
}
auto r = stack.back();
stack.pop_back();
return r;
}
then your code is shorter and cleaner:
// Pop two numbers of stack and perform operation
// Push result back into stack
arithToken = rpnIn[i];
double a = pop( stack ); // pops and removes elements
double b = pop( stack );
(and it is better idea to declare and initialize variables when you need them, not in advance)
Some pieces of my code crash randomly when call push_back or erase on std::list, the code is in a long time runing service . I removed the unimportant part and just keep the most relevant.
std::list<RxCCPReport> pendingSync;
size_t AnchorConnection::HandleCCPTxReport(const char *rxBytes, size_t length) {
if (!pendingSync.empty())
{
std::list<RxCCPReport>::iterator iter = pendingSync.begin();
while (iter != pendingSync.end())
{
if (condition1)
{
iter = pendingSync.erase(iter);
}
else
{
if (condition2)
{
++iter;
}
else if (condition3)
{
++iter;
}
else
{
iter = pendingSync.erase(iter);
}
}
}
}
return length; }
size_t AnchorConnection::HandleCCPRxReport(const char *rxBytes, size_t length) {
RxCCPReport rxCCP;
rxCCP.anc = anc;
rxCCP.rxTime = ccpRxTime;
rxCCP.seqNum = pCsMsg->seqNum;
pendingSync.push_back(rxCCP);
return length;
}
The two function runs on the same thread; code will crash at pendingSync.erase(iter) or pendingSync.push_back(rxCCP) sometimes, about 1 time a week.
the backtrace:
crashed at erase
#0 std::__detail::_List_node_base::_M_unhook (this=0x7fffcc024040) at ../../../../../libstdc++-v3/src/c++98/list.cc:142
__next_node = 0x0
__prev_node = 0x7fffcc024040
#1 0x00000000004db14a in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1570
__n = 0x7fffe5ffad80
#2 0x00000000004daddb in std::list<RxCCPReport, std::allocator<RxCCPReport> >::erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/list.tcc:112
__ret = <error reading variable __ret (Cannot access memory at address 0x10)>
#3 0x00000000004e3d8b in AnchorConnection::HandleCCPTxReport (this=0x7fffdc009240, rxBytes=0x7fffc4022abb "0rl\206%M/\004\205O\263\002\216\356\003\002f", length=12)
at LE/Network/rtls_anchor_conn.cpp:731
rxCCP = {rxTime = 3.1943677384753104, seqNum = 114 'r', anc = }
cSeqRxCCP = 114 'r'
cs = 0x7fffdc016430
ccpTx = 203157767788
ccpTxTime = 3.1794272052158457
pCsMsg = 0x7fffc4022abb
cSeqTxCCP = 114 'r'
crashed at push_back another time
> #0 0x00007ffff6dff387 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
resultvar = 0
pid = 5068
selftid = 5418
#1 0x00007ffff6e00a78 in __GI_abort () at abort.c:90
save_stage = 2
act = {__sigaction_handler = {sa_handler = 0x7ffff6ddb76d, sa_sigaction = 0x7ffff6ddb76d}, sa_mask = {__val = {5, 140737336646961, 3, 140737043728478, 2,
140737336643303, 1, 140737336652017, 3, 140737043728452, 12, 140737336652021, 2, 140737043729264, 140737043729264, 140737043731024}}, sa_flags = 16,
sa_restorer = 0x7fffe57f8d70}
sigs = {__val = {32, 0 <repeats 15 times>}}
#2 0x00007ffff6e41ed7 in __libc_message (do_abort=do_abort#entry=2, fmt=fmt#entry=0x7ffff6f54350 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/unix/sysv/linux/libc_fatal.c:196
ap = {{gp_offset = 40, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
ap_copy = {{gp_offset = 16, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
fd = 26
on_2 = <optimized out>
list = <optimized out>
nlist = <optimized out>
cp = <optimized out>
written = <optimized out>
#3 0x00007ffff6e483e4 in malloc_printerr (action=<optimized out>, str=0x7ffff6f54548 "malloc(): memory corruption (fast)", ptr=<optimized out>, ar_ptr=<optimized out>)
at malloc.c:4967
buf = "00007fffd8001570"
cp = <optimized out>
ar_ptr = <optimized out>
ptr = <optimized out>
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
action = <optimized out>
#4 0x00007ffff6e4bb20 in _int_malloc (av=av#entry=0x7fffd0000020, bytes=bytes#entry=40) at malloc.c:3383
p = 0x7fffd8001560
fb = <optimized out>
pp = <optimized out>
nb = 48
idx = <optimized out>
bin = <optimized out>
victim = 0x7fffd8001560
size = <optimized out>
victim_index = <optimized out>
remainder = <optimized out>
remainder_size = <optimized out>
block = <optimized out>
bit = <optimized out>
map = <optimized out>
fwd = <optimized out>
bck = <optimized out>
errstr = <optimized out>
#5 0x00007ffff6e4e6fc in __GI___libc_malloc (bytes=40) at malloc.c:2905
ar_ptr = 0x7fffd0000020
victim = <optimized out>
hook = <optimized out>
#6 0x00007ffff7929ecd in operator new (sz=40) at ../../../../libstdc++-v3/libsupc++/new_op.cc:51
p = <optimized out>
#7 0x00000000004dc6f8 in __gnu_cxx::new_allocator<std::_List_node<RxCCPReport> >::allocate (this=0x7fffdc011930, __n=1) at /usr/include/c++/4.8.2/ext/new_allocator.h:104
No locals.
#8 0x00000000004dc006 in std::_List_base<RxCCPReport, std::allocator<RxCCPReport> >::_M_get_node (this=0x7fffdc011930) at /usr/include/c++/4.8.2/bits/stl_list.h:334
No locals.
#9 0x00000000004db699 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_create_node<RxCCPReport const&> (this=0x7fffdc011930)
at /usr/include/c++/4.8.2/bits/stl_list.h:502
__p = 0x0
#10 0x00000000004db1c2 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_insert<RxCCPReport const&> (this=0x7fffdc011930, __position=...)
at /usr/include/c++/4.8.2/bits/stl_list.h:1561
__tmp = 0x0
#11 0x00000000004dae68 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::push_back (this=0x7fffdc011930, __x=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1016
No locals.
#12 0x00000000004e475b in AnchorConnection::HandleCCPRxReport (this=0x7fffdc01be90, rxBytes=0x7fffd004d7fb "1{\212\211D\021\006\061+\b\250\256i\227#ԺF(ú\002\005\003o\200#",
length=88) at LE/Network/rtls_anchor_conn.cpp:936
rxCCP = {rxTime = 4.3416058279497198, seqNum = 123 '{', anc = 0x7fffdc016320}
prevSeqNum = 122 'z'
master = 0x7fffdc0101a0
cs = 0x7fffdc016450
masterID = 588618078431250826
logNum = 45794088
pCsMsg = 0x7fffe57f9500
ccpRx = 277418192552
ccpRxTime = 4.3416058279497198
txTime = "0000000000\000\334\377\177\000\000\177\236", <incomplete sequence \345>
temp = "\000\000\000\000"
diagMsg2 = "0F000005036F8040001000000412C8A607120000086000BC07390AD806130000040000FC0114000005F9FF0700731500000EA8AE699740D4BA740800EC69974025000010A604C3FB4C07A3F7520743FE260538072E100002EF022700280491FE1F6D2E100"...
csmsg = {type = 49 '1', seqNum = 123 '{', masterID = "\212\211D\021\006\061+\b", csRxTime = "\250\256i\227#", {firstPath16 = 47828, firstPath = "Ժ"},
extLen = 70 'F', {
ext = "(ú\002\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021", {{logNum32 = 45794088, logNum = "(ú\002"},
diagnostics = "\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021"}}}
FP = 747
rxTime = "409769AEA8\000\345\377\177\000\000Н", <incomplete sequence \345>
I was nearly mad, any suggestion appreciated
Code that receive data over socket is as follows:
#define FRAME_HEADER_LEN (6)
#define FRAME_DATA_IDX (3)
virtual void Run()
{
unsigned int length = 0;
std::string rxBytes;
bool msgProcess;
uint8_t fcode;
unsigned int flen = 0;
while (shutdown_select_anc(socket) != -1)
{
int count = socket->ReceiveData();
if (count <= 0) // Something failed. Socket is probably closed.
{
break;
}
length += count;
rxBytes.append(socket->buf_, count);
/*
* the data coming from the anchor is framed:
*<STX><LENlsb><LENmsb><DATA:<FC><XX>.....><CRClsb><CRCmsb><ETX>
* STX = 0x2
* LEN is the length of data message(16 bits)
* CRC is the 16 - bit CRC of the data bytes
* ETX = 0x3
* FC = is the function code (API code)
*/
if (length <= FRAME_HEADER_LEN) //minimum length is 7 bytes (header + 1 byte function code)
{
continue;
}
do {
msgProcess = false;
crc_err_t pckt_crc = CRC_ERROR;
//search through the received data to find the start of frame
while (length > FRAME_HEADER_LEN)
{
if ((rxBytes.c_str())[0] == 0x2) //this is the start - check if length and end match
{
uint8_t hi = (rxBytes.c_str())[2];
uint8_t lo = (rxBytes.c_str())[1];
flen = lo + ((uint16_t)hi << 8);
if ((flen + FRAME_HEADER_LEN) > length) //we don't have all the frame yet
{
break;
}
if ((rxBytes.c_str())[flen + 5] == 0x3) //end of frame present
{
//received whole frame: check frame checksum here
pckt_crc = check_crc16((uint8_t *)&(rxBytes.c_str())[3], (flen + 2));
break;
}
else //no end of frame in the expected place - start byte was not real start
{
rxBytes.erase(0, 1);
length -= 1;
}
}
else //remove the byte and check if next is a start of frame
{
rxBytes.erase(0, 1);
length -= 1;
}
}
//check if we have a frame
if (((flen + FRAME_HEADER_LEN) > length) || (length <= FRAME_HEADER_LEN))
{
break;
}
if (pckt_crc != CRC_OKAY)
{
//frame packet fully received but it's CRC bad
DBG_PRINTF(DBG_DEFAULT, "ACHTUNG ACHTUNG : incompatible software without CRC or network CRC error\n");
//let incompatible software proceed at the moment
}
fcode = (rxBytes.c_str())[FRAME_DATA_IDX]; //get function code
typename std::map<uint8_t, std::pair<size_t, handler> >::iterator it = handlers.find(fcode);
if (it != handlers.end()) //we have found a handler for this function code
{
if (flen >= it->second.first)
{
handler f = it->second.second;
size_t n = (static_cast<Child*>(this)->*f)(&((rxBytes.c_str())[FRAME_DATA_IDX]), flen );
if (n > 0)
{
msgProcess = true;
rxBytes.erase(0, n + FRAME_HEADER_LEN);
length -= (unsigned int)(n + FRAME_HEADER_LEN);
}
else
{
//Unexpected Message
rxBytes.clear();
length = 0;
}
}
}
else
{
rxBytes.clear();
length = 0;
}
} while((length > 0) && msgProcess);
}
socket->Close();
}
In the push_back case you have
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
Suggests that you have an memory corruption elsewhere, most likely shortly before calling HandleCCPRxReport.
I'm trying to delete some instructions in IR. For analysis purpose, these instructions are inserted before, and now I need to delete them.
BasicBlock::reverse_iterator I = (*b).rbegin();
BasicBlock::reverse_iterator Ie = (*b).rend();
int i=0;
for ( ; I != Ie;I++)
{
if(i>0&&i<4){
errs()<<" Instruction "<<*I<<"\n";
I->eraseFromParent();
i++;
}
else{
i++;
}
}
This code is used in Transformation pass. When I run it, the output error are:
#0 0x00000000032bff15 (opt+0x32bff15)
#1 0x00000000032bffa6 (opt+0x32bffa6)
#2 0x00000000032be43e (opt+0x32be43e)
#3 0x00000000032bf8ac (opt+0x32bf8ac)
#4 0x00007f26cfa81330 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#5 0x00007f26ce81a89a llvm::PointerIntPair<llvm::ilist_node_base<true>*, 1u, unsigned int, llvm::PointerLikeTypeTraits<llvm::ilist_node_base<true>*>, llvm::PointerIntPairInfo<llvm::ilist_node_base<true>*, 1u, llvm::PointerLikeTypeTraits<llvm::ilist_node_base<true>*> > >::getInt() const /home/rasha/llvm/llvm/include/llvm/ADT/PointerIntPair.h:59:0
#6 0x00007f26ce813516 llvm::ilist_node_base<true>::isSentinel() const /home/rasha/llvm/llvm/include/llvm/ADT/ilist_node_base.h:46:0
#7 0x00007f26ce813536 llvm::ilist_node_base<true>::isKnownSentinel() const /home/rasha/llvm/llvm/include/llvm/ADT/ilist_node_base.h:47:0
#8 0x00007f 26ce81e1d9 llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, true, false>::operator*() const /home/rasha/llvm/llvm/include/llvm/ADT/ilist_iterator.h:139:0
#9 0x00007f26ce812d6f (anonymous namespace)::BBRemove::runOnModule(llvm::Module&) /home/rasha/llvm/llvm/lib/Transforms/BBRemove/BBRemove.cpp:79:0
#10 0x0000000002c4a2dc (opt+0x2c4a2dc)
#11 0x0000000002c4aa2c (opt+0x2c4aa2c)
#12 0x0000000002c4ac6d (opt+0x2c4ac6d)
#13 0x0000000001512cd4 (opt+0x1512cd4)
#14 0x00007f26cea6cf45 __libc_start_main /build/eglibc-ripdx6/eglibc-2.19/csu/libc-start.c:321:0
#15 0x00000000014f7a19 (opt+0x14f7a19)
Stack dump:
This error is issued after the first call of eraseFromParent.
BasicBlock::reverse_iterator I = (*b).rbegin();
BasicBlock::reverse_iterator Ie = (*b).rend();
stack<Instruction *> workList;
int i=0;
for ( ; I != Ie;I++)
{
if(i>0&&i<4){
workList.push_back(I);
i++;
}
else{
i++;
}
}
while(!workList.empty()){
Instruction *I=workList.pop();
I->eraseFromParent();
}
Do not modify instruction within the iterator; collect it first then modify.
I am having a XML file as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConfigData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyData>
<FrontCamera>2</FrontCamera>
<RearCamera>8</RearCamera>
</MyData>
</ConfigData>
I need to modify value of an attribute RearCamera from value 8 to 16.
I am using C++ and having libxml2 library
I have tried like below it was not working as expected. Were am i wrong?
xmlDoc* doc = NULL;
xmlNode* root_node = NULL;
xmlNode *child_node = NULL;
xmlNode *cur_node = NULL;
xmlNode *cur = NULL;
LIBXML_TEST_VERSION //!< Macro to check API for match with the DLL we are using
doc = xmlParseFile("ConfigFile.xml"); //!<parse the file and get the DOM
if ( doc == NULL)
{
}
else
{
root_node = xmlDocGetRootElement(doc);
if( root_node != NULL )
{
child_node = root_node->children;
unsigned char* cValue;
int iHandedness = 0;
while(child_node!=NULL)
{
if(!xmlStrcmp(child_node->name,(const xmlChar *)"MyData"))
{
cur = child_node->children;
if(NULL!= cur)
{
for (cur_node = cur; cur_node; cur_node = cur_node->next)
{
if (cur_node->type == XML_ELEMENT_NODE)
{
if(!xmlStrcmp(cur_node->name,(const xmlChar *)"RearCamera"))
{
cur_node->children->content = (const xmlChar *)(16) ;
}
}
}
}
}
child_node = child_node->next;
}
}
xmlSaveFormatFile ("ConfigFile.xml", doc, 1);
xmlFreeDoc(doc); //!< free document
xmlCleanupParser();
}
Save is not happening ,code dump is happening back trace :
n __vfprintf_chk () from /lib/libc.so.6
#1 0xb5bb7028 in xmlGenericErrorDefaultFunc () from /usr/lib/libxml2.so.2
#2 0xb5bb6e6b in xmlReportError () from /usr/lib/libxml2.so.2
#3 0xb5bb839e in __xmlRaiseError () from /usr/lib/libxml2.so.2
#4 0xb5bb8507 in __xmlSimpleError () from /usr/lib/libxml2.so.2
#5 0xb5be3f81 in __xmlIOErr () from /usr/lib/libxml2.so.2
#6 0xb5be43d7 in xmlIOErr () from /usr/lib/libxml2.so.2
#7 0xb5be4841 in xmlFileOpenW () from /usr/lib/libxml2.so.2
#8 0xb5be7369 in __xmlOutputBufferCreateFilename () from /usr/lib/libxml2.so.2
#9 0xb5be7573 in xmlOutputBufferCreateFilename__internal_alias () from /usr/lib/libxml2.so.2
#10 0xb5c97912 in xmlSaveFormatFileEnc__internal_alias () from /usr/lib/libxml2.so.2
#11 0xb5c979f8 in xmlSaveFileEnc__internal_alias () from /usr/lib/libxml2.so.2
Seems you are placing the integer value 16 in the XML field, which should be a character string value "16".
Looking at libxml2, it seems you must use the library's functions to change an attriute value.
See libxml2 attribute modification C of how to change an attribute value.
I'm working on my first C++ extension for a python program. I have been trying to debug this particular piece of code for hours and I am out of ideas.
The segfault seems to have something to do with the PyArrayObject old_simplices_array that is getting passed to the C++ code. That object is a 2d numpy array of type uint32.
This code was modified directly from what scipy.weave puts together. Everything works fine when the code is formatted for and used by scipy.weave.inline. This seems to eliminate the python portion of my program and the algorithm itself from being possible culprits.
That just leaves the syntax and types. Does anyone see any incorrect syntax or type casting the code?
static PyObject* exterior(PyObject* self,
PyArrayObject* old_simplices_array)
{
const short unsigned int step = old_simplices_array->dimensions[1];
const short unsigned int j_max = step - 1;
const long unsigned int col_max =
old_simplices_array->dimensions[0] * step;
short unsigned int j, k, face_index;
long unsigned int col;
unsigned int num_simplices = 0;
PyObject* indices = PyList_New(0);
PyObject* indptr = PyList_New(0);
PyObject* data = PyList_New(0);
PyObject* simplices = PyList_New(0);
PyList_Append(indptr, PyLong_FromLong(0));
PyObject* simplex_to_index = PyDict_New();
for(col = 0; col < col_max; col+=step)
{
for(j = 0; j <= j_max; j++)
{
face_index = 0;
PyObject* face = PyTuple_New(j_max);
for(k = 0; k <= j_max; k++)
{
if(j != k)
{
PyTuple_SetItem(face, face_index,
PyLong_FromLong(old_simplices_array->data[col + k]));
face_index++;
}
}
if(PyDict_Contains(simplex_to_index, face))
{
PyList_Append(indices,
PyDict_GetItem(simplex_to_index, face));
}
else
{
PyDict_SetItem(simplex_to_index, face,
PyLong_FromLong(num_simplices));
PyList_Append(simplices, face);
num_simplices++;
}
PyList_Append(data, PyLong_FromLong(1 - 2 * (j % 2)));
}
PyList_Append(indptr, PyLong_FromLong(col + j));
}
return PyTuple_Pack(3, PyTuple_Pack(3, data, indices, indptr), simplices,
simplex_to_index);
}
------UPDATE------
gdb indicates
const short unsigned int step = old_simplices_array->dimensions[1];
causes a segfault. Did I misuse types?
------UPDATE------
Despite GDB telling me,
const short unsigned int step = old_simplices_array->dimensions[1];
causes the segfault, if I return from the program just before the for loop, I get no segfault (just an error on the python side complaining about returning a NoneType).
This is the full backtrace:
Program received signal SIGSEGV, Segmentation fault.
exterior (self=<optimized out>, old_simplices_array=0xec0a50)
at src/_alto.cpp:39
warning: Source file is more recent than executable.
39 const short unsigned int step = old_simplices_array->dimensions[1];
(gdb) bt
exterior (self=<optimized out>, old_simplices_array=0xec0a50)
at src/_alto.cpp:39
0x00007ffff7aedad2 in PyEval_EvalFrameEx ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7aeddc9 in PyEval_EvalFrameEx ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7aee902 in PyEval_EvalCodeEx ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7a70ad6 in ?? ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7a4565e in PyObject_Call ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7a53b80 in ?? ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7a4565e in PyObject_Call ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7aaaea0 in ?? ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7aa68bc in ?? ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7a4565e in PyObject_Call ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7ae9bce in PyEval_EvalFrameEx ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7aee902 in PyEval_EvalCodeEx ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7aeea32 in PyEval_EvalCode ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7b103fa in PyRun_FileExFlags ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7b10e3d in PyRun_SimpleFileExFlags ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff7b26972 in Py_Main ()
from /usr/lib/sagemath/local/lib/libpython2.7.so.1.0
0x00007ffff6d29ea5 in __libc_start_main ()
from /lib/x86_64-linux-gnu/libc.so.6
0x00000000004006d1 in _start ()
In general, the signature of a method in a C module is PyObject* f(PyObject* self, PyObject* args), where args is intended to be parsed by PyArg_ParseTuple. You can see this in the code scipy.weave generates: http://docs.scipy.org/doc/scipy/reference/tutorial/weave.html#a-quick-look-at-the-code). Unless there's some wrapper function you haven't posted that calls PyArg_ParseTuple for you, your exterior method must call it to extract the PyArrayObject from the generic PyObject* args.