Title: TypeManager.pointer_attribute are broken due to incompatibility with the C/C++ memory ownership model. · Issue #490 · Source-Python-Dev-Team/Source.Python · GitHub
Open Graph Title: TypeManager.pointer_attribute are broken due to incompatibility with the C/C++ memory ownership model. · Issue #490 · Source-Python-Dev-Team/Source.Python
X Title: TypeManager.pointer_attribute are broken due to incompatibility with the C/C++ memory ownership model. · Issue #490 · Source-Python-Dev-Team/Source.Python
Description: The values given to pointer_attribute are managed by CustomType's _allocated_pointers/_pointer_values, but since CustomType may be generated from raw pointers, CustomType cannot have ownership of the value. This applies to CustomType gen...
Open Graph Description: The values given to pointer_attribute are managed by CustomType's _allocated_pointers/_pointer_values, but since CustomType may be generated from raw pointers, CustomType cannot have ownership of t...
X Description: The values given to pointer_attribute are managed by CustomType's _allocated_pointers/_pointer_values, but since CustomType may be generated from raw pointers, CustomType cannot have ownership ...
Opengraph URL: https://github.com/Source-Python-Dev-Team/Source.Python/issues/490
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeManager.pointer_attribute are broken due to incompatibility with the C/C++ memory ownership model.","articleBody":"1. The values given to pointer_attribute are managed by CustomType's [_allocated_pointers](https://github.com/Source-Python-Dev-Team/Source.Python/blob/0171b36297c23d480c17631561c98c0ff2afca28/addons/source-python/packages/source-python/memory/manager.py#L90)/[_pointer_values](https://github.com/Source-Python-Dev-Team/Source.Python/blob/0171b36297c23d480c17631561c98c0ff2afca28/addons/source-python/packages/source-python/memory/manager.py#L94), but since CustomType may be generated from raw pointers, CustomType cannot have ownership of the value. This applies to CustomType generated by `make_object()`, nested [CustomType](https://github.com/Source-Python-Dev-Team/Source.Python/blob/0171b36297c23d480c17631561c98c0ff2afca28/addons/source-python/packages/source-python/memory/manager.py#L249-L252), and Array generated by static_pointer_array/dynamic_pointer_array.\r\n(See also #480, #489).\r\n\r\n2. If the value set in the pointer_attribute is an object generated by Python/Boost.Python, the memory will eventually be double free if the memory is managed by the C++ side. This can be circumvented by the user, but this is incompatible with the actual [Source.Python implementation](https://github.com/Source-Python-Dev-Team/Source.Python/blob/0171b36297c23d480c17631561c98c0ff2afca28/addons/source-python/packages/source-python/memory/manager.py#L512-L519). Furthermore, this means that when the user handles a pointer_attribute, it must be fully aware of how the memory is managed. While this may be feasible at the library level, it is impractical at the user level.\r\n\r\nThese two problems eventually lead to segmentation violation or double free or memory corruption, and these problems are very difficult or impossible to debug.\r\n\r\nProposal:\r\n\r\nWe should not assign the pointer of an object generated by Python/Boost.Python directly to other memory location, we should always make a copy of it and assign it, as in an [earlier implementation](https://github.com/Source-Python-Dev-Team/Source.Python/commit/7690d9674053a158bc79246dfc64d26a507d5209) (https://github.com/Source-Python-Dev-Team/Source.Python/commit/7690d9674053a158bc79246dfc64d26a507d5209). \r\nhttps://github.com/Source-Python-Dev-Team/Source.Python/blob/7690d9674053a158bc79246dfc64d26a507d5209/addons/source-python/packages/source-python/memory/__init__.py#L394-L399\r\n\r\nThis means that _allocated_pointers/_pointer_values are no longer required. If the user needs to delete a copied object, they can always use [CustomType._destructor](https://github.com/Source-Python-Dev-Team/Source.Python/blob/0171b36297c23d480c17631561c98c0ff2afca28/addons/source-python/packages/source-python/memory/manager.py#L73-L74).","author":{"url":"https://github.com/CookStar","@type":"Person","name":"CookStar"},"datePublished":"2023-08-10T00:21:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/490/Source.Python/issues/490"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:87010bcb-0494-1ef7-e04e-e2f62697ef92 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EAEA:121C5C:296E6CF:37ADCA3:69704A60 |
| html-safe-nonce | cdc4bafab729028c256d0ed675ed84a6d2189c453ace3e1d4b1fd50397123990 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUVBOjEyMUM1QzoyOTZFNkNGOjM3QURDQTM6Njk3MDRBNjAiLCJ2aXNpdG9yX2lkIjoiNDU3MDgzNjc0MDg2MjkyMTMxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 77eaffe66cc18298e2ae36443ae0cc98f020ef0348104c19348a26b27c7884a8 |
| hovercard-subject-tag | issue:1844214000 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Source-Python-Dev-Team/Source.Python/490/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb80218eac7d426da3d5c6b76755c130961918880da77227b390f81f3b0902ff/Source-Python-Dev-Team/Source.Python/issues/490 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb80218eac7d426da3d5c6b76755c130961918880da77227b390f81f3b0902ff/Source-Python-Dev-Team/Source.Python/issues/490 |
| og:image:alt | The values given to pointer_attribute are managed by CustomType's _allocated_pointers/_pointer_values, but since CustomType may be generated from raw pointers, CustomType cannot have ownership of t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CookStar |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| turbo-cache-control | no-preview |
| go-import | github.com/Source-Python-Dev-Team/Source.Python git https://github.com/Source-Python-Dev-Team/Source.Python.git |
| octolytics-dimension-user_id | 5440368 |
| octolytics-dimension-user_login | Source-Python-Dev-Team |
| octolytics-dimension-repository_id | 12771934 |
| octolytics-dimension-repository_nwo | Source-Python-Dev-Team/Source.Python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 12771934 |
| octolytics-dimension-repository_network_root_nwo | Source-Python-Dev-Team/Source.Python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f643964067a552f02067066d6a910b2f90a5721f |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width