libgtop 1.0.0 → 1.1.0
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 +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +37 -0
- data/lib/libgtop/loader.rb +37 -0
- data/lib/libgtop/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1b16d5bc12be96d5e915898f4cf267846f253dc4cc7f3a0ac21ce42dfffeec2
|
|
4
|
+
data.tar.gz: dbf926d1e5ad1a8e628a64b4fa0cdec444adb877c55e7238477a9e8565f4e6c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3e3449dc2f24bfbc08d9e6a0a818d2cd47e044193f88455c45716a1c579dd24d2b4ffc0a7f66296693be2bdb4ac8b9c056d0d47af032244bbca351952c11b82
|
|
7
|
+
data.tar.gz: 19edc8dbb51a496efb227de789131c8d1b8cb5cb8aa6993a2d7236a052d64c0ccce05fd56f11885873cffdf319df19198b65be2e48835051afd2b36ed2bfd830
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.1.0] - 2026-11-03
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- The record types are defined. libgtop names them `glibtop_proc_uid`,
|
|
15
|
+
`glibtop_mountentry` and so on, all lowercase, and the loader const_set those
|
|
16
|
+
names directly — which warns `rb_define_const: invalid name` and defines
|
|
17
|
+
nothing. The namespace had 372 constants, 36 functions and not one class.
|
|
18
|
+
They are now CamelCased with the `glibtop_` prefix dropped, so
|
|
19
|
+
`glibtop_proc_uid` is `GTop::ProcUid`, giving 42 record classes with readable
|
|
20
|
+
fields.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- The README now leads with the limitation this gem cannot fix: **the functions
|
|
25
|
+
are not callable.** Every libgtop function takes its result struct as the
|
|
26
|
+
first argument, and GObjectIntrospection resolves an argument's class from
|
|
27
|
+
the raw GI name via `mod.const_defined?("glibtop_proc_uid")`, which raises
|
|
28
|
+
`NameError: wrong constant name` regardless of what this gem names the class.
|
|
29
|
+
Found when console-rb tried to read process statistics through it. A Ruby
|
|
30
|
+
port needs `/proc` directly; fixing this means changing `resolve_class` in
|
|
31
|
+
ruby-gnome, not here.
|
|
32
|
+
|
|
10
33
|
## [1.0.0] - 2026-11-03
|
|
11
34
|
|
|
12
35
|
### Added
|
data/README.md
CHANGED
|
@@ -8,6 +8,43 @@ require "libgtop"
|
|
|
8
8
|
GTop.constants.size # the whole namespace, from the typelib
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Read this first: the functions are not callable
|
|
12
|
+
|
|
13
|
+
This gem loads, defines the `GTop` namespace, and gives you 372 constants and
|
|
14
|
+
42 record classes. It cannot call libgtop.
|
|
15
|
+
|
|
16
|
+
Every function in libgtop takes its result struct as the first argument —
|
|
17
|
+
`glibtop_get_proc_uid(glibtop_proc_uid *buf, pid_t pid)` — and libgtop names
|
|
18
|
+
those records in lowercase. GObjectIntrospection resolves an argument's Ruby
|
|
19
|
+
class from the raw GI name:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
# gobject-introspection/registered-type-info.rb, resolve_class
|
|
23
|
+
mod.const_defined?(name) # name == "glibtop_proc_uid"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`const_defined?` raises `NameError: wrong constant name` for a lowercase name,
|
|
27
|
+
so the call fails while normalising its arguments:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
GTop.glibtop_init
|
|
31
|
+
GTop.glibtop_get_proc_uid(GTop::ProcUid.new, Process.pid)
|
|
32
|
+
# => NameError: wrong constant name glibtop_proc_uid
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Renaming the class to `ProcUid` — which this gem does, because otherwise the
|
|
36
|
+
records are not defined at all — does not help: the resolution uses libgtop's
|
|
37
|
+
name, not the gem's.
|
|
38
|
+
|
|
39
|
+
**So a Ruby port needing process statistics should read `/proc` directly**,
|
|
40
|
+
which is what console-rb does. This is a limitation of ruby-gnome's loader
|
|
41
|
+
meeting a C library whose type names are not valid Ruby constants, and fixing
|
|
42
|
+
it means changing `resolve_class` upstream, not this gem.
|
|
43
|
+
|
|
44
|
+
The gem is published anyway because the namespace, its constants and its record
|
|
45
|
+
layouts are real and correct, and because the next person to consider binding
|
|
46
|
+
libgtop should find this written down rather than rediscover it.
|
|
47
|
+
|
|
11
48
|
## How this works, and why there is nothing to compile
|
|
12
49
|
|
|
13
50
|
libgtop ships a GObject Introspection typelib that describes every class,
|
data/lib/libgtop/loader.rb
CHANGED
|
@@ -22,6 +22,43 @@ module GTop
|
|
|
22
22
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
|
+
# Every function in this namespace takes its result struct as the first
|
|
26
|
+
# argument -- `glibtop_get_proc_uid(glibtop_proc_uid *buf, pid_t pid)` --
|
|
27
|
+
# so without the struct classes the whole API is uncallable from Ruby.
|
|
28
|
+
#
|
|
29
|
+
# libgtop names those records `glibtop_proc_uid`, `glibtop_mountentry` and
|
|
30
|
+
# so on, all lowercase. The loader derives a class name from the record
|
|
31
|
+
# name and const_sets it, which for a lowercase name warns
|
|
32
|
+
# rb_define_const: invalid name 'glibtop_proc_uid' for constant
|
|
33
|
+
# and defines nothing. The result was a namespace with 372 integer
|
|
34
|
+
# constants, 36 module functions and not one class, discovered when
|
|
35
|
+
# console-rb tried to read process statistics with it.
|
|
36
|
+
#
|
|
37
|
+
# So the name is made Ruby-shaped: the `glibtop_` prefix goes, and the rest
|
|
38
|
+
# is CamelCased. `glibtop_proc_uid` becomes {GTop::ProcUid}, which is also
|
|
39
|
+
# what a reader of the C API would guess. That silences the warnings and
|
|
40
|
+
# gives 42 record classes with readable fields.
|
|
41
|
+
#
|
|
42
|
+
# It does NOT make the functions callable, and nothing in this gem can.
|
|
43
|
+
# GObjectIntrospection resolves an argument's Ruby class from the raw GI
|
|
44
|
+
# name, in RegisteredTypeInfo#resolve_class:
|
|
45
|
+
#
|
|
46
|
+
# mod.const_defined?(name) # name == "glibtop_proc_uid"
|
|
47
|
+
#
|
|
48
|
+
# and `const_defined?` raises `NameError: wrong constant name` for a
|
|
49
|
+
# lowercase name whatever this gem calls the class. So
|
|
50
|
+
# `GTop.glibtop_get_proc_uid(GTop::ProcUid.new, pid)` constructs its
|
|
51
|
+
# argument and then dies resolving the argument's type. See the README.
|
|
52
|
+
def rubyish_class_name(info)
|
|
53
|
+
name = info.name
|
|
54
|
+
return super if /\A[A-Z]/.match?(name)
|
|
55
|
+
|
|
56
|
+
rest = name.sub(/\Aglibtop_?/, "")
|
|
57
|
+
return "Glibtop" if rest.empty?
|
|
58
|
+
|
|
59
|
+
rest.split("_").map(&:capitalize).join
|
|
60
|
+
end
|
|
61
|
+
|
|
25
62
|
# A Ruby constant has to begin with an uppercase letter, and this typelib
|
|
26
63
|
# has names that do not. GTop-2.0 declares lowercase struct names such as `glibtop_mountentry`.
|
|
27
64
|
# The default loader calls const_set regardless, which raises NameError
|
data/lib/libgtop/version.rb
CHANGED