Does Visual Studio have anything like Borland's CodeGuard? - visual-studio

Is there anything in Visual Studio that will report memory leaks like Codeguard?
eg:
Error 00001. 0x300010 (Thread 0x0FA4):
Resource leak: The object (0xC65D84) was never deleted
The object (0x00C65D84) [size: 4 bytes] was created with new
| element2.cpp line 3:
| #include "element2.h"
|
|>CS225::Element2::Element2(int _val) : p_val(new int(_val)) { }
|
| CS225::Element2::Element2(const Element2& rhs)
Call Tree:
0x0040E3A7(=bcc_cg.exe:0x01:00D3A7) element2.cpp#3
0x00409116(=bcc_cg.exe:0x01:008116) element-factory.h#19
0x0040D964(=bcc_cg.exe:0x01:00C964) array.cpp#87
0x00405308(=bcc_cg.exe:0x01:004308) driver.cpp#394
0x004054B5(=bcc_cg.exe:0x01:0044B5) driver.cpp#415
0x00405522(=bcc_cg.exe:0x01:004522) driver.cpp#420
------------------------------------------
Error 00002. 0x300010 (Thread 0x0FA4):
Resource leak: The object (0xC65D58) was never deleted
The object (0x00C65D58) [size: 4 bytes] was created with new
| element2.cpp line 6:
|
| CS225::Element2::Element2(const Element2& rhs)
|> : AbstractElement(), p_val(new int(*rhs.p_val))
| { }
|
Call Tree:
0x0040E4B7(=bcc_cg.exe:0x01:00D4B7) element2.cpp#6
0x0040E652(=bcc_cg.exe:0x01:00D652) element2.cpp#26
0x0040D8CD(=bcc_cg.exe:0x01:00C8CD) array.cpp#81
0x00405308(=bcc_cg.exe:0x01:004308) driver.cpp#394
0x004054B5(=bcc_cg.exe:0x01:0044B5) driver.cpp#415
0x00405522(=bcc_cg.exe:0x01:004522) driver.cpp#420

Built in, no. It has <crtdbg.h>, but it's not as comprehensive as implied by your example. There are various add-ons that provide this functionality. Boundschecker is a well-known and popular one.

Visual Leak Detector sounds pretty good. I haven't tried it myself, though.

Related

SuperCollider * marking the constructor method is not expected

