Microsoft MIDL does not report an error if a typedef uses an unknown type, is it a bug? - idl

I would like to know whether I am missing something:
//this is test.idl
typedef foo foo_t;
// end of test.idl
When I compile test.idl with the following command:
midl /W4 test.idl
I get this output
Microsoft (R) 32b/64b MIDL Compiler Version 6.00.0366
Copyright (c) Microsoft Corporation 1991-2002. All rights reserved.
Processing .\test.idl
test.idl
and I get a wrong test.h (at the bottom of this message) which has
only
typedef foo_t;
where the unknown foo type was silently discarded.
I would have expected an error message stating "foo is an unknown
type", am I wrong?
Do I need to pass any particular arguments to the MIDL command?
I got the same result with MIDL compiler version 7.00.0500
/* this ALWAYS GENERATED file contains the definitions for the
interfaces */
/* File created by MIDL compiler version 6.00.0366 */
/* at Thu Nov 13 11:47:40 2008
*/
/* Compiler settings for test.idl:
Oicf, W4, Zp8, env=Win32 (32b run)
protocol : dce , ms_ext, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
__declspec(uuid()), __declspec(selectany), __declspec
(novtable)
DECLSPEC_UUID(), MIDL_INTERFACE()
*/
//##MIDL_FILE_HEADING( )
#pragma warning( disable: 4049 ) /* more than 64k source lines */
/* verify that the <rpcndr.h> version is high enough to compile this
file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif
#include "rpc.h"
#include "rpcndr.h"
#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__
#ifndef __test_h__
#define __test_h__
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
/* Forward Declarations */
#ifdef __cplusplus
extern "C"{
#endif
void * __RPC_USER MIDL_user_allocate(size_t);
void __RPC_USER MIDL_user_free( void * );
/* interface __MIDL_itf_test_0000 */
/* [local] */
typedef foo_t;
extern RPC_IF_HANDLE __MIDL_itf_test_0000_v0_0_c_ifspec;
extern RPC_IF_HANDLE __MIDL_itf_test_0000_v0_0_s_ifspec;
/* Additional Prototypes for ALL interfaces */
/* end of Additional Prototypes */
#ifdef __cplusplus
}
#endif
#endif

I submitted the following bug to Microsoft:
MIDL does not report an error if a typedef uses an unknown type

Related

OpenMP code in CUDA source file not compiling on Google Colab

