private-attribute-cpp 2.2.8.1__tar.gz → 2.2.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/CMakeLists.txt +4 -0
  2. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/PKG-INFO +1 -1
  3. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/private_attribute.cpp +22 -37
  4. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/pyproject.toml +1 -1
  5. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/LICENSE +0 -0
  6. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/README.md +0 -0
  7. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/picosha2.h +0 -0
  8. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/private_attribute.pyi +0 -0
  9. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_attr_classify_owner.py +0 -0
  10. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_class_private_attrs.py +0 -0
  11. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_gc_collect.py +0 -0
  12. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_init_subclass.py +0 -0
  13. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_private_abc.py +0 -0
  14. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_private_attrs.py +0 -0
  15. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_private_func.py +0 -0
  16. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_private_inheritance.py +0 -0
  17. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_private_method.py +0 -0
  18. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_private_wrap.py +0 -0
  19. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_slots_cycle.py +0 -0
  20. {private_attribute_cpp-2.2.8.1 → private_attribute_cpp-2.2.9}/tests/test_use_parents.py +0 -0
@@ -8,6 +8,10 @@ find_package(
8
8
  COMPONENTS Interpreter Development.Module
9
9
  REQUIRED)
10
10
 
11
+ if(SKBUILD_SOABI)
12
+ set(Python_SOABI ${SKBUILD_SOABI})
13
+ endif()
14
+
11
15
  # Build the `private_attribute` extension module with a proper SOABI suffix
12
16
  # (private_attribute.cpython-3XX[-t]-<plat>.so), importable from site-packages.
13
17
  # Detect whether the running Python was built with --enable-shared.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 2.2.8.1
3
+ Version: 2.2.9
4
4
  Summary: A Python package that provides a way to define private attributes in C++ implementation.
5
5
  Author-Email: HuangHaoHua <13140752715@example.com>
6
6
  License-Expression: MIT
@@ -222,18 +222,14 @@ namespace {
222
222
  static std::unordered_map<uintptr_t, std::unordered_map<std::string, PyObjectStorage>> type_attr_dict;
223
223
  };
224
224
  static std::unordered_map<uintptr_t, std::unordered_map<uintptr_t, PyObjectStorage>> type_allowed_code_map;
225
- // 2.2.1: public temporary storage used while a type is still being
226
- // created (its id is not yet written into all_type_attr_set). It holds
227
- // the not-yet-registered type's full private-attribute set and its full
228
- // code-object map, keyed by the type being created. Accesses that happen
229
- // inside type.tp_new (e.g. a parent's __init_subclass__) read from here
230
- // until postprocess promotes the data into the real AllData tables.
225
+ // 2.2.1: while a type is still being created (its id is not yet written
226
+ // into all_type_attr_set), tmp_creation_data points at the in-flight
227
+ // PrivateAttrCreationData. Accesses that happen inside type.tp_new (e.g.
228
+ // a parent's __init_subclass__) read the private-attribute set and the
229
+ // code-object map directly from tmp_creation_data until postprocess
230
+ // promotes the data into the real AllData tables.
231
231
  static std::mutex type_creation_lock_mutex;
232
232
  static bool type_creation_locked = false;
233
- static std::unordered_set<TwoStringTuple> tmp_type_attr_set;
234
- static std::unordered_map<uintptr_t, PyObjectStorage> tmp_type_allowed_code_map;
235
- static std::vector<PyObjectStorage> tmp_type_need_call; // use vector to avoid of the dealloc after python end
236
- static std::unordered_map<std::string, PyObjectStorage> tmp_type_attr_dict;
237
233
  static PrivateAttrCreationData *tmp_creation_data = nullptr;
238
234
 
239
235
  static std::unordered_map<uintptr_t, std::unique_ptr<std::shared_mutex>> all_type_mutex;
@@ -303,22 +299,12 @@ struct PrivateAttrCreationData
303
299
  lock_.lock();
304
300
  AllData::type_creation_locked = true;
305
301
  locked = true;
306
- AllData::tmp_type_allowed_code_map = code_map;
307
- AllData::tmp_type_attr_set = private_attrs_set;
308
- AllData::tmp_type_attr_dict = need_remove_itself;
309
302
  AllData::tmp_creation_data = this;
310
- if (private_func) {
311
- ::AllData::tmp_type_need_call.push_back(private_func);
312
- }
313
303
  }
314
304
  }
315
305
 
316
306
  void unlock() noexcept {
317
307
  if (locked) {
318
- AllData::tmp_type_allowed_code_map.clear();
319
- AllData::tmp_type_attr_set.clear();
320
- ::AllData::tmp_type_need_call.clear();
321
- AllData::tmp_type_attr_dict.clear();
322
308
  AllData::tmp_creation_data = nullptr;
323
309
  AllData::type_creation_locked = false;
324
310
  locked = false;
@@ -506,10 +492,6 @@ clean_all_storages() noexcept
506
492
  AllData::obj_attr_keys.clear();
507
493
  AllData::type_attr_dict.clear();
508
494
  AllData::type_allowed_code_map.clear();
509
- AllData::tmp_type_attr_set.clear();
510
- AllData::tmp_type_allowed_code_map.clear();
511
- AllData::tmp_type_need_call.clear();
512
- AllData::tmp_type_attr_dict.clear();
513
495
  AllData::type_creation_locked = false;
514
496
  AllData::tmp_creation_data = nullptr;
515
497
  AllData::all_type_mutex.clear();
@@ -569,12 +551,13 @@ is_class_code(uintptr_t typ_id, PyCodeObject* code) noexcept
569
551
  return true;
570
552
  }
571
553
  }