I tried to create a Class and the constructor always gave me a Syntax Error about the *new method then I just copied the Example from the documentation:
MyClass {
// this is a normal constructor method
*new { | arga, argb, argc |
^super.new.init(arga, argb, argc)
}
init { | arga, argb, argc |
// do initiation here
}
}
and still got this:
ERROR: syntax error, unexpected '*', expecting '}'
in interpreted text
line 6 char 5:
*new { | arga, argb, argc |
^
^super.new.init(arga, argb, argc)
-----------------------------------
ERROR: Command line parse failed
-> nil
From my own class i get the same error concerning the constructor. Where am I wrong?
If you check out the Writing Classes helpfile, there's a bit at the top that's easy to miss about where to save your classes.
https://depts.washington.edu/dxscdoc/Help/Guides/WritingClasses.html
NOTE: Class definitions are statically compiled when you launch
SuperCollider or "recompile the library." This means that class
definitions must be saved into a file with the extension .sc, in a
disk location where SuperCollider looks for classes. Saving into the
main class library (SCClassLibrary) is generally not recommended. It's
preferable to use either the user or system extension directories.
Platform.userExtensionDir; // Extensions available only to your user account
Platform.systemExtensionDir; // Extensions available to all users on the machine
It is not possible to enter a class definition into an interpreter
window and execute it.
The the Save As Extension option under the file menu. Then recompile the interpretter and try using your class.

Substrate Build a dApp Tutorial - TypeError: Cannot read property 'query' of undefined

I was able to to run a local substrate node on my machine, finishing the first few tutorials - but am running into a problem with the "build-a-dapp" tutorial (https://substrate.dev/docs/en/tutorials/build-a-dapp/).
Its possible to successfully run the adjusted node. Building the custom front end is something of a two step process in the tutorial.
First running the "old" front end used in the very first build-your-own-node tutorial. Which is then started with yarn start - works fine. Afterwards the App.js file is adjusted, after saving it should switch to the new setup with the PoE UI elements. However, it drops the following error message for me:
TypeError: Cannot read property 'query' of undefined
142 | export default function TemplateModule (props) {
143 | const { api } = useSubstrate();
> 144 | return (api.query.templateModule && api.query.templateModule.proofs
145 | ? <Main {...props} /> : null);
146 | }
Compiled version:
212 | const {
213 | api
214 | } = Object(_substrate_lib__WEBPACK_IMPORTED_MODULE_2__["useSubstrate"])();
> 215 | return api.query.templateModule && api.query.templateModule.proofs ? /*#__PURE__*/Object(react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_5__["jsxDEV"])(Main, { ...props
| ^ 216 | }, void 0, false, {
217 | fileName: _jsxFileName,
218 | lineNumber: 145,
I run it on iOS, all the other tutorials worked just fine, I already deleted everything and worked myself again through the tutorial to make sure I did not miss anything - is there any issue with the call of templateModule? Would appreciate any kind of help in this issue.
Cheers,
Martin

failed to resolve: use of undeclared type `MaximumBlockWeight`

I am following the tutorial https://substrate.dev/docs/en/tutorials/upgrade-a-chain/sudo-upgrade
However, when I try to build the release, it's giving me the following errors. Does anyone know what might be causing the problem?
Compiling node-template-runtime v3.0.0 (/home/bill/substrate-node-template/runtime)
error[E0433]: failed to resolve: use of undeclared type `MaximumBlockWeight`
--> /home/bill/substrate-node-template/runtime/src/lib.rs:302:70
|
302 | pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
| ^^^^^^^^^^^^^^^^^^ use of undeclared type `MaximumBlockWeight`
error[E0308]: mismatched types
--> /home/bill/substrate-node-template/runtime/src/lib.rs:302:42
|
302 | pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
| ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found struct `Perbill`
| |
| expected `u64` because of return type
error[E0277]: the trait bound `Perbill: num_traits::sign::Unsigned` is not satisfied
--> /home/bill/substrate-node-template/runtime/src/lib.rs:302:68
|
302 | pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
| ^ the trait `num_traits::sign::Unsigned` is not implemented for `Perbill`
|
= note: required because of the requirements on the impl of `Mul` for `Perbill`
error[E0277]: the trait bound `Perbill: From<u32>` is not satisfied
Apply this change to your code.
https://github.com/paritytech/substrate/commit/332399d16668a6c769f1a7db154bb9ea3b50e61c
There're a lot of updates every day, please keep watching the upstream if you want to make a runtime upgrade.
Here's the latest node-template https://github.com/paritytech/substrate/blob/master/bin/node-template/runtime/src/lib.rs

SpecFlow Step Generation for Scenario Outline Generating Incorrect Methods

I'm new in Visual Studio. I'm using Visual Studio 2015 with SpecFlow. Below is the Feature File:
#mytag
Scenario Outline: Successful Authentication
Given I am a user of type <user>
When I hit the application URL
And I provide <email>
And I click on Log In Button
Then I will be landed to the Home Page
And I will be able to see <name> on the Home Page
Examples:
| user | email | name |
| admin | a.b#example.com | alpha |
| non-admin | b.c#example.com | beta |
When I generate the step definitions I'm expecting parameters in place of the variables, instead the method is generated as below:
[Given(#"I am a user of type admin")]
public void GivenIAmAUserOfTypeAdmin()
{
ScenarioContext.Current.Pending();
}
I was instead expecting a method like:
[Given(#"I am a user of type '(.*)'")]
public void GivenIAmAUserOfType(string p0)
{
ScenarioContext.Current.Pending();
}
What am I missing?
As an example, surrounding the <user> in the Given step with '' like this,
Given I am a user of type '<user>'
will generate the desired results. It's probably needed in order to recognize the regular expression.

CLR IL-significance of square bracket on .locals init

I am trying to generate a dynamic assembly using Reflection & Emit in .NET. I am getting an error, "Common Language Runtime detected an invalid program." I created another program which has the functionality I want using hard-coded types. The functionality I am trying to write will ultimately use dynamic types, but I can use ILDasm to see the IL I need to generate. I am comparing the IL I am generating with the IL which the compiler generates. In the .locals init declaration of one method I see there is an extra item in the compiler-generated code,
compiler-generated:
.locals init ([0] class [System.Core]System.Linq.Expressions.ParameterExpression CS$0$0000,
[1] class [System.Core]System.Linq.Expressions.ParameterExpression[] CS$0$0001)
mine:
.locals init (class [System.Core]System.Linq.Expressions.ParameterExpression V_0,
class [System.Core]System.Linq.Expressions.ParameterExpression[] V_1)
I don't understand the significance of the "[0]" and "[1]" in the compiler-generated code. Can anyone tell me what it means?
As a more general question, I can follow most ILDasm output without too much trouble. But every so often I run across a problematic expression. For instance, in this line from ILDasm
callvirt instance class [EntityFramework]System.Data.Entity.ModelConfiguration.EntityTypeConfiguration`1<!!0> [EntityFramework]System.Data.Entity.DbModelBuilder::Entity<class DynamicEdmxTrial.HardFooAsset>()
the "!!0" probably refers to the generic type of the Entity<>, but I don't know for sure, and I wonder if there is a key to ILDasm output that would explain its more obscure output to me.
The specification is freely available here. It takes a little getting used to, but most details are easily found once you figure out the structure.
!! is listed in II.7.1 Types:
Type ::= | Description | Clause
‘!’ Int32 | Generic parameter in a type definition, | §II.9.1
| accessed by index from 0 |
| ‘!!’ Int32 | Generic parameter in a method | §II.9.2
| definition, accessed by index from 0 |
...
In other words, inside a method that C# would call f<T, U>(), !!0 would be T, and !!1 would be U.
However, the [0] is a good question. The spec does not seem to address it. The .locals directive is described in II.15.4.1.3 The .locals directive, which lists the syntax as
MethodBodyItem ::= ...
| .locals [ init ] ‘(’ LocalsSignature ‘)’
LocalsSignature ::= Local [ ‘,’ Local ]*
Local ::= Type [ Id ]
There is nothing that seems to allow [0] there unless it is part of a Type, and Type does not allow anything starting with [ either. My guess is that this is an undocumented peculiarity specific to Microsoft's implementation, intended to help the human reader see that location 0 is local variable CS$0$0000, for when the generated instructions access local variables by index.
Experimenting with ILAsm shows that this is exactly what it means. Taking a simple C# program:
static class Program {
static void Main() {
int i = 0, j = 1;
}
}
and compiling and then disassembling it (csc test.cs && ildasm /text test.exe >test.il) shows:
....
.locals init (int32 V_0,
int32 V_1)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: ldc.i4.1
IL_0004: stloc.1
IL_0005: ret
....
Modifying the .locals to
.locals init ([0] int32 V_0, [0] int32 V_1)
gives a useful warning message:
test.il(41) : warning : Local var slot 0 is in use
And indeed, declaring variables of different types, then reordering them using [2], [1], [0], assembling and immediately disassembling the result, shows that the variables got reordered.

Resources