Where is the implementation of pixman_region32_init()? - pixman

lib: http://www.pixman.org/
repository: https://cgit.freedesktop.org/pixman/tree/
void pixman_region32_init (pixman_region32_t *region);
I can not find an implementation of that function..
thanks...

It's found in pixman/pixman.h (pixman-0.34.0)
ypedef struct pixman_region32_data pixman_region32_data_t;
typedef struct pixman_box32 pixman_box32_t;
typedef struct pixman_rectangle32 pixman_rectangle32_t;
typedef struct pixman_region32 pixman_region32_t;
struct pixman_region32_data {
long size;
long numRects;
/* pixman_box32_t rects[size]; in memory but not explicitly declared */
};
struct pixman_rectangle32
{
int32_t x, y;
uint32_t width, height;
};
struct pixman_box32
{
int32_t x1, y1, x2, y2;
};
struct pixman_region32
{
pixman_box32_t extents;
pixman_region32_data_t *data;
};

It's in pixman-region32.c. You don't see it because those functions are generated by the PREFIX macro and then the code in pixman-region.c is used. See here:
typedef pixman_box32_t box_type_t;
typedef pixman_region32_data_t region_data_type_t;
typedef pixman_region32_t region_type_t;
typedef int64_t overflow_int_t;
typedef struct {
int x, y;
} point_type_t;
#define PREFIX(x) pixman_region32##x
#define PIXMAN_REGION_MAX INT32_MAX
#define PIXMAN_REGION_MIN INT32_MIN
#include "pixman-region.c"
It first sets the PREFIX macro to pixman_region32 and then imports the code from pixman-region.c.

Related

Casting a const void* pointer parameter into a const char* pointer, in memchr function

I have to reproduce the functioning of the memchr function, which returns the pointer of the first int c occurence.
Of course, size_t n argument has been measured by func strlen before being sent to ft_memchr func parameter.
But I keep on getting this compiling error (compiled with a main.c) "
ft_memchr.c:10:21: error: operand of type 'const void' where arithmetic or pointer type is required
if ((const char *)s[i] == (const char)c)
"
I'm clearly missing something... It seems I can't cast the const void* parameter into a const char* or even a char*, why is that ?
Thank you.
#include <string.h>
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
if ((const char *)s[i] == (const char)c)
return ((char *)s + i);
}
return (NULL);
}

Purpose of *,& symbol behide datatype?

I am learning to implement graph using c++. I came across to see the follow code. Could anyone explain what is the function of symbols * and & behide the data type "vertex" and "string"?
#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;
struct vertex {
typedef pair<int, vertex*> ve;
vector <ve> adj; //cost of edge, distination to vertex
string name;
vertex (string s) : name(s) {}
};
class gragh
{
public:
typedef map<string, vertex *> vmap;
vmap work;
void addvertex (const string&);
void addedge (const string& from, const string&, double cost);
};
void gragh::addvertex (const string &name)
{
vmap::iterator itr = work.find(name);
if (itr == work.end())
{
vertex *v;
v = new vertex(name);
work[name] = v;
return;
}
cout << "Vertex alreay exist";
}
int main()
{
return 0;
}
'*' means to de-reference something i.e. go to the address of some variable whose address lies in the pointer.
int x=*p;
This means x will have the value of memory address to whom p is pointing.
x=&p;
This means x will have the address of that memory location where p resides.

appending IP option field to IP header using netfilter module

According to the bellow code :
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/inet.h>
static struct nf_hook_ops nfho;
unsigned int hook_func(unsigned int hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct iphdr *ip_header;
struct tcphdr *tcp_header;
ip_header = ip_hdr(skb);
ip_header = (struct iphdr *)skb_network_header(skb);
skb_set_transport_header(skb, ip_header->ihl * 4);
tcp_header = (struct tcphdr *)skb_transport_header(skb);
...
...
return NF_ACCEPT;
}
We can access to the packets,
and now i want to know can i append IP option field to IP header here?
struct iphdr *ip_header;
bind(hooknum,(sk_buff *) &ip_header,sizeof(ip_header));
struct tcphdr *tcp_header;
bind(hooknum,(sk_buff *) &tcp_header,sizeof(tcp_header));

assignment from incompatible pointer type (struct) c

for the struct
typedef struct Recording_Settings recording_settings;
struct Recording_Settings
{
gchar *profile;
gchar *destination;
};
recording_settings rec_settings;
I get a warning when I try to do this
static void profile_combo_change_cb(GtkComboBox *combo, gpointer userdata)
{
GtkTreeIter iter;
GtkTreeModel *model;
/* Grab the encoding profile choosen */
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) {
gchar *media_type;
gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &media_type, -1);
rec_settings.profile = rb_gst_get_encoding_profile(media_type); // Warning: assignment from incompatible pointer type
g_free (media_type);
}
}
Am I misunderstanding or missing something?
Thanks.
The type of rb_gst_get_encoding_profile seems to be
GstEncodingProfile *rb_gst_get_encoding_profile (const char *media_type);
but you assign its return value to a gchar *.
GstEncodingProfile is a struct type, as far as I can determine (typedef struct _GstEncodingProfile GstEncodingProfile;), and gchar is probably a typedef for a character type (most likely typedef char gchar; from glib). So the types would be incompatible.

Error declaration prototype with fancy vector

I have a problem, but I don't know what it is. I receive an error when I compile my code (some gnuplot is involved).
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include "gnuplot_i.hpp"
using namespace std;
typedef struct DATA{
char Label[50]; //title
vector<double> y,SD; //y data point SD sigma
}DATA;
typedef map<int, double> Episode;
typedef map<int, Episode> Stat_run;
double GetAvg(double *Array, int Count, double *stddev);
void wait_for_key();
void plotMyLines(DATA *Data, vector< std::map<int, map<int, double> > > Points, int printsteps, double Y1, double Y2, int episode, int run);
void PlotLines(const char *Outfile, vector<double> x, DATA *Data, int Lines, const string &xlabel, const string &ylabel, double Y1, double Y2);
int main()
{
vector<Stat_run> Points;
Stat_run exp1; Episode eps;
Stat_run exp2; Episode eps2;
}
I removed most of my code. The goal is to format some results to send them to my plotting functions. I receive an error that seems simple, but after 2 hours of test, I can't find where is my problem. Error:
error: expected ‘,’ or ‘...’ before ‘-’ token
I receive this error for the prototype of plotMyLines and PlotLines. Any hints appreciated!
I'm pretty sure this is
not the complete minimal code to show the problem
there is a preprocessor mess-up somewhere:
I can compile it no problem
There is not '-' token anywhere in this snippet of code.
Hint to investigate a preprocessor issue, see the output of preprocessing, e.g.
gcc -E -o test.cpp.ii .... (etc)
You should be able to see exactly what the compiler sees at the lines (scroll all the way down to recognize your own code).
The following compiles like a charm on g++
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef struct DATA{
char Label[50]; //title
vector<double> y,SD; //y data point SD sigma
}DATA;
typedef map<int, double> Episode;
typedef map<int, Episode> Stat_run;
double GetAvg(double *Array, int Count, double *stddev);
void wait_for_key();
void plotMyLines(DATA *Data, vector< std::map<int, map<int, double> > > Points, int printsteps, double Y1, double Y2, int episode, int run);
void PlotLines(const char *Outfile, vector<double> x, DATA *Data, int Lines, const string &xlabel, const string &ylabel, double Y1, double Y2);
int main()
{
vector<Stat_run> Points;
Stat_run exp1; Episode eps;
Stat_run exp2; Episode eps2;
}

Resources