Title: Who manages STRING_ARRAY/STRING_POINTER? · Issue #472 · Source-Python-Dev-Team/Source.Python · GitHub
Open Graph Title: Who manages STRING_ARRAY/STRING_POINTER? · Issue #472 · Source-Python-Dev-Team/Source.Python
X Title: Who manages STRING_ARRAY/STRING_POINTER? · Issue #472 · Source-Python-Dev-Team/Source.Python
Description: Who manages the char* set by Pointer.set_string_pointer? Is it impossible to set a string to a char* managed by a C++ object? Test Code 1: from memory import alloc string = "string1" string2 = "string2" s_p1 = alloc(4, False) s_p2 = allo...
Open Graph Description: Who manages the char* set by Pointer.set_string_pointer? Is it impossible to set a string to a char* managed by a C++ object? Test Code 1: from memory import alloc string = "string1" string2 = "str...
X Description: Who manages the char* set by Pointer.set_string_pointer? Is it impossible to set a string to a char* managed by a C++ object? Test Code 1: from memory import alloc string = "string1" stri...
Opengraph URL: https://github.com/Source-Python-Dev-Team/Source.Python/issues/472
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Who manages STRING_ARRAY/STRING_POINTER?","articleBody":"Who manages the char* set by Pointer.set_string_pointer? Is it impossible to set a string to a char* managed by a C++ object?\r\n\r\nTest Code 1:\r\n```python\r\nfrom memory import alloc\r\n\r\nstring = \"string1\"\r\nstring2 = \"string2\"\r\n\r\ns_p1 = alloc(4, False)\r\ns_p2 = alloc(4, False)\r\n\r\ns_p1.set_string_pointer(string)\r\ns_p2.set_string_pointer(string)\r\n\r\nprint(\"uint1\", s_p1.get_uint())\r\nprint(\"uint2\", s_p2.get_uint())\r\n\r\ns_p1.set_string_pointer(s_p2.get_string_pointer())\r\n\r\nprint(\"uint1\", s_p1.get_uint())\r\nprint(\"uint2\", s_p2.get_uint())\r\n\r\nprint(\"string1\", s_p1.get_string_pointer())\r\nprint(\"string2\", s_p2.get_string_pointer())\r\n\r\ns_p1.get_pointer().dealloc()\r\n```\r\nOutput 1:\r\n```\r\nuint1 3949688248\r\nuint2 3949688312\r\nuint1 3953894104\r\nuint2 3949688312\r\nstring1 12\r\nstring2 string2\r\nfree(): invalid pointer\r\n```\r\nFirst, I don't know why string1 is set to `12` instead of `string2` as in string2, but trying to free string1 would result in an illegal pointer deallocation. Who exactly is managing this char*?\r\n\r\nThere is also a problem with TypeManager.pointer_attribute not being able to set STRING_ARRAY.\r\n\r\nTest Code 2:\r\n```python\r\nfrom memory.manager import CustomType\r\nfrom memory.manager import Type\r\nfrom memory.manager import TypeManager\r\n\r\nmanager = TypeManager()\r\n\r\nclass Test(CustomType, metaclass=manager):\r\n _size = 4\r\n string = manager.pointer_attribute(Type.STRING_ARRAY, 0)\r\n\r\ntest = Test()\r\ntest.string = \"test\"\r\n```\r\nOutput 2:\r\n```\r\n[Source.Python]\r\n[SP] Caught an Exception:\r\nTraceback (most recent call last):\r\n File \"../addons/source-python/packages/source-python/plugins/command.py\", line 164, in load_plugin\r\n plugin = self.manager.load(plugin_name)\r\n File \"../addons/source-python/packages/source-python/plugins/manager.py\", line 207, in load\r\n plugin._load()\r\n File \"../addons/source-python/packages/source-python/plugins/instance.py\", line 74, in _load\r\n self.module = import_module(self.import_name)\r\n File \"../addons/source-python/plugins/test/test.py\", line 4214, in \u003cmodule\u003e\r\n test.string = \"test\"\r\n File \"../addons/source-python/packages/source-python/memory/manager.py\", line 515, in fset\r\n instance_ptr = alloc(TYPE_SIZES[type_name.upper()])\r\n\r\nKeyError: 'STRING_ARRAY'\r\n```\r\nSTRING_ARRAY also allows buffer overrun, and it seems that STRING-related issues are somewhat problematic.","author":{"url":"https://github.com/CookStar","@type":"Person","name":"CookStar"},"datePublished":"2023-05-17T16:22:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/472/Source.Python/issues/472"}
| 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:87d30162-c81d-eb00-8637-b6754dfc9185 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 87E0:B32AB:2E9431B:3E9C3D1:697083A7 |
| html-safe-nonce | 984c4d8eb77dd28e0e7f7cc450eee4ba3b5352d5df4b1671ffffac7262f175b8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0UwOkIzMkFCOjJFOTQzMUI6M0U5QzNEMTo2OTcwODNBNyIsInZpc2l0b3JfaWQiOiI3MTUzNjU5NDU1MTAxNTAyMzc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e848b85a85ed39ed02b484fb59b4df5c851fb2487dd068b40f2cbf9bd4f17741 |
| hovercard-subject-tag | issue:1714254331 |
| 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/472/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4423c98796b9ab5efb16ed92dbcb45d60a86c096da2aef52e31f21560518f172/Source-Python-Dev-Team/Source.Python/issues/472 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4423c98796b9ab5efb16ed92dbcb45d60a86c096da2aef52e31f21560518f172/Source-Python-Dev-Team/Source.Python/issues/472 |
| og:image:alt | Who manages the char* set by Pointer.set_string_pointer? Is it impossible to set a string to a char* managed by a C++ object? Test Code 1: from memory import alloc string = "string1" string2 = "str... |
| 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 | 7d6181066430cc06553c8396ca201e194ae33cb9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width