xot 0.3.14 → 0.3.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f172e96fd93b17555e3ecb3c39e39bfdca41262542ac7a466da9d0447d0e40b
4
- data.tar.gz: 02107f5e7b765ad11b7dd4a68f501d5c952e8cde8e0b1b1b4f3e2fd40c605311
3
+ metadata.gz: fb5106dfe6e2a51aa5564dd80ef829359effc9975343a86a6c7e06b858627976
4
+ data.tar.gz: e10270555bcf1fbbafb4d8c5a38808be5384b5c319b6bdac38c8ef34078ed4df
5
5
  SHA512:
6
- metadata.gz: 2049167fac1865e9aac0abe14692db36589471a30087711d35b7235f606173b21237fdb68864c3b00cb98367ad7f4f40f20ec7349273c86c5d725571c25d2f93
7
- data.tar.gz: 840c347e7a028850081974a24807bee0f88bc3833186f12a4f9615ba810c669313d4f7d42ebc277b086bebc976b4a26f3b9c4cd46fdd1c0715007c593e1a434c
6
+ metadata.gz: f77793be260e041b0acca7a8603191a661bf79b90539d41d60cee109bca721c0d83b268e3f2b44a966ee47bab2f99d8e825b7939e6afa10ac2bba26f819b7c10
7
+ data.tar.gz: ff16e23f9bac7b71a8864147f17211412a33a7c8ac1ee83ba2089a66567c95a46a7c4c6457a271046e9b588ef868409fa9761c0c80ac6ce938284e754879c4cf
data/ChangeLog.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # xot ChangeLog
2
2
 
3
3
 
4
+ ## [v0.3.15] - 2026-06-23
5
+
6
+ - Add WeakRef for weak references to RefCountable
7
+ - Compile vendored C sources with the C compiler
8
+
9
+
4
10
  ## [v0.3.14] - 2026-06-12
5
11
 
6
12
  - Link static archive explicitly in export_all_symbols on ucrt32
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.14
1
+ 0.3.15
data/include/xot/ref.h CHANGED
@@ -28,6 +28,28 @@ namespace Xot
28
28
  class EmptyClass {};
29
29
 
30
30
 
31
+ struct WeakRefCount : public NonCopyable
32
+ {
33
+
34
+ bool alive = true;
35
+
36
+ int ref_count = 1;
37
+
38
+ void retain ()
39
+ {
40
+ ++ref_count;
41
+ }
42
+
43
+ void release ()
44
+ {
45
+ assert(ref_count > 0);
46
+
47
+ if (--ref_count == 0) delete this;
48
+ }
49
+
50
+ };// WeakRefCount
51
+
52
+
31
53
  template <typename SuperClass = EmptyClass>
32
54
  class RefCountable : public SuperClass, public NonCopyable
33
55
  {
@@ -61,6 +83,12 @@ namespace Xot
61
83
  if (del) delete this;
62
84
  }
63
85
 
86
+ WeakRefCount* get_weak_ref_count ()
87
+ {
88
+ if (!wref_count) wref_count = new WeakRefCount();
89
+ return wref_count;
90
+ }
91
+
64
92
  virtual void* rucy_wrapper_value () const
