Did the RegEx library change in some way with 6.04?

Everything else that doesn't fall into one of the other PB categories.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Did the RegEx library change in some way with 6.04?

Post by jacdelad »

Before I search until my eyes bleed: Did something happen to the RegEx-library? My Gerber module worked fine until now. I didn't change a single byte, just updated to 6.04 and now, boom, the regex calls all fail suddenly. I cannot render my Gerber files anymore.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Did the RegEx library change in some way with 6.04?

Post by Fred »

Just checked and last change was made in 6.03
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Did the RegEx library change in some way with 6.04?

Post by jacdelad »

Thanks Fred.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Did the RegEx library change in some way with 6.04?

Post by jacdelad »

Seems like I found the culprit, which leads to another question: I thought modules had their own scope for variables and constants. This seems to be wrong. I have an enumeration for RegExes in my module AND in the main program. Both start with 0. Does this mean, one overrides the other one? Does this also mean I ABSOLUTELY HAVE to use #PB_Any within the module, wherever it is possible to use it (RegEx, databases, controls, images...)???
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
AZJIO
Addict
Addict
Posts: 1315
Joined: Sun May 14, 2017 1:48 am

Re: Did the RegEx library change in some way with 6.04?

Post by AZJIO »

jacdelad wrote: Wed Jan 03, 2024 11:53 pm Both start with 0. Does this mean, one overrides the other one?
It is obvious. Any menu or gadget cannot have the same number, even if they are in different windows. As far as I understand, lists that are associated with objects are created inside PureBasic. Upon completion of the program, these lists undergo a closing process. Therefore, when you bind another object to the same number, in the best case, the old object will be destroyed before being bound to the new object, and in the worst case, you get a memory leak if the object remains in memory, and the link to it through the identifier is lost.
If you are using a module then you should not use explicit numbers, you should definitely use the #PB_Any constant

As far as I know, #PB_Any uses large numbers for identifiers, so if the user creates an object starting from zero, it is protected from overriding the occupied identifier by other modules. But in any case, when using the module, it will be more reliable to use the #PB_Any constant for objects of your program.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Did the RegEx library change in some way with 6.04?

Post by jacdelad »

I understand that, but I thought each module had its own scope, so it'd had its own list of objects and it wouldn't collide. I'll have to redo some of my modules.
Also, this isn't 100% clear from the help, though I might be the only one who didn't understand this.

Anyway, thanks for taking time and clearing this up!
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Did the RegEx library change in some way with 6.04?

Post by Demivec »

I started this reply before AZJIO posted and so I'll post it pretty much as is because it presents a different view from AZJIO. Please forgive the redundant things you already know and heard from AZJIO's post.
jacdelad wrote: Wed Jan 03, 2024 11:53 pm Seems like I found the culprit, which leads to another question: I thought modules had their own scope for variables and constants. This seems to be wrong. I have an enumeration for RegExes in my module AND in the main program. Both start with 0. Does this mean, one overrides the other one? Does this also mean I ABSOLUTELY HAVE to use #PB_Any within the module, wherever it is possible to use it (RegEx, databases, controls, images...)???
Did you think that if the code that executed a RegEx function was included in a module that the RegularExpressionID was unique to the module? That is definitely not true. A RegularExpressionID is also not unique to a particular thread whether or not it is generated by code running inside or outside of that thread.

Considering the above facts, you do not need to use #PB_Any if you don't want to. You do need to better control the enumeration process to generate unique ID's as needed. This can be done in several ways.

You can enumerate the range of ID's inside the module with a different starting point than the enumeration in the mainscope to help ensure the range of ID's don't overlap.

A better method with modules is to use a 'Common' module and a named enumeration for the RegularExpressionID's. Both the mainscope and other modules that need to generate their own unique ID's would reference the named enumeration in the 'Common' module.

Here's an example:

Code: Select all

DeclareModule Common
  Enumeration RE_ID 1
  EndEnumeration
  
  ;and other common elements
EndDeclareModule

Module Common: EndModule


Enumeration Common::RE_ID
  ;generate a few ID's
  #REID_main_this
  #REID_main_that
EndEnumeration

DeclareModule parse_mod
  Enumeration Common::RE_ID
    ;generate a few public ID's
    #REID_pm_this
    #REID_pm_that
  EndEnumeration
  
  Declare output()
EndDeclareModule

Module parse_mod
  Enumeration Common::RE_ID
    ;generate a private ID
    #REID_pm_another
  EndEnumeration
  
  Procedure output()
    Debug "REID's visible in parse_mod module"
    ;Debug #REID_main_this ;not visible
    ;Debug #REID_main_that ;not visible
    Debug #REID_pm_that
    Debug #REID_pm_this
    Debug #REID_pm_another
  EndProcedure
EndModule


Enumeration Common::RE_ID
  ;generate an additional ID
  #REID_main_another
EndEnumeration


Procedure output()
  Debug "REID's visible in main scope"
  Debug #REID_main_this
  Debug #REID_main_that
  Debug parse_mod::#REID_pm_this
  Debug parse_mod::#REID_pm_that
  ;Debug parse_mod::#REID_pm_another ;not visible outside parse_mod module
  Debug #REID_main_another
EndProcedure

parse_mod::output()
output()
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Did the RegEx library change in some way with 6.04?

Post by jacdelad »

Thanks Demivec! I know about the common module, but only use it for events and eventtypes and such. Since not everyone uses this technique I'll stick with #PB_Any, which should eliminate all problems.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply