After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 764439 - Declare non-constant struct
Declare non-constant struct
Status: RESOLVED NOTABUG
Product: vala
Classification: Core
Component: Structs
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-04-01 00:25 UTC by Yannick Inizan
Modified: 2017-02-25 16:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
A simple GStreamer plugin with no features (770 bytes, text/plain)
2016-04-01 14:18 UTC, Al Thomas
Details

Description Yannick Inizan 2016-04-01 00:25:35 UTC
a GStreamer plugin needs a description declared with a struct.
ex. in C :

GstPluginDesc gst_plugin_desc = { ... };

if someone (like me) wants write a plugin with Vala, he can't write this plugin because vala doesn't allow non-constant field outside class/struct, and if constant struct is declared, GStreamer doesn't find this struct.

Plugin.vala:1.1-1.38: error: Non-constant field initializers not supported in this context
Gst.PluginDesc gst_plugin_desc = {
Comment 1 Al Thomas 2016-04-01 01:02:19 UTC
In Vala it would be:

public const Gst.PluginDesc gst_plugin_desc = { ... };

A simple test case is usually helpful when reporting a bug, but on this occasion a simple search with the terms "vala gst plugin" brought up several examples.

This example, https://github.com/tigrux/gst-plugin-omap4videodecbin/blob/master/gst/gstomap4videodecbin.vala , has: 

public const Gst.PluginDesc gst_plugin_desc = {
    Gst.VERSION_MAJOR, Gst.VERSION_MINOR,
    "omap4videodecbin",
    "Omap 4 video decoder bin",
    plugin_init,
    "0.0.1",
    "LGPL",
    "gstomap4videodecbin",
    "GstOmap4VideoDecBin",
    "https://github.com/tigrux/gst-plugin-omap4videodecbin"
};

and this example, https://gitorious.org/valastuff/gst-plugins-cl?p=valastuff:gst-plugins-cl.git;a=blob;f=src/gstopencl.vala;h=31c184bd9753b67f68454920749bbfcc907ec009;hb=HEAD , has:

const Gst.PluginDesc gst_plugin_desc = {
    0, 10, 
    "opencl", 
    "OpenCl plugin",
    plugin_init,
    "0.1",
    "LGPL",
    "http://",
    "Package?",
    "Origin?"
  };

Are you saying you have tried those examples and there is an error?
Comment 2 Yannick Inizan 2016-04-01 06:16:29 UTC
same links in my web browser.
my message is simple ...

"and if constant struct is declared, GStreamer doesn't find this struct."


for this moment I have to write C code or use 'sed' after pre-compilation
Comment 3 Yannick Inizan 2016-04-01 06:18:24 UTC
<al> breizhodrome: the error is saying you have declared non-constant fields. don't you want to declare a constant struct? try using 'unowned string' instead of 'string' maybe

it's a Gst.PluginDesc struct. this type of struct cannot be constant
Comment 4 Al Thomas 2016-04-01 14:18:19 UTC
Created attachment 325160 [details]
A simple GStreamer plugin with no features

Compile with:
valac --library my_simple_gst_plugin -X --shared -X -fPIC --pkg gstreamer-1.0 my_simple_gst_plugin.vala --output my_simple_gst_plugin.so

Examine the shared library with:
readelf --dyn-syms my_simple_gst_plugin.so

This will show the "gst_plugin_desc" symbol. This is what GStreamer is looking for in the binary when it loads the binary. It is a struct that is baked in to the binary. This is why it is constant. It does not change during run time.

To test whether GStreamer can read the struct use:
GST_PLUGIN_PATH=./ gst-inspect-1.0 my_simple_gst_plugin

This produces:
Plugin Details:
  Name                     my_simple_gst_plugin
  Description              A simple example of a GStreamer plugin
  Filename                 ./my_simple_gst_plugin.so
  Version                  0.0
  License                  unknown
  Source module            no-source-module
  Source release date      2016-01-01
  Binary package           Unknown binary package
  Origin URL               Provider has no URL


  0 features:

So this confirms that the constant struct is being found and the data read. The details for the struct are documented here:
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPlugin.html#GstPlugin-struct
Some fields can cause the plugin not to be loaded if they do not fit with what GStreamer is expecting. For example changing the license from 'unknown' to 'Unknown'. So your plugin may not be loading because of some error in the fields themselves. 

To state "it's a Gst.PluginDesc struct. this type of struct cannot be constant" is a very strong assertion. I hope the example and explanation above has now made it clear that this data structure needs to be constant.

If you are having problems writing your plugin then asking on the mailing list or posting to a forum such as StackOverflow will hopefully get you a helpful response. As far as this bug report goes you have provided no evidence that it is a bug in the Vala compiler.
Comment 5 Yannick Inizan 2016-04-01 16:52:05 UTC
thanks