I came across on linker error of c++ cli:
Error LNK2022 metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c00019d). foo.obj 1
Error LNK2022 metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c0001ab). bar.obj 1
What is actually metadata tokens? I have learned obj files via ildasm, but I have no idea what is actually problem. Here is brief content:
foo.obj:
// TypeDef #190 (020000bf)
// -------------------------------------------------------
// TypDefName: FooClass (020000BF)
// Flags : [Public] [SequentialLayout] [Class] [Sealed] [AnsiClass] [BeforeFieldInit] (00100109)
// Extends : 01000017 [TypeRef] System.ValueType
// Layout : Packing:0, Size:12
// CustomAttribute #1 (0c00019c)
// -------------------------------------------------------
// CustomAttribute Type: 0a000006
// CustomAttributeName: System.Runtime.CompilerServices.NativeCppClassAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args: ()
//
// CustomAttribute #2 (0c00019d)
// -------------------------------------------------------
// CustomAttribute Type: 0a000007
// CustomAttributeName: System.CLSCompliantAttribute :: instance void .ctor(bool)
// Length: 5
// Value : 01 00 00 00 00 > <
// ctor args: ( <can not decode> )
bar.obj
// TypeDef #199 (020000c8)
// -------------------------------------------------------
// TypDefName: FooClass (020000C8)
// Flags : [Public] [SequentialLayout] [Class] [Sealed] [AnsiClass] [BeforeFieldInit] (00100109)
// Extends : 01000016 [TypeRef] System.ValueType
// Layout : Packing:0, Size:12
// CustomAttribute #1 (0c0001aa)
// -------------------------------------------------------
// CustomAttribute Type: 0a000006
// CustomAttributeName: System.Runtime.CompilerServices.NativeCppClassAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args: ()
//
// CustomAttribute #2 (0c0001ab)
// -------------------------------------------------------
// CustomAttribute Type: 0a000007
// CustomAttributeName: System.CLSCompliantAttribute :: instance void .ctor(bool)
// Length: 5
// Value : 01 00 00 00 00 > <
// ctor args: ( <can not decode> )
All I see, that FooClass extends different ValueTypes (I don't know why). Is there any documentation about that tokens? Is it some kind of pdb information about symbols?
Related
Sending data from (mesh network)smoke sensors to AWS. I am storing the node data using linked list.After passing data to AWS,i am try to de-allocate the memory and coming across following two errors in free().
#include <stdio.h>
#include<stdlib.h>
typedef struct Node
{
uint8_t node_data[15]; //stores node infomation
struct Node* next; //pointer to next node
}node;
node *head=NULL;
node*current=NULL;
static uint8_t k[15]; //this array keeps track of data received on UART port
static uint8_t node_count=0; //keeps the track of no. of nodes added to the system
void push_data(int []); /*this function pushes data present in array into
a node(memory allocated to node dynamically)*/
void delete_node(node*); //this function deletes the memory allocated to node
void pack_data(void); // send node data to aws
void loop()
{
if(Serial2.available()>0)
{
for( uint8_t i=0;i<15;i++)
{
k [i]= Serial2.read();
}
push_data(k);
}
delay(5000);
}
void push_data(uint8_t arr[])
{
if(head==NULL)
{
head=(node*)malloc(sizeof(node));
current=(node*)malloc(sizeof(node));
for(uint8_t i=0;i<15;i++)
{
head->node_data[i]=arr[i];
}
head->next=current;
node_count++;
return;
}
else
{
for(uint8_t i=0;i<15;i++)
{
current->node_data[i]=arr[i];
}
current->next=(struct Node*)malloc(sizeof(struct Node));
current=current->next;
current->next=NULL;
node_count++;
pack_data();
return;
}
}
void pack_data()
{
/*this function converts node data into data format
* and sends the data to aws.*/
/* Once the data is send to aws ,
the memory allocated to nodes is freed
*/
delete_node(head);
return;
}
void delete_node(node* n)
{
node* m=NULL;
while(n!=NULL)
{
m=n->next;
free(n);
n=NULL;
n = m;
}
// return;
}
Whenever is am trying to free the dynamically allocated memory,the delete_node function causes problem.Throwing the following errors
ERROR 1
assert failed: multi_heap_realloc multi_heap_poisoning.c:289 (head != NULL)
ERROR 2
Guru Meditation Error: Core 1 panic'ed (LoadStoreError). Exception was unhandled.
Core 1 register dump:
PC : 0x400f3fc4 PS : 0x00060330 A0 : 0x800efca4 A1 : 0x3ffb1920
A2 : 0x00000000 A3 : 0x3ffcc800 A4 : 0x00000005 A5 : 0x00000000
A6 : 0x00000005 A7 : 0x40000014 A8 : 0x800f3ff4 A9 : 0x3ffb1910
A10 : 0x3ffcc800 A11 : 0x88000028 A12 : 0x00000000 A13 : 0x3ffcc800
A14 : 0x00000008 A15 : 0x00000000 SAR : 0x00000004 EXCCAUSE: 0x00000003
EXCVADDR: 0x4000001e LBEG : 0x40088f8c LEND : 0x40088fa2 LCOUNT : 0xffffffff
I was trying to record light intensity values for a Li-Fi project.
This is my code:
#include <soc/sens_reg.h>
#include <soc/sens_struct.h>
#include <driver/adc.h>
#include <SD.h>
#define ADC1_GPIO36_CHANNEL ADC1_CHANNEL_0
#include <adc_channel.h>
const char filename1[] = "/part1.dat";
const char filename2[] = "/part2.dat";
File file1, file2;
int local_adc1_read(int channel) {
uint16_t adc_value;
SENS.sar_meas_start1.sar1_en_pad = (1 << channel); // Only one channel is selected
while (SENS.sar_slave_addr1.meas_status != 0)
;
SENS.sar_meas_start1.meas1_start_sar = 0;
SENS.sar_meas_start1.meas1_start_sar = 1;
while (SENS.sar_meas_start1.meas1_done_sar == 0)
;
adc_value = SENS.sar_meas_start1.meas1_data_sar;
return adc_value;
}
#define ADC_SAMPLES_COUNT 1000
int16_t abuf[ADC_SAMPLES_COUNT];
int16_t abufPos = 0;
portMUX_TYPE DRAM_ATTR timerMux = portMUX_INITIALIZER_UNLOCKED;
TaskHandle_t complexHandlerTask;
hw_timer_t * adcTimer = NULL; // Our timer
void complexHandler(void *param) {
timerAlarmDisable(adcTimer);
timerDetachInterrupt(adcTimer);
timerEnd(adcTimer);
adcTimer = NULL;
file1 = SD.open(filename1, FILE_WRITE);
file2 = SD.open(filename2, FILE_WRITE);
file1.write((const byte*)abuf, abufPos);
file2.write((const byte*)abuf, abufPos);
file1.close();
file2.close();
}
int counter;
void IRAM_ATTR onTimer() {
portENTER_CRITICAL_ISR(&timerMux);
abuf[abufPos++] = local_adc1_read(ADC1_CHANNEL_0);
//abuf[abufPos++] = adc1_get_raw(ADC1_CHANNEL_0);
if (abufPos >= 8) {
if (abuf[abufPos-7] ==
abuf[abufPos-6] ==
abuf[abufPos-5] ==
abuf[abufPos-4] ==
abuf[abufPos-3] ==
abuf[abufPos-2] ==
abuf[abufPos-1] ==
abuf[abufPos])
{
// Notify adcTask that the buffer is full.
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(complexHandlerTask, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken) {
portYIELD_FROM_ISR();
}
}
portEXIT_CRITICAL_ISR(&timerMux);
}
}
void setup() {
setCpuFrequencyMhz(240);
xTaskCreate(complexHandler, "Handler Task", 8192, NULL, 1, &complexHandlerTask);
adcTimer = timerBegin(3, 80, true); // 80 MHz / 80 = 1 MHz hardware clock for easy figuring
timerAttachInterrupt(adcTimer, &onTimer, true); // Attaches the handler function to the timer
timerAlarmWrite(adcTimer, 100, true); // Interrupts when counter == 45, i.e. 22.222 times a second
timerAlarmEnable(adcTimer);
Serial.begin(115200);
pinMode(2, OUTPUT);
//pinMode(36, INPUT);
if (!SD.begin())
Serial.println("SD begin failed");
while(!SD.begin()) {
Serial.print(".");
//delay(500);
SD.remove(filename1);
SD.remove(filename2);
}
}
void loop() {
}
I got this error:
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:10900
load:0x40080400,len:6388
entry 0x400806b4
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400f095f PS : 0x00060030 A0 : 0x800d1019 A1 : 0x3ffb3f80
A2 : 0x00000000 A3 : 0x3ffb2080 A4 : 0x00000020 A5 : 0x80000020
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x00000005 A9 : 0x00000020
A10 : 0x00000020 A11 : 0x3ffbc0d0 A12 : 0x80087259 A13 : 0x3ffbc0d0
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000000 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x400f095f:0x3ffb3f80 0x400d1016:0x3ffb3fa0 0x40088269:0x3ffb3fe0
I tried decreasing the interrupt frequency, using a huge app (3 MB), increasing the CPU clock to 240 Hz, but nothing changed.
By outcommenting
vTaskNotifyGiveFromISR(complexHandlerTask, &xHigherPriorityTaskWoken);
and
xTaskCreate(complexHandler, "Handler Task", 8192, NULL, 1, &complexHandlerTask);
now the error is
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)
And some register dumps of core 1 and core 0. There isn't any change doing something in the loop.
When connected to an OBD device, setCharacteristicNotification and writeCharacteristic. Notification was received onCharacteristicChanged.
But the notification showed 3E 00 00 3F, same conditions for many write requests. It is expected to return the information about the device.
The codes are as following:
public void writeCharacteristic(String commnd, BluetoothGattCharacteristic characteristic, boolean enabled) {
int commandLength = commnd.length(); // length of the string used for the loop
byte[] bytes = new byte[commnd.length()];
for(int i = 0; i < commandLength ; i++){ // while counting characters if less than the length add one
char character = commnd.charAt(i); // start on the first character
int ascii = (int) character; //convert the first character
bytes[i] = (byte) Integer.parseInt(String.valueOf(ascii));
Log.w(TAG, "byte index:"+i+", ascii:"+ascii+", bytes i:"+bytes[i]);
}
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
characteristic.setValue(bytes);//ch);//messageBytes);
boolean success = mBluetoothGatt.writeCharacteristic(characteristic);
Log.w("Gatt", "write result:"+success);
Log.w(TAG, "set characteric notification, enabled?"+enabled);
setCharacteristicNotificationWithDescriptor(characteristic, true);
}
protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
public boolean setCharacteristicNotificationWithDescriptor(BluetoothGattCharacteristic characteristic, boolean enable) {
Log.w(TAG, "setCharacteristicNotification(UUID=" + characteristic.getUuid().toString() + ", enable=" + enable + " )");
mBluetoothGatt.setCharacteristicNotification(characteristic, enable);
Log.w(TAG, "descriptor:"+CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 });
Log.w(TAG, "notification value:"+BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE+", false:"+new byte[] { 0x00, 0x00 }.toString());
boolean status = mBluetoothGatt.writeDescriptor(descriptor); //descriptor write operation successfully started?
Log.w(TAG, "write descriptor:"+status);
return status;
}
Not sure how to get the correct response? I sent the AT command with 0D. Thank you.
This is the boost::asio::ssl example, it has no memory leaks:
int main(int argc, char* argv[])
{
#if defined(WIN32) || defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS_)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
try
{
boost::asio::io_context io_context;
boost::asio::ip::tcp::resolver resolver(io_context);
boost::asio::ip::tcp::resolver::results_type endpoints =
resolver.resolve("127.0.0.1", "9443");
boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);
ctx.load_verify_file("ca.pem");
client c(io_context, ctx, endpoints);
io_context.run();
while (getchar() != 'q');
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}
But, if I change the code to the following:
int main(int argc, char* argv[])
{
#if defined(WIN32) || defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS_)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
try
{
// just used a thread to execute the ssl test,the rest of the code is exactly the same
std::thread([]()
{
boost::asio::io_context io_context;
boost::asio::ip::tcp::resolver resolver(io_context);
boost::asio::ip::tcp::resolver::results_type endpoints =
resolver.resolve("127.0.0.1", "9443");
boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);
ctx.load_verify_file("ca.pem");
client c(io_context, ctx, endpoints);
io_context.run();
while (getchar() != 'q');
}).join();
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}
then, there is a memory leak:
Detected memory leaks!
Dumping objects ->
{2182} normal block at 0x000000000034C8B0, 8 bytes long.
Data: < > 00 00 00 00 01 00 00 00
{128} normal block at 0x000000000035AB30, 520 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
I found the asio::ssl memory leaks for a long time, but never solved it, and I found if io_context::run is not called in the main thread, then there will be a memory leak. Can someone help me?
It's not really a leak. Any memory allocated in static constructors may be falsely identified as a leak.
To resolve this:
#include "stdafx.h"
#include <gtest/gtest.h>
#include "MemLeakInstrumentation.h"
#include "MemLeakListener.h"
#include "PreventFalseMemoryLeaksFromStatics.hpp"
static int q = prevent_false_memory_leaks_from_statics( L"UnitTest.CouloirAFX" );
int main( int argc, char* argv[] )
{
testing::InitGoogleTest( &argc, argv );
auto& listeners = testing::UnitTest::GetInstance()->listeners();
listeners.Append( new gte::MemLeakListener );
const auto result = RUN_ALL_TESTS();
return result;
}
static int prevent_false_memory_leaks_from_statics( Couloir::String UnitTestName )
{
Couloir::Directory BoostStaticInit( L"C:\\Dev\\Couloir\\Generic\\PFM\\UnitTest.CouloirPFM" );
boost::asio::io_context ioc;
ssl::context AsioStaticInit{ ssl::context::sslv23_client };
In an effort to simplify the problem I am having, I have included two classes in foo.mqh and bar.mqh.
When I compile them, I get:
'bar' - wrong parameters count foo.mqh Line 20 Column 9
which is this line in foo.mqh:
foobar(bar & b) { example = b;}
I have read up on other posts that deal with this error, but they don't seem to be object oriented and I can't correllate those instances with this one.
Is it that bar has a default value? .... because of the constructor? Actually that is probably not it because if I put them in the same file I get the same error.
Is there anyway to get around this?
Any help would be appreciated. Thanks
bar.mqh
#property copyright "Copyright 2015, MetaQuotes Software Corp." // 01
#property link "https://www.mql5.com" // 02
#property strict // 03
// 04
class bar{ // 05
private: // 06
int b; // 07
int u; // 08
int g; // 09
public: // 10
bar * operator=(const bar & example) // 11
{ // 12
b = example.b; // 13
u = example.u; // 14
g = example.u; // 15
return GetPointer(this); // 16
} // 17
bar(bar & example) // 18
{ // 19
b = example.b; // 20
u = example.u; // 21
g = example.u; // 22
} // 23
// 24
}; // 25
foo.mqh
#property copyright "Copyright 2015, MetaQuotes Software Corp." // 01
#property link "https://www.mql5.com" // 02
#property strict // 03
// 04
// 05
#include<bar.mqh> // 06
// 07
class foo { // 08
}; // 09
// 10
class foobar: public foo { // 11
private: // 12
bar example; // 13
public: // 14
foobar(bar & b) { example = b;} // 15
bar getExample() { return example; } // 16
}; // 17
The issue was that I did not have a constructor/destructor declaration.
See bar.mqh below:
//+------------------------------------------------------------------+
//| bar.mqh |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property strict
class bar{
private:
int b;
int u;
int g;
public:
bar() {}
~bar() {}
bar * operator=(const bar & example)
{
b = example.b;
u = example.u;
g = example.u;
return GetPointer(this);
}
bar(bar & example)
{
b = example.b;
u = example.u;
g = example.u;
}
};
foo.mqh did not have to change.