Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 07/02/20 in all areas

  1. Remy Lebeau

    FreeAndNil 10.4 vs 10.3.1 and Pointers

    Yes, actually it does. The thing on its left is the * token. It might help to visualize this if you add whitespace between the TObject and * tokens - the compiler will simply ignore that whitespace, but the tokens are still treated separate: void FreeAndNil(const TObject * const &Obj); So, the 1st const binds to the TObject type, and the 2nd const binds to the * pointer, so you end up with the Obj parameter being a reference to type "const pointer to const TObject".
  2. Remy Lebeau

    FreeAndNil 10.4 vs 10.3.1 and Pointers

    in C++, const is much more flexible than in Delphi, more so than that documentation explains. The semantics of const depend on WHERE the const is placed. In general, const applies to the thing on its left, unless there is nothing there then it applies to the thing on its right instead. So, for instance, if we have these declarations in C++: void FreeAndNil(const TObject* &Obj); or void FreeAndNil(TObject const * &Obj); Then the const applies only to the TObject instance that is being pointed at, so its data members cannot be changed by the function. The const does not apply to the TObject* pointer itself, which is being passed by reference, so that pointer can be freely assigned a new value by the function to point at a different TObject instance or null, and that change is reflected to the caller's variable. Whereas if we have this declaration instead in C++: void FreeAndNil(TObject* const &Obj); Then the const applies only to the TObject* pointer itself, thus it can't be assigned a new value by the function. The const does not apply to the TObject instance, so its data members can be freely modified by the function. The two examples above can be combined to have a const pointer to a const TObject instance: void FreeAndNil(const TObject* const &Obj); or void FreeAndNil(TObject const * const &Obj); It does not make sense to put const after Obj, since by definition a reference cannot be reseated once it has been initialized: void FreeAndNil(... &Obj const); or void FreeAndNil(... &Obj const); Now, given this declaration in Delphi: procedure FreeAndNil(const [ref] Obj: TObject); The semantics of this are roughly equivalent to the above C++ code - a reference to a const pointer to a const TObject instance (I don't have 10.4 installed to look at how FreeAndNil() is actually declared in C++Builder). That is fine and good to get a pointer to a TObject-based instance passed into the function by reference, but normally Delphi would then not allow that pointer to be assigned a new value. So FreeAndNil() employs a workaround for that: TObject(Pointer(@Obj)^) := nil; Applying the @ operator to a reference parameter returns the address of the passed variable. Then all const-ness on that variable is being casted away, thus allowing the function to assign a new value to that variable. That would be something along the lines of the following in C++: ((TObject*&)(*(void**)&ref)) = nullptr; or reinterpret_cast<TObject*&>(const_cast<void*&>(*reinterpret_cast<const void * const *>(&ref))) = nullptr; or const_cast<TObject*&>(const_cast<const TObject * const &>(ref)) = nullptr; Except that if a C++ compiler sees a 'const TObject* const &' function parameter, and is passed anything other than a 'const TObject*' variable, an implicit conversion is performed and an rvalue gets passed to the reference parameter, so the function modifies the rvalue, not the caller's original variable. For example: https://ideone.com/CO4Dac So, there is likely some additional compiler magic in C++Builder to avoid this problem with FreeAndNil() specifically. Unless I'm missing something.
  3. We are excited to announce to the community that the new Deleaker 2020.16 with full RAD Studio 10.4 Sydney is available to download. Deleaker is a famous tool to find leaks, leaked objects and memory, GDI resources, and handles. This is a good addition to a favorite IDE for everyone who wants to explore resource usage and fix leaks without leaving RAD Studio. For those who prefer to watch, we've recorded a video to show how it works: Happy coding!
  4. Devart, a recognized vendor of world-class data connectivity solutions for various data connection technologies and frameworks, released SecureBridge v9.3 with support for RAD Studio 10.4 Sydney. Other notable updates include the support for Lazarus 2.0.8 and the macOS 64-bit target platform in Lazarus. The list of new and improved features inсludes: Support for the newest RAD Studio 10.4 Sydney; Support for the latest Lazarus version 2.0.8; Support for the Socks4 and Socks5 network protocols for routing traffic to a server through a firewall; A new class, TScPKCS12Processor, to support importing certificates and private keys from keystore files in the PKCS #12 format; Support for SSH dynamic port forwarding in TScSSHChannel; Support for the Signed Certificate Timestamp (SCT) certificate extension. SecureBridge offers components that can be used as clients and servers for SSH, SFTP, SSL, FTPS, HTTP/HTTPS, WebSocket, and SignalR protocols to protect data flow over an untrusted network. It is also compatible with data access components to prevent data interception and theft. To learn more about the current release, please visit https://blog.devart.com/securebridge-with-support-for-rad-studio-10-4.html About Devart Devart is one of the leading developers of database tools and administration software, ALM solutions, data providers for various database servers, data integration and backup solutions. The company also implements Web and Mobile development projects. For additional information about Devart, visit https://www.devart.com/
  5. Would choose FreeNullminator, ... hasta la vista .... Object
  6. This code must crash horribly on the first call to FreeAndNil with a non-nil pointer. So this code was either never used or the memory is already freed and the pointer set to nil before that call.
  7. Dalija Prasnikar

    FreeAndNil 10.4 vs 10.3.1 and Pointers

    Everyone please vote for Global Generics https://quality.embarcadero.com/browse/RSP-13724 So we can have type safe FreeAndNil without quirks and lies.
  8. Stefan Glienke

    FreeAndNil 10.4 vs 10.3.1 and Pointers

    Refactoring away from objects to something else and forgetting FreeAndNil is probably the number one source of defects of this category which is why I am happy for this change in 10.4 even though it also has its quirks most notably an API that tells a lie.
  9. Andrea Magni

    MARS & Delphi 10.2

    Thanks, I am using a portion of mORMot (check my mORMotJWT repository: https://github.com/andrea-magni/mORMot-JWT) I have extracted (with permission) in order to benefit of their JWT implementation (that is way better than the JOSE implementation). Unfortunately, they are (were?) not supporting Linux compilation with Delphi because of ARC. That's the reason I still have JOSE and mORMotJWT support at the same time. Glad you solved! Sincerely, Andrea
  10. Edwin Yip

    SynEdit preferred version?

    This is not the correct process as I understand it, you should: - Fork the repository on github web, so you that have your own repository that you can permission to make changes - Clone your forked repository to your local pc - Change the source code as needed (following the contribution rules, if any) - Commit and push your changes to your forked repository - Make a pull request to the original SynEdit2 repository, and wait for acceptance
  11. David Heffernan

    One more memory leak and FastMM4

    Try finslly still wrong. You must acquire the resource immediately before the try Foo := TMyObject.Create; try Foo.Use; finally Foo.Free; end; As you have it, if an exception is raised before the variable is assigned, you'll call Free on an uninitialized variable.
×