flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2, 3 Next |
Author |
|
revolution 30 Mar 2013, 18:25
You can't do anything with the error codes anyway. If you get an error, for whatever reason, in the cleanup code then there is nothing you can do about it except record it and (maybe) tell the user about it.
It is still imperative that you release the open handles. A memory leak is more important than an ephemeral GDI error code IMO. GDI errors happen occasionally and they probably just result in a glitch in the display which is corrected on the next refresh. But memory leaks last for the lifetime of the application and they are cumulative. In my code I never bother with checking release/delete error codes during cleanup because 1) I have nothing to do with such an error code, and 2) it is more important to avoid memory leaks. But you could, if you think it is necessary, record and accumulate any such errors. Then after releasing all handles check your accumulated error variable to see if something caused an error and pass the error to something. |
|||
![]() |
|
revolution 30 Mar 2013, 19:19
Actually now I see you are using the code space to store variables. This is going to be problematic if you ever want to open two windows of the same class because this makes the code not-thread-safe and not-reentrant. I wonder why you didn't use the stack (as would be more usual and cause less problems)?
|
|||
![]() |
|
MHajduk 30 Mar 2013, 20:35
revolution wrote: Actually now I see you are using the code space to store variables. This is going to be problematic if you ever want to open two windows of the same class because this makes the code not-thread-safe and not-reentrant. I wonder why you didn't use the stack (as would be more usual and cause less problems)? Moreover, if you run this program in any number of instances this also not be an issue here because each of the instances of the application has own separated space for code and data and this also won't cause any problems. The technique used in the application (storing variables inside the code of the 'WindowProc' procedure) simplifies in this particular case access to the variables. We can load and store their values directly without additional use of 'lea' instruction. Also there is no need to reserve an extra memory for the variables that should preserve their values between following calls of the 'WindowProc' procedure. All this is done by simple trick with variables located inside the procedure body. |
|||
![]() |
|
revolution 31 Mar 2013, 01:13
MHajduk wrote: This may cause problems only if you would create two instances of the main window class inside the same program. MHajduk wrote: Moreover, if you run this program in any number of instances this also not be an issue here because each of the instances of the application has own separated space for code and data and this also won't cause any problems. In general writing to a code section is just a bad habit. Even though you might not care for this small example it does promote the technique towards using it in other code where this type of habit can cause difficulties. |
|||
![]() |
|
uart777 31 Mar 2013, 04:51
revolution: After reading your posts, I agree with most of the things you say and I have gained much respect for you (for whatever it's worth). However, I would like to ask a question.
Agner Fog's optimization manuals say it's not a good practice to read/write data to/from code section (".text" in PEs) or to write "self-modifiable code". My question is: What is a "code section"? What distinguishes it from data? Who defines the boundaries and where? Isn't this OS/PE specific? |
|||
![]() |
|
revolution 31 Mar 2013, 05:05
Code sections are executable (and sometimes also readable).
Data sections are readable/writeable. The names of the sections are ignored by the OS. This is not OS or PE specific. The CPU MMU hardware can enforce these rules for any OS or file format. The AV angle is certainly OS specific but is still worth considering for any program you intend to make widely available. |
|||
![]() |
|
MHajduk 31 Mar 2013, 12:56
revolution wrote: But people tend to use and modify examples for their own use. If it was a full program I would not say anything, but for an example we expect people to copy and use for various purposes, not just the posted purpose. I have one question: I would like to use constants that are hidden inside the procedure, as for example TRIVERTEX structure that will never be modified, can I left them there (for initialization of the window background)? I think that in this case shouldn't be a problem with data conflict because these values would be always constant and I would like to have some data in one place, tightly tied with the window procedure body. |
|||
![]() |
|
revolution 31 Mar 2013, 13:05
MHajduk wrote: I have one question: I would like to use constants that are hidden inside the procedure, as for example TRIVERTEX structure that will never be modified, can I left them there (for initialization of the window background)? I think that in this case shouldn't be a problem with data conflict because these values would be always constant and I would like to have some data in one place, tightly tied with the window procedure body. In case others are not aware, you can make read-only data sections also (.idata), and logically the layout it "cleaner" from a file format perspective. |
|||
![]() |
|
MHajduk 01 Apr 2013, 18:22
The new version of the program has been published (see the first post in this thread).
![]() The most important changes:
![]() |
|||
![]() |
|
bitRAKE 01 Apr 2013, 20:00
Doesn't assemble in the FASM beta 1.71.08. Couldn't discern why - working well otherwise. Probably still bugs being worked out of the new label code.
|
|||
![]() |
|
MHajduk 01 Apr 2013, 20:51
bitRAKE wrote: Doesn't assemble in the FASM beta 1.71.08. Couldn't discern why - working well otherwise. Probably still bugs being worked out of the new label code. BTW, why people use unstable beta releases to show that this program doesn't compile? It is rather problem of the FASM beta version compiler (not fully tested as it seems) not my code. ![]() Seems that Tomasz introduced some updates in the planned new releases that may break the compatibility with code written for older (yet still latest stable!) releases. It sounds bad, very bad... ![]() |
|||
![]() |
|
hopcode 01 Apr 2013, 22:38
compiles and works ok using 1.71.09 and macros from 1.69.34 i didnt update them. and needed TRIVERTEX struct
Code: struct TRIVERTEX x dd ? y dd ? Red dw ? Green dw ? Blue dw ? Alpha dw ? ends Cheers, ![]()
_________________ ⠓⠕⠏⠉⠕⠙⠑ |
||||||||||
![]() |
|
MHajduk 01 Apr 2013, 23:09
As Tomasz explained in this thread: http://board.flatassembler.net/topic.php?t=15293 the bug is hidden in the new version of include file UTF8.INC and will be fixed soon.
![]() |
|||
![]() |
|
revolution 02 Apr 2013, 14:39
MHajduk: Are you aware that you are still writing to your code section?
Code: ;... section '.text' code readable writeable executable HwndMain dd 0 ; A handle of the main application window. ;... |
|||
![]() |
|
MHajduk 02 Apr 2013, 17:01
revolution wrote: MHajduk: Are you aware that you are still writing to your code section? Code: (...) ; The data section. ; section '.data' data readable writeable HwndMain dd 0 ; A handle of the main application window. HwndBis dd 0 ; A handle of the additional resizable application ; window. (...) ; The code section. ; section '.code' code readable executable start: (...) Code: ; The error handling routine that organizes the program flow when any of ; API functions returns zero value. ; ErrorRoutine16: ; Zeroize bits of the eax register from the 16th to the 31st one. ; Done to assure that the eax register won't contain any "garbage" ; after calling API functions returning 16-bit result. ; and eax, 0xFFFF ErrorRoutine: ; Check value stored in the eax register. If it's nonzero then ; return to the address following the place the error procedure ; has been called. ; test eax, eax jz @f retn 4 ; Check value of the last error that has occured. ; @@: invoke GetLastError test eax, eax jnz @f ; If there was no error, i.e. the 'GetLastError' function returned ; 'ERROR_SUCCESS', we return to the place when the 'ErrorRoutine' ; procedure was called and remove the 'ReturnTo' address stored on ; the stack before the procedure call. ; retn 4 @@: ; If there was an error, we display a message box with a human readable ; description of the error, remove the address of the procedure caller ; and return to the 'ReturnTo' address. ; stdcall ShowLastError, NULL, eax add esp, 4 retn Code: macro IfErr ReturnTo { push ReturnTo call ErrorRoutine } macro IfErr16 ReturnTo { push ReturnTo call ErrorRoutine16 } Quote: stdcall ErrorRoutine, <ReturnTo> The new version of the program has been published in the first post of this thread. |
|||
![]() |
|
MHajduk 02 Apr 2013, 17:09
BTW, I'd like to announce that after a "silent fix" of the bug in the include file UTF8.INC made by Tomasz Grysztar the FASM 1.71.09 beta version compiles the 'GradientFill' example without any problems.
|
|||
![]() |
|
revolution 02 Apr 2013, 17:11
MHajduk wrote: Yeah, it was an unintended and unwanted "heritage" of the previous version when data & code were mixed in one section. |
|||
![]() |
|
MHajduk 02 Apr 2013, 17:38
revolution wrote: I sometimes find it quite depressing to think about how many times I have rewritten the same piece of code before I can finally get it right. ![]() |
|||
![]() |
|
hopcode 02 Apr 2013, 20:05
revolution wrote: For me, a gram of planning can be worth a tonne of future rewards. Cheers, ![]() _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
![]() |
|
Goto page Previous 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.