65
93
  {
66
94
  return NULL;
@@ -86,12 +114,20 @@ namespace Xot
86
114
 
87
115
  virtual ~RefCountable ()
88
116
  {
117
+ if (wref_count)
118
+ {
119
+ wref_count->alive = false;
120
+ wref_count->release();
121
+ wref_count = NULL;
122
+ }
89
123
  }
90
124
 
91
125
  private:
92
126
 
93
127
  mutable int refc_count = 0;
94
128
 
129
+ WeakRefCount* wref_count = NULL;
130
+
95
131
  int refc_update_count (bool increment) const
96
132
  {
97
133
  int c = refc_count + (increment ? +1 : -1);
@@ -304,6 +340,115 @@ namespace Xot
304
340
  };// Ref
305
341
 
306
342
 
343
+ template <typename T>
344
+ class WeakRef
345
+ {
346
+
347
+ typedef WeakRef<T> This;
348
+
349
+ typedef T Value;
350
+
351
+ typedef const T ConstValue;
352
+
353
+ typedef T& Reference;
354
+
355
+ typedef const T& ConstReference;
356
+
357
+ typedef T* Pointer;
358
+
359
+ typedef const T* ConstPointer;
360
+
361
+ public:
362
+
363
+ WeakRef (Pointer ptr = NULL)
364
+ {
365
+ reset(ptr);
366
+ }
367
+
368
+ WeakRef (const This& obj)
369
+ {
370
+ reset(obj.ptr, obj.wref_count);
371
+ }
372
+
373
+ This& operator = (Pointer ptr)
374
+ {
375
+ reset(ptr);
376
+ return *this;
377
+ }
378
+
379
+ This& operator = (const This& obj)
380
+ {
381
+ if (&obj != this) reset(obj.ptr, obj.wref_count);
382
+ return *this;
383
+ }
384
+
385
+ ~WeakRef ()
386
+ {
387
+ if (wref_count) wref_count->release();
388
+ }
389
+
390
+ void reset (Pointer ptr = NULL)
391
+ {
392
+ reset(ptr, ptr ? ptr->get_weak_ref_count() : NULL);
393
+ }
394
+
395
+ Pointer get () {return wref_count && wref_count->alive ? ptr : NULL;}
396
+
397
+ ConstPointer get () const {return wref_count && wref_count->alive ? ptr : NULL;}
398
+
399
+ Pointer operator -> () {return get();}
400
+
401
+ ConstPointer operator -> () const {return get();}
402
+
403
+ Reference operator * () {return *get();}
404
+
405
+ ConstReference operator * () const {return *get();}
406
+
407
+ operator Pointer () {return get();}
408
+
409
+ operator ConstPointer () const {return get();}
410
+
411
+ bool operator == (Pointer ptr) const {return get() == ptr;}
412
+
413
+ bool operator != (Pointer ptr) const {return !operator==(ptr);}
414
+
415
+ bool operator == (ConstPointer ptr) const {return get() == ptr;}
416
+
417
+ bool operator != (ConstPointer ptr) const {return !operator==(ptr);}
418
+
419
+ bool operator == (const This& obj) const {return get() == obj.get();}
420
+
421
+ bool operator != (const This& obj) const {return !operator==(obj);}
422
+
423
+ template <typename X>
424
+ bool operator == (const WeakRef<X>& obj) const {return get() == obj.get();}
425
+
426
+ template <typename X>
427
+ bool operator != (const WeakRef<X>& obj) const {return !operator==(obj);}
428
+
429
+ bool operator < (const This& obj) const {return get() < obj.get();}
430
+
431
+ operator bool () const {return get();}
432
+
433
+ bool operator ! () const {return !operator bool();}
434
+
435
+ private:
436
+
437
+ void reset (Pointer ptr, WeakRefCount* count)
438
+ {
439
+ if (count) count->retain();
440
+ if (wref_count) wref_count->release();
441
+ this->ptr = ptr;
442
+ this->wref_count = count;
443
+ }
444
+
445
+ Pointer ptr = NULL;
446
+
447
+ WeakRefCount* wref_count = NULL;
448
+
449
+ };// WeakRef
450
+
451
+
307
452
  }// Xot
308
453
 
309
454
 
data/lib/xot/extconf.rb CHANGED
@@ -51,8 +51,8 @@ module Xot
51
51
  local_libs << 'stdc++' if gcc?
52
52
 
53
53
  $CPPFLAGS = make_cppflags $CPPFLAGS, defs, inc_dirs
54
- $CFLAGS = make_cflags $CFLAGS + ' -x c++'
55
- $CXXFLAGS = make_cflags $CXXFLAGS + ' -x c++' if $CXXFLAGS
54
+ $CFLAGS = make_cxxflags $CFLAGS + ' -x c++'
55
+ $CXXFLAGS = make_cxxflags $CXXFLAGS + ' -x c++' if $CXXFLAGS
56
56
  $LDFLAGS = make_ldflags ldflags, lib_dirs, frameworks
57
57
  $LOCAL_LIBS << local_libs.reverse.map {|s| " -l#{s}"}.join
