I am quite new to programming, and I need to configure now an industrial camera made by Sentech-Omron (USB3 Vision) to provide video frames to an OpenCV-python application. The system is a Raspberry Pi 4B (8 GB). I tried it on Raspberry OS 10 (32 Bit), 11 (32 & 64 Bit) and Ubuntu (64 Bit). It should be mentioned that there is only one driver for all linux platforms available. It leads always to the same error output.
Problem: I cannot install the provided V4l2-driver from Sentech-Omron (unfortunately it is from 2017). It results in the following error messages in the bash:
pi#raspberrypi:~/Sentech-4.0.3/stcam_dd $ sudo make install
make -C /usr/src/linux-headers-5.15.32-v8+ M=/home/pi/Sentech-4.0.3/stcam_dd modules
make[1]: Entering directory '/usr/src/linux-headers-5.15.32-v8+'
CC [M] /home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.o
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:103:3: error: ‘const struct v4l2_ioctl_ops’ has no member named ‘vidioc_cropcap’; did you mean ‘vidioc_querycap’?
103 | .vidioc_cropcap = stcam_dd_func_cropcap,
| ^~~~~~~~~~~~~~
| vidioc_querycap
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:103:23: error: initialization of ‘int (*)(struct file *, void *, v4l2_std_id *)’ {aka ‘int (*)(struct file *, void *, long long unsigned int *)’} from incompatible pointer type ‘int (*)(struct file *, void *, struct v4l2_cropcap *)’ [-Werror=incompatible-pointer-types]
103 | .vidioc_cropcap = stcam_dd_func_cropcap,
| ^~~~~~~~~~~~~~~~~~~~~
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:103:23: note: (near initialization for ‘stcam_ioctl_ops.vidioc_g_std’)
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:104:3: error: ‘const struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_crop’; did you mean ‘vidioc_g_ctrl’?
104 | .vidioc_g_crop = stcam_dd_func_g_crop,
| ^~~~~~~~~~~~~
| vidioc_g_ctrl
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:104:22: error: initialization of ‘int (*)(struct file *, void *, v4l2_std_id)’ {aka ‘int (*)(struct file *, void *, long long unsigned int)’} from incompatible pointer type ‘int (*)(struct file *, void *, struct v4l2_crop *)’ [-Werror=incompatible-pointer-types]
104 | .vidioc_g_crop = stcam_dd_func_g_crop,
| ^~~~~~~~~~~~~~~~~~~~
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:104:22: note: (near initialization for ‘stcam_ioctl_ops.vidioc_s_std’)
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:105:3: error: ‘const struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_crop’; did you mean ‘vidioc_s_ctrl’?
105 | .vidioc_s_crop = stcam_dd_func_s_crop,
| ^~~~~~~~~~~~~
| vidioc_s_ctrl
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:105:22: error: initialization of ‘int (*)(struct file *, void *, v4l2_std_id *)’ {aka ‘int (*)(struct file *, void *, long long unsigned int *)’} from incompatible pointer type ‘int (*)(struct file *, void *, const struct v4l2_crop *)’ [-Werror=incompatible-pointer-types]
105 | .vidioc_s_crop = stcam_dd_func_s_crop,
| ^~~~~~~~~~~~~~~~~~~~
/home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.c:105:22: note: (near initialization for ‘stcam_ioctl_ops.vidioc_querystd’)
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:277: /home/pi/Sentech-4.0.3/stcam_dd/src/stcam_dd_api.o] Error 1
make[1]: *** [Makefile:1868: /home/pi/Sentech-4.0.3/stcam_dd] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.32-v8+'
make: *** [Makefile:12: default] Error 2
pi#raspberrypi:~/Sentech-4.0.3/stcam_dd $
I have been trying to understand the underlying problem and how to solve it, but I cannot find any solution... Especially as a beginner, it seems very tough.
Do you have any thoughts on this? Do I encounter a general issue when installing the driver?
Related
The codes:
// very complex where clause combined from several runtime variables.
let query: String = String.from("where ..........");
let rows_num: i64 = sqlx::query!( &*query).fetch_one(connection)
The error from compiler:
error: expected string literal
--> src/abc.rs:80:25
|
80 | let rows_num: i64 = sqlx::query!(
| ____________^
81 | | &*query,
82 | | ).fetch_one(connection)
| |^
|
= note: this error originates in the macro sqlx::query (in Nightly builds, run with -Z macro-backtrace for more info)
And the doc states:
The query must be a string literal or else it cannot be introspected (and thus cannot be dynamic or the result of another macro).
I know the sqlx computes at compile time, my where clause computation is at run time.
I really want to use variable, because the where clause depends other several conditions.
Are there any ways to use variable in sqlx?
Using sqlx::query() function instead of the sqlx::query!() macro. The document doesn't mention it in their page.
public
class FirstExample { // Here in this example we define some properties in our class
WRITE // This WRITE command follows a rule type defined in my grammar
Hello World
private
String firstTitle ;
private
String secondTitle ;
private
Integer firstAmount ;
private
Integer secondAmount ;
SET
firstTitle = "Ramesh"
SET
secondTitle = "Suresh"
SET
firstAmount = 100
SET
secondAmount = 200
When I change the command 'WRITE' to 'WRITEE' then error highlights in every line.
In eclipse java editor when we write a wrong syntax then error shows on that line only.
I am searching solution for this issue for past 2 days but not able to find the solution.
Kindly help me.I am not able to upload the picture due to some 10 reputation message comes while posting the question..
I am sending the grammar.Kindly check it once.
grammar org.xtext.example.mydsl.MyPoc with org.eclipse.xtext.common.Terminals hidden (GUESS_COMMENT,WS)
generate myPoc "http://www.xtext.org/example/mydsl/MyPoc"
Domainmodel:
(elements+=Type)*;
Type:Class;
// This is the starting point of the grammar
Class:
(packageList+=packageList)*
(packageList+=Import)*
(directives+=Directives) 'class' name=ID ('extends' superType=[Class])? '{'
(greetings+=Greeting)*
(features+=Feature)*
setValues+=SetValues*
operations+=Operation*
functionCall+=ArithmeticOperation*
directives+=Directive*
allMethod+=AllMethod*
allMethodInClass+=AllMethodInClass*
samples+=Samples*
'}';
//Package list consist of all the packages we want to include in our class
packageList:
('package' name=ID) ('.'?) (classes+=[Class])?;
//Import list consist of all the packages we want to include in our class
Import:
'import' importedNamespace=QualifiedNameWithWildcard;
QualifiedNameWithWildcard:
'QualifiedName' '.*'?;
Greeting:
(directives+=Directives)'Hello World'';'
(directives+=Directives)?'bye'?';'
(directives+=Directives)?';'
;
// Features defines the properties of that class
// In our grammar by default we make the property private
// our grammar takes two types of DataType String or Integer
// Name of the property given as per rule ID defined in Terminal file
Feature:
(directives+=Directives)* type=DATA_TYPE name=ID ';';
// In SetValues we initialize the properties by using SET directive
SetValues:
(directives+=Directives) name=ID ('='?) (INT | STRING)';';
//In Operation we define the function,arguments with there Data Type
Operation:
'Do' name=ID ('(' types+=DATA_TYPE args+=ID (',' types+=DATA_TYPE
args+=ID)* ')')?';';
//In Arithmetic Operation we call the function using $ passing the parameters
ArithmeticOperation:
(directives+=Directives)? name=ID '=' (directives+=Directives)? ('$')? types+=[Operation] ('(' (args+=ID) ','
(args+=ID)* ')')?';';
//In Samples we use Do While loop and inside that loop we use if else block
Samples:
name=ID (directives+=Directives) ('!,' STRING)? loopConstruct+=LoopConstruct* operations+=Operation*;
// In AllMethod we can call any method by using class name with '.' operator
AllMethod:
(classes+=[Class]) "." types+=[Operation] ('(' (args+=INT | ID) ',' (args+=INT | ID)* ');')?;
// In AllMethodInClass we can see all methods present in that class
AllMethodInClass:
types+=[Operation] ('(' (args+=INT | ID) ',' (args+=INT | ID)* ');')?;
//In LoopConstruct we define how we can use Do while loop with directive types given below
LoopConstruct:
(directives+=Directives) ("{"
(directives+=Directives ('!,' STRING))*
(directives+=Directive)*
"}")
(directives+=Directives) ("{"
(directives+=Directives ('!,' STRING))*
(directives+=Directive)*
"}")?
(directives+=Directives)?;
Directive:
(directives+=Directives) ('(' name=ID LOOP_CODITION_CHECK name=ID ')')?
'{' (directives+=Directives ('!,' STRING)?)* '}';
Directives:
name=DirectiveType;
DirectiveType:
{DirectiveType} value=DIRECTIVES_TYPE;
// From here all are rules which shows that what we can use in our grammar
terminal DATA_TYPE:
('Integer' | 'String');
// These are some directives
// WRITE is following this rule
terminal DIRECTIVES_TYPE:
('SET' | 'WRITE' | 'READ' | 'QUIT' | 'If' | 'ElseIf' | 'Else' | 'EndIf' | 'Do' | 'while' | 'private' | 'public' | 'do');
terminal LOOP_CODITION_CHECK:
('=' | '>' | '<' | '!')+;
terminal GUESS_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n');
I want to make it clear that WRITE is not only the issue.The line from where grammar breaks it shows error on the remaining lines comes after that line.
After changing my class rule with your code it gives lots of warning.I am sending the warning messages.
warning(200): ../org.xtext.example.myPoc/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyPoc.g:416:2: Decision can match input such as "RULE_ID {RULE_ID..RULE_DATA_TYPE, RULE_DIRECTIVES_TYPE, 'Do'}" using multiple alternatives: 8, 9
As a result, alternative(s) 9 were disabled for that input
error(201): ../org.xtext.example.myPoc/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyPoc.g:416:2: The following alternatives can never be matched: 9
warning(200): ../org.xtext.example.myPoc/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyPoc.g:1166:1: Decision can match input such as "RULE_DIRECTIVES_TYPE '{' RULE_DIRECTIVES_TYPE '!,' RULE_STRING '}' RULE_DIRECTIVES_TYPE" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.myPoc/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyPoc.g:1184:1: Decision can match input such as "'Do' RULE_ID '(' RULE_DATA_TYPE RULE_ID ',' RULE_DATA_TYPE RULE_ID ')' ';'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.myPoc/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyPoc.g:1546:3: Decision can match input such as "RULE_DIRECTIVES_TYPE" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.myPoc.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyPoc.g:568:1: Decision can match input such as "RULE_ID {RULE_ID, RULE_DATA_TYPE..RULE_DIRECTIVES_TYPE, '}', 'Do'..'('}" using multiple alternatives: 8, 9
As a result, alternative(s) 9 were disabled for that input
error(201): ../org.xtext.example.myPoc.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyPoc.g:568:1: The following alternatives can never be matched: 9
warning(200): ../org.xtext.example.myPoc.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyPoc.g:2810:42: Decision can match input such as "RULE_DIRECTIVES_TYPE '{' RULE_DIRECTIVES_TYPE '!,' RULE_STRING '}' RULE_DIRECTIVES_TYPE" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.myPoc.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyPoc.g:2838:39: Decision can match input such as "'Do' RULE_ID '(' RULE_DATA_TYPE RULE_ID ',' RULE_DATA_TYPE RULE_ID ')' ';'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.myPoc.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyPoc.g:3561:1: Decision can match input such as "RULE_DIRECTIVES_TYPE" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
After the warning code gives an exception
GeneratorException: (Element: -UNKNOWN-; Reported by: Generator)
org.eclipse.emf.common.util.WrappedException: java.io.FileNotFoundException: ..\org.xtext.example.myPoc\src-gen\org\xtext\example\mydsl\parser\antlr\internal\InternalMyPocLexer.java (The system cannot find the file specified)
I have reduced my grammar and remove all the error and warnings from my code but the error highlighting in every line is still there.
Now my grammar is
grammar org.xtext.example.mydsl.MyPoc with org.eclipse.xtext.common.Terminals hidden (GUESS_COMMENT,WS)
generate myPoc "http://www.xtext.org/example/mydsl/MyPoc"
Domainmodel:
(elements+=Type)*;
Type:Class;
// This is the starting point of the grammar
Class:
(packageList+=packageList)*
(packageList+=Import)*
(directives+=Directives) 'class' name=ID ('extends' superType=[Class])? '{'
(greetings+=Greeting
|features+=Feature
|setValues+=SetValues)*
'}';
//Package list consist of all the packages we want to include in our class
packageList:
('package' name=ID) ('.'?) (classes+=[Class])?;
//Import list consist of all the packages we want to include in our class
Import:
'import' importedNamespace=QualifiedNameWithWildcard;
QualifiedNameWithWildcard:
'QualifiedName' '.*'?;
Greeting:
(directives+=Directives)'Hello World'';'
(directives+=Directives)?'bye'?';'
(directives+=Directives)?';'
;
// Features defines the properties of that class
// In our grammar by default we make the property private
// our grammar takes two types of DataType String or Integer
// Name of the property given as per rule ID defined in Terminal file
Feature:
(directives+=Directives)* type=DATA_TYPE name=ID ';';
// In SetValues we initialize the properties by using SET directive
SetValues:
(directives+=Directives) name=ID ('='?) (INT | STRING)';';
Directives:
name=DirectiveType;
DirectiveType:
{DirectiveType} value=DIRECTIVES_TYPE;
// From here all are rules which shows that what we can use in our grammar
terminal DATA_TYPE:
('Integer' | 'String');
// These are some directives used by us taken from there website
terminal DIRECTIVES_TYPE:
('SET' | 'WRITE' | 'READ' | 'QUIT' | 'If' | 'ElseIf' | 'Else' | 'EndIf' | 'Do' | 'while' | 'private' | 'public' | 'do');
terminal LOOP_CODITION_CHECK:
('=' | '>' | '<' | '!')+;
terminal GUESS_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n');
And in eclipse xtext editor when I write private as privatee it shows error in every line.
My code is
public
class MyPoc {
private
String firstTitle ;
**privatee**
String title ;
private
String secondTitle ;
private
Integer firstAmount ;
private
Integer secondAmount ;
SET
firstTitle = "Ramesh";
SET
secondTitle = "Suresh";
SET
firstAmount = 100;
SET
secondAmount = 200;
}
Now I add some more grammar in my class attribute.The console shows no warning and no exception.But in eclipse editor again when we break grammar syntax it shows error in every line.
Class:
(packageList+=packageList)*
(packageList+=Import)*
(directives+=Directives) 'class' name=ID ('extends' superType=[Class])? LBRACKET
(directives+=Directives* (features+=Feature | setValues+=SetValues | operations+=Operation | functionCall+=ArithmeticOperation | allMethod+=AllMethod
| allMethodInClass+=AllMethodInClass | samples+=Samples) SEMICOLON)*
RBRACKET;
Kindly check it once and correct me if I am doing something wrong.
I have found that problem is not in the class part.The problem is in the parts where we define the rule in the grammar.
Like for ArithmeticOperation
ArithmeticOperation:
(directives+=Directives)? name=ID '=' (directives+=Directives)? ('$')? types+=[Operation] ('(' (args+=ID) ','
(args+=ID)* ')')?';';
Actually I have to write this code in eclipse.Here Concat is the opeartion name means method name.
SET Result = WRITE $ Concat (firstTitle , secondTitle)
Kindly correct me if I ma doing something wrong to achieve my target code.
Regards
Xtext error recovery system is not the same than Java Editor (JDT). Its behavior depends on how you write your rules.
Maybe your grammar is too much ambiguous and you should add a line termination symbol.
Also, you should read this article about error recovery with Xtext: Parser error recovery
Edit
Currently the class rule is very ambiguous with chaining rules with the same first token. The first thing you should do is to rewrite your class rule and remove all ambiguities.(warnings & erros when compiling grammar).
See the following example of class rule:
Class:
(packageList+=packageList)*
(packageList+=Import)*
(directives+=Directives) 'class' name=ID ('extends' superType=[Class])? '{'
(greetings+=Greeting | features+=Feature | setValues+=SetValues
| operations+=Operation | functionCall+=ArithmeticOperation
| directives+=Directive | allMethod+=AllMethod
| allMethodInClass+=AllMethodInClass | samples+=Samples)*
'}';
Edit 2
I made some refactorings to your grammar. And now it has the behavior you asked for.
Domainmodel:
(elements+=Type)*;
Type:Class;
// This is the starting point of the grammar
Class:
(packageList+=packageList)*
(packageList+=Import)*
(directives+=Directives) 'class' name=ID ('extends' superType=[Class])? LBRACKET
(directives+=Directives* (features+=Feature | setValues+=SetValues) SEMICOLON)*
RBRACKET;
terminal SEMICOLON:
';'
;
terminal LBRACKET:
'{'
;
terminal RBRACKET:
'}'
;
//Package list consist of all the packages we want to include in our class
packageList:
('package' name=ID) ('.'?) (classes+=[Class])?;
//Import list consist of all the packages we want to include in our class
Import:
'import' importedNamespace=QualifiedNameWithWildcard;
QualifiedNameWithWildcard:
'QualifiedName' '.*'?;
// Features defines the properties of that class
// In our grammar by default we make the property private
// our grammar takes two types of DataType String or Integer
// Name of the property given as per rule ID defined in Terminal file
Feature:
type=DATA_TYPE name=ID ;
// In SetValues we initialize the properties by using SET directive
SetValues:
name=ID ('='?) (INT | STRING);
Directives:
name=DirectiveType;
DirectiveType:
{DirectiveType} value=DIRECTIVES_TYPE;
// From here all are rules which shows that what we can use in our grammar
terminal DATA_TYPE:
('Integer' | 'String');
// These are some directives used by us taken from there website
terminal DIRECTIVES_TYPE:
('SET' | 'WRITE' | 'READ' | 'QUIT' | 'If' | 'ElseIf' | 'Else' | 'EndIf' | 'Do' | 'while' | 'private' | 'public' | 'do');
terminal LOOP_CODITION_CHECK:
('=' | '>' | '<' | '!')+;
terminal GUESS_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n');
Details of what i changed:
- Removed (useless?) greeting rule.
- Made line/block separators terminals.
- Moved directive to parent rule.
Sample code for editor:
public
class MyPoc {
private
String firstTitle ;
privatee
String title ;
private
String secondTitle ;
private
Integer firstAmount ;
private
Integer secondAmount ;
SET
firstTitle = "Ramesh";
SET
secondTitle = "Suresh";
SET
firstAmount = 100;
SET
secondAmount = 200;
}
I'm having a lot of trouble getting sml-mode in Emacs to sanely indent my code. For example, here is a block where it is behaving particularly strangely:
datatype type_node
= Param of TyParam.t
| LongId of LongId.t
| Offset of field * field list option
| List of type_t list
| Fun of type_t list * t list
| Any
| VProc
| Cont of TyArg.t list option
| Addr of type_t
and dataconsdef_node
= ConsDef of BomId.t * type_t option
and field_node
= Immutable of int * type_t
| Mutable of int * type_t
and fundef_node
= Def of Attrs.t option * BomId.t * TyParam.t list option
* Param.t list option * Param.t list option * type_t * exp_t
and varpat_node
= Wild
| Var of BomId.t * type_t option
and caserule_node
= LongRule of LongId.t * varpat_t list * exp_t
| LiteralRule Literal.t * exp_t
| DefaultRule of varpat_t * exp_t
and tycaserule_node
= TyRule of type_t * exp_t
| Default of exp_t
and simpleexp_node
= PrimOp of 'var Prim.prim * simpleexp_t list
| AllocId of LongId.t * simpleexp_t list
| AllocType of Type.t * simpleexp_t list
| AtIndex of int * simpleexp_t * simpleexp_t option
| TypeCast of Type.t * simpleexp_t
| HostVproc
| VpLoad of int * simpleexp_t
| VpAddr of int * simpleexp_t
| VpStore of int * simpleexp_t * t
| Id of LongId.t
| Lit of Literal.t
| MLString of string
and exp_node
= Let of VarPat.t list * rhs * t
| Do of SimpleExp.t * t
| Fun of FunDef.t list * t
| Cont of BomId.t * Param.t list option * t * t
| If of SimpleExp.t * t * t
| Case of SimpleExp.t * CaseRule.t list
| Typecase of TyParam.t * TyCaseRule.t list
| Apply of LongId.t * SimpleExp.t list option * SimpleExp.t list option
| Throw of LongId.t * SimpleExp.t list option
| Return of SimpleExp.t list option
and foo_node
= bar
Apologies for the huge code dump, but the content doesn't matter -- just the extremely inconsistent indentation. Attempting to define signatures inside of a structure Foo : sig ... end = struct ... end block is even worse:
structure Attrs : sig
type t
datatype node
= Attributes of string list
include WRAPPED
sharing type node' = node
sharing type obj = t
end
or:
functor DoWrap(type node) : sig
type t = node Wrap.t
include WRAPPED
sharing type node' = node
sharing type obj = t
end = struct
open Wrap
type t = node Wrap.t
type node' = node
type obj = t
end
I'm a diehard Emacs fan and I would hate to have to avoid it on this project, since it's one that I'll be working on the the next few months. However, I can't turn code like this in to my supervisor. The above is the behavior that I get when I select a block of text and indent-region.
I've looked at this answer, but the solution doesn't apply, since this is the behavior M-C-\ gives me, and it would be a huge pain to work on code without being able to auto-indent the whole file.
Is there an easy fix for this? Are there alternative sml-mode implementations?
Presuming that you are using the latest version of SML Mode from GNU ELPA, it looks like you have hit a corner-case in which the built-in SMIE grammar of SML Mode breaks down. I had similar issues with Tuareg Mode for OCaml.
You likely need to downgrade your version of SML Mode to version 4.0 or lower, which can obtain from http://www.iro.umontreal.ca/~monnier/elisp/. These versions do not yet use SMIE for indentation, but some ad-hoc indentation code. At least for OCaml and Tuareg, I found this old-fashioned approach to yield much better and much more reliable indentation.
You may want to report this issue to the maintainer of SML Mode, though, whose mail address you can find in the header of SML Mode, or in the footer of the aforementioned website.
I plan to embed SQL into my C-code using the PostgreSQL SPI, and I would like to the reference NAMEDATALEN const, so my code will be flexible enough to change with the database.
Is there a #include <> I can put in my C-code to reference this const?
Answer referenced from: Complete C-type Table (PostgreSQL v.9.1)
----------------------------------
| SQL Type | C Type | Defined In |
----------------------------------
| name | Name | postgres.h |
----------------------------------
It looks as though I need to do the following, to achieve my goal...
#include <postgres.h>
//char my_name[NAMEDATALEN]; // Theoretically, this should also be valid.
Name my_name;
EDIT: After some more digging, I was able to prove my hunch correct.
Pasted from postgres.h
00047 #include "c.h"
Pasted from c.h
00443 /*
00444 * Representation of a Name: effectively just a C string, but null-padded to
00445 * exactly NAMEDATALEN bytes. The use of a struct is historical.
00446 */
00447 typedef struct nameData
00448 {
00449 char data[NAMEDATALEN];
00450 } NameData;
00451 typedef NameData *Name;
I have a class Test_Class in Ada 2005 which has a parent-linked task property called Primary, from type Primary_Task, defined as:
type Test_Class is tagged limited
record
Info : Integer;
Value : Float;
Primary : Primary_Task (Test_Class'Access);
end record;
I need build a one-step constructor for my class in the form
function Construct (T : access Test_Class) return Test_Class_Ptr is
begin
return new Test_Class'(Info => T.Info + 1,
Value => 0.0,
Primary => [WHAT I WANNA KNOW]);
end Construct;
Currently my code is:
-- test_pkg.ads
package Test_Pkg is
type Test_Class;
type Test_Class_Ptr is access all Test_Class;
task type Primary_Task (This_Test : access Test_Class) is
pragma Storage_Size (1000);
end Primary_Task;
type Test_Class is tagged limited
record
Info : Integer;
Value : Float;
Primary : Primary_Task (Test_Class'Access);
end record;
function Construct (T : access Test_Class) return Test_Class_Ptr;
end Test_Pkg;
-- test_pkg.adb
with Text_IO; use Text_IO;
package body Test_Pkg is
[...]
function Construct (T : access Test_Class) return Test_Class_Ptr is
T_Ptr : constant Test_Class_Ptr := new Test_Class;
begin
T_Ptr.Info := T.Info + 1;
T_Ptr.Value := 0.0;
return T_Ptr;
end Construct;
end Test_Pkg;
So, how can I code it? What should I put in Primary => [...] code? Should I change the definition of Primary : Primary_Task (Test_Class'Access); in Test_Class definition?
I got an answer from Randy Brukardt (thank you) on comp.lang.ada:
In Ada 2005 or later, use "<>" to default initialize a component in an
aggregate (which is the only thing you can do with a task).
(...)
function Construct (T : access Test_Class) return Test_Class_Ptr is
begin
return new Test_Class'(Info => T.Info + 1,
Value => 0.0,
Primary => <>);
end Construct;
However, I tried to compile it using GNAT GPL 2011 and got the GNATBUG below
c:\tst>gnatmake -gnat12 test_pkg.adb
gcc -c -gnat12 test_pkg.adb
+===========================GNAT BUG DETECTED==============================+
| GPL 2011 (20110428) (i686-pc-mingw32) GCC error: |
| in create_tmp_var, at gimplify.c:505 |
| Error detected around test_pkg.adb:20:29 |
| Please submit a bug report by email to report#adacore.com. |
| GAP members can alternatively use GNAT Tracker: |
| http://www.adacore.com/ section 'send a report'. |
| See gnatinfo.txt for full info on procedure for submitting bugs. |
| Use a subject line meaningful to you and us to track the bug. |
| Include the entire contents of this bug box in the report. |
| Include the exact gcc or gnatmake command that you entered. |
| Also include sources listed below in gnatchop format |
| (concatenated together with no headers between files). |
| Use plain ASCII or MIME attachment. |
+==========================================================================+
Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
Consider also -gnatd.n switch (see debug.adb).
test_pkg.adb
test_pkg.ads
raised TYPES.UNRECOVERABLE_ERROR : comperr.adb:423
gnatmake: "test_pkg.adb" compilation error
So GNAT GPL users may have to wait for the next release to use this solution.