private-attribute-cpp 2.2.8__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 → private_attribute_cpp-2.2.9}/CMakeLists.txt +4 -0
  2. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/PKG-INFO +1 -1
  3. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/private_attribute.cpp +23 -41
  4. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/pyproject.toml +1 -1
  5. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/LICENSE +0 -0
  6. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/README.md +0 -0
  7. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/picosha2.h +0 -0
  8. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/private_attribute.pyi +0 -0
  9. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_attr_classify_owner.py +0 -0
  10. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_class_private_attrs.py +0 -0
  11. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_gc_collect.py +0 -0
  12. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_init_subclass.py +0 -0
  13. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_private_abc.py +0 -0
  14. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_private_attrs.py +0 -0
  15. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_private_func.py +0 -0
  16. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_private_inheritance.py +0 -0
  17. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_private_method.py +0 -0
  18. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_private_wrap.py +0 -0
  19. {private_attribute_cpp-2.2.8 → private_attribute_cpp-2.2.9}/tests/test_slots_cycle.py +0 -0
  20. {private_attribute_cpp-2.2.8 → 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
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;
@@ -269,7 +265,6 @@ namespace {
269
265
  static std::shared_mutex all_register_new_metaclass_mutex;
270
266
  static std::unordered_map<uintptr_t, PyObjectStorage> all_register_type_weak_ref;
271
267
  static std::unordered_map<uintptr_t, uintptr_t> weakref_type;
272
- static std::unordered_set<uintptr_t> all_register_type;
273
268
  // Single dict-backed strong-ref cache shared by the module itself (keyed by
274
269
  // kModuleSelfKey) and by PrivateAttrBase (keyed by kPrivateAttrBaseKey),
275
270
  // so clean_all_storages can release everything at interpreter shutdown.
@@ -304,22 +299,12 @@ struct PrivateAttrCreationData
304
299
  lock_.lock();
305
300
  AllData::type_creation_locked = true;
306
301
  locked = true;
307
- AllData::tmp_type_allowed_code_map = code_map;
308
- AllData::tmp_type_attr_set = private_attrs_set;
309
- AllData::tmp_type_attr_dict = need_remove_itself;
310
302
  AllData::tmp_creation_data = this;
311
- if (private_func) {
312
- ::AllData::tmp_type_need_call.push_back(private_func);
313
- }
314
303
  }
315
304
  }
316
305
 
317
306
  void unlock() noexcept {
318
307
  if (locked) {
319
- AllData::tmp_type_allowed_code_map.clear();
320
- AllData::tmp_type_attr_set.clear();
321
- ::AllData::tmp_type_need_call.clear();
322
- AllData::tmp_type_attr_dict.clear();
323
308
  AllData::tmp_creation_data = nullptr;
324
309
  AllData::type_creation_locked = false;
325
310
  locked = false;
@@ -507,10 +492,6 @@ clean_all_storages() noexcept
507
492
  AllData::obj_attr_keys.clear();
508
493
  AllData::type_attr_dict.clear();
509
494
  AllData::type_allowed_code_map.clear();
510
- AllData::tmp_type_attr_set.clear();
511
- AllData::tmp_type_allowed_code_map.clear();
512
- AllData::tmp_type_need_call.clear();
513
- AllData::tmp_type_attr_dict.clear();
514
495
  AllData::type_creation_locked = false;
515
496
  AllData::tmp_creation_data = nullptr;
516
497
  AllData::all_type_mutex.clear();
@@ -528,7 +509,6 @@ clean_all_storages() noexcept
528
509
  AllData::all_type_clear.clear();
529
510
  AllData::all_type_del.clear();
530
511
  AllData::all_register_type_weak_ref.clear();
531
- AllData::all_register_type.clear();
532
512
  AllData::store_module_self.clear();
533
513
  }
534
514
 
@@ -571,12 +551,13 @@ is_class_code(uintptr_t typ_id, PyCodeObject* code) noexcept
571
551
  return true;
572
552
  }