572
- // 2.2.1: fall back to the temporary (in-creation) code-object map while a
573
- // type has not been fully registered yet (e.g. inside type.tp_new / a
574
- // parent's __init_subclass__).
554
+ // 2.2.1: fall back to the in-creation code-object map while a type has not
555
+ // been fully registered yet (e.g. inside type.tp_new / a parent's
556
+ // __init_subclass__).
575
557
  if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(typ_id) == ::AllData::all_type_attr_set.end()){
576
558
  uintptr_t code_id = (uintptr_t)code;
577
- if (::AllData::tmp_type_allowed_code_map.find(code_id) != ::AllData::tmp_type_allowed_code_map.end()) {
559
+ if (::AllData::tmp_creation_data &&
560
+ ::AllData::tmp_creation_data->code_map.find(code_id) != ::AllData::tmp_creation_data->code_map.end()) {
578
561
  return true;
579
562
  }
580
563
  }
@@ -588,8 +571,8 @@ get_type_need_call(uintptr_t typ_id) noexcept
588
571
  return ::AllData::type_need_call[typ_id];
589
572
  }
590
573
  if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(typ_id) == ::AllData::all_type_attr_set.end()) {
591
- if (!::AllData::tmp_type_need_call.empty()) {
592
- return ::AllData::tmp_type_need_call.back();
574
+ if (::AllData::tmp_creation_data && ::AllData::tmp_creation_data->private_func) {
575
+ return ::AllData::tmp_creation_data->private_func;
593
576
  }
594
577
  }
595
578
  return nullptr;
@@ -606,11 +589,11 @@ is_type_private(uintptr_t typ_id, const std::string& name) noexcept
606
589
  }
607
590
  }
608
591
  // 2.2.1: if a type has not been registered yet (its id is absent from
609
- // all_type_attr_set), read from the temporary in-creation storage instead.
592
+ // all_type_attr_set), read from the in-creation storage instead.
610
593
  else if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(typ_id) == ::AllData::all_type_attr_set.end()) {
611
- auto& attr_set = ::AllData::tmp_type_attr_set;
612
594
  TwoStringTuple key = get_string_hash_tuple2(name);
613
- if (attr_set.find(key) != attr_set.end()){
595
+ if (::AllData::tmp_creation_data &&
596
+ ::AllData::tmp_creation_data->private_attrs_set.find(key) != ::AllData::tmp_creation_data->private_attrs_set.end()){
614
597
  return true;
615
598
  }
616
599
  }
@@ -2708,9 +2691,10 @@ type_get_final_attr(uintptr_t main_type, uintptr_t target_type, const std::strin
2708
2691
  PyObject* obj = item_set[key];
2709
2692
  return obj;
2710
2693
  } else if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(main_type) == ::AllData::all_type_attr_set.end()) {
2711
- // now we can only use name instead of key on ::AllData::tmp_type_attr_dict[name]
2712
- if (::AllData::tmp_type_attr_dict.find(name) != ::AllData::tmp_type_attr_dict.end()) {
2713
- PyObject* obj = ::AllData::tmp_type_attr_dict[name];
2694
+ // now we can only use name instead of key on tmp_creation_data->need_remove_itself[name]
2695
+ if (::AllData::tmp_creation_data &&
2696
+ ::AllData::tmp_creation_data->need_remove_itself.find(name) != ::AllData::tmp_creation_data->need_remove_itself.end()) {
2697
+ PyObject* obj = ::AllData::tmp_creation_data->need_remove_itself[name];
2714
2698
  return obj;
2715
2699
  }
2716
2700
  }
@@ -2769,7 +2753,8 @@ type_private_attr(uintptr_t type_id, const std::string& name) noexcept
2769
2753
  return true;
2770
2754
  }
2771
2755
  } else if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(type_id) == ::AllData::all_type_attr_set.end()) {
2772
- if (::AllData::tmp_type_attr_set.find(hash_tuple) != ::AllData::tmp_type_attr_set.end()) {
2756
+ if (::AllData::tmp_creation_data &&
2757
+ ::AllData::tmp_creation_data->private_attrs_set.find(hash_tuple) != ::AllData::tmp_creation_data->private_attrs_set.end()) {
2773
2758
  return true;
2774
2759
  }
2775
2760
  }
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
4
4
 
5
5
  [project]
6
6
  name = "private_attribute_cpp"
7
- version = "2.2.8.1"
7
+ version = "2.2.9"
8
8
  description = "A Python package that provides a way to define private attributes in C++ implementation."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"