58
58
  end
data/lib/xot/rake/util.rb CHANGED
@@ -213,22 +213,28 @@ module Xot
213
213
  [root, RbConfig::CONFIG['rubyarchhdrdir'] || "#{root}/#{RUBY_PLATFORM}"]
214
214
  end
215
215
 
216
- def make_cflags(flags = '')
217
- warning_opts = %w[no-unknown-pragmas]
218
- warning_opts += %w[
216
+ def make_cflags(flags = '', std: 'gnu17', stdlib: nil)
217
+ warn_opts = %w[no-unknown-pragmas]
218
+ warn_opts += %w[
219
219
  no-deprecated-register
220
220
  no-reserved-user-defined-literal
221
221
  ] if clang?
222
+
222
223
  s = flags.dup
223
- s << warning_opts.map {|s| " -W#{s}"}.join
224
- s << " -arch arm64" if osx? && arm64?
225
- s << ' -std=c++20' if gcc? || emcc?
226
- s << ' -std=c++20 -stdlib=libc++ -mmacosx-version-min=10.10' if clang?
227
- s << ' ' + RbConfig::CONFIG['debugflags'] if debug?
228
- s.gsub!(/-O\d?\w*/, '-O0') if debug?
224
+ s << " -arch arm64" if osx? && arm64?
225
+ s << " -std=#{std}" if clang? || gcc? || emcc?
226
+ s << " -stdlib=#{stdlib}" if clang? && stdlib
227
+ s << ' -mmacosx-version-min=10.10' if clang? && osx?
228
+ s << ' ' + RbConfig::CONFIG['debugflags'] if debug?
229
+ s.gsub!(/-O\d?\w*/, '-O0') if debug?
230
+ s << warn_opts.map {|s| " -W#{s}"}.join
229
231
  s
230
232
  end
231
233
 
234
+ def make_cxxflags(flags = '')
235
+ make_cflags flags, std: 'c++20', stdlib: 'libc++'
236
+ end
237
+
232
238
  def make_ldflags(flags = '', libdirs = [], frameworks = [])
233
239
  s = flags.dup
234
240
  s << libdirs.map {|s| " -L#{s}"}.join
@@ -242,11 +248,17 @@ module Xot
242
248
  make_cppflags flags, defs, inc_dirs
243
249
  end
244
250
 
251
+ def cflags(warnings = true)
252
+ cflags = get_env :CFLAGS, RbConfig::CONFIG['CFLAGS']
253
+ cflags = cflags.gsub(/-W[\w\-\=]+/, '') + ' -w' unless warnings
254
+ make_cflags cflags
255
+ end
256
+
245
257
  def cxxflags(warnings = true)
246
258
  cflags = get_env :CFLAGS, RbConfig::CONFIG['CFLAGS']
247
259
  cxxflags = get_env :CXXFLAGS, RbConfig::CONFIG['CXXFLAGS']
248
260
  cflags = cflags.gsub(/-W[\w\-\=]+/, '') + ' -w' unless warnings
249
- make_cflags "#{cflags} #{cxxflags}"
261
+ make_cxxflags "#{cflags} #{cxxflags}"
250
262
  end
251
263
 
252
264
  def arflags()
data/lib/xot/rake.rb CHANGED
@@ -327,7 +327,11 @@ module Xot
327
327
  unless get_env :VENDOR_NOCOMPILE, false
328
328
  vendor_srcs_map(*srcdirs).each do |src, obj|
329
329
  rake_puts "compiling #{src}"
330
- sh %( #{cxx} -c #{cppflags} #{cxxflags false} -o #{obj} #{src} )
330
+ if File.extname(src) == '.c'
331
+ sh %( #{cc} -c #{cppflags} #{cflags false} -o #{obj} #{src} )
332
+ else
333
+ sh %( #{cxx} -c #{cppflags} #{cxxflags false} -o #{obj} #{src} )
334
+ end
331
335
  end
332
336
  end
333
337
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-12 00:00:00.000000000 Z
11
+ date: 2026-06-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This library include some useful utility classes and functions for development
14
14
  with C++.