[GH-ISSUE #126] Question: Pointer to lxw_worksheet if lxw_workbook is closed #106

Closed
opened 2026-05-05 11:41:30 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @petricf on GitHub (Sep 5, 2017).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/126

Originally assigned to: @jmcnamara on GitHub.

If - by accident or coding error - lxw_worbook is closed, but lxw_woksheet/-format/... is used afterwards - what does happen ?

Does it throw an assert, ignore requests, invalid memory access exception, ... ?

Is there a method to verify that the workbook is closed when actually using the other pointers ?
In other words - can i check (for example) an lxw_worksheet pointer whether the accompanied workbook is still open ?

Functions like

bool worksheet_valid (lxw_worksheet * sheet);
bool format_valid (lxw_format * format);
bool is_document_open (lxw_worksheet * worksheet);

to check the pointers without requiring access to lxw_workbook pointer would be nice.

Reasoning: At the location i use lxw_worksheet i have currently no access to its accompanied lxw_workbook.

Originally created by @petricf on GitHub (Sep 5, 2017). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/126 Originally assigned to: @jmcnamara on GitHub. If - by accident or coding error - lxw_worbook is closed, but lxw_woksheet/-format/... is used afterwards - what does happen ? Does it throw an assert, ignore requests, invalid memory access exception, ... ? Is there a method to verify that the workbook is closed when actually using the other pointers ? In other words - can i check (for example) an lxw_worksheet pointer whether the accompanied workbook is still open ? Functions like > bool worksheet_valid (lxw_worksheet * sheet); > bool format_valid (lxw_format * format); > bool is_document_open (lxw_worksheet * worksheet); to check the pointers without requiring access to lxw_workbook pointer would be nice. Reasoning: At the location i use lxw_worksheet i have currently no access to its accompanied lxw_workbook.
gitea-mirror 2026-05-05 11:41:30 -06:00
Author
Owner

@jmcnamara commented on GitHub (Sep 6, 2017):

Does it throw an assert, ignore requests, invalid memory access exception, ... ?

Currently there isn't a warning but there probably should be. Also, I could add a function to check if a workbook is closed.

However, I'm not convinced by the use case for accessing the workbook from a worksheet. That seems to me to be something that could be handled in the application logic.

If that part of the request gets some +1 then I'll add it.

<!-- gh-comment-id:327420939 --> @jmcnamara commented on GitHub (Sep 6, 2017): > Does it throw an assert, ignore requests, invalid memory access exception, ... ? Currently there isn't a warning but there probably should be. Also, I could add a function to check if a workbook is closed. However, I'm not convinced by the use case for accessing the workbook from a worksheet. That seems to me to be something that could be handled in the application logic. If that part of the request gets some +1 then I'll add it.
Author
Owner

@petricf commented on GitHub (Sep 6, 2017):

All functions writing to a worksheet do not need access to the lxw_workbook pointer. They have a lxw_worksheet pointer.
If you simply pass the the worksheet pointer to separate (for example) thread or (im my case) a separate class instance (at init) you run in a problem (no - not if you code carefully - but shit happens ...).
Inside there you don't know whether the workbook have been already closed when accessing the class methods (which are using the worksheet pointer to write data) later.

So you have a worksheet pointer whose workbook have been closed but you do not have the ability to verify this.

<!-- gh-comment-id:327542305 --> @petricf commented on GitHub (Sep 6, 2017): All functions writing to a worksheet do not need access to the lxw_workbook pointer. They have a lxw_worksheet pointer. If you simply pass the the worksheet pointer to separate (for example) thread or (im my case) a separate class instance (at init) you run in a problem (no - not if you code carefully - but shit happens ...). Inside there you don't know whether the workbook have been already closed when accessing the class methods (which are using the worksheet pointer to write data) later. So you have a worksheet pointer whose workbook have been closed but you do not have the ability to verify this.
Author
Owner

@jmcnamara commented on GitHub (Sep 6, 2017):

not if you code carefully

For me this is the important part. In general I am against adding syntactic sugar for things that can be handled in the end-users application apart from cases that are really painful to do otherwise or cases that are frequently requested.

<!-- gh-comment-id:327546704 --> @jmcnamara commented on GitHub (Sep 6, 2017): > not if you code carefully For me this is the important part. In general I am against adding syntactic sugar for things that can be handled in the end-users application apart from cases that are really painful to do otherwise or cases that are frequently requested.
Author
Owner

@petricf commented on GitHub (Sep 6, 2017):

Sure. But nobody is perfect - even i am not.
Having a safeguard - in my opinion - is never a mistake.

<!-- gh-comment-id:327608839 --> @petricf commented on GitHub (Sep 6, 2017): Sure. But nobody is perfect - even i am not. Having a safeguard - in my opinion - is never a mistake.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#106
No description provided.