我最近使用valgrind与glib(与gobject),它不能很好地工作.
我已经G_SLICE=always-malloc G_DEBUG=gc-friendly在命令行中添加了,但valgrind报告仍然有很多"可能丢失".
因为我在自动化测试中使用valgrind,所以我添加--error-exitcode=1,但那些"可能丢失"将使valgrind退出1,这将使我的测试失败.
有谁知道如何让valgrind不把"可能丢失"视为错误.
我正在为 Rhythmbox 编写一个插件,其中引发的信号传入一个类型为 的对象GArray。GLib Arrays的文档向我展示了一些我感兴趣但无法访问的方法。
例如,g_array_index可以为我获取GArray 中的第 n 个项目,但我无法调用它。GArray 对象也没有向我展示任何有用的方法。
要了解我的意思,请在 Python 控制台中执行此操作:
from gi.repository.GLib import Array
x = Array()
dir(x)
Run Code Online (Sandbox Code Playgroud)
这是 dir(x) 的输出
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__gtype__', '__hash__', '__info__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_free_on_dealloc', 'copy', 'data', 'len']
Run Code Online (Sandbox Code Playgroud)
我看到那里没有从数组中读取的方法,也没有关于g_array_indexGLib Arrays 文档页面上提到的任何方法或任何其他方法。我也试过
for a in x:
print a
Run Code Online (Sandbox Code Playgroud)
并且
list(x)
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误: …
按照http://docs.gstreamer.com/display/GstSDK/Installing+on+Windows上的说明在 Windows 7 上安装 GStreamer 并编译教程/示例,以便使用 Visual Studio 2010 进行编译。
安装 SDK 后,我尝试编译“hello world”示例...
Cannot open include file: 'gst/gst.h': No such file or directory.
Run Code Online (Sandbox Code Playgroud)
奇怪 - 教程应该配置了这些文件的路径。不过,我们可以手动添加它们...
将 C:\gstreamer-sdk\0.10\x86\include\gstreamer-0.10 添加到项目包含目录
Cannot open include file: 'glib.h': No such file or directory
Run Code Online (Sandbox Code Playgroud)
将 C:\gstreamer-sdk\0.10\x86\include\glib-2.0 添加到项目包含目录
Cannot open include file: 'glibconfig.h': No such file or directory
Run Code Online (Sandbox Code Playgroud)
在这一点上,它似乎是一个死胡同,因为 PC 上的任何地方都没有 glibconfig.h 文件。
gstreamer 文档中是否缺少某些步骤?
ps 我看到一个类似的问题,但它接受的答案似乎是一个死链接。
当我打电话时,我试图理解这意味着什么g_source_new。通话中的最新 API 文档(此时是 2.38.2)只是说:
创建一个新的 GSource 结构。指定大小以允许创建从包含附加数据的 GSource 派生的结构。传入的大小必须至少为 sizeof (GSource)。
我试图了解调用此 API 是否意味着我正在实例化我的新实例,GSource或者它是否旨在作为新GSource类型的注册。
潜在的问题是:我是否允许创建一个新的GSourceusingg_source_new然后将其应用于任意数量的上下文(通过g_source_attach)?或者即使在尝试将GSource我定义的相同功能应用于多个上下文时,我也必须同时使用这两个功能吗?
我正在尝试让 GStreamer SDK 的 basic-tutorial-5 在 OSX 上工作。
SDK 从http://gstreamer.freedesktop.org/data/pkg/osx/1.2.4.1/下载
教程(1.0)来自http://cgit.freedesktop.org/~slomo/gst-sdk-tutorials/
我收到以下错误
basic-tutorial-5.c:5:10: fatal error: 'gst/video/videooverlay.h' file not found
Run Code Online (Sandbox Code Playgroud)
当我跑
gcc `pkg-config gstreamer-1.0 gtk+-3.0 --cflags --libs` basic-tutorial-5.c -o basic5
Run Code Online (Sandbox Code Playgroud)
任何指针都会有所帮助!
谢谢。
编辑:
有一个gst/video/videooverlay.h在/local/frameworks/Gstreamer.framework/Headers。
的输出pkg-config gstreamer-1.0 gtk+-3.0 --cflags --libs不包括/Library/Frameworks/Gstreamer.framework/Versions/1.0/Headers
感谢@Biffen 使用时
gcc `pkg-config --cflags --libs gtk+-3.0` -o basic5 basic-tutorial-5.c -I/Library/Frameworks/Gstreamer.framework/Versions/1.0/Headers -framework GStreamer
Run Code Online (Sandbox Code Playgroud)
还有一点动作:
basic-tutorial-5.c:114:17: warning: 'gtk_button_new_from_stock' is deprecated
[-Wdeprecated-declarations]
play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
^
/usr/local/Cellar/gtk+3/3.12.2/include/gtk-3.0/gtk/gtkbutton.h:103:16: note:
'gtk_button_new_from_stock' declared here
GtkWidget* gtk_button_new_from_stock …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些函数从 glib 绑定到 Crystal 中。我已经这样做了并且有效:
@[Link("glib-2.0")]
lib LibG
fun g_utf8_strup(str : UInt8*, len : UInt32) : UInt8*
fun g_utf8_strdown(str : UInt8*, len : UInt32) : UInt8*
end
Run Code Online (Sandbox Code Playgroud)
然而它引入了内存泄漏:使用 g_* 函数创建的对象永远不会被垃圾收集。
是否有可能让glib在Crystal中与Boehm GC一起很好地发挥作用?受PCRE的启发,我尝试过:
@[Link("glib-2.0")]
lib LibG
# These 2 functions work perfectly
fun g_utf8_strup(str : UInt8*, len : UInt32) : UInt8*
fun g_utf8_strdown(str : UInt8*, len : UInt32) : UInt8*
alias Malloc = LibC::SizeT -> Void*
alias Free = Void* ->
$g_malloc : Malloc
$g_free : Free
end
# …Run Code Online (Sandbox Code Playgroud) 上下文
我正在将 C/GTK+ GUI 应用程序转换为 C#。我在 VS2017 中使用 GTKSharp 绑定版本 3.22.0。
该应用程序声明了几个信号,例如
g_signal_new ("SIG_NAME", params...);
Run Code Online (Sandbox Code Playgroud)
并通过 发出它们g_signal_emit_by_name(... "SIG_NAME"...)。
问题
我找不到一种方法将该行为转换为 GTK#。
我研究了 GTK# 的源代码,了解如何定义和处理自定义信号,就像这里一样,但我无法模仿那里实现的行为。
该方法
我尝试过像这样定义自定义对象:
using System;
using Gtk;
public class MyApp
{
public class MyCustomObj : GLib.Object
{
public delegate void MyDelegateSignalHandler(int arg0, int arg1);
public delegate void MyDelegate(int arg0, int arg1);
public class MyDelegateArgs : GLib.SignalArgs
{
public int a { get; set; }
}
public MyCustomObj() : base()
{}
[GLib.Signal("MyEvent")]
public …Run Code Online (Sandbox Code Playgroud) 我创建了我认为最简单的 GTK 4 应用程序来创建一个带有菜单栏的窗口,GAction当单击菜单项时,该菜单栏会激活 。
#include <stdio.h>
#include <assert.h>
#include <gtk/gtk.h>
static void
activate_quit(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
printf("Quit activated\n");
}
static void
startup(GApplication *app, gpointer user_data)
{
assert(user_data == NULL);
char *menubar_ui = (
"<interface>"
" <menu id='menubar'>"
" <submenu>"
" <attribute name='label' translatable='yes'>_File</attribute>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Quit</attribute>"
" <attribute name='action'>app.quit</attribute>"
" <attribute name='accel'><Primary>q</attribute>"
" </item>"
" </section>"
" </submenu>"
" </menu>"
"</interface>"
);
GtkBuilder *builder = gtk_builder_new_from_string(menubar_ui, -1);
GObject *menubar …Run Code Online (Sandbox Code Playgroud) 我在 OSX 12.0.1 Monterey 上安装了 gstreamer。我刚刚在运行 python 3.9 的虚拟环境中安装了 python 绑定:
pip3 install pycairo PyGObject
我可以毫无问题gi地导入。gi.repository.Gst然而,似乎几乎所有 gstreamer 插件都丢失了。这是我的测试脚本:
import gi
gi.require_versions({'Gst': '1.0'})
from gi.repository import Gst, GLib
Gst.init(None)
Gst.debug_set_active(True)
Gst.debug_set_default_threshold(5)
if not Gst.init_check()[0]:
print("gstreamer initialization failed")
class Main:
def __init__(self):
self.pipeline = Gst.parse_launch('playbin uri=https://gstreamer.freedesktop.org/data/media/small/sintel.mkv')
self.pipeline.set_state(Gst.State.PLAYING)
self.main_loop = GLib.MainLoop.new(None, False)
GLib.MainLoop.run(self.main_loop)
self.bus = self.pipeline.get_bus()
self.msg = self.bus.timed_pop_filtered(
Gst.CLOCK_TIME_NONE,
Gst.MessageType.ERROR | Gst.MessageType.EOS
)
if self.msg is not None:
self.msg.unref()
self.bus.unref()
self.pipeline.set_state(Gst.State.NULL)
self.pipeline.unref()
Main()
Run Code Online (Sandbox Code Playgroud)
它失败了:
0:00:00.006178000 92472 0x7fbd7d049210 INFO …Run Code Online (Sandbox Code Playgroud)