I am trying to run a simple Hello World program with OpenMP directives on Google Colab using OpenMP library and CUDA. I have followed this tutorial but I am getting an error even if I am trying to include %%cu in my code. This is my code-
%%cu
#include<stdio.h>
#include<stdlib.h>
#include<omp.h>
/* Main Program */
int main(int argc , char **argv)
{
int Threadid, Noofthreads;
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Objective : OpenMP program to print \"Hello World\" using OpenMP PARALLEL directives\n ");
printf("\n\t\t..........................................................................\n");
/* Set the number of threads */
/* omp_set_num_threads(4); */
/* OpenMP Parallel Construct : Fork a team of threads */
#pragma omp parallel private(Threadid)
{
/* Obtain the thread id */
Threadid = omp_get_thread_num();
printf("\n\t\t Hello World is being printed by the thread : %d\n", Threadid);
/* Master Thread Has Its Threadid 0 */
if (Threadid == 0) {
Noofthreads = omp_get_num_threads();
printf("\n\t\t Master thread printing total number of threads for this execution are : %d\n", Noofthreads);
}
}/* All thread join Master thread */
return 0;
}
And this is the error I am getting-
/tmp/tmpxft_00003eb7_00000000-10_15fcc2da-f354-487a-8206-ea228a09c770.o: In function `main':
tmpxft_00003eb7_00000000-5_15fcc2da-f354-487a-8206-ea228a09c770.cudafe1.cpp:(.text+0x54): undefined reference to `omp_get_thread_num'
tmpxft_00003eb7_00000000-5_15fcc2da-f354-487a-8206-ea228a09c770.cudafe1.cpp:(.text+0x78): undefined reference to `omp_get_num_threads'
collect2: error: ld returned 1 exit status
Without OpenMP directives, a simple Hello World program is running perfectly as can be seen below-
%%cu
#include <iostream>
int main()
{
std::cout << "Welcome To GeeksforGeeks\n";
return 0;
}
Output-
Welcome To GeeksforGeeks
There are two problems here:
nvcc doesn't enable or natively support OpenMP compilation. This has to be enabled by additional command line arguments passed through to the host compiler (gcc by default)
The standard Google Colab/Jupyter notebook plugin for nvcc doesn't allow passing of extra compilation arguments, meaning that even if you solve the first issue, it doesn't help in Colab or Jupyter.
You can solve the first problem as described here, and you can solve the second as described here and here.
Combining these in Colab got me this:
and then this:

Problem compiling Cypress software with IAR

I've a Cypress BLE module and have compilation problem with IAR.
In "ezsapi.h" are defined this macros:
#ifdef __GNUC__
/* standard GNU C */
#ifdef _WIN32
/* MinGW, Cygwin, TDM-GCC, etc. */
#define __PACKDEF(STRUCTNAME, STRUCTDEF) typedef struct STRUCTDEF __attribute__((__packed__,gcc_struct)) STRUCTNAME
#else
/* generic gcc */
#define __PACKDEF(STRUCTNAME, STRUCTDEF) typedef struct STRUCTDEF __attribute__((__packed__)) STRUCTNAME
#endif
#define ALIGNED __attribute__((aligned(0x4)))
#else
/* Microsoft Visual C++ */
#define __PACKDEF(STRUCTNAME, STRUCTDEF) __pragma(pack(push, 1)) STRUCTDEF __pragma(pack(pop)) STRUCTNAME
#define ALIGNED
#endif
IAR usually use #pragma pack(push,1) and #pragma pack(pop) and I tryed to modify the macro in:
#define __PACKDEF(STRUCTNAME, STRUCTDEF) #pragma(pack(push, 1)) STRUCTDEF #pragma(pack(pop)) STRUCTNAME
With original macros the errors reported is:
ezsapi.h(694) : Error[Pe020]: identifier "pack" is undefined
ezsapi.h(694) : Error[Pe018]: expected a ")" ezsapi.h(694) :
Error[Pe079]: expected a type specifier ezsapi.h(694) : Error[Pe260]:
explicit type is missing ("int" assumed) ezsapi.h(694) : Error[Pe141]:
unnamed prototyped parameters not allowed when body is present
ezsapi.h(694) : Error[Pe130]: expected a "{"
and with my macro the errors reported is:
(69 is the line where the macro is located)
ezsapi.h(69) : Error[Pe052]: expected a macro parameter name
ezsapi.h(69) : Error[Pe052]: expected a macro parameter name
ezsapi.h(694) : Error[Pe020]: identifier "pack" is undefined
ezsapi.h(694) : Error[Pe018]: expected a ")" ezsapi.h(694) :
Error[Pe079]: expected a type specifier ezsapi.h(694) : Error[Pe260]:
explicit type is missing ("int" assumed) ezsapi.h(694) : Error[Pe141]:
unnamed prototyped parameters not allowed when body is present
ezsapi.h(694) : Error[Pe130]: expected a "{"
What's the correct formula for IAR?
What's escaping me?
Thanks.
There are two ways of solving this problem. My suggestion is that you use the __packed type attibute instead of #pragma pack() as this has a more well defined meaning. This, however, needs IAR language extensions to be switched on. If you can't enable language extensions or for some other reason need to use pack-pragma you have to use an alternative pragma syntax to be able to include it in a preprocessor macro. If you use _Pragma("pack(push,1)") and _Pragma("pack(pop)") you macro should work as expected. Definitions of PACKDEF for both alternatives are shown below:
#define PACKDEF(STRUCTNAME, STRUCTDEF) typedef __packed struct STRUCTDEF STRUCTNAME
#define PACKDEF(STRUCTNAME, STRUCTDEF) _Pragma("pack(push,1)") typedef struct STRUCTDEF STRUCTNAME _Pragma("pack(pop)")

Use libcryptsetup to open a plain encrypted partition

I have a deployed kiosk system which mounts an encrypted partition at boot time using crytpsetup and a key file on disk as such:
cryptsetup open --type plain --key-file /root/key.bin /dev/sda3 sda3
This yields a /dev/mapper/sda3 device which I can then mount for data access.
I am moving the key to a smart card and want to open the partition using libcryptsetup so the key is not exposed on the command line. Unfortunately, the only example given in the cryptsetup source is for LUKS.
I have tried to reverse engineer the cryptsetup source to get the correct library calls but have been frustrated by the complexity of the options.
Are there examples of other projects which use the library for plain encryption or perhaps a skeleton of the library calls required to duplicate the actions of the command line invocation?
The basic sequence of the library calls required for duplicating the actions on command line to open an encrypted partition using cryptsetup library will be as follows
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/types.h>
#include <libcryptsetup.h>
int activate_and_check_status(const char *path, const char *device_name)
{
struct crypt_device *cd;
struct crypt_active_device cad;
int r;
/*
* LUKS device activation example.
* It's sequence of sub-steps: device initialization, LUKS header load
* and the device activation itself.
*/
r = crypt_init(&cd, path);
if (r < 0 ) {
printf("crypt_init() failed for %s.\n", path);
return r;
}
/*
* crypt_load() is used to load the LUKS header from block device
* into crypt_device context.
*/
r = crypt_load(cd, /* crypt context */
CRYPT_LUKS1, /* requested type */
NULL); /* additional parameters (not used) */
if (r < 0) {
printf("crypt_load() failed on device %s.\n", crypt_get_device_name(cd));
crypt_free(cd);
return r;
}
/*
* Device activation creates device-mapper devie mapping with name device_name.
*/
r = crypt_activate_by_passphrase(cd, /* crypt context */
device_name, /* device name to activate */
CRYPT_ANY_SLOT,/* which slot use (ANY - try all) */
"foo", 3, /* passphrase */
CRYPT_ACTIVATE_READONLY); /* flags */
if (r < 0) {
printf("Device %s activation failed.\n", device_name);
crypt_free(cd);
return r;
}
printf("LUKS device %s/%s is active.\n", crypt_get_dir(), device_name);
printf("\tcipher used: %s\n", crypt_get_cipher(cd));
printf("\tcipher mode: %s\n", crypt_get_cipher_mode(cd));
printf("\tdevice UUID: %s\n", crypt_get_uuid(cd));
/*
* Get info about active device (query DM backend)
*/
r = crypt_get_active_device(cd, device_name, &cad);
if (r < 0) {
printf("Get info about active device %s failed.\n", device_name);
crypt_deactivate(cd, device_name);
crypt_free(cd);
return r;
}
printf("Active device parameters for %s:\n"
"\tDevice offset (in sectors): %" PRIu64 "\n"
"\tIV offset (in sectors) : %" PRIu64 "\n"
"\tdevice size (in sectors) : %" PRIu64 "\n"
"\tread-only flag : %s\n",
device_name, cad.offset, cad.iv_offset, cad.size,
cad.flags & CRYPT_ACTIVATE_READONLY ? "1" : "0");
crypt_free(cd);
return 0;
}
The API references for luks format, open, activate and deactivate with examples for cryptsetup is available at this link:
cryptsetup API

"compiling error" FreeRTOS Arduino Library with Visual Studio 2015 and Visual Micro plugin

I have recently installed MS Visual Studio 2015 with the Arduino plugin "Visual Micro".
Everything works fine, upload a sketch etc. Except when I try to compile my code when I use FreeRTOS. I downloaded the FreeRTOS libary through the Arduino IDE (library manager). Therefore(in MS VS 2015) I could chose to include the library in MS VS 2015. So I included the library in one of my sketches. Below you see my code example. Within the Arduino IDE i can compile the code and upload it to the device, but in MS VS there are some errors.
#include <timers.h>
#include <task.h>
#include <StackMacros.h>
#include <semphr.h>
#include <queue.h>
#include <projdefs.h>
#include <portmacro.h>
#include <portable.h>
#include <mpu_wrappers.h>
#include <list.h>
#include <FreeRTOSVariant.h>
#include <FreeRTOSConfig.h>
#include <event_groups.h>
#include <croutine.h>
#include <Arduino_FreeRTOS.h>
//define Tasks
void TaskBlinkSlow(void *pvParameters);
void TaskBlinkFast(void *pvParameters);
void setup()
{
/* add setup code here */
xTaskCreate(TaskBlinkSlow, "TaskSlow", 128, NULL, 1, NULL);
xTaskCreate(TaskBlinkFast, "TaskFast", 128, NULL, 2, NULL);
pinMode(13, OUTPUT);
}
void loop()
{
//Empty, things are done in tasks!!!
}
void TaskBlinkSlow(void * pvParameters)
{
for (;;) {
for (int i = 0; i < 8; i++) {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
void TaskBlinkFast(void * pvParameters)
{
for (;;) {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
}
At the end of this post you will find the short snippet of the compilers error log. Maybe someone already came around the same issue and has a quick fix.
An example debugger breakpoint has been created. To switch the demo
breakpoint off, deselect Visual Micro>Tutorial Mode.
Compiling debug version of 'FreeRTOS' for 'Arduino/Genuino Uno'
FreeRTOS.ino:In file included from timers.h:75:3: error: #error
"include Arduino_FreeRTOS.h must appear in source files before include
timers.h" :#error "include Arduino_FreeRTOS.h must appear in source
files before include timers.h" timers.h:In file included from
FreeRTOS.ino:from task.h:75:3: error: #error "include
Arduino_FreeRTOS.h must appear in source files before include task.h"
:#error "include Arduino_FreeRTOS.h must appear in source files before
include task.h" task.h:In file included from timers.h:from
FreeRTOS.ino:from list.h:99:3: error: #error Arduino_FreeRTOS.h must
be included before list.h :#error Arduino_FreeRTOS.h must be included
before list.h FreeRTOS.ino:In file included from semphr.h:74:3: error:
error "include Arduino_FreeRTOS.h" must appear in source files before "include semphr.h" :#error "include Arduino_FreeRTOS.h" must appear in
source files before "include semphr.h" semphr.h:In file included from
FreeRTOS.ino:from queue.h:75:3: error: #error "include
Arduino_FreeRTOS.h" must appear in source files before "include
queue.h" :#error "include Arduino_FreeRTOS.h" must appear in source
files before "include queue.h" FreeRTOS.ino:In file included from
list.h:99:3: error: #error Arduino_FreeRTOS.h must be included before
list.h :#error Arduino_FreeRTOS.h must be included before list.h
task.h:In file included from timers.h:from FreeRTOS.ino:from
list.h:184:22: error: 'TickType_t' does not name a type
:configLIST_VOLATILE TickType_t xItemValue; *< The value being
listed. In most cases this is used to sort the list in descending
order. * list.h:196:22: error: 'TickType_t' does not name a type
:configLIST_VOLATILE TickType_t xItemValue list.h:208:22: error:
'UBaseType_t' does not name a type :configLIST_VOLATILE UBaseType_t
uxNumberOfItems list.h:386:47: error: expected initializer before
'PRIVILEGED_FUNCTION :void vListInitialise( List_t * const pxList )
PRIVILEGED_FUNCTION list.h:397:55: error: expected initializer before
'PRIVILEGED_FUNCTION :void vListInitialiseItem( ListItem_t * const
pxItem ) PRIVILEGED_FUNCTION list.h:410:77: error: expected
initializer before 'PRIVILEGED_FUNCTION :void vListInsert( List_t *
const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION
list.h:431:80: error: expected initializer before 'PRIVILEGED_FUNCTION
:void vListInsertEnd( List_t * const pxList, ListItem_t * const
pxNewListItem ) PRIVILEGED_FUNCTION list.h:446:1: error: 'UBaseType_t'
does not name a type :UBaseType_t uxListRemove( ListItem_t * const
pxItemToRemove ) PRIVILEGED_FUNCTION timers.h:In file included from
FreeRTOS.ino:from task.h:109:20: error: ISO C++ forbids declaration of
'BaseType_t' with no type [-fpermissive] :typedef BaseType_t
(*TaskHookFunction_t)( void * ) task.h:109:20: error: typedef
'BaseType_t' is initialized (use decltype instead) task.h:109:22:
error: 'TaskHookFunction_t' was not declared in this scope :typedef
BaseType_t (*TaskHookFunction_t)( void * ) timers.h:In file included
from FreeRTOS.ino:from task.h:136:2: error: 'BaseType_t' does not name
a type :BaseType_t xOverflowCount task.h:137:2: error: 'TickType_t'
does not name a type :TickType_t xTimeOnEntering task.h:146:2: error:
'uint32_t' does not name a type :uint32_t ulLengthInBytes
task.h:147:2: error: 'uint32_t' does not name a type :uint32_t
ulParameters task.h:155:2: error: 'TaskFunction_t' does not name a
type :TaskFunction_t pvTaskCode task.h:157:2: error: 'uint16_t' does
not name a type :uint16_t usStackDepth task.h:159:2: error:
'UBaseType_t' does not name a type :UBaseType_t uxPriority
task.h:160:2: error: 'StackType_t' does not name a type :StackType_t
*puxStackBuffer task.h:161:27: error: 'portNUM_CONFIGURABLE_REGIONS' was not declared in this scope :MemoryRegion_t xRegions[
portNUM_CONFIGURABLE_REGIONS ] task.h:170:2: error: 'UBaseType_t' does
not name a type :UBaseType_t xTaskNumber; * A number unique to the
task. * task.h:172:2: error: 'UBaseType_t' does not name a type
:UBaseType_t uxCurrentPriority; * The priority at which the task was
running (may be inherited) when the structure was populated. *
task.h:173:2: error: 'UBaseType_t' does not name a type :UBaseType_t
uxBasePriority; * The priority to which the task will return if the
task's current priority has been inherited to avoid unbounded priority
inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is
defined as 1 in FreeRTOSConfig.h. * timers.h:In file include
If you read the error messages, the issue is explained clearly.
include Arduino_FreeRTOS.h must appear first.
Your example shows it included last.
Put it first and the errors will go away.
Arduino_FreeRTOS.h includes many definitions that are used in other places, hence the need for it to be first.
Unrelated to your question, but using delay() is nasty as it consumes CPU cycles needlessly. Try vTaskDelay() as alternative which defers (or blocks) to the Scheduler to unblock other Tasks or run the idle Task which is the Arduino loop() function.
The loop() function can then put the CPU to sleep, reducing power consumption. See the feilipu.me post on topic for more.
vTaskDelay() counts Ticks, so hence the need to divide by the Tick period in milliseconds. i.e.
Time in ms / portTICK_PERIOD_MS = Ticks
#include <Arduino_FreeRTOS.h>
#include <croutine.h>
#include <event_groups.h>
#include <FreeRTOSConfig.h>
#include <FreeRTOSVariant.h>
#include <list.h>
#include <mpu_wrappers.h>
#include <portable.h>
#include <portmacro.h>
#include <projdefs.h>
#include <queue.h>
#include <semphr.h>
#include <Stack_Macros.h>
#include <task.h>
#include <timers.h>
void setup()
{
}
void loop()
{
}
Found the issue, the includes where in the wrong order: dont know why;).
You cant only include freeRTOS in MS VS you need to correct the order of the includes by yourself.
Here is the correct order:
#include <Arduino_FreeRTOS.h>
#include <croutine.h>
#include <event_groups.h>
#include <FreeRTOSConfig.h>
#include <FreeRTOSVariant.h>
#include <list.h>
#include <mpu_wrappers.h>
#include <portable.h>
#include <portmacro.h>
#include <projdefs.h>
#include <queue.h>
#include <semphr.h>
#include <StackMacros.h>
#include <task.h>
#include <timers.h>
I'm not sure about the Arduino code you are referring to, but normally there is no reason to include FreeRTOSConfig.h directly - instead include FreeRTOS.h first, and that will get the ordering of the port layer files and FreeRTOSConfig.h files correct for you, then include the header files that contain the API functions you want to use.

Why is IDL incomplete?

I'm using OpenDDS 3.4.1 on Linux and trying to manually compile an IDL because I already have a build system for the project and would just like to generated the needed files and integrate. Here a test IDL I'm using.
#include "orbsvcs/TimeBase.idl"
module StockQuoter {
#pragma DCPS_DATA_TYPE "StockQuoter::Quote"
#pragma DCPS_DATA_KEY "StockQuoter::Quote ticker"
struct Quote {
string ticker;
string exchange;
string full_name;
double value;
TimeBase::TimeT timestamp;
};
};
Then compile the IDL as follows:
$ opendds_idl ./StockQuoter.idl
processing ./StockQuoter.idl
$ tao_idl -I$DDS_ROOT/DDS -I$TAO_ROOT/orbsvcs ./StockQuoter.idl
processing ./StockQuoter.idl
But once I get to using tao_idl on the generated IDL, I get the following:
$tao_idl -I$DDS_ROOT/DDS -I$TAO_ROOT/orbsvcs ./StockQuoterTypeSupport.idl
.../ACE_wrappers/bin/tao_idl: "./StockQuoterTypeSupport.idl", line 21: module must contain at least one declaration: ::StockQuoter
.../ACE_wrappers/bin/tao_idl: "./StockQuoterTypeSupport.idl", line 21: module must contain at least one declaration: ::StockQuoter
.../ACE_wrappers/bin/tao_idl: "./StockQuoterTypeSupport.idl", line 21: module must contain at least one declaration: ::StockQuoter
.../ACE_wrappers/bin/tao_idl: "./StockQuoterTypeSupport.idl", line 21: module must contain at least one declaration: ::StockQuoter
Of course the result means I can't register type support in my pub/subs because the needed objects are missing which I can confirm by looking at the StockQuoterTypeSupport.idl file. I looked at chapter 8 of the OpenDDS dev guide for opendds_idl parameters, but nothing seemed to work. Any ideas?
Edit:
Here's the generated IDL StockQuoterTypeSupport.idl.
/* Generated by .../DDS/bin/opendds_idl version 3.4.1 (ACE version 5.6a_p14)
running on input file ./StockQuoter.idl*/
#ifndef OPENDDS_IDL_GENERATED_STOCKQUOTERTYPESUPPORT_IDL_X54N2R
#define OPENDDS_IDL_GENERATED_STOCKQUOTERTYPESUPPORT_IDL_X54N2R
#include "./StockQuoter.idl"
#include "dds/DdsDcpsInfrastructure.idl"
#include "dds/DdsDcpsPublication.idl"
#include "dds/DdsDcpsSubscriptionExt.idl"
#include "dds/DdsDcpsTopic.idl"
#include "dds/DdsDcpsTypeSupportExt.idl"
/* Begin MODULE: StockQuoter */
/* Begin STRUCT: Quote */
module StockQuoter {
};
/* End STRUCT: Quote */
/* End MODULE: StockQuoter */
#endif /* OPENDDS_IDL_GENERATED_STOCKQUOTERTYPESUPPORT_IDL_X54N2R */
It looks there is a problem with the opendds_idl compiler. Can you try to recompile OpenDDS using ACE/TAO x.2.3 which you can obtain from download.dre.vanderbilt.edu. I have that combination on my system and that works without a problem.

Resources