573
553
  }
574
- // 2.2.1: fall back to the temporary (in-creation) code-object map while a
575
- // type has not been fully registered yet (e.g. inside type.tp_new / a
576
- // 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__).
577
557
  if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(typ_id) == ::AllData::all_type_attr_set.end()){
578
558
  uintptr_t code_id = (uintptr_t)code;
579
- 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()) {
580
561
  return true;
581
562
  }
582
563
  }
@@ -590,8 +571,8 @@ get_type_need_call(uintptr_t typ_id) noexcept
590
571
  return ::AllData::type_need_call[typ_id];
591
572
  }
592
573
  if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(typ_id) == ::AllData::all_type_attr_set.end()) {
593
- if (!::AllData::tmp_type_need_call.empty()) {
594
- 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;
595
576
  }
596
577
  }
597
578
  return nullptr;
@@ -608,11 +589,11 @@ is_type_private(uintptr_t typ_id, const std::string& name) noexcept
608
589
  }
609
590
  }
610
591
  // 2.2.1: if a type has not been registered yet (its id is absent from
611
- // all_type_attr_set), read from the temporary in-creation storage instead.
592
+ // all_type_attr_set), read from the in-creation storage instead.
612
593
  else if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(typ_id) == ::AllData::all_type_attr_set.end()) {
613
- auto& attr_set = ::AllData::tmp_type_attr_set;
614
594
  TwoStringTuple key = get_string_hash_tuple2(name);
615
- 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()){
616
597
  return true;
617
598
  }
618
599
  }
@@ -2710,9 +2691,10 @@ type_get_final_attr(uintptr_t main_type, uintptr_t target_type, const std::strin
2710
2691
  PyObject* obj = item_set[key];
2711
2692
  return obj;
2712
2693
  } else if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(main_type) == ::AllData::all_type_attr_set.end()) {
2713
- // now we can only use name instead of key on ::AllData::tmp_type_attr_dict[name]
2714
- if (::AllData::tmp_type_attr_dict.find(name) != ::AllData::tmp_type_attr_dict.end()) {
2715
- 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];
2716
2698
  return obj;
2717
2699
  }
2718
2700
  }
@@ -2771,7 +2753,8 @@ type_private_attr(uintptr_t type_id, const std::string& name) noexcept
2771
2753
  return true;
2772
2754
  }
2773
2755
  } else if (::AllData::type_creation_locked && ::AllData::all_type_attr_set.find(type_id) == ::AllData::all_type_attr_set.end()) {
2774
- 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()) {
2775
2758
  return true;
2776
2759
  }
2777
2760
  }
@@ -3547,7 +3530,7 @@ static bool
3547
3530
  is_registed_type(PyObject* type) noexcept
3548
3531
  {
3549
3532
  uintptr_t typ_id = (uintptr_t)type;
3550
- return (AllData::all_register_type.find(typ_id) != AllData::all_register_type.end());
3533
+ return (AllData::all_register_type_weak_ref.find(typ_id) != AllData::all_register_type_weak_ref.end());
3551
3534
  }
3552
3535
 
3553
3536
  static PyObject* ensure_metaclass_tp(PyObject* /*self*/, PyObject* metaclass) noexcept;
@@ -4259,7 +4242,6 @@ metaclass_weakref_callback(PyObject* /*self*/, PyObject* weakref) noexcept
4259
4242
  if (::AllData::weakref_type.find(weakref_id) == ::AllData::weakref_type.end()) Py_RETURN_NONE;
4260
4243
  uintptr_t id = ::AllData::weakref_type[weakref_id];
4261
4244
  ::AllData::weakref_type.erase(weakref_id);
4262
- ::AllData::all_register_type.erase(id);
4263
4245
 
4264
4246
  auto it = ::AllData::all_register_type_weak_ref.find(id);
4265
4247
  if (it != ::AllData::all_register_type_weak_ref.end()) {
@@ -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"
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"